保险杠开关#
介绍#
保险杠开关是一种机械开关,可以检测何时被按下和释放。
For the example belows, the configured Bumper Switch will be named bumper_1
and will be used in all subsequent examples throughout this API documentation when referring to Bumper
class methods.
以下是所有方法的列表:
Getters – 检查保险杠开关当前是否被按下。
pressing
– Returns whether the Bumper Switch is being pressed.
回调——当保险杠开关被按下或释放时运行代码。
pressed
– Calls a function when the Bumper Switch is pressed.released
– Calls a function when the Bumper Switch is released.
构造函数——手动初始化和配置保险杠开关。
Bumper
– Create a Bumper Switch.
吸气剂#
pressing#
pressing
returns an integer 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:
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)
参数 |
描述 |
---|---|
打回来 |
先前定义的 函数 在按下保险杠开关时执行。 |
arg |
可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数](…/Logic/Functions.md#functions-with-parameters)。 |
# 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)
参数 |
描述 |
---|---|
|
先前定义的 函数 在保险杠开关释放时执行。 |
|
可选。包含要传递给回调函数的参数的元组。更多信息,请参阅带参数的函数](…/Logic/Functions.md#functions-with-parameters)。 |
# 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(port)
范围 |
描述 |
---|---|
|
Which Smart Port that the Bumper Switch is connected to as |
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)