Robot Programming Help Needed
jason_wu
Posts: 4
'{$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
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
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 Williams
Applications Engineer, Parallax
Dallas Office
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 Williams
Applications Engineer, Parallax
Dallas Office