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.

Committer:
mdu7078
Date:
Wed Apr 24 15:45:44 2013 +0000
Revision:
0:372aa18dd17d
Child:
1:244a23186799
First version of RaceTimer with all interrupt code and functionality completed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mdu7078 0:372aa18dd17d 1 /* * * * * * * * * * * * * * * * * * * * * * * * * * *
mdu7078 0:372aa18dd17d 2 * This times a race with up to two separate timers *
mdu7078 0:372aa18dd17d 3 * which start whenever a button press interrupt is *
mdu7078 0:372aa18dd17d 4 * detected. The timers are stopped only by *
mdu7078 0:372aa18dd17d 5 * recording a tripwire interrupt which will save *
mdu7078 0:372aa18dd17d 6 * the time and output it to the serial port. *
mdu7078 0:372aa18dd17d 7 * *
mdu7078 0:372aa18dd17d 8 * Created by: Michael Dushkoff (mad1841@rit.edu) *
mdu7078 0:372aa18dd17d 9 * * * * * * * * * * * * * * * * * * * * * * * * * * */
mdu7078 0:372aa18dd17d 10
mdu7078 0:372aa18dd17d 11 #include "mbed.h"
mdu7078 0:372aa18dd17d 12 #include "sMotor.h"
mdu7078 0:372aa18dd17d 13
mdu7078 0:372aa18dd17d 14 /* Stepper motor constants, (change based on motor) */
mdu7078 0:372aa18dd17d 15 int step_speed = 1200 ; // set default motor speed
mdu7078 0:372aa18dd17d 16 int numstep = 512 ; // defines full turn of 360 degree
mdu7078 0:372aa18dd17d 17
mdu7078 0:372aa18dd17d 18 /* Create two stepper motor controllers */
mdu7078 0:372aa18dd17d 19 sMotor mt1(p33, p34, p35, p36);
mdu7078 0:372aa18dd17d 20 sMotor mt2(p11, p12, p13, p14);
mdu7078 0:372aa18dd17d 21
mdu7078 0:372aa18dd17d 22 /* Create two individual timers */
mdu7078 0:372aa18dd17d 23 Timer t1;
mdu7078 0:372aa18dd17d 24 Timer t2;
mdu7078 0:372aa18dd17d 25
mdu7078 0:372aa18dd17d 26 /* Interrupt sensors */
mdu7078 0:372aa18dd17d 27 InterruptIn sEnd1(p20);
mdu7078 0:372aa18dd17d 28 InterruptIn sEnd2(p21);
mdu7078 0:372aa18dd17d 29 InterruptIn bInt1(p23);
mdu7078 0:372aa18dd17d 30 InterruptIn bInt2(p24);
mdu7078 0:372aa18dd17d 31
mdu7078 0:372aa18dd17d 32 /* Indicator LEDs */
mdu7078 0:372aa18dd17d 33 DigitalOut iled1(LED1);
mdu7078 0:372aa18dd17d 34 DigitalOut iled2(LED4);
mdu7078 0:372aa18dd17d 35 DigitalOut tled1(LED2); //Timer LED1
mdu7078 0:372aa18dd17d 36 DigitalOut tled2(LED3); //Timer LED2
mdu7078 0:372aa18dd17d 37
mdu7078 0:372aa18dd17d 38 /* Tells when to stop the timer */
mdu7078 0:372aa18dd17d 39 int end1 = 0;
mdu7078 0:372aa18dd17d 40 int end2 = 0;
mdu7078 0:372aa18dd17d 41
mdu7078 0:372aa18dd17d 42 /* This is a print button that allows the time to be outputted */
mdu7078 0:372aa18dd17d 43 DigitalIn button(p8);
mdu7078 0:372aa18dd17d 44
mdu7078 0:372aa18dd17d 45 /* Rise detection */
mdu7078 0:372aa18dd17d 46 int rise = 0;
mdu7078 0:372aa18dd17d 47
mdu7078 0:372aa18dd17d 48 /* This detects tripwire interrupt 1 */
mdu7078 0:372aa18dd17d 49 void l1(){
mdu7078 0:372aa18dd17d 50 if (end1 == -1){
mdu7078 0:372aa18dd17d 51 t1.stop();
mdu7078 0:372aa18dd17d 52 tled1 = 0;
mdu7078 0:372aa18dd17d 53 iled1 = 1;
mdu7078 0:372aa18dd17d 54 end1 = 1;
mdu7078 0:372aa18dd17d 55 }
mdu7078 0:372aa18dd17d 56 }
mdu7078 0:372aa18dd17d 57
mdu7078 0:372aa18dd17d 58 /* This detects tripwire interrupt 2 */
mdu7078 0:372aa18dd17d 59 void l2(){
mdu7078 0:372aa18dd17d 60 if (end2 == -1){
mdu7078 0:372aa18dd17d 61 t2.stop();
mdu7078 0:372aa18dd17d 62 tled2 = 0;
mdu7078 0:372aa18dd17d 63 iled2 = 1;
mdu7078 0:372aa18dd17d 64 end2 = 1;
mdu7078 0:372aa18dd17d 65 }
mdu7078 0:372aa18dd17d 66 }
mdu7078 0:372aa18dd17d 67
mdu7078 0:372aa18dd17d 68 /* This detects button interrupt 1 */
mdu7078 0:372aa18dd17d 69 void b1(){
mdu7078 0:372aa18dd17d 70 if (end1 == 0){
mdu7078 0:372aa18dd17d 71 end1 = -1;
mdu7078 0:372aa18dd17d 72 tled1 = 1;
mdu7078 0:372aa18dd17d 73 mt1.step(numstep,0,step_speed);
mdu7078 0:372aa18dd17d 74 t1.start();
mdu7078 0:372aa18dd17d 75 }
mdu7078 0:372aa18dd17d 76 }
mdu7078 0:372aa18dd17d 77
mdu7078 0:372aa18dd17d 78 /* This detects button interrupt 2 */
mdu7078 0:372aa18dd17d 79 void b2(){
mdu7078 0:372aa18dd17d 80 if (end2 == 0){
mdu7078 0:372aa18dd17d 81 end2 = -1;
mdu7078 0:372aa18dd17d 82 tled2 = 1;
mdu7078 0:372aa18dd17d 83 mt2.step(numstep,0,step_speed);
mdu7078 0:372aa18dd17d 84 t2.start();
mdu7078 0:372aa18dd17d 85 }
mdu7078 0:372aa18dd17d 86 }
mdu7078 0:372aa18dd17d 87
mdu7078 0:372aa18dd17d 88 int main() {
mdu7078 0:372aa18dd17d 89 /* Set the LEDs off */
mdu7078 0:372aa18dd17d 90 iled1 = 0;
mdu7078 0:372aa18dd17d 91 iled2 = 0;
mdu7078 0:372aa18dd17d 92 tled1 = 0;
mdu7078 0:372aa18dd17d 93 tled2 = 0;
mdu7078 0:372aa18dd17d 94
mdu7078 0:372aa18dd17d 95 /* Attach interrupt service routine to pins */
mdu7078 0:372aa18dd17d 96 sEnd1.fall(&l1);
mdu7078 0:372aa18dd17d 97 sEnd2.fall(&l2);
mdu7078 0:372aa18dd17d 98 bInt1.fall(&b1);
mdu7078 0:372aa18dd17d 99 bInt2.fall(&b2);
mdu7078 0:372aa18dd17d 100
mdu7078 0:372aa18dd17d 101 /* Set the stepper motors to default position */
mdu7078 0:372aa18dd17d 102 mt1.step(numstep,1,step_speed);
mdu7078 0:372aa18dd17d 103 mt2.step(numstep,1,step_speed);
mdu7078 0:372aa18dd17d 104
mdu7078 0:372aa18dd17d 105 while(1) {
mdu7078 0:372aa18dd17d 106 if (button == 1 && rise == 0){
mdu7078 0:372aa18dd17d 107 /* Set rise detector to high */
mdu7078 0:372aa18dd17d 108 rise = 1;
mdu7078 0:372aa18dd17d 109
mdu7078 0:372aa18dd17d 110 /* Check Track 1 */
mdu7078 0:372aa18dd17d 111 if (end1 == 1){
mdu7078 0:372aa18dd17d 112 printf("========== Track 1 Time ==========\n");
mdu7078 0:372aa18dd17d 113 printf(" Finished in: %lf seconds\n", t1.read());
mdu7078 0:372aa18dd17d 114 printf("==================================\n\n");
mdu7078 0:372aa18dd17d 115 }
mdu7078 0:372aa18dd17d 116 else {
mdu7078 0:372aa18dd17d 117 printf("Track 1 has not finished\n\n");
mdu7078 0:372aa18dd17d 118 }
mdu7078 0:372aa18dd17d 119
mdu7078 0:372aa18dd17d 120 /* Check Track 2 */
mdu7078 0:372aa18dd17d 121 if (end2 == 1){
mdu7078 0:372aa18dd17d 122 printf("========== Track 2 Time ==========\n");
mdu7078 0:372aa18dd17d 123 printf(" Finished in: %lf seconds\n", t2.read());
mdu7078 0:372aa18dd17d 124 printf("==================================\n\n");
mdu7078 0:372aa18dd17d 125 }
mdu7078 0:372aa18dd17d 126 else {
mdu7078 0:372aa18dd17d 127 printf("Track 2 has not finished\n\n");
mdu7078 0:372aa18dd17d 128 }
mdu7078 0:372aa18dd17d 129 }
mdu7078 0:372aa18dd17d 130 else if (button == 0){
mdu7078 0:372aa18dd17d 131 /* Reset rise detection */
mdu7078 0:372aa18dd17d 132 rise = 0;
mdu7078 0:372aa18dd17d 133 }
mdu7078 0:372aa18dd17d 134 }
mdu7078 0:372aa18dd17d 135 }