陀螺儀感應器#
介紹#
gyro 類用於測量機器人的航向和旋轉運動,從而可以追蹤其隨時間推移的姿態。
類別建構函數#
gyro(
triport::port &port);
類別析構函數#
銷毀 gyro 物件並釋放相關資源。
virtual ~gyro();
參數#
範圍 |
類型 |
描述 |
|---|---|---|
|
|
陀螺儀感測器連接的 3 線端口,寫成 |
例子#
// Create a gyro instance in Port A
gyro GyroA = gyro(Brain.ThreeWirePort.A);
成員功能#
gyro 類別包含以下成員函數:
calibrate— 校準陀螺儀以達到穩定的航向追蹤。setHeading— 設定陀螺儀的航向。setRotation— 設定陀螺儀的目前旋轉值。heading— 返回陀螺儀的航向。rotation— 返回陀螺儀的旋轉角度。
在呼叫任何 gyro 成員函數之前,必須先建立一個 gyro 實例,如下所示:
/* This constructor is required when using VS Code.
Gyro Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create a gyro instance in Port A
gyro GyroA = gyro(Brain.ThreeWirePort.A);
calibrate#
校準陀螺儀感測器。
Available Functionsvoid calibrate(
int32_t value = 0 );
參數 |
類型 |
描述 |
|---|---|---|
|
|
校準所需時間(秒)。預設值為 |
此函數不傳回值。
Notescalibrate僅應在感測器不移動時調用。
// Start calibration with the calibration time set to 3 seconds.
GyroA.calibrate(3);
setHeading#
將陀螺儀感測器的航向設定為特定值。
Available Functionsvoid setHeading(
double value,
rotationUnits units );
參數 |
類型 |
描述 |
|---|---|---|
|
|
新標題要使用的值。 |
|
|
表示航向的單位:
|
此函數不傳回值。
setRotation#
將陀螺儀感應器的旋轉角度設定為特定值。
Available Functionsvoid setRotation(
double value,
rotationUnits units );
參數 |
類型 |
描述 |
|---|---|---|
|
|
要用於新旋轉值的值。 |
|
|
表示旋轉值的單位:
|
此函數不傳回值。
heading#
返回陀螺儀感測器的目前航向。
Available Functionsdouble heading(
rotationUnits units = degrees );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
表示航向的單位:
|
傳回一個 double 表示陀螺儀感測器的目前航向,單位為指定值,預設為 degrees。
// Get the current heading for the Gyro.
double value = GyroA.heading();
Brain.Screen.print(value);
rotation#
返回陀螺儀感應器的目前旋轉角度。
Available Functionsdouble rotation(
rotationUnits units = degrees );
範圍 |
類型 |
描述 |
|---|---|---|
|
|
表示旋轉值的單位:
|
傳回一個 double 表示陀螺儀感測器的目前旋轉值,單位為指定值,預設為 degrees。
// Get the current rotation for the Gyro.
double value = GyroA.rotation();
Brain.Screen.print(value);