传动系统#
Introduction#
A drivetrain allows the robot to move continuously or for set distances, rotate by degrees or to a heading, and respond to changes in its rotational orientation.
The Drivetrain category also includes configuration methods that let you set drive and turn speeds, apply timeouts to avoid execution stalls, and manually update the robot’s heading or rotation values. These features provide flexibility when designing autonomous behaviors.
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.turn– Turns the drivetrain left or right indefinitely.turn_for– Turns the drivetrain for a set distance.turn_to_heading– Turns the drivetrain to a specified heading using sensors.turn_to_rotation– Turns the drivetrain to a specific rotational value.stop– Stops a drivetrain with configurable behavior.
Mutators – Set default movement and turn speeds.
set_heading– Sets a drivetrain’s heading to a specific value.set_rotation– Sets a drivetrain’s rotational value to a specific value.set_timeout– Limits how long a drivetrain function waits before giving up if movement is blocked.set_drive_velocity– Sets the default moving velocity for the drivetrain.set_turn_velocity– Sets the turning moving velocity for the drivetrain.
Getters – Return robot state and position.
Actions#
drive#
drive moves the drivetrain in a specified direction indefinitely.
Usage:
drivetrain.drive(direction)
参数 |
描述 |
|---|---|
|
The direction in which to drive:
|
def main():
# Drive forward then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
drive_for#
drive_for moves the drivetrain in a specified direction for a set distance.
Usage:
drivetrain.drive_for(direction, distance, units, wait)
参数 |
描述 |
|---|---|
|
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.
|
def main():
# Drive forward and backward
drivetrain.drive_for(FORWARD, 200, MM)
drivetrain.drive_for(REVERSE, 200, MM)
# VR threads — Do not delete
vr_thread(main)
turn#
turn turns the drivetrain left or right indefinitely.
Usage:
drivetrain.turn(direction)
参数 |
描述 |
|---|---|
|
The direction in which to turn:
|
def main():
# Turn right and left, then stop
drivetrain.turn(RIGHT)
wait(2, SECONDS)
drivetrain.turn(LEFT)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
turn_for#
turn_for turns the drivetrain left or right for a specified angle or rotations.
Usage:
drivetrain.turn_for(direction, angle, units, wait)
参数 |
描述 |
|---|---|
|
The direction in which to turn:
|
|
The amount of degrees the drivetrain will turn as a float or integer. |
|
The unit that represents the rotational value:
|
|
Optional.
|
def main():
# Turn the robot right and left
drivetrain.turn_for(RIGHT, 90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_for(LEFT, 90, DEGREES)
# VR threads — Do not delete
vr_thread(main)
turn_to_heading#
turn_to_heading turns a drivetrain to a specified heading.
Usage:
drivetrain.turn_to_heading(angle, units, wait)
参数 |
描述 |
|---|---|
|
The heading to turn the drivetrain to face as a float or integer. |
|
The unit that represents the rotational value:
|
|
Optional.
|
def main():
# Turn to face the cardinal directions
drivetrain.turn_to_heading(90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(180, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(270, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_heading(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
turn_to_rotation#
turn_to_rotation turns a drivetrain to a specified rotational value.
Usage:
drivetrain.turn_to_rotation(angle, units, wait)
参数 |
描述 |
|---|---|
|
The rotational value to turn the drivetrain to face as a float or integer. |
|
The unit that represents the rotational value:
|
|
Optional.
|
def main():
# Turn left, then spin in a circle
# clockwise and face right
drivetrain.turn_to_rotation(-90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_rotation(450, DEGREES)
# VR threads — Do not delete
vr_thread(main)
stop#
stop stops a drivetrain.
Usage:
drivetrain.stop()
参数 |
描述 |
|---|---|
This method has no parameters. |
def main():
# Drive forward then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# VR threads — Do not delete
vr_thread(main)
Mutators#
set_heading#
set_heading sets the heading of a drivetrain.
Usage:
drivetrain.set_heading(heading, units)
参数 |
描述 |
|---|---|
|
The new heading as a float or integer. |
|
The unit that represents the heading:
|
def main():
# Face the new 0 degrees
drivetrain.set_heading(90, DEGREES)
drivetrain.turn_to_heading(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
set_rotation#
set_rotation method sets the rotation for the drivetrain.
Usage:
drivetrain.set_rotation(rotation, units)
参数 |
描述 |
|---|---|
|
The new rotational value as a float or integer. |
|
The unit that represents the heading:
|
def main():
# Spin counterclockwise two times
drivetrain.set_rotation(720, DEGREES)
drivetrain.turn_to_rotation(0, DEGREES)
# VR threads — Do not delete
vr_thread(main)
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)
参数 |
描述 |
|---|---|
|
The maximum number of seconds a motor function will run before stopping and moving to the next function as an integer or float. |
|
The unit that represents the time:
|
def main():
# Turn right after driving forward
drivetrain.set_timeout(1, SECONDS)
drivetrain.drive_for(FORWARD, 25, INCHES)
drivetrain.turn_for(RIGHT, 90)
# VR threads — Do not delete
vr_thread(main)
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, units)
参数 |
描述 |
|---|---|
|
The velocity at which the drivetrain will move as a float or integer. |
|
The unit that represents the velocity:
|
def main():
# Drive forward at different velocities
# Default velocity
drivetrain.drive_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Drive slower
drivetrain.set_drive_velocity(20, PERCENT)
drivetrain.drive_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Drive faster
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive_for(FORWARD, 150, MM)
# VR threads — Do not delete
vr_thread(main)
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, units)
参数 |
描述 |
|---|---|
|
The velocity at which the drivetrain will turn as a float or integer. |
|
The unit that represents the velocity:
|
def main():
# Turn at different velocities
# Default velocity
drivetrain.turn_for(RIGHT, 120, DEGREES)
wait(1, SECONDS)
# Turn slower
drivetrain.set_turn_velocity(20, PERCENT)
drivetrain.turn_for(RIGHT, 120, DEGREES)
wait(1, SECONDS)
# Turn faster
drivetrain.set_turn_velocity(100, PERCENT)
drivetrain.turn_for(RIGHT, 120, DEGREES)
# VR threads — Do not delete
vr_thread(main)
Getters#
heading#
heading returns the current heading of a drivetrain as a float.
Usage:
drivetrain.heading(units)
参数 |
描述 |
|---|---|
|
The unit that represents the rotational value:
|
def main():
# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.print("Heading: ")
brain.print(drivetrain.heading(DEGREES))
# VR threads — Do not delete
vr_thread(main)
rotation#
rotation returns the current rotational value of a drivetrain as a float.
Usage:
drivetrain.rotation(units)
参数 |
描述 |
|---|---|
|
The unit that represents the rotational value:
|
def main():
# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.print("Rotation: ")
brain.print(drivetrain.rotation(DEGREES))
# VR threads — Do not delete
vr_thread(main)
is_done#
is_done returns a Boolean indicating whether a drivetrain is not currently moving.
True– The drivetrain is not moving.False– The drivetrain is moving.
Note: is_done only works with Drivetrain methods that have a wait parameter.
Usage:
drivetrain.is_done()
参数 |
描述 |
|---|---|
This method has no parameters. |
is_moving#
is_moving returns a Boolean indicating whether a drivetrain is currently moving.
True– The drivetrain is moving.False– The drivetrain is not moving.
Usage:
drivetrain.is_moving()
参数 |
描述 |
|---|---|
This method has no parameters. |