竞赛#
初始化竞赛类#
竞争控制是使用以下构造函数创建的:
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.
类方法#
autonomous()#
The autonomous(callback) method runs a callback function when the autonomous period starts.
参数 |
描述 |
|---|---|
|
当调用自主函数时运行的函数。 |
**返回:**无。
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.
参数 |
描述 |
|---|---|
|
当调用 drivercontrol 函数时运行的函数。 |
**返回:**无。
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.