传动系统#

初始化 DriveTrain 类#

使用以下构造函数创建 DriveTrain:

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

此构造函数使用七个参数:

范围

描述

lm

左侧 电机电机组 的名称。

rm

右侧 电机电机组 的名称。

wheelTravel

**可选。**驱动轮的周长。默认值为 300 毫米。

trackWidth

**可选。**传动系统的轮距。默认值为 320 毫米。

wheelBase

**可选。**传动系统的轴距。默认值为 320 毫米。

units

Optional. A valid DistanceUnit for the units that wheelTravel, trackWidth and wheelBase are specified in. The default is MM.

externalGearRatio

**可选。**如果使用齿轮传动,则使用齿轮比来补偿驱动距离。

必须先创建 Motors 和/或 Motor Groups,然后才能使用 DriveTrain 类构造函数创建对象。

# Create the Motors.
left_motor = Motor(Ports.PORT1, GearSetting.RATIO_18_1, False)
right_motor = Motor(Ports.PORT2, GearSetting.RATIO_18_1, True)
# Construct a 2-Motor Drivetrain "drivetrain" with the
# DriveTrain class.
drivetrain = DriveTrain(left_motor, right_motor, 319.19, 295, 40, MM, 1)

如果制作带有多个电机的传动系统,则需要先单独创建 电机,然后再将它们分组到 电机组中。

# Create the left Motors and group them under the
# MotorGroup "left_motors".
left_motor_a = Motor(Ports.PORT1, GearSetting.RATIO_18_1, False)
left_motor_b = Motor(Ports.PORT2, GearSetting.RATIO_18_1, False)
left_motors = MotorGroup(left_motor_a, left_motor_b)
# Create the right Motors and group them under the
# MotorGroup "right_motors".
right_motor_a = Motor(Ports.PORT3, GearSetting.RATIO_18_1, True)
right_motor_b = Motor(Ports.PORT4, GearSetting.RATIO_18_1, True)
right_motors = MotorGroup(right_motor_a, right_motor_b)
# Construct a 4-Motor Drivetrain "drivetrain" with the
# DriveTrain class.
drivetrain = DriveTrain(left_motors, right_motors, 319.19, 295, 40, MM, 1)

This drivetrain object will be used in all subsequent examples throughout this API documentation when referring to DriveTrain class methods.

要在您的传动系统中加入 惯性传感器陀螺仪传感器 以增强转弯功能,您可以在使用 SmartDrive 类构造函数创建对象时将其包含在内。

类方法#

drive()#

The drive(direction, velocity, units) method is used to drive the Drivetrain in the specified direction forever, until another Drivetrain method is used, or the project is stopped.

这是一种非等待方法,允许下一个方法无延迟运行。

参数

描述

方向

有效的 DirectionType

速度

Optional. The velocity at which the Drivetrain will move. The default velocity set by The set_velocity() method will be used.

单位

Optional. A valid VelocityUnits type. The default is RPM.

**返回:**无。

# Drive the Drivetrain forward.
drivetrain.drive(FORWARD)

# Drive the Drivetrain in reverse for 100 percent velocity.
drivetrain.drive(REVERSE, 100, PERCENT)

drive_for()#

The drive_for(direction, distance, units, velocity, units_v, wait) method is used to drive the Drivetrain a given distance.

This can be a waiting or non-waiting method depending on if the wait parameter is used.

参数

描述

方向

有效的 DirectionType

距离

传动系统移动的距离。

单位

Optional. A valid DistanceUnits type. The default is INCHES.

速度

Optional. The velocity the Drivetrain will move with. The default velocity set by The set_drive_velocity() method will be used if not provided.

单位

Optional. A valid VelocityUnits type. The default is RPM.

等待

Optional. The wait parameter determines whether the method will block subsequent method (wait=True) or allow immediate execution (wait=False). If unspecified, the default for The wait parameter is wait=True.

**返回:**无。

# Drive forward for 10 inches.
drivetrain.drive_for(FORWARD, 10)

turn()#

The turn(direction, velocity, units) method is used to turn the Drivetrain either left or right.

这是一种非等待方法,允许下一个方法无延迟运行。

参数

描述

方向

有效的 TurnType

速度

Optional. The velocity at which the Drivetrain will turn. The default velocity set by The set_turn_velocity() method will be used if not provided.

单位

Optional. A valid VelocityUnits type. The default is RPM.

**返回:**无。

# Turn the Drivetrain to the right.
drivetrain.turn(RIGHT)

# Turn the Drivetrain to the left at 25 percent velocity.
drivetrain.turn(LEFT, 25, PERCENT)

turn_for()#

The turn_for(direction, angle, units, velocity, units_v, wait) turns the drivetrain left or right for a specified angle or rotations.

This can be a waiting or non-waiting method depending on if the wait parameter is used.

参数

描述

方向

有效的 TurnType

角度

传动系统转动的角度。

单位

Optional. A valid RotationUnits type. The default is DEGREES.

速度

Optional. The velocity at which the Drivetrain will turn. The default velocity set by The set_turn_velocity() method will be used if not provided.

单位

Optional. A valid VelocityUnits type. The default is RPM.

等待

Optional. The wait parameter determines whether the method will block subsequent method (wait=True) or allow immediate execution (wait=False). If unspecified, the default for The wait parameter is wait=True.

**返回:**无。

# Turn right for 90 degrees.
drivetrain.turn_for(RIGHT, 90)

stop()#

The stop() method is used to stop the Drivetrain, setting it to 0 velocity and configuring the current stopping mode.

**返回:**无。

# Stop the Drivetrain.
drivetrain.stop()

is_moving()#

The is_moving() method checks if the Drivetrain is currently moving.

Returns: True if the Drivetrain is currently moving. False if the Drivetrain is not currently moving.

is_done()#

The is_done() method checks if the Drivetrain is not currently moving.

这是一种非等待方法,允许下一个方法无延迟运行。

Returns: True if the Drivetrain is not currently moving. False if the Drivetrain is currently moving.

set_drive_velocity()#

The set_drive_velocity(velocity, units) method is used to set the default velocity for the Drivetrain. This velocity setting affects all subsequent Drivetrain methods unless a specific velocity is provided in those method.

参数

描述

速度

为传动系统设置的新速度为默认速度。

单位

Optional. A valid VelocityUnits type. The default is RPM.

**返回:**无。

# Set the Drivetrain to drive at a velocity of 200 RPM.
drivetrain.set_drive_velocity(200)

# Set the Drivetrain to drive at a velocity of 100 PERCENT.
drivetrain.set_drive_velocity(100, PERCENT)

set_turn_velocity()#

The set_turn_velocity(velocity, units) method is used to set the default velocity for turning maneuvers in the Drivetrain. This setting specifies the speed at which the Drivetrain will execute turning method unless overridden by a specific velocity in those method.

参数

描述

速度

设置为转弯操作默认的新速度。

单位

Optional. A valid VelocityUnits type. The default is RPM, unless previously changed using The drivetrain.set_turn_velocity() method.

**返回:**无。

# Set the Drivetrain to turn at a velocity of 200 RPM.
drivetrain.set_turn_velocity(200)

# Set the Drivetrain to turn at a velocity of 100 PERCENT.
drivetrain.set_turn_velocity(100, PERCENT)

set_stopping()#

The set_stopping(mode) method is used to set the stopping mode for all motors on the Drivetrain. This setting determines the behavior of the motors when they receive a stop method or when the velocity is set to zero.

参数

描述

模式

A valid BrakeType. The default is COAST, unless previously changed using the drivetrain.set_stopping() method.

**返回:**无。

# Set the stopping mode to BRAKE.
drivetrain.set_stopping(BRAKE)

set_timeout()#

The set_timeout(timeout, units) method is used to set the timeout value for all motors on the Drivetrain. This setting determines how long the Drivetrain will attempt to execute drive_for and turn_for method before timing out if the motors have not completed their movements.

参数

描述

暂停

设置为传动系统操作默认的超时持续时间。

单位

Optional. A valid TimeUnits type. The default is MSEC, unless previously changed using the set_timeout() method.

**返回:**无。

# Set the timeout for the Drivetrain to 1000 milliseconds.
drivetrain.set_timeout(1000)

# Set the timeout for the Drivetrain to 2 seconds.
drivetrain.set_timeout(2, SECONDS)

get_timeout()#

The get_timeout() method gets the current timeout setting.

返回: Drivetrain 方法超时后的当前时间。

velocity()#

The velocity() method returns the average velocity of the left and right motors.

参数

描述

单位

Optional. A valid VelocityUnits type. The default is RPM.

**返回:**以提供的单位表示的传动系统速度。

current()#

The current() method returns the average current of the left and right motors.

参数

描述

单位

Optional. The only valid unit for current is AMP.

**返回:**以提供的单位表示的动力传动系统电流。

power()#

The power() method returns the total power all Drivetrain motors are using.

参数

描述

单位

Optional. The only valid unit for power is WATT.

**返回:**以提供的单位表示的传动系统功率。

torque()#

The torque() method returns the total torque of all Drivetrain motors.

参数

描述

单位

Optional. A valid TorqueUnits type. The default is NM.

**返回:**以提供的单位表示的传动系统扭矩。

efficiency()#

The efficiency() method returns the average efficiency of the left and right motors.

参数

描述

单位

Optional. The only valid unit for efficiency is PERCENT.

**返回:**以提供的单位表示的传动系统效率。

temperature()#

The temperature() method returns the average temperature of the left and right motors.

参数

描述

单位

Optional. A valid TemperatureUnits type. The default is CELSIUS.

**返回:**以提供的单位表示的传动系统温度。