竞赛#

初始化竞赛类#

竞争控制是使用以下构造函数创建的:

competition() 构造函数创建一个竞赛对象。可以使用 drivercontrol()autonomous() 方法添加要在驾驶员或自主控制期间运行的函数。

// create competition instance
competition Competition;

当引用 Competition 类方法时,此“Competition”对象将在整个 API 文档的所有后续示例中使用。

类方法#

自主()#

当自主阶段开始时,autonomous(callback) 方法运行回调函数。

参数

描述

打回来

当调用自主函数时运行的函数。

**返回:**无。

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(callback) 方法在驱动程序控制周期开始时回调一个函数。

参数

描述

打回来

当调用 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() 方法返回机器人在比赛控制下的状态。

**返回:**一个布尔值,表示自主控制周期或驾驶员控制周期是否处于活动状态。如果其中一个处于活动状态,则该方法将返回“true”。如果两个控制周期均未处于活动状态,则返回“false”。

是DriverControl()#

isDriverControl() 方法检查机器人的状态是否为驱动控制。

**返回:**如果机器人处于驱动控制模式,则返回“true”。如果不处于驱动控制模式,则返回“false”。

是否自主()#

isAutonomous() 方法检查机器人的状态是否为自主。

**返回:**如果机器人处于自主模式,则返回“true”。如果不是自主模式,则返回“false”。

是竞争切换()#

isCompetitionSwitch() 方法检查比赛开关是否已连接。

**返回:**如果比赛开关已连接,则返回 true。如果未连接,则返回 false

是FieldControl()#

isFieldControl() 方法检查字段控件是否已连接。

返回: 如果字段控件已连接,则返回 true。如果未连接,则返回 false