电位器#

介绍#

电位器是一种模拟传感器,用于测量旋转轴的角位置。它输出的电压与其位置成正比。

根据电位器型号的不同,其可检测的旋转量也不同:

  • 电位器 – 最高可达 250 度

  • 电位器 V2 – 330 度(连续)

VEX V5 电位器 V1.

VEX V5 电位器 V2.

电位器

电位器 V2

本页面使用 potentiometer_a 作为电位器名称示例。请根据需要将其替换为您自己配置的名称。

以下是可用方法列表:

  • angle – 返回电位器的角度位置(以度或百分比表示)。

  • changed – 注册一个函数,当电位器的值发生变化时,该函数将被调用。

构造函数 – 手动初始化电位器或电位器 V2。

角度#

angle 返回电位器的角度位置,以度或百分比表示。

Usage:
potentiometer_a.angle(units)

范围

描述

units

计量单位:

  • DEGREES (默认)
    • 电位器:0.0 至 250.0
    • 电位器 V2:0.0 至 330.0
  • PERCENT – 位置以全旋转百分比表示(0% 至 100%)

已更改#

changed 注册一个函数,当电位器的值发生变化时,该函数将被调用。

Usage:
changed(callback, arg)

参数

描述

callback

先前定义的 函数,当电位器的值发生变化时执行。

arg

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

def my_function():
  brain.screen.print("Value changed!")

# Call my_function whenever potentiometer_a's angle changes
potentiometer_a.changed(my_function)

构造函数#

构造函数用于手动创建 PotentiometerV2 和 Potentiometer 对象,这是在 VEXcode 之外配置电位器所必需的。

PotentiometerV2#

PotentiometerV2 产生 V5 电位器 V2。

Usage:
PotentiometerV2(port)

范围

描述

port

The 3-Wire Port that the Potentiometer V2 is connected to:

  • On the V5 Brain – brain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expander – expander.a where expander is the name of the expander instance.

# Create a Potentiometer V2 in Port A
potentiometer_a = PotentiometerV2(brain.three_wire_port.a)

Potentiometer#

Potentiometer 创建一个电位器。

Usage:
Potentiometer(port)

范围

描述

port

The 3-Wire Port that the Potentiometer is connected to:

  • On the V5 Brain – brain.three_wire_port.x where x is the number of the port.
  • On a 3-Wire Expander – expander.a where expander is the name of the expander instance.

# Create a Potentiometer in Port A
potentiometer_a = Potentiometer(brain.three_wire_port.a)