VEX IQ C++ API
|
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... | |
![]() | |
device (int32_t index) | |
~device () | |
Friends | |
class | drivetrain |
Additional Inherited Members | |
![]() | |
int32_t | _index |
Use the motor class to control motor devices.
vex::motor::motor | ( | int32_t | index | ) |
Creates a new motor object on the port specified.
index | The port index for this motor. The index is zero-based. |
|
inline |
vex::motor::motor | ( | int32_t | index, |
bool | reverse | ||
) |
Creates a new motor object on the port specified and sets the reversed flag.
index | The port index for this motor. The index is zero-based. |
reverse | Sets the reverse flag for the new motor object. |
void vex::motor::setReversed | ( | bool | value | ) |
Sets the motor mode to "reverse", which will make motor commands spin the motor in the opposite direction.
value | If set to true, motor commands spin the motor in the opposite direction. |
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.
velocity | Sets the amount of velocity. |
units | The measurement unit for the velocity value. |
|
inline |
void vex::motor::setStopping | ( | brakeType | mode | ) |
Set default stopping mode (note this will stop the motor if it's spinning).
mode | The stopping mode can be set to coast, brake, or hold. |
void vex::motor::resetRotation | ( | void | ) |
Resets the motor's encoder to the value of zero.
void vex::motor::setRotation | ( | float | value, |
rotationUnits | units | ||
) |
Sets the value of the motor's encoder to the value specified in the parameter.
value | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
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.
time | Sets the amount of time. |
units | The measurement unit for the time value. |
float vex::motor::timeout | ( | timeUnits | units | ) |
bool vex::motor::didTimeout | ( | void | ) |
brakeType vex::motor::_getBrakeMode | ( | ) |
void vex::motor::spin | ( | directionType | dir | ) |
Turns the motor on, and spins it in the specified direction.
dir | The direction to spin the motor. |
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.
dir | The direction to spin the motor. |
velocity | Sets the amount of velocity. |
units | The measurement unit for the velocity value. |
|
inline |
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.
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
velocity | Sets the amount of velocity. |
units_v | The 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. |
bool vex::motor::spinTo | ( | float | rotation, |
rotationUnits | units, | ||
bool | waitForCompletion = true |
||
) |
Turns on the motor and spins it to an absolute target rotation value.
rotation | Sets the amount of rotation. |
units | The 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. |
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.
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
velocity | Sets the amount of velocity. |
units_v | The 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. |
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.
dir | The direction to spin the motor. |
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
velocity | Sets the amount of velocity. |
units_v | The 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. |
bool vex::motor::spinFor | ( | float | rotation, |
rotationUnits | units, | ||
bool | waitForCompletion = true |
||
) |
Turns on the motor and spins it to a relative target rotation value.
rotation | Sets the amount of rotation. |
units | The 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. |
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.
dir | The direction to spin the motor. |
rotation | Sets the amount of rotation. |
units | The 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. |
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.
time | Sets the amount of time. |
units | The measurement unit for the time value. |
velocity | Sets the amount of velocity. |
units_v | The measurement unit for the velocity value. |
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.
dir | The direction to spin the motor. |
time | Sets the amount of time. |
units | The measurement unit for the time value. |
velocity | Sets the amount of velocity. |
units_v | The measurement unit for the velocity value. |
void vex::motor::spinFor | ( | float | time, |
timeUnits | units | ||
) |
time | Sets the amount of time. |
units | The measurement unit for the time value. |
void vex::motor::spinFor | ( | directionType | dir, |
float | time, | ||
timeUnits | units | ||
) |
dir | The direction to spin the motor. |
time | Sets the amount of time. |
units | The measurement unit for the time value. |
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.
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
velocity | Sets the amount of velocity. |
units_v | The measurement unit for the velocity value. |
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..
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
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.
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
velocity | Sets the amount of velocity. |
units_v | The measurement unit for the velocity value. |
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.
dir | The direction to spin the motor. |
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
velocity | Sets the amount of velocity. |
units_v | The measurement unit for the velocity value. |
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.
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
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.
dir | The direction to spin the motor. |
rotation | Sets the amount of rotation. |
units | The measurement unit for the rotation value. |
bool vex::motor::isSpinning | ( | ) |
Determines if the motor is performing a spinFor/spinTo command.
|
inline |
Determines if a spinFor/spinTo command has reached its target position.
void vex::motor::stop | ( | ) |
Stops the motor using the default brake mode.
void vex::motor::stop | ( | brakeType | mode | ) |
Stops the motor using a specified brake mode.
mode | The brake mode can be set to coast, brake, or hold. |
void vex::motor::setMaxTorque | ( | float | value, |
percentUnits | units | ||
) |
Sets the max torque of the motor.
value | Sets the amount of torque (0 to 100%) |
units | The measurement unit for the torque value. |
void vex::motor::setMaxTorque | ( | float | value, |
torqueUnits | units | ||
) |
Sets the max torque of the motor.
value | Sets the amount of torque (max 0.414 Nm) |
units | The measurement unit for the torque value. |
void vex::motor::setMaxTorque | ( | float | value, |
currentUnits | units | ||
) |
Sets the max torque of the motor.
value | Sets the amount of torque (max 1.2A) |
units | The measurement unit for the torque value. |
directionType vex::motor::direction | ( | void | ) |
Gets which direction the motor is spinning.
float vex::motor::rotation | ( | rotationUnits | units | ) |
Gets the current rotation of the motor's encoder.
units | The measurement unit for the rotation. |
float vex::motor::velocity | ( | velocityUnits | units | ) |
Gets the current velocity of the motor.
units | The measurement unit for the velocity. |
float vex::motor::current | ( | currentUnits | units = currentUnits::amp | ) |
Gets the electrical current of the motor.
units | The measurement unit for the current. |
|
friend |