diff --git a/include/hardware/Motor/Motor.hpp b/include/hardware/Motor/Motor.hpp index b40b4e5..a914055 100644 --- a/include/hardware/Motor/Motor.hpp +++ b/include/hardware/Motor/Motor.hpp @@ -478,6 +478,23 @@ class Motor : public Encoder { * @endcode */ Temperature getTemperature() const; + /** + * @brief set the output velocity of the motor + * + * @param outputVelocity the theoretical maximum output velocity of the motor, after gearing, to set + * @return int 0 success + * @return INT_MAX error occurred, setting errno + * + * @b Example: + * @code {.cpp} + * void initialize() { + * lemlib::Motor motor(1, 360_rpm); + * // set the output velocity to 450 rpm + * motor.setOutputVelocity(450_rpm); + * } + * @endcode + */ + int setOutputVelocity(AngularVelocity outputVelocity); private: AngularVelocity m_outputVelocity; Angle m_offset = 0_stDeg; diff --git a/include/hardware/Motor/MotorGroup.hpp b/include/hardware/Motor/MotorGroup.hpp index fced502..ff488d7 100644 --- a/include/hardware/Motor/MotorGroup.hpp +++ b/include/hardware/Motor/MotorGroup.hpp @@ -1,5 +1,6 @@ #include "pros/motor_group.hpp" #include "hardware/Motor/Motor.hpp" +#include "units/Angle.hpp" #include namespace lemlib { @@ -333,6 +334,23 @@ class MotorGroup : Encoder { * @endcode */ std::vector getTemperatures(); + /** + * @brief set the output velocity of the motors + * + * @param outputVelocity the theoretical maximum output velocity of the motor group, after gearing, to set + * @return int 0 success + * @return INT_MAX error occurred, setting errno + * + * @b Example: + * @code {.cpp} + * void initialize() { + * lemlib::MotorGroup motorGroup({1, -2, 3}, 360_rpm); + * // set the output velocity to 450 rpm + * motorGroup.setOutputVelocity(450_rpm); + * } + * @endcode + */ + int setOutputVelocity(AngularVelocity outputVelocity); /** * @brief Get the number of connected motors in the group * @@ -495,7 +513,7 @@ class MotorGroup : Encoder { * @return const std::vector vector of lemlib::Motor objects */ const std::vector getMotors(); - const AngularVelocity m_outputVelocity; + AngularVelocity m_outputVelocity; /** * This member variable is a vector of motor information * diff --git a/src/hardware/Motor/Motor.cpp b/src/hardware/Motor/Motor.cpp index f7177c1..1a85a6c 100644 --- a/src/hardware/Motor/Motor.cpp +++ b/src/hardware/Motor/Motor.cpp @@ -175,4 +175,12 @@ Temperature Motor::getTemperature() const { if (result.internal() == INFINITY) return result; // error checking return result; } + +// Always returns 0 because the velocity setter is not dependent on hardware and should never fail +int Motor::setOutputVelocity(AngularVelocity outputVelocity) { + Angle angle = getAngle(); + m_outputVelocity = outputVelocity; + setAngle(angle); + return 0; +} } // namespace lemlib \ No newline at end of file diff --git a/src/hardware/Motor/MotorGroup.cpp b/src/hardware/Motor/MotorGroup.cpp index 4fb637f..9e80b35 100644 --- a/src/hardware/Motor/MotorGroup.cpp +++ b/src/hardware/Motor/MotorGroup.cpp @@ -4,6 +4,7 @@ #include "units/Temperature.hpp" #include #include +#include #include namespace lemlib { @@ -144,6 +145,14 @@ std::vector MotorGroup::getTemperatures() { return temperatures; } +// Always returns 0 because the velocity setter is not dependent on hardware and should never fail +int MotorGroup::setOutputVelocity(AngularVelocity outputVelocity) { + Angle angle = getAngle(); + m_outputVelocity = outputVelocity; + setAngle(angle); + return 0; +} + int MotorGroup::getSize() { const std::vector motors = getMotors(); int size = 0;