电位器#

介绍#

pot 和 potV2 类与电位器配合使用,电位器是一种模拟传感器,用于测量旋转轴的角位置。电位器输出的电压与其位置成正比。

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

  • 电位器 - 最高可达 250 度

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

VEX V5 电位器 V1.

VEX V5 电位器 V2.

电位器

电位器 V2

电位器#

Class Constructors#

pot(
  triport::port &port );

Class Destructor#

销毁 pot 对象并释放相关资源。

~pot();

Parameters#

范围

类型

描述

port

triport::port &

电位器连接的 3 线端口,写成 Brain.ThreeWirePort.X 或 ExpanderName.X,其中 X 是端口字母(例如, Brain.ThreeWirePort.A 或 Expander1.A)。

Example#

// Create a pot instance in Port A
pot PotentiometerA = pot(Brain.ThreeWirePort.A);

电位器 V2#

Class Constructors#

potV2(
  triport::port &port );

Class Destructor#

销毁 potV2 对象并释放相关资源。

~potV2();

Parameters#

范围

类型

描述

port

triport::port &

电位器 V2 连接的 3 线端口,写成 Brain.ThreeWirePort.X 或 ExpanderName.X,其中 X 是端口字母(例如, Brain.ThreeWirePort.A 或 Expander1.A)。

Examples#

// Create a Potentiometer V2 on 3-Wire Port A
potV2 PotentiometerV2A = potV2(Brain.ThreeWirePort.A);

成员功能#

pot 和 potV2 类包含以下成员函数:

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

在调用任何 pot 或 potV2 成员函数之前,必须创建 pot 或 potV2 实例,如下所示:

/* This constructor is required when using VS Code.
Potentiometer configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */

// Create a potV2 instance in Port A
potV2 PotentiometerV2A = potV2(Brain.ThreeWirePort.A);

angle#

返回电位器的角度位置。

1 — 此函数以百分比表示角度。

int32_t angle (
  percentUnits units = percentUnits::pct );

2 — 此函数以选定的旋转单位表示角度。

double angle(
  rotationUnits units );

Parameters

范围

类型

描述

units

percentUnits

表示位置占完整旋转百分比的单位: percent / pct (默认值)— 百分比,从 0 到 100%。

units

rotationUnits

表示角度的单位:

  • deg / degrees — 度,电位器为 0 至 250 度,电位器 V2 为 0 至 330 度
  • turns / rev — 转

Return Values

返回:

  • 使用 percentUnits时,int32_t 为 。

  • 当使用 double , rotationUnits。

Examples
// Get the current angle of the Potentiometer V2 in the
// range 0 to 330 degrees.
double angle = PotentiometerV2A.angle(degrees);

// Print the current angle of the Potentiometer to the
// brain screen.
Brain.Screen.print(angle);