传动系统#

介绍#

驱动系统使机器人能够连续移动或移动设定的距离,按度数或朝向某个方向旋转,并对其旋转方向的变化做出反应。

驱动系统类别还包括配置方法,可用于设置行驶和转弯速度、应用超时以避免执行停滞,以及手动更新机器人的航向或旋转值。这些功能在设计自主行为时提供了灵活性。

以下是所有方法的列表:

操作——移动和转向机器人。

  • 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.

变异器 – 设置默认移动和转向速度。

  • 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.

获取器 – 返回机器人状态和位置。

  • heading – Returns a drivetrain’s current heading.

  • rotation – Returns a drivetrain’s current rotational value.

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

  • is_moving – Returns whether a drivetrain is currently moving.

行动#

drive#

drive moves the drivetrain in a specified direction indefinitely.

Usage:
drivetrain.drive(direction)

参数

描述

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

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)

参数

描述

direction

The direction in which to drive:

  • FORWARD
  • REVERSE

distance

传动系统需要移动的距离,以浮点数或整数表示。

units

The unit that represents the distance:

  • INCHES
  • MM – Millimeters

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.

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)

参数

描述

direction

The direction in which to turn:

  • LEFT
  • RIGHT

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)

参数

描述

direction

The direction in which to turn:

  • LEFT
  • RIGHT

angle

传动系统将旋转的角度数,以浮点数或整数表示。

units

The unit that represents the rotational value:

  • DEGREES

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.

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)

参数

描述

angle

驱动系统转向方向的参数,可以是浮点数或整数。

units

The unit that represents the rotational value:

  • 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.

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)

参数

描述

angle

驱动系统转向的旋转值,以浮点数或整数表示。

units

The unit that represents the rotational value:

  • DEGREES

wait

Optional.

  • wait=True (default) – The project waits until turn_to_rotation 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_rotation to finish.

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()

参数

描述

此方法没有参数。

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

# VR threads — Do not delete
vr_thread(main)

变异体#

set_heading#

set_heading sets the heading of a drivetrain.

Usage:
drivetrain.set_heading(heading, units)

参数

描述

heading

新标题以浮点数或整数形式表示。

units

The unit that represents the heading:

  • DEGREES

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)

参数

描述

rotation

新的旋转值,以浮点数或整数表示。

units

The unit that represents the heading:

  • DEGREES

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.

注意: 传动系统的时间限制是为了防止未达到目标位置的传动系统功能停止项目其余部分的执行。

Usage:
drivetrain.set_timeout(value, units)

参数

描述

value

电机功能在停止并切换到下一个功能之前将运行的最大秒数,以整数或浮点数表示。

units

The unit that represents the time:

  • SECONDS
  • MSEC – Milliseconds

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)

参数

描述

velocity

传动系统的运动速度,以浮点数或整数表示。

units

The unit that represents the velocity:

  • PERCENT

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)

参数

描述

velocity

传动系统的转速,以浮点数或整数表示。

units

The unit that represents the velocity:

  • PERCENT

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)

获取器#

heading#

heading returns the current heading of a drivetrain as a float.

Usage:
drivetrain.heading(units)

参数

描述

units

The unit that represents the rotational value:

  • DEGREES
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)

参数

描述

units

The unit that represents the rotational value:

  • DEGREES

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()

参数

描述

此方法没有参数。

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()

参数

描述

此方法没有参数。