Trapos#

Introducción#

Los subprocesos permiten que el controlador del dron VEX AIR ejecute varias tareas simultáneamente dentro del mismo programa. Permiten la multitarea, permitiendo que el dron VEX AIR realice acciones independientes simultáneamente.

Nota: Debes primero definir una función para usarla con un hilo.

Constructor – Crea e inicia nuevos hilos.

  • Thread – Starts a new thread that runs the specified function in parallel with the main program.

Constructor#

Thread#

Thread creates and starts a thread. When you create a thread, you can name it to manage it individually in your project.

Uso:

my_thread = Thread(my_function)

Parámetros

Descripción

my_thread

Opcional. Un nombre para el nuevo hilo.

callback

El nombre de una función definida previamente.

Nota: Una función siempre debe definirse antes de ser llamada.

# Only play sounds when the drone moves laterally
def moving_sounds():
    while True:
        if drone.is_move_active():
            controller.sound.play(LOOPING)
            while controller.sound.is_active():
                wait(50, MSEC)
        wait(5, MSEC)

# Run moving_sounds at the same time
moving_sounds_thread = Thread(moving_sounds)

# Fly the drone using the controller
drone.take_off(climb_to=500)
while True:
    drone.move_with_vectors(
        forward=controller.axis4.position(),
        rightward=controller.axis3.position(),
        upward=controller.axis1.position(),
        rotation=controller.axis2.position()
    )
    wait(5, MSEC)