Controlador#

Introducción#

El V5 Brain se puede conectar a un controlador V5. Un controlador V5 cuenta con dos joysticks analógicos y varios botones que el Brain puede usar para detectar movimientos y pulsaciones.

This page uses Controller1 as the example V5 Controller name. Replace these with your own configured name as needed.

A continuación se muestra una lista de todos los métodos disponibles:

Acciones: activa o desactiva las acciones programadas del controlador.

  • rumble — Sends a rumble string to the V5 Controller.

  • print — Prints text on the Controller’s screen.

  • setCursor — Sets the cursor position used for printing text on the Controller’s screen.

  • newLine — Moves the cursor to the beginning of the next row.

  • clearScreen — Clears the whole screen.

  • clearLine — Clears a screen row.

  • RemoteControlCodeEnabled — Enable or disable Controller configured actions.

Getters: leen estados de botones y posiciones del joystick.

  • .pressing — Returns whether the specified button is being pressed.

  • .position — Returns the position of the joystick’s specified axis.

  • column — Returns the current column where text will be printed as an integer.

  • row — Returns the current row where text will be printed as an integer.

Devolución de llamada: ejecuta el código cuando los botones o joysticks cambian de estado.

  • .pressed — Registers a callback function for when the specified button is pressed.

  • .released — Registers a callback function for when the specified button is released.

  • .changed — Registers a callback function for when the joystick’s axis changes.

Constructores: inicializan y configuran manualmente el controlador.

Comportamiento#

rumble#

rumble sends a rumble string to the V5 Controller.

Uso:

Controller.rumble(pattern);

Parámetro

Descripción

pattern

A pattern using . and - for short and long rumbles.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    // Rumble the V5 Controller to the pattern short-short-long-long.
    Controller1.rumble("..--");
}

print#

print prints text on the controller’s screen using the current cursor position.

Uso:

Controller.Screen.print(value, sep, precision);

Parámetro

Descripción

value

El texto que se imprimirá en la pantalla del controlador.

sep

Optional. A string to inset between values. This must be written as a keyword argument (sep=). The default is ” “.

precision

Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument (precision=). The default is 2.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    // Print the number 1 on the screen.
    Controller1.Screen.print(1);
}

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();  
    // Print the numbers 1, 2, 3 and 4 on the screen.
    Controller1.Screen.print("1, 2, 3, 4");
}

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    // Print the number 1 on the screen.
    Motor1.spin(forward);
    wait(2,seconds);
    Controller1.Screen.print("motor1 : %7.2f", Motor1.velocity(percent));
}

setCursor#

setCursor sets the cursor to a specific row and column on the controller’s screen. The controller screen has 3 rows and 19 columns.

Pantalla V5 Brain que muestra las filas y columnas disponibles para imprimir texto con diferentes tamaños de fuente y configuraciones.

Uso:

Controller.Screen.setCursor(row, col);

Parámetro

Descripción

row

La fila del cursor del 1 al 3.

col

La columna del cursor del 1 al 19.

newLine#

newLine method moves the cursor to the beginning of the next line.

Uso:

Controller.Screen.newLine();

Parámetros

Descripción

Este método no tiene parámetros.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    
    // Clear screen to print to multiple lines
    Controller1.Screen.clearScreen();
    Controller1.Screen.setCursor(1,1);

    // Print text on both rows
    Controller1.Screen.print("VEX V5");
    Controller1.Screen.newLine();
    Controller1.Screen.print("Controller");
}

clearScreen#

clearScreen clears the whole screen.

Uso:

Controller.Screen.clearScreen();

Parámetros

Descripción

Este método no tiene parámetros.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();

    // Print text and then clear the screen.
    Controller1.Screen.print("VEX V5");
    wait(2000, msec);
    Controller1.Screen.clearScreen();
}

clearLine#

clearLine clears a screen row.

Uso predeterminado:

Controller.Screen.clearLine(line);

Overload Usages: Controller.Screen.clearLine();

Parámetros

Descripción

line

La línea a borrar del 1 al 3. Si no se especifica, se borrará la línea actual.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    
    // Clear screen to print to multiple lines
    Controller1.Screen.clearScreen();
    Controller1.Screen.setCursor(1,1);

    // Print text 
    Controller1.Screen.print("VEX V5");
    Controller1.Screen.newLine();
    Controller1.Screen.print("Controller");
    wait(2000, msec);

    // Clear row 2.
    Controller1.Screen.clearLine(2);
}

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 (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;
}

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 ButtonDown (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 doce objetos de botón disponibles con este método, como se muestra a continuación:

Los botones del controlador VEX V5 están resaltados en amarillo.

Botón

Dominio

ButtonA

Controller.ButtonA.pressing() — The A button

ButtonB

Controller.ButtonB.pressing() — The B button

ButtonX

Controller.ButtonX.pressing() — The X button

ButtonY

Controller.ButtonY.pressing() — The Y button

ButtonDown

Controller.ButtonDown.pressing() — The Down button

ButtonUp

Controller.ButtonUp.pressing() — The Up button

ButtonLeft

Controller.ButtonLeft.pressing() — The Left button

ButtonRight

Controller.ButtonRight.pressing() — The Right button

ButtonL1

Controller.ButtonL1.pressing() — The L1 button

ButtonL2

Controller.ButtonL2.pressing() — The L2 button

ButtonR1

Controller.ButtonR1.pressing() — The R1 button

ButtonR2

Controller.ButtonR2.pressing() — The R2 button

Parámetros

Descripción

Este método no tiene parámetros.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    // Turn right while L1 is pressed
    while (true) {
        if (Controller1.ButtonL1.pressing()) {
            Drivetrain.turn(right);
        } else {
            Drivetrain.stop();
        }
        wait(5, 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 Axis1 (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:

Un eje del controlador VEX V5 resaltado en amarillo.

Eje

Dominio

Axis1

Controller.Axis1.position() — The Right Joystick’s vertical axis

Axis2

Controller.Axis2.position() — The Right Joystick’s horizontal axis

Axis3

Controller.Axis3.position() — The Left Joystick’s horizontal axis

Axis4

Controller.Axis4.position() — The Left Joystick’s vertical axis

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 (Controller1.Axis4.position() > 10) {
            Drivetrain.turn(right);
        } else if (Controller1.Axis4.position() < -10) {
            Drivetrain.turn(left);
        } else {
            Drivetrain.stop();
        }
        wait(20, msec);
    }
}

column#

column returns the current column where text will be printed as an integer.

Uso:

Controller.Screen.column()

Parámetros

Descripción

Este método no tiene parámetros.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();

    // Clear screen
    Controller1.Screen.clearScreen();

    // Print the column number on row 2, column 3.
    Controller1.Screen.setCursor(2, 3);
    Controller1.Screen.print(Controller1.Screen.column());
}

row#

row returns the current row where text will be printed as an integer.

Uso:

Controller.Screen.row()

Parámetros

Descripción

Este método no tiene parámetros.

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
      
    // Clear screen
    Controller1.Screen.clearScreen();

    // Print the column number on row 2, column 3.
    Controller1.Screen.setCursor(2, 3);
    Controller1.Screen.print(Controller1.Screen.row());
}

Llamar de vuelta#

.pressed#

.pressed registers a callback function that runs when a specific button on the controller is pressed. This method must be called on a specific button object, such as ButtonDown — (see full list of button objects below).

Uso:
Se puede utilizar uno de los objetos de botón disponibles con este método, como se muestra a continuación:

Los botones del controlador VEX V5 están resaltados en amarillo.

Botón

Dominio

ButtonA

Controller.ButtonA.pressed(callback); — The A button

ButtonB

Controller.ButtonB.pressed(callback); — The B button

ButtonX

Controller.ButtonX.pressed(callback); — The X button

ButtonY

Controller.ButtonY.pressed(callback); — The Y button

ButtonDown

Controller.ButtonDown.pressed(callback); — The Down button

ButtonUp

Controller.ButtonUp.pressed(callback); — The Up button

ButtonLeft

Controller.ButtonLeft.pressed(callback); — The Left button

ButtonRight

Controller.ButtonRight.pressed(callback); — The Right button

ButtonL1

Controller.ButtonL1.pressed(callback); — The L1 button

ButtonL2

Controller.ButtonL2.pressed(callback); — The L2 button

ButtonR1

Controller.ButtonR1.pressed(callback); — The R1 button

ButtonR2

Controller.ButtonR2.pressed(callback); — The R2 button

Parámetros

Descripción

callback

Una función de devolución de llamada previamente definida que se llama automáticamente cuando cambia el valor del eje. La función debe coincidir con la firma de devolución de llamada requerida. Consulte Funciones de devolución de llamada para obtener más información.

Callback Signature:
void callback();

Argumentos

Descripción

Esta función de devolución de llamada no tiene argumentos.

// Drive forward when A is pressed
void driveForward() {
    Drivetrain.driveFor(forward, 100, mm);
}

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    // Call driveForward when the A button is pressed
    Controller1.ButtonA.pressed(driveForward);
}

.released#

.released registers a callback function that runs when a specific button on the controller is released. This method must be called on a specific button object, such as ButtonDown — (see full list of button objects below).

Uso:
Se puede utilizar uno de los objetos de botón disponibles con este método, como se muestra a continuación:

Los botones del controlador VEX V5 están resaltados en amarillo.

Botón

Dominio

ButtonA

Controller.ButtonA.released(callback); — The A button

ButtonB

Controller.ButtonB.released(callback); — The B button

ButtonX

Controller.ButtonX.released(callback); — The X button

ButtonY

Controller.ButtonY.released(callback); — The Y button

ButtonDown

Controller.ButtonDown.released(callback); — The Down button

ButtonUp

Controller.ButtonUp.released(callback); — The Up button

ButtonLeft

Controller.ButtonLeft.released(callback); — The Left button

ButtonRight

Controller.ButtonRight.released(callback); — The Right button

ButtonL1

Controller.ButtonL1.released(callback); — The L1 button

ButtonL2

Controller.ButtonL2.released(callback); — The L2 button

ButtonR1

Controller.ButtonR1.released(callback); — The R1 button

ButtonR2

Controller.ButtonR2.released(callback); — The R2 button

Parámetros

Descripción

callback

Una función de devolución de llamada previamente definida que se llama automáticamente cuando cambia el valor del eje. La función debe coincidir con la firma de devolución de llamada requerida. Consulte Funciones de devolución de llamada para obtener más información.

Callback Signature:
void callback();

Argumentos

Descripción

Esta función de devolución de llamada no tiene argumentos.

// Drive backward when A is released
void backUp() {
    Drivetrain.driveFor(reverse, 100, mm);
}

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    // Call backUp when the A button is released
    Controller1.ButtonA.released(backUp);
}

.changed#

.changed registers a callback function that runs when the joystick’s position changes. This method must be called on a specific axis object, such as Axis1 (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:

Un eje del controlador VEX V5 resaltado en amarillo.

Eje

Dominio

Axis1

Controller.Axis1.changed(callback); — The Right Joystick’s vertical axis

Axis2

Controller.Axis2.changed(callback); — The Right Joystick’s horizontal axis

Axis3

Controller.Axis3.changed(callback); — The Left Joystick’s horizontal axis

Axis4

Controller.Axis4.changed(callback); — The Left Joystick’s vertical axis

Parámetros

Descripción

callback

Una función de devolución de llamada previamente definida que se llama automáticamente cuando cambia el valor del eje. La función debe coincidir con la firma de devolución de llamada requerida. Consulte Funciones de devolución de llamada para obtener más información.

Callback Signature:
void callback();

Argumentos

Descripción

Esta función de devolución de llamada no tiene argumentos.

// Play a rumble pattern when the left joystick moves
void rumblePattern() {    
    Controller1.rumble("..--");
    wait(1, seconds);
}

int main() {
    // Initializing Robot Configuration. DO NOT REMOVE!
    vexcodeInit();
    // Call the rumble function when the left joystick moves
    Controller1.Axis4.changed(rumblePattern);
}

Constructores#

Constructors are used to manually create controller objects, which are necessary for configuring a controller outside of VEXcode. You can only create two controllers in a project.

controller#

controller creates a controller.

Usage:
controller Controller = controller(controller_type);

Parámetros

Descripción

controller_type

The type of controller to create.

  • primary - The primary controller.
  • partner - The partner controller.

// Create a controller
controller Controller = controller(primary);

// Create two controllers
controller Controller1 = controller(primary);
controller Controller2 = controller(partner);