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 |
|---|---|
|
The name of the Left |
|
The name of the Right |
|
The name of the |
|
Opcional. La circunferencia de las ruedas motrices. El valor predeterminado es 300 mm. |
|
Opcional. Ancho de vía del tren motriz. El valor predeterminado es 320 mm. |
|
Opcional. La distancia entre ejes del tren motriz. El valor predeterminado es 320 mm. |
|
Optional. A valid |
|
Opcional. La relación de transmisión se utiliza para compensar las distancias de conducción si se utilizan engranajes. |
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.
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 |
|---|---|
|
A valid |
|
Optional. The velocity at which the Drivetrain will move. The default velocity set by The |
|
Optional. A valid |
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 |
|---|---|
|
A valid |
|
La distancia que debe recorrer el tren motriz. |
|
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 ( |
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 |
|---|---|
|
A valid |
|
Optional. The velocity at which the Drivetrain will turn. The default velocity set by The |
|
Optional. A valid |
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 |
|---|---|
|
El ángulo de rumbo hacia el cual girar. |
|
Optional. A valid |
|
Opcional. Gire los motores del smartdrive usando esta velocidad. |
|
Optional. A valid |
|
Optional. The wait parameter determines whether the method will block subsequent method ( |
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 |
|---|---|
|
El ángulo de rotación al que girar. |
|
Optional. A valid |
|
Opcional. Gire los motores del Smart Drivetrain usando esta velocidad. |
|
Optional. A valid |
|
Optional. The wait parameter determines whether the method will block subsequent method ( |
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 |
|---|---|
|
El ángulo hacia el que girar. |
|
Optional. A valid |
|
Opcional. Gire los motores del Smart Drivetrain usando esta velocidad. |
|
Optional. A valid |
|
Optional. The wait parameter determines whether the method will block subsequent method ( |
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 |
|---|---|
|
La nueva velocidad que se establecerá como predeterminada para el Smart Drivetrain. |
|
Optional. A valid |
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 |
|---|---|
|
La nueva velocidad que se establecerá como predeterminada para las maniobras de giro. |
|
Optional. A valid |
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 |
|---|---|
|
A valid |
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 |
|---|---|
|
The new turn threshold in |
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 |
|---|---|
|
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 |
|---|---|
|
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 |
|---|---|
|
El nuevo valor a utilizar para el encabezado. |
|
Optional. A valid |
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
El nuevo valor a utilizar para la rotación. |
|
Optional. A valid |
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
La duración del tiempo de espera que se establecerá como predeterminada para las operaciones de Smart Drivetrain. |
|
Optional. A valid |
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
Optional. The only valid unit for current is |
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 |
|---|---|
|
Optional. The only valid unit for power is |
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 |
|---|---|
|
Optional. A valid |
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 |
|---|---|
|
Optional. The only valid unit for efficiency is |
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 |
|---|---|
|
Optional. A valid |
Devoluciones: La temperatura del Smart Drivetrain en las unidades proporcionadas.