传动系统#
介绍#
The VEX GO Drivetrain uses a built-in Inertial Sensor to support precise forward, reverse, and turning movements. These methods allow the robot to move continuously or for set distances, rotate by a specified number of degrees or to a heading, and respond to changes in its orientation.
The Drivetrain category also includes configuration methods that let you set drive and turn speeds, define stopping behavior, apply timeouts to avoid execution stalls, and manually update the robot’s heading or rotation values.
以下是所有方法的列表:
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 drivetrain to a specified heading.turn_to_rotation— Turns the drivetrain to a specified rotation.stop— Stops the drivetrain using the currently configured stopping behavior.
Mutators — Set default movement and turn speeds.
set_drive_velocity— Sets the default drive velocity for the drivetrain.set_turn_velocity— Sets the turning velocity for the drivetrain.set_stopping— Sets the stop behavior.set_timeout— Limits how long a drivetrain function waits before giving up if movement is blocked.set_heading— Sets a drivetrain’s heading to a specific value.set_rotation— Sets a drivetrain’s rotation to a specific value.
Getters — Return robot state and position.
get_heading— Returns a drivetrain’s current heading.get_rotation— Returns a drivetrain’s current rotation.get_velocity— Returns a drivetrain’s current velocity.get_yaw— Returns the yaw of the robot.get_roll— Returns the roll of the robot.get_pitch— Returns the pitch of the robot.get_crashed— Returns whether the robot has crashed.is_stopped— Returns whether a drivetrain is currently not moving.
行动#
drive#
drive 使传动系统无限期地沿指定方向移动。
用法:
drivetrain.drive(direction)
参数 |
描述 |
|---|---|
|
行驶方向:
|
# Build Used: Super Code Base 2.0
def main():
# Drive forward then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
drive_for#
drive_for 将传动系统沿指定方向移动一段设定的距离。
Usage:
drivetrain.drive_for(direction, distance, units, wait)
参数 |
描述 |
|---|---|
|
行驶方向:
|
|
动力传动系统移动的距离,以浮点数或整数表示。 |
|
Optional. The unit that represents the distance:
|
|
Optional.
|
# Build Used: Super Code Base 2.0
def main():
# Drive back and forth
drivetrain.drive_for(FORWARD, 100, MM)
drivetrain.drive_for(REVERSE, 4, INCHES)
# Start threads — Do not delete
start_thread(main)
drive_until#
drive_until 将传动系统向前移动,直到满足某个条件。
用法:
drivetrain.drive_until(condition, wait)
参数 |
描述 |
|---|---|
|
The condition that stops the drivetrain:
|
|
Optional.
|
# Build Used: Super Code Base 2.0
def main():
# Turn right after a crash
drivetrain.drive_until(CRASH)
drivetrain.turn_for(RIGHT, 90)
# Start threads — Do not delete
start_thread(main)
turn#
turn 无限地向左或向右转动传动系统。
用法:
drivetrain.turn(direction)
参数 |
描述 |
|---|---|
|
转弯方向:
|
# Build Used: Super Code Base 2.0
def main():
# Turn right and left, then stop
drivetrain.turn(RIGHT)
wait(2, SECONDS)
drivetrain.turn(LEFT)
wait(2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
turn_for#
turn_for turns the drivetrain left or right for a specified angle in degrees.
用法:
drivetrain.turn_for(direction, angle, wait)
参数 |
描述 |
|---|---|
|
转弯方向:
|
|
The number of degrees the drivetrain will turn as a float or integer. |
|
Optional.
|
# Build Used: Super Code Base 2.0
def main():
# Turn right then left
drivetrain.turn_for(RIGHT, 90)
drivetrain.turn_for(LEFT, 90)
# Start threads — Do not delete
start_thread(main)
turn_to_heading#
turn_to_heading 将传动系统转向指定的航向。
用法:
drivetrain.turn_to_heading(angle, wait)
参数 |
描述 |
|---|---|
|
转动传动系统的方向,以浮点数或整数度为单位。 |
|
Optional.
|
# Build Used: Super Code Base 2.0
def main():
# Turn to face the cardinal directions
drivetrain.turn_to_heading(90)
wait(1, SECONDS)
drivetrain.turn_to_heading(180)
wait(1, SECONDS)
drivetrain.turn_to_heading(270)
wait(1, SECONDS)
drivetrain.turn_to_heading(0)
# Start threads — Do not delete
start_thread(main)
turn_to_rotation#
turn_to_rotation 将传动系统转到指定的旋转方向。
用法:
drivetrain.turn_to_rotation(angle, wait)
参数 |
描述 |
|---|---|
|
以浮点数或整数度数表示的旋转传动系统朝向。 |
|
Optional.
|
# Build Used: Super Code Base 2.0
def main():
# Spin around twice
drivetrain.turn_to_rotation(720)
# Start threads — Do not delete
start_thread(main)
stop#
stop stops the drivetrain using the currently configured stopping behavior.
用法:
drivetrain.stop()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Drive forward then stop
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
修改器#
set_drive_velocity#
set_drive_velocity 设置传动系统的默认移动速度。此速度设置将用于后续调用任何传动系统函数。
用法:
drivetrain.set_drive_velocity(velocity)
参数 |
描述 |
|---|---|
|
传动系统移动的速度,以浮点数或整数表示,范围从 0% 到 100%。 |
# Build Used: Super Code Base 2.0
def main():
# Drive at different velocities
drivetrain.drive_for(FORWARD, 150, MM)
wait(1, SECONDS)
# Drive slow
drivetrain.set_drive_velocity(20)
drivetrain.drive_for(REVERSE, 50, MM)
wait(1, SECONDS)
# Drive fast
drivetrain.set_drive_velocity(100)
drivetrain.drive_for(FORWARD, 150, MM)
# Start threads — Do not delete
start_thread(main)
set_turn_velocity#
set_turn_velocity 设置传动系统的默认转弯速度。此速度设置将用于后续调用任何传动系统函数。
用法:
drivetrain.set_turn_velocity(velocity)
参数 |
描述 |
|---|---|
|
传动系统转动的速度,以浮点数或整数表示,范围从 0% 到 100%。 |
# Build Used: Super Code Base 2.0
def main():
# Turn at different velocities
drivetrain.turn_for(RIGHT, 180)
wait(1, SECONDS)
# Turn fast
drivetrain.set_turn_velocity(100)
drivetrain.turn_for(RIGHT, 180)
# Start threads — Do not delete
start_thread(main)
set_stopping#
set_stopping 设置传动系统的停止模式。
用法:
drivetrain.set_stopping(brake)
参数 |
描述 |
|---|---|
|
How the drivetrain will stop:
|
# Build Used: Super Code Base 2.0
def main():
drivetrain.set_drive_velocity(100)
# Drive, then coast to a stop
drivetrain.set_stopping(COAST)
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
set_timeout#
set_timeout 设置传动系统函数等待达到目标的时间限制。如果传动系统无法在设定的时间内完成运动,它将自动停止并继续执行下一个函数。
Note: The drivetrain’s time limit prevents drivetrain functions that do not reach their target position from blocking the execution of the rest of the project.
用法:
drivetrain.set_timeout(value, units)
参数 |
描述 |
|---|---|
|
The maximum number of seconds a drivetrain function will run before stopping and moving to the next function as an integer or float. |
|
Optional. The unit that represents the time:
|
# Build Used: Super Code Base 2.0
def main():
# Turn right after driving forward
drivetrain.set_timeout(1, SECONDS)
drivetrain.drive_for(FORWARD, 25, INCHES)
drivetrain.turn_for(RIGHT, 90)
# Start threads — Do not delete
start_thread(main)
set_heading#
set_heading 将传动系统的航向设置为指定值。
用法:
drivetrain.set_heading(value)
参数 |
描述 |
|---|---|
|
新航向使用的度值。 |
# Build Used: Super Code Base 2.0
def main():
# Face the new 0 degree heading
drivetrain.set_heading(90)
drivetrain.turn_to_heading(0)
# Start threads — Do not delete
start_thread(main)
set_rotation#
set_rotation 将传动系统的旋转设置为指定值。
用法:
drivetrain.set_rotation(value)
参数 |
描述 |
|---|---|
|
用于新旋转的度数值。 |
# Build Used: Super Code Base 2.0
def main():
# Spin counterclockwise two times
drivetrain.set_rotation(720)
drivetrain.turn_to_rotation(0)
# Start threads — Do not delete
start_thread(main)
吸气剂#
get_heading#
get_heading 以浮点数形式返回动力传动系统的当前航向。
用法:
drivetrain.get_heading()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Monitor the heading while turning
monitor_sensor("drivetrain.get_heading")
drivetrain.turn_for(RIGHT, 450)
# Start threads — Do not delete
start_thread(main)
get_rotation#
get_rotation returns the current rotation of the drivetrain as a float in degrees.
用法:
drivetrain.get_rotation()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Monitor the rotation while turning
monitor_sensor("drivetrain.get_rotation")
drivetrain.turn_for(RIGHT, 450)
# Start threads — Do not delete
start_thread(main)
get_velocity#
get_velocity 以百分比浮点数返回传动系统的当前速度。
用法:
drivetrain.get_velocity()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Display the velocity of the robot before and while moving
console.print("Start: ")
console.print(drivetrain.get_velocity())
console.new_line()
drivetrain.drive(FORWARD)
wait(1, SECONDS)
console.print("Moving: ")
console.print(drivetrain.get_velocity())
drivetrain.stop()
# Start threads — Do not delete
start_thread(main)
get_yaw#
get_yaw 以浮点数形式返回机器人当前的偏航角。
用法:
drivetrain.get_yaw()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Change the LED color based on the yaw while
# moving the robot by hand
monitor_sensor("drivetrain.get_yaw")
while True:
if drivetrain.get_yaw() > 0:
bumper.set_color(GREEN)
elif drivetrain.get_yaw() < 0:
bumper.set_color(RED)
else:
bumper.set_color(NONE)
# Start threads — Do not delete
start_thread(main)
get_roll#
get_roll 以浮点数形式返回机器人当前的滚动角度。
用法:
drivetrain.get_roll()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Change the LED color based on the roll while
# moving the robot by hand
monitor_sensor("drivetrain.get_roll")
while True:
if drivetrain.get_roll() > 0:
bumper.set_color(GREEN)
elif drivetrain.get_roll() < 0:
bumper.set_color(RED)
else:
bumper.set_color(NONE)
# Start threads — Do not delete
start_thread(main)
get_pitch#
get_pitch 以浮点数形式返回机器人当前的俯仰角度。
用法:
drivetrain.get_pitch()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Change the LED color based on the pitch while
# moving the robot by hand
monitor_sensor("drivetrain.get_pitch")
while True:
if drivetrain.get_pitch() > 0:
bumper.set_color(GREEN)
elif drivetrain.get_pitch() < 0:
bumper.set_color(RED)
else:
bumper.set_color(NONE)
# Start threads — Do not delete
start_thread(main)
get_crashed#
get_crashed 返回一个布尔值,指示机器人是否已经崩溃。
True— The robot has crashed.False— The robot has not crashed.
用法:
drivetrain.get_crashed()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Drive until a crash
drivetrain.drive(FORWARD)
while not drivetrain.get_crashed():
wait(50, MSEC)
drivetrain.stop()
drivetrain.turn_for(RIGHT, 90)
# Start threads — Do not delete
start_thread(main)
is_stopped#
is_stopped 返回一个布尔值,指示传动系统当前是否没有移动。
True— The drivetrain is stopped.False— The drivetrain is moving.
Note: is_stopped only detects movement from drivetrain methods that include a wait parameter.
用法:
drivetrain.is_stopped()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Build Used: Super Code Base 2.0
def main():
# Turn when the drivetrain is done moving forward
drivetrain.drive_for(FORWARD, 200, MM, wait=False)
wait(0.25, SECONDS)
while True:
if drivetrain.is_stopped():
drivetrain.turn_for(RIGHT, 180)
break
else:
console.print("Still moving...")
wait(0.1, SECONDS)
console.clear()
# Start threads — Do not delete
start_thread(main)