LightLib
PROS library for VEX V5: EKF/MCL localization, RAMSETE path following, high-level chassis API
Loading...
Searching...
No Matches
okapi::Motor Class Reference

#include <motor.hpp>

Inheritance diagram for okapi::Motor:
okapi::AbstractMotor okapi::ControllerOutput< double >

Public Member Functions

 Motor (std::int8_t iport)
 A V5 motor.
 
 Motor (std::uint8_t iport, bool ireverse, AbstractMotor::gearset igearset, AbstractMotor::encoderUnits iencoderUnits, const std::shared_ptr< Logger > &logger=Logger::getDefaultLogger())
 A V5 motor.
 
std::int32_t moveAbsolute (double iposition, std::int32_t ivelocity) override
 Motor movement functions

 
std::int32_t moveRelative (double iposition, std::int32_t ivelocity) override
 Sets the relative target position for the motor to move to.
 
std::int32_t moveVelocity (std::int16_t ivelocity) override
 Sets the velocity for the motor.
 
std::int32_t moveVoltage (std::int16_t ivoltage) override
 Sets the voltage for the motor from -12000 to 12000.
 
std::int32_t modifyProfiledVelocity (std::int32_t ivelocity) override
 Changes the output velocity for a profiled movement (moveAbsolute or moveRelative).
 
double getTargetPosition () override
 Motor telemetry functions

 
double getPosition () override
 Gets the absolute position of the motor in its encoder units.
 
std::int32_t tarePosition () override
 Sets the "absolute" zero position of the motor to its current position.
 
std::int32_t getTargetVelocity () override
 Gets the velocity commanded to the motor by the user.
 
double getActualVelocity () override
 Gets the actual velocity of the motor.
 
std::int32_t getCurrentDraw () override
 Gets the current drawn by the motor in mA.
 
std::int32_t getDirection () override
 Gets the direction of movement for the motor.
 
double getEfficiency () override
 Gets the efficiency of the motor in percent.
 
std::int32_t isOverCurrent () override
 Checks if the motor is drawing over its current limit.
 
std::int32_t isOverTemp () override
 Checks if the motor's temperature is above its limit.
 
std::int32_t isStopped () override
 Checks if the motor is stopped.
 
std::int32_t getZeroPositionFlag () override
 Checks if the motor is at its zero position.
 
uint32_t getFaults () override
 Gets the faults experienced by the motor.
 
uint32_t getFlags () override
 Gets the flags set by the motor's operation.
 
std::int32_t getRawPosition (std::uint32_t *timestamp) override
 Gets the raw encoder count of the motor at a given timestamp.
 
double getPower () override
 Gets the power drawn by the motor in Watts.
 
double getTemperature () override
 Gets the temperature of the motor in degrees Celsius.
 
double getTorque () override
 Gets the torque generated by the motor in Newton Metres (Nm).
 
std::int32_t getVoltage () override
 Gets the voltage delivered to the motor in millivolts.
 
std::int32_t setBrakeMode (AbstractMotor::brakeMode imode) override
 Motor configuration functions

 
brakeMode getBrakeMode () override
 Gets the brake mode that was set for the motor.
 
std::int32_t setCurrentLimit (std::int32_t ilimit) override
 Sets the current limit for the motor in mA.
 
std::int32_t getCurrentLimit () override
 Gets the current limit for the motor in mA.
 
std::int32_t setEncoderUnits (AbstractMotor::encoderUnits iunits) override
 Sets one of AbstractMotor::encoderUnits for the motor encoder.
 
encoderUnits getEncoderUnits () override
 Gets the encoder units that were set for the motor.
 
std::int32_t setGearing (AbstractMotor::gearset igearset) override
 Sets one of AbstractMotor::gearset for the motor.
 
gearset getGearing () override
 Gets the gearset that was set for the motor.
 
std::int32_t setReversed (bool ireverse) override
 Sets the reverse flag for the motor.
 
std::int32_t setVoltageLimit (std::int32_t ilimit) override
 Sets the voltage limit for the motor in Volts.
 
virtual std::int32_t setPosPID (double ikF, double ikP, double ikI, double ikD)
 Sets new PID constants.
 
virtual std::int32_t setPosPIDFull (double ikF, double ikP, double ikI, double ikD, double ifilter, double ilimit, double ithreshold, double iloopSpeed)
 Sets new PID constants.
 
virtual std::int32_t setVelPID (double ikF, double ikP, double ikI, double ikD)
 Sets new PID constants.
 
virtual std::int32_t setVelPIDFull (double ikF, double ikP, double ikI, double ikD, double ifilter, double ilimit, double ithreshold, double iloopSpeed)
 Sets new PID constants.
 
std::shared_ptr< ContinuousRotarySensorgetEncoder () override
 Get the encoder associated with this motor.
 
void controllerSet (double ivalue) override
 Writes the value of the controller output.
 
std::uint8_t getPort () const
 
bool isReversed () const
 
- Public Member Functions inherited from okapi::AbstractMotor
virtual ~AbstractMotor ()
 
double getPositionError ()
 Gets the positional error (target position minus actual position) of the motor in its encoder units.
 
double getVelocityError ()
 Gets the difference between the target velocity of the motor and the actual velocity of the motor.
 

Protected Attributes

std::uint8_t port
 
std::int8_t reversed {1}
 

Additional Inherited Members

- Public Types inherited from okapi::AbstractMotor
enum class  brakeMode { coast = 0 , brake = 1 , hold = 2 , invalid = INT32_MAX }
 Indicates the 'brake mode' of a motor. More...
 
enum class  encoderUnits { degrees = 0 , rotations = 1 , counts = 2 , invalid = INT32_MAX }
 Indicates the units used by the motor encoders. More...
 
enum class  gearset { red = 100 , green = 200 , blue = 600 , invalid = INT32_MAX }
 Indicates the internal gear ratio of a motor. More...
 

Detailed Description

Definition at line 13 of file motor.hpp.

Constructor & Destructor Documentation

◆ Motor() [1/2]

okapi::Motor::Motor ( std::int8_t  iport)

A V5 motor.

Parameters
iportThe port number in the range [1, 21]. A negative port number is shorthand for reversing the motor.

◆ Motor() [2/2]

okapi::Motor::Motor ( std::uint8_t  iport,
bool  ireverse,
AbstractMotor::gearset  igearset,
AbstractMotor::encoderUnits  iencoderUnits,
const std::shared_ptr< Logger > &  logger = Logger::getDefaultLogger() 
)

A V5 motor.

Parameters
iportThe port number in the range [1, 21].
ireverseWhether the motor is reversed (this setting is not written to the motor, it is maintained by okapi::Motor instead).
igearsetThe internal gearset to set in the motor.
iencoderUnitsThe encoder units to set in the motor.
loggerThe logger that initialization warnings will be logged to.

Member Function Documentation

◆ controllerSet()

void okapi::Motor::controllerSet ( double  ivalue)
overridevirtual

Writes the value of the controller output.

This method might be automatically called in another thread by the controller. The range of input values is expected to be [-1, 1].

Parameters
ivalueThe controller's output in the range [-1, 1].

Implements okapi::ControllerOutput< double >.

◆ getActualVelocity()

double okapi::Motor::getActualVelocity ( )
overridevirtual

Gets the actual velocity of the motor.

Returns
The motor's actual velocity in RPM or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getBrakeMode()

brakeMode okapi::Motor::getBrakeMode ( )
overridevirtual

Gets the brake mode that was set for the motor.

Returns
One of brakeMode, according to what was set for the motor, or brakeMode::invalid if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getCurrentDraw()

std::int32_t okapi::Motor::getCurrentDraw ( )
overridevirtual

Gets the current drawn by the motor in mA.

Returns
The motor's current in mA or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getCurrentLimit()

std::int32_t okapi::Motor::getCurrentLimit ( )
overridevirtual

Gets the current limit for the motor in mA.

The default value is 2500 mA.

Returns
The motor's current limit in mA or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getDirection()

std::int32_t okapi::Motor::getDirection ( )
overridevirtual

Gets the direction of movement for the motor.

Returns
1 for moving in the positive direction, -1 for moving in the negative direction, and PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getEfficiency()

double okapi::Motor::getEfficiency ( )
overridevirtual

Gets the efficiency of the motor in percent.

An efficiency of 100% means that the motor is moving electrically while drawing no electrical power, and an efficiency of 0% means that the motor is drawing power but not moving.

Returns
The motor's efficiency in percent or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getEncoder()

std::shared_ptr< ContinuousRotarySensor > okapi::Motor::getEncoder ( )
overridevirtual

Get the encoder associated with this motor.

Returns
The encoder for this motor.

Implements okapi::AbstractMotor.

◆ getEncoderUnits()

encoderUnits okapi::Motor::getEncoderUnits ( )
overridevirtual

Gets the encoder units that were set for the motor.

Returns
One of encoderUnits according to what is set for the motor or encoderUnits::invalid if the operation failed.

Implements okapi::AbstractMotor.

◆ getFaults()

uint32_t okapi::Motor::getFaults ( )
overridevirtual

Gets the faults experienced by the motor.

Compare this bitfield to the bitmasks in pros::motor_fault_e_t.

Returns
A currently unknown bitfield containing the motor's faults. 0b00000100 = Current Limit Hit

Implements okapi::AbstractMotor.

◆ getFlags()

uint32_t okapi::Motor::getFlags ( )
overridevirtual

Gets the flags set by the motor's operation.

Compare this bitfield to the bitmasks in pros::motor_flag_e_t.

Returns
A currently unknown bitfield containing the motor's flags. These seem to be unrelated to the individual get_specific_flag functions

Implements okapi::AbstractMotor.

◆ getGearing()

gearset okapi::Motor::getGearing ( )
overridevirtual

Gets the gearset that was set for the motor.

Returns
One of gearset according to what is set for the motor, or gearset::invalid if the operation failed.

Implements okapi::AbstractMotor.

◆ getPort()

std::uint8_t okapi::Motor::getPort ( ) const
Returns
The port number.

◆ getPosition()

double okapi::Motor::getPosition ( )
overridevirtual

Gets the absolute position of the motor in its encoder units.

Returns
The motor's absolute position in its encoder units or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getPower()

double okapi::Motor::getPower ( )
overridevirtual

Gets the power drawn by the motor in Watts.

Returns
The motor's power draw in Watts or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getRawPosition()

std::int32_t okapi::Motor::getRawPosition ( std::uint32_t *  timestamp)
overridevirtual

Gets the raw encoder count of the motor at a given timestamp.

Parameters
timestampA pointer to a time in milliseconds for which the encoder count will be returned. If NULL, the timestamp at which the encoder count was read will not be supplied
Returns
The raw encoder count at the given timestamp or PROS_ERR if the operation failed.

Implements okapi::AbstractMotor.

◆ getTargetPosition()

double okapi::Motor::getTargetPosition ( )
overridevirtual

Motor telemetry functions

These functions allow programmers to collect telemetry from motors
Gets the target position set for the motor by the user.

Returns
The target position in its encoder units or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getTargetVelocity()

std::int32_t okapi::Motor::getTargetVelocity ( )
overridevirtual

Gets the velocity commanded to the motor by the user.

Returns
The commanded motor velocity from +-100, +-200, or +-600, or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getTemperature()

double okapi::Motor::getTemperature ( )
overridevirtual

Gets the temperature of the motor in degrees Celsius.

Returns
The motor's temperature in degrees Celsius or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getTorque()

double okapi::Motor::getTorque ( )
overridevirtual

Gets the torque generated by the motor in Newton Metres (Nm).

Returns
The motor's torque in NM or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getVoltage()

std::int32_t okapi::Motor::getVoltage ( )
overridevirtual

Gets the voltage delivered to the motor in millivolts.

Returns
The motor's voltage in V or PROS_ERR_F if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ getZeroPositionFlag()

std::int32_t okapi::Motor::getZeroPositionFlag ( )
overridevirtual

Checks if the motor is at its zero position.

Although this function forwards data from the motor, the motor presently does not provide any value. This function returns PROS_ERR with errno set to ENOSYS.

Returns
1 if the motor is at zero absolute position, 0 if the motor has moved from its absolute zero, or PROS_ERR if the operation failed, setting errno

Implements okapi::AbstractMotor.

◆ isOverCurrent()

std::int32_t okapi::Motor::isOverCurrent ( )
overridevirtual

Checks if the motor is drawing over its current limit.

Returns
1 if the motor's current limit is being exceeded and 0 if the current limit is not exceeded, or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ isOverTemp()

std::int32_t okapi::Motor::isOverTemp ( )
overridevirtual

Checks if the motor's temperature is above its limit.

Returns
1 if the temperature limit is exceeded and 0 if the the temperature is below the limit, or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ isReversed()

bool okapi::Motor::isReversed ( ) const
Returns
Whether this motor is reversed.

◆ isStopped()

std::int32_t okapi::Motor::isStopped ( )
overridevirtual

Checks if the motor is stopped.

Although this function forwards data from the motor, the motor presently does not provide any value. This function returns PROS_ERR with errno set to ENOSYS.

Returns
1 if the motor is not moving, 0 if the motor is moving, or PROS_ERR if the operation failed, setting errno

Implements okapi::AbstractMotor.

◆ modifyProfiledVelocity()

std::int32_t okapi::Motor::modifyProfiledVelocity ( std::int32_t  ivelocity)
overridevirtual

Changes the output velocity for a profiled movement (moveAbsolute or moveRelative).

This will have no effect if the motor is not following a profiled movement.

Parameters
ivelocityThe new motor velocity from -+-100, +-200, or +-600 depending on the motor's gearset
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ moveAbsolute()

std::int32_t okapi::Motor::moveAbsolute ( double  iposition,
std::int32_t  ivelocity 
)
overridevirtual

Motor movement functions

These functions allow programmers to make motors move
Sets the target absolute position for the motor to move to.

This movement is relative to the position of the motor when initialized or the position when it was most recently reset with setZeroPosition().

Note
This function simply sets the target for the motor, it does not block program execution until the movement finishes.
Parameters
ipositionThe absolute position to move to in the motor's encoder units
ivelocityThe maximum allowable velocity for the movement in RPM
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ moveRelative()

std::int32_t okapi::Motor::moveRelative ( double  iposition,
std::int32_t  ivelocity 
)
overridevirtual

Sets the relative target position for the motor to move to.

This movement is relative to the current position of the motor. Providing 10.0 as the position parameter would result in the motor moving clockwise 10 units, no matter what the current position is.

Note
This function simply sets the target for the motor, it does not block program execution until the movement finishes.
Parameters
ipositionThe relative position to move to in the motor's encoder units
ivelocityThe maximum allowable velocity for the movement in RPM
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ moveVelocity()

std::int32_t okapi::Motor::moveVelocity ( std::int16_t  ivelocity)
overridevirtual

Sets the velocity for the motor.

This velocity corresponds to different actual speeds depending on the gearset used for the motor. This results in a range of +-100 for pros::c::red, +-200 for green, and +-600 for blue. The velocity is held with PID to ensure consistent speed, as opposed to setting the motor's voltage.

Parameters
ivelocityThe new motor velocity from -+-100, +-200, or +-600 depending on the motor's gearset
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ moveVoltage()

std::int32_t okapi::Motor::moveVoltage ( std::int16_t  ivoltage)
overridevirtual

Sets the voltage for the motor from -12000 to 12000.

Parameters
ivoltageThe new voltage value from -12000 to 12000.
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ setBrakeMode()

std::int32_t okapi::Motor::setBrakeMode ( AbstractMotor::brakeMode  imode)
overridevirtual

Motor configuration functions

These functions allow programmers to configure the behavior of motors
Sets one of AbstractMotor::brakeMode to the motor.

Parameters
imodeThe new motor brake mode to set for the motor
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ setCurrentLimit()

std::int32_t okapi::Motor::setCurrentLimit ( std::int32_t  ilimit)
overridevirtual

Sets the current limit for the motor in mA.

Parameters
ilimitThe new current limit in mA
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ setEncoderUnits()

std::int32_t okapi::Motor::setEncoderUnits ( AbstractMotor::encoderUnits  iunits)
overridevirtual

Sets one of AbstractMotor::encoderUnits for the motor encoder.

Parameters
iunitsThe new motor encoder units
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ setGearing()

std::int32_t okapi::Motor::setGearing ( AbstractMotor::gearset  igearset)
overridevirtual

Sets one of AbstractMotor::gearset for the motor.

Parameters
igearsetThe new motor gearset
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ setPosPID()

virtual std::int32_t okapi::Motor::setPosPID ( double  ikF,
double  ikP,
double  ikI,
double  ikD 
)
virtual

Sets new PID constants.

Parameters
ikFthe feed-forward constant
ikPthe proportional constant
ikIthe integral constant
ikDthe derivative constant
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

◆ setPosPIDFull()

virtual std::int32_t okapi::Motor::setPosPIDFull ( double  ikF,
double  ikP,
double  ikI,
double  ikD,
double  ifilter,
double  ilimit,
double  ithreshold,
double  iloopSpeed 
)
virtual

Sets new PID constants.

Parameters
ikFthe feed-forward constant
ikPthe proportional constant
ikIthe integral constant
ikDthe derivative constant
ifiltera constant used for filtering the profile acceleration
ilimitthe integral limit
ithresholdthe threshold for determining if a position movement has reached its goal
iloopSpeedthe rate at which the PID computation is run (in ms)
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

◆ setReversed()

std::int32_t okapi::Motor::setReversed ( bool  ireverse)
overridevirtual

Sets the reverse flag for the motor.

This will invert its movements and the values returned for its position.

Parameters
ireverseTrue reverses the motor, false is default
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ setVelPID()

virtual std::int32_t okapi::Motor::setVelPID ( double  ikF,
double  ikP,
double  ikI,
double  ikD 
)
virtual

Sets new PID constants.

Parameters
ikFthe feed-forward constant
ikPthe proportional constant
ikIthe integral constant
ikDthe derivative constant
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

◆ setVelPIDFull()

virtual std::int32_t okapi::Motor::setVelPIDFull ( double  ikF,
double  ikP,
double  ikI,
double  ikD,
double  ifilter,
double  ilimit,
double  ithreshold,
double  iloopSpeed 
)
virtual

Sets new PID constants.

Parameters
ikFthe feed-forward constant
ikPthe proportional constant
ikIthe integral constant
ikDthe derivative constant
ifiltera constant used for filtering the profile acceleration
ilimitthe integral limit
ithresholdthe threshold for determining if a position movement has reached its goal
iloopSpeedthe rate at which the PID computation is run (in ms)
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

◆ setVoltageLimit()

std::int32_t okapi::Motor::setVoltageLimit ( std::int32_t  ilimit)
overridevirtual

Sets the voltage limit for the motor in Volts.

Parameters
ilimitThe new voltage limit in Volts
Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

◆ tarePosition()

std::int32_t okapi::Motor::tarePosition ( )
overridevirtual

Sets the "absolute" zero position of the motor to its current position.

Returns
1 if the operation was successful or PROS_ERR if the operation failed, setting errno.

Implements okapi::AbstractMotor.

Member Data Documentation

◆ port

std::uint8_t okapi::Motor::port
protected

Definition at line 454 of file motor.hpp.

◆ reversed

std::int8_t okapi::Motor::reversed {1}
protected

Definition at line 455 of file motor.hpp.


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