Lesson 45: Safety Patterns
Safety patterns are habits that keep mechanisms from hurting people, damaging the robot, or destroying themselves when something goes wrong.
Hard Limits and Soft Limits
A hard limit is usually a physical sensor such as a limit switch. A soft limit is a software boundary such as "do not move past 70 inches." Use both when a mechanism can damage itself.
if (topLimit.get() && requestedSpeed > 0.0) {
requestedSpeed = 0.0;
}Timeouts
If a mechanism should finish moving in two seconds, stop it after two seconds. A timeout protects the robot when a sensor unplugged or a mechanism got stuck.
Current Limits
Current limits can protect motors and wiring. They also help detect a stalled mechanism. If current is high and the encoder is not moving, something is probably wrong.
Validate Sensors
Ask whether a sensor value is believable. If an arm angle jumps from 20 degrees to 900 degrees, the safe answer is not to trust it.
Fail Safe
When the robot is confused, choose the safer action: stop the motor, hold position gently, or refuse to start the action. Make the fault visible to the drivers.
Practice
For each mechanism on your robot, write one hard limit, one soft limit, one timeout, and one fault message.