class
MotorGroup
Contents
Base classes
- class AbstractMotor
Constructors, destructors, conversion operators
-
MotorGroup(const std::initializer_list<Motor>& imotors,
const std::shared_ptr<Logger>& ilogger = Logger::
getDefaultLogger()) - A group of V5 motors which act as one motor (i.e.
-
MotorGroup(const std::initializer_list<std::shared_ptr<AbstractMotor>>& imotors,
const std::shared_ptr<Logger>& ilogger = Logger::
getDefaultLogger()) - A group of V5 motors which act as one motor (i.e.
Public functions
- auto moveAbsolute(double iposition, std::int32_t ivelocity) -> std::int32_t override
- Motor movement functions.
- auto moveRelative(double iposition, std::int32_t ivelocity) -> std::int32_t override
- Sets the relative target position for the motor to move to.
- auto moveVelocity(std::int16_t ivelocity) -> std::int32_t override
- Sets the velocity for the motor.
- auto moveVoltage(std::int16_t ivoltage) -> std::int32_t override
- Sets the voltage for the motor from
-12000
to12000
. - auto modifyProfiledVelocity(std::int32_t ivelocity) -> std::int32_t override
- Changes the output velocity for a profiled movement (moveAbsolute or moveRelative).
- auto getTargetPosition() -> double override
- Motor telemetry functions.
- auto getPosition() -> double override
- Gets the absolute position of the motor in its encoder units.
- auto tarePosition() -> std::int32_t override
- Sets the "absolute" zero position of the motor to its current position.
- auto getTargetVelocity() -> std::int32_t override
- Gets the velocity commanded to the motor by the user.
- auto getActualVelocity() -> double override
- Gets the actual velocity of the motor.
- auto getCurrentDraw() -> std::int32_t override
- Gets the current drawn by the motor in mA.
- auto getDirection() -> std::int32_t override
- Gets the direction of movement for the motor.
- auto getEfficiency() -> double override
- Gets the efficiency of the motor in percent.
- auto isOverCurrent() -> std::int32_t override
- Checks if the motor is drawing over its current limit.
- auto isOverTemp() -> std::int32_t override
- Checks if the motor's temperature is above its limit.
- auto isStopped() -> std::int32_t override
- Checks if the motor is stopped.
- auto getZeroPositionFlag() -> std::int32_t override
- Checks if the motor is at its zero position.
- auto getFaults() -> uint32_t override
- Gets the faults experienced by the motor.
- auto getFlags() -> uint32_t override
- Gets the flags set by the motor's operation.
- auto getRawPosition(std::uint32_t* timestamp) -> std::int32_t override
- Gets the raw encoder count of the motor at a given timestamp.
- auto getPower() -> double override
- Gets the power drawn by the motor in Watts.
- auto getTemperature() -> double override
- Gets the temperature of the motor in degrees Celsius.
- auto getTorque() -> double override
- Gets the torque generated by the motor in Newton Metres (Nm).
- auto getVoltage() -> std::int32_t override
- Gets the voltage delivered to the motor in millivolts.
-
auto setBrakeMode(AbstractMotor::
brakeMode imode) -> std::int32_t override - Motor configuration functions.
- auto getBrakeMode() -> brakeMode override
- Gets the brake mode that was set for the motor.
- auto setCurrentLimit(std::int32_t ilimit) -> std::int32_t override
- Sets the current limit for the motor in mA.
- auto getCurrentLimit() -> std::int32_t override
- Gets the current limit for the motor in mA.
-
auto setEncoderUnits(AbstractMotor::
encoderUnits iunits) -> std::int32_t override - Sets one of AbstractMotor::
encoderUnits for the motor encoder. - auto getEncoderUnits() -> encoderUnits override
- Gets the encoder units that were set for the motor.
-
auto setGearing(AbstractMotor::
gearset igearset) -> std::int32_t override - Sets one of AbstractMotor::
gearset for the motor. - auto getGearing() -> gearset override
- Gets the gearset that was set for the motor.
- auto setReversed(bool ireverse) -> std::int32_t override
- Sets the reverse flag for the motor.
- auto setVoltageLimit(std::int32_t ilimit) -> std::int32_t override
- Sets the voltage limit for the motor in Volts.
- void controllerSet(double ivalue) override
- Writes the value of the controller output.
- auto getSize() -> size_t
- Gets the number of motors in the motor group.
- auto getEncoder() -> std::shared_ptr<ContinuousRotarySensor> override
- Get the encoder associated with the first motor in this group.
- auto getEncoder(std::size_t index) -> std::shared_ptr<ContinuousRotarySensor> virtual
- Get the encoder associated with this motor.
Protected variables
- std::vector<std::shared_ptr<AbstractMotor>> motors
Function documentation
okapi:: MotorGroup:: MotorGroup(const std::initializer_list<Motor>& imotors,
const std::shared_ptr<Logger>& ilogger = Logger:: getDefaultLogger())
A group of V5 motors which act as one motor (i.e.
Parameters | |
---|---|
imotors | The motors in this group. |
ilogger | The logger this instance will log initialization warnings to. |
they are mechanically linked). A MotorGroup requires at least one motor. If no motors are supplied, a std::invalid_argument
exception is thrown.
okapi:: MotorGroup:: MotorGroup(const std::initializer_list<std::shared_ptr<AbstractMotor>>& imotors,
const std::shared_ptr<Logger>& ilogger = Logger:: getDefaultLogger())
A group of V5 motors which act as one motor (i.e.
Parameters | |
---|---|
imotors | The motors in this group. |
ilogger | The logger this instance will log initialization warnings to. |
they are mechanically linked). A MotorGroup requires at least one motor. If no motors are supplied, a std::invalid_argument
exception is thrown.
std::int32_t okapi:: MotorGroup:: moveAbsolute(double iposition,
std::int32_t ivelocity) override
Motor movement functions.
Parameters | |
---|---|
iposition | The absolute position to move to in the motor's encoder units |
ivelocity | The maximum allowable velocity for the movement in RPM |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
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().
std::int32_t okapi:: MotorGroup:: moveRelative(double iposition,
std::int32_t ivelocity) override
Sets the relative target position for the motor to move to.
Parameters | |
---|---|
iposition | The relative position to move to in the motor's encoder units |
ivelocity | The maximum allowable velocity for the movement in RPM |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
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.
std::int32_t okapi:: MotorGroup:: moveVelocity(std::int16_t ivelocity) override
Sets the velocity for the motor.
Parameters | |
---|---|
ivelocity | The 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. |
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.
std::int32_t okapi:: MotorGroup:: moveVoltage(std::int16_t ivoltage) override
Sets the voltage for the motor from -12000
to 12000
.
Parameters | |
---|---|
ivoltage | The new voltage value from -12000 to 12000 . |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
std::int32_t okapi:: MotorGroup:: modifyProfiledVelocity(std::int32_t ivelocity) override
Changes the output velocity for a profiled movement (moveAbsolute or moveRelative).
Parameters | |
---|---|
ivelocity | The 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. |
This will have no effect if the motor is not following a profiled movement.
double okapi:: MotorGroup:: getTargetPosition() override
Motor telemetry functions.
Returns | The target position in its encoder units or PROS_ERR_F if the operation failed, setting errno. |
---|
These functions allow programmers to collect telemetry from motors Gets the target position set for the motor by the user.
double okapi:: MotorGroup:: getPosition() override
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. |
---|
std::int32_t okapi:: MotorGroup:: tarePosition() override
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. |
---|
std::int32_t okapi:: MotorGroup:: getTargetVelocity() override
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. |
---|
double okapi:: MotorGroup:: getActualVelocity() override
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. |
---|
std::int32_t okapi:: MotorGroup:: getCurrentDraw() override
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. |
---|
std::int32_t okapi:: MotorGroup:: getDirection() override
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. |
---|
double okapi:: MotorGroup:: getEfficiency() override
Gets the efficiency of the motor in percent.
Returns | The motor's efficiency in percent or PROS_ERR_F if the operation failed, setting errno. |
---|
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.
std::int32_t okapi:: MotorGroup:: isOverCurrent() override
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. |
---|
std::int32_t okapi:: MotorGroup:: isOverTemp() override
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. |
---|
std::int32_t okapi:: MotorGroup:: isStopped() override
Checks if the motor is stopped.
Returns | 1 if the motor is not moving, 0 if the motor is moving, or PROS_ERR if the operation failed, setting errno |
---|
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
.
std::int32_t okapi:: MotorGroup:: getZeroPositionFlag() override
Checks if the motor is at its zero position.
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 |
---|
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
.
uint32_t okapi:: MotorGroup:: getFaults() override
Gets the faults experienced by the motor.
Returns | A currently unknown bitfield containing the motor's faults. 0b00000100 = Current Limit Hit |
---|
Compare this bitfield to the bitmasks in pros::motor_fault_e_t.
uint32_t okapi:: MotorGroup:: getFlags() override
Gets the flags set by the motor's operation.
Returns | A currently unknown bitfield containing the motor's flags. These seem to be unrelated to the individual get_specific_flag functions |
---|
Compare this bitfield to the bitmasks in pros::motor_flag_e_t.
std::int32_t okapi:: MotorGroup:: getRawPosition(std::uint32_t* timestamp) override
Gets the raw encoder count of the motor at a given timestamp.
Parameters | |
---|---|
timestamp | A 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. |
double okapi:: MotorGroup:: getPower() override
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. |
---|
double okapi:: MotorGroup:: getTemperature() override
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. |
---|
double okapi:: MotorGroup:: getTorque() override
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. |
---|
std::int32_t okapi:: MotorGroup:: getVoltage() override
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. |
---|
std::int32_t okapi:: MotorGroup:: setBrakeMode(AbstractMotor:: brakeMode imode) override
Motor configuration functions.
Parameters | |
---|---|
imode | The 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. |
These functions allow programmers to configure the behavior of motors Sets one of AbstractMotor::
This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.
brakeMode okapi:: MotorGroup:: getBrakeMode() override
Gets the brake mode that was set for the motor.
Returns | One of brakeMode, according to what was set for the motor, or brakeMode:: |
---|
std::int32_t okapi:: MotorGroup:: setCurrentLimit(std::int32_t ilimit) override
Sets the current limit for the motor in mA.
Parameters | |
---|---|
ilimit | The new current limit in mA. |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached: EACCES - Another resource is currently trying to access the port.
std::int32_t okapi:: MotorGroup:: getCurrentLimit() override
Gets the current limit for the motor in mA.
Returns | The motor's current limit in mA or PROS_ERR if the operation failed, setting errno. |
---|
The default value is 2500
mA.
std::int32_t okapi:: MotorGroup:: setEncoderUnits(AbstractMotor:: encoderUnits iunits) override
Sets one of AbstractMotor::
Parameters | |
---|---|
iunits | The new motor encoder units. |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
encoderUnits okapi:: MotorGroup:: getEncoderUnits() override
Gets the encoder units that were set for the motor.
Returns | One of encoderUnits according to what is set for the motor or encoderUnits:: |
---|
std::int32_t okapi:: MotorGroup:: setGearing(AbstractMotor:: gearset igearset) override
Sets one of AbstractMotor::
Parameters | |
---|---|
igearset | The new motor gearset. |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
gearset okapi:: MotorGroup:: getGearing() override
Gets the gearset that was set for the motor.
Returns | One of gearset according to what is set for the motor, or gearset:: if the operation failed. |
---|
std::int32_t okapi:: MotorGroup:: setReversed(bool ireverse) override
Sets the reverse flag for the motor.
Parameters | |
---|---|
ireverse | True reverses the motor, false is default. |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This will invert its movements and the values returned for its position.
std::int32_t okapi:: MotorGroup:: setVoltageLimit(std::int32_t ilimit) override
Sets the voltage limit for the motor in Volts.
Parameters | |
---|---|
ilimit | The new voltage limit in Volts. |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
void okapi:: MotorGroup:: controllerSet(double ivalue) override
Writes the value of the controller output.
Parameters | |
---|---|
ivalue | the controller's output in the range [-1, 1] |
This method might be automatically called in another thread by the controller. The range of input values is expected to be [-1, 1]
.
std::shared_ptr<ContinuousRotarySensor> okapi:: MotorGroup:: getEncoder() override
Get the encoder associated with the first motor in this group.
Returns | The encoder for the motor at index 0 . |
---|
std::shared_ptr<ContinuousRotarySensor> okapi:: MotorGroup:: getEncoder(std::size_t index) virtual
Get the encoder associated with this motor.
Parameters | |
---|---|
index | The index in motors to get the encoder from. |
Returns | The encoder for the motor at index . |