We wrote and debugged each subsystem's code separately until each was functional on its own, then integrated software at the same time as we integrated the physical subsystems. Using hash defines allowed us to easily read and tweak each other's code, as well as allowing us to avoid hard-coding (especially useful with timers)! We used the ME210 SES event-handling framework.
Wall-following:
Our wall-following algorithm used a set of four switches to determine the behavior of our hippo: one on the left front, one on the right front, one on the right-side corner, and one farther back on the right side (right back). We decided that our hippo would travel counter-clockwise, with its right side contacting the wall.

Running along the wall should activate side bumpers only (that is, right corner and/or right back). Thus, any front bumpers, or any combination of front bumpers and side bumpers (for instance, front left and right corner, or both fronts and right back) meant that the hippo was either not properly wall-following yet, or had hit a corner. In these situations, the hippo was programmed to reverse its left wheel while spinning the right wheel forward, with the right wheel slightly faster than the left. This allowed the hippo to keep contact with the wall while turning.
The side bumpers told us not only that the hippo was following the wall, but how well it was following. We biased into the wall (slightly rightwards) when only the hippo's right back bumper was active, and away from the wall (slightly leftwards) when only the right corner bumper was active. Both right-side bumpers exclusively active meant that the hippo was following the wall properly. If all bumpers were released, then we had strayed from the wall a bit, and we biased slightly right to find the wall again.
The locomotion bumper state diagram (including the mandatory 2-minute shutoff timer):

We used the provided SES event-handling framework to test for bumper activity; a bumper "event" occurred when a bumper was pressed/depressed and the bumpers being hit were different than the last time the bumpers were checked.
Locomotion stuck timer:
In addition to wall-following, we had a "stuck timer" in case something went wrong (e.g. the hippo got stuck in the chute). If the state of the bumpers had not changed in three seconds (about the time it took for the hippo to traverse the field), the hippo would turn in an evasive maneuver and then move forward. This stuck response would end if the hippo's bumper state changed.
Sorter mechanism:
Our setup allowed us to read analog values as described earlier. In software, two timers were implemented to delay the sorter so that it (1) would not read the same ball multiple times and (2) would not try to act upon a new ball before the previous one was done sorting. When the IR sensor read a value above the correct threshold, that value would be stored and acted upon only after a certain amount of time had passed. A delay was also programmed in right after the ball processing code, to allow the stepper motor time to rotate and release the ball.
Special strategy/servo:
The servo that released the "poop" (black balls) was delayed by a forty-second timer. After this time, it could be primed when the high right switch was hit (which told us that we were against the wall separating us from our opponent), releasing black balls a few seconds after the switch toggled. This timer restarted every time the high right switch was hit, which ensured that the servo would not release until after we had left the high wall and were facing the correct direction to fire poop at our opponent! Checking the high switch was a separate if statement in bumper event testing that did not interfere with the locomotion code.
Holding black balls in the hippo was a risky strategy, so we added a "special strategy" switch that allowed us to choose whether we wanted to store black balls or not. If the switch was off, the servo would simply move out of the way as soon as the hippo turned on.
The servo also had an "emergency release" timer that automatically moved it out of the way 1:30 after the hippo was activated, just in case.
Solenoid:
The solenoid was controlled by a simple timer which turned it on after 10 seconds, releasing the arm. This way, the arm would not be deployed unsafely, since the hippo would be following the wall by this time. To conserve power, the solenoid was turned off half a second afterward.
No comments:
Post a Comment