Page 191 - The Unofficial Guide to Lego Mindstorms Robots
P. 191
180
Figure 9-1.
Cruise, a simple robot behavior
over control of the robot. Figure 9-2 shows a diagram with both t he cruise and avoid behaviors. The circle with an ''S"
indicates that the avoid behavior can take control of the motors from the cruise behavi or.
Figure 9-2.
The avoid behavior takes control of the robot when the bumper is pressed
There won't always be a one-to-one relationship between inputs and behaviors. It's entirely possible that one behavior will be
triggered by some combination of inputs. Likewise, a single input might trigger multiple behaviors, depending on the input's
value.
Implementation
It's fairly easy to implement subsumption architecture on a system that includes preemptive multitasking. As you'll recall, the
R CX's default firmware supports this featur e. Our implementation of subsumption architecture is written in NQC.
Th e basic idea is that each beh avior is a separate task. The behaviors all run simultaneously, trying to control the robot
ac cording to their own rules. O ne additional task decides which behavior is in charge and then sends its commands to the
motors.
Ro boTag behaviors
The robots in RoboTag actually need four different beha viors, shown in Figure 9-3. The basic cruise behavior is the same
as before—it moves the robot forward. If one robot coll ides with the other robot, the bumper is pressed. This causes the tag
behavior to take control of the robot. If the robot drives over the edge of t he playing field, the reading from the light sensor
c auses the avoid behavior to assert itself. Finally, the top level behavi or is tagged. This behavior is triggered if the robot
has been tagged by the other robot.