Create Competition.c

Competition.c

The “#pragma config” block is not written by hand but created with a GUI within the RobotC editor.  It allows the user to control all the settings of the Cortex ports (both input and output), including naming them, reversing directions of motors, and configuring  inputs for different sensors.  This is where we keep our master list of motor/sensor port numbers.  

The next few “#pragma” statements are straight from the template and required for competition.

The series of “# include” statements reference other files.  They essentially import text from a separate file, which allows for better organization of code by separating different parts into different files.  

“Vex_Competition_Includes.c” is the code underlying competition protocol as provided and mandated by VEX.  It manages things like going into autonomous, then teleop, then disabling once the match is over.  Again, this is provided by VEX and not to be modified.  

“Utilities.c”, “Constants.c”, “Subsystem_Functions.c”, “Autonomous_Selection.c”, and “Autonomous_Modes.c” are our own files.  Again, the “# include” statement effectively copies and pastes the files here; they are only written in separate files for organization.  

Each of these files contains a brief description of its contents:

“Utilities.c” includes functions independent of any robot, like mathematical functions and pieces of the PID logic.  
“Subsystem_Functions.c” defines all the functions of each subsystem of our robots.  For instance, it contains both the teleoperated and autonomous driving functions.
“Constants.c” is a listing of all the constants used.  Instead of hard-coding these into the functions that use them, they all reference here so that they can be tweaked easily.
“Autonomous_Selection.c” contains all the code required to make autonomous selection work.  When the robot starts up, if an LCD button is pressed, the screen allows the user to scroll through available autonomous routines and select run to run in that match.
“Autonomous_Modes.c” contains the actual routines to be run during autonomous mode.  These can be modified at any time and are easy to build from the building blocks defined in “Subsystem_Functions.c”.  


The robot has three modes it can be in: Pre-Auton, Autonomous, or User Control.  It goes into Pre-Auton automatically when it boots up, so this mode is used for setting various things that occur at startup.  In particular, the robot reads the port for the jumper clip and decides if it is the Dead or Alive robot and sets the arm potentiometer limits accordingly.  It ensures the launcher is in the retracted position.  Finally, if an LCD button is pressed, the robot transitions into autonomous selection mode (autonomous selection allows the user to scroll through the available autonomous routines and choose one to run).  

In the autonomous task, the only line is “runSelectedAutonomous();”.  This calls a function stored in the file “Autonomous_Modes.c” so that all the autonomous routines are stored in one place for easy editing.  

The user control task contains a “while(true)” loop with functions for each subsystem to be controlled by the operator.  All of these functions come from the “Subsystem_Functions.c” file.  This loop repeats the entire time the robot is in User Control mode and continuously updates all the motors based on the user’s input each time through.