Week 27. Mar 4.8 2019 - michelle-qin/Portfolio GitHub Wiki

Snake Pendulum Finalization

Last Friday, a student came up to me about an issue they had been experiencing the past couple days with the Snake Pendulum. In some rare cases, a pendulum would remain standing and completely miss the time for it to return to its resting position. This didn't seem alarming to the student, as the error only occurred in some situations. However, we wanted to try to be as perfect as possible on the programming side to ensure the success of this kiosk in the Moxi museum.

As I analyzed the serial monitor outputs, I realized that the instances when the error occurs only happens when one pendulum is supposed to return within 5 seconds of the other pendulum returning. When I looked through the code, I realized that the issue is caused by the delay I implemented last week. The delay is, as I like to call it, "universal" - it blocks all other commands until the delay is finished (this reason was also why we had to program 2 independent timers for the pendulums).

So, to solve this, my first approach was to implement 2 independent timers for the delays, just like what we did for the pendulums. Speaking with a mentor Joe, this seemed like the correct approach. However, when Joe looked through my code, he thought that there would be debugging issues when I would try to implement the other 2 independent timers due to the arrangement/structure of my code. He proposed reorganizing my code into a more simplified and logical way. Even this would take more time to do, we went ahead and discussed how to do it.

The approach that Joe suggested for rearranging my code was using a switch statement to manage my states. Essentially, in the snake pendulum, there are 3 states: OFF (when the button is not pressed and the pendulums are not in action), ON (when the button is pressed to make the pendulums move in action), and WAITING (the brief moment when the pendulum returns to its original position after finishing their action). The switch statement would implement 3 cases to manage these different states. In the main loop, we will continuously call the switch statement to see what state we are currently in, and command the appropriate actions. Adding this to the code didn't require too much new code, and it made the overall structure much more clean, understandable, and logical.

The code has been pushed to GitHub and the kiosk saw a lot of success at the Moxi last night :-) Below are photos of the finished product.

I'm currently in the process of documenting the code. After that, I will jump back into the Ball Wall project.

images/SPS1.jpg

images/SPS2.jpg