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.

main.cpp

Committer:
mdu7078
Date:
2013-05-13
Revision:
4:ef3904a7f2f8
Parent:
3:6be11b32f35f

File content as of revision 4:ef3904a7f2f8:

/* * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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 "mMotor.h"

/* Stepper motor constants, (change based on motor) */
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);
mMotor mt2(p11, p12, p13, p14);

/* Create two individual timers */
Timer t1;
Timer t2;

/* Interrupt sensors */
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;

/* Setup detection */
int setup = 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 (setup == 0){
        mt1.step(numstep2,0,step_speed);
        transmit();
        setup = 1;
    }
}

/* This detects button interrupt 2 */
void b2(){
    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;
    
    setup = 1;
    
    printf("Ready!\n\r");
    while(1) {
        // Do nothing
    }
}