What is wrong with my code?!

i dont know what's wrong with my code!

i made a simple code that should make my robot simply avoid walls, stuff etc.

i placed SC-QR-1 (my robot's name) upside-down and pressed [F5] (the "run" shortcut) and watched him move his cute little robot legs.. WTF?

the new code seemed to work untill the walk part was over and he started to turn.. ..left. and then again left and again and again.. etc.

he is suposed to keep walking!!!

short version: when i turn him on he does the "walking" part and goes into a loop with the "turn_left" part

i dont know whats wrong! you see.. he is laying upside down! the distance to the wall he is faceing is allways +2,5 meters!!!

i use the srf05 and its hooked up like this

the srf05 works! that is not the problem!

i also made a new code with the same idea

here is the new code:

***********************************

symbol trig = 3
symbol echo = 6
symbol range = w1

pause 3000

main:
gosub find_range
if range > 150 then
gosub walking
else
gosub turn_left
end if
pause 100
low 3
goto main

find_range:
low 3
pulsout trig,2
pulsin echo,1,range
pause 10
return

turn_left:
low 3
servo 0, 35 ' servo 0 to 5/5
servo 2, 120 ' servo 2 to 3/5
servo 4, 120 ' servo 4 to 3/5
servo 6, 35 ' servo 6 to 5/5
pause 100
servo 1, 35 ' servo 1 short leg
pause 100
servo 0, 80 ' servo 0 to 4/5
pause 100
servo 1, 100 ' servo 1 normal leg
pause 200
servo 3, 220 ' servo 3 short leg
pause 200
servo 2, 180 ' servo 2 to 4/5
pause 200
servo 3, 120 ' servo 3 normal leg
pause 200
servo 7, 20 ' servo 7 short leg
pause 100
servo 6, 70 ' servo 6 to 4/5
pause 100
servo 7, 100 ' servo 7 normal leg
pause 200
servo 5, 215 ' servo 5 short leg
pause 100
servo 4, 170 ' servo 4 to 4/5
pause 100
servo 5, 120 ' servo 5 normal leg
pause 500
return

walking:
servo 1, 35 ' servo 1 short leg
servo 3, 120 ' servo 3 normal leg
servo 5, 120 ' servo 5 normal leg
servo 7, 20 ' servo 7 short leg
pause 200
servo 0, 80 ' servo 0 to 4/5
servo 2, 80 ' servo 2 to 2/5
servo 4, 170 ' servo 4 to 4/5
servo 6, 170 ' servo 6 to 2/5
pause 400
servo 1, 100 ' servo 1 normal leg
servo 3, 220 ' servo 3 short leg
servo 5, 215 ' servo 5 short leg
servo 7, 100 ' servo 7 normal leg
pause 200
servo 0, 170 ' servo 0 to 2/5
servo 2, 180 ' servo 2 to 4/5
servo 4, 80 ' servo 4 to 2/5
servo 6, 70 ' servo 6 to 4/5
pause 400
return

***********************************

and i even tryed a code like this:

****************************

main:
gosub find_range
if range > 150 then
gosub walking
end if
gosub find_range
if range < 150 then
gosub turn_left
end if
pause 100
low 3
goto main

(and all teh sub menys)

*************************************

but then it got TOTALLY wired!

here is the link to my robot project: SC-QR-1

please help me!!!

EDIT: if fixed it.. =D

debug?

The code looks right; maybe there’s something wrong with your sensor. Try laying it on it’s back and measuring while plugged into your computer …

Also, I don’t think it would be the problem, but you don’t need the “low 3” commands. The pulseout to the sonar stops after 20ms already.

Good luck! Love the bot by the way. We need a turorial on multiple servo legs.

lots of servos and the srf05
can cause issues because of the server pulses. Try taking out the sensor code and see if it works.

also

what I did was put my pulse code for the SRF05 in its own sub. Then just called it in my main. Maybe try putting all your code in subs then

call them in main.

ohh… the sensor

ohh… the sensor works

i have used the debug thingy lots of times!

my srf05 works fine =D

good idea!i’m going to try

good idea!

i’m going to try that!

=D