A robot that doesn’t do anything isn’t very interesting. Now that you have modified your servos, attached them to Stamp II I/O ports and have checked their operation, we will make our BoE-Bot wander randomly around its environment. We need to have two modules to implement this simple functionality: One that determines a direction and duration to go in that direction and another to send commands to our wheels.
We will call these modules wander and act respectively. Act simply operates the motors. It isn’t really a behavior, it’s an output a d will be labeled on our diagram as motors. Wander is a behavior so it will appear on our subsumption diagrams as a behavior.
The State Machine and Stamp II Code for Act
We know that to get our servos to turn the wheels we need to output a pulse whose width needs to be approximately 1ms to 2ms long, with 1.5ms being the stop position. We also know that this pulse needs to be repeated every 20ms to 30ms for our servos to continue moving. This suggests that we will have two operations that we will need to program.
We have two servos, so we could say that we have three operations, output left servo pulse, output right servo pulse and wait. To keep this module simple we will limit it to two states, one to output the pulses and one to delay before the next pulse time. Since we know that we need to repeat the pulse every 20ms to 30ms and we know that we don’t want to spend all of our time in the act module waiting for this time to elapse, we therefore know that we will be exiting and entering this block of code several times before the full set of state transitions occurs. We know that each instruction takes about 250us to execute for the Stamp II, this tells us about how long each module that we will be calling will take to run, we count up the instructions and multiply by 250us. For now we’ll guess and say that it will take 5 passes through state 2 for 20ms to elapse.
No comments:
Post a Comment