Sensors allow the robot to understand its environment so it can interact with it successfully. For example, a robotic arm controller needs to know when it has reached the limit of its movement; otherwise, if it keeps supplying power, it will burn out the motor or damage the arm. Examples of commonly used sensors are:
Limit Switches
Mechanical or optical switches can be used to determine when a mechanism has reached its limit of movement.
- Mechanical switches work like light switches on a wall;
two or more brass electrical contacts can be connected and disconnected by an internal brass bar. A cut-away view shows a limit switch whose top electrical contact will connect to either the bottom right or top right contact depending on whether the switch is pressed or not.
Exercise: Use a multimeter to test the continuity (conductivity) between the contacts on a mechanical limit switch. Press the switch and observe how the continuity changes.
Note: Using mechanical switches can be complex. When a switch contact closes or springs open, it actually bounces several times before making a secure connection. Although this happens fast, usually 10-50ms, that's a long time for a computer and the computer will see the switch close-open-close-open-close-open... Software needs to take special measures to debounce mechanical switches.
- Optical switches work like the safety on your garage door: a beam of light (often invisible), is emitted from a source and a light detector conducts or doesn't conduct based on whether it sees the beam of light.
Some optical switches (like your garage sensor) operate on the principle of something breaking the beam and are called opto-interrupters or just beam-break sensors. Other optical switches look for a beam of light bouncing off a nearby object; these are called opto-reflectors or proximity sensors.
An obvious advantage of optical sensors is that no contact is required. An arm slamming into a mechanical switch can easily break it, but if the arm passes through and blocks a beam of light, there is no risk of mechanical damage.
Rotary Encoders
Opto-interrupters are commonly used to track the rotation of a shaft to monitor and report (encode) its position or count its rotations. In an optical encoder uses a disk attached to the rotating shaft with slots cut out. The disk rotates between the light emitter and detector of an opto-interrupter, alternately passing the light beam through the slot and then blocking the beam between slots.
A tiny optical encoder can have 360 or more slots cut in the rotating disk allowing a beam-break to occur for every 1-degree of rotation of the shaft.
Attaching a rotary encoder to a wheel's axle allows the robot controller to determine whether the wheel is turning or slipping, how fast the wheel is turning, and with a clever encoder arrangement called quadrature, even determine which direction the wheel is turning. Similarly, an encoder at the joint of an arm allows the controller to precisely determine the angle of the arm which is critical to controlling it.
Techniques other than optical interruption are also used for encoders including magnets and capacitance sensors, but optical encoders are most common.
Exercise: Ask a mentor to help you take apart an old-style mouse (the kind that had a heavy metal ball instead of bright lights underneath). In these mice, the ball turned two shafts (X and Y directions) that each had an optical rotary encoder attached. The mouse movement was detected by counting the interruptions of the light beam in each axis.
Distance Sensors
Robots often need to detect the distance between objects including the robot itself and a target. The most common solution is a distance sensor that emits a beam of sound or light and measures the time it takes for the echo or reflection to come back.
- Ultrasonic rangefinders
work the same way a bat finds its prey: the sensor emits an ultrasonic chirp and then listens for the echo of that chirp bouncing off the nearest surfaces. The distance to the target is
(time_to_receive_echo X speed_of_sound_in_air) / 2
Ultrasonic sensors are incredibly inexpensive and can often be purchased for under $1. However, as with other sensors, ultrasonic range-finding can be challenging; the sound chirp spreads out quickly from the sensor and will bounce off every surface (floor, ceiling, etc.) not just the target. This limits the range and reliability of the sensor. More expensive ultrasonic rangefinders emit a narrower beam. Techniques to focus the sound waves are often required for reliable operation; these can vary from a simple cardboard tube (paper dime rolls work well) to exponential horns and lensing (sound refracting) techniques.
- Light Detection and Ranging (LIDAR)
uses a low-power laser to measure distance to a target in much the same way as the ultrasonic sensor. However, unlike a sound beam that spreads out quickly from its source, a laser beam maintains a very narrow focus over long distances, reducing unwanted reflections. Of course lasers have their limitations too including transparent surfaces or surfaces that will deflect rather than reflect the beam. LIDAR is expensive too (~$150).