As not many people will know, most of my christmas presents and time has been used to learn about programming in basic picaxe. This is because my school is entred into a competition run by toyota and rapid to build an obstacle avoiding robot. The PCB is supplied (but sadly i have no diagram which i will explain) and we essentially have to write a program and build it.
http://www.rapidonline.com/toyota/rules ... hicle.html Thats a link to the website
I just wanted any basic know it alls to give a simple check over of my program, as i am not really sure if it works
![Razz :P](./images/smilies/icon_razz.gif)
Just so you know, ~ means that there will be a pin number but since i dont know it yet as i dont have the pcb diagram it is substituted.
The basic jist of the robot is that it will move forwards, repeatedly pinging the sonar array and whenever it sees anything within a defined range (on this, for example 15 cm) it stops, moves the sonar array to see either side and where there is more space, and then moves into it. And just to make it that little bit more complicated our group has decided to make it omni directional.
![Smile :)](./images/smilies/icon_e_smile.gif)
'Toyota Challenge Program JHGS space invaders V2
'Alasdair Hutchinson
#picaxe 18m
symbol trig = ~ 'Define output pin for Trigger on sonar
symbol echo = ~ 'Define input pin for Echo on sonar
symbol range = w1 'range in cm defined from ping
symbol front_left = w2 'distance in cm to object to the front-left
symbol front_right = w3 'distance in cm to object to the front-right
main: 'main
servopos 2,150 'face sonar array forwards
gosub ping 'gosub ping
if range => 15 then 'if nothing ahead within 15
gosub nodanger 'gosub nodanger
else 'otherwise
gosub somethingthere 'gosub somethingthere
end if 'end if
goto main 'goto main
whichway: 'whichway subroutine
servopos 2,150 'face sonar array forwards
if front_left > front_right then 'if the space to the left is greater
gosub straferight 'go to the straferight sub
end if 'end if
if front_right > front_left then 'if the space to the right is greater
gosub strafeleft 'go to the strafeleft sub
end if 'end if
return 'return
ping: 'ping subroutine
pulsout trig,2 'produce 20uS trigger pulse
pulsin echo,1,range 'measures the range
pause 10 'pause 10 ms
let range = range * 10 / 58 'converts range to cm
return 'return
somethingthere: 'somthingthere subroutine
gosub ping 'gosub ping
if distance > 15 then return 'this is a range re-check
endif 'end if
gosub allstop 'gosub allstop
gosub look_left 'look left
pause (insert time for servo to move)'wait for the servo to be finished turning
gosub ping 'gosub ping
let front_left = range 'change front left variable to be range
gosub look_right 'look right
pause (insert time for servo to move)'wait for the servo to be finished turning
gosub ping 'gosub ping
let front_right = range 'change front right variable to be range
gosub whichway 'gosub whichway
return 'return
allstop: 'allstop subroutine
Halt A, Halt B 'stop the motors
servopos 2,150 'face sonar array forward
pause 600 'stop for a 600ms
return 'return
look_right: 'look_right subroutine
servopos 2, 215 'rotate servo far right
return 'return
look_left: 'look_left subroutine
servopos 2, 85 'rotate servo far left
return 'return
straferight: 'straferight subroutine
forward hmotor
forward B 'make the horizontal movement motor high
halt A 'make the vertical movement motor low
do until range > 15
gosub ping 'ping subroutine
exit do '
gosub allstop '
goto main 'goto main
strafeleft: 'strafeleft subroutine
backward B 'make the horizontal movement motor backward
halt A 'make the vertical movement motor low
do until range > 15
gosub ping 'ping subroutine
exit do ' '
gosub allstop '
goto main 'goto main
nodanger: 'nodanger subroutine
forward A 'make the vertical movement motor forward
halt B 'make the horizontal movement motor stop
return 'return
And the last thing, I need to make a subroutine and check for if it gets stuck in a u bend, so that it reverses then strafes a certain way, but that is not done yet. Any ideas?