Skip to content
Snippets Groups Projects
Commit 52bf6d10 authored by Anian Bühler's avatar Anian Bühler
Browse files

added constrain to pid integral

parent 3926e841
No related branches found
No related tags found
1 merge request!1dev_prefereences to master
...@@ -59,8 +59,11 @@ public class PidBlock extends TranslatorBlock ...@@ -59,8 +59,11 @@ public class PidBlock extends TranslatorBlock
+ " long error = setpoint - input; // get error\n" + " long error = setpoint - input; // get error\n"
+ " out = kp * error; //P output\n\n"; + " out = kp * error; //P output\n\n";
if(integrative) { if(integrative) {
functionCode +=" long cumError = cumError + error * elapsedTime; // compute integral\n" functionCode +=" long cumError = cumError + error * elapsedTime; // compute integral\n";
+ " out = out + ki * cumError; //I output\n\n"; if(limited) {
functionCode += " cumError = constrain(cumError, limitLow, limitHigh); //limit integral against windup";
}
functionCode += " out = out + ki * cumError; //I output\n\n";
} }
if(derivative) { if(derivative) {
functionCode +=" long rateError = (error - lastError) / elapsedTime; // compute derivative\n" functionCode +=" long rateError = (error - lastError) / elapsedTime; // compute derivative\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment