Tren de transmisión#

Introducción#

El robot 123 tiene un sistema de tracción de dos ruedas que le permite desplazarse y girar. Los métodos de la transmisión controlan cómo se mueve el robot.

El sistema de transmisión puede medir la distancia de dos maneras: pasos y mm (milímetros). Un paso equivale a un cuadrado en un campo de 123.

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 or reverse until it detects an object, crash, or line.

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

  • stop — Stops the robot’s movement.

Motadores: Ajusta la configuración de la transmisión.

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

Obtenedores: comprobar el estado del movimiento.

  • is_stopped — Returns whether the robot has stopped moving, as a Boolean value.

  • get_heading — Returns the robot’s current heading from 0 to 359 degrees.

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:
robot.drive(direction)

Parámetros

Descripción

direction

The direction the robot moves: FORWARD or REVERSE.

# Drive for 2 seconds.
robot.drive(FORWARD)
wait(2, SECONDS)
robot.stop()

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:
robot.drive_for(direction, distance, unit)

Parámetros

Descripción

direction

The direction the robot moves: FORWARD or REVERSE.

distance

La distancia que recorre el robot. Puede ser un número entero o decimal.

unit

The distance unit: MM (millimeters) or STEPS (one square on a 123 Field).

# Drive back and forth.
robot.drive_for(FORWARD, 3, STEPS)
robot.drive_for(REVERSE, 3, STEPS)

drive_until#

drive_until moves the robot forward or reverse until it detects an object, a crash, or a line.

Usage:
robot.drive_until(direction)

Parámetros

Descripción

direction

The direction the robot moves: FORWARD or REVERSE.

# Reverse after a crash.
robot.drive_until(FORWARD)
robot.drive_for(REVERSE, 1, STEPS)

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:
robot.turn(direction)

Parámetros

Descripción

direction

The direction the robot turns: LEFT or RIGHT.

# Turn for 2 seconds.
robot.turn(RIGHT)
wait(2, SECONDS)
robot.stop()

turn_for#

turn_for turns the robot left or right for a specific number of degrees. The project will wait until the robot is done turning before the next line of code runs.

Usage:
robot.turn_for(direction, degrees)

Parámetros

Descripción

direction

The direction the robot turns: LEFT or RIGHT.

degrees

El número de grados de giro. Puede ser un número entero o decimal.

# Turn left, then turn around to the right.
robot.turn_for(LEFT, 90)
robot.turn_for(RIGHT, 180)

turn_to_heading#

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.

El proyecto esperará a que el robot termine de girar antes de ejecutar la siguiente línea de código.

Usage:
robot.turn_to_heading(heading)

Parámetros

Descripción

heading

La dirección hacia la que debe apuntar el robot, desde -359 hasta 359 grados.

# Turn to face the cardinal directions.
robot.turn_to_heading(90)
wait(2, SECONDS)
robot.turn_to_heading(180)
wait(2, SECONDS)
robot.turn_to_heading(270)
wait(2, SECONDS)
robot.turn_to_heading(0)
wait(2, SECONDS)

stop#

stop stops the robot’s movement.

Usage:
robot.stop()

Parámetros

Descripción

Este método no tiene parámetros.

# Stop driving after 4 seconds.
robot.drive(FORWARD)
wait(4, SECONDS)
robot.stop()

Mutadores#

set_timeout#

set_timeout sets how many seconds 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:
robot.set_timeout(time, unit)

Parámetros

Descripción

time

El tiempo que se debe permitir para un movimiento. Puede ser un número entero o decimal.

unit

The time unit: MSEC or SECONDS.

# Turn right after driving for 1 second.
robot.set_timeout(1, SECONDS)
robot.drive_for(FORWARD, 1000, MM)
robot.turn_for(RIGHT, 90)

set_heading#

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 los nuevos 0 grados.

Usage:
robot.set_heading(heading)

Parámetros

Descripción

heading

El valor de rumbo, en grados, que se debe establecer para el robot.

# Face the new 0 degree heading.
robot.set_heading(90)
robot.turn_to_heading(0)

Getters#

is_stopped#

is_stopped returns a Boolean that reports whether the robot has stopped moving.

  • True — The robot is stopped.

  • False — The robot is still moving.

Usage:
robot.is_stopped()

Parámetros

Descripción

Este método no tiene parámetros.

# Glow blue after a crash.
robot.drive_until(FORWARD)
while True:
    if robot.is_stopped():
        robot.led.glow(BLUE)
    else:
        robot.led.glow(GREEN)
    wait(0.05, SECONDS)

get_heading#

get_heading returns the direction the robot is currently facing as a whole number from 0 to 359 degrees.

La dirección inicial del robot es de 0 grados.

Usage:
robot.get_heading()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the heading after turning.
robot.turn_for(RIGHT, 450)
console.print(robot.get_heading())