保险杠#
介绍#
The Bumper Switch is a mechanical switch that completes a circuit when pressed, allowing the robot to detect presses and releases.
VEX EXP 碰撞开关是一款三线设备/_static/img/sensing/bumper_switch_1_new_image.png带有一个宽大的黑色底座,用于将其连接到机器人上,顶部有一个红色可按压按钮。
This page uses bumper_switch 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 whenever the Bumper Switch is pressed.released– Registers a function to be called whenever the Bumper Switch is released.
构造函数 – 手动初始化和配置碰撞开关。
Bumper– Create a Bumper Switch.
紧迫#
pressing returns a Boolean indicating whether the Bumper Switch is currently being pressed. This can be used to check if the robot bumps into other objects.
True– The Bumper Switch is being pressed.False– The Bumper Switch is not being pressed.
Usage:
bumper_switch.pressing()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display a message after bumper_switch is pressed
while not bumper_switch.pressing():
pass
brain.screen.print("Bumper Switch pressed!")
按下#
pressed registers a function to be called whenever the Bumper Switch is pressed.
Usage:
bumper_switch.pressed(callback, arg)
参数 |
描述 |
|---|---|
|
一个先前定义的函数,当按下保险杠开关时执行。 |
|
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
def my_function():
brain.screen.print("Pressed")
# Call my_function whenever bumper_switch is pressed
bumper_switch.pressed(my_function)
发布#
released registers a function to be called whenever the Bumper Switch is released.
Usage:
bumper_switch.released(callback, arg)
参数 |
描述 |
|---|---|
|
先前定义的 函数,当 Bumper 开关释放时执行。 |
|
Optional. A tuple containing arguments to pass to the callback function. See Functions with Parameters for more information. |
def my_function():
brain.screen.print("Released")
# Call my_function whenever bumper_switch is released
bumper_switch.released(my_function)
构造器#
Constructors are used to manually create Bumper objects, which are necessary for configuring a Bumper Switch outside of VEXcode.
Bumper#
Bumper creates a Bumper Switch.
Usage:
Bumper(port)
范围 |
描述 |
|---|---|
|
The 3-Wire Port that the Bumper Switch is connected to:
|
# Create a Bumper Switch in Port A
bumper_switch = Bumper(brain.three_wire_port.a)