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 |
---|---|
|
The direction in which to drive:
|
# 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 |
---|---|
|
The direction in which to drive:
|
|
The distance for the drivetrain to move as a float or integer. |
|
The unit that represents the distance:
|
|
Optional.
|
# 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 |
---|---|
|
The condition that stops the drivetrain:
|
|
Optional.
|
# Example coming soon
turn#
turn
turns the drivetrain left or right indefinitely.
Usage:
drivetrain.turn(direction)
Parameters |
Description |
---|---|
|
The direction in which to turn:
|
# 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 |
---|---|
|
The direction in which to turn:
|
|
The amount of degrees the drivetrain will turn as a float or integer. |
|
Optional.
|
# 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 |
---|---|
|
The heading to turn the drivetrain to face as a float or integer in degrees. |
|
Optional.
|
# 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 |
---|---|
|
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 |
---|---|
|
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 |
---|---|
|
How the drivetrain will stop:
|
# 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 |
---|---|
|
The maximum number of seconds a motor function will run before stopping and moving to the next function as an integer or float. |
|
Optional. The unit that represents the time:
|
# Example coming soon
set_heading#
set_heading
sets the heading of the drivetrain.
Usage:
drivetrain.set_heading(value)
Parameters |
Description |
---|---|
|
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