Skip to content

Commit

Permalink
Remove errorSum
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Jul 2, 2024
1 parent 0d5e859 commit 3d670b9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
1 change: 0 additions & 1 deletion docs/blog/2024-07-01_shelly_solar_diverter.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ http://192.168.125.92/script/1/status
"output": 0,
"error": 0,
"dError": 0,
"errorSum": 0,
"pTerm": 0,
"iTerm": 0,
"dTerm": 0
Expand Down
7 changes: 2 additions & 5 deletions docs/downloads/solar_diverter_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ let PID = {
error: 0,
// difference between current and last error
dError: 0,
// sum of all errors, clamped to minimum output
errorSum: 0,
// Proportional Term
pTerm: 0,
// Integral Term
Expand Down Expand Up @@ -105,9 +103,8 @@ function calculatePID(input) {
PID.input = input;
const error = CONFIG.PID.SET_POINT - PID.input;
PID.dError = input === CONFIG.PID.SET_POINT ? 0 : error - PID.error;
PID.errorSum = input === CONFIG.PID.SET_POINT ? 0 : Math.max(PID.errorSum + error, CONFIG.PID.OUTPUT_MIN);
PID.pTerm = error * CONFIG.PID.KP;
PID.iTerm = PID.errorSum * CONFIG.PID.KI;
PID.iTerm = input === CONFIG.PID.SET_POINT ? 0 : Math.max(PID.iTerm + error * CONFIG.PID.KI, CONFIG.PID.OUTPUT_MIN);
PID.dTerm = PID.dError * CONFIG.PID.KD;
PID.error = error;
PID.output = PID.pTerm + PID.iTerm + PID.dTerm;
Expand Down Expand Up @@ -161,7 +158,7 @@ function divert(voltage, gridPower) {
DIVERT.divertPower = Math.max(0, DIVERT.divertPower + correction);

if (CONFIG.DEBUG > 0)
print(scriptName, ":", "Grid:", voltage, "V", gridPower, "W. Correction:", correction, "W. Total Divert Power:", DIVERT.divertPower, "W");
print(scriptName, ":", "Grid:", voltage, "V,", gridPower, "W. Correction:", correction, "W. Total Divert Power:", DIVERT.divertPower, "W");

let remaining = DIVERT.divertPower;

Expand Down

0 comments on commit 3d670b9

Please sign in to comment.