Skip to content

Commit 5bc8743

Browse files
committed
Implement motor speed control
1 parent 489c4b4 commit 5bc8743

3 files changed

Lines changed: 16 additions & 8 deletions

File tree

Parameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const float valveSpeed = 0.01; // disabled
77

88
// motor control
99
const float openingTolerance = 0.1; // disabled
10+
const int motorSpeed = 100; // value in (0,1000]
1011

1112
const float minOpening = 0.05; // disabled
1213
const float maxOpeningAtPsiDelta = 1.5; // disabled

PressureControlSoftware.ino

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ void loop() {
2929
float offPsi = targetPsi - measuredPsi;
3030

3131
float valveOpening = Valve::getOpening();
32-
33-
if (abs(offPsi) > toleratedPsiDelta) {
34-
Valve::move(offPsi < 0); // open or close depending on inequality
35-
}
36-
else {
37-
Valve::stop();
38-
}
3932

4033
#ifndef SERIAL_DEBUG
4134
Display::showPressureSelection(measuredPsi, targetPsi);
@@ -48,5 +41,18 @@ void loop() {
4841
Serial.print(offPsi, 2);
4942
Serial.println(" psi");
5043
#endif
44+
45+
// motor movement
46+
// stop the motor depending on the motor speed
47+
if (currentMillis % 1000 > motorSpeed) {
48+
Valve::stop();
49+
continue;
50+
}
51+
if (abs(offPsi) > toleratedPsiDelta) {
52+
Valve::move(offPsi < 0); // open or close depending on inequality
53+
}
54+
else {
55+
Valve::stop();
56+
}
5157
}
5258
}

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ There are two `.ino` file, one for the Motor-Arduino, one for the Main-Arduino.
3333
Parameters can be adjusted in the header file `Parameters.h`. Not that instead of using a comma `,`, a dot `.` must be used for decimals. Lines are terminated with a semicolon `;`.
3434

3535
* **Tolerated PSI delta** `toleratedPsiDelta`, _akzeptierte Differenz von Soll- und Ist-PSI_, permitted value range [0,maxPSI]. After which difference in preassure levels (target vs. actual) a motion is being triggered. Note that there is no tolerance for motion because this is already caught by the motor positioning tolerance.
36+
* **Motor speed** `motorSpeed`, permitted values range (0,1000]. Defines how many milliseconds within one second the motor is permitted to move. When set to 1000, for instance, the motor may more all the time. When set to 200, it will move for (at most) 200 ms and will stay still for the next 800 ms.
3637
* [disabled] ~~**Valve adjustment speed** `valveSpeed`, _Geschwindigkeit der Ventilanpassung_, permitted value range [0, inf). How quickly the valve adjusts do divergence of actual and target pressure. Per 100 ms.~~
37-
Now controlled through the `MotorController.ino` script.
38+
Now controlled through the `MotorController.ino` script or `motorSpeed` variable.
3839
* [disabled] ~~**Opening tolerance** `openingTolerance`, _Motor-Positions-Toleranz_, permitted value range [0,1]. Controls which deviation of target motor position and actual motor position is still tolerated until a motion is being triggered. If the motor target is e.g. `0.2`, and the measured position is `0.25`, nothing will happen with an `openingTolerance` greater than or equal to `0.05`. The tolerance for motion is derived from this value through division by 2. So while adjusting the motor position, movement will not stop unless half of the `openingTolerance` is reached.~~
3940
* [disabled] ~~**Minimum valve opening**, `minOpening`, _geringste Öffnung des Ventils_, permitted value range [0,1]. Once a deviation from the target PSI is exceeding `toleratedPsiDelta` the valve will be opened to `minOpening` the least. May be set to `0` when in doubt.~~
4041
* [disabled] ~~**Max opening at PSI delta** `maxOpeningAtPsiDelta`, _Differenz von Soll- und Ist-PSI, bei der das Ventil komplett offen steht_, permitted value range [0,maxPSI). At what PSI difference the valve is openend entirely.~~

0 commit comments

Comments
 (0)