Transmisión#

Introducción#

El sistema de transmisión controla el movimiento del robot, permitiéndole avanzar, girar y detenerse con precisión.

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.

  • drive_until – Moves the drivetrain until a condition is met.

  • 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.

  • turn_to_rotation – Turns the drivetrain to a specified rotation.

  • stop – Stops a drivetrain with configurable behavior.

Mutadores: establecen velocidades de movimiento y giro predeterminadas.

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

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

  • set_stopping – Sets the stop behavior (brake, coast, or hold).

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

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

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

Getters – Devuelven el estado y la posición del robot.

  • get_heading – Returns a drivetrain’s current heading.

  • get_rotation – Returns a drivetrain’s current rotation.

  • get_velocity – Returns a drivetrain’s current velocity.

  • get_yaw – Returns the yaw of the robot in degrees.

  • get_roll – Returns the roll of the robot in degrees.

  • get_pitch – Returns the pitch of the robot in degrees.

  • get_crashed – Returns whether the robot has crashed.

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

Comportamiento#

drive#

drive mueve el tren motriz en una dirección específica indefinidamente.

Uso:
drivetrain.drive(direction)

Parámetros

Descripción

direction

La dirección en la que se debe conducir:

  • FORWARD
  • REVERSE

# Build Used: Super Code Base 2.0
def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)

drive_for#

drive_for mueve el sistema de transmisión en una dirección específica durante una distancia establecida.

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

Parámetros

Descripción

direction

La dirección en la que se debe conducir:

  • FORWARD
  • REVERSE

distance

La distancia que debe recorrer el tren motriz, expresada en forma de número flotante o entero.

units

The unit that represents the distance:

  • MM – Millimeters
  • INCHES (default)

wait

Opcional.

  • wait=True (predeterminado): el proyecto espera hasta que se complete drive_for antes de ejecutar siguiente línea de código.
  • wait=False : el proyecto inicia la acción y pasa a la siguiente línea de código inmediatamente, sin esperar a que finalice drive_for drive_for

# Build Used: Super Code Base 2.0
def main():
    # Drive back and forth
    drivetrain.drive_for(FORWARD, 100, MM)
    drivetrain.drive_for(REVERSE, 4, INCHES)
    

# Start threads — Do not delete
start_thread(main)

drive_until#

drive_until mueve la transmisión hacia adelante hasta que se cumpla una determinada condición.

Uso:
drivetrain.drive_until(condition, wait)

Parámetros

Descripción

condition

La condición que detiene la transmisión:

  • CRASH – Se detiene cuando la transmisión choca contra un objeto.
  • OBJECT – Se detiene cuando el sensor ocular detecta un objeto. Se debe configurar un sensor ocular para que se utilice este parámetro.

wait

Opcional.

  • wait=True (predeterminado): el proyecto espera hasta que se complete drive_until antes de ejecutar la siguiente línea de código.
  • wait=False : el proyecto inicia la acción y pasa a la siguiente línea de código inmediatamente, sin esperar a que finalice drive_until

# Build Used: Super Code Base 2.0
def main():
    # Turn right after a crash
    drivetrain.drive_until(CRASH)
    drivetrain.turn_for(RIGHT, 90)

# Start threads — Do not delete
start_thread(main)

turn#

turn gira la transmisión hacia la izquierda o hacia la derecha indefinidamente.

Uso:
drivetrain.turn(direction)

Parámetros

Descripción

direction

La dirección en la que girar:

  • LEFT
  • RIGHT

# Build Used: Super Code Base 2.0
def main():
    # Turn right and left, then stop
    drivetrain.turn(RIGHT)
    wait(2, SECONDS)
    drivetrain.turn(LEFT)
    wait(2, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)

turn_for#

turn_for gira la transmisión hacia la izquierda o hacia la derecha en un ángulo o rotaciones específicos.

Uso:
drivetrain.turn_for(direction, angle, wait)

Parámetros

Descripción

direction

La dirección en la que girar:

  • LEFT
  • RIGHT

angle

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

wait

Opcional.

  • wait=True (predeterminado) – El proyecto espera hasta que turn_for se complete antes de ejecutar la siguiente línea de código.
  • wait=False - El proyecto inicia la acción y pasa a la siguiente línea de código de inmediato, sin esperar a que turn_for termine.

# Build Used: Super Code Base 2.0
def main():
    # Turn right then left
    drivetrain.turn_for(RIGHT, 90)
    drivetrain.turn_for(LEFT, 90)

# Start threads — Do not delete
start_thread(main)

turn_to_heading#

turn_to_heading gira una transmisión hacia un rumbo específico.

Uso:
drivetrain.turn_to_heading(angle, wait)

Parámetros

Descripción

angle

El rumbo para girar la transmisión para que quede como un flotante o un entero en grados.

wait

Opcional.

  • wait=True (predeterminado) – El proyecto espera hasta que turn_to_heading se complete antes de ejecutar la siguiente línea de código.
  • wait=False - El proyecto inicia la acción y pasa a la siguiente línea de código inmediatamente, sin esperar a que turn_to_heading termine.

# Build Used: Super Code Base 2.0
def main():
    # Turn to face the cardinal directions
    drivetrain.turn_to_heading(90)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(180)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(270)
    wait(1, SECONDS)
    drivetrain.turn_to_heading(0)

# Start threads — Do not delete
start_thread(main)

turn_to_rotation#

turn_to_rotation gira una transmisión a una rotación especificada.

Uso:
drivetrain.turn_to_rotation(angle, wait)

Parámetros

Descripción

angle

La rotación para girar la transmisión para que quede orientada como un flotador o un número entero en grados.

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.

# Build Used: Super Code Base 2.0
def main():
    # Spin around twice
    drivetrain.turn_to_rotation(720)

# Start threads — Do not delete
start_thread(main)

stop#

stop parada de una transmisión.

Uso:
drivetrain.stop()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Drive forward then stop
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)

Mutadores#

set_drive_velocity#

set_drive_velocity establece la velocidad de movimiento predeterminada para un tren de transmisión. Este ajuste de velocidad se utilizará en las llamadas posteriores a cualquier función de tren de transmisión.

Uso:
drivetrain.set_drive_velocity(velocity)

Parámetros

Descripción

velocity

La velocidad a la que se moverá la transmisión como un valor flotante o entero del 0 % al 100 %.

# Build Used: Super Code Base 2.0
def main():
    # Drive at different velocities
    drivetrain.drive_for(FORWARD, 150, MM)
    wait(1, SECONDS)
    # Drive slow
    drivetrain.set_drive_velocity(20)
    drivetrain.drive_for(REVERSE, 50, MM)
    wait(1, SECONDS)
    # Drive fast
    drivetrain.set_drive_velocity(100)
    drivetrain.drive_for(FORWARD, 150, MM)

# Start threads — Do not delete
start_thread(main)

set_turn_velocity#

set_turn_velocity establece la velocidad de giro predeterminada de una transmisión. Esta configuración de velocidad se utilizará en las llamadas posteriores a cualquier función de transmisión.

Uso:
drivetrain.set_turn_velocity(velocity)

Parámetros

Descripción

velocity

La velocidad a la que girará la transmisión como un valor flotante o entero del 0 % al 100 %.

# Build Used: Super Code Base 2.0
def main():
    # Turn at different velocities
    drivetrain.turn_for(RIGHT, 180)
    wait(1, SECONDS)
    # Turn fast
    drivetrain.set_turn_velocity(100)
    drivetrain.turn_for(RIGHT, 180)

# Start threads — Do not delete
start_thread(main)

set_stopping#

set_stopping establece el modo de detención de un tren motriz.

Uso:
drivetrain.set_stopping(brake)

Parámetros

Descripción

brake

Cómo se detendrá la transmisión:

  • BRAKE – Se detiene inmediatamente.
  • COAST – Disminuye la velocidad gradualmente hasta detenerse.
  • HOLD – Se detiene y resiste el movimiento usando la retroalimentación del motor.

# Build Used: Super Code Base 2.0
def main():
    drivetrain.set_drive_velocity(100)
    # Drive, then coast to a stop
    drivetrain.set_stopping(COAST)
    drivetrain.drive(FORWARD)
    wait(2, SECONDS)
    drivetrain.stop()

# Start threads — Do not delete
start_thread(main)

set_timeout#

set_timeout establece un límite de tiempo que una función de transmisión esperará para alcanzar su objetivo. Si la transmisión no puede completar el movimiento dentro del tiempo establecido, se detendrá automáticamente y continuará con la siguiente función.

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.

Uso:
drivetrain.set_timeout(value, units)

Parámetros

Descripción

value

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

units

Opcional. Unidad que representa el tiempo:

  • SECONDS
  • MSEC (predeterminado) – Milisegundos

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

# Start threads — Do not delete
start_thread(main)

set_heading#

set_heading establece el rumbo del tren motriz a un valor especificado.

Uso:
drivetrain.set_heading(value)

Parámetros

Descripción

value

El valor a utilizar para el nuevo rumbo en grados.

# Build Used: Super Code Base 2.0
def main():
    # Face the new 0 degree heading
    drivetrain.set_heading(90)
    drivetrain.turn_to_heading(0)

# Start threads — Do not delete
start_thread(main)

set_rotation#

set_rotation establece la rotación de la transmisión en un valor especificado.

Uso:
drivetrain.set_rotation(value)

Parámetros

Descripción

value

El valor a utilizar para la nueva rotación en grados.

# Build Used: Super Code Base 2.0
def main():
    # Spin counterclockwise two times
    drivetrain.set_rotation(720)
    drivetrain.turn_to_rotation(0)

# Start threads — Do not delete
start_thread(main)

Captadores#

get_heading#

get_heading devuelve el rumbo actual del tren motriz como un punto flotante en grados.

Uso:
drivetrain.get_heading()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Monitor the heading while turning
    monitor_sensor("drivetrain.get_heading")
    drivetrain.turn_for(RIGHT, 450)


# Start threads — Do not delete
start_thread(main)

get_rotation#

get_rotation devuelve la rotación actual del sensor inercial en grados.

Uso:
drivetrain.get_rotation()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Monitor the rotation while turning
    monitor_sensor("drivetrain.get_rotation")
    drivetrain.turn_for(RIGHT, 450)


# Start threads — Do not delete
start_thread(main)

get_velocity#

get_velocity devuelve la velocidad actual del sistema de transmisión como un valor flotante en porcentaje.

Uso:
drivetrain.get_velocity()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Display the velocity of the robot before and while moving
    console.print("Start: ")
    console.print(drivetrain.get_velocity())
    console.new_line()
    drivetrain.drive(FORWARD)
    wait(1, SECONDS)
    console.print("Moving: ")
    console.print(drivetrain.get_velocity())
    drivetrain.stop()


# Start threads — Do not delete
start_thread(main)

get_yaw#

get_yaw devuelve la guiñada actual del robot como un punto flotante en grados.

Uso:
drivetrain.get_yaw()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Change the LED color based on the yaw while
    # moving the robot by hand
    monitor_sensor("drivetrain.get_yaw")
    while True:
        if drivetrain.get_yaw() > 0:
            bumper.set_color(GREEN)
        elif drivetrain.get_yaw() < 0:
            bumper.set_color(RED)
        else:
            bumper.set_color(NONE)

# Start threads — Do not delete
start_thread(main)

get_roll#

get_roll devuelve el balanceo actual del robot como un flotante en grados.

Uso:
drivetrain.get_roll()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Change the LED color based on the roll while
    # moving the robot by hand
    monitor_sensor("drivetrain.get_roll")
    while True:
        if drivetrain.get_roll() > 0:
            bumper.set_color(GREEN)
        elif drivetrain.get_roll() < 0:
            bumper.set_color(RED)
        else:
            bumper.set_color(NONE)

# Start threads — Do not delete
start_thread(main)

get_pitch#

get_pitch devuelve el paso actual del robot como un flotante en grados.

Uso:
drivetrain.get_pitch()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Change the LED color based on the pitch while
    # moving the robot by hand
    monitor_sensor("drivetrain.get_pitch")
    while True:
        if drivetrain.get_pitch() > 0:
            bumper.set_color(GREEN)
        elif drivetrain.get_pitch() < 0:
            bumper.set_color(RED)
        else:
            bumper.set_color(NONE)

# Start threads — Do not delete
start_thread(main)

get_crashed#

get_crashed devuelve un valor booleano que indica si el robot se ha bloqueado o no.

  • True – El robot se ha estrellado.

  • False – El robot no se ha estrellado.

Uso:
drivetrain.get_crashed()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Drive until a crash
    drivetrain.drive(FORWARD)
    while not drivetrain.get_crashed():
        wait(50, MSEC)
    drivetrain.stop()
    drivetrain.turn_for(RIGHT, 90)

# Start threads — Do not delete
start_thread(main)

is_stopped#

is_stopped devuelve un valor booleano que indica si un tren motriz no se está moviendo actualmente.

  • True – La transmisión está detenida.

  • False – La transmisión está en movimiento.

Uso:
drivetrain.is_stopped()

Parámetros

Descripción

Este método no tiene parámetros.

# Build Used: Super Code Base 2.0
def main():
    # Turn when the drivetrain is done moving forward
    drivetrain.drive_for(FORWARD, 200, MM, wait=False)
    wait(0.25, SECONDS)
    while True:
        if drivetrain.is_stopped():
            drivetrain.turn_for(RIGHT, 180)
            break
        else:
            console.print("Still moving...")
            wait(0.1, SECONDS)
            console.clear()

# Start threads — Do not delete
start_thread(main)