In the code supplied by
In the code supplied by Frits (start here robot) you have to sections, 1 where it makes the actual turn and 1 where it turns it head. Mine drives the head lights on (no danger) and blinks when taking a turn. It flashes the lights before it starts (to give me some time and unhook it from the cable). Leds are on 2 and 3. Looks like this;
high 2 : high 3
wait 4
Servo 0,150 : Servo 1, 150
low 2 : low 3
wait 1
high 2 : high 3
wait 1
low 2 : low 3
wait 1
high 2 : high 3
wait 1
low 2 : low 3
wait 1
high 2 : high 3
wait 1
low 2 : low 3
Symbol dangerlevel = 90 ’ how far away should thing be, before we react?
symbol turn = 400 ’ this sets how much should be turned
symbol servo_turn = 500 ’ This sets for how long time we should wait for the servo to turn (depending on it´s speed) before we measure distance
main: ’ the main loop
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
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 4 : low 5 : high 6 : low 7 : high 2 : high 3
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<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return
body_lturn:
low 4 : high 5 : high 6 : low 7 ’ this should be your combination that turns the robot one way
pause turn : gosub totalhalt
return
body_rturn:
high 4 : low 5 : low 6 : high 7 ’ this should be your combination that turns the robot the other way
pause turn : gosub totalhalt
return
rturn:
servopos 0, 105 : servopos 1, 195
wait 1
low 3
return
lturn:
servopos 0, 195 : servopos 1, 105
wait 1
low 2
return
totalhalt:
low 4 : low 5 : low 6 : low 7 ’ low on all 4 halts the robot!
Servopos 0,150 : Servopos 1, 150
wait 1 ’ freeze all for one second
return