Competition Template

This is the template you get when you create a new “Vex Competition Template”. Is this all there is? Where is the main function? How does it know when to start the autonomous and operator control?

Also, when I add in my own code into the empty parts, the rest of the generated code turns into errors which doesn’t make sense since all I’m adding are motor ports for the controller.


#pragma platform(VEX)

//Competition Control and Duration Settings
#pragma competitionControl(Competition)
#pragma autonomousDuration(20)
#pragma userControlDuration(120)

#include "Vex_Competition_Includes.c"   //Main competition background code...do not modify!

/////////////////////////////////////////////////////////////////////////////////////////
//
//                          Pre-Autonomous Functions
//
// You may want to perform some actions before the competition starts. Do them in the
// following function.
//
/////////////////////////////////////////////////////////////////////////////////////////

void pre_auton()
{
        // All activities that occur before the competition starts
        // Example: clearing encoders, setting servo positions, ...
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 Autonomous Task
//
// This task is used to control your robot during the autonomous phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task autonomous()
{
  // .....................................................................................
  // Insert user code here.
  // .....................................................................................

        AuonomousCodePlaceholderForTesting();  // Remove this function call once you have "real" code.
}

/////////////////////////////////////////////////////////////////////////////////////////
//
//                                 User Control Task
//
// This task is used to control your robot during the user control phase of a VEX Competition.
// You must modify the code to add your own robot specific commands here.
//
/////////////////////////////////////////////////////////////////////////////////////////

task usercontrol()
{
        // User control code here, inside the loop

        while (true)
        {
          // This is the main execution loop for the user control program. Each time through the loop
          // your program should update motor + servo values based on feedback from the joysticks.

          // .....................................................................................
          // Insert user code here. This is where you use the joystick values to update your motors, etc.
          // .....................................................................................

          UserControlCodePlaceholderForTesting(); // Remove this function call once you have "real" code.
        }
}


task main is in the “Vex_Competition_Includes.c” file, along with some other code to make it communicate with the VEX Field Control system. When connected to a VEX Competition Control system, the system controls when the autonomous and user control sections start. When it’s not, the autonomous code runs first (for the duration specified at the top), then it automatically switches over to the user control period (also specified at the top).

More details here: http://www.robotc.net/support/vex/media/competitions/Using_the_ROBOTC_Competition_Templates.pdf

When I try to use my own functions, which are already defined, it says that function must be defined at main scope level. Does that mean it has to be defined in the main function?

You should be able to create your own functions in the template, but make sure you place them above the void pre_auton function.