Controlador#
Introducción#
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 es compatible con el controlador V5. Consulte la API del controlador V5 para obtener más información.
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.
Clases derivadas#
The controller class provides the following derived classes:
Constructores#
1 - Crea un controlador utilizando el tipo de controlador principal. Normalmente se utiliza cuando hay un único controlador conectado.
controller();
2 - Crea un controlador para el tipo de controlador especificado. Se utiliza cuando se conectan dos controladores.
controller( controllerType id );
Funciones disponibles
controller();
controller(controllerType id);
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Optional. The controller type to create: |
Notas
Only one primary controller and one partner controller can be created in a single project.
Ejemplo
// Create the primary controller
controller Controller1 = controller();
// Create a partner controller
controller Controller2 = controller(partner);
Incinerador de basuras#
~controlador#
~controller destroys the controller object and releases associated resources.
Función disponible
~controller();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The type of controller being created:
|
Notas#
Only one
primaryand onepartnercontroller may exist in a single project.
Ejemplo#
// Create an EXP controller instance
controller Controller = controller();
Funciones de los miembros#
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.
retumbar#
rumble makes the controller vibrate using a pattern. In the pattern string, dots are short vibrations, dashes are long vibrations, and spaces are pauses.
Función disponible
void rumble(const char *str);
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Una cadena formada por puntos, guiones y espacios que representan el patrón de vibración. |
Valor de retorno
Esta función no devuelve ningún valor.
Ejemplo
// Rumble with a short-short-long pattern
Controller1.rumble("..-");
Adquiridor#
instalado#
installed returns whether the controller is connected to the Brain.
Función disponible
bool installed();
Parámetros
Esta función no tiene parámetros.
Valor de retorno
Devuelve un valor booleano.
true- The controller is installed/connected.false- The controller is not installed/connected.
Variables globales#
Código de control remoto habilitado#
RemoteControlCodeEnabled enables or disables controller actions configured in the Devices menu. Controller configured actions are enabled by default.
Usage:
RemoteControlCodeEnabled = state;
Valor |
Descripción |
|---|---|
|
Habilita las acciones configuradas por el controlador. |
|
Deshabilita las acciones configuradas por el controlador. |
true- Controller-configured actions are enabled.false- Controller-configured actions are disabled.
Las acciones configuradas por el controlador están habilitadas de forma predeterminada.
Esta variable solo funcionará al usar 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;