Tren motriz#

Inicializando la clase DriveTrain#

Un DriveTrain se crea utilizando el siguiente constructor:

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

Este constructor utiliza siete parámetros:

Parámetro

Descripción

lm

The name of the Left Motor or Motor Group.

rm

The name of the Right Motor or Motor Group.

wheelTravel

Opcional. La circunferencia de las ruedas motrices. El valor predeterminado es 300 mm.

trackWidth

Opcional. Ancho de vía del tren motriz. El valor predeterminado es 320 mm.

wheelBase

Opcional. La distancia entre ejes del tren motriz. El valor predeterminado es 320 mm.

units

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

externalGearRatio

Opcional. La relación de transmisión se utiliza para compensar las distancias de conducción si se utilizan engranajes.

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.

Métodos de clase#

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.

Este es un método sin espera y permite que el siguiente método se ejecute sin demora.

Parámetros

Descripción

direction

A valid DirectionType.

velocity

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

units

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

direction

A valid DirectionType.

distance

La distancia que debe recorrer el tren motriz.

units

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

velocity

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

units_v

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

wait

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.

Devoluciones: Ninguna.

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

Este es un método sin espera y permite que el siguiente método se ejecute sin demora.

Parámetros

Descripción

direction

A valid TurnType.

velocity

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.

units

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

direction

A valid TurnType.

angle

El ángulo en el que debe girar la transmisión.

units

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

velocity

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.

units_v

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

wait

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.

Devoluciones: Ninguna.

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

Devoluciones: Ninguna.

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

Este es un método sin espera y permite que el siguiente método se ejecute sin demora.

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.

Parámetros

Descripción

velocity

La nueva velocidad que se establecerá como predeterminada para el tren motriz.

units

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

velocity

La nueva velocidad que se establecerá como predeterminada para las maniobras de giro.

units

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

mode

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

timeout

La duración del tiempo de espera que se establecerá como predeterminada para las operaciones de transmisión.

units

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

Devoluciones: Ninguna.

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

Devuelve: El tiempo actual después del cual se agotará el tiempo de espera de un método Drivetrain.

velocity()#

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

Parámetros

Descripción

units

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

Devuelve: La velocidad del tren motriz en las unidades proporcionadas.

current()#

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

Parámetros

Descripción

units

Optional. The only valid unit for current is AMP.

Devuelve: La corriente del tren motriz en las unidades proporcionadas.

power()#

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

Parámetros

Descripción

units

Optional. The only valid unit for power is WATT.

Devoluciones: La potencia del tren motriz en las unidades proporcionadas.

torque()#

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

Parámetros

Descripción

units

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

Devoluciones: El torque del tren motriz en las unidades proporcionadas.

efficiency()#

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

Parámetros

Descripción

units

Optional. The only valid unit for efficiency is PERCENT.

Devoluciones: La eficiencia del tren motriz en las unidades proporcionadas.

temperature()#

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

Parámetros

Descripción

units

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

Devoluciones: La temperatura del tren motriz en las unidades proporcionadas.