Page 51 - Designing Autonomous Mobile Robots : Inside the Mindo f an Intellegent Machine
P. 51
Chapter 3
encoder interrupts is much greater than the length of time required for the interrupt
procedure to execute, one might think there could be no risk of an interrupt overrun.
Wrong!
What if this encoder service routine itself gets interrupted by an interrupt with a
longer service cycle? If this is allowed to happen, then the encoder service routine
may not complete its calculations before another interrupt comes in from the en-
coder. Since the interrupt is masked, it will miss this encoder tick. Such an error
may be so small that it is never noticed overtly, but the dead-reckoning of the robot
will be significantly degraded.
For this reason, all interrupt controllers offer a way of setting interrupt priority. An
interrupt of a higher priority can interrupt an interrupt handler (or its thread) of
lower priority, but the lower priority interrupt will be automatically held off while any
higher priority interrupt is being serviced. In such a case the lower priority interrupt
will set a latch, so that it will be serviced when all higher priority interrupts have
been serviced.
Many errors that occur in real-time systems are subtle in their symptoms. The best protec-
tion against them is the forethought of the programmer.
Inter-task communications
The second potential problem with our dead-reckoning interrupt procedure origi-
nates from the way we save our results. For example, the dead-reckoning routine will
be calculating both X and Y coordinates and possibly Azimuth. If it saves one of
these and is interrupted before it can save the others, then an interrupting thread
that consumes this data may pick up a garbled set of coordinates. Similarly, if a
consumer of these coordinates has read the X value and is about to read the Y value
when the encoder interrupt occurs, it may end up with a mismatched set.
This sort of problem can be even more severe if a routine must store more than one
byte or word, all of which represent a single value. Partial storage in such cases can
cause very large errors because of the nature of binary data storage. To avoid these
problems, the programmer may get the entire set of results prepared in local storage,
then hold off all interrupts for the few cycles that it takes to store the complete set.
Here the power of the object-oriented concepts of the previous chapter play into the
concepts of multitasking. If we build a dead-reckoning object, then we can force other
tasks to call its methods to get things like the latest position estimate and we can
34

