Example using one behavior per sensor
As another example of how powerful this idea of vector summation is, itis useful to consider how obstacle avoidance runaway is commonly implemented
on real robots. Fig. 4.18 shows a layout of the IR range sensors on a
Khepera robot. Since the sensors are permanently mounted on the platform,
their angle i relative to the front is known. If a sensor receives a range
reading, something is in front of that sensor. Under a repulsive field RUNAWAY,
the output vector will be 180 opposite i. The IR sensor isn’t capable
of telling that the obstacle may be a little off the sensor axis, so a reading is
treated as if an obstaclewas straight in front of that sensor and perpendicular
to it.
If this sensor were the only sensor on the robot, the RUNAWAY behavior is
very straightforward. But what if, as in the case of a Khepera, the robot has
multiple range sensors? Bigger obstacles will be detected bymultiple sensors
at the same time. The common way is to have a RUNAWAY behavior for each
sensor. This called multiple instantiations of the same behavior. Below is
a code fragment showing multiple instantiations; all that had to be done is
add a for loop to poll each sensor. This takes advantage of two properties
of vector addition: it is associative (a+b+c+d can be performed as ((a + b) +
c) + d), and it is commutative (doesn’t matter what order the vectors are
summed).
while (robot==ON) {
vector.mag=vector.dir=0.0; //initialize to 0
for (i=0; i<=numberIR; i++) {
vectorCurrent=Runaway(i); // accept a sensor number
vectorOutput = VectorSum(tempVector,vectorCurrent);
}
turn(vector.direction);
forward(vector.magnitude*MAX-VELOCITY);
}
As seen in Fig. 4.19, the robot is able to get out of the cave-like trap called
a BOX CANYON box canyon without building a model of the wall. Each instance contributes
a vector, some of which have a X or Y component that cancels out.
From an ethological perspective, the above program is elegant because it
is equivalent to behavioral instantiations in animals. Recall from Ch. 3 the
model of rana computrix and its real-life toad counterpart where each eye
sees and responds to a fly independently of the other eye. In this case, the
program is treating the robot as if it had 8 independent eyes!
From a robotics standpoint, the example illustrates two important points.
First, the direct coupling of sensing to action works. Second, behavioral
programming is consistent with good software engineering practices. The
FUNCTIONAL RUNAWAY function exhibits functional cohesion, where the function does one
COHESION thing well and every statement in the function has something directly to do
with the function’s purpose.122 Functional cohesion is desirable, because it
means the function is unlikely to introduce side effects into the main program
DATA COUPLING or be dependent on another function. The overall organization shows data
coupling, where each function call takes a simple argument.122 Data coupling
is good, because it means all the functions are independent; for example, the
program can be easily changed to accommodate more IRs sensors.
The alternative to multiple instantiation is to have the perceptual schema
for RUNAWAY process all 8 range readings. One approach is to sum all 8 vectors
internally. (As an exercise show that the resulting vector is the same.)
This is not as elegant from a software engineering perspective because the
code is now specific to the PROCEDURAL robot (the function is said to have procedural co-
COHESION hesion),122 and can be used only with a robot that has eight range sensors at
those locations. Another approach, which produces a different emergent behavior,
is to have the perceptual schema return the direction and distance of
the single largest range reading. This makes the behavior more selective.
No comments:
Post a Comment