Simple Interface for Start Here Bot
I got frustrated with the robot starting to run away from me as soon as I put in the batteries so I have slightly modded the code in these instructions to create a simple interface. The robot now starts in a stationary mode when you put in the batteries and doesnât start moving until you wave in front of the sensor. If you put your hands around the sensor when the robot is moving and hold it there for about 10 seconds the robot will then stop. I have never used Picaxe Basic before so this isnât very elegant but it seems to work. Thanks and I hope this is useful to folks. Also, I would love to get suggestions from more experienced folks on how to improve the code. Â
Symbol dangerlevel = 70 â how far away should thing be, before we react?
Â
symbol turn = 300 â this sets how much should be turned
symbol servo_turn = 700 â This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance
w4 = 0 'this variable will be used to check if the robot has been activated
Â
main: â the main loop
if w4 = 0 then
gosub checkstart âthis is a new function to check if the robot has been activated
endif
Â
readadc 0, b1 â read how much distance ahead
if b1 < dangerlevel then
gosub nodanger â if nothing ahead, drive forward
elseÂ
gosub whichway â if obstacle ahead then decide which way is better
end if
goto main â this ends the loop, the rest are only sub-routines
Â
checkstart:
readadc 0, b1 â read how much distance ahead
if b1 < dangerlevel then
wait 1
goto checkstartÂ
else
w4 = 1
wait 1
goto nodanger
goto nodanger
return
end if
nodanger:â this should be your combination to make the robot drive forward, these you most likely need to adjust to fit the way you have wired your robots motors
high 5 : high 7 : low 4 : low 6
return
Â
Â
whichway:
gosub totalhalt â first stop!
Â
'Look one way:
gosub lturn â look to one side
pause servo_turn â wait for the servo to be finished turning
readadc 0, b1
gosub totalhalt
Â
Â
'Look the other way:
gosub rturn â look to another side
pause servo_turn â wait for the servo to be finished turning
readadc 0, b2
gosub totalhalt
Â
â Decide which is the better way:
if b1 > dangerlevel and b2 > dangerlevel thenÂ
gosub totalhalt
w4 = 0
else if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return
Â
body_lturn:
high 4 : low 6 : low 5 : high 7 â this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return
Â
body_rturn:
high 6: low 4 : low 7 : high 5 â this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return
Â
rturn:
servo 0, 100 â look to one side
return
Â
lturn:
servo 0, 200 â look to the other side
return
Â
totalhalt:
low 4 : low 5 : low 6 : low 7 â low on all 4 halts the robot!
Servo 0,150 â face forward
wait 1 â freeze all for one second
return
Â
Â
Â
Â
Â