First Robot Wall Racer
I could not figure out how to do the real wall racer yet so I will try this version. I will attemp the real wall racer when I have more free time. Basically is the same as the first robot but I have to modified the code so that the back motor always drive forward and the front motor to turn right and left.
I think I have to play around with the high and low to make the motor turn in the right direction.
Symbol dangerlevel = 35' how far away should thing be, before we react?
symbol turn = 500 ' this sets how much should be turned
symbol servo_turn = 120 ' 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 1, 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 7 : low 6
low 4: low 5
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
gosub totalhalt
readadc 1, b1
'Look the other way:
gosub rturn ' look to another side
pause servo_turn ' wait for the servo to be finished turning
gosub totalhalt
readadc 1, b2
' Decide which is the better way:
if b1<b2 then
gosub body_lturn
else
gosub body_rturn
end if
return
body_lturn:
low 7: high 6
high 5 : low 4' this should be your combination that turns the robot one wayreturn
body_rturn:
low 7: high 6
low 5 : high 4' this should be your combination that turns the robot the other way
return
rturn:
servo 0, 110' look to one side
return
lturn:
servo 0, 200 ' look to the other side
return
totalhalt:
Servo 0,150 ' face forward
pause 50 ' freeze all for one second
return
Race fast and Avoiding Obstacle.
- Actuators / output devices: RC motors
- Control method: autonomously controlled by onboard microcontroller
- CPU: Picaxe 28x1
- Power source: 4-AA
- Programming language: Picaxe basic
- Sensors / input devices: SHARP IR sensor
- Target environment: indoor