保险杠#

介绍#

碰撞开关是一种弹簧式数字传感器,用于检测与物体的物理接触或碰撞。

红色的 VEX V5 碰撞开关。

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

以下是可用方法列表:

  • pressing – Returns whether the specified Bumper Switch is currently 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.

  • 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)

参数

描述

callback

一个先前定义的函数,当按下保险杠开关时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数

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)

参数

描述

callback

先前定义的 函数,当 Bumper 开关释放时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅带参数的函数

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)

范围

描述

port

The 3-Wire Port that the Bumper Switch is connected to:

  • On the V5 Brainbrain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expanderexpander.a where expander is the name of the expander instance.

# Create a Bumper Switch in Port A
bumper_switch = Bumper(brain.three_wire_port.a)