This is the basic program for a car with an infrared obsticle detection sensor mounted at the front. The sensor is the Infrared Proximity Obstacle Avoidance Sensor 2cm to 30cm which sends an infrared beam out the front and if this hits something it reflects back and is detected. This alerts the program to the fact there is an obstacle in the way of the Robot.
in this case the front_hit task is called.
When it detects an obsticle at the front it will stop, go back a little, turn and then move forwards again. It will keep on doing this until it gets out of the obsticles way.
Program
---
Car program with front obsticle avoidence.
---
prog_vars =
d/count 0
prog_vars.
prog_start =
-- Clear the screen
pclear
print "Program Start"
-- Reset the buttons
rstb
-- USER LED off
l1 0
-- Set sensor on pin a1 to call front_hit task if we collide.
btp a1 front_hit
-- Start moving at half speed
bms 50
prog_start.
prog_loop =
inc /count
prog_loop.
front_hit =
---
If the front sensor is triggered we need to stop, go back
for a bit and then turn, so we don't hit the same thing again.
Fianlly move forward again.
---
-- USER on
l1 1
-- Go backwards for 2 secs
bms -50
dly 2000
-- Turn left
turn -50
dly 2000
-- go forwards
bms 50
-- USER off
l1 0
front_hit.
prog_stop =
print "Bye"
stop
prog_stop.