Skip to content

Commit

Permalink
update PID logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Jul 2, 2024
1 parent 319e937 commit 3d70242
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/downloads/solar_diverter_v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const CONFIG = {
// PID Proportional Gain
KP: 0.8,
// PID Integral Gain
KI: 0,
KI: 0.01,
// PID Derivative Gain
KD: 0.8
KD: 0.8,
// PID Output Minimum Clamp (W)
ITERM_MIN: -10,
},
DIMMERS: {
"192.168.125.93": {
Expand Down Expand Up @@ -111,7 +113,7 @@ function calculatePID(input) {
PID.output = 0;
} else {
PID.pTerm = error * CONFIG.PID.KP;
PID.iTerm = Math.max(PID.iTerm + error * CONFIG.PID.KI, 0);
PID.iTerm = Math.max(PID.iTerm + error * CONFIG.PID.KI, CONFIG.PID.ITERM_MIN);
PID.dTerm = (error - PID.error) * CONFIG.PID.KD;
}
PID.output = PID.pTerm + PID.iTerm + PID.dTerm;
Expand Down

0 comments on commit 3d70242

Please sign in to comment.