Skip to content

Commit

Permalink
Merge pull request #86 from kivancsikert/mk4/fix-motor-driver
Browse files Browse the repository at this point in the history
Fix non-latching valve drivers
  • Loading branch information
lptr authored Feb 3, 2024
2 parents 088258c + 3bd2228 commit 0e7c36d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions src/kernel/drivers/Drv8801Driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class Drv8801Driver
void drive(MotorPhase phase, double duty = 1) override {
if (duty == 0) {
Log.traceln("Stopping");
sleep();
digitalWrite(enablePin, LOW);
return;
}
wakeUp();
digitalWrite(enablePin, HIGH);

int direction = (phase == MotorPhase::FORWARD ? 1 : -1);
Expand Down
13 changes: 9 additions & 4 deletions src/peripherals/valve/ValveComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,26 @@ class HoldingValveControlStrategy
void driveAndHold(PwmMotorDriver& controller, ValveState targetState) {
switch (targetState) {
case ValveState::OPEN:
controller.drive(MotorPhase::FORWARD, holdDuty);
driveAndHold(controller, MotorPhase::FORWARD);
break;
case ValveState::CLOSED:
controller.drive(MotorPhase::REVERSE, holdDuty);
driveAndHold(controller, MotorPhase::REVERSE);
break;
default:
// Ignore
break;
}
delay(switchDuration.count());
controller.stop();
}

const milliseconds switchDuration;
const double holdDuty;

private:
void driveAndHold(PwmMotorDriver& controller, MotorPhase phase) {
controller.drive(phase, 1.0);
delay(switchDuration.count());
controller.drive(phase, holdDuty);
}
};

class NormallyClosedValveControlStrategy
Expand Down

0 comments on commit 0e7c36d

Please sign in to comment.