In order for a robot to negotiate its environment independently, it must be able to both see and avoid obstacles in its path. If you tried out the S3 demo modes, you may remember that in Demo 3 your robot could detect objects with its infrared (IR) sensors and in Demo 4 your robot could detect (with its IR sensors) and avoid obstacles as it roamed around. Robots can be built or programmed to detect objects in a number of different ways, and with a variety of different sensors.
Infrared Emitters and Receivers as Obstacle Sensors - A common solution for obstacle detection in robotics is the use of Infrared (IR) Emitters and Receivers, which are mounted in the front of your robot. These special LEDs emit non-visble infrared light, similar to that of a television remote control. These emitters, paired with a single infrared receiver, make up the obstacle sensors on your S3.
The above image shows the front of your S3. You may notice that your left and right sides are opposite from the labels on the robot. This is because the robot is facing the opposite direction from you – if you turn 180 degrees around, away from the computer screen, you should notice that now your right and left match the robot's right and left sides. Direction is always determined from the robot's perspective, not yours. If you keep in mind that the IR emitters and receiver are always facing forward on your robot, you shouldn't have any problems creating navigation programs with forward, backward, right, and left direction commands.
The emitters send alternating pulses of infrared light which are reflected back to the receiver only after hitting an obstacle. Since only one LED flashes at a time, your S3 can figure out which LED was emitting light when the receiver detected a reflection. It will use this information to decide on which side the obstacle lies. If the object is directly in front, then the light from both LEDs will reflect to the receiver when they flash.
Every robot sensor has advantages and disadvantages, with each having certain physics limitations. How it is positioned on your robot can also have an effect on its performance. Infrared does not effectively see black objects because they absorb the infrared light instead of reflecting it back to the receiver. The infrared object sensing system on the S3 works best when objects are not too dark in color, and are located between 1” and 12” from the front of the robot.
We can create a program in BlocklyProp that demonstrates behavior similar to the Demo 3 program (obstacle detection without roaming).
The loop command makes the program run continuously. If an obstacle is not detected, all LEDs will appear green. If an obstacle is directly in front of the S3, all the LEDs will appear red. Obstacles to the left are indicated by a single red LED on the left side, and an obstacle on the right is indicated by a single red LED on the right side.
It should be fairly easy now to modify either of the programs above into an obstacle avoidance program. Can you see how?
Special thanks to Parallax friend Whit Stodghill for his assistance in writing, editing, and testing material for these S3 tutorials.