Product Introduction

9. Safety Timeouts
Action loops need safety timeouts. Repeat that to yourself five times. Your program
must deal with an autonomous robot getting stuck in a loop, for whatever reason. Start a
system timer when entering the loop, then monitor it and take action when needed.
One method is simply to add ‘time’ to the loop conditional. If the time limit is reached, the
loop exits normally and the program continues. Here is an outline in pseudocode:
Another method is to check the timer inside the loop, and take actions such as setting a
timeout flag (boolean variable) and/or immediately exit the loop (break command in Java).
The flag can be used after the loop to take further action if desired.
More purposeful methods are possible too, such as: take a corrective action (still within the
loop), reset the timer, increment a counter, then continue the loop.
10. Reaching the Target
For spin moves and some other maneuvers, proportional steering can sometimes fail to
achieve the full desired target heading. Why? As the error gets smaller and smaller, so
do the power levels. At some point the robot may be unable to move further; the code is
“stuck” in the loop.
This can be addressed by adjusting the minimum power levels, although this may risk
overshooting the target. Or, if testing shows the robot gets stuck consistently short of the
target, you could use a purposely higher target. When the loop “times out”, the robot
heading is known.
Low closing power is a characteristic of “P-only” control. Various improvements are
offered by proportional-integral (PI) and proportional-integral-derivative (PID) controls, but
they are outside the scope of this introduction.