Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wombat] move motorvoltagecontroller into voltage controller. #39

Merged
merged 4 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions wombat/src/main/cpp/utils/VoltageController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
54 changes: 20 additions & 34 deletions wombat/src/main/include/utils/VoltageController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T, typename ...Args>
static MotorVoltageController Of(Args& ...args) {
T *t = new T(args...); // Be warned, does not deallocate!
return MotorVoltageController{t};
}

template<typename ...Args>
static MotorVoltageController Group(Args& ...args) {
return Of<frc::MotorControllerGroup>(args...);
}
/**
* Create a MotorVoltageController with a given frc::MotorController
* subclass. Please note that this creates an unsafe pointer (will never dealloc)
*/
template<typename T, typename ...Args>
static VoltageController Of(Args& ...args) {
T *t = new T(args...); // Be warned, does not deallocate!
return VoltageController{t};
}

template<typename ...Args>
static VoltageController Group(Args& ...args) {
return Of<frc::MotorControllerGroup>(args...);
}

private:
frc::MotorController *_MotorController;
Expand Down