DriveTrain#
Initializing the DriveTrain Class#
A DriveTrain is created by using the following constructor:
DriveTrain(lm, rm, wheelTravel, trackWidth, wheelBase, units, externalGearRatio)
This constructor uses seven parameters:
Parameter |
Description |
---|---|
|
The name of the Left Motor or Motor Group. |
|
The name of the Right Motor or Motor Group. |
|
Optional. The circumference of the driven wheels. The default is 300 mm. |
|
Optional. The track width of the Drivetrain. The default is 320 mm. |
|
Optional. The wheel base of the Drivetrain. The default is 320 mm. |
|
Optional. A valid DistanceUnit for the units that wheelTravel, trackWidth and wheelBase are specified in. The default is |
|
Optional. The gear ratio used to compensate drive distances if gearing is used. |
Motors and/or Motor Groups must be created first before they can be used to create an object with the DriveTrain Class constructor.
# 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)
If making a Drivetrain with multiple motors, you need to create the Motors separately before grouping them into a Motor Group.
# 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.
To incorporate an Inertial Sensor or Gyro Sensor for enhanced turning functionality in your Drivetrain, you can include it when creating an object using the SmartDrive Class constructor.
Class Methods#
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.
This is a non-waiting method and allows the next method to run without delay.
Parameters |
Description |
---|---|
direction |
A valid DirectionType. |
velocity |
Optional. The velocity at which the Drivetrain will move. The default velocity set by The |
units |
Optional. A valid VelocityUnits type. The default is |
Returns: None.
# 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.
Parameters |
Description |
---|---|
direction |
A valid DirectionType. |
distance |
The distance for the Drivetrain to move. |
units |
Optional. A valid DistanceUnits type. The default is |
velocity |
Optional. The velocity the Drivetrain will move with. The default velocity set by The |
units_v |
Optional. A valid VelocityUnits type. The default is |
wait |
Optional. The wait parameter determines whether the method will block subsequent method ( |
Returns: None.
# 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.
This is a non-waiting method and allows the next method to run without delay.
Parameters |
Description |
---|---|
direction |
A valid TurnType. |
velocity |
Optional. The velocity at which the Drivetrain will turn. The default velocity set by The |
units |
Optional. A valid VelocityUnits type. The default is |
Returns: None.
# 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)
method is used to turn the Drivetrain for a specific angle, either left or right.
This can be a waiting or non-waiting method depending on if the wait
parameter is used.
Parameters |
Description |
---|---|
direction |
A valid TurnType. |
angle |
The angle for the Drivetrain to turn. |
units |
Optional. A valid RotationUnits type. The default is |
velocity |
Optional. The velocity at which the Drivetrain will turn. The default velocity set by The |
units_v |
Optional. A valid VelocityUnits type. The default is |
wait |
Optional. The wait parameter determines whether the method will block subsequent method ( |
Returns: None.
# 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.
Returns: None.
# 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.
This is a non-waiting method and allows the next method to run without delay.
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.
Parameters |
Description |
---|---|
velocity |
The new velocity to set as default for the Drivetrain. |
units |
Optional. A valid VelocityUnits type. The default is |
Returns: None.
# 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.
Parameters |
Description |
---|---|
velocity |
The new velocity to set as default for turning maneuvers. |
units |
Optional. A valid VelocityUnits type. The default is |
Returns: None.
# 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.
Parameters |
Description |
---|---|
mode |
A valid BrakeType. The default is |
Returns: None.
# 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.
Parameters |
Description |
---|---|
timeout |
The timeout duration to set as default for Drivetrain operations. |
units |
Optional. A valid TimeUnits type. The default is |
Returns: None.
# 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.
Returns: The current time after which a Drivetrain method will timeout.
velocity()#
The velocity()
method returns the average velocity of the left and right motors.
Parameters |
Description |
---|---|
units |
Optional. A valid VelocityUnits type. The default is |
Returns: The Drivetrain velocity in the provided units.
current()#
The current()
method returns the average current of the left and right motors.
Parameters |
Description |
---|---|
units |
Optional. The only valid unit for current is |
Returns: The Drivetrain current in the provided units.
power()#
The power()
method returns the total power all Drivetrain motors are using.
Parameters |
Description |
---|---|
units |
Optional. The only valid unit for power is |
Returns: The Drivetrain power in the provided units.
torque()#
The torque()
method returns the total torque of all Drivetrain motors.
Parameters |
Description |
---|---|
units |
Optional. A valid TorqueUnits type. The default is |
Returns: The Drivetrain torque in the provided units.
efficiency()#
The efficiency()
method returns the average efficiency of the left and right motors.
Parameters |
Description |
---|---|
units |
Optional. The only valid unit for efficiency is |
Returns: The Drivetrain efficiency in the provided units.
temperature()#
The temperature()
method returns the average temperature of the left and right motors.
Parameters |
Description |
---|---|
units |
Optional. A valid TemperatureUnits type. The default is |
Returns: The Drivetrain temperature in the provided units.