旋轉感應器#

介紹#

rotation 類用於控制和存取 EXP 旋轉感測器的資料。

旋轉感測器用於測量軸的旋轉。它可以用於機器人上任何有軸旋轉的地方,即使該軸沒有直接連接到馬達。

馬達內建編碼器,可追蹤自身的旋轉。旋轉感測器的工作原理類似於外部編碼器,可以追蹤獨立軸的旋轉。

旋轉感測器可以返回軸的角度、位置和速度。角度是指軸的絕對位置,範圍從 0 度到 359.99 度。當專案開始或機器人斷電時,角度不會重置。位置感測器追蹤軸在專案進行期間正向或反向旋轉的角度或圈數,並且可以根據需要進行重置。

旋轉感測器相容於 1/8 英吋和 1/4 英吋標準 VEX 軸。

類別建構函數#

rotation(
    int32_t index,
    bool    reverse = false );

類別析構函數#

銷毀旋轉角度為 rotation 對象並釋放相關資源。

virtual ~rotation();

參數#

範圍

類型

描述

index

int32_t

旋轉感測器連接的智慧型端口,記為 PORTx,其中 x 是端口號(例如, PORT1)。

reverse

bool

Optional. Whether to reverse the Rotation Sensor output:

  • true — Reverses the direction of the reported angle and position values.
  • false (default) — Reports angle and position values in the standard direction.

範例#

// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);

成員功能#

rotation 類別包含以下成員函數:

  • setPosition — 將旋轉感測器的目前位置設定為特定值。

  • angle — 返回軸的當前角度,範圍從 0 到 359.99 度。

  • position — 返回軸旋轉的角度或圈數。

  • velocity — 返回軸的旋轉速度。

在呼叫任何 rotation 成員函數之前,必須建立一個 rotation 實例,如下所示:

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

// Create a Rotation Sensor instance in Port 1
rotation Rotation1 = rotation(PORT1);

setPosition#

將旋轉感測器的目前位置設定為特定值。

位置是指軸在專案進行過程中旋轉的距離。設定位置會在不移動軸的情況下改變目前位置值。

Available Functions
void setPosition(
    double        value,
    rotationUnits units );

Parameters

範圍

類型

描述

value

double

要指派給旋轉感測器的位置值。該值可以是整數或小數。

units

rotationUnits

The position unit:

  • deg / degrees — degrees
  • turns / rev — turns

Return Values

此函數不傳回值。

angle#

返回軸的當前角度。

角度值表示軸在一個旋轉週期內的絕對位置,範圍從 0 到 359.99 度。專案開始或機器人斷電時,該值不會重設。

Available Functions
double angle( rotationUnits units = degrees );

Parameters

範圍

類型

描述

units

rotationUnits

可選。角度單位:

  • deg / degrees (預設)— 度
  • turns / rev — 圈

Return Values

傳回一個 double ,表示軸的目前角度(以指定的單位表示)。

Examples
// Get the current angle of the shaft
  double angle = Rotation1.angle(degrees);

  // Print the current angle of the shaft to the
  // Brain's screen.
  Brain.Screen.print(angle);

position#

返回軸旋轉的距離。

與角度不同,位置可以超過 359.99 度,也可以低於 0 度。位置參數追蹤軸在專案進行過程中正向或反向旋轉的距離,並可依需求進行重設。

Available Functions
double position( rotationUnits units );

Parameters

範圍

類型

描述

units

rotationUnits

The position unit:

  • deg / degrees — degrees
  • turns / rev — turns

Return Values

傳回一個 double 表示軸以指定單位旋轉了多少度。

velocity#

返回軸的旋轉速度。

Available Functions
double velocity( velocityUnits units );

Parameters

範圍

類型

描述

units

velocityUnits

速度單位:

  • rpm — 每分鐘轉數
  • dps — 每秒度數

Return Values

傳回 double ,表示軸以指定單位旋轉的速度。