Making the BoE-Bot Wander

All we need wander to do is choose a direction randomly and a duration to go that direction. This module will be as easy to design as the act module, and it will demonstrate the ease with which we can add new behaviors, and how these behaviors can remember what they are doing. The first step in designing our form of a finite state machine is to write down all of the steps that are to be taken and all of the transition functions that need to be tested. After we have our list, the state machine can be drawn.

Here is our action list for wander:
State 0
Choose a direction to go with the random function (wDir)
Go to State 1
State 1
Choose duration to go with the random function (wDur)
Add some minimum time to the duration so it’s not too short
Go to state 2
State 2
Decrement wDur
If wDur = 0 then go to state 0

Some arrows do not have transition labels attached on it. When a state machine automatically transitions from one state to another and does not need to make a decision a transition function is not needed.

The wander module purpose is to randomly choose a direction for our robot to go and random time duration for it to take going there. The random() instruction plays is an important role in the wander logic. Random uses a word variable type and needs a "seed" to set up its return value. We will just use the last return value it gave us as the seed for the next on e. We will also use a mask to only get numbers in a certain range; a small range for the direction changes, a much larger one for the duration. Another interesting feature is the lookup instruction. This instruction uses a word sized variable, because we break the drive variable into a byte0 and byte1 variables, we can get both the left and right motor values from a single lookup! You’ll see how this is done in the following code, and you’ll see how this makes it very simple for us to change what the robot will do.

1 comment:

  1. Thank you! I like your blog and bookmark this blog for further use thanks again! Welcome to my blog!

    Everything About Cool Robots! All The Latest Cool Robots And Robotics News.
    http://www.coolrobots.net/

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...