軸#
介紹#
axis 類別是 controller 類別的衍生類別。它提供對控制器操縱桿軸值和操縱桿軸更改回調的存取。
An axis object is accessed through a controller object. It is not constructed directly.

使用權#
controller 類別提供以下軸物件。每個物件都是 axis 類別的一個實例。
軸對象 |
用法範例 |
描述 |
|---|---|---|
|
|
右搖桿水平軸。 |
|
|
右搖桿垂直軸。 |
|
|
左搖桿垂直軸。 |
|
|
左搖桿水平軸。 |
筆記#
在使用
axis成員函數之前,請建立一個controller物件。位置
position傳回的值介於-100到100之間。
// Create a controller object
controller Controller = controller();
成員功能#
axis 類別包含以下成員函數:
獲取器 — 讀取操縱桿軸位置。
position— 返回操縱桿軸的位置。
回呼函數-當搖桿沿著某個軸的位置改變時,執行一個函數。
changed— 當操縱桿的位置沿該軸改變時運行函數。
Getter#
position#
position 返回操縱桿軸的位置,值範圍為 -100 到 100。
可用功能
int32_t position(percentUnits units = percentUnits::pct) const;
範圍 |
類型 |
描述 |
|---|---|---|
|
|
可選。傳回的軸值所使用的單位。預設值為 |
傳回值
返回 int32_t 值,范围从 -100 到 100。
100— 操縱桿軸已完全朝正方向移動。0— 操縱桿軸居中。-100— 操縱桿軸完全向負方向移動。
例子
// Turn with the left joystick
while (true) {
if (Controller.Axis4.position() > 10) {
Drivetrain.turn(right);
}
else if (Controller.Axis4.position() < -10) {
Drivetrain.turn(left);
}
else {
Drivetrain.stop();
}
wait(20, msec);
}
打回來#
changed#
changed 當操縱桿的位置沿著該軸改變時運行一個函數。
可用功能
void changed(void (* callback)(void)) const;
範圍 |
類型 |
描述 |
|---|---|---|
|
|
每次操縱桿沿該軸位置變化時運行的函數。 |
傳回值
此函數不傳回值。
例子
在 main之外定義回呼函數。
// Rumble when the left joystick moves
void controllerRumble() {
Controller.rumble(".");
}
在 main中註冊回呼。
int main() {
vexcodeInit();
// Run controllerRumble when the joystick's position changes along Axis4
Controller.Axis4.changed(controllerRumble);
}