Drivetrain#

Drive#

The Drive block is used to move the 123 Robot in the specified direction forever, until a new Drivetrain command is used, or the project is stopped.

This is a non-waiting block and allows any subsequent blocks to execute without delay.

  drive [forward v]

Select which direction for the 123 Robot to move in.

Diagram illustrating the Drivetrain commands for controlling the 123 Robot's movement and turning directions.

In this example, the 123 Robot will drive forward for 2 seconds, then stop.

  when started :: hat events
  drive [forward v]
  wait (2) seconds
  stop driving

Drive For#

The Drive For block is used to move the 123 Robot for a given distance.

This is a waiting block and does not allow subsequent blocks to trigger until it is done.

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

Select which direction for the 123 Robot to move in.

Diagram illustrating the Drivetrain blocks for controlling the 123 Robot's movement and turning actions.

Set how far the 123 Robot will move by entering a value, and choosing the unit of measurement (steps or millimeters).

Illustration of the 123 Robot's drivetrain blocks for driving and turning commands in programming.

In this example, the robot will drive forward for 2 steps.

  when started :: hat events
  drive [forward v] for (3) [steps v]

Drive Until#

The Drive Until block is used to move the 123 Robot indefinitely until a specified condition is met.

This is a waiting block and does not allow subsequent blocks to trigger until it is done.

  drive [forward v] until [object v]

Select which direction for the 123 Robot to move in.

Diagram illustrating the Drivetrain commands for the 123 Robot, including Drive Until, Turn, and Set Drive Heading blocks.

Select which behavior to use:

  • object - An object is detected by the Eye Sensor on the front of the 123 Robot.

  • crash - The 123 Robot crashes into an object or wall.

  • line - The Line Detector Sensor detects a line underneath the 123 Robot.

Diagram illustrating the Drive Until block for the 123 Robot, showing movement until a specified condition is met.

In this example, the 123 Robot will drive until it crashes into a wall, then it will stop driving.

  when started :: hat events
  drive [forward v] until [crash v]
  stop driving

Turn#

The Turn block is used to rotate the 123 Robot forever, until a new Drivetrain block is used, or the program is stopped.

This is a non-waiting block and allows any subsequent blocks to execute without delay.

  turn [right v]

Select which direction the 123 Robot will turn.

Diagram illustrating the turn direction options for the 123 Robot in a Drivetrain programming context.

In this example, the 123 Robot will turn towards the right for 2 seconds, then stop.

  when started :: hat events
  drive [right v]
  wait (2) seconds
  stop driving  

Turn For#

The Turn For block is used to rotate the 123 Robot for a given number of degrees.

This is a waiting block and does not allow subsequent blocks to trigger until it is done.

  turn [right v] for (90) degrees

Select which direction the 123 Robot will turn.

Diagram illustrating the Turn to Heading" block for controlling the 123 Robot's direction using the Gyro sensor.

Set how far the 123 Robot will turn by entering the number of degrees.

In this example, the 123 Robot will turn left for 45 degrees.

  when started :: hat events
  turn [left v] for (45) degrees

Turn to Heading#

The Turn to Heading block is used to turn a 123 Robot to a specific heading using the built-in Gyro sensor.

This is a waiting block and does not allow subsequent blocks to trigger until it is done.

  turn to heading (90) degrees

The Turn to Heading block turns to an absolute degree measure. This means:

  • When the 123 Robot turns clockwise past 360 degrees, the degree measure will start increasing again from 0 degrees.

  • When the 123 Robot turns counterclockwise past 0 degrees, the degree measure start decreasing again from 360 degrees.

Compass icon illustrating the Turn to Heading block for the 123 Robot's Gyro sensor navigation.

In this example, the 123 Robot will turn to face 270 degrees.

  when started :: hat events
  turn to heading (270) degrees

Stop Driving#

The Stop Driving block is used to stop the 123 Robot from moving.

This is a non-waiting block and allows any subsequent blocks to execute without delay.

  stop driving

In this example, the 123 Robot will drive forward for 2 seconds, then stop.

  when started :: hat events
  drive [forward v]
  wait (2) seconds
  stop driving  

Set Drive Timeout#

The Set Drive Timeout block is used to set a time limit for Drivetrain movement commands.

This is a non-waiting block and allows any subsequent blocks to execute without delay.

  set drive timeout to (1) seconds

The Drivetrain’s time limit is used to prevent Drivetrain blocks that do not reach their target position from waiting the execution of other blocks in the stack.

For instance, if a 123 Robot is unable to reach its target position because it encounters an obstacle like a wall, the Drivetrain block will continue running indefinitely. This would prevent any subsequent blocks in the stack from executing. By setting a time limit, the Drivetrain block will automatically stop after the specified duration, allowing the code to proceed to the next block even if the target position is not reached.

In this example, the Drivetrain is set to move forward for 15 steps with a timeout of 2 seconds. The 123 Robot won’t be able to reach the target position within 2 seconds, so the Drive block will automatically stop, and the robot will turn right by 90 degrees.

  when started :: hat events
  set drive timeout to (2) seconds
  drive [forward v] for (15) [steps v]
  turn [right v] for (90) degrees

Set Drive Heading#

The Set Drive Heading block is used to set the Drivetrain’s Gyro Sensor’s heading value.

This is a non-waiting block and allows any subsequent blocks to execute without delay.

  set drive heading to (0) degrees

The Set Drive Heading block can be used to set the Drivetrain’s position to any given heading. This block can be used to reset the orientation of the Drivetrain’s gyro when the heading is set to a value of 0.

In this example, the Drivetrain’s Gyro Sensor’s heading will be set to 90 degrees before the 123 Robot turns to a heading of 0 degrees.

  when started :: hat events
  set drive heading to (90) degrees
  turn to heading (0) degrees