5 June 07

Good hacking session tonight. I implemented a simple “evade” behavior for my iRobot Create that keeps track of the number of bumps within a short amount of time.

If there are four bumps in the small amount of time (about 20 seconds), the robot does a nearly 180° turn and escapes.

Exactly 180°?

The evade turn is anywhere between 155° and 200°. The degree of randomness is so that if the robot gets really stuck, it will hopefully luck its way out in successive tries.

The 20 second figure from above isn’t exact either. After a bump, I wait half a second before counting that bumb (this is so the bump sensor has time to clear, and I don’t count 20 bumps in quick succession). Then, I wait 4.5 seconds, and either clear the counter, or record another bump. If I count 4 bumps before any of the 4.5 second timers are up, I’m in an evade situation.

This behavior is working well, and the robot is successfully extricating itself from the jams it likes to get into. There’s just one problem...

That Derned Reverse

The code I’m writing form my iRobot Create has two behaviors that look at the bump sensors: escape and evade.

Escape is the behavior that handles crashes. It backs up a short distance, and turns away from the crash. The only problem with escape is that if the robot enters an area with walls on three sides, it may become stuck, which is why I’ve added....

Evade, which I’ve been describing above. This behavior has a higher priority than escape, and extricates the robot nicely from tight spots where escape is insufficient.

The problem I’m having right now is with escape’s reversing: after executing an evade, the robot tries to do an escape as well, resulting in it reversing into an the obstacle we’ve just turned away from.

There are a number of ways I could solve the problem, but none of them really appeal to me. They involve parts of my code knowing things that those parts of the code shouldn’t.

One solution that might be okay would be for stateful behaviors (such as escape) to automatically revert to their non-active state if they did not win the previous round of arbitration.

I think I may go with that one.

Comments:

Textile Help