Transmisión#
Introducción#
El sistema de transmisión incluye ruedas y motores que controlan cómo el robot se desplaza y gira. Estos sistemas se pueden encontrar en robots como Code Base 2.0, Super Car o en robots personalizados.
Los sistemas de transmisión utilizan el sensor inercial (Inertial.md) del sistema de control para detectar colisiones y ayudar al robot a moverse y girar con precisión. Al inicio de cada proyecto, el sistema de transmisión calibra automáticamente el sensor inercial. Mantenga el robot inmóvil durante aproximadamente 2 segundos durante la calibración para que pueda moverse y girar correctamente.
Existen muchas maneras de programar el sistema de transmisión. A continuación se muestra una lista de todos los métodos del sistema de transmisión:
Acciones: Mover y girar el robot.
drive— Moves the robot forward or reverse forever.drive_for— Moves the robot forward or reverse for a specific distance.drive_until— Moves the robot forward until the Eye Sensor detects an object or the robot detects a crash.turn— Turns the robot left or right forever.turn_for— Turns the robot left or right for a specific number of degrees.turn_to_heading— Turns the robot to face a specific heading from -359 to 359 degrees. The robot will turn the shortest direction to reach the target heading.turn_to_rotation— Turns the robot to a specific rotation.stop— Stops the robot’s movement.
Motadores: Ajusta la configuración de la transmisión.
set_drive_velocity— Tells the robot how fast to drive.set_turn_velocity— Tells the robot how fast to turn.set_stopping— Tells how the robot will stop moving: by braking, coasting, or holding.set_timeout— Sets how long the robot will try to finish a movement.set_heading— Changes the robot’s current heading to a new heading.set_rotation— Changes the robot’s current rotation to a new rotation.
Obtenedores: comprobar el estado del movimiento.
get_heading— Returns the robot’s current heading from 0 to 359 degrees.get_rotation— Returns the robot’s current rotation.get_velocity— Returns how fast the robot is driving, as a percentage from -100% to 100%.get_yaw— Returns the robot’s current yaw.get_roll— Returns the robot’s current roll.get_pitch— Returns the robot’s current pitch.get_crashed— Returns whether the robot has detected a crash, as a Boolean value.is_stopped— Returns whether the robot is finished moving, as a Boolean value.
Comportamiento#
drive#
drive moves the robot forward or reverse forever. The robot will continue to move until it is given another action, like turning or stopping.
Uso:
drivetrain.drive(direction)
Parámetros |
Descripción |
|---|---|
|
The direction the robot moves: |
# Build Used: 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 moves the robot forward or reverse for a specific distance.
Usage:
drivetrain.drive_for(direction, distance, units, wait)
Parámetros |
Descripción |
|---|---|
|
The direction the robot moves: |
|
La distancia que recorre el robot. Puede ser un número entero o decimal. |
|
Optional. The distance unit: |
|
Optional. |
# Build Used: 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 moves the robot forward until the Eye Sensor detects an object or the robot detects a crash.
Uso:
drivetrain.drive_until(condition, wait)
Parámetros |
Descripción |
|---|---|
|
The condition that stops the robot: |
|
Optional. |
# Build Used: 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 turns the robot left or right forever. The robot will continue to turn until it is given another action, like driving to stopping.
Uso:
drivetrain.turn(direction)
Parámetros |
Descripción |
|---|---|
|
The direction the robot turns: |
# Build Used: 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 turns the robot left or right for a specific number of degrees. The turn is relative to the current position of the robot.
Uso:
drivetrain.turn_for(direction, angle, wait)
Parámetros |
Descripción |
|---|---|
|
The direction the robot turns: |
|
El número de grados que gira el robot. Puede ser un número entero o decimal. |
|
Optional. |
# Build Used: 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#
A heading is the direction the robot’s brain is facing, measured in degrees. turn_to_heading turns the robot to face a specific heading from -359 to 359 degrees. The robot will turn the shortest direction to reach the target heading.
El rumbo inicial es de 0 grados.

Uso:
drivetrain.turn_to_heading(angle, wait)
Parámetros |
Descripción |
|---|---|
|
La dirección hacia la que debe mirar el robot, expresada como un número entero, entre -359 y 359 grados. |
|
Optional. |
# Build Used: 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 turns the robot to a specific rotation.
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. Rotation can also be set using set_rotation.
Los valores de rotación son absolutos. Esto significa que la dirección del giro depende de la rotación actual del robot. Girar a la derecha aumenta la rotación, y girar a la izquierda la disminuye.
Por ejemplo, si el robot comienza en 0 grados y se le da una rotación de 720 grados, girará dos veces a la derecha. Si luego se le da una rotación de 360 grados, girará una vez a la izquierda, ya que 360 es menor que 720.

Uso:
drivetrain.turn_to_rotation(angle, wait)
Parámetros |
Descripción |
|---|---|
|
El valor de rotación, en grados, que alcanzará el robot. Puede ser un número entero. |
|
Optional. |
# Build Used: Code Base 2.0
def main():
# Make one full turn to the right
drivetrain.turn_to_rotation(360)
# Make another full turn to the right
drivetrain.turn_to_rotation(720)
# Make one full turn to the left, returning to 360 degrees
drivetrain.turn_to_rotation(360)
# Start threads — Do not delete
start_thread(main)
stop#
stop stops the robot’s movement.
Uso:
drivetrain.stop()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Build Used: 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 tells the robot how fast to drive. A higher percentage makes the robot drive faster and a lower percentage makes the robot drive slower.
Todos los proyectos comienzan con el robot conduciendo al 50% de su velocidad por defecto.
Nota: Una mayor velocidad hace que el robot se desplace más rápido, pero puede ser menos preciso. Una menor velocidad hace que el robot se desplace más despacio, pero es más preciso.
Uso:
drivetrain.set_drive_velocity(velocity)
Parámetros |
Descripción |
|---|---|
|
La velocidad de conducción varía del 0% al 100%. |
# Build Used: Code Base 2.0
def main():
# Drive at different velocities
drivetrain.drive_for(FORWARD, 100, MM)
wait(1, SECONDS)
# Drive slow
drivetrain.set_drive_velocity(20)
drivetrain.drive_for(FORWARD, 100, MM)
wait(1, SECONDS)
# Drive fast
drivetrain.set_drive_velocity(100)
drivetrain.drive_for(FORWARD, 100, MM)
# Start threads — Do not delete
start_thread(main)
set_turn_velocity#
set_turn_velocity tells the robot how fast to turn. A higher percentage makes the robot turn faster and a lower percentage makes the robot turn slower.
Todos los proyectos comienzan con el robot girando al 50% de su velocidad por defecto.
Nota: Una mayor velocidad hace que el robot gire más rápido, pero puede ser menos preciso. Una menor velocidad hace que el robot gire más despacio, pero es más preciso.
Uso:
drivetrain.set_turn_velocity(velocity)
Parámetros |
Descripción |
|---|---|
|
La velocidad de giro varía del 0% al 100%. |
# Build Used: 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 sets how the robot will stop moving: by braking, coasting, or holding.
Uso:
drivetrain.set_stopping(brake)
Parámetros |
Descripción |
|---|---|
|
How the robot will stop:
|
If this method is not used, the robot will use BRAKE when stopping.
# Build Used: Code Base 2.0
def main():
# Drive, then coast to a stop
drivetrain.set_drive_velocity(100)
drivetrain.set_stopping(COAST)
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
set_timeout#
set_timeout sets how long the robot will try to finish a movement. If the robot cannot finish in that time it will stop trying and move on to the next line of code. This keeps the robot from getting stuck on a movement.
Uso:
drivetrain.set_timeout(value, units)
Parámetros |
Descripción |
|---|---|
|
El tiempo que el robot puede intentar para completar un movimiento. Puede ser un número entero o decimal. |
|
Optional. The unit of time: |
# Build Used: Code Base 2.0
def main():
# Drive as far as possible for 1 second before turning right
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#
A heading is the direction the robot’s brain is facing, measured in degrees. set_heading changes the robot’s current heading to a new heading value.
Por ejemplo, si el robot ha girado para mirar hacia la derecha, al establecer la orientación a 0 grados, esa posición mirando hacia la derecha se convierte en la nueva posición de 0 grados. Entonces, el robot puede girar a otras posiciones en función de esa nueva orientación.
Uso:
drivetrain.set_heading(value)
Parámetros |
Descripción |
|---|---|
|
El valor de rumbo, en grados, que se debe configurar para el robot. Puede ser un número entero entre 0 y 359. |
# Build Used: 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#
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the robot’s current rotation to a new value.
Por ejemplo, si el robot ha dado dos vueltas completas a la derecha, su valor de rotación será de 720 grados. Si se establece la rotación en 0 grados, esta volverá a su valor original. A partir de ahí, el robot podrá girar según ese nuevo valor.
Uso:
drivetrain.set_rotation(value)
Parámetros |
Descripción |
|---|---|
|
El valor de rotación, en grados, que se debe configurar para el robot. Puede ser un número entero. |
# Build Used: 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#
A heading is the direction the robot’s brain is facing, measured in degrees. get_heading returns that heading from 0 to 359 degrees.
La dirección inicial del robot es de 0 grados.

Uso:
drivetrain.get_heading()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Build Used: Code Base 2.0
def main():
# Display the heading while turning
monitor_sensor("drivetrain.get_heading")
drivetrain.turn_for(RIGHT, 450)
# Start threads — Do not delete
start_thread(main)
get_rotation#
Rotation is how much the robot has turned, measured in degrees. At the beginning of a project, the rotation value is set to 0 degrees. get_rotation returns the robot’s current rotation.
Girar a la derecha aumenta la rotación, y girar a la izquierda la disminuye. Por ejemplo, dar dos vueltas completas a la derecha produce una rotación de 720 grados.

Uso:
drivetrain.get_rotation()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Build Used: Code Base 2.0
def main():
# Display 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 returns how fast the robot is driving, as a percentage from -100% to 100%.
Un valor positivo significa que el robot avanza. Un valor negativo significa que el robot retrocede.
Uso:
drivetrain.get_velocity()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Build Used: 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(0.5, SECONDS)
console.print("Moving: ")
console.print(drivetrain.get_velocity())
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
get_yaw#
Yaw is how much the robot has turned left or right from its starting position, measured in degrees. get_yaw returns the robot’s current yaw value.
Girar a la derecha aumenta el valor de guiñada, y girar a la izquierda lo disminuye.
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#
Roll is how much the robot tilts to the left or right, measured in degrees. get_roll returns the robot’s current roll value.
Con el cerebro mirando hacia adelante, inclinarlo hacia la izquierda aumenta el valor de balanceo, e inclinarlo hacia la derecha lo disminuye.
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#
Pitch is how much the robot tilts forward or backward, measured in degrees. get_pitch returns the robot’s current pitch value.
Con el cerebro orientado hacia adelante, inclinarlo hacia adelante aumenta el valor del tono, e inclinarlo hacia atrás lo disminuye.
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 returns whether the robot has detected a crash, as a Boolean value.
True— A crash has been detected.False— A crash has not been detected.
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 returns whether the robot is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.
True— The robot is finished moving.False— The robot is still moving.
This method works together with the following drivetrain methods that have the wait parameter: drive_for, drive_until, turn_for, turn_to_heading, and turn_to_rotation.
Uso:
drivetrain.is_stopped()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
# Build Used: Code Base 2.0
def main():
# Turn when the drivetrain is done moving forward
drivetrain.drive_for(FORWARD, 100, 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)