Home > AreaBot, My Robots, RobotC Code > BumperBot – A Detailed Behavior Primer

BumperBot – A Detailed Behavior Primer

Bumper Bot

Bumper Bot

Featuring: BumperBot

RobotC Source code for a behavior-based bumper robot:Download: bbBumperBot.zip

Behaviors – Defined

Behaviors are the way to implement functionality in when using the behavior framework. A behavior represents an action or reaction to events (triggers) and resulting request to control where the robot moves.

A behavior may have zero or many triggers connected to its input.  The behavior has one output to the arbitrator (in my fixed-priority arbitration scheme).  The behavior may either request or decline control of the robot by this output.

An example of a behavior with no triggers is CRUISE.  It processes no input from the robot.  It requests to drive the robot given its two internal constants; speed and steering.  Every time the behavior runs, the output is the same.

An example of a behavior implements a trigger is BUMP ESCAPE.  It monitors collisions with an object on its bumpers and requests action from the robot based on that input.  The behavior does nothing until the bumpers are depressed.  The robot requests to back up for a time, spin right or left, move forward when a collision occurs and relinquishes control when the escape is complete.

Other examples of a behavior trigger are: an amount time passing, a random number generator, a sensor value, motor tacho, battery level, or a combination of inputs.

Types of Behaviors

There are two main types of behaviors; Servo and Ballistic.  Each has a purpose and offers a way to determine a behavior’s requested motor actions (speed and steering).

Servo Behaviors

Another term for Servo Behaviors is feedback and control systems.  These behaviors may or may not use external input, but provide instant feedback as an output.  CRUISE is the simplest form of servo behavior.  It takes no input and outputs a constant speed and steering.  A more complex behavior LIGHT SPEED uses input from a light sensor and directly translates that into a speed value.  The LIGHT HOME behavior may implement two light sensors on either side of the robot.  The behavior may request steering based on the difference in light levels allowing the robot to move toward a light source.

These behaviors all process input (or lack thereof) and determine motor commands directly from that input in a stateless feedback/control loop.

Ballistic Behaviors

Another term for a ballistic behavior is a finite state machine.  Ballistic behaviors maintain state between successive calls in order to complete a series of steps before relinquishing control of the robot.

An interesting note about behavior-based programming is that behaviors each run for a fraction of a second at a time in this framework.  That serves servo behaviors well because they may alter their commands with each successive pass providing real-time feedback to robot conditions.  Ballistic behaviors, on the other hand, must “remember” what they were trying to accomplish in order to complete the operation.

BUMP ESCAPE is a great example of the ballistic behavior.  When the robot collides with an object, BUMP ESCAPE is triggered.  The robot backs up for a time, spins, positions forward, and returns to its start state for the next collision.
Complexity in implementing ballistic behaviors stems from maintaining state between loops while still keeping the robot on its mission.  Here are a few examples to consider:

  • During the backup state above, a higher order behavior is triggered.  It takes control of the robot and then releases control.  If the BUMP ESCAPE is triggered again what state should it start in?
  • What if another behavior is triggered in the middle of an escape?  How will the robot respond so that it does not crash again or worse, oscillate between a collision and another behavior’s action.

It is important to consider the winning behavior during each loop of the arbitrator to handle this complexity.  I implemented the lastWinner variable to allow behaviors to examine the winner of the last round.

BUMP ESCAPE checks lastWinner during all states except START_STATE.  It is assumed BUMP ESCAPE should be the previous winner in all other states (or we could not get to the other states).  If BUMP ESCAPE is not the last winner, then we know a behavior of higher priority must have triggered, and BUMP ESCAPE resets itself to the starting behavior.

Oscillation between two behaviors where the robot is stuck in a corner or in a position where it can no longer make forward progress can be a real issue.  BUMP ESCAPE may need to deal with a couple of these issues.

The robot might be in a corner where BUMP ESCAPE triggers on the right, then backs up and spins left only to bump on the left.  The robot backs up spins right and hits again.  This action is called “Canyoning”.  My version of BUMP ESCAPE adds a bit of randomization to the spin so the robot tries different spin times so repeats are less frequent.  We also use the state: Forward to add a small forward movement after the main escape action to move the robot to a different place before releasing control.

Robot Sample

I am uploading my code for a bumper robot that implements CRUISE and BUMP_ESCAPE.  My robot is a simple differential robots with a bumper placed in the front to detect collisions.  Here is the behavior diagram.

Basic behavior-based room explorer

Basic behavior-based room explorer

I will post a short video soon…

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: