The Photophobic Robot and Subsumption Programming

It will be interesting if the robot has some higher purpose. To read the photocells we will use the Stamp II instruction rctime. The darker it is, the longer it takes to read the cell. As it takes long time to read a single photocell, we will want to break up the readings into different states, doing the math to determine whether or not the left or the right photocell sees brighter light also takes time. When we have made a decision, we want to turn in the direction of the darker reading.

We should turn, so we will be setting duration for the turn as well as a direction. Our robot could easily jerk back-and-forth, which doesn’t look like its being very decisive, if we don’t have certain duration! This will be a more complex state machine than our previous ones because it has five states instead of two. Here is a list of actions that will need to be done:
State 0
Read light level on left photocell
Set state = 1
State 1
Read light level on right photocell
Modify this value by 1.5 because this cell reads a little lower than the other one
Set state = 2
State 2
Add margin to left reading
If left is brighter than the right
Set lDir = turn right (tr)
Set lDur = 30
Set lstate = 4 (next state is decrement)
Else
Set lstate = 3
State 3
Add margin to right reading
If right is brighter than the left
Set lDir = turn left (tl)
Set lDur = 30
Set lstate = 4
Else
Set lstate = 0 (do nothing, both sides are the same)
State 4
Decrement lDur, lDur = lDur – 1
If lDur = 0
Set lstate = 0 (start over from beginning)
Else
It does nothing, go back to state 4 again for a decrement, we are still turning

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...