Home
Origins
Specifications
Performance
Software
Code
Photo Gallery







Competition Code

Programmed in IC, a variant of C.

/********************************************************************

Program Name: Final Version

Purpose: Kick robot ass

Original Program: Dane Powell, 10/26/03

Revised: Dane Powell, 11/22/03

Most Recent

********************************************************************/



/*** Beginning of code ***/



/** Initialize motor ports and counter **/

int DRIVE1 = 0; /* Drive motors 1-4 */

int DRIVE2 = 1;

int DRIVE3 = 2;

int DRIVE4 = 3;

int ARM1 = 4;   /* Arm motors 1-2 */

int ARM2 = 5;

int COUNTER = 0;    /* Counter for recording distance from start to wall */

int DUPCOUNT = 0;   /* Duplicate of counter for use in WAW strategy */

int rkval=0;    /* Used in floating-point variable conversion */

int x=0;    /* Counter for mayhem strategy */

float DELAY = 0.0;	/* Default delay time */

char final='s'; /* Denotes current strategy - default to standard, or 's' */



/** end of initialization - beginning of program body **/



void main(){        /* Select which strategy we are going to use */

    if (dip_switches()<=7){ /* Set beacon to white side */

        set_ir_transmit_frequency(100); set_ir_receive_frequency(125);

    }

    if (dip_switches()>7){  /* Set beacon to black side */

        set_ir_transmit_frequency(125); set_ir_receive_frequency(100);

    }

    ir_transmit_on();

    while (choose_button()==0){	/* Take the RoboKnob value */

        rkval=robo_knob();

        DELAY=(float)rkval; /* convert it to floating-point */

        DELAY=DELAY/10.0;   /* convert it to a delay in seconds */

        printf("%d\n", rkval);  /* send it to the LCD */

        sleep(0.5);	/* Wait and repeat until choose button is pressed */

    }

    if (dip_switches()==0){

        strat0();       /* 0000 = Standard strat, white side */

    }

    if (dip_switches()==8){

        strat8();       /* 1000 = Standard strat, black side */

    }

    if (dip_switches()==1){

        strat1();       /* 0001 = Mayhem strat, white side */

    }

    if (dip_switches()==9){

        strat9();       /* 1001 = Mayhem strat, black side */

    }

    if (dip_switches()==2){

        strat2();       /* 0010 = Wait-at-wall (WAW) strat, white side */

    }

    if (dip_switches()==10){

        strat10();       /* 1010 = Wait-at-wall (WAW) strat, black side */

    }

}



/*** Individual strategies ***/



/*** Strategy 0 ***/

/** Standard Strategy, white side **/



void strat0(){

    printf("WStand");   /* confirm strategy */

    sleep(1.0);

    final = 's';	/* Tells the program which strategy to use later on */

    quickwin();

}



/*** Strategy 8 ***/

/** Standard strategy, black side **/



void strat8(){

    printf("BStand");

    sleep(1.0);

    final='s';

    quickwin();

}



/*** Strategy 1 ***/

/** Mayhem strategy, white side **/



void strat1(){

    printf("WMayhem");

    sleep(1.0);

    final='m';

    quickwin();

}



/*** Strategy 9 ***/

/** Mayhem strategy, black side **/



void strat9(){

    printf("BMayhem");

    sleep(1.0);

    final='m';

    quickwin();

}



/*** Strategy 2 ***/

/** Wait-at-wall strategy, white side **/



void strat2(){

    printf("W-WAW");

    if (DELAY<=1.25){

    printf("INVALID DELAY");	/* A value of less than 1.25 could cause an error later on */

    sleep(30.0);	/* Give time to turn off the bot */

    }

    sleep(1.0);

    final='w';

    quickwin();

}



/*** Strategy 10 ***/

/** Wait-at-wall strategy, black side **/



void strat10(){

    printf("B-WAW");

    if (DELAY<=1.25){

    printf("INVALID DELAY");

    sleep(30.0);

    }

    sleep(1.0);

    final='w';

    quickwin();

}



/*** Strategy functions ***/



void quickwin(){

    while (analog(20)>6){   /* Search for start light */

        printf("%d\n", analog(20));

        sleep(0.2);

    }	/* Go... */

    beep(); /* Tell us that it's running */

    if (final!= 'w'){   /* If we are not using the WAW strategy */

        sleep(DELAY);   /* wait for the amount of time set by the RoboKnob */

    }

    forward_all();

    while ((digital(0)==1)||(COUNTER<50)){  /* While the mercury switch is open or the robot is less than halfway 
to the wall (to help prevent false trips) */
forward_all(); /* go forward */ COUNTER = COUNTER + 1; /* and increment the counter */ } /* The loop breaks when the mercury switch is tripped */ brake(DRIVE1); /* After the loop breaks, the motors begin to stagger-stop */ brake(DRIVE3); forward(ARM1); /* The arm drops */ forward(ARM2); sleep(0.05); brake(DRIVE4); /* Drive motors stop completely */ brake(DRIVE2); sleep(0.05); brake(ARM1); /* Arm is completely dropped and snaps block */ brake(ARM2); sleep(1.2); forward(ARM1); /* Arm begins to retract */ forward(ARM2); sleep(0.1); /* Arm retracts for a second before the robot reverses, so it doesn't catch the wall */ DUPCOUNT = COUNTER; if (final=='w'){ /* If we are using the WAW strategy, we want the robot to just sit at the wall and retract the arm */ while (DUPCOUNT > 0){ /* This is all just a duplicate of the counter loop below */ brake_all(); /* except it doesn't go anywhere, just finishes retracting the arm */ DUPCOUNT = DUPCOUNT - 2; } sleep(0.25); brake(ARM1); /* Stop the arm */ brake(ARM2); sleep(DELAY-1.25); /* Wait for the set delay, minus the ~1.25 seconds we already lost in the loop */ } while (COUNTER > 0){ /* The counter is now counting down from the stored time */ reverse_all(); /* While the counter is decrementing, the robot reverses */ COUNTER = COUNTER - 2; /* Decrements the counter by 2 each iteration (so it only goes back half as far) */ } /* The loop breaks when the counter reaches 1/2 its original value */ sleep(0.25); /* So it goes slightly farther than halfway back */ brake(ARM1); /* Stop the arm if we haven't already */ brake(ARM2); if ((final=='s')||(final=='w')){ standard_final(); /* Use the standard final strategy */ } if (final=='m'){ mayhem_final(); /* Use the mayhem finale */ } } void standard_final(){ stagger('b'); /* The robot stops right around the card reader */ stagger('f'); /* It breaks the beam and goes forward */ sleep(0.4); stagger('b'); /* stops */ sleep(1.0); /* waits for the gate to close */ stagger('r'); /* and then goes backwards */ sleep(0.5); stagger('b'); /* stops again */ stagger('f'); /* breaks the beam and goes forward... */ sleep(0.2); stagger('b'); /* stops */ sleep(1.0); /* waits for the gate to close */ stagger('r'); /* and then goes backwards */ sleep(0.5); stagger('b'); /* ...and stops again */ stagger('f'); /* (More iterations of above, just in case something went wrong) */ sleep(0.2); stagger('b'); stagger('r'); sleep(0.5); stagger('b'); } void mayhem_final(){ while (x<10){ while (digital(0)==1){ /* While the mercury switch is open... */ forward_all(); /* go forward */ } /* The loop breaks when the mercury switch is tripped */ x++; stagger('b'); stagger('r'); sleep(1.0); stagger('b'); } /* The bot basically just goes back and forth a set number of times - hopefully bashing the enemy bot
into the wall over and over */
} /*** Motor Functions ***/ void forward_all(){ forward(DRIVE1); forward(DRIVE2); forward(DRIVE3); forward(DRIVE4); } void reverse_all(){ reverse(DRIVE1); reverse(DRIVE2); reverse(DRIVE3); reverse(DRIVE4); } void brake_all(){ brake(DRIVE1); brake(DRIVE2); brake(DRIVE3); brake(DRIVE4); } void stagger(char direction){ if (direction=='b'){ brake(DRIVE1); brake(DRIVE3); sleep(0.05); brake(DRIVE2); brake(DRIVE4); } if (direction=='f'){ forward(DRIVE1); forward(DRIVE3); sleep(0.05); forward(DRIVE2); forward(DRIVE4); } if (direction=='r'){ reverse(DRIVE1); reverse(DRIVE3); sleep(0.05); reverse(DRIVE2); reverse(DRIVE4); } } /*** End of code ***/