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.
Car program with front obsticle avoidence.
-- Clear the screen
print "Program Start"
-- Reset the buttons
-- USER LED off
-- Set sensor on pin a1 to call front_hit task if we collide.
btp a1 front_hit
-- Start moving at half speed
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
-- Go backwards for 2 secs
-- Turn left
-- go forwards
-- USER off