Drivetrain#

Introduction#

The 123 Robot has a two-wheel drivetrain that lets it drive and turn. The Drivetrain blocks control how the robot moves.

The drivetrain can measure distance in two ways: steps and mm (millimeters). One step is one square on a 123 Field.

There are many ways to code the drivetrain. Below is a list of all Drivetrain blocks:

Actions — Move and turn the 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. The robot will turn the shortest direction to reach the target heading.

  • stop driving — Stops the robot’s movement.

Settings — Adjust drivetrain settings.

Values — Check movement status.

  • drive is done — Reports whether the robot is finished moving.

  • drive heading — Reports the robot’s current heading from 0 to 359 degrees.

Actions#

drive#

The drive stack block moves the robot forward or reverse forever. The robot will continue to move until it is given another action, like turning or stopping.

  drive [forward v]

Parameters

Description

direction

The direction the robot moves: forward or reverse.

Example

  when started
  [Drive for 2 seconds.]
  drive [forward v]
  wait (2) seconds
  stop driving

drive for#

The drive for stack block moves the robot forward or reverse for a specific distance. The project will wait until the robot is done moving before the next block in the stack runs.

  drive [forward v] for (1) [steps v]

Parameters

Description

direction

The direction the robot moves: forward or reverse.

distance

The distance the robot drives. This can be an integer or a decimal.

unit

The distance unit: steps or mm.

Example

  when started
  [Drive back and forth.]
  drive [forward v] for (3) [steps v]
  drive [reverse v] for (3) [steps v]

drive until#

The drive until stack block moves the robot forward or reverse until the Eye Sensor detects an object, crash, or line.

  drive [forward v] until [object v]

Parameters

Description

direction

The direction the robot moves: forward or reverse.

condition

The condition that stops the robot:

  • object — The Eye Sensor detects an object.
  • crash — The robot crashes into an object.
  • line — The Line Detector detects a line under the robot.

Example

  when started
  [Reverse after a crash.]
  drive [forward v] until [crash v]
  drive [reverse v] for (1) [steps v]

turn#

The turn stack block turns the robot left or right forever. The robot will continue to turn until it is given another action, like driving or stopping.

  turn [right v]

Parameters

Description

direction

The direction the robot turns: left or right.

Example

  when started
  [Turn for 2 seconds.]
  turn [right v]
  wait (2) seconds
  stop driving  

turn for#

The turn for stack block 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 block in the stack runs.

  turn [right v] for (90) degrees

Parameters

Description

direction

The direction the robot turns: left or right.

angle

The number of degrees the robot turns. This can be an integer or a decimal.

Example

  when started
  [Turn left, then turn around to the right.]
  turn [left v] for (90) degrees
  turn [right v] for (180) degrees

turn to heading#

A heading is the direction the robot is facing, measured in degrees. The turn to heading stack block 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.

The robot’s starting heading is 0 degrees.

  turn to heading (90) degrees

Parameters

Description

heading

The direction the robot should face, in degrees. This can be an integer or a decimal from -359 to 359.

Example

  when started
  [Turn to face the cardinal directions.]
  turn to heading (90) degrees
  wait (2) seconds
  turn to heading (180) degrees
  wait (2) seconds
  turn to heading (270) degrees
  wait (2) seconds
  turn to heading (0) degrees
  wait (2) seconds

stop driving#

The stop driving stack block stops the robot’s movement.

  stop driving

Parameters

Description

This block has no parameters.

Example

  when started
  [Stop driving after 4 seconds.]
  drive [forward v]
  wait [4] seconds
  stop driving

Settings#

set drive timeout#

The set drive timeout stack block 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 block in the stack. This keeps the robot from getting stuck on a movement.

  set drive timeout to (1) seconds

Parameters

Description

time

The number of seconds the robot can try to finish a movement. This can be a whole number or a decimal.

Example

  when started
  [Turn right after driving for 1 second.]
  set drive timeout to (1) seconds
  drive [forward v] for (1000) [mm v]
  turn [right v] for (90) degrees

set drive heading#

A heading is the direction the robot is facing, measured in degrees. The set drive heading stack block changes the robot’s current heading to a new heading value.

For example, if the robot has turned to face right, setting the heading to 0 degrees makes that right-facing position the new 0 degrees. Then the robot can turn to other positions based on that new heading.

  set drive heading to (0) degrees

Parameters

Description

heading

The heading value, in degrees, to set for the robot. This can be an integer or a decimal from 0 to 359.

Example

  when started
  [Face the new 0 degree heading.]
  set drive heading to (90) degrees
  turn to heading (0) degrees

Values#

drive is done#

The drive is done Boolean block reports whether the robot is finished moving. 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 block works together with the following Drivetrain blocks: drive for, drive until, turn for, and turn to heading.

    <drive is done?>

Parameters

Description

This block has no parameters.

Example

    when started
    [Glow blue after a crash.]
    drive [forward v] until [crash v]
    forever
      if <drive is done?> then
        glow [blue v]
      else
        glow [green v]

drive heading#

A heading is the direction the robot is facing, measured in degrees. The drive heading reporter block reports the robot’s current heading from 0 to 359 degrees.

The robot’s starting heading is 0 degrees.

    (drive heading in degrees)

Parameters

Description

This block has no parameters.

Example

    when started
    [Display the heading after turning.]
    turn [right v] for (450) degrees
    print (drive heading in degrees) ▶