Behavior-based Control Aside from robotics, this is a good example of how to break a task down into smaller tasks. There are several approaches to robotic control (from bottom up): (1) Reflexive control (2) Behavior-based control (3) Hierarchical control (1) Reflexive control: You have the sensors connected more or less directly to the effectors (motors). So the robot responds reflexively to whatever it is sensing. Example: Braitenberg vehicles. (2) In BBC (behavior-based control), the overall behavior of the robot is broken down into several more or less independent behaviors. (3) Hierarchical control involves "thinking" in some form. Involves things like memory, planning, cognition, reasoning, internal representations, ... You have an overall goal, and you that break that down into subgoals, and so on. This is too expensive for many ordinary activities. On the other hand, reflexive control is not flexible enough for any but the simplest activities. Therefore BBC has developed as an intermediate between the two. For these purposes, a behavior is defined to be a tightly coupled pair of perception and action. It is tightly coupled because that perception is directly relevant to that action. Example: Consider a bird feeding. One behavior is seeing a seed and pecking at it. Another behavior is seeing a predator (e.g., a cat) and flying away. We can distinguish two kinds of perceptions (relative to behaviors): releasers and guides. A releaser releases or activates a behavior. A guide guides the resulting action. The sight of a predator might release the fleeing behavior. Perception of the environment, including the predator, would guide the resulting flight. (Where are the exits? How can we get out of reach? etc.) When restricted to a particular behavior, perception often reduces to the recognition and use of affordances. An affordance is a directly perceivable stimulus in the environment that can be used to guide a specific action. For example, if you are trying to go out the door, the door affords this action. Basically what you need to do is be able to recognize doors and doorknobs. The point is to be able to behave competently in the world without thinking about it (because thinking is too slow and expensive). In a behavior the perception and the action serve some well-defined purpose, so they go together. This is part of what makes this a good design strategy. Often behaviors can be tested independently. (This is an example of unit testing.) So if we break a robot's behavior down into simpler behaviors we have to figure out how to put them back together again. Because often, more than behavior can be released at the same time. Example: The Eating behavior might be released by food at the same time as the Fleeing behavior is released by a predator. One solution is have a hierarchy of priorities among the behaviors. For example, Fleeing is probably higher priority than Eating. Another: sometimes several behaviors can be carried on at the same time because they are mostly independent. (E.g., walking and chewing gum.) A third: sometimes actions can be blended. (E.g., braking and turning) Digression: In C++, 0 is interpreted as false, and any non-zero value is interpreted as true. For example in if-statements, and while- and for-loops. The standard truth values in C++ are the boolean values false = 0 and true = 1. bool x = true; The not operation (!) and the other boolean operations (&&, ||, ...) interpret nonzero values as true. ! 1 == 0, ! 0 == 1, .... You can do lots of tricky and "clever" programming with this information, but it will your programs hard to read and debug.