SmartDrive#
Introducción#
The smartdrive class is derived from the drivetrain base class and incorporates an Inertial Sensor, Gyro Sensor, or GPS Sensor for heading and rotation-based functions.
Constructores de clases#
1 — Creates a smartdrive using existing
motor_groupobjects for the left (&l) and right (&r) sides, along with aguidosensor.smartdrive( motor_group &l, motor_group &r, guido &g, double wheelTravel = 320, double trackWidth = 320, double wheelBase = 130, distanceUnits unit = mm, double externalGearRatio = 1.0 );
2 — Creates a smartdrive using existing
motorobjects for the left (&l) and right (&r) sides, along with aguidosensor.smartdrive( motor &l, motor &r, guido &g, double wheelTravel = 320, double trackWidth = 320, double wheelBase = 130, distanceUnits unit = mm, double externalGearRatio = 1.0 );
Instructor de clase#
Destroys the smartdrive object and releases associated resources.
~smartdrive();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
References to existing |
|
|
A reference to an existing |
|
|
The wheel’s circumference. Default is |
|
|
The distance between the left and right wheels. Default is |
|
|
The width of the wheel base. Default is |
|
|
Units for the
|
|
|
The gear ration compensation factor. Default is |
Ejemplo#
/* This constructor is required when using VS Code.
Drivetrain configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the left and right motor instances
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);
// Create the inertial instance
inertial myInertial = inertial(PORT3);
// Create the smartdrive instance
smartdrive myDrivetrain = smartdrive(
leftMotor, // left motor object
rightMotor, // right motor object
myInertial, // inertial object
259.34, // wheelTravel
320, // trackWidth
40, // wheelBase
mm, // unit
1.0 ); // externalGearRatio
Funciones de los miembros#
The smartdrive class includes the following member functions:
turnToHeading— Rotates the robot to face a specific absolute heading.turnToRotation— Rotates the robot to reach a specific cumulative rotation.calibrateDrivetrain— Calibrates the drivetrain’s configured Inertial Sensor, Gyro Sensor, or GPS Sensor.setHeading— Manually sets the robot’s heading value.setRotation— Manually sets the robot’s cumulative rotation value.heading— Returns the drivetrain’s heading angle.rotation— Returns how much the drivetrain has turned since the project started.
Before calling any smartdrive member functions, a smartdrive instance must be created, as shown below:
/* This constructor is required when using VS Code.
Drivetrain configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */
// Create the left and right motor instances
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);
// Create the inertial instance
inertial myInertial = inertial(PORT3);
// Create the smartdrive instance
smartdrive myDrivetrain = smartdrive(
leftMotor, // left motor object
rightMotor, // right motor object
myInertial, // inertial object
259.34, // wheelTravel
320, // trackWidth
40, // wheelBase
mm, // unit
1.0 ); // externalGearRatio
girarAlEncabezado#
Gira el sistema de transmisión hacia una dirección específica.
Available Functions1 — Gira el tren motriz hacia la dirección especificada utilizando la velocidad de giro configurada.
bool turnToHeading( double angle, rotationUnits units, bool waitForCompletion = true );
Parameters2 — Gira el tren de transmisión hacia la dirección especificada a la velocidad especificada.
bool turnToHeading( double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion = true );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
La dirección hacia la que girará el sistema de transmisión. |
|
|
The units representing the angle:
|
|
|
La velocidad a la que girará la transmisión se representa como un valor doble. Si no se especifica la velocidad o si previamente se estableció en, la velocidad predeterminada es del 50 %. |
|
|
The unit to represent the velocity:
|
|
|
Optional.
|
Returns a Boolean indicating whether the drivetrain reached the target heading parameter value:
true— The drivetrain successfully reaches the targetheadingparameter value.false— The drivetrain does not complete the movement or if thewaitForCompletionparameter is set tofalse.
Executing another drivetrain movement function (such as
turnordrive) whileturnToHeadingis in progress will interrupt the current movement.Because
turnToHeadingis target-based (uses anangleparameter), functions such asisDoneandisMovingwork withturnToHeading.
// Face the new 0 degrees
myDrivetrain.setHeading(90, degrees);
myDrivetrain.turnToHeading(0, degrees);
girarArotación#
Gira el sistema de transmisión hasta un valor de rotación específico.
Available Functions1 — Gira el tren de transmisión a la rotación especificada utilizando la velocidad de giro configurada.
bool turnToRotation( double angle, rotationUnits units, bool waitForCompletion = true );
Parameters2 — Gira el tren de transmisión a la rotación especificada a la velocidad especificada.
bool turnToRotation( double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion = true );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
El valor de rotación al que girará el sistema de transmisión. |
|
|
The units representing the angle:
|
|
|
La velocidad a la que girará la transmisión se representa como un valor doble. Si no se especifica la velocidad o si previamente se estableció en, la velocidad predeterminada es del 50 %. |
|
|
The unit to represent the velocity:
|
|
|
Optional.
|
Returns a Boolean indicating whether the drivetrain reached the target rotation parameter value:
true— The drivetrain successfully reaches the targetrotationparameter value.false— The drivetrain does not complete the movement or if thewaitForCompletionparameter is set tofalse.
Executing another drivetrain movement function (such as
turnordrive) whileturnToRotationis in progress will interrupt the current movement.Because
turnToRotationis target-based (uses anangleparameter), functions such asisDoneandisMovingwork withturnToRotation.
// Spin counterclockwise for 2 turns, then face forward
myDrivetrain.setRotation(720, degrees);
myDrivetrain.turnToRotation(0, degrees);
calibrar la transmisión#
Calibra el sistema de transmisión.
calibrateDrivetrain is a helper function generated automatically by VEXcode when a drivetrain is configured with an Inertial Sensor, GPS Sensor, or Gyro Sensor. It is provided as part of the project source and is not part of the VEX V5 C++ API.
calibrateDrivetrain();
Esta función no acepta ningún parámetro.
Return ValuesEsta función no devuelve ningún valor.
NotesEl robot se calibra automáticamente al inicio de cada proyecto.
Durante la calibración, asegúrese de que el robot esté sobre una superficie plana y permanezca inmóvil.
The following is the auto-generated implementation of calibrateDrivetrain created by VEXcode:
bool vexcode_initial_drivetrain_calibration_completed = false;
void calibrateDrivetrain() {
wait(200, msec);
Brain.Screen.print("Calibrating");
Brain.Screen.newLine();
Brain.Screen.print("Inertial");
DrivetrainInertial.calibrate();
while (DrivetrainInertial.isCalibrating()) {
wait(25, msec);
}
vexcode_initial_drivetrain_calibration_completed = true;
// Clears the screen and returns the cursor to row 1, column 1.
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
}
establecer encabezado#
Establece la dirección para el sistema de transmisión.
Available Functionsvoid setHeading(
double value,
rotationUnits units);
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
La dirección hacia la que apunta actualmente el sistema de transmisión. |
|
|
The units representing the heading:
|
Esta función no devuelve ningún valor.
Examples// Face the new 0 degrees
myDrivetrain.setHeading(90, degrees);
DrivemyDrivetraintrain.turnToHeading(0, degrees);
establecer rotación#
Establece la rotación para el sistema de transmisión.
Available Functionsvoid setRotation(
double value,
rotationUnits units);
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
La rotación hacia la que está orientada actualmente la transmisión. |
|
|
The units representing the heading:
|
Esta función no devuelve ningún valor.
Examples// Spin counterclockwise for 2 turns, then face forward
myDrivetrain.setRotation(720, degrees);
myDrivetrain.turnToRotation(0, degrees);
título#
Devuelve la dirección del sistema de transmisión.
Available Functionsdouble heading( rotationUnits units = rotationUnits::deg );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Optional. The units representing the heading:
|
Returns a double indicating the heading of the drivetrain in the units specified by the units parameter.
// Show heading before and after turning
Brain.Screen.print("Before: %f", myDrivetrain.heading(degrees));
myDrivetrain.turnFor(right, 90, degrees);
wait(1, seconds);
Brain.Screen.newLine();
Brain.Screen.print("After: %f", myDrivetrain.heading(degrees));
myDrivetrain.stop();
rotación#
Devuelve la rotación del sistema de transmisión.
Available Functionsdouble rotation( rotationUnits units = rotationUnits::deg );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Optional. The units representing the heading:
|
Returns a double indicating the rotation of the drivetrain in the units specified by the units parameter.
// Show rotation before and after turning
Brain.Screen.print("Before: %f", myDrivetrain.rotation(degrees));
myDrivetrain.turnFor(right, 90, degrees);
wait(1, seconds);
Brain.Screen.newLine();
Brain.Screen.print("After: %f", myDrivetrain.rotation(degrees));
myDrivetrain.stop();