The Sensors sub-team draws from both software and electrical students and is responsible for giving the robot the ability to sense its environment. Students on this team learn how to mount sensors on the robot, connect them to the control system, read environmental data from them, and provide that data to higher level software. For example, using a laser rangefinder to determine distance to an object or an optical encoder to determine the position of a mechanical arm.
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:
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.
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.
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).
Inexpensive HC-SR04 ultrasonic sensors are helpful for learning about sensors and making basic robots more interactive. Every team should have a box of sensors and cables ready to connect to a roboRIO. The sensors are cheap and plentiful; the main obstacle is usually cabling and although students can crimp nice new cables with locking connectors, for many purposes, it is quicker and easier to make cables using off-the-shelf materials; it takes only a few minutes to wire them as needed and this is something rookie students can do without special training and minimal supervision to get comfortable with wiring. It also avoids most of the hassle associated with poor crimps.
Materials Needed:
One 4-pin female-to-female dupont jumper wires (cost: $0.38 - $1.20)
Two 3-pin female dupont shell/housings (less than $0.02 each or from an amazon/US supplier)
Everything is available from Amazon, AliExpress, Gearbest, Banggood, etc. depending on how fast you need it. Instructions for students:
Using sharp tweezers or the tip of a pointy knife or small screwdriver, remove the two black plastic shell/housings from the 4-wire cable: slightly lift the black tabs that retain each wire in the connector and slide the wires out so you're left with a 4-wire bundle and two 4-pin shells. Watch this video to see how it's done.
Reinsert the wires from one end of the 4-wire bundle into one of the 4-pin shells in this order: Red(Vcc), White(Trig), Yellow(Echo), Black(Gnd).
Reinsert 3 of the 4 wires on the other end of the bundle into a 3-pin shell in this order: Black (Gnd), Red (5v), Yellow (S) and label it A
Reinsert the last wire into one end of another 3-pin shell: White (S), Empty, Empty and label it B
You can discard or save the left-over 4-pin shell housing.
Use the new cable to connect the ultrasonic sensor to the RoboRIO as follows:
Plug the 4-pin connector into the HC-SR04 with the Red wire on the Vcc pin and the Black wire on the Gnd pin - this is important because the sensor will be destroyed if you connect it backwards.
Plug connector A into one of the DIO ports (let's say DIO 0) with the black wire on the OUTSIDE edge of the roboRIO
Plug connector B into another DIO port (let's say DIO 1) with the white wire towards the INSIDE edge of the roboRIO
You can use the ultrasonic sensor in your programs by creating an Ultrasonic object. WPILib already provides an Ultrasonic class that makes things easy. A sample snippet is below:
import edu.wpi.first.wpilibj.Ultrasonic;
public class Robot extends IterativeRobot {
private Ultrasonic ultrasonic;
@Override
public void robotInit() {
ultrasonic = new Ultrasonic(1,0); // trig, echo
ultrasonic.setAutomaticMode(true);
ultrasonic.setEnabled(true);
}
@Override
public void teleopPeriodic() {
double range = ultrasonic.getRangeInches();
// do something with the range
}
}
Students should first get comfortable using the sensor and displaying the range readings on the console, a good next exercise is to add collision avoidance to a robot.
Mounting solutions
Acrylic mounts from amazon
Printable models from thingverse
Inexpensive HC-SR04 ultrasonic sensors are helpful for learning about sensors and making basic robots more interactive. Every team should have a box of sensors and cables ready to connect to a roboRIO. The sensors are cheap and plentiful; the main obstacle is usually cabling and although students can crimp nice new cables with locking connectors, for many purposes, it is quicker and easier to make cables using off-the-shelf materials; it takes only a few minutes to wire them as needed and this is something rookie students can do without special training and minimal supervision to get comfortable with wiring. It also avoids most of the hassle associated with poor crimps.
Materials Needed:
One 4-pin female-to-female dupont jumper wires (cost: $0.38 - $1.20)
Two 3-pin female dupont shell/housings (less than $0.02 each or from an amazon/US supplier)
Everything is available from Amazon, AliExpress, Gearbest, Banggood, etc. depending on how fast you need it. Instructions for students:
Using sharp tweezers or the tip of a pointy knife or small screwdriver, remove the two black plastic shell/housings from the 4-wire cable: slightly lift the black tabs that retain each wire in the connector and slide the wires out so you're left with a 4-wire bundle and two 4-pin shells. Watch this video to see how it's done.
Reinsert the wires from one end of the 4-wire bundle into one of the 4-pin shells in this order: Red(Vcc), White(Trig), Yellow(Echo), Black(Gnd).
Reinsert 3 of the 4 wires on the other end of the bundle into a 3-pin shell in this order: Black (Gnd), Red (5v), Yellow (S) and label it A
Reinsert the last wire into one end of another 3-pin shell: White (S), Empty, Empty and label it B
You can discard or save the left-over 4-pin shell housing.
Use the new cable to connect the ultrasonic sensor to the RoboRIO as follows:
Plug the 4-pin connector into the HC-SR04 with the Red wire on the Vcc pin and the Black wire on the Gnd pin - this is important because the sensor will be destroyed if you connect it backwards.
Plug connector A into one of the DIO ports (let's say DIO 0) with the black wire on the OUTSIDE edge of the roboRIO
Plug connector B into another DIO port (let's say DIO 1) with the white wire towards the INSIDE edge of the roboRIO
You can use the ultrasonic sensor in your programs by creating an Ultrasonic object. WPILib already provides an Ultrasonic class that makes things easy. A sample snippet is below:
import edu.wpi.first.wpilibj.Ultrasonic;
public class Robot extends IterativeRobot {
private Ultrasonic ultrasonic;
@Override
public void robotInit() {
ultrasonic = new Ultrasonic(1,0); // trig, echo
ultrasonic.setAutomaticMode(true);
ultrasonic.setEnabled(true);
}
@Override
public void teleopPeriodic() {
double range = ultrasonic.getRangeInches();
// do something with the range
}
}
Students should first get comfortable using the sensor and displaying the range readings on the console, a good next exercise is to add collision avoidance to a robot.
Mounting solutions
Acrylic mounts from amazon
Printable models from thingverse
Using sensors effectively allows the robot to understand itself and the world around it and is critical for building effective robots. See: overview from team 1678
Software architecture
Understanding sensors
Application (App) Notes?
Interfacing with sensors
Digital GPIO on the Raspberry Pi
SPI
Asynch Serial
RS485
CAN bus and more info
Ethernet
Closed Loop Control
Mounting sensors
3D printing
McGyvering?
Scanning LIDAR
see: XV11 LIDAR and mount
and: Sweep LIDAR
Note: FRC lasers must be class 1
Improved machine vision system
Refine current Pi-based vision