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 17:39:44 2013 +0000
Revision:
1:244a23186799
Parent:
0:372aa18dd17d
Child:
2:0e23dd14e129
Full project working with adjustments.

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 1:244a23186799 12 #include "mMotor.h"
mdu7078 1:244a23186799 13 //#include "sMotor.h"
mdu7078 0:372aa18dd17d 14
mdu7078 0:372aa18dd17d 15 /* Stepper motor constants, (change based on motor) */
mdu7078 1:244a23186799 16 int step_speed = 200 ; // set default motor speed
mdu7078 1:244a23186799 17 int numstep = 512 ; // defines full turn of 360 degrees
mdu7078 0:372aa18dd17d 18
mdu7078 0:372aa18dd17d 19 /* Create two stepper motor controllers */
mdu7078 1:244a23186799 20 mMotor mt1(p33, p34, p35, p36);
mdu7078 1:244a23186799 21 mMotor mt2(p11, p12, p13, p14);
mdu7078 0:372aa18dd17d 22
mdu7078 0:372aa18dd17d 23 /* Create two individual timers */
mdu7078 0:372aa18dd17d 24 Timer t1;
mdu7078 0:372aa18dd17d 25 Timer t2;
mdu7078 0:372aa18dd17d 26
mdu7078 0:372aa18dd17d 27 /* Interrupt sensors */
mdu7078 0:372aa18dd17d 28 InterruptIn sEnd1(p20);
mdu7078 0:372aa18dd17d 29 InterruptIn sEnd2(p21);
mdu7078 0:372aa18dd17d 30 InterruptIn bInt1(p23);
mdu7078 0:372aa18dd17d 31 InterruptIn bInt2(p24);
mdu7078 0:372aa18dd17d 32
mdu7078 0:372aa18dd17d 33 /* Indicator LEDs */
mdu7078 0:372aa18dd17d 34 DigitalOut iled1(LED1);
mdu7078 0:372aa18dd17d 35 DigitalOut iled2(LED4);
mdu7078 0:372aa18dd17d 36 DigitalOut tled1(LED2); //Timer LED1
mdu7078 0:372aa18dd17d 37 DigitalOut tled2(LED3); //Timer LED2
mdu7078 0:372aa18dd17d 38
mdu7078 0:372aa18dd17d 39 /* Tells when to stop the timer */
mdu7078 0:372aa18dd17d 40 int end1 = 0;
mdu7078 0:372aa18dd17d 41 int end2 = 0;
mdu7078 0:372aa18dd17d 42
mdu7078 0:372aa18dd17d 43 /* This is a print button that allows the time to be outputted */
mdu7078 0:372aa18dd17d 44 DigitalIn button(p8);
mdu7078 0:372aa18dd17d 45
mdu7078 0:372aa18dd17d 46 /* Rise detection */
mdu7078 0:372aa18dd17d 47 int rise = 0;
mdu7078 0:372aa18dd17d 48
mdu7078 0:372aa18dd17d 49 /* This detects tripwire interrupt 1 */
mdu7078 0:372aa18dd17d 50 void l1(){
mdu7078 0:372aa18dd17d 51 if (end1 == -1){
mdu7078 0:372aa18dd17d 52 t1.stop();
mdu7078 0:372aa18dd17d 53 tled1 = 0;
mdu7078 0:372aa18dd17d 54 iled1 = 1;
mdu7078 0:372aa18dd17d 55 end1 = 1;
mdu7078 0:372aa18dd17d 56 }
mdu7078 0:372aa18dd17d 57 }
mdu7078 0:372aa18dd17d 58
mdu7078 0:372aa18dd17d 59 /* This detects tripwire interrupt 2 */
mdu7078 0:372aa18dd17d 60 void l2(){
mdu7078 0:372aa18dd17d 61 if (end2 == -1){
mdu7078 0:372aa18dd17d 62 t2.stop();
mdu7078 0:372aa18dd17d 63 tled2 = 0;
mdu7078 0:372aa18dd17d 64 iled2 = 1;
mdu7078 0:372aa18dd17d 65 end2 = 1;
mdu7078 0:372aa18dd17d 66 }
mdu7078 0:372aa18dd17d 67 }
mdu7078 0:372aa18dd17d 68
mdu7078 0:372aa18dd17d 69 /* This detects button interrupt 1 */
mdu7078 0:372aa18dd17d 70 void b1(){
mdu7078 0:372aa18dd17d 71 if (end1 == 0){
mdu7078 0:372aa18dd17d 72 end1 = -1;
mdu7078 0:372aa18dd17d 73 tled1 = 1;
mdu7078 0:372aa18dd17d 74 mt1.step(numstep,0,step_speed);
mdu7078 0:372aa18dd17d 75 t1.start();
mdu7078 0:372aa18dd17d 76 }
mdu7078 0:372aa18dd17d 77 }
mdu7078 0:372aa18dd17d 78
mdu7078 0:372aa18dd17d 79 /* This detects button interrupt 2 */
mdu7078 0:372aa18dd17d 80 void b2(){
mdu7078 0:372aa18dd17d 81 if (end2 == 0){
mdu7078 0:372aa18dd17d 82 end2 = -1;
mdu7078 0:372aa18dd17d 83 tled2 = 1;
mdu7078 0:372aa18dd17d 84 mt2.step(numstep,0,step_speed);
mdu7078 0:372aa18dd17d 85 t2.start();
mdu7078 0:372aa18dd17d 86 }
mdu7078 0:372aa18dd17d 87 }
mdu7078 0:372aa18dd17d 88
mdu7078 0:372aa18dd17d 89 int main() {
mdu7078 1:244a23186799 90 printf("Starting up...\n\r");
mdu7078 1:244a23186799 91
mdu7078 0:372aa18dd17d 92 /* Set the LEDs off */
mdu7078 0:372aa18dd17d 93 iled1 = 0;
mdu7078 0:372aa18dd17d 94 iled2 = 0;
mdu7078 0:372aa18dd17d 95 tled1 = 0;
mdu7078 0:372aa18dd17d 96 tled2 = 0;
mdu7078 0:372aa18dd17d 97
mdu7078 0:372aa18dd17d 98 /* Attach interrupt service routine to pins */
mdu7078 0:372aa18dd17d 99 sEnd1.fall(&l1);
mdu7078 0:372aa18dd17d 100 sEnd2.fall(&l2);
mdu7078 1:244a23186799 101 bInt1.rise(&b1);
mdu7078 1:244a23186799 102 bInt2.rise(&b2);
mdu7078 0:372aa18dd17d 103
mdu7078 0:372aa18dd17d 104 /* Set the stepper motors to default position */
mdu7078 0:372aa18dd17d 105 mt1.step(numstep,1,step_speed);
mdu7078 0:372aa18dd17d 106 mt2.step(numstep,1,step_speed);
mdu7078 0:372aa18dd17d 107
mdu7078 1:244a23186799 108 printf("Ready!\n\r");
mdu7078 0:372aa18dd17d 109 while(1) {
mdu7078 1:244a23186799 110 //printf("%d", button.read());
mdu7078 1:244a23186799 111 if (button.read() == 1 && rise == 0){
mdu7078 0:372aa18dd17d 112 /* Set rise detector to high */
mdu7078 0:372aa18dd17d 113 rise = 1;
mdu7078 0:372aa18dd17d 114
mdu7078 0:372aa18dd17d 115 /* Check Track 1 */
mdu7078 0:372aa18dd17d 116 if (end1 == 1){
mdu7078 1:244a23186799 117 printf("========== Track 1 Time ==========\n\r");
mdu7078 1:244a23186799 118 printf(" Finished in: %lf seconds\n\r", t1.read());
mdu7078 1:244a23186799 119 printf("==================================\n\r\n\r");
mdu7078 0:372aa18dd17d 120 }
mdu7078 0:372aa18dd17d 121 else {
mdu7078 1:244a23186799 122 printf("Track 1 has not finished\n\r\n\r");
mdu7078 0:372aa18dd17d 123 }
mdu7078 0:372aa18dd17d 124
mdu7078 0:372aa18dd17d 125 /* Check Track 2 */
mdu7078 0:372aa18dd17d 126 if (end2 == 1){
mdu7078 1:244a23186799 127 printf("========== Track 2 Time ==========\n\r");
mdu7078 1:244a23186799 128 printf(" Finished in: %lf seconds\n\r", t2.read());
mdu7078 1:244a23186799 129 printf("==================================\n\r\n\r");
mdu7078 0:372aa18dd17d 130 }
mdu7078 0:372aa18dd17d 131 else {
mdu7078 1:244a23186799 132 printf("Track 2 has not finished\n\r\n\r");
mdu7078 0:372aa18dd17d 133 }
mdu7078 0:372aa18dd17d 134 }
mdu7078 1:244a23186799 135 else if (button.read() == 0 && rise == 1){
mdu7078 0:372aa18dd17d 136 /* Reset rise detection */
mdu7078 1:244a23186799 137 rise = 2;
mdu7078 1:244a23186799 138 wait (0.001); //Debounce
mdu7078 1:244a23186799 139 }
mdu7078 1:244a23186799 140 else if (button.read() == 0 && rise == 2){
mdu7078 0:372aa18dd17d 141 rise = 0;
mdu7078 0:372aa18dd17d 142 }
mdu7078 0:372aa18dd17d 143 }
mdu7078 0:372aa18dd17d 144 }