Transmisión#

Introducción#

Un sistema de transmisión permite al robot moverse de forma continua o a distancias preestablecidas, girar en grados o hacia una dirección determinada y responder a los cambios en su orientación rotacional.

La categoría de Sistema de Transmisión también incluye métodos de configuración que permiten ajustar las velocidades de avance y giro, aplicar tiempos de espera para evitar bloqueos en la ejecución y actualizar manualmente los valores de rumbo o rotación del robot. Estas funciones ofrecen flexibilidad al diseñar comportamientos autónomos.

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

Acciones: Mover y girar el robot.

  • drive – Moves the drivetrain in a specified direction indefinitely.

  • drive_for – Moves the drivetrain for a set distance.

  • turn – Turns the drivetrain left or right indefinitely.

  • turn_for – Turns the drivetrain for a set distance.

  • turn_to_heading – Turns the drivetrain to a specified heading using sensors.

  • turn_to_rotation – Turns the drivetrain to a specific rotational value.

  • stop – Stops a drivetrain with configurable behavior.

Motadores: Establece las velocidades de movimiento y giro predeterminadas.

  • set_heading – Sets a drivetrain’s heading to a specific value.

  • set_rotation – Sets a drivetrain’s rotational value to a specific value.

  • set_timeout – Limits how long a drivetrain function waits before giving up if movement is blocked.

  • set_drive_velocity – Sets the default moving velocity for the drivetrain.

  • set_turn_velocity – Sets the turning moving velocity for the drivetrain.

Funciones de obtención: devuelven el estado y la posición del robot.

  • heading – Returns a drivetrain’s current heading.

  • rotation – Returns a drivetrain’s current rotational value.

  • is_done – Returns whether a drivetrain is currently not moving.

  • is_moving – Returns whether a drivetrain is currently moving.

Comportamiento#

drive#

drive moves the drivetrain in a specified direction indefinitely.

Usage:
drivetrain.drive(direction)

Parámetros

Descripción

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

drive_for#

drive_for moves the drivetrain in a specified direction for a set distance.

Usage:
drivetrain.drive_for(direction, distance, units, wait)

Parámetros

Descripción

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

distance

La distancia que debe recorrer el sistema de transmisión, expresada como un número decimal o entero.

units

The unit that represents the distance:

  • INCHES
  • MM – Millimeters

wait

Optional.

  • wait=True (default) – The project waits until drive_for is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for drive_for to finish.

def main():
    # Drive forward and backward
    drivetrain.drive_for(FORWARD, 200, MM)
    drivetrain.drive_for(REVERSE, 200, MM)

# VR threads — Do not delete
vr_thread(main)

turn#

turn turns the drivetrain left or right indefinitely.

Usage:
drivetrain.turn(direction)

Parámetros

Descripción

direction

The direction in which to turn:

  • LEFT
  • RIGHT

def main():
    # Turn right and left, then stop
    drivetrain.turn(RIGHT)
    wait(2, SECONDS)
    drivetrain.turn(LEFT)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

turn_for#

turn_for turns the drivetrain left or right for a specified angle or rotations.

Usage:
drivetrain.turn_for(direction, angle, units, wait)

Parámetros

Descripción

direction

The direction in which to turn:

  • LEFT
  • RIGHT

angle

La cantidad de grados que girará la transmisión como un número decimal o entero.

units

The unit that represents the rotational value:

  • DEGREES

wait

Optional.

  • wait=True (default) – The project waits until turn_for is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for turn_for to finish.

def main():
    # Turn the robot right and left
    drivetrain.turn_for(RIGHT, 90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_for(LEFT, 90, DEGREES)

# VR threads — Do not delete
vr_thread(main)

turn_to_heading#

turn_to_heading turns a drivetrain to a specified heading.

Usage:
drivetrain.turn_to_heading(angle, units, wait)

Parámetros

Descripción

angle

El rumbo hacia el que se debe girar el tren motriz debe ser un número decimal o entero.

units

The unit that represents the rotational value:

  • DEGREES

wait

Optional.

  • wait=True (default) – The project waits until turn_to_heading is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for turn_to_heading to finish.

def main():
    # Turn to face the cardinal directions
    drivetrain.turn_to_heading(90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(180, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(270, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

turn_to_rotation#

turn_to_rotation turns a drivetrain to a specified rotational value.

Usage:
drivetrain.turn_to_rotation(angle, units, wait)

Parámetros

Descripción

angle

El valor de rotación hacia el que debe girar el tren de transmisión, expresado como un número decimal o entero.

units

The unit that represents the rotational value:

  • DEGREES

wait

Optional.

  • wait=True (default) – The project waits until turn_to_rotation is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for turn_to_rotation to finish.

def main():
    # Turn left, then spin in a circle 
    # clockwise and face right
    drivetrain.turn_to_rotation(-90, DEGREES)
    wait(1, SECONDS)
    drivetrain.turn_to_rotation(450, DEGREES)

# VR threads — Do not delete
vr_thread(main)

stop#

stop stops a drivetrain.

Usage:
drivetrain.stop()

Parámetros

Descripción

Este método no tiene parámetros.

def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# VR threads — Do not delete
vr_thread(main)

Mutadores#

set_heading#

set_heading sets the heading of a drivetrain.

Usage:
drivetrain.set_heading(heading, units)

Parámetros

Descripción

heading

El nuevo encabezado como un número decimal o entero.

units

The unit that represents the heading:

  • DEGREES

def main():
    # Face the new 0 degrees
    drivetrain.set_heading(90, DEGREES)
    drivetrain.turn_to_heading(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

set_rotation#

set_rotation method sets the rotation for the drivetrain.

Usage:
drivetrain.set_rotation(rotation, units)

Parámetros

Descripción

rotation

El nuevo valor de rotación como un número decimal o entero.

units

The unit that represents the heading:

  • DEGREES

def main():
    # Spin counterclockwise two times
    drivetrain.set_rotation(720, DEGREES)
    drivetrain.turn_to_rotation(0, DEGREES)

# VR threads — Do not delete
vr_thread(main)

set_timeout#

set_timeout sets a time limit for how long a drivetrain function will wait to reach its target. If the drivetrain cannot complete the movement within the set time, it will stop automatically and continue with the next function.

Nota: El límite de tiempo del tren motriz se utiliza para evitar que las funciones del tren motriz que no alcanzan su posición objetivo detengan la ejecución del resto del proyecto.

Usage:
drivetrain.set_timeout(value, units)

Parámetros

Descripción

value

El número máximo de segundos que una función del motor se ejecutará antes de detenerse y pasar a la siguiente función, expresado como un número entero o decimal.

units

The unit that represents the time:

  • SECONDS
  • MSEC – Milliseconds

def main():
    # Turn right after driving forward
    drivetrain.set_timeout(1, SECONDS)
    drivetrain.drive_for(FORWARD, 25, INCHES)
    drivetrain.turn_for(RIGHT, 90)

# VR threads — Do not delete
vr_thread(main)

set_drive_velocity#

set_drive_velocity sets the default moving velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions.

Usage:
drivetrain.set_drive_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad a la que se moverá el sistema de transmisión, expresada como un número decimal o entero.

units

The unit that represents the velocity:

  • PERCENT

def main():
    # Drive forward at different velocities
    # Default velocity
    drivetrain.drive_for(FORWARD, 150, MM)
    wait(1, SECONDS)
    # Drive slower
    drivetrain.set_drive_velocity(20, PERCENT)
    drivetrain.drive_for(FORWARD, 150, MM)
    wait(1, SECONDS)
    # Drive faster
    drivetrain.set_drive_velocity(100, PERCENT)
    drivetrain.drive_for(FORWARD, 150, MM)

# VR threads — Do not delete
vr_thread(main)

set_turn_velocity#

set_turn_velocity sets the default turning velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions.

Usage:
drivetrain.set_turn_velocity(velocity, units)

Parámetros

Descripción

velocity

La velocidad a la que girará el sistema de transmisión, expresada como un número decimal o entero.

units

The unit that represents the velocity:

  • PERCENT

def main():
    # Turn at different velocities
    # Default velocity
    drivetrain.turn_for(RIGHT, 120, DEGREES)
    wait(1, SECONDS)
    # Turn slower
    drivetrain.set_turn_velocity(20, PERCENT)
    drivetrain.turn_for(RIGHT, 120, DEGREES)
    wait(1, SECONDS)
    # Turn faster
    drivetrain.set_turn_velocity(100, PERCENT)
    drivetrain.turn_for(RIGHT, 120, DEGREES)

# VR threads — Do not delete
vr_thread(main)

Getters#

heading#

heading returns the current heading of a drivetrain as a float.

Usage:
drivetrain.heading(units)

Parámetros

Descripción

units

The unit that represents the rotational value:

  • DEGREES
def main():
    # Display the heading after turning
    drivetrain.turn_for(RIGHT, 450, DEGREES)
    brain.print("Heading: ")
    brain.print(drivetrain.heading(DEGREES))

# VR threads — Do not delete
vr_thread(main)

rotation#

rotation returns the current rotational value of a drivetrain as a float.

Usage:
drivetrain.rotation(units)

Parámetros

Descripción

units

The unit that represents the rotational value:

  • DEGREES

def main():
    # Display the rotation after turning
    drivetrain.turn_for(RIGHT, 450, DEGREES)
    brain.print("Rotation: ")
    brain.print(drivetrain.rotation(DEGREES))

# VR threads — Do not delete
vr_thread(main)

is_done#

is_done returns a Boolean indicating whether a drivetrain is not currently moving.

  • True – The drivetrain is not moving.

  • False – The drivetrain is moving.

Note: is_done only works with Drivetrain methods that have a wait parameter.

Usage:
drivetrain.is_done()

Parámetros

Descripción

Este método no tiene parámetros.

is_moving#

is_moving returns a Boolean indicating whether a drivetrain is currently moving.

  • True – The drivetrain is moving.

  • False – The drivetrain is not moving.

Usage:
drivetrain.is_moving()

Parámetros

Descripción

Este método no tiene parámetros.