Tren de transmisión#

Introducción#

The drivetrain class controls how a robot drives and turns. A drivetrain is made of motors and wheels that work together to move the robot.

A drivetrain does not use a Gyro Sensor or Inertial Sensor for heading-based or rotation-based turns. It can drive forward or reverse and turn left or right, but it cannot turn to a specific heading or rotation. For heading-based and rotation-based turns, use the smartdrive class.

This page uses myDrivetrain as the example drivetrain name. Replace it with your own configured name as needed.

Clases derivadas#

The drivetrain class serves as a base class for the following derived class:

  • smartdrive - Creates a drivetrain with Gyro Sensor or Inertial Sensor support.

Constructores de clases#

1 - Creates a drivetrain using existing motor_group objects for the left and right sides.

drivetrain(
    motor_group      &l,
    motor_group      &r,
    double           wheelTravel = 320,
    double           trackWidth = 320,
    double           wheelBase = 130,
    distanceUnits    unit = mm,
    double           externalGearRatio = 1.0 );

2 - Creates a drivetrain using existing motor objects for the left and right sides.

drivetrain(
    motor            &l,
    motor            &r,
    double           wheelTravel = 320,
    double           trackWidth = 320,
    double           wheelBase = 130,
    distanceUnits    unit = mm,
    double           externalGearRatio = 1.0 );

Instructor de clase#

Destroys the drivetrain object and releases associated resources.

virtual ~drivetrain();

Parámetros#

Parámetro

Tipo

Descripción

&l / &r

motor_group / motor

The left and right motors or motor groups. Both parameters must use the same type: either two motor_group objects or two motor objects.

wheelTravel

double

The circumference of the drivetrain wheels. The default is 320.

trackWidth

double

The distance between the left and right wheels. The default is 320.

wheelBase

double

The distance between the front and back wheels. The default is 130.

unit

distanceUnits

The unit for wheelTravel, trackWidth, and wheelBase: mm (default) or inches.

externalGearRatio

double

The gear ratio used to adjust drive distances if gears are used. The default is 1.0.

Ejemplo#

// Create the left and right motor objects.
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);

// Create the drivetrain object.
drivetrain myDrivetrain = drivetrain(
    leftMotor,  // left motor
    rightMotor, // right motor
    259.34,     // wheelTravel
    320,        // trackWidth
    40,         // wheelBase
    mm,         // unit
    1.0 );      // externalGearRatio

Funciones de los miembros#

The drivetrain class includes the following member functions:

Acciones: Mover y girar el robot.

  • drive - Moves the robot forward or reverse forever.

  • driveFor - Moves the robot forward or reverse for a specific distance.

  • turn - Turns the robot left or right forever.

  • turnFor - Turns the robot left or right for a specific number of degrees or revolutions.

  • stop - Stops the robot’s movement.

Ajustes - Ajustar la configuración de la transmisión.

  • setDriveVelocity - Tells the robot how fast to drive.

  • setTurnVelocity - Tells the robot how fast to turn.

  • setStopping - Tells how the robot will stop moving: by braking, coasting, or holding.

  • setTimeout - Sets how long the robot will try to finish a movement.

Valores - Comprobar el estado del movimiento.

  • isDone - Returns whether the robot is finished moving, as a Boolean value.

  • isMoving - Returns whether the robot is moving, as a Boolean value.

  • velocity - Returns how fast the robot is driving.

  • current - Returns how much electrical current the drivetrain is using.

  • power - Returns how quickly the drivetrain is using energy.

  • torque - Returns how much torque the drivetrain is using.

  • efficiency - Returns how efficiently the drivetrain is using power.

  • temperature - Returns how warm the drivetrain is.

  • voltage - Returns the electrical voltage of the drivetrain.

Before calling any drivetrain member functions, a drivetrain object must be created.

/* 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 objects.
motor leftMotor = motor(PORT1, false);
motor rightMotor = motor(PORT9, true);

// Create the drivetrain object.
drivetrain myDrivetrain = drivetrain(
    leftMotor,  // left motor
    rightMotor, // right motor
    259.34,     // wheelTravel
    320,        // trackWidth
    40,         // wheelBase
    mm,         // unit
    1.0 );      // externalGearRatio

Comportamiento#

conducir#

drive moves the robot forward or reverse forever. The robot will continue to move until it is given another action, like turning or stopping.

Available Functions

1 - Acciona utilizando la velocidad de accionamiento actual.

void drive(
    directionType dir );

2 - Conduce a la velocidad especificada.

void drive(
    directionType dir,
    double        velocity,
    velocityUnits units );

Parameters

Parámetro

Tipo

Descripción

dir

directionType

The direction the robot moves: forward or reverse.

velocity

double

The velocity to drive with from 0% to 100% when using velocityUnits::pct, from 0 to 120 rpm when using rpm, or from 0 to 720 degrees per second when using dps. If no velocity is provided, the robot drives at the current drive velocity.

units

velocityUnits

The velocity unit: velocityUnits::pct (percent), rpm (rotations per minute), or dps (degrees per second).

Return Values

Esta función no devuelve ningún valor.

Notes
  • drive is non-waiting. The project will run the next line of code right away.

  • The robot will continue to move until stop is called or another drivetrain movement function runs.

  • isDone and isMoving are not used with drive because drive does not have a target distance.

Examples
// Drive forward and back.
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.drive(reverse, 25, rpm);
wait(2, seconds);
myDrivetrain.stop();

driveFor#

driveFor moves the robot forward or reverse for a specific distance. The project will wait until the robot is done moving before the next line of code runs.

Available Functions

1 - Conduce en la dirección especificada durante una distancia utilizando la velocidad de conducción actual.

bool driveFor(
    directionType dir,
    double        distance,
    distanceUnits units,
    bool          waitForCompletion = true );

2 - Conduce en una dirección basada en el valor de la distancia utilizando la velocidad de conducción actual.

bool driveFor(
    double        distance,
    distanceUnits units,
    bool          waitForCompletion = true );

3 - Conduce en una dirección basada en el valor de la distancia a la velocidad especificada.

bool driveFor(
    double        distance,
    distanceUnits units,
    double        velocity,
    velocityUnits units_v,
    bool          waitForCompletion = true );

4 - Conduce en la dirección especificada durante una distancia a la velocidad especificada.

bool driveFor(
    directionType dir,
    double        distance,
    distanceUnits units,
    double        velocity,
    velocityUnits units_v,
    bool          waitForCompletion = true );

Parameters

Parámetro

Tipo

Descripción

dir

directionType

The direction the robot moves: forward or reverse.

distance

double

La distancia que recorre el robot.

units

distanceUnits

The distance unit: mm (millimeters), inches, or cm (centimeters).

velocity

double

The velocity to drive with from 0% to 100% when using velocityUnits::pct, from 0 to 120 rpm when using rpm, or from 0 to 720 degrees per second when using dps. If no velocity is provided, the robot drives at the current drive velocity.

units_v

velocityUnits

The velocity unit: velocityUnits::pct (percent), rpm (rotations per minute), or dps (degrees per second).

waitForCompletion

bool

true (default) makes the project wait until the robot is done moving before the next line of code runs. false makes the next line of code run right away.

Return Values

Devuelve, como valor booleano, si el robot alcanzó la distancia objetivo.

  • true - The robot reached the target distance.

  • false - The robot did not finish the movement, or the function returned before the movement completed because waitForCompletion was set to false.

Notes
  • Running another drivetrain movement function while driveFor is running will interrupt the current movement.

  • driveFor uses a target distance, so isDone and isMoving can be used with it.

Examples
// Drive 200 mm, then back 200 mm.
myDrivetrain.driveFor(forward, 200, mm);
myDrivetrain.driveFor(reverse, 200, mm);

doblar#

turn turns the robot left or right forever. The robot will continue to turn until it is given another action, like driving or stopping.

Available Functions

1 - Gira utilizando la velocidad de giro actual.

void turn(
    turnType dir );

2 - Gira a la velocidad especificada.

void turn(
    turnType     dir,
    double       velocity,
    velocityUnits units );

Parameters

Parámetro

Tipo

Descripción

dir

turnType

The direction the robot turns: left or right.

velocity

double

The velocity to turn with from 0% to 100% when using velocityUnits::pct, from 0 to 120 rpm when using rpm, or from 0 to 720 degrees per second when using dps. If no velocity is provided, the robot turns at the current turn velocity.

units

velocityUnits

The velocity unit: velocityUnits::pct (percent), rpm (rotations per minute), or dps (degrees per second).

Return Values

Esta función no devuelve ningún valor.

Notes
  • turn is non-waiting. The project will run the next line of code right away.

  • The robot will continue turning until stop is called or another drivetrain movement function runs.

  • isDone and isMoving are not used with turn because turn does not have a target angle.

Examples
// Turn right, then left, then stop.
myDrivetrain.turn(right);
wait(2, seconds);
myDrivetrain.turn(left);
wait(2, seconds);
myDrivetrain.stop();

turnoPara#

turnFor turns the robot left or right for a specific number of degrees, revolutions, or raw units. The turn is relative to the current position of the robot. The project will wait until the robot is done turning before the next line of code runs.

Available Functions

1 - Giros para el ángulo especificado utilizando la velocidad de giro actual.

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

2 - Gira en la dirección especificada para un ángulo utilizando la velocidad de giro actual.

bool turnFor(
    turnType      dir,
    double        angle,
    rotationUnits units,
    bool          waitForCompletion = true );

3 - Giros para el ángulo especificado a la velocidad especificada.

bool turnFor(
    double        angle,
    rotationUnits units,
    double        velocity,
    velocityUnits units_v,
    bool          waitForCompletion = true );

4 - Gira en la dirección especificada para un ángulo a la velocidad especificada.

bool turnFor(
    turnType      dir,
    double        angle,
    rotationUnits units,
    double        velocity,
    velocityUnits units_v,
    bool          waitForCompletion = true );

Parameters

Parámetro

Tipo

Descripción

dir

turnType

The direction the robot turns: left or right.

angle

double

La cantidad de vueltas que da el robot.

units

rotationUnits

The turn unit: deg (degrees), rev (revolutions), or raw (raw units). One revolution is equal to 360 degrees.

velocity

double

The velocity to turn with from 0% to 100% when using velocityUnits::pct, from 0 to 120 rpm when using rpm, or from 0 to 720 degrees per second when using dps. If no velocity is provided, the robot turns at the current turn velocity.

units_v

velocityUnits

The velocity unit: velocityUnits::pct (percent), rpm (rotations per minute), or dps (degrees per second).

waitForCompletion

bool

true (default) makes the project wait until the robot is done turning before the next line of code runs. false makes the next line of code run right away.

Return Values

Devuelve, como valor booleano, si el robot alcanzó el ángulo objetivo.

  • true - The robot reached the target angle.

  • false - The robot did not finish the turn, or the function returned before the turn completed because waitForCompletion was set to false.

Notes
  • Running another drivetrain movement function while turnFor is running will interrupt the current movement.

  • turnFor uses a target angle, so isDone and isMoving can be used with it.

Examples
// Turn right, then left.
myDrivetrain.turnFor(right, 90, degrees);
wait(1, seconds);
myDrivetrain.turnFor(left, 90, degrees);

detener#

stop stops the robot’s movement. If a stopping mode is provided, it controls how the robot stops for this function call.

Available Functions

1 - Detiene el sistema de transmisión utilizando el modo de parada actual.

void stop();

2 - Detiene el sistema de transmisión utilizando el modo de parada especificado.

void stop(
    brakeType mode );

Parameters

Parámetro

Tipo

Descripción

mode

brakeType

How the robot will stop:

  • brake - Stops immediately.
  • coast - Slows to a stop.
  • hold - Stops immediately and holds the wheels’ position.

Return Values

Esta función no devuelve ningún valor.

Examples
// Drive forward, then coast to a stop.
myDrivetrain.setDriveVelocity(100, percent);
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.stop(coast);

Mutadores#

establecerVelocidadDeConducción#

setDriveVelocity tells the robot how fast to drive. A higher percentage makes the robot drive faster and a lower percentage makes the robot drive slower.

Todos los proyectos comienzan con el robot conduciendo al 50% de su velocidad por defecto.

Nota: Una mayor velocidad hace que el robot se desplace más rápido, pero puede ser menos preciso. Una menor velocidad hace que el robot se desplace más despacio, pero puede ser más preciso.

Available Functions
void setDriveVelocity(
  double velocity,
  velocityUnits units );

Parameters

Parámetro

Tipo

Descripción

velocity

double

The velocity to drive with from 0% to 100% when using velocityUnits::pct, from 0 to 120 rpm when using rpm, or from 0 to 720 degrees per second when using dps.

units

velocityUnits

The velocity unit: velocityUnits::pct (percent), rpm (rotations per minute), or dps (degrees per second).

Return Values

Esta función no devuelve ningún valor.

Notes
  • La velocidad de accionamiento se utiliza en las funciones de movimiento de la transmisión posteriores, a menos que se proporcione una velocidad específica en la llamada a la función.

Examples
// Drive forward, then coast to a stop.
myDrivetrain.setDriveVelocity(100, percent);
myDrivetrain.drive(forward);
wait(2, seconds);
myDrivetrain.stop(coast);

establecerVelocidadDeGiro#

setTurnVelocity tells the robot how fast to turn. A higher percentage makes the robot turn faster and a lower percentage makes the robot turn slower.

Todos los proyectos comienzan con el robot girando al 50% de su velocidad por defecto.

Nota: Una mayor velocidad hace que el robot gire más rápido, pero puede ser menos preciso. Una menor velocidad hace que el robot gire más despacio, pero puede ser más preciso.

Available Functions
void setTurnVelocity(
  double velocity,
  velocityUnits units );

Parameters

Parámetro

Tipo

Descripción

velocity

double

The velocity to turn with from 0% to 100% when using velocityUnits::pct, from 0 to 120 rpm when using rpm, or from 0 to 720 degrees per second when using dps.

units

velocityUnits

The velocity unit: velocityUnits::pct (percent), rpm (rotations per minute), or dps (degrees per second).

Return Values

Esta función no devuelve ningún valor.

Notes
  • La velocidad de giro se utiliza en las funciones de giro de la transmisión posteriores, a menos que se proporcione una velocidad específica en la llamada a la función.

Examples
// Try default, slow, then fast.
myDrivetrain.turnFor(right, 360, degrees);
wait(1, seconds);
myDrivetrain.setTurnVelocity(20, percent);
myDrivetrain.turnFor(right, 360, degrees);
wait(1, seconds);
myDrivetrain.setTurnVelocity(100, percent);
myDrivetrain.turnFor(right, 360, degrees);

establecerDetención#

setStopping sets how the robot will stop moving: by braking, coasting, or holding.

Available Functions
void setStopping(
  brakeType mode );

Parameters

Parámetro

Tipo

Descripción

mode

brakeType

How the robot will stop:

  • brake - Stops immediately.
  • coast - Slows to a stop.
  • hold - Stops immediately and holds the wheels’ position.

Return Values

Esta función no devuelve ningún valor.

Notes
  • The stopping mode is used by later stop calls unless a specific stopping mode is provided in the function call.

  • If this function is not used, the robot will use brake when stopping.

establecerTiempoDeEspera#

setTimeout sets how long the robot will try to finish a movement. If the robot cannot finish in that time, it will stop trying and move on to the next line of code. This keeps the robot from getting stuck on a movement.

Available Functions
void setTimeout(
  int32_t time,
  timeUnits units );

Parameters

Parámetro

Tipo

Descripción

time

int32_t

El tiempo que el robot puede intentar para completar un movimiento. Debe ser un número entero positivo.

units

timeUnits

The unit of time: sec (seconds) or msec (milliseconds).

Return Values

Esta función no devuelve ningún valor.

Notes
  • The timeout only applies to drivetrain functions that move to a target, such as driveFor and turnFor.

Examples
// Turn right after driving forward.
myDrivetrain.setTimeout(1, seconds);
myDrivetrain.driveFor(forward, 25, inches);
myDrivetrain.turnFor(right, 90, degrees);

Getters#

estáHecho#

isDone returns whether the robot is finished moving, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

Available Functions
bool isDone( void );

Parameters

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

Return Values
  • true - The robot is finished moving.

  • false - The robot is still moving.

Notes
  • isDone works with target-based drivetrain movement functions, such as driveFor and turnFor.

  • isDone is not used with drive or turn, since those functions do not move to a target.

se está mudando#

isMoving returns whether the robot is moving, as a Boolean value. This can be used to control the timing of other behaviors based on the robot’s movement.

Available Functions
virtual bool isMoving( void );

Parameters

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

Return Values
  • true - The robot is moving.

  • false - The robot is not moving.

Notes
  • isMoving works with target-based drivetrain movement functions, such as driveFor and turnFor.

  • isMoving is not used with drive or turn, since those functions do not move to a target.

velocidad#

velocity returns how fast the robot is driving.

It can return velocity as a percentage, in rpm, or in dps. A positive value means the robot is driving forward. A negative value means the robot is driving in reverse.

Available Functions
double velocity(
  velocityUnits units );

Parameters

Parámetro

Tipo

Descripción

units

velocityUnits

The unit to return velocity in: percent, pct, rpm, or dps.

Return Values

Returns the drivetrain velocity as a double in the selected unit.

Examples
// Show velocity before and during motion.
Brain.Screen.print("Resting: %f", myDrivetrain.velocity(percent));
myDrivetrain.drive(forward, 100, velocityUnits::pct);
wait(1, seconds);
Brain.Screen.newLine();
Brain.Screen.print("Moving: %f", myDrivetrain.velocity(percent));
myDrivetrain.stop();

actual#

current returns how much electrical current the drivetrain is using. Current is the amount of electricity flowing through the drivetrain. It can be returned in amps (amperes) or as a percentage, depending on the unit.

Un valor de corriente más alto significa que el sistema de transmisión está utilizando más corriente eléctrica. Esto puede ocurrir cuando el robot empuja contra un objeto o intenta moverse cuando está atascado.

Esto puede utilizarse para comprobar si el sistema de transmisión tiene dificultades durante el movimiento. Si la corriente se mantiene alta, el sistema de transmisión puede sobrecalentarse o consumir energía de forma menos eficiente.

Available Functions

1 - Devuelve la corriente eléctrica del tren motriz en amperios.

double current(
    currentUnits units = currentUnits::amp );

2 - Devuelve la corriente eléctrica del tren motriz como un porcentaje.

double current(
    percentUnits units );

Parameters

Parámetro

Tipo

Descripción

units

currentUnits

The unit to return current in: amp.

units

percentUnits

The unit to return current in: percent or pct.

Return Values

Returns the drivetrain current as a double in the selected unit.

fuerza#

power returns how much power the drivetrain is using, measured in watts. Power shows how quickly the drivetrain is using energy.

Un valor de potencia más alto significa que el sistema de transmisión consume energía más rápidamente. Esto puede ocurrir cuando el robot empuja contra un objeto o intenta moverse cuando está atascado.

Esto puede utilizarse para comparar movimientos o comprobar si la transmisión está teniendo dificultades. Si la potencia se mantiene alta, la transmisión puede calentarse o consumir energía de forma menos eficiente.

Available Functions
double power(
  powerUnits units = powerUnits::watt );

Parameters

Parámetro

Tipo

Descripción

units

powerUnits

The power unit: watt.

Return Values

Returns drivetrain power as a double in watts.

esfuerzo de torsión#

El par motor indica la fuerza con la que el sistema de transmisión puede empujar o tirar mientras las ruedas giran.

torque returns how much torque the drivetrain is using, measured in Newton-meters (Nm) or inch-pounds (InLb).

Un valor de par motor más elevado indica que el sistema de transmisión está ejerciendo mayor fuerza de empuje o tracción. Esto puede ocurrir cuando el robot empuja contra un objeto o intenta moverse estando atascado.

Esto puede utilizarse para comprobar si el sistema de transmisión está teniendo dificultades o para comparar la fuerza que requieren los diferentes movimientos.

Available Functions
double torque(
  torqueUnits units = torqueUnits::nm );

Parameters

Parámetro

Tipo

Descripción

units

torqueUnits

The unit to return torque in: Nm (newton meters, default) or InLb (inch pounds).

Return Values

Returns drivetrain torque as a double in the selected unit.

eficiencia#

efficiency returns how efficiently the drivetrain is using power, as a percentage from 0% to 100%.

La eficiencia indica cuánta potencia del sistema de transmisión se utiliza para el movimiento. Un valor de eficiencia más alto significa que se utiliza más potencia del sistema de transmisión para el movimiento. Un valor de eficiencia más bajo puede ocurrir cuando el sistema de transmisión trabaja intensamente pero no genera mucho movimiento, como cuando el robot está atascado o empujando contra un objeto.

Esto puede utilizarse para comparar movimientos o comprobar si el sistema de transmisión está desperdiciando energía en lugar de utilizarla para el movimiento.

Available Functions
double efficiency(
  percentUnits units = percentUnits::pct );

Parameters

Parámetro

Tipo

Descripción

units

percentUnits

The unit to return efficiency in: percent or pct.

Return Values

Returns drivetrain efficiency as a double in the selected unit.

temperatura#

temperature returns the average temperature of the drivetrain as a percentage from 0% to 100%.

La temperatura indica el grado de calentamiento de los motores del sistema de transmisión. Una temperatura más alta significa que los motores se calientan durante su funcionamiento. Para que los motores funcionen a pleno rendimiento, deben mantenerse por debajo de los 55 °C.

Si los motores se sobrecalientan, reducirán su corriente máxima para protegerse. A 70 °C, los motores dejarán de funcionar hasta que se enfríen.

Esto puede utilizarse para comprobar si el sistema de transmisión se calienta demasiado durante movimientos repetidos, recorridos largos o cuando ejerce presión contra un objeto.

Available Functions
double temperature(
  percentUnits units );

Parameters

Parámetro

Tipo

Descripción

units

percentUnits

The unit to return temperature in: percent or pct.

Return Values

Returns the average drivetrain temperature as a double in the selected unit.

Notes
  • A returned value of 50% means the average motor temperature is about 45°C (113°F).

  • The typical operating temperature range for the drivetrain is about 20°C (68°F) to 70°C (158°F).

Voltaje#

voltage returns the electrical voltage of the drivetrain.

El voltaje es la presión eléctrica que se suministra a los motores del sistema de transmisión. Este valor, junto con la corriente y la potencia, permite comprender cómo el sistema de transmisión utiliza la energía eléctrica.

Available Functions
double voltage(
  voltageUnits units = voltageUnits::volt );

Parameters

Parámetro

Tipo

Descripción

units

voltageUnits

The unit to return voltage in: volt (default) or voltageUnits::mV. voltageUnits::mV means millivolts.

Return Values

Returns drivetrain voltage as a double in the selected unit.