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

#include <abstractMotor.hpp>

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

Classes

struct  GearsetRatioPair
 A simple structure representing the full ratio between motor and wheel. More...
 

Public Types

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

Public Member Functions

virtual ~AbstractMotor ()
 
virtual std::int32_t moveAbsolute (double iposition, std::int32_t ivelocity)=0
 Motor movement functions

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

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

 
virtual brakeMode getBrakeMode ()=0
 Gets the brake mode that was set for the motor.
 
virtual std::int32_t setCurrentLimit (std::int32_t ilimit)=0
 Sets the current limit for the motor in mA.
 
virtual std::int32_t getCurrentLimit ()=0
 Gets the current limit for the motor in mA.
 
virtual std::int32_t setEncoderUnits (encoderUnits iunits)=0
 Sets one of encoderUnits for the motor encoder.
 
virtual encoderUnits getEncoderUnits ()=0
 Gets the encoder units that were set for the motor.
 
virtual std::int32_t setGearing (gearset igearset)=0
 Sets one of gearset for the motor.
 
virtual gearset getGearing ()=0
 Gets the gearset that was set for the motor.
 
virtual std::int32_t setReversed (bool ireverse)=0
 Sets the reverse flag for the motor.
 
virtual std::int32_t setVoltageLimit (std::int32_t ilimit)=0
 Sets the voltage limit for the motor in Volts.
 
virtual std::shared_ptr< ContinuousRotarySensorgetEncoder ()=0
 Returns the encoder associated with this motor.
 
- Public Member Functions inherited from okapi::ControllerOutput< double >
virtual void controllerSet (double ivalue)=0
 Writes the value of the controller output.
 

Detailed Description

Definition at line 13 of file abstractMotor.hpp.

Member Enumeration Documentation

◆ brakeMode

Indicates the 'brake mode' of a motor.

Enumerator
coast 

Motor coasts when stopped, traditional behavior.

brake 

Motor brakes when stopped.

hold 

Motor actively holds position when stopped.

invalid 

Definition at line 18 of file abstractMotor.hpp.

◆ encoderUnits

Indicates the units used by the motor encoders.

Enumerator
degrees 

degrees

rotations 

rotations

counts 

counts

invalid 

invalid

Definition at line 28 of file abstractMotor.hpp.

◆ gearset

enum class okapi::AbstractMotor::gearset
strong

Indicates the internal gear ratio of a motor.

Enumerator
red 

36:1, 100 RPM, Red gear set

green 

18:1, 200 RPM, Green gear set

blue 

6:1, 600 RPM, Blue gear set

invalid 

Definition at line 38 of file abstractMotor.hpp.

Constructor & Destructor Documentation

◆ ~AbstractMotor()

virtual okapi::AbstractMotor::~AbstractMotor ( )
virtual

Member Function Documentation

◆ getActualVelocity()

virtual double okapi::AbstractMotor::getActualVelocity ( )
pure virtual

Gets the actual velocity of the motor.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getBrakeMode()

virtual brakeMode okapi::AbstractMotor::getBrakeMode ( )
pure virtual

Gets the brake mode that was set for the motor.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getCurrentDraw()

virtual std::int32_t okapi::AbstractMotor::getCurrentDraw ( )
pure virtual

Gets the current drawn by the motor in mA.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getCurrentLimit()

virtual std::int32_t okapi::AbstractMotor::getCurrentLimit ( )
pure virtual

Gets the current limit for the motor in mA.

The default value is 2500 mA.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getDirection()

virtual std::int32_t okapi::AbstractMotor::getDirection ( )
pure virtual

Gets the direction of movement for the motor.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getEfficiency()

virtual double okapi::AbstractMotor::getEfficiency ( )
pure virtual

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.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getEncoder()

virtual std::shared_ptr< ContinuousRotarySensor > okapi::AbstractMotor::getEncoder ( )
pure virtual

Returns the encoder associated with this motor.

Returns
the encoder for this motor

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getEncoderUnits()

virtual encoderUnits okapi::AbstractMotor::getEncoderUnits ( )
pure virtual

Gets the encoder units that were set for the motor.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getFaults()

virtual uint32_t okapi::AbstractMotor::getFaults ( )
pure virtual

Gets the faults experienced by the motor.

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getFlags()

virtual uint32_t okapi::AbstractMotor::getFlags ( )
pure virtual

Gets the flags set by the motor's operation.

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getGearing()

virtual gearset okapi::AbstractMotor::getGearing ( )
pure virtual

Gets the gearset that was set for the motor.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getPosition()

virtual double okapi::AbstractMotor::getPosition ( )
pure virtual

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getPositionError()

double okapi::AbstractMotor::getPositionError ( )

Gets the positional error (target position minus actual position) of the motor in its encoder units.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

◆ getPower()

virtual double okapi::AbstractMotor::getPower ( )
pure virtual

Gets the power drawn by the motor in Watts.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getRawPosition()

virtual std::int32_t okapi::AbstractMotor::getRawPosition ( std::uint32_t *  timestamp)
pure virtual

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getTargetPosition()

virtual double okapi::AbstractMotor::getTargetPosition ( )
pure virtual

Motor telemetry functions

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getTargetVelocity()

virtual std::int32_t okapi::AbstractMotor::getTargetVelocity ( )
pure virtual

Gets the velocity commanded to the motor by the user.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getTemperature()

virtual double okapi::AbstractMotor::getTemperature ( )
pure virtual

Gets the temperature of the motor in degrees Celsius.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getTorque()

virtual double okapi::AbstractMotor::getTorque ( )
pure virtual

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getVelocityError()

double okapi::AbstractMotor::getVelocityError ( )

Gets the difference between the target velocity of the motor and the actual velocity of the motor.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

◆ getVoltage()

virtual std::int32_t okapi::AbstractMotor::getVoltage ( )
pure virtual

Gets the voltage delivered to the motor in millivolts.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ getZeroPositionFlag()

virtual std::int32_t okapi::AbstractMotor::getZeroPositionFlag ( )
pure virtual

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ isOverCurrent()

virtual std::int32_t okapi::AbstractMotor::isOverCurrent ( )
pure virtual

Checks if the motor is drawing over its current limit.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ isOverTemp()

virtual std::int32_t okapi::AbstractMotor::isOverTemp ( )
pure virtual

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ isStopped()

virtual std::int32_t okapi::AbstractMotor::isStopped ( )
pure virtual

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ modifyProfiledVelocity()

virtual std::int32_t okapi::AbstractMotor::modifyProfiledVelocity ( std::int32_t  ivelocity)
pure virtual

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.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ moveAbsolute()

virtual std::int32_t okapi::AbstractMotor::moveAbsolute ( double  iposition,
std::int32_t  ivelocity 
)
pure virtual

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.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ moveRelative()

virtual std::int32_t okapi::AbstractMotor::moveRelative ( double  iposition,
std::int32_t  ivelocity 
)
pure virtual

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.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ moveVelocity()

virtual std::int32_t okapi::AbstractMotor::moveVelocity ( std::int16_t  ivelocity)
pure virtual

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.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ moveVoltage()

virtual std::int32_t okapi::AbstractMotor::moveVoltage ( std::int16_t  ivoltage)
pure virtual

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ setBrakeMode()

virtual std::int32_t okapi::AbstractMotor::setBrakeMode ( brakeMode  imode)
pure virtual

Motor configuration functions

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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.

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ setCurrentLimit()

virtual std::int32_t okapi::AbstractMotor::setCurrentLimit ( std::int32_t  ilimit)
pure virtual

Sets the current limit for the motor in mA.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ setEncoderUnits()

virtual std::int32_t okapi::AbstractMotor::setEncoderUnits ( encoderUnits  iunits)
pure virtual

Sets one of encoderUnits for the motor encoder.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ setGearing()

virtual std::int32_t okapi::AbstractMotor::setGearing ( gearset  igearset)
pure virtual

Sets one of gearset for the motor.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ setReversed()

virtual std::int32_t okapi::AbstractMotor::setReversed ( bool  ireverse)
pure virtual

Sets the reverse flag for the motor.

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ setVoltageLimit()

virtual std::int32_t okapi::AbstractMotor::setVoltageLimit ( std::int32_t  ilimit)
pure virtual

Sets the voltage limit for the motor in Volts.

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.

◆ tarePosition()

virtual std::int32_t okapi::AbstractMotor::tarePosition ( )
pure virtual

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

This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.

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

Implemented in okapi::Motor, and okapi::MotorGroup.


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