竞赛#
介绍#
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.).
类构造函数#
competition();
类析构函数#
Destroys the competition object and releases associated resources.
~competition();
参数#
此构造函数不接受任何参数。
示例#
// Create the competition instance
competition Competition = competition();
成员功能#
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#
注册一个在自主期开始时要调用的函数。
Available Functionsvoid autonomous( void (* callback)(void) );
姓名 |
类型 |
描述 |
|---|---|---|
|
|
指向一个不接受任何参数且不返回任何值的函数的指针。该函数将在自主学习阶段开始时运行。 |
此函数不返回值。
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#
注册一个在驾驶员控制期开始时要调用的函数。
Available Functionsvoid drivercontrol( void (* callback)(void) );
范围 |
类型 |
描述 |
|---|---|---|
|
|
指向一个不接受任何参数且不返回任何值的函数的指针。此函数将在驾驶员控制期开始时运行。 |
此函数不返回值。
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#
返回你的机器人在比赛控制下的状态。
Available Functionsbool isEnabled();
此函数不接受任何参数。
Return Values返回一个布尔值,指示自主控制期或驾驶员控制期是否处于活动状态:
true– The autonomous or driver control period is active.false– Neither control period is active.
isDriverControl#
返回一个布尔值,指示机器人是否处于驾驶员控制模式。
Available Functionsbool isDriverControl();
此函数不接受任何参数。
Return Values返回一个布尔值,指示机器人是否处于驾驶员控制模式:
true– The robot is in driver control mode.false– The robot is not in driver control mode.
isAutonomous#
返回一个布尔值,指示机器人是否处于自主模式。
Available Functionsbool isAutonomous();
此函数不接受任何参数。
Return Values返回一个布尔值,指示机器人是否处于自主模式:
true– The robot is in autonomous mode.false– The robot is not in autonomous mode.
isCompetitionSwitch#
返回一个布尔值,指示竞赛控制开关是否已连接:
Available Functionsbool isCompetitionSwitch();
此函数不接受任何参数。
Notes此功能检查比赛控制开关是否已连接。比赛控制开关在V5现场控制系统安装之前使用。
返回一个布尔值,指示竞赛控制开关是否已连接:
true– The Competition Control Switch is connected.false– The Competition Control Switch is not connected.
isFieldControl#
返回一个布尔值,指示现场控制器是否已连接。
Available Functionsbool isFieldControl();
此函数不接受任何参数。
Return Values返回一个布尔值,指示字段控制器是否已连接:
true– The Field Controller is connected.false– The Field Controller is not connected.