Distance Sensors and Current Sensing
Measuring how far away something is, and using motor current as a sensor in its own right.
Sign in to track progress, earn XP, and save lessons.
Beyond yes/no switches, two analog quantities are extremely useful: distance and electrical current.
Distance sensors
FRC teams most often use time-of-flight (ToF) laser sensors, which fire an invisible Class 1 laser and time the reflection to measure absolute distance fairly independently of target color or reflectance.
- The REV 2m Distance Sensor (part REV-31-1505) is based on the ST VL53L0X ToF module. It reports distance over I2C (address 0x52) with a measurement range of roughly 5 cm to 200 cm (2 m) at millimeter resolution. It ships with a 4-pin JST-PH cable.
- The Playing With Fusion Time-of-Flight sensor (SEN-36005) is built on the newer ST VL53L1X and communicates over the CAN bus (1 Mbit). It supports up to 254 configurable CAN IDs so you can chain several on one bus, and ranges about 1.4 m in short mode and up to ~4 m in long mode depending on lighting.
Uses include detecting how far a robot is from a wall before scoring, sensing a game piece inside a mechanism, or measuring elevator height as a sanity check against the encoder.
Key limitation: ToF sensors have a measurement cone and a maximum sample rate that drops with ambient light, so they are best for short, well-defined gaps, not long open-field ranging.
Current sensing
Every channel on the REV Power Distribution Hub (PDH) and the older CTRE Power Distribution Panel (PDP) measures the current flowing through it, reported over CAN via WPILib's PowerDistribution class. Modern smart motor controllers (Talon FX, Spark MAX/Flex) also report their motor output current over CAN.
Why current is a sensor:
- Stall / contact detection: When an intake grabs a game piece or an arm hits a hard stop, current spikes. You can detect a successful intake by watching for a current threshold instead of adding a beam break.
- Brownout protection: Watching total current helps you stay under the limits that cause the roboRIO to brown out and reset.
- Mechanism health: Abnormally high steady-state current can warn of a jam or binding.
PowerDistribution pdh = new PowerDistribution(1, ModuleType.kRev);
double intakeAmps = pdh.getCurrent(5); // channel 5
if (intakeAmps > 30.0) { /* probably have a game piece */ }
Current-based detection is cheap (no extra hardware) but noisy, so filter it (a moving average or WPILib LinearFilter) and require the threshold to persist for several loops before acting.
Key takeaways
- Time-of-flight sensors give absolute distance: the REV 2m sensor (VL53L0X, I2C, ~2 m) and the Playing With Fusion SEN-36005 (VL53L1X, CAN, ~1.4 m short / ~4 m long).
- The REV PDH and CTRE PDP report per-channel current over CAN; smart motor controllers report motor current.
- Motor current spikes can detect intakes, stalls, and jams without extra sensors — but filter it before acting.
Go deeper
Lesson quiz
RequiredAnswer all 3 questions correctly to complete this lesson.
1.An analog ultrasonic rangefinder outputs a voltage proportional to the measured distance. What must a team do to use its readings in robot code?
2.By default, what value does the roboRIO's FPGA return for an analog input reading a 0-5V sensor?
3.How can a team measure the current drawn by an individual motor channel on a REV PDH or CTRE PDP?
Answer every question to submit.