From 5963da403537018805d3fbaba74554a170477f5e Mon Sep 17 00:00:00 2001 From: toxicdefender404 Date: Thu, 28 Nov 2024 20:26:38 +0000 Subject: [PATCH 1/3] add output velocity setter --- include/hardware/Motor/MotorGroup.hpp | 20 +++++++++++++++++++- src/hardware/Motor/MotorGroup.cpp | 7 +++++++ 2 files changed, 26 insertions(+), 1 deletion(-) 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/MotorGroup.cpp b/src/hardware/Motor/MotorGroup.cpp index 4fb637f..1b321c0 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,12 @@ 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) { + m_outputVelocity = outputVelocity; + return 0; +} + int MotorGroup::getSize() { const std::vector motors = getMotors(); int size = 0; From e49480fbfaf6b1df398606bbbf90d89385764819 Mon Sep 17 00:00:00 2001 From: toxicdefender404 Date: Thu, 28 Nov 2024 21:32:33 +0000 Subject: [PATCH 2/3] add setters to motor class --- include/hardware/Motor/Motor.hpp | 17 +++++++++++++++++ src/hardware/Motor/Motor.cpp | 6 ++++++ 2 files changed, 23 insertions(+) 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/src/hardware/Motor/Motor.cpp b/src/hardware/Motor/Motor.cpp index f7177c1..5a82ac5 100644 --- a/src/hardware/Motor/Motor.cpp +++ b/src/hardware/Motor/Motor.cpp @@ -175,4 +175,10 @@ 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) { + m_outputVelocity = outputVelocity; + return 0; +} } // namespace lemlib \ No newline at end of file From 7c0bf12566a8f620a71a6eb77cf3e665ff39e080 Mon Sep 17 00:00:00 2001 From: toxicdefender404 Date: Sat, 30 Nov 2024 23:41:32 +0000 Subject: [PATCH 3/3] keep angle the same when output velocity changes --- src/hardware/Motor/Motor.cpp | 2 ++ src/hardware/Motor/MotorGroup.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/hardware/Motor/Motor.cpp b/src/hardware/Motor/Motor.cpp index 5a82ac5..1a85a6c 100644 --- a/src/hardware/Motor/Motor.cpp +++ b/src/hardware/Motor/Motor.cpp @@ -178,7 +178,9 @@ Temperature Motor::getTemperature() const { // 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 1b321c0..9e80b35 100644 --- a/src/hardware/Motor/MotorGroup.cpp +++ b/src/hardware/Motor/MotorGroup.cpp @@ -147,7 +147,9 @@ std::vector MotorGroup::getTemperatures() { // 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; }