Controlador#
Introducción#
El Brain IQ (2.ª generación) se puede conectar a un mando IQ (2.ª generación) o a un mando IQ (1.ª generación). Ambos mandos cuentan con dos joysticks analógicos y varios botones que el Brain puede usar para detectar movimientos y pulsaciones.
For the examples below, the configured Distance Sensors will be named Controller, and will be used in all subsequent examples throughout this API documentation when referring to Controller class methods.
A continuación se muestra una lista de los métodos disponibles:
Acciones: habilitar o deshabilitar el controlador.
RemoteControlCodeEnabled– Enables or disables controller configured actions.
Getters: devuelven valores de los joysticks y botones del controlador.
pressing– Returns whether the specified button is being pressed.position– Returns the position of the joystick’s specified axis.
Devolución de llamada: interactúa con el controlador a través de métodos de devolución de llamada.
pressed– Calls a function when the specified button is pressed.released– Calls a function when the specified button is released.changed– Calls a function when the joystick’s axis changes.
Constructores: inicializan manualmente el controlador.
controller– Create a Controller.
Comportamiento#
RemoteControlCodeEnabled#
RemoteControlCodeEnabled is a variable that can be set to a Boolean that enables or disables Controller configured actions from the Devices menu. The controller is enabled by default. It can be set to either of the following:
true— Enable Controller configured actions.false— Disable Controller configured actions.
Usage:
RemoteControlCodeEnabled = false;
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Drive forward or backward using the left joystick
RemoteControlCodeEnabled = false;
while (true) {
if (Controller.AxisA.position() > 0) {
Drivetrain.drive(forward);
} else if (Controller.AxisA.position() < 0) {
Drivetrain.drive(reverse);
// Press E ▲ to use the controller configured actions
} else if (Controller.ButtonEUp.pressing()) {
break;
} else {
Drivetrain.stop();
}
wait(20, msec);
}
RemoteControlCodeEnabled = true;
}
Captadores#
pressing#
pressing returns an integer indicating whether a specific button on the controller is currently being pressed. This method must be called on a specific button object, such as ButtonEDown (see full list of button objects below).
1- The specified button is being pressed.0- The specified button is not being pressed.
Uso:
Se puede usar uno de los diez objetos de botón disponibles con este método, como se muestra a continuación:
Botón |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn right while E Up is held
while (true) {
if (Controller.ButtonEUp.pressing()) {
Drivetrain.turn(right);
} else {
Drivetrain.stop();
}
wait(20, msec);
}
}
position#
position returns the position of the joystick’s specified axis as an integer from –100 to 100, representing a percentage. This method must be called on a specific axis object, such as AxisA (see full list of axis objects below).
Uso:
Se puede utilizar uno de los cuatro ejes disponibles con este método, como se muestra a continuación:
Eje |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Turn with the left joystick
RemoteControlCodeEnabled = false;
while (true) {
if (Controller.AxisB.position() > 10) {
Drivetrain.turn(right);
} else if (Controller.AxisB.position() < -10) {
Drivetrain.turn(left);
} else {
Drivetrain.stop();
}
wait(20, msec);
}
}
Llamar de vuelta#
pressed#
pressed registers a function to be called when a specific button on the controller is pressed. This method must be called on a specific button object, such as ButtonEDown – (see full list of button objects below).
Uso:
Se puede usar uno de los diez objetos de botón disponibles con este método, como se muestra a continuación:
Botón |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parámetro |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se presione el botón especificado. |
// Drive forward when E Up is pressed
void driveForward() {
Drivetrain.driveFor(forward, 100, mm);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Controller.ButtonEUp.pressed(driveForward);
}
released#
released registers a function to be called when a specific button on the controller is released. This method must be called on a specific button object, such as ButtonEDown – (see full list of button objects below).
Uso:
Se puede usar uno de los diez objetos de botón disponibles con este método, como se muestra a continuación:
Botón |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parámetro |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando se suelte el botón especificado. |
// Drive backward when F Down is released
void backUp() {
Drivetrain.driveFor(reverse, 100, mm);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Controller.ButtonFDown.released(backUp);
}
changed#
changed registers a function to be called when the joystick’s position changes. This method must be called on a specific axis object, such as AxisA (see full list of axis objects below).
Uso:
Se puede utilizar uno de los cuatro ejes disponibles con este método, como se muestra a continuación:
Eje |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
|
La función de devolución de llamada que se llamará cuando cambie la posición del eje especificado. |
// Play a sound when the right joystick moves
void beep() {
Brain.playSound(tada);
wait(1, seconds);
}
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
Controller.AxisD.changed(beep);
}
Constructores#
controller#
controller creates a controller object.
Usage:
controller Controller = controller();
Parámetro |
Descripción |
|---|---|
Este método no tiene parámetros. |
int main() {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// Create a Controller object
controller Controller = controller();
// Drive forward while R Up is held
while (true) {
if (Controller.ButtonRUp.pressing()) {
Drivetrain.drive(forward);
} else {
Drivetrain.stop();
}
wait(20, msec);
}
}