Wrote my own navigation code, but need help fixing code.
noobmuncher
Posts: 124
Hello, since my robot is some what similar in make up to the Boe Bot I am modifying the Roaming with the PING))) - Advanced (.bs2) program to work for it. www.parallax.com/Portals/0/Downloads/src/prod/RoamingWithPING-V1.0.zip
Although i am running into two problems i am seeming to find difficult to fix even though normally it is a minor adjustment. i am trying to have the robot rely purely on the ping measurement and not need the IR signals to operate. Also my servo is facing forward, (i.e the side with the shaft is facing the front of the robot.). I tried using the simplified roaming with ping, but it was... not what i was looking for.
Any help with this code would be greatly appreciated.
Post Edited (noobmuncher) : 8/22/2008 9:06:39 AM GMT
Although i am running into two problems i am seeming to find difficult to fix even though normally it is a minor adjustment. i am trying to have the robot rely purely on the ping measurement and not need the IR signals to operate. Also my servo is facing forward, (i.e the side with the shaft is facing the front of the robot.). I tried using the simplified roaming with ping, but it was... not what i was looking for.
Any help with this code would be greatly appreciated.
Post Edited (noobmuncher) : 8/22/2008 9:06:39 AM GMT
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"A complex design is the sign of an inferior designer." - Jamie Hyneman, Myth Buster
DGSwaner
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' Basic Navigation program for my yet to be named cylindrical robot. The robot will
' initially use just the ((PING senor for it's object detection.
'
'
' Variables
'
counter VAR Word
CmConstant CON 2260
cmDistance_left VAR Word
cmDistance_center VAR Word
cmDistance_right VAR Word
time_left VAR Word
time_center VAR Word
time_right VAR Word
direction VAR Word
movement VAR Word
' Initialization
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
'
' Main procedure
'
DO
GOSUB Scan
IF cmDistance_left > cmDistance_center OR cmDistance_right THEN
GOSUB go_left
ELSE
cmDistance_center > cmDistance_left OR cmDistance_right THEN
GOSUB go_forward
ELSE
cmDistance_right > cmDistance_left OR cmDistance_center THEN
GOSUB go_right
ENDIF
LOOP
'
'Subroutines
'
Scan: 'Scan sub-route
FOR counter = 1 TO 150 'Turn Left 90 Degrees
PULSOUT 14, 350
PAUSE 20
NEXT
PULSOUT 15, 5 'Take measurement
PULSIN 15, 1, time_left
cmDistance_left = cmConstant ** time_left
DEBUG HOME, DEC3 cmDistance_left, " cm"
PAUSE 100
FOR counter = 1 TO 150 'Center Head
PULSOUT 14, 750
PAUSE 20
NEXT
PULSOUT 15, 5 'Take measurement
PULSIN 15, 1, time_center
cmDistance_center = cmConstant ** time_center
DEBUG HOME, DEC3 cmDistance_center, " cm"
PAUSE 100
FOR counter = 1 TO 150 'Turn Right 90 Degrees
PULSOUT 14, 1150
PAUSE 20
NEXT
PULSOUT 15, 5 'Take measurement
PULSIN 15, 1, time_right
cmDistance_right = cmConstant ** time_right
DEBUG HOME, DEC3 cmDistance_right, " cm"
PAUSE 100
RETURN
go_left:
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
FOR counter = 1 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
cmDistance_left - 20 / 15.24 * 40.65 = movement
FOR counter = 1 TO movement
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
go_forward:
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
cmDistance_center - 20 / 15.24 * 40.65 = movement
FOR counter = 1 TO movement
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
go_right:
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
cmDistance_right - 20 / 15.24 * 40.65 = movement
FOR counter = 1 TO movement
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
(cmDistance_left - 20) / (15.24 * 40.65) = movement
and also the "Loop" command at the end of the main section. Please help, i don't know how to fix this.
variable = (figure_1 * figure_2) / figure_3
EDIT # 2
ALSO, you cannot use decimal like that, you have to use whole numbers to represent decimals.
There is a way to do it using the */ command, i think, but i dont fully understand it yet. (if anyone can clearify the */ concept for me that would be awesome!)
the way i do it is pull out my trusty TI-83 and use the FRACT command to convert a decimal to a fraction and add it to the whole number.
ex:
3.5 would be (3 + (1/2))
so, in your case, it would be:
movement = (cmDistance_left - 20) / ((15 + (6/25)) * (40 + (13/20)))
to make this concept a little more clear,
in the case of:
variable_1 = variable_2
the value held in variable_2 will always be assigned to variable_1 (this is true in all programing languages)
just remember the variable you are assigning will always be on the left of the "=" and the value or string your are assigning to it will be on the right.
and a TIP:
I personally like to enclose all my arguements for an IF statement in parenthesis. Although this is not necessary in PBASIC, (i got in the habit with C++) it also makes the code easier to read, and helps eliminate errors in the code.
Example:
IF (argument_1 < argument_2) THEN
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
ELSE
GOSUB my_sub
ENDIF
* this may seem frivilous, but as your IF's get more complex, using AND OR operators, this can make a big difference in your debugging.
EDIT
i just noticed,
IF cmDistance_left > cmDistance_center OR cmDistance_right THEN
GOSUB go_left
ELSE
cmDistance_center > cmDistance_left OR cmDistance_right THEN
GOSUB go_forward
ELSE
cmDistance_right > cmDistance_left OR cmDistance_center THEN
GOSUB go_right
ENDIF
LOOP
i believe your 1st ELSE should be an ELSEIF and your last ELSE doesn't need a statement.
example:
IF (cmDistance_left > cmDistance_center OR cmDistance_right) THEN
GOSUB go_left
ELSEIF (cmDistance_right > cmDistance_left OR cmDistance_center) THEN 'The argument has to be on the same line as the ELSEIF as if it were just an IF
GOSUB go_right
ELSE
GOSUB go_forward
ENDIF
that should work, either that or im making a fool of myself.. lol
Post Edited (Scurge) : 8/22/2008 5:11:51 PM GMT