Behavior:Exercise1-Obstacle Avoidance
Contents |
Setup
This exercise involves using range sensors from the Sensors section. Make sure that they are calibrated correctly. At this point you should have a working IR sensor. The first thing we will use this new sensor for is obstacle avoidance which is one of the most important features of a robot. The Roomba and Create robots were designed to be harmless when they bump into objects. However, we will now consider these collisions to be extremely bad. Fortunately, the IR sensor provides range data to objects before an actual collision. The purpose of this exercise is to create a robot controller that responds to the IR sensor data in a manner that prevents all collisions.
In order to prevent all collisions IR sensors should be placed in a ring around the robot. We will assume for the purposes of this exercise that there are a number of sensors arranged facing the front, left, and right sides of the robot. This will allow the robot to react to observed obstacles on all sides. A recommended setup is shown in the following image:
need picture of sensor placements
Behavior Layer
In this exercise, the behavior network will be used for the first time. When using the exercise example code, the behavior network can be created as such:
// Global Parameters #include <roomba/BehaviorNetwork.hh> BehaviorNetwork* network;
The exerciseInit function is used to initialize BehaviorNetwork, as well as create the behaviors used in the program, and add them to the network:
bool exerciseInit()
{
network = new BehaviorNetwork( client );
GoalBehavior* x = new GoalBehavior();
network->add_behavior( x );
LinearSafetyBehavior* l = new LinearSafetyBehavior();
network->add_behavior( l );
AngularSafetyBehavior* a = new AngularSafetyBehavior();
network->add_behavior( a );
// Return value indicate whether the program should quit.
// false = quit, true = continue
return network->networkInit();
}
the exerciseFini function:
void exerciseFini()
{
network->networkFini();
}
and the exerciseUpdate function:
bool exerciseUpdate()
{
return network->networkUpdate();
}
Arbitration
Since there will be a number of different functions used to set values on the robot, the behavior layer is designed to arbitrate between requests of many behaviors. For each iteration only one request can be made of the robot at a time. For the behavior layer, each change in speed is requested with a priority (lower is better), and the request with the lowest priority is chosen.
For example, while the normal way to request a change in speed is:
client->SetLinearSpeed( 0.0 );
in the behavior layer, the same function can be used to assign a priority:
client->SetLinearSpeed( 0.0, 0 );
for a default priority, or for a more urgent priority
client->SetLinearSpeed( 0.0, -5 );
Re-Use of Code
In a previous example, you made a reactive controller that would wander around a scene while avoiding obstacles. In this example, we are adding an additional goal of servoing to a pre-specified position. However, even though the task is somewhat different, good software engineering is all about re-use of code. We will still classify sensor readings as FLBR (Front, Left, Back, and Right), and we will still follow the same strategy that was defined before for obstacle avoidance.
Behaviors
Here is an example of a way to split the aspects of this task into behaviors. One way to accomplish the task is to split the actions into three behaviors, one to drive the robot toward the goal, and two to handle obstacle avoidance. The obstacle avoidance behaviors should run at a lower priority in order to prioritize avoiding objects in the environment over getting to the goal.
Linear Safety Behavior
A good place to start is to make a behavior to stop the robot before it hits an obstacle. Since we will never drive the robot backwards, we only need to worry about the Front reading. When the front reading is closer than the safety distance, the robot should stop. As an additional touch, it may be advisable to slow the robot as the front reading gets closer to the safe distance.
Angular Safety Behavior
The next behavior that should be constructed, is a behavior that keeps the robot from getting stuck near obstacles. When the robot has an obstacle in front of it, turn the robot to the direction (RIGHT,LEFT) that has obstacles the furthest away.
Goal Direction Behavior
The final behavior will set the robot to turn toward the goal and, when facing the goal, to move forward. This is a relatively simple behavior to construct.
![[LOGO]](/workbook/skins/workbook/create_small2.png)



