Autonomous

How do I program for Autonomous mode?

**To run code during Autonomous mode in the FIRST competition, simply place it in the User_Autonomous_Code function inside the user_routines_fast.c file.

This function checks the bit named “autonomous_mode” and repeats as long as it equals 1. This bit is set by the Operator Interface or Arena control system during competition.

To simulate Autonomous mode using a dongel on the Operator Interface, see the Competition Port Pin-out Guide here.**

Can I simulate the FIRST competition Autonomous operation with the Mini RC?

Since no link is required with a remote user for the program to begin executing (see p.3 of the 2004 EDU RC User’s Guide), Autonomous mode is in essence always on. To simulate a period in which no user input is allowed, you can write a program to use timers to ignore the user inputs for a certain duration.

Can you give me a simple routine for Autonomous mode. I know that this code goes in the user_routines_fast.c file. Is there any other file that needs to be modified or variables that need to be carried? In the examples I have been given there is a mixed bag of C, C++, and BASIC commands. We cannot get the code to work. Thanks for your help.

**You only need to modify the user_routines_fast.c file to do Autonomous mode. As far as variables, (given that the user must know C) here is an example:

Variables are either global or local. The two that are defined as static (delay and direction) are only local to this routine. The others are global bytes in the txdata and rxdata structure (pwm01 and pwm02).

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

  • FUNCTION NAME: User_Autonomous_Code

  • PURPOSE: Execute user’s code during autonomous robot operation.

  • You should modify this routine by adding code which you wish to run in

  • autonomous mode. It will be executed every program loop, and not

  • wait for or use any data from the Operator Interface.

  • CALLED FROM: main.c file, main() routine when in Autonomous mode

  • ARGUMENTS: none

  • RETURNS: void

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

#define FORWARD 0

#define RIGHT 1

#define LEFT 2

#define BACKWARD 3

#define SLOW_FORWARD 5

void User_Autonomous_Code(void)

{

/*

This code demostrates how to move a robot in autonomous mode. When invoked,

the robot will move forward for 5 seconds, turn right for 1 second, backup

for 2 seconds, turn left for 1 second then continue forward at a slow speed

until autonomous mode is deactivated.

Two motors should be hooked up to pwms 1 and 2. The wiring on one motor should

be swapped in reference to the other motor (on the victor output terminals).

When autonomous mode is complete, pwm 1 and pwm 2 are set to neutral.

*/

static unsigned char delay;

static unsigned char direction;

pwm01 = pwm02 = pwm03 = pwm04 = pwm05 = pwm06 = pwm07 = pwm08 = 127;

pwm09 = pwm10 = pwm11 = pwm12 = pwm13 = pwm14 = pwm15 = pwm16 = 127;

relay1_fwd = relay1_rev = relay2_fwd = relay2_rev = 0;

relay3_fwd = relay3_rev = relay4_fwd = relay4_rev = 0;

relay5_fwd = relay5_rev = relay6_fwd = relay6_rev = 0;

relay7_fwd = relay7_rev = relay8_fwd = relay8_rev = 0;

direction = FORWARD; /* Initialize prior to auton loop */

delay = 191; /* 5 second delay (191 * .0262ms = ~5s) */

while (autonomous_mode) /* DO NOT CHANGE! */

{

if (statusflag.NEW_SPI_DATA) /* 26.2ms loop area */

{

Getdata(&rxdata); /* DO NOT DELETE, or you will be stuck here forever! */

/* Add your own autonomous code here. */

switch (direction)

{

case FORWARD:

pwm01 = pwm02 = 127 + 60;

delay–;

if (delay == 0)

{

direction = RIGHT;

delay = 38; /* 1 second delay (38 * .0262ms = ~1s) */

}

break;

case RIGHT:

pwm01 = 127 - 40; /* do a slow right turn */

pwm02 = 127 + 40;

delay–;

if (delay == 0)

{

direction = BACKWARD;

delay = 76; /* 2 second delay (76 * .0262ms = ~2s) */

}

break;

case BACKWARD:

pwm01 = 127 - 50; /* go backwards for 2 seconds */

pwm02 = 127 - 50;

delay–;

if (delay == 0)

{

direction = LEFT;

delay = 38; /* 1 second delay (38 * .0262ms = ~1s) */

}

break;

case LEFT:

pwm01 = 127 + 40; /* do a slow left turn */

pwm02 = 127 - 40;

delay–;

if (delay == 0)

{

direction = SLOW_FORWARD;

delay = 1; /* immediately go forward at a slow rate */

}

break;

case SLOW_FORWARD:

pwm01 = pwm02 = 127 + 30; /* go forward slowly */

break;

}

/* Generate_Pwms(pwm13,pwm14,pwm15,pwm16); - not needed if your not using pwms 13-16 */

Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */

}

pwm01 = 127; /* set to neutral after autonomous mode */

pwm02 = 127;

}

}**