Skip to content

Commit

Permalink
Make ValveControlStrategy independent of motor controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
lptr committed Oct 27, 2024
1 parent 887dd3e commit 7bfabb4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion main/peripherals/flow_control/FlowControl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class FlowControlFactory
PwmMotorDriver& targetMotor = findMotor(valveConfig.motor.get());
ValveControlStrategy* strategy;
try {
strategy = createValveControlStrategy(
strategy = createMotorValveControlStrategy(
targetMotor,
valveConfig.strategy.get(),
valveConfig.switchDuration.get(),
Expand Down
2 changes: 1 addition & 1 deletion main/peripherals/valve/Valve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ValveFactory
PwmMotorDriver& targetMotor = findMotor(deviceConfig.motor.get());
ValveControlStrategy* strategy;
try {
strategy = createValveControlStrategy(
strategy = createMotorValveControlStrategy(
targetMotor,
deviceConfig.strategy.get(),
deviceConfig.switchDuration.get(),
Expand Down
43 changes: 26 additions & 17 deletions main/peripherals/valve/ValveComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,23 @@ class ValveControlStrategy {
virtual String describe() const = 0;
};

class HoldingValveControlStrategy
class MotorValveControlStrategy
: public ValveControlStrategy {
public:
MotorValveControlStrategy(PwmMotorDriver& controller)
: controller(controller) {
}

protected:
PwmMotorDriver& controller;
};

class HoldingMotorValveControlStrategy
: public MotorValveControlStrategy {

public:
HoldingValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double holdDuty)
: controller(controller)
HoldingMotorValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double holdDuty)
: MotorValveControlStrategy(controller)
, switchDuration(switchDuration)
, holdDuty(holdDuty) {
}
Expand All @@ -67,7 +78,6 @@ class HoldingValveControlStrategy
}
}

PwmMotorDriver& controller;
const milliseconds switchDuration;
const double holdDuty;

Expand All @@ -79,11 +89,11 @@ class HoldingValveControlStrategy
}
};

class NormallyClosedValveControlStrategy
: public HoldingValveControlStrategy {
class NormallyClosedMotorValveControlStrategy
: public HoldingMotorValveControlStrategy {
public:
NormallyClosedValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double holdDuty)
: HoldingValveControlStrategy(controller, switchDuration, holdDuty) {
NormallyClosedMotorValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double holdDuty)
: HoldingMotorValveControlStrategy(controller, switchDuration, holdDuty) {
}

void open() override {
Expand All @@ -103,11 +113,11 @@ class NormallyClosedValveControlStrategy
}
};

class NormallyOpenValveControlStrategy
: public HoldingValveControlStrategy {
class NormallyOpenMotorValveControlStrategy
: public HoldingMotorValveControlStrategy {
public:
NormallyOpenValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double holdDuty)
: HoldingValveControlStrategy(controller, switchDuration, holdDuty) {
NormallyOpenMotorValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double holdDuty)
: HoldingMotorValveControlStrategy(controller, switchDuration, holdDuty) {
}

void open() override {
Expand All @@ -127,11 +137,11 @@ class NormallyOpenValveControlStrategy
}
};

class LatchingValveControlStrategy
: public ValveControlStrategy {
class LatchingMotorValveControlStrategy
: public MotorValveControlStrategy {
public:
LatchingValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double switchDuty = 1.0)
: controller(controller)
LatchingMotorValveControlStrategy(PwmMotorDriver& controller, milliseconds switchDuration, double switchDuty = 1.0)
: MotorValveControlStrategy(controller)
, switchDuration(switchDuration)
, switchDuty(switchDuty) {
}
Expand All @@ -157,7 +167,6 @@ class LatchingValveControlStrategy
}

private:
PwmMotorDriver& controller;
const milliseconds switchDuration;
const double switchDuty;
};
Expand Down
8 changes: 4 additions & 4 deletions main/peripherals/valve/ValveConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ enum class ValveControlStrategyType {
Latching
};

static ValveControlStrategy* createValveControlStrategy(PwmMotorDriver& motor, ValveControlStrategyType strategy, milliseconds switchDuration, double holdDuty) {
static MotorValveControlStrategy* createMotorValveControlStrategy(PwmMotorDriver& motor, ValveControlStrategyType strategy, milliseconds switchDuration, double holdDuty) {
switch (strategy) {
case ValveControlStrategyType::NormallyOpen:
return new NormallyOpenValveControlStrategy(motor, switchDuration, holdDuty);
return new NormallyOpenMotorValveControlStrategy(motor, switchDuration, holdDuty);
case ValveControlStrategyType::NormallyClosed:
return new NormallyClosedValveControlStrategy(motor, switchDuration, holdDuty);
return new NormallyClosedMotorValveControlStrategy(motor, switchDuration, holdDuty);
case ValveControlStrategyType::Latching:
return new LatchingValveControlStrategy(motor, switchDuration, holdDuty);
return new LatchingMotorValveControlStrategy(motor, switchDuration, holdDuty);
default:
throw std::runtime_error("Unknown strategy");
}
Expand Down

0 comments on commit 7bfabb4

Please sign in to comment.