![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.
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.
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.
Diff: main.cpp
- Revision:
- 0:372aa18dd17d
- Child:
- 1:244a23186799
diff -r 000000000000 -r 372aa18dd17d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Apr 24 15:45:44 2013 +0000 @@ -0,0 +1,135 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * + * This times a race with up to two separate timers * + * which start whenever a button press interrupt is * + * detected. The timers are stopped only by * + * recording a tripwire interrupt which will save * + * the time and output it to the serial port. * + * * + * Created by: Michael Dushkoff (mad1841@rit.edu) * + * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +#include "mbed.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 + +/* Create two stepper motor controllers */ +sMotor mt1(p33, p34, p35, p36); +sMotor mt2(p11, p12, p13, p14); + +/* Create two individual timers */ +Timer t1; +Timer t2; + +/* Interrupt sensors */ +InterruptIn sEnd1(p20); +InterruptIn sEnd2(p21); +InterruptIn bInt1(p23); +InterruptIn bInt2(p24); + +/* Indicator LEDs */ +DigitalOut iled1(LED1); +DigitalOut iled2(LED4); +DigitalOut tled1(LED2); //Timer LED1 +DigitalOut tled2(LED3); //Timer LED2 + +/* Tells when to stop the timer */ +int end1 = 0; +int end2 = 0; + +/* This is a print button that allows the time to be outputted */ +DigitalIn button(p8); + +/* Rise detection */ +int rise = 0; + +/* This detects tripwire interrupt 1 */ +void l1(){ + if (end1 == -1){ + t1.stop(); + tled1 = 0; + iled1 = 1; + end1 = 1; + } +} + +/* This detects tripwire interrupt 2 */ +void l2(){ + if (end2 == -1){ + t2.stop(); + tled2 = 0; + iled2 = 1; + end2 = 1; + } +} + +/* This detects button interrupt 1 */ +void b1(){ + if (end1 == 0){ + end1 = -1; + tled1 = 1; + mt1.step(numstep,0,step_speed); + t1.start(); + } +} + +/* This detects button interrupt 2 */ +void b2(){ + if (end2 == 0){ + end2 = -1; + tled2 = 1; + mt2.step(numstep,0,step_speed); + t2.start(); + } +} + +int main() { + /* 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.fall(&b1); + bInt2.fall(&b2); + + /* Set the stepper motors to default position */ + mt1.step(numstep,1,step_speed); + mt2.step(numstep,1,step_speed); + + while(1) { + if (button == 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"); + } + else { + printf("Track 1 has not finished\n\n"); + } + + /* Check Track 2 */ + if (end2 == 1){ + printf("========== Track 2 Time ==========\n"); + printf(" Finished in: %lf seconds\n", t2.read()); + printf("==================================\n\n"); + } + else { + printf("Track 2 has not finished\n\n"); + } + } + else if (button == 0){ + /* Reset rise detection */ + rise = 0; + } + } +}