Transmisión#
Introducción#
El sistema de transmisión controla cómo se desplaza y gira el robot de realidad virtual. Este sistema puede avanzar o retroceder, girar a la izquierda o a la derecha, orientarse y seguir su propio movimiento de rotación.
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.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.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_heading— Changes the robot’s current heading to a new heading.set_rotation— Changes the robot’s current rotation to a new rotation.set_timeout— Sets how much time the robot will try to finish a movement.set_drive_velocity— Tells the robot how fast to drive.set_turn_velocity— Tells the robot how fast to turn.
Obtener: comprobar el estado de la transmisión.
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.
Usage:
drivetrain.drive(direction)
Parámetros |
Descripción |
|---|---|
|
The direction the robot moves: |
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 robot forward or reverse for a specific distance. The project will wait until the robot is done moving before the next line of code runs.
Usage:
drivetrain.drive_for(direction, distance, units, wait)
Parámetros |
Descripción |
|---|---|
|
The direction the robot moves: |
|
The distance the robot drives. This can be an |
|
Optional. The distance unit: |
|
Optional. |
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 robot left or right forever. The robot will continue to turn until it is given another action, like driving or stopping.
Usage:
drivetrain.turn(direction)
Parámetros |
Descripción |
|---|---|
|
The direction the robot turns: |
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 robot left or right for a specific number of degrees. The turn is relative to the current position of the robot. The project will wait until the robot is done turning before the next line of code runs.
Usage:
drivetrain.turn_for(direction, angle, units, wait)
Parámetros |
Descripción |
|---|---|
|
The direction the robot turns: |
|
The number of degrees the robot turns. This can be an |
|
Optional. The rotation unit: |
|
Optional. |
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#
A heading is the direction the robot 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.
La dirección inicial del robot es de 0 grados.
El proyecto esperará a que el robot termine de girar antes de ejecutar la siguiente línea de código.
Usage:
drivetrain.turn_to_heading(angle, units, wait)
Parámetros |
Descripción |
|---|---|
|
The direction the robot should face, in degrees. This can be an |
|
Optional. The rotation unit: |
|
Optional. |
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 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 the set_rotation method.
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.
El proyecto esperará a que el robot termine de girar antes de ejecutar la siguiente línea de código.
Usage:
drivetrain.turn_to_rotation(angle, units, wait)
Parámetros |
Descripción |
|---|---|
|
The rotation value, in degrees, that the robot will turn to. This can be an |
|
Optional. The rotation unit: |
|
Optional. |
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 the robot’s movement.
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#
A heading is the direction the robot 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.
Usage:
drivetrain.set_heading(heading, units)
Parámetros |
Descripción |
|---|---|
|
The heading value, in degrees, to set for the robot. This can be an |
|
Optional. The heading unit: |
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#
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.
Usage:
drivetrain.set_rotation(rotation, units)
Parámetros |
Descripción |
|---|---|
|
The rotation value, in degrees, to set for the robot. This can be an |
|
Optional. The rotation unit: |
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 how much time 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.
Usage:
drivetrain.set_timeout(value, units)
Parámetros |
Descripción |
|---|---|
|
The amount of time the robot can try to finish a movement. This can be a positive |
|
Optional. The time unit: |
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 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 puede ser más preciso.
Usage:
drivetrain.set_drive_velocity(velocity, units)
Parámetros |
Descripción |
|---|---|
|
The velocity to drive with from 0% to 100%. This can be an |
|
Optional. The velocity unit: |
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 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 puede ser más preciso.
Usage:
drivetrain.set_turn_velocity(velocity, units)
Parámetros |
Descripción |
|---|---|
|
The velocity to turn with from 0% to 100%. This can be an |
|
Optional. The velocity unit: |
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#
A heading is the direction the robot is facing, measured in degrees. heading returns the robot’s current heading from 0 to 359.99 degrees.
La dirección inicial del robot es de 0 grados.
Usage:
drivetrain.heading(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The heading unit: |
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 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 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.
Usage:
drivetrain.rotation(units)
Parámetros |
Descripción |
|---|---|
|
Optional. The rotation unit: |
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 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, turn_for, turn_to_heading, and turn_to_rotation.
Usage:
drivetrain.is_done()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |
is_moving#
is_moving returns whether the robot is 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 moving.False— The robot is not moving.
Usage:
drivetrain.is_moving()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |