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.
For the examples below, the configured controller will be named controller_1 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 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.set_cursor– Sets the cursor position used for printing text on the Controller’s screen.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.clear_screen– Clears the whole screen.clear_row– Clears a screen row.next_row– Moves the cursor to the beginning of the next row.remote_control_code_enabled– Enable or disable Controller configured actions.
Getters: leen los estados de los botones y las posiciones del joystick.
.pressing– Returns whether the specified button is being pressed..position– Returns the position of the joystick’s specified axis.
Devolución de llamada: ejecuta el código cuando los botones o joysticks cambian de estado.
.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 y configuran manualmente el controlador.
Controller– Create a controller.
Comportamiento#
rumble#
rumble sends a rumble string to the V5 Controller.
Uso:
controller.rumble(pattern)
Parámetro |
Descripción |
|---|---|
|
A pattern using |
# Rumble the V5 Controller to the pattern short-short-long-long.
controller.rumble('..--')
print#
controller.screen.print prints text on the Controller’s screen using the current cursor position.
Uso:
controller.screen.print(text, sep, precision)
Parámetro |
Descripción |
|---|---|
|
El texto que se imprimirá en la pantalla del controlador. |
|
Optional. A string to inset between values. This must be written as a keyword argument (sep=). The default is |
|
Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument ( |
# Print the number 1 on the screen.
controller.screen.print(1)
# Print the numbers 1, 2, 3 and 4 on the screen.
controller.screen.print(1, 2, 3, 4, sep='-')
# Print motor1's velocity on the screen using a format string.
controller.screen.print("motor1 : % 7.2f" %(motor1.velocity()))
set_cursor#
set_cursor sets the cursor to a specific row and column on the controller’s screen. The controller screen has 3 rows and 19 columns.

Uso:
controller.screen.set_cursor(row, col)
Parámetro |
Descripción |
|---|---|
|
La fila del cursor del 1 al 3. |
|
La columna del cursor del 1 al 19. |
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. |
# Print the column number on row 2, column 3.
controller.screen.set_cursor(2, 3)
controller.screen.print(controller.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. |
# Print the column number on row 2, column 3.
controller.screen.set_cursor(2, 3)
controller.screen.print(controller.screen.row())
clear_screen#
clear_screen clears the whole screen.
Uso:
controller.screen.clear_screen()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Print text and then clear the screen.
controller.screen.print("VEX V5")
wait(2, SECONDS)
controller.screen.clear_screen()
clear_row#
clear_row clears a screen row.
Uso:
controller.screen.clear_row(row)
Parámetros |
Descripción |
|---|---|
|
Opcional. La fila a borrar, del 1 al 3. El valor predeterminado es la fila actual del cursor. |
# Clear row 2.
controller.screen.clear_row(2)
next_row#
next_row moves the cursor to the beginning of the next row.
Uso:
controller.screen.next_row()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Print text and then clear row 2.
controller.screen.print("VEX V5")
controller.screen.next_row()
controller.screen.print("Controller")
remote_control_code_enabled#
remote_control_code_enabled 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:
remote_control_code_enabled = False
# Drive forward or backward using the left joystick
remote_control_code_enabled = False
while True:
if controller_1.axis3.position() > 0:
drivetrain.drive(FORWARD)
elif controller_1.axis3.position() < 0:
drivetrain.drive(REVERSE)
# Press A to use the controller configured actions
elif controller_1.buttonA.pressing():
break
else:
drivetrain.stop()
wait(20, MSEC)
remote_control_code_enabled = 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 doce 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. |
# Turn right while L1 is pressed
while True:
if controller_1.buttonL1.pressing():
drivetrain.turn(RIGHT)
else:
drivetrain.stop()
.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:

Eje |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Turn with the left joystick
remote_control_code_enabled = False
while True:
if controller_1.axis4.position() > 10:
drivetrain.turn(RIGHT)
elif controller_1.axis4.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 utilizar uno de los objetos de botón disponibles con este método, como se muestra a continuación:

Botón |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
llamar de vuelta |
Una función que se define previamente para ejecutarse cuando se presiona el botón especificado. |
arg |
Opcional. Una tupla que contiene argumentos para pasar a la función de devolución de llamada. Funciones con parámetros para más información. |
# Drive forward when A is pressed
def drive_forward():
drivetrain.drive_for(FORWARD, 100, MM)
controller_1.buttonA.pressed(drive_forward)
.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 buttonL1 – (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:

Botón |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
llamar de vuelta |
Una función que se define previamente para ejecutarse cuando se suelta el botón especificado. |
arg |
Opcional. Una tupla que contiene argumentos para pasar a la función de devolución de llamada. Funciones con parámetros para más información. |
# Drive backward when A is released
def back_up():
drivetrain.drive_for(REVERSE, 100, MM)
controller_1.buttonA.released(back_up)
.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 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:

Eje |
Dominio |
|---|---|
|
|
|
|
|
|
|
|
Parámetros |
Descripción |
|---|---|
llamar de vuelta |
Una función que se define previamente para ejecutarse cuando cambia el valor del eje. |
arg |
Opcional. Una tupla que contiene los argumentos que se pasan a la función de devolución de llamada. Consulte Funciones con parámetros para obtener más información. |
# Play a sound when the left joystick moves
def tada_sound():
brain.play_sound(SoundType.TADA)
wait(1, SECONDS)
controller_1.axis4.changed(tada_sound)
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_type)
Parámetros |
Descripción |
|---|---|
|
Optional.The type of controller to create.
|
# Create a Controller
controller_1 = Controller(PRIMARY)
# Create two Controllers
controller_1 = Controller(PRIMARY)
controller_2 = Controller(PARTNER)