VEX V5 C++ API
Public Member Functions | Protected Attributes | List of all members
vex::drivetrain Class Reference

Inherited by vex::smartdrive.

Public Member Functions

 drivetrain (motor_group &leftMotors, motor_group &rightMotors, double wheelTravel=319.1764, double trackWidth=292.1, double wheelBase=130, distanceUnits unit=distanceUnits::mm, double externalGearRatio=1.0)
 Creates a new drivetrain object. More...
 
 drivetrain (vex::motor &leftMotor, vex::motor &rightMotor, double wheelTravel=319.1764, double trackWidth=292.1, double wheelBase=130, distanceUnits unit=distanceUnits::mm, double externalGearRatio=1.0)
 
 ~drivetrain ()
 
void setGearRatio (double ratio)
 Sets the external gear ratio of the drivetrain. More...
 
void setDriveVelocity (double velocity, velocityUnits units)
 Sets the velocity of the drive based on the parameters set in the command. This command will not run the motors. Any subsequent call that does not contain a specified motor velocity will use this value. More...
 
void setDriveVelocity (double velocity, percentUnits units)
 
void setTurnVelocity (double velocity, velocityUnits units)
 Sets the turn velocity of the drive based on the parameters set in the command. This command will not run the motor. More...
 
void setTurnVelocity (double velocity, percentUnits units)
 
void setTimeout (double time, timeUnits units)
 Sets the timeout for the drivetrain. If the drivetrain does not reach its' commanded position prior to the completion of the timeout, the motors will stop. More...
 
double timeout (timeUnits units)
 
bool didTimeout ()
 
void setStopping (brakeType mode)
 Sets the stopping mode of the motor group by passing a brake mode as a parameter. More...
 
void drive (directionType dir)
 Turns the motors on, and drive in the specified direction. More...
 
void drive (directionType dir, double velocity, velocityUnits units)
 Turn on the motors and drive in the specified direction and a specified velocity. More...
 
bool driveFor (double distance, distanceUnits units, bool waitForCompletion=true)
 Turn on the motors and drive a distance at the default velocity. More...
 
bool driveFor (directionType dir, double distance, distanceUnits units, bool waitForCompletion=true)
 Turn on the motors and drive a distance at a specified velocity. More...
 
bool driveFor (double distance, distanceUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turn on the motors and drive a distance at a specified velocity. More...
 
bool driveFor (directionType dir, double distance, distanceUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turn on the motors and drive a distance at a specified velocity. More...
 
void startDriveFor (double distance, distanceUnits distUnit)
 Start driving a distance at a pre-set velocity. More...
 
void startDriveFor (directionType dir, double distance, distanceUnits distUnit)
 Start driving a distance at a pre-set velocity. More...
 
void startDriveFor (double distance, distanceUnits distUnit, double velocity, velocityUnits velUnit)
 Start driving a distance at a specified velocity. More...
 
void startDriveFor (directionType dir, double distance, distanceUnits distUnit, float velocity, velocityUnits velUnit)
 Start driving a distance at a specified velocity. More...
 
void turn (turnType dir)
 Turns the motors on, and rotate in the specified direction. More...
 
void turn (turnType dir, double velocity, velocityUnits units)
 Turns the motors on, and rotate in the specified direction and a specified velocity. More...
 
virtual bool turnFor (double angle, rotationUnits units, bool waitForCompletion=true)
 Turn on the motors and rotate an angle at the default velocity. More...
 
virtual bool turnFor (turnType dir, double angle, rotationUnits units, bool waitForCompletion=true)
 Turn on the motors and rotate an angle at the default velocity. More...
 
virtual bool turnFor (double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turn on the motors and rotate an angle at a specified velocity. More...
 
virtual bool turnFor (turnType dir, double angle, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turn on the motors and rotate an angle at a specified velocity. More...
 
virtual void startTurnFor (double angle, rotationUnits angleUnit)
 Start turning the drivetrain for a given angle. More...
 
virtual void startTurnFor (turnType dir, double angle, rotationUnits angleUnit)
 Start turning the drivetrain for a given angle. More...
 
virtual void startTurnFor (double angle, rotationUnits angleUnit, double velocity, velocityUnits velUnit)
 Start turning the drivetrain for a given angle at a given velocity. More...
 
virtual void startTurnFor (turnType dir, double angle, rotationUnits angleUnit, float velocity, velocityUnits velUnit)
 Start turning the drivetrain for a given angle at a given velocity. More...
 
void arcade (double drivePower, double turnPower, percentUnits units=percentUnits::pct)
 Drive in arcade mode, normally corresponding to two controller joystick axis values. More...
 
virtual bool isMoving (void)
 Checks to see if any of the motors are rotating to a specific target. More...
 
bool isDone (void)
 Checks to see if all the motor are done rotating to a specific target. More...
 
void stop ()
 Stops the drive using the default brake mode. More...
 
void stop (brakeType mode)
 Stops the drive using a specified brake mode. More...
 
double velocity (velocityUnits units)
 Gets the average velocity of the drivetrain;. More...
 
double velocity (percentUnits units)
 
double current (currentUnits units=currentUnits::amp)
 Gets the total current of the drivetrain;. More...
 
double power (powerUnits units=powerUnits::watt)
 Gets the average power of the drivetrain;. More...
 
double torque (torqueUnits units=torqueUnits::Nm)
 Gets the average torque of the drivetrain;. More...
 
double efficiency (percentUnits units=percentUnits::pct)
 Gets the average efficiency of the drivetrain;. More...
 
double temperature (percentUnits units)
 Gets the average temperature of the drivetrain;. More...
 

Protected Attributes

double _turnVelocity
 
velocityUnits _turnVelUnit
 

Constructor & Destructor Documentation

◆ drivetrain() [1/2]

vex::drivetrain::drivetrain ( motor_group leftMotors,
motor_group rightMotors,
double  wheelTravel = 319.1764,
double  trackWidth = 292.1,
double  wheelBase = 130,
distanceUnits  unit = distanceUnits::mm,
double  externalGearRatio = 1.0 
)

Creates a new drivetrain object.

Parameters
leftMotorsmotor group driving the left side of the drivetrain
rightMotorsmotor group driving the right side of the drivetrain
wheelTravelcircumference of the wheel type used
trackWidthdistance between the wheels on opposite sides
wheelBase
unitdistance unit for wheelTravel and trackWith
externalGearRatioexternal gear ratio, usually 1.0

◆ drivetrain() [2/2]

vex::drivetrain::drivetrain ( vex::motor leftMotor,
vex::motor rightMotor,
double  wheelTravel = 319.1764,
double  trackWidth = 292.1,
double  wheelBase = 130,
distanceUnits  unit = distanceUnits::mm,
double  externalGearRatio = 1.0 
)

◆ ~drivetrain()

vex::drivetrain::~drivetrain ( )

Member Function Documentation

◆ setGearRatio()

void vex::drivetrain::setGearRatio ( double  ratio)

Sets the external gear ratio of the drivetrain.

Parameters
ratiogear ratio value, usually 1.0

◆ setDriveVelocity() [1/2]

void vex::drivetrain::setDriveVelocity ( double  velocity,
velocityUnits  units 
)

Sets the velocity of the drive based on the parameters set in the command. This command will not run the motors. Any subsequent call that does not contain a specified motor velocity will use this value.

Parameters
velocitySets the amount of velocity.
unitsThe measurement unit for the velocity value.

◆ setDriveVelocity() [2/2]

void vex::drivetrain::setDriveVelocity ( double  velocity,
percentUnits  units 
)

◆ setTurnVelocity() [1/2]

void vex::drivetrain::setTurnVelocity ( double  velocity,
velocityUnits  units 
)

Sets the turn velocity of the drive based on the parameters set in the command. This command will not run the motor.

Parameters
velocitySets the amount of velocity.
unitsThe measurement unit for the velocity value.

◆ setTurnVelocity() [2/2]

void vex::drivetrain::setTurnVelocity ( double  velocity,
percentUnits  units 
)

◆ setTimeout()

void vex::drivetrain::setTimeout ( double  time,
timeUnits  units 
)

Sets the timeout for the drivetrain. If the drivetrain does not reach its' commanded position prior to the completion of the timeout, the motors will stop.

Parameters
timeSets the amount of time.
unitsThe measurement unit for the time value.

◆ timeout()

double vex::drivetrain::timeout ( timeUnits  units)
Returns
a timeout in given time units

◆ didTimeout()

bool vex::drivetrain::didTimeout ( )
Returns
True if the last drivetrain operation timed out

◆ setStopping()

void vex::drivetrain::setStopping ( brakeType  mode)

Sets the stopping mode of the motor group by passing a brake mode as a parameter.

Parameters
modeThe stopping mode can be set to coast, brake, or hold.

◆ drive() [1/2]

void vex::drivetrain::drive ( directionType  dir)

Turns the motors on, and drive in the specified direction.

Parameters
dirThe direction to drive.

◆ drive() [2/2]

void vex::drivetrain::drive ( directionType  dir,
double  velocity,
velocityUnits  units 
)

Turn on the motors and drive in the specified direction and a specified velocity.

Parameters
dirThe direction to drive.
velocitySets the amount of velocity.
unitsThe measurement unit for the velocity value.

◆ driveFor() [1/4]

bool vex::drivetrain::driveFor ( double  distance,
distanceUnits  units,
bool  waitForCompletion = true 
)

Turn on the motors and drive a distance at the default velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
distanceSets the distance to drive.
unitsThe measurement unit for the distance value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

◆ driveFor() [2/4]

bool vex::drivetrain::driveFor ( directionType  dir,
double  distance,
distanceUnits  units,
bool  waitForCompletion = true 
)

Turn on the motors and drive a distance at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
dirThe direction to drive in.
distanceSets the distance to drive.
unitsThe measurement unit for the distance value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

◆ driveFor() [3/4]

bool vex::drivetrain::driveFor ( double  distance,
distanceUnits  units,
double  velocity,
velocityUnits  units_v,
bool  waitForCompletion = true 
)

Turn on the motors and drive a distance at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
distanceSets the distance to drive.
unitsThe measurement unit for the distance value.
velocitySets the amount of velocity.
units_vThe measurement unit for the velocity value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

◆ driveFor() [4/4]

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

Turn on the motors and drive a distance at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
dirThe direction to drive in.
distanceSets the distance to drive.
unitsThe measurement unit for the distance value.
velocitySets the amount of velocity.
units_vThe measurement unit for the velocity value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

◆ startDriveFor() [1/4]

void vex::drivetrain::startDriveFor ( double  distance,
distanceUnits  distUnit 
)

Start driving a distance at a pre-set velocity.

Parameters
distanceSets the distance to drive.
distUnitThe measurement unit for the distance value.

◆ startDriveFor() [2/4]

void vex::drivetrain::startDriveFor ( directionType  dir,
double  distance,
distanceUnits  distUnit 
)

Start driving a distance at a pre-set velocity.

Parameters
dirThe direction to drive in.
distanceSets the distance to drive.
distUnitThe measurement unit for the distance value.

◆ startDriveFor() [3/4]

void vex::drivetrain::startDriveFor ( double  distance,
distanceUnits  distUnit,
double  velocity,
velocityUnits  velUnit 
)

Start driving a distance at a specified velocity.

Parameters
distanceSets the distance to drive.
distUnitThe measurement unit for the distance value.
velocitySets the amount of velocity.
velUnitThe measurement unit for the velocity value.

◆ startDriveFor() [4/4]

void vex::drivetrain::startDriveFor ( directionType  dir,
double  distance,
distanceUnits  distUnit,
float  velocity,
velocityUnits  velUnit 
)

Start driving a distance at a specified velocity.

Parameters
dirThe direction to drive in.
distanceSets the distance to drive.
distUnitThe measurement unit for the distance value.
velocitySets the amount of velocity.
velUnitThe measurement unit for the velocity value.

◆ turn() [1/2]

void vex::drivetrain::turn ( turnType  dir)

Turns the motors on, and rotate in the specified direction.

Parameters
dirThe direction to rotate the robot.

◆ turn() [2/2]

void vex::drivetrain::turn ( turnType  dir,
double  velocity,
velocityUnits  units 
)

Turns the motors on, and rotate in the specified direction and a specified velocity.

Parameters
dirThe direction to rotate the robot.
velocitySets the amount of velocity.
unitsThe measurement unit for the velocity value.

◆ turnFor() [1/4]

virtual bool vex::drivetrain::turnFor ( double  angle,
rotationUnits  units,
bool  waitForCompletion = true 
)
virtual

Turn on the motors and rotate an angle at the default velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
angleSets the angle to turn.
unitsThe measurement unit for the angle value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

Reimplemented in vex::smartdrive.

◆ turnFor() [2/4]

virtual bool vex::drivetrain::turnFor ( turnType  dir,
double  angle,
rotationUnits  units,
bool  waitForCompletion = true 
)
virtual

Turn on the motors and rotate an angle at the default velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
dirDirection to turn in, left or right.
angleSets the angle to turn.
unitsThe measurement unit for the angle value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

Reimplemented in vex::smartdrive.

◆ turnFor() [3/4]

virtual bool vex::drivetrain::turnFor ( double  angle,
rotationUnits  units,
double  velocity,
velocityUnits  units_v,
bool  waitForCompletion = true 
)
virtual

Turn on the motors and rotate an angle at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
angleSets the angle to turn.
unitsThe measurement unit for the angle value.
velocitySets the amount of velocity.
units_vThe measurement unit for the velocity value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

Reimplemented in vex::smartdrive.

◆ turnFor() [4/4]

virtual bool vex::drivetrain::turnFor ( turnType  dir,
double  angle,
rotationUnits  units,
double  velocity,
velocityUnits  units_v,
bool  waitForCompletion = true 
)
virtual

Turn on the motors and rotate an angle at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
dirDirection to turn in, left or right.
angleSets the angle to turn.
unitsThe measurement unit for the angle value.
velocitySets the amount of velocity.
units_vThe measurement unit for the velocity value.
waitForCompletion(Optional) If true, your program will wait until the motor reaches the target rotational value. If false, the program will continue after calling this function. By default, this parameter is true.

Reimplemented in vex::smartdrive.

◆ startTurnFor() [1/4]

virtual void vex::drivetrain::startTurnFor ( double  angle,
rotationUnits  angleUnit 
)
virtual

Start turning the drivetrain for a given angle.

Parameters
angleSets the angle to turn.
angleUnitThe measurement unit for the angle value.

Reimplemented in vex::smartdrive.

◆ startTurnFor() [2/4]

virtual void vex::drivetrain::startTurnFor ( turnType  dir,
double  angle,
rotationUnits  angleUnit 
)
virtual

Start turning the drivetrain for a given angle.

Parameters
dirDirection to turn in, left or right.
angleSets the angle to turn.
angleUnitThe measurement unit for the angle value.

Reimplemented in vex::smartdrive.

◆ startTurnFor() [3/4]

virtual void vex::drivetrain::startTurnFor ( double  angle,
rotationUnits  angleUnit,
double  velocity,
velocityUnits  velUnit 
)
virtual

Start turning the drivetrain for a given angle at a given velocity.

Parameters
angleSets the angle to turn.
angleUnitThe measurement unit for the angle value.
velocitySets the amount of velocity.
velUnitThe measurement unit for the velocity value.

Reimplemented in vex::smartdrive.

◆ startTurnFor() [4/4]

virtual void vex::drivetrain::startTurnFor ( turnType  dir,
double  angle,
rotationUnits  angleUnit,
float  velocity,
velocityUnits  velUnit 
)
virtual

Start turning the drivetrain for a given angle at a given velocity.

Parameters
dirDirection to turn in, left or right.
angleSets the angle to turn.
angleUnitThe measurement unit for the angle value.
velocitySets the amount of velocity.
velUnitThe measurement unit for the velocity value.

Reimplemented in vex::smartdrive.

◆ arcade()

void vex::drivetrain::arcade ( double  drivePower,
double  turnPower,
percentUnits  units = percentUnits::pct 
)

Drive in arcade mode, normally corresponding to two controller joystick axis values.

Parameters
drivePowerpercent power to apply to driving, -100..100
turnPowerpercent power to apply to turning, -100..100
unitspercent

◆ isMoving()

virtual bool vex::drivetrain::isMoving ( void  )
virtual

Checks to see if any of the motors are rotating to a specific target.

Returns
Returns a true Boolean if the motor is on and is rotating to a target. Returns a false Boolean if the motor is done rotating to a target.

Reimplemented in vex::smartdrive.

◆ isDone()

bool vex::drivetrain::isDone ( void  )

Checks to see if all the motor are done rotating to a specific target.

Returns
Returns a false Boolean if the motor is on and is rotating to a target. Returns a true Boolean if the motor is done rotating to a target.

◆ stop() [1/2]

void vex::drivetrain::stop ( )

Stops the drive using the default brake mode.

◆ stop() [2/2]

void vex::drivetrain::stop ( brakeType  mode)

Stops the drive using a specified brake mode.

Parameters
modeThe brake mode can be set to coast, brake, or hold.

◆ velocity() [1/2]

double vex::drivetrain::velocity ( velocityUnits  units)

Gets the average velocity of the drivetrain;.

Returns
Returns a double that represents the current velocity of the motor in the units defined in the parameter.
Parameters
unitsThe measurement unit for the velocity.

◆ velocity() [2/2]

double vex::drivetrain::velocity ( percentUnits  units)
inline

◆ current()

double vex::drivetrain::current ( currentUnits  units = currentUnits::amp)

Gets the total current of the drivetrain;.

Returns
Returns a double that represents the electrical current of the motor in the units defined in the parameter.
Parameters
unitsThe measurement unit for the current.

◆ power()

double vex::drivetrain::power ( powerUnits  units = powerUnits::watt)

Gets the average power of the drivetrain;.

Returns
Returns a double that represents the power of the motor in the units defined in the parameter.
Parameters
unitsThe measurement unit for the power.

◆ torque()

double vex::drivetrain::torque ( torqueUnits  units = torqueUnits::Nm)

Gets the average torque of the drivetrain;.

Returns
Returns a double that represents the torque of the motor in the units defined in the parameter.
Parameters
unitsThe measurement unit for the torque.

◆ efficiency()

double vex::drivetrain::efficiency ( percentUnits  units = percentUnits::pct)

Gets the average efficiency of the drivetrain;.

Returns
Returns the efficiency of the motor in the units defined in the parameter.
Parameters
units(Optional) The measurement unit for the efficiency. By default, this parameter is a percentage.

◆ temperature()

double vex::drivetrain::temperature ( percentUnits  units)

Gets the average temperature of the drivetrain;.

Returns
Returns the temperature of the motor in the units defined in the parameter.
Parameters
unitsThe measurement unit for the temperature.

Member Data Documentation

◆ _turnVelocity

double vex::drivetrain::_turnVelocity
protected

◆ _turnVelUnit

velocityUnits vex::drivetrain::_turnVelUnit
protected