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:
3:6be11b32f35f
Parent:
2:0e23dd14e129
--- a/main.cpp	Wed Apr 24 18:36:21 2013 +0000
+++ b/main.cpp	Mon May 13 16:20:15 2013 +0000
@@ -12,8 +12,11 @@
 #include "mMotor.h"
 
 /* Stepper motor constants, (change based on motor) */
-int step_speed = 3000; // set default motor speed
-int numstep = 200; // defines full turn of 360 degrees
+int step_speed = 5000; // set default motor speed 4000 (fast) 5000 (natural)
+int numstep1 = 30; // Defines rising turn (200)
+int numstep2 = 30;  // Defines falling turn (20)
+
+DigitalOut txo(p30);  //Defines the transmit pin output
 
 /* Create two stepper motor controllers */
 mMotor mt1(p33, p34, p35, p36);
@@ -24,8 +27,6 @@
 Timer t2;
 
 /* Interrupt sensors */
-InterruptIn sEnd1(p20);
-InterruptIn sEnd2(p21);
 InterruptIn bInt1(p23);
 InterruptIn bInt2(p24);
 
@@ -45,99 +46,65 @@
 /* Rise detection */
 int rise = 0;
 
-/* This detects tripwire interrupt 1 */
-void l1(){
-    if (end1 == -1){
-        t1.stop();
-        tled1 = 0;
-        iled1 = 1;
-        end1 = 1;
-    }
-}
+/* Setup detection */
+int setup = 1;
 
-/* This detects tripwire interrupt 2 */
-void l2(){
-    if (end2 == -1){
-        t2.stop();
-        tled2 = 0;
-        iled2 = 1;
-        end2 = 1;
-    }
+void transmit(){
+    txo = 0;
+    wait(0.01);
+    txo = 1;
+    wait(0.01);
+    txo = 0;
+    wait(0.01);
+    txo = 1;
 }
 
 /* This detects button interrupt 1 */
 void b1(){
-    if (end1 == 0){
-        end1 = -1;
-        tled1 = 1;
-        mt1.step(numstep,0,step_speed);
-        t1.start();
+    if (setup == 0){
+        mt1.step(numstep2,0,step_speed);
+        transmit();
+        setup = 1;
     }
 }
 
 /* This detects button interrupt 2 */
 void b2(){
-    if (end2 == 0){
-        end2 = -1;
-        tled2 = 1;
-        mt2.step(numstep,0,step_speed);
-        t2.start();
+    if (setup == 1){
+        mt1.step(numstep1,1,step_speed);
+        setup = 0;
     }
 }
 
 int main() {
+    /* Drive transmit pin */
+    txo = 1;
+    
+    /* Put into setup mode */
+    setup = 1;
+    
+    /* Turn LEDs on */
+    iled1 = 1;
+    iled2 = 1;
+    tled1 = 1;
+    tled2 = 1;
+    
     printf("Starting up...\n\r");
     
+    /* Attach interrupt service routine to pins */
+    bInt1.rise(&b1);
+    bInt2.rise(&b2);
+    
     /* Set the LEDs off */
     iled1 = 0;
     iled2 = 0;
     tled1 = 0;
     tled2 = 0;
     
-    /* Attach interrupt service routine to pins */
-    sEnd1.fall(&l1);
-    sEnd2.fall(&l2);
-    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);
+    setup = 1;
     
     printf("Ready!\n\r");
     while(1) {
-        //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\r");
-                printf(" Finished in: %lf seconds\n\r", t1.read());
-                printf("==================================\n\r\n\r"); 
-            }
-            else {
-                printf("Track 1 has not finished\n\r\n\r");   
-            }
-            
-            /* Check Track 2 */
-            if (end2 == 1){
-                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\r\n\r");   
-            }
-        }
-        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;
-        }
+        // Do nothing
     }
 }