轴#
介绍#
axis 类是 controller 类的派生类。它提供对 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 返回操纵杆轴的位置,值范围为 -100 到 100。
可用功能
int32_t position(percentUnits units = percentUnits::pct) const;
范围 |
类型 |
描述 |
|---|---|---|
|
|
可选。返回的轴值所使用的单位。默认值为 |
返回值
Returns an int32_t value from -100 to 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 当操纵杆的位置沿该轴改变时运行一个函数。
可用功能
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);
}