SmartDrive#

Inicialización de la clase SmartDrive#

Un SmartDrive se crea utilizando el siguiente constructor:

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

Este constructor utiliza ocho parámetros:

Parámetro

Descripción

lm

El nombre del Motor o Grupo Motor izquierdo.

rm

El nombre del Motor o Grupo Motor derecho.

g

El nombre del Sensor inercial o Sensor giroscópico.

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.

Los Motores, Grupos de motores, Sensores inerciales y/o Sensores giroscópicos deben crearse primero antes de que puedan usarse para crear un objeto con el constructor de la clase SmartDrive.

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

Si va a crear un sistema de transmisión inteligente con varios motores, deberá crear los Motores por separado antes de agruparlos en un Grupo de motores.

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

Para crear un objeto DriveTrain sin un Sensor inercial o Sensor giroscópico, utilice el constructor de clase DriveTrain.

Métodos de clase#

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.

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

Parámetros

Descripción

dirección

Un DirectionType válido.

velocidad

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

unidades

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

dirección

Un DirectionType válido.

distancia

La distancia que debe recorrer el tren motriz.

unidades

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

velocidad

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

unidades_v

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

esperar

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.
smartdrive.drive_for(FORWARD, 10)

turn()#

The turn(direction, velocity, units) method is used to turn the Smart 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

dirección

Un TurnType válido.

velocidad

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

unidades

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

ángulo

El ángulo de rumbo hacia el cual girar.

unidades

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

velocidad

Opcional. Gire los motores del smartdrive usando esta velocidad.

unidades_v

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

esperar

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

Parámetros

Descripción

ángulo

El ángulo de rotación al que girar.

unidades

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

velocidad

Opcional. Gire los motores del Smart Drivetrain usando esta velocidad.

unidades_v

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

esperar

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

Parámetros

Descripción

ángulo

El ángulo hacia el que girar.

unidades

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

velocidad

Opcional. Gire los motores del Smart Drivetrain usando esta velocidad.

unidades_v

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

esperar

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

velocidad

La nueva velocidad que se establecerá como predeterminada para el Smart Drivetrain.

unidades

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

velocidad

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

unidades

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

modo

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

valor

The new turn threshold in DEGREES. The default for a Smart Drivetrain is 1 degree.

Devoluciones: Ninguna.

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.

Parámetros

Descripción

valor

La nueva constante de giro está en el rango de 0,1 a 4,0. El valor predeterminado es 1,0.

Devoluciones: Ninguna.

set_turn_direction_reverse()#

The set_turn_direction_reverse(value) method sets the expected turn direction for positive heading change.

Parámetros

Descripción

valor

Un valor booleano para establecer si la dirección se invierte o no.

Devoluciones: Ninguna.

set_heading()#

The set_heading(value, units) method sets the heading for the Smart Drivetrain.

Parámetros

Descripción

valor

El nuevo valor a utilizar para el encabezado.

unidades

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

unidades

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

Devuelve: El rumbo actual del Smart Drivetrain en las unidades especificadas.

# Get the current heading for the Smart Drivetrain.
value = smartdrive.heading()

set_rotation()#

The set_rotation() method sets the rotation for the Smart Drivetrain.

Parámetros

Descripción

valor

El nuevo valor a utilizar para la rotación.

unidades

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

Devoluciones: Ninguna.

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

Parámetros

Descripción

unidades

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

Devuelve: La rotación actual del Smart Drivetrain en las unidades especificadas.

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

Parámetros

Descripción

se acabó el tiempo

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

unidades

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

Devoluciones: Ninguna.

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

obtener_tiempo_de_espera()#

The smartdrive.get_timeout() method gets the current timeout setting.

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

velocity()#

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

Parámetros

Descripción

unidades

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

Devoluciones: La velocidad del Smart Drivetrain en las unidades proporcionadas.

current()#

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

Parámetros

Descripción

unidades

Optional. The only valid unit for current is AMP.

Devoluciones: La corriente del Smart Drivetrain en las unidades proporcionadas.

power()#

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

Parámetros

Descripción

unidades

Optional. The only valid unit for power is WATT.

Devoluciones: La potencia del Smart Drivetrain en las unidades proporcionadas.

torque()#

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

Parámetros

Descripción

unidades

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

Devoluciones: El torque del Smart Drivetrain en las unidades proporcionadas.

efficiency()#

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

Parámetros

Descripción

unidades

Optional. The only valid unit for efficiency is PERCENT.

Devoluciones: La eficiencia del Smart Drivetrain en las unidades proporcionadas.

temperature()#

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

Parámetros

Descripción

unidades

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

Devoluciones: La temperatura del Smart Drivetrain en las unidades proporcionadas.