保险杠#

介绍#

VEX IQ(第二代)Bumper 类别提供了与 Bumper 开关交互的方法。

This page uses Bumper1 as the example Bumper Switch name. Replace it with your own configured name as needed.

以下是所有可用方法的列表:

动作——与保险杠开关互动。

  • pressed – Calls a function when the Bumper Switch is pressed.

  • released – Calls a function when the Bumper Switch is released.

Getters – 从保险杠开关返回数据。

  • pressing – Returns whether the Bumper Switch is being pressed.

  • installed – Whether the Bumper Switch is connected to the Brain.

构造函数 - 手动初始化保险杠开关。

  • bumper – Create a Bumper Switch.

行动#

pressed#

pressed calls a function when the bumper switch is pressed.

Usage:
Bumper1.pressed(callback);

范围

描述

callback

先前定义的当按下保险杠开关时执行的功能。

// Drive forward when the Bumper Switch is pressed
void onBumperPressed() {
  Drivetrain.driveFor(forward, 100, mm);
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Call onBumperPressed when the Bumper is pressed
  Bumper1.pressed(onBumperPressed);
}

released#

released calls a function when the bumper switch is released.

Usage:
Bumper1.released(callback);

范围

描述

callback

先前定义的在释放保险杠开关时执行的功能。

// Drive backward when the Bumper Switch is released
void onBumperReleased() {
  Drivetrain.driveFor(reverse, 100, mm);
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Call onBumperReleased when the Bumper is released
  Bumper1.released(onBumperReleased);
}

吸气剂#

pressing#

pressing returns a Boolean indicating whether the Bumper Switch is currently being pressed.

  • 1 - The Bumper Switch is being pressed.

  • 0 - The Bumper Switch is not being pressed.

Usage:
Bumper1.pressing()

参数

描述

该方法没有参数。

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Drive forward until the Bumper is pressed
  while (true) {
    Drivetrain.drive(forward);

    // If pressed, stop and back up
    if (Bumper1.pressing()) {
      Drivetrain.stop();
      Drivetrain.driveFor(reverse, 100, mm);
      break;
    }

    wait(20, msec);
  }
}

installed#

installed returns a Boolean indicating whether the Bumper Switch is currently connected to the Brain.

  • 1 – The Bumper Switch is connected to the Brain.

  • 0 – The Bumper Switch is not connected to the Brain.

Usage:
Bumper1.installed()

参数

描述

该方法没有参数。

构造函数#

bumper#

bumper creates an object of the bumper Class in the specified port.

Usage:
bumper Bumper1 = bumper(smartport);

范围

描述

smartport

保险杠开关所连接的智能端口,记为 PORTx,其中 x 为端口号。

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Create a Bumper object in Port 3
  bumper CustomBumper = bumper(PORT3);
}