Picaxe programming, problem with head turning and scanning.
For some time now i have been playing around with my code to get it just right, but i have hit a snag that i cant seem to fix.
If you are good at programming you will see the mistake
main:
for b1 = 80 to 175 step 5
servo 0,b1
pause 15
next b1
for b1 =175 to 80 step -5
servo 0,b1
pause 15
next b1
gosub sonarrange
if range < 30 then search
if range > 30 then drivef
goto main
This code was designed so that the robot could turn it's head while turning so that he could see object coming from both sides, but with this code he only see objects coming from the right...
I have looked at many code to fin inspiration but nothing came!!
Does anybody know how to fix this?
The three main measurements angles are 80, 125 and 175.
Update
Here is the entire code, might make things simpler
symbol trig = 3
symbol echo = 6
symbol range = w1
main:
for b1 = 80 to 175 step 5
servo 0,b1
pause 15
next b1
for b1 =175 to 80 step -5
servo 0,b1
pause 15
next b1
gosub sonarrange
if range < 30 then search
if range > 30 then drivef
goto main
search:
gosub totalstop
gosub lookstrait
if b3<40 then
goto landr
else
goto drivef
end if
goto main
landr:
gosub lookleft
gosub lookright
if b1<25 or b2<25 then
goto wtf
else
goto itisoktoscan
end if
goto main
itisoktoscan:
if b1>b2 then bodyturnleft
if b1<b2 then bodyturnright
goto main
wtf:
gosub goback
gosub totalstop
if b1>b2 then bodyturnleft
if b1<b2 then bodyturnright
goto main
lookleft:
servo 0,175
pause 1000
gosub sonarrange
b1=range
return
lookright:
servo 0,75
pause 1000
gosub sonarrange
b2=range
return
lookstrait:
pause 100
servo 0,125
pause 1000
gosub sonarrange
b3=range
return
' this is what you will need to change to suit your robot
drivef:
high 7 : high 5 : low 4 : low 6
goto main
goback:
high 6 : high 4 : low 5 : low 7
return
totalstop:
low 4 : low 5 : low 6 : low 7
Servo 0,125
return
bodyturnleft:
gosub totalstop
low 4 : high 5 : low 6 : low 7
pause 400
gosub totalstop
goto main
bodyturnright:
gosub totalstop
low 5 : high 7 : low 4 : low 6
pause 400
gosub totalstop
goto main
' this is what you will need to change to suit your robot
sonarrange:
pulsout trig,2
pulsin echo,1,range
pause 10
let range = range * 10 / 58
return