Timeout logic ensures that your robot stops moving if it stops receiving valid commands from the controller. This is critical for preventing runaways caused by communication loss or controller failures.
- Wireless links can drop unexpectedly
- Controllers can crash or freeze
- Software can fail to update motor commands
Without timeout logic, a robot may continue executing its last command, potentially causing collisions, injuries, or damage.
- Keep track of when the last valid command was received from the controller
- Define a timeout threshold (e.g., 100–500 ms)
- If the threshold is exceeded, disable motors and enter a safe state
Example:
if (timeSinceLastControllerCommand > 200) { // milliseconds
disableMotors(); // stop the robot safely
}
To prevent “stale” or repeated commands from bypassing safety:
- Include a sequence number or freshness counter in each controller packet
- Only accept commands with a higher counter than the last received
- If no new commands arrive within the timeout, disable motors
Benefits:
- Prevents the robot from continuing a repeated stale command
- Ensures robot motion always reflects recent operator input