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_group objects for the left (&l) and right (&r) sides, along with a guido sensor.

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 motor objects for the left (&l) and right (&r) sides, along with a guido sensor.

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

&l / &r

motor_group / motor

References to existing motor or motor_group instances. Both parameters must be of the same type: either two motor_group instances or two motor instances. The &l parameter refers to the left motor or motor group, and &r refers to the right motor or motor group.

&g

guido

A reference to an existing gps, gyro, or inertial instance.

wheelTravel

double

The wheel’s circumference. Default is 320, expressed in millimeters by default or in the units specified by the unit parameter.

trackWidth

double

The distance between the left and right wheels. Default is 320, expressed in millimeters by default or in the units specified by the unit parameter.

wheelBase

double

The width of the wheel base. Default is 130, expressed in millimeters by default or in the units specified by the unit parameter.

unit

distanceUnits

Units for the wheelTravel, trackWidth, and wheelBase parameters:

  • mm (default) — millimeters
  • inches

externalGearRatio

double

The gear ration compensation factor. Default is 1.0.

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:

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 Functions

1 Gira el tren motriz hacia la dirección especificada utilizando la velocidad de giro configurada.

bool turnToHeading(
    double        angle,
    rotationUnits units,
    bool          waitForCompletion = true );

2 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 );

Parameters

Parámetro

Tipo

Descripción

angle

double

La dirección hacia la que girará el sistema de transmisión.

units

rotationUnits

The units representing the angle:

  • deg — degrees
  • rev — revolutions
  • raw — raw units

velocity

double

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

units_v

velocityUnits

The unit to represent the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

waitForCompletion

bool

Optional.

  • true (default) — The project waits until the function finishes before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for the function to finish.

Return Values

Returns a Boolean indicating whether the drivetrain reached the target heading parameter value:

  • true — The drivetrain successfully reaches the target heading parameter value.
  • false — The drivetrain does not complete the movement or if the waitForCompletion parameter is set to false.

Notes
  • Executing another drivetrain movement function (such as turn or drive) while turnToHeading is in progress will interrupt the current movement.

  • Because turnToHeading is target-based (uses an angle parameter), functions such as isDone and isMoving work with turnToHeading.

Examples
// 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 Functions

1 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 );

2 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 );

Parameters

Parámetro

Tipo

Descripción

angle

double

El valor de rotación al que girará el sistema de transmisión.

units

rotationUnits

The units representing the angle:

  • deg — degrees
  • rev — revolutions
  • raw — raw units

velocity

double

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

units_v

velocityUnits

The unit to represent the velocity:

  • velocityUnits::pct — percent
  • rpm — rotations per minute
  • dps — degrees per second

waitForCompletion

bool

Optional.

  • true (default) — The project waits until the function finishes before executing the next line of code.
  • false — The project starts the action and moves on to the next line of code right away, without waiting for the function to finish.

Return Values

Returns a Boolean indicating whether the drivetrain reached the target rotation parameter value:

  • true — The drivetrain successfully reaches the target rotation parameter value.
  • false — The drivetrain does not complete the movement or if the waitForCompletion parameter is set to false.

Notes
  • Executing another drivetrain movement function (such as turn or drive) while turnToRotation is in progress will interrupt the current movement.

  • Because turnToRotation is target-based (uses an angle parameter), functions such as isDone and isMoving work with turnToRotation.

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

Available Functions
calibrateDrivetrain();

Parameters

Esta función no acepta ningún parámetro.

Return Values

Esta función no devuelve ningún valor.

Notes
  • El 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.

Function Implementation

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 Functions
void  setHeading( 
  double value, 
  rotationUnits units);

Parameters

Parámetro

Tipo

Descripción

value

double

La dirección hacia la que apunta actualmente el sistema de transmisión.

units

rotationUnits

The units representing the heading:

  • deg — degrees
  • rev — revolutions
  • raw — raw units

Return Values

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 Functions
void  setRotation( 
  double value, 
  rotationUnits units);

Parameters

Parámetro

Tipo

Descripción

value

double

La rotación hacia la que está orientada actualmente la transmisión.

units

rotationUnits

The units representing the heading:

  • deg — degrees
  • rev — revolutions
  • raw — raw units

Return Values

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 Functions
double heading( rotationUnits units = rotationUnits::deg );

Parameters

Parámetro

Tipo

Descripción

units

rotationUnits

Optional. The units representing the heading:

  • degrees / deg (default) — degrees
  • rev — revolutions
  • raw — raw units

Return Values

Returns a double indicating the heading of the drivetrain in the units specified by the units parameter.

Examples
// 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 Functions
double rotation( rotationUnits units = rotationUnits::deg );

Parameters

Parámetro

Tipo

Descripción

units

rotationUnits

Optional. The units representing the heading:

  • degrees / deg (default) — degrees
  • rev — revolutions
  • raw — raw units

Return Values

Returns a double indicating the rotation of the drivetrain in the units specified by the units parameter.

Examples
// 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();