unidad inteligente#
Inicializando la clase smartdrive#
Un sistema de transmisión inteligente se crea utilizando el siguiente constructor:
The smartdrive constructor creates a smartdrive object. This object can do everything a drivetrain can do but has additional methods that include use of an Inertial Sensor or Gyro in order to make more accurate turns.
Parámetro |
Descripción |
|---|---|
|
The name of the Left |
|
The name of the Right |
|
The name of the device you are using to detect the angle or heading of the robot. This can be the any |
|
Circunferencia de las ruedas motrices. El valor predeterminado es 300 mm. |
|
Ancho de vía del sistema de propulsión inteligente. El valor predeterminado es 320 mm. |
|
Distancia entre ejes del Smart Drivetrain. La distancia predeterminada es de 320 mm. |
|
A valid |
|
La relación de transmisión utilizada 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 smartdrive Class constructor.
// Create the Motors.
motor left_motor = motor(PORT1,false);
motor right_motor = motor(PORT2, true);
// Create the Inertial Sensor
inertial Inertial = inertial(PORT3);
// Construct a 2-Motor Smart Drivetrain "Smartdrive" with the
// smartdrive class.
smartdrive Smartdrive = smartdrive(left_motor, right_motor, Inertial, 259.34, 320, 40, mm, ratio18_1);
If making a 4-Motor Smart Drivetrain, you need to create the Motors separately before grouping them into a Motor Group.
// Create the left Motors and group them under the
// motor_group "leftMotors".
motor leftMotorA = motor(PORT1, false);
motor leftMotorB = motor(PORT2, false);
motor_group leftMotors = motor_group(leftMotorA, leftMotorB);
// Create the right Motors and group them under the
// MotorGroup "rightMotors".
motor rightMotorA = motor(PORT3, true);
motor rightMotorB = motor(PORT4, true);
motor_group rightMotors = motor_group(rightMotorA, rightMotorB);
// Create the Inertial Sensor
inertial Inertial = inertial(PORT5);
// Construct a 4-Motor smartdrive "Smartdrive" with the
// smartdrive class.
smartdrive Smartdrive = smartdrive(leftMotors, rightMotors, Inertial, 259.34, 320, 40, mm, ratio18_1);
This Smartdrive object will be used in all subsequent examples throughout this API documentation when referring to smartdrive class methods.
To create an object without Inertial Sensor or Gyro Sensor functionality, instead create an object using the drivetrain Class constructor.
Métodos de clase#
drive()#
Este es un método sin espera y permite que el siguiente método se ejecute sin demora.
Este método se llama de las siguientes maneras:
The drive(dir) method is used to drive the smartdrive in the specified direction forever at the default velocity as specified by the setDriveVelocity() method, until another Smart Drivetrain movement method is used, or the project is stopped.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
// Drive the smartdrive forward.
Smartdrive.drive(forward);
The drive(dir, velocity, units) method is used to drive the Smart Drivetrain in the specified direction forever at a specified velocity, until another Smart Drivetrain movement method is used, or the project is stopped.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
La velocidad a la que se moverá el smartdrive. |
|
A valid |
Devoluciones: Ninguna.
// Drive the smartdrive forward at 100 rpm.
Smartdrive.drive(forward, 100, rpm);
driveFor()#
This can be a waiting or non-waiting method depending on if the waitForCompletion parameter is used.
Este método se llama de las siguientes maneras:
The driveFor(distance, units, waitForCompletion) method is used to drive the Smart Drivetrain for a specified distance at the default velocity.
Parámetros |
Descripción |
|---|---|
|
La distancia que debe recorrer el smartdrive. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el smartdrive ha alcanzado la distancia objetivo.
// Drive the Smart Drivetrain for 10 inches.
Smartdrive.driveFor(10, inches);
The driveFor(dir, distance, units, waitForCompletion) method is used to drive the Smart Drivetrain in a specified direction for a specified distance at the default velocity.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
La distancia que debe recorrer el Smart Drivetrain. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el Smart Drivetrain ha alcanzado la distancia objetivo.
// Drive the Smart Drivetrain forward for 10 inches.
Smartdrive.driveFor(forward, 10, inches);
The driveFor(distance, units, velocity, units_v, waitForCompletion) method is used to drive the Smart Drivetrain for a specified distance at the default velocity.
Parámetros |
Descripción |
|---|---|
|
La distancia que debe recorrer el Smart Drivetrain. |
|
A valid |
|
The velocity the Smart Drivetrain will move with. The default velocity set by the |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el Smart Drivetrain ha alcanzado la distancia objetivo.
// Drive the Smart Drivetrain for 10 inches at 100 rpm.
Smartdrive.driveFor(10, inches, 100, rpm);
The driveFor(dir, distance, units, velocity, units_v, waitForCompletion) method is used to drive the Smart Drivetrain for a specified distance at the default velocity.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
La distancia que debe recorrer el Smart Drivetrain. |
|
A valid |
|
The velocity the Smart Drivetrain will move with. The default velocity set by the |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el Smart Drivetrain ha alcanzado la distancia objetivo.
// Drive the Smart Drivetrain forward for 10 inches at 100 rpm.
Smartdrive.driveFor(forward, 10, inches, 100, rpm);
turn()#
Este es un método sin espera y permite que el siguiente método se ejecute sin demora.
Este método se llama de las siguientes maneras:
The turn(dir) method is used to turn the robot in a specified direction at the default velocity as specified by the setTurnVelocity() method, until another Smart Drivetrain movement method is used, or the project is stopped.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
// Turn the Smart Drivetrain right.
Smartdrive.turn(right);
The turn(dir, velocity, units) method is used to turn the robot in a specified direction at a specified velocity, until another Smart Drivetrain movement method is used, or the project is stopped.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
The velocity at which the Smart Drivetrain will turn. The default velocity set by The |
|
A valid |
Devoluciones: Ninguna.
// Turn the Smart Drivetrain right at 100 rpm.
Smartdrive.turn(right, 100, rpm);
turnFor()#
This can be a waiting or non-waiting method depending on if the waitForCompletion parameter is used.
The turnFor() method in the smartdrive class works differently than in the drivetrain class because the Inertial Sensor or Gyro Sensor, instead of the internal motor encoders, are utilized to make more accurate turns.
Este método se llama de las siguientes maneras:
The turnFor(angle, units, waitForCompletion) method is used to turn the Smart Drivetrain for a specific angle at the default velocity as specified by the setTurnVelocity() method.
Parámetros |
Descripción |
|---|---|
|
El ángulo en el que debe girar el Smart Drivetrain. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el tren motriz inteligente ha girado al ángulo objetivo.
// Turn the Smart Drivetrain for 90 degrees.
Smartdrive.turnFor(90, degrees);
The turnFor(dir, angle, units, waitForCompletion) method is used to turn the Smart Drivetrain for a specific angle at the default velocity as specified by the setTurnVelocity() method.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
El ángulo en el que debe girar el Smart Drivetrain. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el tren motriz inteligente ha girado al ángulo objetivo.
// Turn the Smart Drivetrain right for 90 degrees.
Smartdrive.turnFor(right, 90, degrees);
The turnFor(angle, units, velocity, units_v, waitForCompletion) method is used to turn the Smart Drivetrain for a specific angle at a specified velocity.
Parámetros |
Descripción |
|---|---|
|
El ángulo en el que debe girar el Smart Drivetrain. |
|
A valid |
|
The velocity at which the Smart Drivetrain will turn. The default velocity set by The |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el tren motriz inteligente ha girado al ángulo objetivo.
// Turn the Smart Drivetrain for 90 degrees at 100 rpm.
Smartdrive.turnFor(90, degrees, 100, rpm);
The turnFor(dir, angle, units, velocity, units_v, waitForCompletion) method is used to turn the Smart Drivetrain for a specific angle at a specified velocity.
Parámetros |
Descripción |
|---|---|
|
A valid |
|
El ángulo en el que debe girar el Smart Drivetrain. |
|
A valid |
|
The velocity at which the Smart Drivetrain will turn. The default velocity set by The |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que representa si el tren motriz inteligente ha girado al ángulo objetivo.
// Turn the Smart Drivetrain right for 90 degrees at 100 rpm.
Smartdrive.turnFor(right, 90, degrees, 100, rpm);
turnToHeading()#
This can be a waiting or non-waiting method depending on if the waitForCompletion parameter is used.
Este método se llama de las siguientes maneras:
The turnToHeading(angle, units, waitForCompletion) method turns the Smart Drivetrain to a specific heading.
Parámetros |
Descripción |
|---|---|
|
El ángulo de rumbo hacia el cual girar. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el Smart Drivetrain ha alcanzado el valor de giro objetivo.
// Turn to heading 180 degrees.
Smartdrive.turnToHeading(180, degrees);
The turnToHeading(angle, units, velocity, units_v, waitForCompletion) method turns the Smart Drivetrain to a specific heading.
Parámetros |
Descripción |
|---|---|
|
El ángulo de rumbo hacia el cual girar. |
|
A valid |
|
Gire los motores del Smart Drivetrain usando esta velocidad. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el Smart Drivetrain ha alcanzado el valor de giro objetivo.
// Turn to heading 180 degrees at 100 rpm.
Smartdrive.turnToHeading(180, degrees, 100, rpm);
turnToRotation()#
This can be a waiting or non-waiting method depending on if the waitForCompletion parameter is used.
Este método se llama de las siguientes maneras:
The turnToRotation(angle, units, waitForCompletion) method turns the Smart Drivetrain to a specific rotation.
Parámetros |
Descripción |
|---|---|
|
El ángulo de rotación al que girar. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el Smart Drivetrain ha alcanzado el valor de giro objetivo.
// Turn to rotation 180 degrees.
Smartdrive.turnToRotation(180, degrees);
The turnToRotation(angle, units, velocity, units_v, waitForCompletion) method turns the Smart Drivetrain to a specific rotation.
Parámetros |
Descripción |
|---|---|
|
El ángulo de rotación al que girar. |
|
A valid |
|
Gire los motores del Smart Drivetrain usando esta velocidad. |
|
A valid |
|
Determines whether the command will block subsequent commands ( |
Devuelve: Un valor booleano que indica cuándo el Smart Drivetrain ha alcanzado el valor de giro objetivo.
// Turn to rotation 180 degrees at 100 rpm.
Smartdrive.turnToRotation(180, degrees, 100, rpm);
stop()#
Este es un comando sin espera y permite que el siguiente comando se ejecute sin demora.
Este método se llama de las siguientes maneras:
The stop() command is used to stop the Smart Drivetrain, setting the Smart Drivetrain to 0 velocity and configuring the current stopping mode. The default Brake Type is coast, unless previously changed using the setStopping() command.
Devoluciones: Ninguna.
// Spin Smartdrive for 2.5 seconds.
Smartdrive.spin(forward);
wait(2.5 seconds);
// Stop Smartdrive.
Smartdrive.stop();
The stop(mode) command is used to stop the Smart Drivetrain using a specific Brake Type.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
// Spin Smartdrive for 2.5 seconds.
Smartdrive.spin(forward);
wait(2.5 seconds);
// Stop Smartdrive using the hold Brake Type.
Smartdrive.stop(hold);
isMoving()#
The isMoving() command returns if any Smart Drivetrain motor is on and rotating to a specific target.
Returns: true if any Smart Drivetrain motor is on and rotating to a target. false if it they are done rotating to a target.
isDone()#
The isDone() command returns if all Smart Drivetrain motors are done rotating to a specific target.
Returns: true if the all Smart Drivetrain motors are done rotating to a target. false if any Smart Drivetrain motor is on and rotating to a target.
isTurning()#
The isTurning() method returns if a turnToHeading(), turnToRotation(), or turnFor() method is currently running.
Returns: true if the a turnToHeading(), turnToRotation(), or turnFor() method is currently running. false if one is not.
setDriveVelocity()#
The setDriveVelocity(velocity, units) method is used to set the default velocity for the Smartdrive. This velocity setting affects all subsequent drive method unless a specific velocity is provided in those method.
Parámetros |
Descripción |
|---|---|
|
La nueva velocidad que se establecerá como predeterminada para el Smartdrive. |
|
A valid |
Devoluciones: Ninguna.
// Set the Smart Drivetrain to drive at a velocity of 200 rpm.
Smartdrive.setDriveVelocity(200, rpm);
setTurnVelocity()#
The setTurnVelocity(velocity, units) method is used to set the default velocity for turning maneuvers in the Smartdrive. 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. |
|
A valid |
Devoluciones: Ninguna.
// Set the Smart Drivetrain to turn at a velocity of 200 RPM.
Smartdrive.setTurnVelocity(200, rpm);
setStopping()#
The setStopping(mode) method is used to set the stopping mode for all motors on the Smartdrive. 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.setStopping(brake);
setGearRatio()#
The setGearRatio(mode) method is used to set the gear ratio for all motors on the Smartdrive.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devoluciones: Ninguna.
setTurnThreshold()#
The setTurnThreshold(t) method sets the turn threshold for the Smartdrive. 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.
setTurnConstant()#
The setTurnConstant(kp) method sets the turn constant for the Smartdrive. 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.
setTurnDirectionReverse()#
The setTurnDirectionReverse(value) method sets the expected turn direction for positive heading.
Parámetros |
Descripción |
|---|---|
|
A boolean value to set the reversed flag to |
Devoluciones: Ninguna.
setHeading()#
The setHeading(value, units) method sets the heading for the Smart Drivetrain Inertial Sensor or Gyro Sensor.
Parámetros |
Descripción |
|---|---|
|
El nuevo valor a utilizar para el encabezado. |
|
A valid |
Devoluciones: Ninguna.
// set the value of heading to 180 degrees.
Smartdrive.setHeading(180, degrees);
setRotation()#
The setRotation() method sets the rotation for the Smart Drivetrain Inertial Sensor or Gyro Sensor.
Parámetros |
Descripción |
|---|---|
|
El nuevo valor a utilizar para la rotación. |
|
A valid |
Devoluciones: Ninguna.
// Set the value of rotation to 180 degrees.
Smartdrive.setRotation(180, degrees);
setTimeout()#
The Smartdrive.setTimeout(time, units) method is used to set the timeout value for all motors on the Smartdrive. This setting determines how long the Smart Drivetrain will attempt to execute driveFor or turnFor 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. |
|
A valid |
Devoluciones: Ninguna.
// Set the timeout for the Smart Drivetrain to 10 seconds.
Smartdrive.setTimeout(10, seconds);
heading()#
The heading(units) method returns the current heading of the Smartdrive.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa el rumbo actual del Smart Drivetrain en las unidades especificadas.
// Get the current heading for the Smartdrive.
double value = Smartdrive.heading();
rotation()#
The rotation(units) method returns the current rotation of the Smartdrive.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa la rotación actual del Smart Drivetrain en las unidades especificadas.
// Get the current rotation for the Smartdrive.
double value = Smartdrive.rotation();
velocity()#
The velocity(units) method returns the average velocity of the Smart Drivetrain.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa la velocidad del Smart Drivetrain en las unidades especificadas.
current()#
The current() method returns the average current of the Smart Drivetrain.
Parámetros |
Descripción |
|---|---|
|
The only valid units for current are |
Devuelve: Un doble que representa la corriente del Smart Drivetrain en las unidades especificadas.
voltage()#
The voltage(units) method returns the average velocity of the Smart Drivetrain.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa el voltaje del Smart Drivetrain en las unidades especificadas.
power()#
The power(units) method returns the average power of the Smart Drivetrain .
Parámetros |
Descripción |
|---|---|
|
The only valid unit for power is |
Devuelve: Un doble que representa la potencia del Smart Drivetrain en las unidades especificadas.
torque()#
The torque() method returns the average torque of the Smart Drivetrain.
Parámetros |
Descripción |
|---|---|
|
A valid |
Devuelve: Un doble que representa el torque del Smart Drivetrain en las unidades especificadas.
efficiency()#
The efficiency() method returns the average efficiency of the Smart Drivetrain.
Parámetros |
Descripción |
|---|---|
|
The only valid unit for efficiency is |
Devuelve: Un doble que representa la eficiencia del Smart Drivetrain en las unidades proporcionadas.
temperature()#
The temperature() method returns the average temperature of the Smart Drivetrain.
Parámetros |
Descripción |
|---|---|
|
The only valid unit for temperature is |
Devuelve: Un doble que representa la temperatura del Smart Drivetrain en las unidades proporcionadas.