保险杠开关#
介绍#
The Bumper Switch is a mechanical switch that completes a circuit when pressed, allowing the robot to detect presses and releases.
This page uses bumper_1 as the example Bumper Switch name. Replace it with your own configured name as needed.
以下是所有方法的列表:
检查器 — 检查肩键开关当前是否被按下。
pressing— Returns whether the Bumper Switch is being pressed.
回调函数——当肩键开关被按下或释放时运行代码。
pressed— Registers a function to be called when the Bumper Switch is pressed.released— Registers a function to be called when the Bumper Switch is released.
构造函数 — 手动初始化和配置碰撞开关。
Bumper— Create a Bumper Switch.
吸气剂#
pressing#
pressing returns an integer indicating whether the Bumper Switch is being pressed. This can be used to check if the robot bumps into other objects.
1— The Bumper Switch is being pressed.0— The Bumper Switch is not being pressed.
Usage:
bumper_1.pressing()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Back up and turn if bumper switch
# is pressed
while True:
drivetrain.drive(FORWARD)
if bumper_1.pressing():
drivetrain.drive_for(REVERSE, 100, MM)
drivetrain.turn_for(RIGHT, 90, DEGREES)
打回来#
pressed#
pressed registers a function to be called when the Bumper Switch is pressed.
Usage:
bumper_1.pressed(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数 在按下保险杠开关时执行。 |
|
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
# Drive forward when bumper switch
# is pressed
def bumper_pressed():
drivetrain.drive_for(FORWARD, 100, MM)
bumper_1.pressed(bumper_pressed)
released#
released registers a function to be called when the Bumper Switch is released.
Usage:
bumper_1.released(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数 在保险杠开关释放时执行。 |
|
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
# Drive reverse when bumper switch
# is released
def bumper_released():
drivetrain.drive_for(REVERSE, 100, MM)
bumper_1.released(bumper_released)
构造函数#
Constructors are used to manually create Bumper objects, which are necessary for configuring a Bumper Switch outside of VEXcode.
Bumper Switch#
Bumper creates a Bumper Switch.
Usage:
Bumper(smartport)
范围 |
描述 |
|---|---|
|
保险杠开关所连接的智能端口,记为 PORTx,其中 x 为端口号。 |
bumper_1 = Bumper(PORT1)
# Back up and turn if bumper switch pressed
while True:
drivetrain.drive(FORWARD)
if bumper_1.pressing():
drivetrain.drive_for(REVERSE, 100, MM)
drivetrain.turn_for(RIGHT, 90, DEGREES)