Home > AreaBot, My Robots, RobotC Code > AreaRover II – Better coverage by adding a new behavior

AreaRover II – Better coverage by adding a new behavior


After watching AreaRover move around  my arena, andTFR_20090624_0340 blogging about its behavior, I came up with some ideas to improve its operation.  The best part is I did not change the previous code to make this happen… I added a new behavior on top of the others!

The previous AreaRover bounced off walls and followed walls when the opportunity was presented, but really had issue with inside corners.  Because the robot implemented the Lego Ultrasonic sensor mounted to point straight left, it is blind in the front.  This is by design and offers the best method for following a wall, butInsideCorner is not good when the robot follows a wall into a corner.  The robot follows the wall into the corner until it collides at the end.  At this point, BUMP_ESCAPE takes control and spins the robot out of harms way.

Unfortunately, wall following is stopped, and the robot moves on.  In order to better cover the ground inside a corridor with an inside corner, the robot needs to learn to follow the wall better.


Download Code: bbAreaRover2.zip

See the video here: ***COMING SOON***


If there is a way to detect when the robot is both following a wall and bumping into something, I can make some assumptions.  Of course the assumptions are not totally correct.

Scenarios where wall following and bump escape may be triggered together

  • following a wall into an inside corner
  • following a wall around an outside corner and running into it
  • bumping into a wall at an angle where a wall is close enough to be detected
  • more?

What if I can intercept this special event and allow the robot to follow the inside corner.



The greatest aspect of behavior-based programming is the ability add new behaviors on top of old in order to create more complex robot intelligence.  I was able to continue to take advantage of CRUISE, WALL FOLLOW, and BUMP_ESCAPE to move the robot around the room, and add a new behavior [FOLLOW CORNER] to navigate inside corners.


How it works

I was able to utilize the output from BUMP ESCAPE and WALL FOLLOW to create a trigger when both were requesting control of the robot.  This concept saved me from having to link into the sensors directly (although you could), to determine if the robot was following a wall when a collision occurred.  I felt the robot already knew how to do these things, so why not borrow the results.

The behavior is implemented as a finite state machine (FSM) with three main states; START, CORNER, and SPIN.  The START state is the default used to monitor for trigger conditions.  Each loop checks if BUMP ESCAPE and WALL FOLLOW are both requesting control.  When true, the state changes to CORNER.  This state assumes an inside corner was encountered and takes control to correct the situation.  The first step is backing up to allow room to turn.  The next state SPIN executes once the robot has backed up far enough.  It spins the robot right (the US sensor is on the left) so that the robot is aligned with the next wall.  Once spinning is complete, the behavior relinquishes control and lets WALL FOLLOW take over again.

The INHIBIT state was added last to allow a random factor to skip control in a corner.  A random chance was added to the START state that can either allow or disallow the trigger to occur.  What I found was the behavior almost always triggered regardless of the set trigger percentage because of the timing of the behavior-based framework.  Behaviors are called many times each second and it takes time to move the robot, so the odds of triggering increased.  To prevent the robot was continually reevaluating its situation, I added the inhibit state where the behavior is disabled for a period of time.


What can I say.  The new behavior worked as planned.

The robot demonstrates several concepts of behavior-based programming.

  • Adding new functionality and intelligence did not effect existing behaviors.  The new actions were added on top of existing, functioning code. 
  • Debugging and troubleshooting efforts were reduced because only the behavior was new and allowed me to focus on tuning the that behavior.
  • I did add a new function to the behavior-based framework to return a behavior’s request for control.  I did this to keep the behavior “classes” encapsulated.
  • The robot does find inside corners and gives the robot an opportunity to continue following the walls allowing it to better cover the area in the room.
  • By adding a percentage trigger, the robot seems to make decisions more accurately.
  • This behavior demonstrates a method to INHIBIT a behavior is two ways.
    • The behavior can inhibit WALL FOLLOWING and BUMP ESCAPE by triggering at a higher priority and taking control of the robot.
    • The behavior inhibits itself based on a percentage factor.  x% of the time, the behavior inhibits itself for a time.
  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: