VEXcode IQ C++ Unofficial documentation for version 3.0.4.1
Loading...
Searching...
No Matches
vex::motor Class Reference

Use the motor class to control motor devices. More...

#include <vex_motor.h>

Inheritance diagram for vex::motor:
vex::device

Public Member Functions

 motor (int32_t index)
 Creates a new motor object on the port specified.
 
bool installed ()
 
int32_t value ()
 
 motor (int32_t index, bool reverse)
 Creates a new motor object on the port specified and sets the reversed flag.
 
 motor (int32_t index, double gearRatio)
 Creates a new motor object on the port specified and sets the output gear ratio.
 
 motor (int32_t index, double gearRatio, bool reverse)
 Creates a new motor object on the port specified and sets the output gear ratio and reverse flag.
 
void setReversed (bool value)
 Sets the motor mode to "reverse", which will make motor commands spin the motor in the opposite direction.
 
void setVelocity (double velocity, velocityUnits units)
 Sets the velocity of the motor based on the parameters set in the command. This command will not run the motor. Any subsequent call that does not contain a specified motor velocity will use this value.
 
void setVelocity (double velocity, percentUnits units)
 Sets the velocity of the motor based on the parameters set in the command. This command will not run the motor. Any subsequent call that does not contain a specified motor velocity will use this value.
 
void setBrake (brakeType mode)
 
void setStopping (brakeType mode)
 Sets the stopping mode of the motor by passing a brake mode as a parameter.
 
void resetPosition (void)
 Resets the motor's encoder to the value of zero.
 
void setPosition (double value, rotationUnits units)
 Sets the value of the motor's encoder to the value specified in the parameter.
 
void setTimeout (int32_t time, timeUnits units)
 Sets the timeout for the motor. If the motor does not reach its' commanded position prior to the completion of the timeout, the motor will stop.
 
void spin (directionType dir)
 Turns the motor on, and spins it in the specified direction.
 
void spin (directionType dir, double velocity, velocityUnits units)
 Turns on the motor and spins it in a specified direction and a specified velocity.
 
void spin (directionType dir, double velocity, percentUnits units)
 
void spin (directionType dir, double voltage, voltageUnits units)
 Turns on the motor and spins it in a specified direction and a specified voltage.
 
bool spinTo (double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turns on the motor and spins it to an absolute target rotation value at a specified velocity.
 
bool spinToPosition (double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 
bool spinTo (double rotation, rotationUnits units, bool waitForCompletion=true)
 Turns on the motor and spins it to an absolute target rotation value.
 
bool spinToPosition (double rotation, rotationUnits units, bool waitForCompletion=true)
 
bool spinFor (double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turns on the motor and spins it to a relative target rotation value at a specified velocity.
 
bool spinFor (directionType dir, double rotation, rotationUnits units, double velocity, velocityUnits units_v, bool waitForCompletion=true)
 
bool spinFor (double rotation, rotationUnits units, bool waitForCompletion=true)
 Turns on the motor and spins it to a relative target rotation value.
 
bool spinFor (directionType dir, double rotation, rotationUnits units, bool waitForCompletion=true)
 
bool spinFor (double time, timeUnits units, double velocity, velocityUnits units_v)
 Turns on the motor and spins it to a relative target time value at a specified velocity.
 
bool spinFor (directionType dir, double time, timeUnits units, double velocity, velocityUnits units_v)
 
bool spinFor (double time, timeUnits units)
 Turns on the motor and spins it to a relative target time value.
 
bool spinFor (directionType dir, double time, timeUnits units)
 
bool isSpinning (void)
 Checks to see if the motor is rotating to a specific target.
 
bool isDone (void)
 Checks to see if the motor is done rotating to a specific target.
 
bool isSpinningMode (void)
 
void stop (void)
 Stops the motor using the default brake mode.
 
void stop (brakeType mode)
 Stops the motor using a specified brake mode.
 
void setMaxTorque (double value, percentUnits units)
 Sets the max torque of the motor.
 
void setMaxTorque (double value, torqueUnits units)
 Sets the max torque of the motor.
 
void setMaxTorque (double value, currentUnits units)
 Sets the max torque of the motor.
 
directionType direction (void)
 Gets which direction the motor is spinning.
 
double position (rotationUnits units)
 Gets the current position of the motor's encoder.
 
double velocity (velocityUnits units)
 Gets the current velocity of the motor.
 
double velocity (percentUnits units)
 
double current (currentUnits units=currentUnits::amp)
 Gets the electrical current of the motor.
 
double current (percentUnits units)
 Gets the electrical current of the motor in percentage of maximum.
 
double voltage (voltageUnits units=voltageUnits::volt)
 Gets the electrical voltage of the motor.
 
double power (powerUnits units=powerUnits::watt)
 Gets the power of the motor.
 
double torque (torqueUnits units=torqueUnits::Nm)
 Gets the torque of the motor.
 
double efficiency (percentUnits units=percentUnits::pct)
 Gets the efficiency of the motor.
 
double temperature (percentUnits units=percentUnits::pct)
 Gets the temperature of the motor.
 
double temperature (temperatureUnits units)
 Gets the temperature of the motor.
 
- Public Member Functions inherited from vex::device
 device (int32_t index)
 
IQ_DeviceType type ()
 
int32_t index ()
 
void init (int32_t index)
 
int32_t readDigitalPin ()
 
int32_t readAnalogPin ()
 

Protected Member Functions

int32_t getTimeout ()
 
double getVelocity (velocityUnits units)
 
- Protected Member Functions inherited from vex::device
void setPollInterval (int32_t value)
 
bool pollValid (bool bSave)
 

Additional Inherited Members

- Protected Attributes inherited from vex::device
int16_t _index
 

Detailed Description

Use the motor class to control motor devices.

Definition at line 34 of file vex_motor.h.

Constructor & Destructor Documentation

◆ motor() [1/4]

vex::motor::motor ( int32_t index)

Creates a new motor object on the port specified.

Parameters
indexThe port index for this motor. The index is zero-based.

◆ motor() [2/4]

vex::motor::motor ( int32_t index,
bool reverse )

Creates a new motor object on the port specified and sets the reversed flag.

Parameters
indexThe port index for this motor. The index is zero-based.
reverseSets the reverse flag for the new motor object.

◆ motor() [3/4]

vex::motor::motor ( int32_t index,
double gearRatio )

Creates a new motor object on the port specified and sets the output gear ratio.

Parameters
indexThe port index for this motor. The index is zero-based.
gearRatiothe theoretical gear ration of the motor.

◆ motor() [4/4]

vex::motor::motor ( int32_t index,
double gearRatio,
bool reverse )

Creates a new motor object on the port specified and sets the output gear ratio and reverse flag.

Parameters
indexThe port index for this motor. The index is zero-based.
gearRatiothe theoretical gear ration of the motor.
reverseSets the reverse flag for the new motor object.

Member Function Documentation

◆ current() [1/2]

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

Gets the electrical current of the motor.

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.

◆ current() [2/2]

double vex::motor::current ( percentUnits units)

Gets the electrical current of the motor in percentage of maximum.

Returns
Returns a double that represents the electrical current of the motor as percentage of max current.
Parameters
unitsThe measurement unit for the current.

◆ direction()

directionType vex::motor::direction ( void )

Gets which direction the motor is spinning.

Returns
Returns the direction that the motor is spinning.

◆ efficiency()

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

Gets the efficiency of the motor.

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.

◆ installed()

bool vex::motor::installed ( )
virtual

Reimplemented from vex::device.

◆ isDone()

bool vex::motor::isDone ( void )

Checks to see if the motor is 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.

◆ isSpinning()

bool vex::motor::isSpinning ( void )

Checks to see if the motor is 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.

◆ position()

double vex::motor::position ( rotationUnits units)

Gets the current position of the motor's encoder.

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

◆ power()

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

Gets the power of the motor.

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.

◆ setMaxTorque() [1/3]

void vex::motor::setMaxTorque ( double value,
currentUnits units )

Sets the max torque of the motor.

Parameters
valueSets the amount of torque.
unitsThe measurement unit for the torque value.

◆ setMaxTorque() [2/3]

void vex::motor::setMaxTorque ( double value,
percentUnits units )

Sets the max torque of the motor.

Parameters
valueSets the amount of torque.
unitsThe measurement unit for the torque value.

◆ setMaxTorque() [3/3]

void vex::motor::setMaxTorque ( double value,
torqueUnits units )

Sets the max torque of the motor.

Parameters
valueSets the amount of torque.
unitsThe measurement unit for the torque value.

◆ setPosition()

void vex::motor::setPosition ( double value,
rotationUnits units )

Sets the value of the motor's encoder to the value specified in the parameter.

Parameters
valueSets the current position of the motor.
unitsThe measurement unit for the position value.

◆ setReversed()

void vex::motor::setReversed ( bool value)

Sets the motor mode to "reverse", which will make motor commands spin the motor in the opposite direction.

Parameters
valueIf set to true, motor commands spin the motor in the opposite direction.

◆ setStopping()

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

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

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

◆ setTimeout()

void vex::motor::setTimeout ( int32_t time,
timeUnits units )

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

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

◆ setVelocity() [1/2]

void vex::motor::setVelocity ( double velocity,
percentUnits units )
inline

Sets the velocity of the motor based on the parameters set in the command. This command will not run the motor. 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.

Definition at line 86 of file vex_motor.h.

◆ setVelocity() [2/2]

void vex::motor::setVelocity ( double velocity,
velocityUnits units )

Sets the velocity of the motor based on the parameters set in the command. This command will not run the motor. 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.

◆ spin() [1/4]

void vex::motor::spin ( directionType dir)

Turns the motor on, and spins it in the specified direction.

Parameters
dirThe direction to spin the motor.

◆ spin() [2/4]

void vex::motor::spin ( directionType dir,
double velocity,
percentUnits units )
inline

Definition at line 134 of file vex_motor.h.

◆ spin() [3/4]

void vex::motor::spin ( directionType dir,
double velocity,
velocityUnits units )

Turns on the motor and spins it in a specified direction and a specified velocity.

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

◆ spin() [4/4]

void vex::motor::spin ( directionType dir,
double voltage,
voltageUnits units )

Turns on the motor and spins it in a specified direction and a specified voltage.

Parameters
dirThe direction to spin the motor.
voltageSets the amount of volts.
unitsThe measurement unit for the voltage value.

◆ spinFor() [1/4]

bool vex::motor::spinFor ( double rotation,
rotationUnits units,
bool waitForCompletion = true )

Turns on the motor and spins it to a relative target rotation value.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
rotationSets the amount of rotation.
unitsThe measurement unit for the rotation 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.

◆ spinFor() [2/4]

bool vex::motor::spinFor ( double rotation,
rotationUnits units,
double velocity,
velocityUnits units_v,
bool waitForCompletion = true )

Turns on the motor and spins it to a relative target rotation value at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
rotationSets the amount of rotation.
unitsThe measurement unit for the rotation 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.

◆ spinFor() [3/4]

bool vex::motor::spinFor ( double time,
timeUnits units )

Turns on the motor and spins it to a relative target time value.

Returns
true on success, false if parameter error
Parameters
timeSets the amount of time.
unitsThe measurement unit for the time value.

◆ spinFor() [4/4]

bool vex::motor::spinFor ( double time,
timeUnits units,
double velocity,
velocityUnits units_v )

Turns on the motor and spins it to a relative target time value at a specified velocity.

Returns
true on success, false if parameter error
Parameters
timeSets the amount of time.
unitsThe measurement unit for the time value.
velocitySets the amount of velocity.
units_vThe measurement unit for the velocity value.

◆ spinTo() [1/2]

bool vex::motor::spinTo ( double rotation,
rotationUnits units,
bool waitForCompletion = true )

Turns on the motor and spins it to an absolute target rotation value.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
rotationSets the amount of rotation.
unitsThe measurement unit for the rotation 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.

◆ spinTo() [2/2]

bool vex::motor::spinTo ( double rotation,
rotationUnits units,
double velocity,
velocityUnits units_v,
bool waitForCompletion = true )

Turns on the motor and spins it to an absolute target rotation value at a specified velocity.

Returns
Returns a Boolean that signifies when the motor has reached the target rotation value.
Parameters
rotationSets the amount of rotation.
unitsThe measurement unit for the rotation 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.

◆ stop()

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

Stops the motor using a specified brake mode.

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

◆ temperature() [1/2]

double vex::motor::temperature ( percentUnits units = percentUnits::pct)

Gets the temperature of the motor.

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

◆ temperature() [2/2]

double vex::motor::temperature ( temperatureUnits units)

Gets the temperature of the motor.

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

◆ torque()

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

Gets the torque of the motor.

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.

◆ value()

int32_t vex::motor::value ( )
virtual

Reimplemented from vex::device.

◆ velocity() [1/2]

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

Definition at line 284 of file vex_motor.h.

◆ velocity() [2/2]

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

Gets the current velocity of the motor.

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.

◆ voltage()

double vex::motor::voltage ( voltageUnits units = voltageUnits::volt)

Gets the electrical voltage of the motor.

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

The documentation for this class was generated from the following file: