Drivetrain#

Introduction#

The Drivetrain controls a robot’s movement, allowing it to drive forward, turn, and stop with precision.

Below is a list of all methods:

Actions – Move and turn the robot.

  • drive – Moves the drivetrain in a specified direction indefinitely.

  • drive_for – Moves the drivetrain for a set distance.

  • drive_until – Moves the drivetrain until a condition is met.

  • turn – Turns the drivetrain left or right indefinitely.

  • turn_for – Turns the drivetrain for a set distance.

  • turn_to_heading – Turns the smart drivetrain to a specified heading using sensors.

  • stop – Stops a drivetrain with configurable behavior.

Mutators – Set default movement and turn speeds.

  • set_drive_velocity – Sets the default moving velocity for the drivetrain.

  • set_turn_velocity – Sets the turning moving velocity for the drivetrain.

  • set_stopping – Sets the stop behavior (brake, coast, or hold).

  • set_timeout – Limits how long a drivetrain function waits before giving up if movement is blocked.

  • set_heading – Sets a smart drivetrain’s heading to a specific value.

Getters – Return robot state and position.

  • get_heading – Returns a smart drivetrain’s current heading.

  • get_velocity – Returns a drivetrain’s current velocity.

  • get_yaw – Returns the yaw of the robot in degrees.

  • get_roll – Returns the roll of the robot in degrees.

  • get_pitch – Returns the pitch of the robot in degrees.

  • get_crashed – Returns whether the robot has crashed.

  • is_stopped – Returns whether a drivetrain is currently not moving.

Actions#

drive#

drive moves the drivetrain in a specified direction indefinitely.

Usage:
drivetrain.drive(direction)

Parameters

Description

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

# Drive forward then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()

drive_for#

drive_for moves the drivetrain in a specified direction for a set distance.

Usage:
drivetrain.drive_for(direction, distance, units, wait)

Parameters

Description

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

distance

The distance for the drivetrain to move as a float or integer.

units

The unit that represents the distance:

  • MM – Millimeters
  • INCHES (default)
  • DistanceUnits.CM – Centimeters

wait

Optional.

  • wait=True (default) – The project waits until drive_for is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for drive_for to finish.

# Example coming soon

drive_until#

drive_until moves the drivetrain forward until a certain condition is met.

Usage:
drivetrain.drive_until(condition, wait)

Parameters

Description

condition

The condition that stops the drivetrain:

  • CRASH – Stops when the drivetrain crashes into an object.
  • OBJECT – Stops when the Eye Sensor detects an object. An Eye Sensor must be configured for this parameter to be used.

wait

Optional.

  • wait=True (default) – The project waits until drive_until is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for drive_until to finish.

# Example coming soon

turn#

turn turns the drivetrain left or right indefinitely.

Usage:
drivetrain.turn(direction)

Parameters

Description

direction

The direction in which to turn:

  • LEFT
  • RIGHT

# Example coming soon

turn_for#

turn_for turns the drivetrain left or right for a specified angle or rotations.

Usage:
drivetrain.turn_for(direction, angle, wait)

Parameters

Description

direction

The direction in which to turn:

  • LEFT
  • RIGHT

angle

The amount of degrees the drivetrain will turn as a float or integer.

wait

Optional.

  • wait=True (default) – The project waits until turn_for is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for turn_for to finish.

# Example coming soon

turn_to_heading#

turn_to_heading turns a smart drivetrain to a specified heading.

Usage:
drivetrain.turn_to_heading(angle, wait)

Parameters

Description

angle

The heading to turn the drivetrain to face as a float or integer in degrees.

wait

Optional.

  • wait=True (default) – The project waits until turn_to_heading is complete before executing the next line of code.
  • wait=False - The project starts the action and moves on to the next line of code right away, without waiting for turn_to_heading to finish.

# Example coming soon

stop#

stop stops a drivetrain.

Usage:
drivetrain.stop()

Parameters

Description

This method has no parameters.

# Example coming soon

Mutators#

set_drive_velocity#

set_drive_velocity sets the default moving velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions.

Usage:
drivetrain.set_drive_velocity(velocity)

Parameters

Description

velocity

The velocity at which the drivetrain will move as a float or integer from 0% to 100%.

# Example coming soon

set_turn_velocity#

set_turn_velocity sets the default turning velocity for a drivetrain. This velocity setting will be used for subsequent calls to any drivetrain functions.

Usage:
drivetrain.set_turn_velocity(velocity)

Parameters

Description

velocity

The velocity at which the drivetrain will turn as a float or integer from 0% to 100%.

# Example coming soon

set_stopping#

set_stopping sets the stopping mode for a drivetrain.

Usage:
drivetrain.set_stopping(brake)

Parameters

Description

brake

How the drivetrain will stop:

  • BRAKE – Stops immediately.
  • COAST – Slows gradually to a stop.
  • HOLD – Stops and resists movement using motor feedback.

# Example coming soon

set_timeout#

set_timeout sets a time limit for how long a drivetrain function will wait to reach its target. If the drivetrain cannot complete the movement within the set time, it will stop automatically and continue with the next function.

Note: The drivetrain’s time limit is used to prevent drivetrain functions that do not reach their target position from stopping the execution of the rest of the project.

Usage:
drivetrain.set_timeout(value, units)

Parameters

Description

value

The maximum number of seconds a motor function will run before stopping and moving to the next function as an integer or float.

units

Optional. The unit that represents the time:

  • SECONDS
  • MSEC (default) – Milliseconds

# Example coming soon

set_heading#

set_heading sets the heading of the drivetrain.

Usage:
drivetrain.set_heading(value)

Parameters

Description

value

The new heading as a float or integer in degrees.

# Example coming soon

Getters#

get_heading#

get_heading returns the current heading of the drivetrain as a float in degrees.

Usage:
drivetrain.get_heading()

Parameters

Description

This method has no parameters.

# Example coming soon

get_velocity#

get_velocity returns the current velocity of the drivetrain as a float in percent.

Usage:
drivetrain.get_velocity()

Parameters

Description

This method has no parameters.

# Example coming soon

get_yaw#

get_yaw returns the current yaw of the robot as a float in degrees.

Usage:
drivetrain.get_yaw()

Parameters

Description

This method has no parameters.

# Example coming soon

get_roll#

get_roll returns the current roll of the robot as a float in degrees.

Usage:
drivetrain.get_roll()

Parameters

Description

This method has no parameters.

# Example coming soon

get_pitch#

get_pitch returns the current pitch of the robot as a float in degrees.

Usage:
drivetrain.get_pitch()

Parameters

Description

This method has no parameters.

# Example coming soon

get_crashed#

get_crashed returns a Boolean indicating whether or not the robot has crashed.

  • True – The robot has crashed.

  • False – The robot has not crashed.

Usage:
drivetrain.get_crashed()

Parameters

Description

This method has no parameters.

# Example coming soon

is_stopped#

is_stopped returns a Boolean indicating whether a drivetrain is not currently moving.

  • True – The drivetrain is stopped.

  • False – The drivetrain is moving.

Usage:
drivetrain.is_stopped()

Parameters

Description

This method has no parameters.

# Example coming soon