轴#
介绍#
The axis class is derived from the controller base class and provides access to the V5 Controller’s joysticks, allowing your robot to monitor changes in position along the four available axes.

使用权#
The controller class provides four axis objects (Axis1–Axis4). Each object is an instance of the axis class and can be accessed through a controller instance.
轴对象 |
用法示例 |
描述 |
|---|---|---|
|
|
右摇杆水平轴。 |
|
|
右摇杆垂直轴。 |
|
|
左摇杆垂直轴。 |
|
|
左摇杆水平轴。 |
笔记#
The
axisobject is provided by the controller. It is not constructed directly.
成员功能#
The Axis class includes the following member functions:
Before calling any axis member functions, a controller instance must be created, as shown below:
// Create a V5 controller instance
controller Controller = controller();
位置#
返回操纵杆轴的位置,数值为 -100 到 100 之间的整数,表示百分比。
Available Functionsint32_t position(
percentUnits units = percentUnits::pct ) const
此函数不接受任何参数。
Return ValuesThis function returns an int32_t as a percent from -100 to 100.
这个函数可以对任何控制器轴对象调用,例如:
Controller.Axis1Controller.Axis2Controller.Axis3Controller.Axis4
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);
}
已更改#
注册一个在操纵杆轴位置改变时运行的回调函数。
Available FunctionsThe controller provides four axis objects (Axis1–Axis4):
void changed(
void (* callback)(void) ) const;
范围 |
描述 |
|---|---|
|
预先定义的回调函数,当轴值发生变化时会自动调用。该函数必须符合所需的回调函数签名。有关更多信息,请参阅回调函数。 |
此函数不返回值。
Examples这个函数可以对任何控制器轴对象调用,例如:
Controller.Axis1Controller.Axis2Controller.Axis3Controller.Axis4
// Play a rumble pattern when the left joystick moves
void rumblePattern() {
Controller.rumble("..--");
wait(1, seconds);
}
// Call the rumble function when the left joystick moves
Controller.Axis4.changed(rumblePattern);