Thursday, October 14, 2010

Fall break: motion module and the rest of AB reverse


IT'S A DINOSAUR!! It's based on the chomper motion module... And then a foam dinosaur shape added on! Pretty simple, but fun.

Now, AB reverse is similar to the AB on off problem from Day 7. Except it took 10 hours to code. (Seriously. 4 hours Sunday, 4 hours Monday, and 2 hours today.)



The basic code didn't change... But some details did!

The first issue I ran into was the program behaving like it was level triggered (pressing the switch was one direction, not pressing was the other) instead of edge (pressing the switch turned the motor one way, and pressing it again turned it the other). The mysterious reason behind this was... rather subtle actually.

Professor Berg took an oscilloscope and attached it to the sensor (one end grounded, the other on the resistor associated with that sensor). The oscilloscope showed that the switch actually "bounced": for half a millisecond, the switch went on-off-on-off repeatedly. (This is called contact bounce, according to wiki). Since the computer is fast enough to recognize even this short a time, the motor sometimes reversed when the switch was initially pressed.

Luckily, this was easily fixed. A 2 ms wait was added after each waituntil, so that the switch settled down before the program proceeded. Clearly, humans cannot press and unpress the switch that quickly, so this will not create any problems.

The other problem was that one of the switches' wire was broken. Professor Berg soldered it together (which was super cool! Did you know that there's special tubing that will shrink when heated?)


Finally, the program was working! Except that when both switches were pressed, sometimes the motor wouldn't turn on when one switch was released. I realized that the boolean statement in the "both" block (for when both switches are pressed) wasn't exactly working, so I created my own boolean blocks using the text language. Then it worked!


SUCCESS!!!

No comments:

Post a Comment