This is an old revision of the document!
Sensing 101 Hints
Bumper Events for Safe Forward Motion
What this requires is two variables to be added to your goforward class. One for the bumper state in the finite machine, and one to keep track of the bumpers that are hit. Call the first one bstate
and the second one bhit
.
Use the bits in bhit to keep track of which bumpers were hit. The first bit can be the left bumper, the second bit the middle bumper, and the third bit the right bumper. The bits toggle based on the event message for the bumpers.
The bump state then should have three states, let's order them as 0, 1, and 2. In state 0, the robot should be moving forward so long as (bhit is equal to 0). Having any bumper be hit (so that bhit > 0) should immediately trigger state 1. If the bumpers cease to be hit when in state 1 (bhit equals 0 again) should trigger state 2. Pausing fully without hits in state 2 should then return to state 0. Some of this logic gets implemented in the bumper callback function