Shop OBEX P1 Docs P2 Docs Learn Events
Robot Programming Help Needed — Parallax Forums

Robot Programming Help Needed

jason_wujason_wu Posts: 4
edited 2004-09-22 15:28 in BASIC Stamp
'{$STAMP BS2}
debug "!!!READY!!!",cr

'
Declarations
pulse_count var word
left_photo var word
right_photo var word
left_IR_det var bit
right_IR_det var bit
'
Initialization
output 2
freqout 2, 2000, 3000
low 12
low 13
output 7
output 1
'
Main Routine
main:
·freqout 7, 1, 38500
·left_IR_det = in8
·freqout 1, 1, 38500
·right_IR_det = in0
·debug home, "Left=", bin1 left_IR_det
·pause 10
·debug " Right= ", bin1 right_IR_det
·pause 10

·high 3
·pause 3
·rctime 3, 1, right_photo
·high 5
·pause 3
·rctime 5, 1, left_photo
·debug home, "L ", dec5 left_photo," R ", dec5 right_photo
·if abs(left_photo-right_photo) > 10 then check_dir
·if left_IR_det = 0 and right_IR_det = 0 then u_turn
·if right_IR_det = 0 then right_turn
·if left_IR_det = 0 then left_turn

·forward:
··for pulse_count = 1 to 100
··· pulsout 12, 500
··· pulsout 13, 1000
··next
·· goto main
·check_dir:
··if left_photo > right_photo then right_turn
··if left_photo < right_photo then left_turn


'
Navigation Poutines
·left_turn:
··for pulse_count = 1 to 35
··· pulsout 12, 500
··· pulsout 13, 500
··next
···· goto main


·right_turn:
··for pulse_count = 1 to 35
··· pulsout 12, 1000
··· pulsout 13, 1000
··next
···· goto main


·u_turn:

··for pulse_count = 1 to 75
·· pulsout 12, 1000
·· pulsout 13, 1000
··next
····· goto main

i cant run my program, so i need yr all help.Can anybody hepl my to redo my mistake....thanks...




Post Edited By Moderator (Jon Williams) : 9/22/2004 12:59:50 PM GMT

Comments

  • Shawn LoweShawn Lowe Posts: 635
    edited 2004-09-14 03:40
    What are you trying to do?
  • jason_wujason_wu Posts: 4
    edited 2004-09-14 08:05
    i try to move my a robot car with detect the photoregister and infrared.For example, when the robot detected darkness, it will go backward·and turn a U_turn or when it detected a blocked thing with the sensor, then it wil make a turn like turn right or turn left....
  • JavalinJavalin Posts: 892
    edited 2004-09-22 12:49
    if your using a BS2 and the latest pbasic editor, use the directive menu to add a PBASIC language directive (Directive->PBasic->version 2.5)

    This will colour comment your code and make it easy to read!

    Also, break it down into smaller chunks and try to get it working piece by piece. This will allow you to trouble-shoot problems.

    Finnally, use declarations/constants to refer to pins i.e. instead of output 2, use
    LCD_pin con 2
    output lcd_pin

    This will make it easier to read (again), and keeps the pin numbers (etc) the same.

    Good luck....
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-22 12:59
    What, exactly, is wrong? The program compiles and looking very quickly, seems to have correct logic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • DaveGDaveG Posts: 84
    edited 2004-09-22 14:54
    Jon,

    It seems like Jason's code is missing an important command in the "turn" and "forward" sequences.
    Shouldn't there be a PAUSE 20 (as shown below) inserted after the pulsout commands, to slow down the
    loop and give the servos time to react?

    right_turn:
    for pulse_count = 1 to 35
    pulsout 12, 1000
    pulsout 13, 1000
    PAUSE 20
    next
    goto main

    Dave G
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-09-22 15:28
    Good catch, Dave -- that's what I get for working before heading over to Starbucks....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.