This is a starting gate for a line following competition in which two cars are held up by a stepper motor and then released at the same time. A transmission signal is sent through an antenna to alert the ending line that the race timer should start and will only stop when the tripwire is broken.

Dependencies:   mMotor mbed

About

This program is intended to start two cars at the same time from a starting gate rig that uses a stepper motor to control the release of the cars. Two buttons control the release mechanism and once the cars are released, a signal is sent through an antenna to the ending gate rig which tells it to start its timers. This is specifically made for this application only and uses the custom mMotor library to drive a 5718m-05e-05 stepper motor.

Hardware

The circuit diagram is given below. Vs should be external to the mbed since the mbed can not provide enough current to drive the stepper motor.

/media/uploads/mdu7078/starting-gate-1.png

Circuit diagram constructed using CircuitLab.

Usage

The starting gate is controlled by two separate buttons which cause the gate to release or reset based on which button is pressed. The buttons themselves can only be pressed once before pressing the opposite button to prevent the gate from going too far in either direction.

Revision:
1:244a23186799
Parent:
0:372aa18dd17d
Child:
2:0e23dd14e129
--- a/main.cpp	Wed Apr 24 15:45:44 2013 +0000
+++ b/main.cpp	Wed Apr 24 17:39:44 2013 +0000
@@ -9,15 +9,16 @@
  * * * * * * * * * * * * * * * * * * * * * * * * * * */
  
 #include "mbed.h"
-#include "sMotor.h"
+#include "mMotor.h"
+//#include "sMotor.h"
 
 /* Stepper motor constants, (change based on motor) */
-int step_speed = 1200 ; // set default motor speed
-int numstep = 512 ; // defines full turn of 360 degree
+int step_speed = 200 ; // set default motor speed
+int numstep = 512 ; // defines full turn of 360 degrees
 
 /* Create two stepper motor controllers */
-sMotor mt1(p33, p34, p35, p36);
-sMotor mt2(p11, p12, p13, p14);
+mMotor mt1(p33, p34, p35, p36);
+mMotor mt2(p11, p12, p13, p14);
 
 /* Create two individual timers */
 Timer t1;
@@ -86,6 +87,8 @@
 }
 
 int main() {
+    printf("Starting up...\n\r");
+    
     /* Set the LEDs off */
     iled1 = 0;
     iled2 = 0;
@@ -95,40 +98,46 @@
     /* Attach interrupt service routine to pins */
     sEnd1.fall(&l1);
     sEnd2.fall(&l2);
-    bInt1.fall(&b1);
-    bInt2.fall(&b2);
+    bInt1.rise(&b1);
+    bInt2.rise(&b2);
     
     /* Set the stepper motors to default position */
     mt1.step(numstep,1,step_speed);
     mt2.step(numstep,1,step_speed);
     
+    printf("Ready!\n\r");
     while(1) {
-        if (button == 1 && rise == 0){
+        //printf("%d", button.read());
+        if (button.read() == 1 && rise == 0){
             /* Set rise detector to high */
             rise = 1;
             
             /* Check Track 1 */
             if (end1 == 1){
-                printf("========== Track 1 Time ==========\n");
-                printf(" Finished in: %lf seconds\n", t1.read());
-                printf("==================================\n\n"); 
+                printf("========== Track 1 Time ==========\n\r");
+                printf(" Finished in: %lf seconds\n\r", t1.read());
+                printf("==================================\n\r\n\r"); 
             }
             else {
-                printf("Track 1 has not finished\n\n");   
+                printf("Track 1 has not finished\n\r\n\r");   
             }
             
             /* Check Track 2 */
             if (end2 == 1){
-                printf("========== Track 2 Time ==========\n");
-                printf(" Finished in: %lf seconds\n", t2.read());
-                printf("==================================\n\n"); 
+                printf("========== Track 2 Time ==========\n\r");
+                printf(" Finished in: %lf seconds\n\r", t2.read());
+                printf("==================================\n\r\n\r"); 
             }
             else {
-                printf("Track 2 has not finished\n\n");   
+                printf("Track 2 has not finished\n\r\n\r");   
             }
         }
-        else if (button == 0){
+        else if (button.read() == 0 && rise == 1){
             /* Reset rise detection */
+            rise = 2;
+            wait (0.001); //Debounce
+        }
+        else if (button.read() == 0 && rise == 2){
             rise = 0;
         }
     }