智能驾驶#
初始化 SmartDrive 类#
使用以下构造函数创建 SmartDrive:
SmartDrive(lm, rm, g, wheelTravel, trackWidth, wheelBase, units, externalGearRatio)
此构造函数使用八个参数:
范围 |
描述 |
|---|---|
|
The name of the Left |
|
The name of the Right |
|
The name of the |
|
**可选。**驱动轮的周长。默认值为 300 毫米。 |
|
**可选。**传动系统的轮距。默认值为 320 毫米。 |
|
**可选。**传动系统的轴距。默认值为 320 毫米。 |
|
Optional. A valid |
|
**可选。**如果使用齿轮传动,则使用齿轮比来补偿驱动距离。 |
Motors, Motor Groups, Inertial Sensors, and/or Gyro Sensors must be created first before they can be used to create an object with the SmartDrive Class constructor.
# Create the Inertial Sensor.
brain_inertial = Inertial()
# 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 Smart Drivetrain "drivetrain" with the
# DriveTrain class.
smartdrive = SmartDrive(left_motor, right_motor, brain_inertial, 319.19, 295, 40, MM, 1)
If making a Smart Drivetrain with multiple motors, you need to create the Motors separately before grouping them into a Motor Group.
# Create the Inertial Sensor.
brain_inertial = Inertial()
# 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.
smartdrive = SmartDrive(left_motors, right_motors, brain_inertial, 319.19, 295, 40, MM, 1)
This smartdrive object will be used in all subsequent examples throughout this API documentation when referring to SmartDrive class methods.
To create a DriveTrain object without an Inertial Sensor or Gyro Sensor, use the DriveTrain Class constructor.
类方法#
drive()#
The drive(direction, velocity, units) method is used to drive the Smart Drivetrain in the specified direction forever, until another Drivetrain method is used, or the project is stopped.
这是一种非等待方法,允许下一个方法无延迟运行。
参数 |
描述 |
|---|---|
|
A valid |
|
Optional. The velocity at which the Drivetrain will move. The default velocity set by The |
|
Optional. A valid |
**返回:**无。
# Drive the Smart Drivetrain forward.
smartdrive.drive(FORWARD)
# Drive the Smart Drivetrain in reverse for 100 percent velocity.
smartdrive.drive(REVERSE, 100, PERCENT)
drive_for()#
The drive_for(direction, distance, units, velocity, units_v, wait) method is used to drive the Smart Drivetrain a given distance.
This can be a waiting or non-waiting method depending on if the wait parameter is used.
参数 |
描述 |
|---|---|
|
A valid |
|
传动系统移动的距离。 |
|
Optional. A valid |
|
Optional. The velocity the Drivetrain will move with. The default velocity set by The |
|
Optional. A valid |
|
Optional. The wait parameter determines whether the method will block subsequent method ( |
**返回:**无。
# Drive forward for 10 inches.
smartdrive.drive_for(FORWARD, 10)
turn()#
The turn(direction, velocity, units) method is used to turn the Smart Drivetrain either left or right.
这是一种非等待方法,允许下一个方法无延迟运行。
参数 |
描述 |
|---|---|
|
A valid |
|
Optional. The velocity at which the Drivetrain will turn. The default velocity set by The |
|
Optional. A valid |
**返回:**无。
# Turn the Smart Drivetrain to the right.
smartdrive.turn(RIGHT)
# Turn the Smart Drivetrain to the left at 25% velocity.
smartdrive.turn(LEFT, 25, PERCENT)
turn_to_heading()#
The turn_to_heading(angle, units, velocity, units_v, wait) method turns the Smart Drivetrain to a specific heading.
This can be a waiting or non-waiting method depending on if the wait parameter is used.
参数 |
描述 |
|---|---|
|
转向的航向角。 |
|
Optional. A valid |
|
**可选。**使用此速度旋转智能驱动器的电机。 |
|
Optional. A valid |
|
Optional. The wait parameter determines whether the method will block subsequent method ( |
**返回:**无。
# Turn to heading 180 degrees.
smartdrive.turn_to_heading(180)
turn_to_rotation()#
The turn_to_rotation(angle, units, velocity, units_v, wait) method turns the Smart Drivetrain to a specific rotation.
This can be a waiting or non-waiting method depending on if the wait parameter is used.
参数 |
描述 |
|---|---|
|
要旋转的旋转角度。 |
|
Optional. A valid |
|
**可选。**使用此速度旋转智能传动系统的电机。 |
|
Optional. A valid |
|
Optional. The wait parameter determines whether the method will block subsequent method ( |
**返回:**无。
# Turn to rotation 180 degrees.
smartdrive.turn_to_rotation(180)
turn_for()#
The turn_for(angle, units, velocity, units_v, wait) method turns the Smart Drivetrain for a specified angle.
This can be a waiting or non-waiting method depending on if the wait parameter is used.
参数 |
描述 |
|---|---|
|
转向的角度。 |
|
Optional. A valid |
|
**可选。**使用此速度旋转智能传动系统的电机。 |
|
Optional. A valid |
|
Optional. The wait parameter determines whether the method will block subsequent method ( |
**返回:**无。
# Turn for 180 degrees.
smartdrive.turn_for(180)
stop()#
The stop() method is used to stop the Smart Drivetrain, setting it to 0 velocity and configuring the current stopping mode.
**返回:**无。
# Stop the Smart Drivetrain.
smartdrive.stop()
set_drive_velocity()#
The set_drive_velocity(velocity, units) method is used to set the default velocity for the Smart Drivetrain. This velocity setting affects all subsequent Drivetrain methods unless a specific velocity is provided in those method.
参数 |
描述 |
|---|---|
|
为智能传动系统设置的新速度为默认速度。 |
|
Optional. A valid |
**返回:**无。
# Set the Smart Drivetrain to drive at a velocity of
# 200 RPM.
smartdrive.set_drive_velocity(200)
# Set the Smart Drivetrain to drive at a velocity of
# 100 PERCENT.
smartdrive.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 Smart Drivetrain. This setting specifies the speed at which the Smart Drivetrain will execute turning method unless overridden by a specific velocity in those method.
参数 |
描述 |
|---|---|
|
设置为转弯操作默认的新速度。 |
|
Optional. A valid |
**返回:**无。
# Set the Smart Drivetrain to turn at a velocity of
# 200 RPM.
smartdrive.set_turn_velocity(200)
# Set the Smart Drivetrain to turn at a velocity of
# 100 PERCENT.
smartdrive.set_turn_velocity(100, PERCENT)
set_stopping()#
The set_stopping(mode) method is used to set the stopping mode for all Motors on the Smart 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 |
**返回:**无。
# Set the stopping mode to BRAKE.
smartdrive.set_stopping(BRAKE)
set_turn_threshold()#
The set_turn_threshold(value) method sets the turn threshold for the Smart Drivetrain. The threshold value is used to determine that turns are complete. If this is too large, then turns will not be accurate. If too small, then turns may not complete.
参数 |
描述 |
|---|---|
|
The new turn threshold in |
**返回:**无。
set_turn_constant()#
The set_turn_constant(value) method sets the turn constant for the Smart Drivetrain. The Smart Drivetrain uses a simple P controller when doing turns. This constant, generally known as kp, is the gain used in the equation that turns angular error into motor velocity.
参数 |
描述 |
|---|---|
|
新的转弯常数,范围为 0.1 - 4.0。默认值为 1.0。 |
**返回:**无。
set_turn_direction_reverse()#
The set_turn_direction_reverse(value) method sets the expected turn direction for positive heading change.
参数 |
描述 |
|---|---|
|
用于设置方向是否反转的布尔值。 |
**返回:**无。
set_heading()#
The set_heading(value, units) method sets the heading for the Smart Drivetrain.
参数 |
描述 |
|---|---|
|
用于标题的新值。 |
|
Optional. A valid |
**返回:**无。
# Set the value of heading to 180 degrees.
smartdrive.set_heading(180)
heading()#
The heading(units) method returns the current heading of the Smart Drivetrain.
参数 |
描述 |
|---|---|
|
Optional. A valid |
**返回:**以指定单位表示的智能传动系统的当前航向。
# Get the current heading for the Smart Drivetrain.
value = smartdrive.heading()
set_rotation()#
The set_rotation() method sets the rotation for the Smart Drivetrain.
参数 |
描述 |
|---|---|
|
用于旋转的新值。 |
|
Optional. A valid |
**返回:**无。
# Set the value of rotation to 180 degrees.
smartdrive.set_rotation(180)
rotation()#
The rotation(units) method returns the current rotation of the Smart Drivetrain.
参数 |
描述 |
|---|---|
|
Optional. A valid |
**返回:**智能传动系统以指定单位表示的当前旋转。
# Get the current rotation for the Smart Drivetrain.
value = smartdrive.rotation()
is_turning()#
The is_turning() method checks if the Smart Drivetrain is currently turning.
Returns: True if the Smart Drivetrain is currently turning. False if it is not currently turning.
is_moving()#
The is_moving() method checks if the Smart Drivetrain is currently moving.
Returns: True if the Smart Drivetrain is currently moving. False if it is not currently moving.
is_done()#
The is_done() method checks if the Smart Drivetrain is not currently moving.
Returns: True if the Smart Drivetrain is not currently moving. False if it is currently moving.
set_timeout()#
The set_timeout(timeout, units) method is used to set the timeout value for all motors on the Smart Drivetrain. This setting determines how long the Smart 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 |
**返回:**无。
# Set the timeout for the Smart Drivetrain to
# 1000 milliseconds.
drivetrain.set_timeout(1000)
获取超时()#
The smartdrive.get_timeout() method gets the current timeout setting.
**返回:**智能传动系统方法超时后的当前时间。
velocity()#
The velocity() method returns the average velocity of the left and right Motors.
参数 |
描述 |
|---|---|
|
Optional. A valid |
**返回:**以提供的单位表示的智能传动系统的速度。
current()#
The current() method returns the average current of the left and right Motors.
参数 |
描述 |
|---|---|
|
Optional. The only valid unit for current is |
**返回:**提供的单位中的智能传动系统电流。
power()#
The power() method returns the total power all Smart Drivetrain Motors are using.
参数 |
描述 |
|---|---|
|
Optional. The only valid unit for power is |
**返回:**智能传动系统的功率(以提供的单位表示)。
torque()#
The torque() method returns the total torque of all Smart Drivetrain motors.
参数 |
描述 |
|---|---|
|
Optional. A valid |
**返回:**以提供的单位表示的智能传动系统的扭矩。
efficiency()#
The efficiency() method returns the average efficiency of the left and right Motors.
参数 |
描述 |
|---|---|
|
Optional. The only valid unit for efficiency is |
**返回:**智能传动系统在所提供单位中的效率。
temperature()#
The temperature() method returns the average temperature of the left and right Motors.
参数 |
描述 |
|---|---|
|
Optional. A valid |
**返回:**以提供的单位表示的智能传动系统的温度。