RCX Programming


Lesson 4

In this lesson we present a program for a small LEGO car that does random walk with obstacle avoidance. The car has four bumpers, one on the left side, one on the right side and two front bumpers. When the car bumps into an obstacle a touch sensor is pressed by the bumper. The left and right bumpers can be sensed through touch sensors on input port 1 and 3. The touch sensors of the two front bumpers are both connected to input port 2.

A simple program for the small car is (SmallCar.c).

You should design and implement a similar program but for a different car: A car based on the model of page 16 in MindStorms for Schools, 9793, 9794. Your car should have two front bumpers, as on page 33 of the building instruction and a light sensor pointing directly backward. The two touch sensors should be connected to port 1 and 3. The light sensor to port 2. When the left bumper is pressed the car should drive backwards and turn right before doing the next step of the random walk. A similar reaction should be the result of the right bumper being pressed. The light sensor should be used to detect an obstacle behind the car. The raw value from the light sensor can be used to estimate the distance to an obstacle. The car should react by going forward for a while before proceeding in the next step of the random walk.

The Small.c program has, however, several drawbacks because the program performs the steps Sense-Plan-Act sequentially: When the car is doing a single step of the random walk, the touch sensors are not sampled and it may take in the order of 400 msec to react to a touch sensor being pressed. Furthermore, when the car is trying to avoid an obstacle by going backwards or turning away, it may take as long as 2 sec before the program can react to a touch sensor being pressed. Try to make the program react faster when a touch sensor is pressed by sampling the touch sensors more often. Try to figure out how the car should react when a touch sensor is pressed in the middle of going backwards or turning away.


Access to the other include and source files.
Last update: 26-02-06