Tuesday, May 17, 2011

Final Project--Programming!

While I had been endlessly laser printing, press-fitting, and SolidWork-ing, Clara had been working on our creep's code.  She also devised a brilliant laser plan for our motion detector.  Earlier in the project, we had experimented with other possible motion sensors.  We tried using an ultrasound sensor, but it only detected movement up to 1 or 2 feet away, which was not far enough for us.  We thought about using a video camera, and somehow programming it so that it could sense how far away a person was by the amount of space they took up in the image.

Very messy (as usual) sketch--we thought we might be able to make a program so that different stages of our creep would be activated based on how many boxes a person took up (i.e. how much of the video camera's screen they took up)
This idea also didn't seem like it would work--we had no way of predicting which direction or from exactly what distance people would enter our image.

The lasers seems like just the ticket though!  We only had one laser, so Clara rigged a system using a 50/50 refractor lense and a mirror that let us split the beam so it reached both light sensors.

First laser setup
With this laser system, walking through the first beam would trigger stage one, walking through beam two would have no effect, and walking through beam 3 would trigger stage two.  This required a program that would need to ignore signals from the second beam.

Chris suggested we move the 50/50 refractor lense to the format below, which was much better since it gave us only 2 laser beams to deal with.

Second laser setup
For both of these setups, the 50/50 refractor lense must be at a 45 degree angle in front of the laser.  We at first had it set up on the same type of stand that was holding the light sensors, but decided to build a piece of delrin that could sit in front of the laser with a lense-sized hole at a 45 degree angle.

Solidworks model
Actual piece
Now onto the program itself:

The pictures below are of our final program.  One of the changes made along the way was the switch in laser formation.  Before the switch, walking through beam one triggered stage one, and walking through beam two twice triggered phase two.  After switching the laser formation, we switched the program so that phase two was activated the first time one walks through laser two.

Additionally, before we started programming, we had decided to install a touch sensor on the box's base, so that the elevator would always know when to stop.

Touch sensor peeping up! (Our entire Delrin structure sits on top of this base)

Our faux base was balanced on these Lego blocks

As you can see from the picture, we installed a faux base into our box so that the touch sensor would have space beneath it.

Earlier versions of the program did not reset the elevator at the beginning of the program.  We added this feature after we had tested out our entire creep and saw that it was VERY difficult to reset the elevator manually if the program for some reason left it in the middle of its cycle.  After we added the automatic reset to the beginning of our program, we no longer had this problem.

We used two NXTs for our program.  The boss was located in the creep's box, and communicated via bluetooth to the NXT connected to the light sensors.  In the boss, port A was connected to the elevator's motor (stage one), port B was connected to the scissor mechanism's motor (stage two), and port 1 was connected to the touch sensor. 
In the other  NXT, hereafter referred to as the laser NXT, the light sensor that triggers phase one was plugged into port 2, and the light sensor that triggers phase two was plugged into port 1. 

The next four pictures show the boss's programs:

After initializing by making sure the elevator is pressing the touch sensor, the program waits for somebody to cross the first laser line.  When this happens, the receiving NXT sends the boss a signal to enter "stage1."  In stage1, the motor attached to the gear trains turns backward for 3 seconds at a power of 40, thus elevating itself on the linear gear track (and causing our creep to creep).


Stage 1
If no laser is tripped for 15 seconds, the program times out and the laser NXT sends the command 'DONE,' which makes the creep descend until it reaches the touch sensor.

Move
If the second laser is tripped, the laser NXT sends a 'move' command to the boss.  This causes the program to run 'creepmove180' two times, with a 5 second interval in between.  This causes the motor connected to the scissor mechanism to rotate 180 degrees (popping the creep), wait 5 seconds (theoretically holding him in the popped position), and then rotate another 180 degrees (lowering him back down).
Creep move 18
After phase two is complete, the laser NXT will send the command 'DONE,' which causes the creep to descend until it reaches the touch sensor in it's box's faux base.  After this stage is complete, the program once again waits for somebody to cross the first laser, and thus triggering 'stage1' and repeating the process.
Done

The picture below shows the laser NXT's program:

Laser NXT's program
The program starts by initializing the two light sensors.  In order for a laser to be tripped, its light sensor reading must drop by a value greater than 20.  When the first laser is tripped (port 2), the laser NXT sends 'stage1' to the boss, causing stage one to occur.  After stage1 has occured, the program enters a loop with two possible conditions--true (the second laser is tripped) and false (the second laser is not tripped).  If the true condition is satisfied, the laser NXT sends the 'move' command to the boss, followed by 'done.'  If the true condition is not satisfied after the time-out period (15 seconds), the laser NXT sends just the 'done' command, causing the elevator to descent to its initial position.  The timeout timer begins after stage one is complete, when the program is about to enter the true/false loop.

Also: While testing the creep today, Lyn noticed that all four gears on the end of the gear trains were almost at the edge of their linear gear columns, setting them up for potential issues with getting off-track.  I had noticed this problem before and not known how to remedy it, but Lyn came up with a great quick fix--doubling the gear!

Two round gears instead of one!
As you can see, switching from one gear to two made a huge difference stability-wise!

No comments:

Post a Comment