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:
Mon May 13 16:22:38 2013 +0000
Revision:
4:ef3904a7f2f8
Parent:
3:6be11b32f35f
Finished state.

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 0:372aa18dd17d 13
mdu7078 0:372aa18dd17d 14 /* Stepper motor constants, (change based on motor) */
mdu7078 3:6be11b32f35f 15 int step_speed = 5000; // set default motor speed 4000 (fast) 5000 (natural)
mdu7078 3:6be11b32f35f 16 int numstep1 = 30; // Defines rising turn (200)
mdu7078 3:6be11b32f35f 17 int numstep2 = 30; // Defines falling turn (20)
mdu7078 3:6be11b32f35f 18
mdu7078 3:6be11b32f35f 19 DigitalOut txo(p30); //Defines the transmit pin output
mdu7078 0:372aa18dd17d 20
mdu7078 0:372aa18dd17d 21 /* Create two stepper motor controllers */
mdu7078 1:244a23186799 22 mMotor mt1(p33, p34, p35, p36);
mdu7078 1:244a23186799 23 mMotor mt2(p11, p12, p13, p14);
mdu7078 0:372aa18dd17d 24
mdu7078 0:372aa18dd17d 25 /* Create two individual timers */
mdu7078 0:372aa18dd17d 26 Timer t1;
mdu7078 0:372aa18dd17d 27 Timer t2;
mdu7078 0:372aa18dd17d 28
mdu7078 0:372aa18dd17d 29 /* Interrupt sensors */
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 3:6be11b32f35f 49 /* Setup detection */
mdu7078 3:6be11b32f35f 50 int setup = 1;
mdu7078 0:372aa18dd17d 51
mdu7078 3:6be11b32f35f 52 void transmit(){
mdu7078 3:6be11b32f35f 53 txo = 0;
mdu7078 3:6be11b32f35f 54 wait(0.01);
mdu7078 3:6be11b32f35f 55 txo = 1;
mdu7078 3:6be11b32f35f 56 wait(0.01);
mdu7078 3:6be11b32f35f 57 txo = 0;
mdu7078 3:6be11b32f35f 58 wait(0.01);
mdu7078 3:6be11b32f35f 59 txo = 1;
mdu7078 0:372aa18dd17d 60 }
mdu7078 0:372aa18dd17d 61
mdu7078 0:372aa18dd17d 62 /* This detects button interrupt 1 */
mdu7078 0:372aa18dd17d 63 void b1(){
mdu7078 3:6be11b32f35f 64 if (setup == 0){
mdu7078 3:6be11b32f35f 65 mt1.step(numstep2,0,step_speed);
mdu7078 3:6be11b32f35f 66 transmit();
mdu7078 3:6be11b32f35f 67 setup = 1;
mdu7078 0:372aa18dd17d 68 }
mdu7078 0:372aa18dd17d 69 }
mdu7078 0:372aa18dd17d 70
mdu7078 0:372aa18dd17d 71 /* This detects button interrupt 2 */
mdu7078 0:372aa18dd17d 72 void b2(){
mdu7078 3:6be11b32f35f 73 if (setup == 1){
mdu7078 3:6be11b32f35f 74 mt1.step(numstep1,1,step_speed);
mdu7078 3:6be11b32f35f 75 setup = 0;
mdu7078 0:372aa18dd17d 76 }
mdu7078 0:372aa18dd17d 77 }
mdu7078 0:372aa18dd17d 78
mdu7078 0:372aa18dd17d 79 int main() {
mdu7078 3:6be11b32f35f 80 /* Drive transmit pin */
mdu7078 3:6be11b32f35f 81 txo = 1;
mdu7078 3:6be11b32f35f 82
mdu7078 3:6be11b32f35f 83 /* Put into setup mode */
mdu7078 3:6be11b32f35f 84 setup = 1;
mdu7078 3:6be11b32f35f 85
mdu7078 3:6be11b32f35f 86 /* Turn LEDs on */
mdu7078 3:6be11b32f35f 87 iled1 = 1;
mdu7078 3:6be11b32f35f 88 iled2 = 1;
mdu7078 3:6be11b32f35f 89 tled1 = 1;
mdu7078 3:6be11b32f35f 90 tled2 = 1;
mdu7078 3:6be11b32f35f 91
mdu7078 1:244a23186799 92 printf("Starting up...\n\r");
mdu7078 1:244a23186799 93
mdu7078 3:6be11b32f35f 94 /* Attach interrupt service routine to pins */
mdu7078 3:6be11b32f35f 95 bInt1.rise(&b1);
mdu7078 3:6be11b32f35f 96 bInt2.rise(&b2);
mdu7078 3:6be11b32f35f 97
mdu7078 0:372aa18dd17d 98 /* Set the LEDs off */
mdu7078 0:372aa18dd17d 99 iled1 = 0;
mdu7078 0:372aa18dd17d 100 iled2 = 0;
mdu7078 0:372aa18dd17d 101 tled1 = 0;
mdu7078 0:372aa18dd17d 102 tled2 = 0;
mdu7078 0:372aa18dd17d 103
mdu7078 3:6be11b32f35f 104 setup = 1;
mdu7078 0:372aa18dd17d 105
mdu7078 1:244a23186799 106 printf("Ready!\n\r");
mdu7078 0:372aa18dd17d 107 while(1) {
mdu7078 3:6be11b32f35f 108 // Do nothing
mdu7078 0:372aa18dd17d 109 }
mdu7078 0:372aa18dd17d 110 }