控制器#
介绍#
The IQ (2nd gen) Controller is represented by the controller class. You create a controller object and can access joystick input and button states.
IQ (2nd gen) additionally supports IQ (1st gen) controllers with a blue Smart Radio installed.
Derived Classes#
The controller class provides the following derived classes:
Class Constructors#
1 — Creates a controller using the primary controller type.
Typically used when a single controller is connected.controller();
2 — Creates a controller for the specified controller type.
Used when two controllers are connected.controller( controllerType id );
Class Destructor#
~controller();
参数#
范围 |
Type |
描述 |
|---|---|---|
|
|
The type of controller being created:
|
Notes#
Only one
primaryand onepartnercontroller may exist in a single project.
Example#
// Create a controller instance
controller Controller = controller();
Member Functions#
The controller class includes the following member functions:
installed— Checks whether the controller is connected to the brain.
installed#
Checks whether the controller is installed/connected.
Available Functionsbool installed();
This function does not accept any parameters.
Return ValuesReturns a Boolean indicating whether the controller is installed.
true— The controller is installed/connected.false— The controller is not installed/connected.
Global Variables#
When one or more controllers are configured in the Devices window, VEXcode IQ provides a global variable that controls the execution of controller-configured actions.
远程控制代码已启用#
Enables or disables controller-configured actions defined in the Devices configuration.
AssignmentRemoteControlCodeEnabled = false;
true— Controller-configured actions are enabled.false— Controller-configured actions are disabled.
Controller-configured actions are enabled by default.
// 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 the controller configured actions
} else if (Controller1.ButtonA.pressing()) {
break;
} else {
Drivetrain.stop();
}
wait(20, msec);
}
RemoteControlCodeEnabled = true;