传动系统#

介绍#

VEX IQ(第二代)机器人使用传动系统来驱动和转向。传动系统由电机和轮子组成,它们协同工作以移动机器人。

配置好的驱动系统可以使用连接的陀螺仪传感器(Sensing/Gyro.md)、大脑内置的惯性传感器(Inertial.md),或者不使用任何传感器。使用传感器时,驱动系统会利用它来帮助机器人精确地移动和转向。在每个项目开始时,驱动系统会自动校准传感器。校准期间,请保持机器人静止约2秒钟,以便机器人能够正确地移动和转向。

This page uses drivetrain as the example drivetrain name. Replace it with your own configured name as needed.

传动系统编码方式有很多种。以下列出了所有传动系统编码方法:

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

  • drive — Moves the robot forward or reverse forever.

  • drive_for — Moves the robot forward or reverse for a specific distance.

  • turn — Turns the robot left or right forever.

  • turn_for — Turns the robot left or right for a specific number of degrees.

  • turn_to_heading — Turns the robot to face a specific heading from -359 to 359 degrees. The robot will turn the shortest direction to reach the target heading.

  • turn_to_rotation — Turns the robot to a specific rotation.

  • stop — Stops the robot’s movement.

  • calibrate_drivetrain — Calibrates the sensor configured with the drivetrain.

变异器 — 调整传动系统设置。

  • set_drive_velocity — Tells the robot how fast to drive.

  • set_turn_velocity — Tells the robot how fast to turn.

  • set_stopping — Tells how the robot will stop moving: by braking, coasting, or holding.

  • set_timeout — Sets how much time the robot will try to finish a movement.

  • set_heading — Changes the robot’s current heading to a new heading.

  • set_rotation — Changes the robot’s current rotation to a new rotation.

  • set_turn_threshold — Tells how close the robot must get to a target angle before a turn is complete.

  • set_turn_constant — Changes how strongly the robot corrects its turns.

获取者 — 查看移动状态。

  • heading — Returns the robot’s current heading from 0 to 359 degrees.

  • rotation — Returns the robot’s current rotation.

  • velocity — Returns how fast the robot is driving.

  • current — Returns how much electrical current the drivetrain is using.

  • is_moving — Returns whether the robot is moving, as a Boolean value.

  • is_done — Returns whether the robot is finished moving, as a Boolean value.

  • is_turning — Returns whether the robot is turning, as a Boolean value.

  • power — Returns how quickly the drivetrain is using energy.

  • torque — Returns how much torque the drivetrain is using.

  • efficiency — Returns how efficiently the drivetrain is using power.

  • temperature — Returns how warm the drivetrain is.

构造函数——手动创建和配置传动系统。

  • DriveTrain — Creates a drivetrain without a Gyro Sensor or Inertial Sensor.

  • SmartDrive — Creates a drivetrain with a Gyro Sensor or Inertial Sensor.

行动#

drive#

drive moves the robot forward or reverse forever. The robot will continue to move until it is given another action, like turning or stopping.

Usage:
drivetrain.drive(direction, velocity, units)

参数

描述

direction

The direction the robot moves: FORWARD or REVERSE.

velocity

Optional. The velocity to drive with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float). If no velocity is provided, the robot drives at the current drive velocity.

units

Optional. The velocity unit: PERCENT (default), RPM (rotations per minute), or VelocityUnits.DPS (degrees per second).

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

# Drive slowly in reverse then stop
drivetrain.drive(REVERSE, 20, PERCENT)
wait(2, SECONDS)
drivetrain.stop()

drive_for#

drive_for moves the robot forward or reverse for a specific distance. The project will wait until the robot is done moving before the next line of code runs.

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

参数

描述

direction

The direction the robot moves: FORWARD or REVERSE.

distance

The distance the robot drives. This can be an integer or decimal (float).

units

Optional. The distance unit: INCHES (default), MM (millimeters), or DistanceUnits.CM (centimeters).

velocity

Optional. The velocity to drive with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float). If no velocity is provided, the robot drives at the current drive velocity.

units_v

Optional. The velocity unit: RPM (rotations per minute, default), PERCENT, or VelocityUnits.DPS (degrees per second).

wait

Optional. wait=True (default) makes the project wait until the robot is done moving before the next line of code runs. wait=False makes the next line of code run right away.

# Drive forward and backward
drivetrain.drive_for(FORWARD, 10)
drivetrain.drive_for(REVERSE, 10)

# Quickly drive forward and backward
drivetrain.drive_for(FORWARD, 200, MM, 100, PERCENT)
drivetrain.drive_for(REVERSE, 200, MM, 100, PERCENT)

turn#

turn turns the robot left or right forever. The robot will continue to turn until it is given another action, like driving or stopping.

Usage:
drivetrain.turn(direction, velocity, units)

参数

描述

direction

The direction the robot turns: LEFT or RIGHT.

velocity

Optional. The velocity to turn with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float). If no velocity is provided, the robot turns at the current turn velocity.

units

Optional. The velocity unit: RPM (rotations per minute, default), PERCENT, or VelocityUnits.DPS (degrees per second).

# Turn right and left, then stop
drivetrain.turn(RIGHT)
wait(2, SECONDS)
drivetrain.turn(LEFT)
wait(2, SECONDS)
drivetrain.stop()

# Quickly turn right and left, then stop
drivetrain.turn(RIGHT, 100, PERCENT)
wait(2, SECONDS)
drivetrain.turn(LEFT, 100, PERCENT)
wait(2, SECONDS)
drivetrain.stop()

turn_for#

turn_for turns the robot left or right for a specific number of degrees or turns. The turn is relative to the current position of the robot. The project will wait until the robot is done turning before the next line of code runs.

Usage:
drivetrain.turn_for(direction, angle, units, velocity, units_v, wait)

参数

描述

direction

The direction the robot turns: LEFT or RIGHT.

angle

The amount the robot turns. This can be an integer or decimal (float).

units

Optional. The turn unit: DEGREES (default) or TURNS. One turn is equal to 360 degrees.

velocity

Optional. The velocity to turn with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float). If no velocity is provided, the robot turns at the current turn velocity.

units_v

Optional. The velocity unit: RPM (rotations per minute, default), PERCENT, or VelocityUnits.DPS (degrees per second).

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

# Turn the robot right and left
drivetrain.turn_for(RIGHT, 90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_for(LEFT, 90, DEGREES)

# Quickly turn the robot right and left
drivetrain.turn_for(RIGHT, 90, DEGREES, 100, PERCENT)
wait(1, SECONDS)
drivetrain.turn_for(LEFT, 90, DEGREES, 100, PERCENT)

turn_to_heading#

A heading is the direction the robot is facing, measured in degrees. turn_to_heading turns the robot to face a specific heading from -359 to 359 degrees. The robot will turn the shortest direction to reach the target heading.

机器人的初始航向角为0度。

程序会等到机器人完成转向后才运行下一行代码。

Usage:
drivetrain.turn_to_heading(angle, units, velocity, units_v, wait)

参数

描述

angle

The direction the robot should face, in degrees. This can be an integer or decimal (float) from -359 to 359.

units

Optional. The heading unit: DEGREES (default).

velocity

Optional. The velocity to turn with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float). If no velocity is provided, the robot turns at the current turn velocity.

units_v

Optional. The velocity unit: PERCENT (default), RPM (rotations per minute), or VelocityUnits.DPS (degrees per second).

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

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

# Turn twice slowly
drivetrain.turn_to_heading(90, DEGREES, 20, PERCENT)
wait(1, SECONDS)
drivetrain.turn_to_heading(180, DEGREES, 20, PERCENT)

turn_to_rotation#

turn_to_rotation turns the robot to a specific rotation.

Rotation is how much the robot has turned, measured in degrees or turns. At the beginning of a project, the rotation value is set to 0 degrees. Rotation can also be set using the set_rotation method.

旋转角度是绝对值。这意味着转弯方向取决于机器人当前的旋转角度。向右转弯会增加旋转角度,向左转弯会减少旋转角度。

例如,如果机器人从0度开始,你将其旋转720度,它会向右转两次。如果你再将其旋转360度,它会向左转一次,因为360小于720。

程序会等到机器人完成转向后才运行下一行代码。

Usage:
drivetrain.turn_to_rotation(angle, units, velocity, units_v, wait)

参数

描述

angle

The rotation value, in degrees or turns, that the robot will turn to. This can be an integer or decimal (float).

units

Optional. The rotation unit: DEGREES (default) or TURNS. One turn is equal to 360 degrees.

velocity

Optional. The velocity to turn with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float). If no velocity is provided, the robot turns at the current turn velocity.

units_v

Optional. The velocity unit: PERCENT (default), RPM (rotations per minute), or VelocityUnits.DPS (degrees per second).

wait

Optional. wait=True (default) makes the project wait until the robot is done turning before the next line of code runs. wait=False makes the next line of code run right away.

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

# Turn left then slowly spin in a
# circle clockwise
drivetrain.turn_to_rotation(-90, DEGREES)
wait(1, SECONDS)
drivetrain.turn_to_rotation(450, DEGREES, 20, PERCENT)

stop#

stop stops the robot’s movement.

Usage:
drivetrain.stop(mode)

参数

描述

mode

Optional. How the robot will stop: BRAKE (default), COAST, or HOLD.

  • BRAKE — Stops immediately.
  • COAST — Slows to a stop.
  • HOLD — Stops immediately and holds the wheels’ position.

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

# Drive forward and coast to a stop
drivetrain.set_drive_velocity(100, PERCENT)
drivetrain.drive(FORWARD)
wait(2, SECONDS)
drivetrain.stop(COAST)

calibrate_drivetrain#

calibrate_drivetrain is a built-in function that calibrates the Gyro Sensor or Inertial Sensor configured with the drivetrain.

校准有助于传感器正确测量运动。校准期间,请保持机器人静止约 2 秒钟。如果机器人在校准期间移动,传感器可能无法正确测量运动。

程序将等待校准完成后再运行下一行代码。

**注意:**此函数不能在 VS Code 中使用。

Usage:
calibrate_drivetrain()

参数

描述

此函数没有参数。

修改器#

set_drive_velocity#

set_drive_velocity tells the robot how fast to drive. A higher percentage makes the robot drive faster and a lower percentage makes the robot drive slower.

每个项目开始时,机器人默认以 50% 的速度行驶。

**注意:**速度越高,机器人行驶速度越快,但精度可能越低;速度越低,机器人行驶速度越慢,但精度可能越高。

Usage:
drivetrain.set_drive_velocity(velocity, units)

参数

描述

velocity

The velocity to drive with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float).

units

Optional. The velocity unit: PERCENT (default), RPM (rotations per minute), or VelocityUnits.DPS (degrees per second).

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

set_turn_velocity#

set_turn_velocity tells the robot how fast to turn. A higher percentage makes the robot turn faster and a lower percentage makes the robot turn slower.

每个项目开始时,机器人默认以 50% 的速度旋转。

**注意:**速度越高,机器人转弯越快,但精度可能越低;速度越低,机器人转弯越慢,但精度可能越高。

Usage:
drivetrain.set_turn_velocity(velocity, units)

参数

描述

velocity

The velocity to turn with from 0% to 100% when using PERCENT, from 0 to 120 rpm when using RPM, or from 0 to 720 degrees per second when using VelocityUnits.DPS. This can be an integer or decimal (float).

units

Optional. The velocity unit: PERCENT (default), RPM (rotations per minute), or VelocityUnits.DPS (degrees per second).

# Turn at different velocities
# Default velocity
drivetrain.turn_for(RIGHT, 360)
wait(1, SECONDS)
# Turn slower
drivetrain.set_turn_velocity(20, PERCENT)
drivetrain.turn_for(RIGHT, 360)
wait(1, SECONDS)
# Turn faster
drivetrain.set_turn_velocity(100, PERCENT)
drivetrain.turn_for(RIGHT, 360)

set_stopping#

set_stopping sets how the robot will stop moving: by braking, coasting, or holding.

Usage:
drivetrain.set_stopping(mode)

参数

描述

mode

How the robot will stop:

  • BRAKE — Stops immediately.
  • COAST — Slows to a stop.
  • HOLD — Stops immediately and holds the wheels’ position.

If this method is not used, the robot will use BRAKE when stopping.

set_timeout#

set_timeout sets how much time the robot will try to finish a movement. If the robot cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the robot from getting stuck on a movement.

Usage:
drivetrain.set_timeout(value, units)

参数

描述

value

The amount of time the robot can try to finish a movement. This can be a positive integer or decimal (float).

units

Optional. The unit of time: MSEC (milliseconds, default) or SECONDS.

# Turn right after driving forward
drivetrain.set_timeout(1, SECONDS)
drivetrain.drive_for(FORWARD, 25, INCHES)
drivetrain.turn_for(RIGHT, 90)

set_heading#

A heading is the direction the robot is facing, measured in degrees. set_heading changes the robot’s current heading to a new heading value.

例如,如果机器人转向右侧,将航向设置为 0 度,则该右侧位置将成为新的 0 度航向。然后,机器人可以根据新的航向转向其他位置。

Usage:
drivetrain.set_heading(heading, units)

参数

描述

heading

The heading value, in degrees or turns, to set for the robot. This can be an integer or decimal (float).

units

Optional. The heading unit: DEGREES (default) or TURNS. One turn is equal to 360 degrees.

# Face the new 0 degrees
drivetrain.set_heading(90, DEGREES)
drivetrain.turn_to_heading(0, DEGREES)

set_rotation#

Rotation is how much the robot has turned, measured in degrees or turns. At the beginning of a project, the rotation value is set to 0 degrees. set_rotation changes the robot’s current rotation to a new value.

例如,如果机器人向右转了两圈,它的旋转角度将为 720 度。将旋转角度设置为 0 度会将旋转角度从 720 度重置为 0 度。然后,机器人可以根据这个新的旋转角度进行旋转。

Usage:
drivetrain.set_rotation(rotation, units)

参数

描述

rotation

The rotation value, in degrees or turns, to set for the robot. This can be an integer or decimal (float).

units

Optional. The rotation unit: DEGREES (default) or TURNS. One turn is equal to 360 degrees.

# Spin counterclockwise two times
drivetrain.set_rotation(720, DEGREES)
drivetrain.turn_to_rotation(0, DEGREES)

set_turn_threshold#

set_turn_threshold sets how close the robot must get to a target angle before a turn is complete.

较小的阈值可以使转弯更精确,但机器人可能需要更长时间才能完成转弯。较大的阈值可以使转弯更快完成,但精度可能会降低。

Usage:
drivetrain.set_turn_threshold(value)

参数

描述

value

The turn threshold, in degrees. This can be an integer or decimal (float). The default turn threshold is 1 degree.

# Set the turn threshold to 5 degrees
drivetrain.set_turn_threshold(5)

set_turn_constant#

set_turn_constant changes how strongly the robot corrects its turns.

数值越高,机器人修正转弯的力度越大;数值越低,机器人修正转弯的力度越小。默认值为 1.0。

Usage:
drivetrain.set_turn_constant(value)

参数

描述

value

The turn constant. This can be a decimal (float) from 0.1 to 4.0. The default is 1.0.

# Increase the turn constant to 2.0
drivetrain.set_turn_constant(2.0)

吸气剂#

heading#

A heading is the direction the robot is facing, measured in degrees. heading returns the robot’s current heading from 0 to 359 degrees.

机器人的初始航向角为0度。

Usage:
drivetrain.heading(units)

参数

描述

units

Optional. The unit to return heading in: DEGREES (default) or TURNS. One turn is equal to 360 degrees.

# Display the heading after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print("Heading: ")
brain.screen.print(drivetrain.heading())

rotation#

Rotation is how much the robot has turned, measured in degrees or turns. At the beginning of a project, the rotation value is set to 0 degrees. rotation returns the robot’s current rotation.

向右转会增加旋转角度,向左转会减少旋转角度。例如,向右转两圈将得到 720 度的旋转角度。

Usage:
drivetrain.rotation(units)

参数

描述

units

Optional. The unit to return rotation in: DEGREES (default) or TURNS. One turn is equal to 360 degrees.

# Display the rotation after turning
drivetrain.turn_for(RIGHT, 450, DEGREES)
brain.screen.print("Rotation: ")
brain.screen.print(drivetrain.rotation())

velocity#

velocity returns how fast the robot is driving.

It can return velocity as a percentage from -100% to 100%, in RPM from -127 rpm to 127 rpm, or in VelocityUnits.DPS (degrees per second). A positive value means the robot is driving forward. A negative value means the robot is driving in reverse.

Usage:
drivetrain.velocity(units)

参数

描述

units

Optional. The unit to return velocity in: PERCENT (default), RPM (rotations per minute), or VelocityUnits.DPS (degrees per second).

current#

current returns how much electrical current the drivetrain is using, measured in amps (amperes). Current is the amount of electricity flowing through the drivetrain.

电流值越高,意味着驱动系统消耗的电流越大。这种情况可能发生在机器人推挤物体或被卡住后试图移动时。

这可以用来检查传动系统在运动过程中是否运转吃力。如果电流持续偏高,传动系统可能会发热或动力利用效率降低。

Usage:
drivetrain.current(units)

参数

描述

units

Optional. The unit to return current in: CurrentUnits.AMP (amps, default).

is_moving#

is_moving returns whether the robot is moving, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is moving.

  • False — The robot is not moving.

This method works together with the following Drivetrain methods that have the wait parameter: drive_for, turn_for, turn_to_heading, and turn_to_rotation.

Usage:
drivetrain.is_moving()

参数

描述

该方法没有参数。

is_done#

is_done returns whether the robot is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is finished moving.

  • False — The robot is still moving.

This method works together with the following Drivetrain methods that have the wait parameter: drive_for, turn_for, turn_to_heading, and turn_to_rotation.

Usage:
drivetrain.is_done()

参数

描述

该方法没有参数。

is_turning#

is_turning returns whether the robot is turning, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

  • True — The robot is turning.

  • False — The robot is not turning.

This method works together with the following Drivetrain methods that have the wait parameter: turn_for, turn_to_heading, and turn_to_rotation.

Usage:
drivetrain.is_turning()

参数

描述

该方法没有参数。

power#

power returns how much power the drivetrain is using, measured in watts. Power shows how quickly the drivetrain is using energy.

功率值越高,意味着驱动系统消耗能量的速度越快。这种情况可能发生在机器人推挤物体或被卡住后试图移动时。

这可以用来比较不同的运动轨迹,或者检查传动系统是否运转吃力。如果功率持续偏高,传动系统可能会过热或能量利用效率降低。

Usage:
drivetrain.power()

参数

描述

该方法没有参数。

torque#

扭矩表示传动系统在车轮旋转时能够施加多大的推力或拉力。

torque returns how much torque the drivetrain is using, measured in Newton-meters (Nm) or inch-pounds (InLb).

扭矩值越高,意味着传动系统需要更大的推力或拉力。这种情况可能发生在机器人推挤物体或被卡住后试图移动时。

这可以用来检查传动系统是否运转不畅,或者比较不同动作所需的推力大小。

Usage:
drivetrain.torque(units)

参数

描述

units

Optional. The unit to return torque in: TorqueUnits.NM (newton meters, default) or TorqueUnits.INLB (inch pounds).

efficiency#

efficiency returns how efficiently the drivetrain is using power, as a percentage from 0% to 100%.

效率值反映了传动系统有多少动力被用于运动。效率值越高,意味着传动系统用于运动的动力越多。当传动系统高负荷运转但运动量不大时,例如机器人被卡住或抵挡物体时,效率值会降低。

这可以用来比较运动情况,或者检查传动系统是否浪费动力而不是将其用于运动。

Usage:
drivetrain.efficiency()

参数

描述

该方法没有参数。

temperature#

temperature returns the average temperature of the drivetrain in the selected temperature unit.

温度显示传动系统电机的温度。温度越高,意味着电机在工作过程中温度越高。为了保持最佳性能,电机温度应保持在 55°C 以下。

如果电机过热,它们会降低最大电流以保护自身。当温度达到 70°C 时,电机将停止运转,直到冷却下来。

这可以用来检查传动系统在重复运动、长时间运行或推动物体时是否过热。

Usage:
drivetrain.temperature(units)

参数

描述

units

Optional. The unit to return temperature in: TemperatureUnits.CELSIUS (default) or TemperatureUnits.FAHRENHEIT.

构造函数#

Constructors are used to create DriveTrain and SmartDrive objects in code. This is useful when configuring a drivetrain without using the Devices window.

At least two Motor or MotorGroup objects must be created before creating a drivetrain.

DriveTrain#

DriveTrain creates a drivetrain without a Gyro Sensor or Inertial Sensor.

Usage:
DriveTrain(lm, rm, wheelTravel, trackWidth, wheelBase, units, externalGearRatio)

范围

描述

lm

左侧运动运动组

rm

右侧运动神经元运动神经元组

wheelTravel

可选。传动车轮的周长。默认值为 300 毫米。

trackWidth

可选。左右车轮之间的宽度。默认值为 320 毫米。

wheelBase

可选。前后轮之间的距离。默认值为 320 毫米。

units

Optional. The unit for wheelTravel, trackWidth, and wheelBase: MM (millimeters, default), INCHES, or DistanceUnits.CM (centimeters).

externalGearRatio

Optional. The gear ratio used to adjust drive distances if gears are used. This can be an integer or decimal (float). The default is 1.0.

# Create left and right drive motor objects
left_drive_smart = Motor(Ports.PORT1, 1.0, False)
right_drive_smart = Motor(Ports.PORT2, 1.0, True)

'''
Create a Drivetrain with the following values:
wheelTravel: 200
trackWidth: 173
wheelBase: 76
units: MM
externalGearRatio: 1
'''
drivetrain = DriveTrain(left_drive_smart, right_drive_smart, 200, 173, 76, MM, 1)

# Create two motor group objects for left and right motors
left_motor_a = Motor(Ports.PORT1, 1.0, False)
left_motor_b = Motor(Ports.PORT2, 1.0, False)
left_drive_smart = MotorGroup(left_motor_a, left_motor_b)

right_motor_a = Motor(Ports.PORT3, 1.0, True)
right_motor_b = Motor(Ports.PORT4, 1.0, True)
right_drive_smart = MotorGroup(right_motor_a, right_motor_b)

'''
Create a Drivetrain with the following values:
wheelTravel: 200
trackWidth: 173
wheelBase: 76
units: MM
externalGearRatio: 1
'''
drivetrain = DriveTrain(left_drive_smart, right_drive_smart, 200, 173, 76, MM, 1)

SmartDrive#

SmartDrive creates a drivetrain with a Gyro Sensor or Inertial Sensor.

Usage:
SmartDrive(lm, rm, g, wheelTravel, trackWidth, wheelBase, units, externalGearRatio)

范围

描述

lm

左侧运动运动组

rm

右侧运动神经元运动神经元组

g

传动系统使用的陀螺仪传感器惯性传感器

wheelTravel

可选。传动车轮的周长。默认值为 300 毫米。

trackWidth

可选。左右车轮之间的宽度。默认值为 320 毫米。

wheelBase

可选。前后轮之间的距离。默认值为 320 毫米。

units

Optional. The unit for wheelTravel, trackWidth, and wheelBase: MM (millimeters, default), INCHES, or DistanceUnits.CM (centimeters).

externalGearRatio

Optional. The gear ratio used to adjust drive distances if gears are used. This can be an integer or decimal (float). The default is 1.0.

# Create the Inertial Sensor
brain_inertial = Inertial()

# Make left and right drive motors
left_drive_smart = Motor(Ports.PORT1, 1.0, False)
right_drive_smart = Motor(Ports.PORT6, 1.0, True)

# Create a SmartDrive object with wheelTravel 200
drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)

如果要制作一个带有多个电机的智能驱动系统,需要先分别创建电机,然后再将它们分组到一个电机组中。

# Create the Inertial Sensor
brain_inertial = Inertial()

# Create two motor groups for left and right motors
left_motor_a = Motor(Ports.PORT1, 1.0, False)
left_motor_b = Motor(Ports.PORT2, 1.0, False)
left_drive_smart = MotorGroup(left_motor_a, left_motor_b)

right_motor_a = Motor(Ports.PORT5, 1.0, True)
right_motor_b = Motor(Ports.PORT6, 1.0, True)
right_drive_smart = MotorGroup(right_motor_a, right_motor_b)

# Create a SmartDrive object with wheelTravel 200 mm
drivetrain = SmartDrive(left_drive_smart, right_drive_smart, brain_inertial, 200)