diff --git a/wombat/src/main/cpp/utils/VoltageController.cpp b/wombat/src/main/cpp/utils/VoltageController.cpp index 43bac3a9..b71af805 100644 --- a/wombat/src/main/cpp/utils/VoltageController.cpp +++ b/wombat/src/main/cpp/utils/VoltageController.cpp @@ -10,24 +10,25 @@ units::volt_t VoltageController::GetEstimatedRealVoltage() const { return units::math::min(units::math::max(-vb, GetVoltage()), vb); } -MotorVoltageController::MotorVoltageController(frc::MotorController *MotorController) : _MotorController(MotorController) {} +VoltageController::VoltageController(frc::MotorController *MotorController) : _MotorController(MotorController) +{} -void MotorVoltageController::SetVoltage(units::volt_t voltage) { +void VoltageController::SetVoltage(units::volt_t voltage) { _MotorController->Set(voltage / GetBusVoltage()); } -units::volt_t MotorVoltageController::GetVoltage() const { +units::volt_t VoltageController::GetVoltage() const { return _MotorController->Get() * GetBusVoltage(); } -units::volt_t MotorVoltageController::GetBusVoltage() const { +units::volt_t VoltageController::GetBusVoltage() const { return frc::RobotController::GetInputVoltage() * 1_V; } -void MotorVoltageController::SetInverted(bool invert) { +void VoltageController::SetInverted(bool invert) { _MotorController->SetInverted(invert); } -bool MotorVoltageController::GetInverted() const { +bool VoltageController::GetInverted() const { return frc::RobotController::GetInputVoltage(); } diff --git a/wombat/src/main/include/utils/VoltageController.h b/wombat/src/main/include/utils/VoltageController.h index dcdef728..bad03620 100644 --- a/wombat/src/main/include/utils/VoltageController.h +++ b/wombat/src/main/include/utils/VoltageController.h @@ -13,60 +13,46 @@ namespace wom { */ class VoltageController { public: + VoltageController(frc::MotorController *MotorController); /** * Set the voltage of the output. */ - virtual void SetVoltage(units::volt_t voltage) = 0; + void SetVoltage(units::volt_t voltage); /** * Get the voltage of the output. */ - virtual units::volt_t GetVoltage() const = 0; + units::volt_t GetVoltage() const; /** * Set the output as inverted. */ - virtual void SetInverted(bool invert) = 0; + void SetInverted(bool invert); /** * Get whether the output is inverted */ - virtual bool GetInverted() const = 0; + bool GetInverted() const; /** - * Get the estimated real voltage of the output, based on the controller voltage. + * Get the estimated real voltage of the output, based on the controller voltage. */ units::volt_t GetEstimatedRealVoltage() const; - }; - - /** - * The MotorVoltageController is an adapter for an frc::MotorController to - * a VoltageController. - */ - class MotorVoltageController : public VoltageController { - public: - MotorVoltageController(frc::MotorController *MotorController); - - void SetVoltage(units::volt_t voltage) override; - units::volt_t GetVoltage() const override; - - void SetInverted(bool invert) override; - bool GetInverted() const override; units::volt_t GetBusVoltage() const; - /** - * Create a MotorVoltageController with a given frc::MotorController - * subclass. Please note that this creates an unsafe pointer (will never dealloc) - */ - template - static MotorVoltageController Of(Args& ...args) { - T *t = new T(args...); // Be warned, does not deallocate! - return MotorVoltageController{t}; - } - - template - static MotorVoltageController Group(Args& ...args) { - return Of(args...); - } + /** + * Create a MotorVoltageController with a given frc::MotorController + * subclass. Please note that this creates an unsafe pointer (will never dealloc) + */ + template + static VoltageController Of(Args& ...args) { + T *t = new T(args...); // Be warned, does not deallocate! + return VoltageController{t}; + } + + template + static VoltageController Group(Args& ...args) { + return Of(args...); + } private: frc::MotorController *_MotorController;