competition#
Initializing the Competition Class#
Competition Control is created by using the following constructor:
The competition()
constructor creates a competition object. Functions to be run in driver or autonomous control periods can be added using the drivercontrol()
and autonomous()
methods.
// create competition instance
competition Competition;
This Competition
object will be used in all subsequent examples throughout this API documentation when referring to Competition class methods.
Class Methods#
autonomous()#
The autonomous(callback)
method runs a callback function when the autonomous period starts.
Parameters |
Description |
---|---|
callback |
A function to run when the autonomous function is called. |
Returns: None.
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()#
The drivercontrol(callback)
method calls back a function when the driver control period starts.
Parameters |
Description |
---|---|
callback |
A function to run when the drivercontrol function is called. |
Returns: None.
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()#
The isEnabled()
method returns the status of your robot when under competition control.
Returns: A Boolean value representing if the autonomous or driver control period is active. If either one is active, the method will return true
. false
if neither control period is active.
isDriverControl()#
The isDriverControl()
method checks if the state of the robot is driver control.
Returns: true
if the robot is in driver control mode. false
if it is not in driver control mode.
isAutonomous()#
The isAutonomous()
method checks if the state of the robot is autonomous.
Returns: true
if the robot is in autonomous mode. false
if it is not in autonomous.
isCompetitionSwitch()#
The isCompetitionSwitch()
method checks if the competition switch is connected.
Returns: true
if the competition switch is connected. false
if it is not connected.
isFieldControl()#
The isFieldControl()
method checks if the field control is connected.
Returns: true
if the field control is connected. false
if it is not connected.