Lesson 30: Hardware Fail Detection
Hardware fail detection means writing code that notices when something is probably wrong. It will not replace inspection and maintenance, but it can help drivers and pit crew react faster.
What Can Fail?
- A sensor can unplug or return impossible values.
- A motor can be commanded but not move.
- An encoder can stop counting.
- A mechanism can hit a hard stop before the code expects it.
- Pneumatics can lose pressure or fail to move a cylinder.
Detect Impossible Values
If an arm angle should always be between 0 and 180 degrees, values outside that range probably mean a sensor problem.
double angle = armPot.get();
boolean sensorOk = angle >= 0.0 && angle <= 180.0;
if (!sensorOk) {
armMotor.set(0.0);
}Detect No Movement
If a motor is commanded for a long time but the encoder does not change, stop and report a fault.
if (Math.abs(motorCommand) > 0.4 && Math.abs(encoderRate) < 0.1) {
driveFault = true;
}Report Clearly
A hidden fault does not help the team. Show faults on a dashboard, LEDs, or driver station output. Use plain names like "left encoder not moving" instead of "fault 4."
Practice
Choose one mechanism and write three checks: one impossible sensor value, one timeout, and one "commanded but not moving" condition.