控制器#
介绍#
The controller class represents a VEX EXP Controller connected to the EXP Brain. A controller object can be used to access joystick axis values, read button states, register button or joystick callbacks, make the controller rumble, and check whether the controller is connected.
VEX EXP 与 V5 控制器兼容。有关更多信息,请参阅 V5 控制器 API。
When one or more controllers are configured in the Devices window, VEXcode EXP also provides RemoteControlCodeEnabled. This global variable enables or disables controller actions configured in the Devices menu.
派生类#
The controller class provides the following derived classes:
构造函数#
1 - 使用主控制器类型创建控制器。通常用于连接单个控制器的情况。
controller();
2 - 为指定的控制器类型创建一个控制器。用于连接两个控制器时。
controller( controllerType id );
可用功能
controller();
controller(controllerType id);
范围 |
类型 |
描述 |
|---|---|---|
|
|
Optional. The controller type to create: |
笔记
Only one primary controller and one partner controller can be created in a single project.
例子
// Create the primary controller
controller Controller1 = controller();
// Create a partner controller
controller Controller2 = controller(partner);
毁灭者#
控制器#
~controller destroys the controller object and releases associated resources.
可用功能
~controller();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The type of controller being created:
|
笔记#
Only one
primaryand onepartnercontroller may exist in a single project.
例子#
// Create an EXP controller instance
controller Controller = controller();
成员功能#
The controller class includes the following member functions:
rumble- Rumbles the controller using a pattern.installed- Checks whether the controller is connected to the brain.
隆隆#
rumble makes the controller vibrate using a pattern. In the pattern string, dots are short vibrations, dashes are long vibrations, and spaces are pauses.
可用功能
void rumble(const char *str);
范围 |
类型 |
描述 |
|---|---|---|
|
|
由点、短划线和空格组成的字符串,代表隆隆声模式。 |
返回值
此函数不返回值。
例子
// Rumble with a short-short-long pattern
Controller1.rumble("..-");
Getter#
已安装#
installed returns whether the controller is connected to the Brain.
可用功能
bool installed();
参数
此函数没有参数。
返回值
返回布尔值。
true- The controller is installed/connected.false- The controller is not installed/connected.
全局变量#
RemoteControlCodeEnabled#
RemoteControlCodeEnabled enables or disables controller actions configured in the Devices menu. Controller configured actions are enabled by default.
Usage:
RemoteControlCodeEnabled = state;
价值 |
描述 |
|---|---|
|
启用控制器配置的操作。 |
|
禁用控制器配置的操作。 |
true- Controller-configured actions are enabled.false- Controller-configured actions are disabled.
控制器配置的操作默认启用。
此变量仅在使用 VEXcode 时有效。
// Drive forward or backward using the left joystick
RemoteControlCodeEnabled = false;
while (true) {
if (Controller1.Axis3.position() > 0) {
Drivetrain.drive(forward);
}
else if (Controller1.Axis3.position() < 0) {
Drivetrain.drive(reverse);
}
// Press A to use controller configured actions again
else if (Controller1.ButtonA.pressing()) {
break;
}
else {
Drivetrain.stop();
}
wait(20, msec);
}
RemoteControlCodeEnabled = true;