VEX IQ C++ API
Public Member Functions | Friends | List of all members
vex::motor Class Reference

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

Inherits vex::device.

Public Member Functions

 motor (int32_t index)
 Creates a new motor object on the port specified. More...
 
 ~motor ()
 
 motor (int32_t index, bool reverse)
 Creates a new motor object on the port specified and sets the reversed flag. More...
 
void setReversed (bool value)
 Sets the motor mode to "reverse", which will make motor commands spin the motor in the opposite direction. More...
 
void setVelocity (float 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. More...
 
void setVelocity (float velocity, percentUnits units)
 
void setStopping (brakeType mode)
 Set default stopping mode (note this will stop the motor if it's spinning). More...
 
void resetRotation (void)
 Resets the motor's encoder to the value of zero. More...
 
void setRotation (float value, rotationUnits units)
 Sets the value of the motor's encoder to the value specified in the parameter. More...
 
void setTimeout (float 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. More...
 
float timeout (timeUnits units)
 
bool didTimeout (void)
 
brakeType _getBrakeMode ()
 
void spin (directionType dir)
 Turns the motor on, and spins it in the specified direction. More...
 
void spin (directionType dir, float velocity, velocityUnits units)
 Turns on the motor and spins it in a specified direction and a specified velocity. More...
 
void spin (directionType dir, float velocity, percentUnits units)
 
bool spinTo (float rotation, rotationUnits units, float velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turns on the motor and spins it to an absolute target rotation value at a specified velocity. More...
 
bool spinTo (float rotation, rotationUnits units, bool waitForCompletion=true)
 Turns on the motor and spins it to an absolute target rotation value. More...
 
bool spinFor (float rotation, rotationUnits units, float velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turns on the motor and spins it to a relative target rotation value at a specified velocity. More...
 
bool spinFor (directionType dir, float rotation, rotationUnits units, float velocity, velocityUnits units_v, bool waitForCompletion=true)
 Turns on the motor and spins it to a relative target rotation value at a specified velocity. More...
 
bool spinFor (float rotation, rotationUnits units, bool waitForCompletion=true)
 Turns on the motor and spins it to a relative target rotation value. More...
 
bool spinFor (directionType dir, float rotation, rotationUnits units, bool waitForCompletion=true)
 Turns on the motor and spins it to a relative target rotation value. More...
 
void spinFor (float time, timeUnits units, float velocity, velocityUnits units_v)
 Turns on the motor and spins it to a relative target time value at a specified velocity. More...
 
void spinFor (directionType dir, float time, timeUnits units, float velocity, velocityUnits units_v)
 Turns on the motor and spins it to a relative target time value at a specified velocity. More...
 
void spinFor (float time, timeUnits units)
 
void spinFor (directionType dir, float time, timeUnits units)
 
void startSpinTo (float rotation, rotationUnits units, float velocity, velocityUnits units_v)
 Starts spinning a motor to an absolute target rotation but does not wait for the motor to reach that target. More...
 
void startSpinTo (float rotation, rotationUnits units)
 Starts spinning a motor to an absolute target rotation but does not wait for the motor to reach that target.. More...
 
void startSpinFor (float rotation, rotationUnits units, float velocity, velocityUnits units_v)
 Starts spinning a motor to a relative target rotation but does not wait for the motor to reach that target. More...
 
void startSpinFor (directionType dir, float rotation, rotationUnits units, float velocity, velocityUnits units_v)
 Starts spinning a motor to a relative target rotation but does not wait for the motor to reach that target. More...
 
void startSpinFor (float rotation, rotationUnits units)
 Starts spinning a motor to a relative target but does not wait for the motor to reach that target. More...
 
void startSpinFor (directionType dir, float rotation, rotationUnits units)
 Starts spinning a motor to a relative target but does not wait for the motor to reach that target. More...
 
bool isSpinning ()
 Determines if the motor is performing a spinFor/spinTo command. More...
 
bool isDone ()
 Determines if a spinFor/spinTo command has reached its target position. More...
 
void stop ()
 Stops the motor using the default brake mode. More...
 
void stop (brakeType mode)
 Stops the motor using a specified brake mode. More...
 
void setMaxTorque (float value, percentUnits units)
 Sets the max torque of the motor. More...
 
void setMaxTorque (float value, torqueUnits units)
 Sets the max torque of the motor. More...
 
void setMaxTorque (float value, currentUnits units)
 Sets the max torque of the motor. More...
 
directionType direction (void)
 Gets which direction the motor is spinning. More...
 
float rotation (rotationUnits units)
 Gets the current rotation of the motor's encoder. More...
 
float velocity (velocityUnits units)
 Gets the current velocity of the motor. More...
 
float current (currentUnits units=currentUnits::amp)
 Gets the electrical current of the motor. More...
 
- Public Member Functions inherited from vex::device
 device (int32_t index)
 
 ~device ()
 

Friends

class drivetrain
 

Additional Inherited Members

- Protected Attributes inherited from vex::device
int32_t _index
 

Detailed Description

Use the motor class to control motor devices.

Constructor & Destructor Documentation

◆ motor() [1/2]

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()

vex::motor::~motor ( )
inline

◆ motor() [2/2]

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.

Member Function Documentation

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

◆ setVelocity() [1/2]

void vex::motor::setVelocity ( float  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.

◆ setVelocity() [2/2]

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

◆ setStopping()

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

Set default stopping mode (note this will stop the motor if it's spinning).

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

◆ resetRotation()

void vex::motor::resetRotation ( void  )

Resets the motor's encoder to the value of zero.

◆ setRotation()

void vex::motor::setRotation ( float  value,
rotationUnits  units 
)

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

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

◆ setTimeout()

void vex::motor::setTimeout ( float  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.

◆ timeout()

float vex::motor::timeout ( timeUnits  units)
Returns
Returns a timeout in given time units

◆ didTimeout()

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

◆ _getBrakeMode()

brakeType vex::motor::_getBrakeMode ( )

◆ spin() [1/3]

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/3]

void vex::motor::spin ( directionType  dir,
float  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() [3/3]

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

◆ spinTo() [1/2]

bool vex::motor::spinTo ( float  rotation,
rotationUnits  units,
float  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.

◆ spinTo() [2/2]

bool vex::motor::spinTo ( float  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.

◆ spinFor() [1/8]

bool vex::motor::spinFor ( float  rotation,
rotationUnits  units,
float  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() [2/8]

bool vex::motor::spinFor ( directionType  dir,
float  rotation,
rotationUnits  units,
float  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
dirThe direction to spin the motor.
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/8]

bool vex::motor::spinFor ( float  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() [4/8]

bool vex::motor::spinFor ( directionType  dir,
float  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
dirThe direction to spin the motor.
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() [5/8]

void vex::motor::spinFor ( float  time,
timeUnits  units,
float  velocity,
velocityUnits  units_v 
)

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

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.

◆ spinFor() [6/8]

void vex::motor::spinFor ( directionType  dir,
float  time,
timeUnits  units,
float  velocity,
velocityUnits  units_v 
)

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

Parameters
dirThe direction to spin the motor.
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.

◆ spinFor() [7/8]

void vex::motor::spinFor ( float  time,
timeUnits  units 
)
Returns
Returns a Boolean that signifies when the motor has reached the target time value.
Parameters
timeSets the amount of time.
unitsThe measurement unit for the time value.

◆ spinFor() [8/8]

void vex::motor::spinFor ( directionType  dir,
float  time,
timeUnits  units 
)
Returns
Returns a Boolean that signifies when the motor has reached the target time value.
Parameters
dirThe direction to spin the motor.
timeSets the amount of time.
unitsThe measurement unit for the time value.

◆ startSpinTo() [1/2]

void vex::motor::startSpinTo ( float  rotation,
rotationUnits  units,
float  velocity,
velocityUnits  units_v 
)

Starts spinning a motor to an absolute target rotation but does not wait for the motor to reach that target.

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.

◆ startSpinTo() [2/2]

void vex::motor::startSpinTo ( float  rotation,
rotationUnits  units 
)

Starts spinning a motor to an absolute target rotation but does not wait for the motor to reach that target..

Parameters
rotationSets the amount of rotation.
unitsThe measurement unit for the rotation value.

◆ startSpinFor() [1/4]

void vex::motor::startSpinFor ( float  rotation,
rotationUnits  units,
float  velocity,
velocityUnits  units_v 
)

Starts spinning a motor to a relative target rotation but does not wait for the motor to reach that target.

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.

◆ startSpinFor() [2/4]

void vex::motor::startSpinFor ( directionType  dir,
float  rotation,
rotationUnits  units,
float  velocity,
velocityUnits  units_v 
)

Starts spinning a motor to a relative target rotation but does not wait for the motor to reach that target.

Parameters
dirThe direction to spin the motor.
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.

◆ startSpinFor() [3/4]

void vex::motor::startSpinFor ( float  rotation,
rotationUnits  units 
)

Starts spinning a motor to a relative target but does not wait for the motor to reach that target.

Parameters
rotationSets the amount of rotation.
unitsThe measurement unit for the rotation value.

◆ startSpinFor() [4/4]

void vex::motor::startSpinFor ( directionType  dir,
float  rotation,
rotationUnits  units 
)

Starts spinning a motor to a relative target but does not wait for the motor to reach that target.

Parameters
dirThe direction to spin the motor.
rotationSets the amount of rotation.
unitsThe measurement unit for the rotation value.

◆ isSpinning()

bool vex::motor::isSpinning ( )

Determines if the motor is performing a spinFor/spinTo command.

Returns
True if spinning.

◆ isDone()

bool vex::motor::isDone ( )
inline

Determines if a spinFor/spinTo command has reached its target position.

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::motor::stop ( )

Stops the motor using the default brake mode.

◆ stop() [2/2]

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.

◆ setMaxTorque() [1/3]

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

Sets the max torque of the motor.

Parameters
valueSets the amount of torque (0 to 100%)
unitsThe measurement unit for the torque value.

◆ setMaxTorque() [2/3]

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

Sets the max torque of the motor.

Parameters
valueSets the amount of torque (max 0.414 Nm)
unitsThe measurement unit for the torque value.

◆ setMaxTorque() [3/3]

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

Sets the max torque of the motor.

Parameters
valueSets the amount of torque (max 1.2A)
unitsThe measurement unit for the torque value.

◆ direction()

directionType vex::motor::direction ( void  )

Gets which direction the motor is spinning.

Returns
Returns the direction that the motor is spinning.

◆ rotation()

float vex::motor::rotation ( rotationUnits  units)

Gets the current rotation of the motor's encoder.

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

◆ velocity()

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

Gets the current velocity of the motor.

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

◆ current()

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

Gets the electrical current of the motor.

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

Friends And Related Function Documentation

◆ drivetrain

friend class drivetrain
friend