Competition#

Introduction#

The competition class helps you structure a V5 project for official competition control. It lets you register functions to run during Autonomous and Driver Control, and provides simple status checks so your code can respond to match state (enabled/disabled, autonomous/driver, field control, etc.).

Class Constructors#

competition();

Class Destructor#

Destroys the competition object and releases associated resources.

~competition();

Parámetros#

This constructor does not accept any parameters.

Examples#

// Create the competition instance
competition Competition = competition();

Member Functions#

The competition class includes the following member functions:

  • autonomous — Registers a function to be called when the Autonomous period begins.

  • drivercontrol — Registers a function to be called when the Driver Control period begins.

  • isEnabled — Returns the status of your robot when under competition control.

  • isDriverControl — Returns whether the state of the robot is driver control.

  • isAutonomous — Returns whether the state of the robot is autonomous.

  • isCompetitionSwitch — Returns whether the competition switch is connected.

  • isFieldControl — Returns whether the field control is connected.

Before calling any competition member functions, a competition instance must be created, as shown below:

// Create the competition instance
competition Competition = competition();

autonomous#

Registers a function to be called when the Autonomous period begins.

Available Functions
void autonomous( void (* callback)(void) );

Parameters

Name

Type

Descripción

callback

void (*)(void)

A pointer to a function that takes no parameters and returns no value. This function will run when the Autonomous period starts.

Return Values

This function does not return a value.

Examples
void autonomousControl(void) {
  // Place automonous code here.
  Brain.Screen.clearScreen();
  Brain.Screen.print("autonomous");
}

int main(){
    // Create competition instance.
    competition Competition;

    // Set up callback for the autonomous control period.
    Competition.autonomous(autonomousControl);

    // Prevent main from exiting with an infinite loop.
    while (true) {
        wait(100, msec);
    }
}

drivercontrol#

Registers a function to be called when the Driver Control period begins.

Available Functions
void drivercontrol( void (* callback)(void) );

Parameters

Parameter

Type

Descripción

callback

void (*)(void)

A pointer to a function that takes no parameters and returns no value. This function will run when the Driver Control period starts.

Return Values

This function does not return a value.

Examples
void userControl(void) {
  Brain.Screen.clearScreen();
  // place driver control in this while loop
  while (true) {
    wait(20, msec);
  }
}

int main(){
    // Create competition instance.
    competition Competition;

    // Set up callback for the driver control period.
    Competition.drivercontrol(userControl);

    // Prevent main from exiting with an infinite loop.
    while (true) {
        wait(100, msec);
    }
}

isEnabled#

Returns the status of your robot when under competition control.

Available Functions
bool isEnabled();

Parameters

This function does not accept any parameters.

Return Values

Returns a Boolean indicating whether the autonomous or driver control period is active:

  • true – The autonomous or driver control period is active.

  • false – Neither control period is active.

isDriverControl#

Returns a Boolean indicating if the robot is in driver control mode.

Available Functions
bool isDriverControl();

Parameters

This function does not accept any parameters.

Return Values

Returns a Boolean indicating if the robot is in driver control mode:

  • true – The robot is in driver control mode.

  • false – The robot is not in driver control mode.

isAutonomous#

Returns a Boolean indicating if the robot is in autonomous mode.

Available Functions
bool isAutonomous();

Parameters

This function does not accept any parameters.

Return Values

Returns a Boolean indicating if the robot is in autonomous mode:

  • true – The robot is in autonomous mode.

  • false – The robot is not in autonomous mode.

isCompetitionSwitch#

Returns a Boolean indicating if the Competition Control Switch is connected:

Available Functions
bool isCompetitionSwitch();

Parameters

This function does not accept any parameters.

Notes
  • This function checks whether the Competition Control Switch is connected. The Competition Control Switch is used before the V5 Field Control System is in place.

Return Values

Returns a Boolean indicating if the Competition Control Switch is connected:

  • true – The Competition Control Switch is connected.

  • false – The Competition Control Switch is not connected.

isFieldControl#

Returns a Boolean indicating if the Field Controller is connected.

Available Functions
bool isFieldControl();

Parameters

This function does not accept any parameters.

Return Values

Returns a Boolean indicating if the Field Controller is connected:

  • true – The Field Controller is connected.

  • false – The Field Controller is not connected.