Week 4: September 19 25 - ngetachew/Portfolio GitHub Wiki

The first thing I did on Wednesday was fixing the sensor problem from last week. The use of the _thread module made this really simple. All I had to do was call the start_new_thread() function and pass in the names of the two functions like so:

_thread.start_new_thread(self.step,())

_thread.start_new_thread(self.stopAtTop,())

where step() is a function that uses the stepper module's relativeMove() function as long as a global variable reads true, and stopAtTop() continually updates that global variable. Conveniently, the _thread module kills the threads when the functions return.

After this, the Perpetual Motion Machine was fully functioning. The when the start button was pressed, the staircase would turn on, and the stepper motor ramp would move the ball to the top. The ball would then slide into the staircase and get dropped into another ramp. It would wait here until the stepper motor was in its home position. Then, after 1 second, the gate would open, allowing it to roll back to its starting position. Below is an image of the user interface.

Perpetual Motion UI

One of our mentors, Doug Whetter, recommended changing the program so that the staircase wouldn't turn on as soon as the start button was pressed. This should have been simple, but the program was not cooperating. Sometimes it would run without a hitch; other times, random problems would occur such as the stairs not turning on or the gate not opening. The unpredictability of this is what lead us to conclude that there was a problem with the hardware, so we changed it back.

We then found another problem. Even though we changed it back, the gate still wasn't always opening properly. The solution we found was a little unorthodox, but it worked. In the openGate() function we sent the PWM signal twice in a row:

Perpetual Motion Code Snippet