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();
参数#
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 Functionsvoid autonomous( void (* callback)(void) );
Name |
Type |
描述 |
|---|---|---|
|
|
A pointer to a function that takes no parameters and returns no value. This function will run when the Autonomous period starts. |
This function does not return a value.
Examplesvoid 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 Functionsvoid drivercontrol( void (* callback)(void) );
Parameter |
Type |
描述 |
|---|---|---|
|
|
A pointer to a function that takes no parameters and returns no value. This function will run when the Driver Control period starts. |
This function does not return a value.
Examplesvoid 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 Functionsbool isEnabled();
This function does not accept any parameters.
Return ValuesReturns 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 Functionsbool isDriverControl();
This function does not accept any parameters.
Return ValuesReturns 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 Functionsbool isAutonomous();
This function does not accept any parameters.
Return ValuesReturns 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 Functionsbool isCompetitionSwitch();
This function does not accept any parameters.
NotesThis function checks whether the Competition Control Switch is connected. The Competition Control Switch is used before the V5 Field Control System is in place.
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 Functionsbool isFieldControl();
This function does not accept any parameters.
Return ValuesReturns a Boolean indicating if the Field Controller is connected:
true– The Field Controller is connected.false– The Field Controller is not connected.