Controlador#

Introducción#

El controlador EXP permite a los usuarios controlar y personalizar el comportamiento de su robot.

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

Acciones: Activa o desactiva las acciones programadas en el controlador.

Obtenedores: Leen el estado de los botones y la posición del joystick.

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

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

Función de 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: Inicialice y configure manualmente el controlador.

Comportamiento#

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.axis3.position() > 0:
        drivetrain.drive(FORWARD)
    elif controller.axis3.position() < 0:
        drivetrain.drive(REVERSE)
    # Press A to use the controller configured actions
    elif controller.buttonA.pressing():
        break
    else:
        drivetrain.stop()
    wait(20, MSEC)

remote_control_code_enabled = True

Getters#

.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 utilizar uno de los diez objetos de botón disponibles con este método, como se muestra a continuación:

Vista frontal y superior del mando EXP, con los joysticks, las flechas y los botones de acción resaltados en amarillo. En la superficie del mando se encuentran dos joysticks, uno a la izquierda y otro a la derecha, con flechas arriba y abajo a la izquierda y botones A y B a la derecha. En la parte superior del mando se ubican los botones L1 y L2 a la izquierda y los botones R1 y R2 a la derecha.

Botón

Dominio

buttonA

controller.buttonA.pressing() — The A button

buttonB

controller.buttonB.pressing() — The B button

buttonDown

controller.buttonDown.pressing() — The Down button

buttonUp

controller.buttonUp.pressing() — The Up button

buttonL1

controller.buttonL1.pressing() — The L1 button

buttonL2

controller.buttonL2.pressing() — The L2 button

buttonL3

controller.buttonL3.pressing() — The L3 button

buttonR1

controller.buttonR1.pressing() — The R1 button

buttonR2

controller.buttonR2.pressing() — The R2 button

buttonR3

controller.buttonR3.pressing() — The R3 button

Parámetros

Descripción

Este método no tiene parámetros.

# Turn right while L1 is pressed
while True:
    if controller.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:

Con este método se puede utilizar uno de los cuatro ejes disponibles, como se muestra a continuación:

La parte frontal del controlador EXP muestra los números de los ejes del joystick resaltados en rojo. En la superficie del controlador, el joystick izquierdo está etiquetado como Eje 4 para el movimiento hacia la izquierda y la derecha, y Eje 3 para el movimiento hacia arriba y hacia abajo, mientras que el joystick derecho está etiquetado como Eje 1 para el movimiento hacia la izquierda y la derecha, y Eje 2 para el movimiento hacia arriba y hacia abajo.

Eje

Dominio

axis1

controller_1.axis1.position() — The Right Joystick’s horizontal axis

axis2

controller_1.axis2.position() — The Right Joystick’s vertical axis

axis3

controller_1.axis3.position() — The Left Joystick’s vertical axis

axis4

controller_1.axis4.position() — The Left Joystick’s horizontal axis

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.axis4.position() > 10:
        drivetrain.turn(RIGHT)
    elif controller.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 diez objetos de botón disponibles con este método, como se muestra a continuación:

Vista frontal y superior del mando EXP, con los joysticks, las flechas y los botones de acción resaltados en amarillo. En la superficie del mando se encuentran dos joysticks, uno a la izquierda y otro a la derecha, con flechas arriba y abajo a la izquierda y botones A y B a la derecha. En la parte superior del mando se ubican los botones L1 y L2 a la izquierda y los botones R1 y R2 a la derecha.

Botón

Dominio

buttonA

controller.buttonA.pressed(callback, arg) — The A button

buttonB

controller.buttonB.pressed(callback, arg) — The B button

buttonDown

controller.buttonDown.pressed(callback, arg) — The Down button

buttonUp

controller.buttonUp.pressed(callback, arg) — The Up button

buttonL1

controller.buttonL1.pressed(callback, arg) — The L1 button

buttonL2

controller.buttonL2.pressed(callback, arg) — The L2 button

buttonL3

controller.buttonL3.pressed(callback, arg) — The L3 button

buttonR1

controller.buttonR1.pressed(callback, arg) — The R1 button

buttonR2

controller.buttonR2.pressed(callback, arg) — The R2 button

buttonR3

controller.buttonR3.pressed(callback, arg) — The R3 button

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 los argumentos que se pasarán a la función de devolución de llamada. Funciones con parámetros para obtener más información.

# Drive forward when A is pressed
def drive_forward():
    drivetrain.drive_for(FORWARD, 100, MM)

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

Vista frontal y superior del mando EXP, con los joysticks, las flechas y los botones de acción resaltados en amarillo. En la superficie del mando se encuentran dos joysticks, uno a la izquierda y otro a la derecha, con flechas arriba y abajo a la izquierda y botones A y B a la derecha. En la parte superior del mando se ubican los botones L1 y L2 a la izquierda y los botones R1 y R2 a la derecha.

Botón

Dominio

buttonA

controller.buttonA.released(callback, arg) — The A button

buttonB

controller.buttonB.released(callback, arg) — The B button

buttonDown

controller.buttonDown.released(callback, arg) — The Down button

buttonUp

controller.buttonUp.released(callback, arg) — The Up button

buttonL1

controller.buttonL1.released(callback, arg) — The L1 button

buttonL2

controller.buttonL2.released(callback, arg) — The L2 button

buttonL3

controller.buttonL3.released(callback, arg) — The L3 button

buttonR1

controller.buttonR1.released(callback, arg) — The R1 button

buttonR2

controller.buttonR2.released(callback, arg) — The R2 button

buttonR3

controller.buttonR3.released(callback, arg) — The R3 button

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 los argumentos que se pasarán a la función de devolución de llamada. Funciones con parámetros para obtener más información.

# Drive backward when A is released
def back_up():
    drivetrain.drive_for(REVERSE, 100, MM)

controller.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:

La parte frontal del controlador EXP muestra los números de los ejes del joystick resaltados en rojo. En la superficie del controlador, el joystick izquierdo está etiquetado como Eje 4 para el movimiento hacia la izquierda y la derecha, y Eje 3 para el movimiento hacia arriba y hacia abajo, mientras que el joystick derecho está etiquetado como Eje 1 para el movimiento hacia la izquierda y la derecha, y Eje 2 para el movimiento hacia arriba y hacia abajo.

Eje

Dominio

axis1

controller.axis1.changed(callback, arg) — The Right Joystick’s horizontal axis

axis2

controller.axis2.changed(callback, arg) — The Right Joystick’s vertical axis

axis3

controller.axis3.changed(callback, arg) — The Left Joystick’s vertical axis

axis4

controller.axis4.changed(callback, arg) — The Left Joystick’s horizontal axis

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 pasarán 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.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()

Parámetros

Descripción

Este constructor no tiene parámetros.

# Create a Controller
controller = Controller()