Hi, this is my first year in the FIRST competition, and i dont know how to make an autonomous mode, i dont know where to write my code, and i dont know how to activate it at all. can someone tell me how can i do it?
If you’re using MPLab and the C18 compiler, you write your autonomous code in the User_Autonomous_Code(void) function found in the user_routines_fast.c file. Here’s what it looks like in the default code:
/*******************************************************************************
* 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
*******************************************************************************/
void User_Autonomous_Code(void)
{
/* Initialize all PWMs and Relays when entering Autonomous mode, or else it
will be stuck with the last values mapped from the joysticks. Remember,
even when Disabled it is reading inputs from the Operator Interface.
*/
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;
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. */
Generate_Pwms(pwm13,pwm14,pwm15,pwm16);
Putdata(&txdata); /* DO NOT DELETE, or you will get no PWM outputs! */
}
}
}
I think a short example would be insufficiently helpful, and a helpful example would be insufficiently short. What you need to write depends on 1) what you want your robot to do, 2) how you want your robot to do it, and 3) exactly what sensors and motors your robot has connected.
We are using EasyC this year - I highly recommend it, as it eliminates a lot of programming “stuff” you have to know about. No need to know about .c/.h files, what goes where, yada-yada.
With EasyC, you put the autonomous code into the Autonomous() routine.