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

Fixed bug in pidBlock

parent 9bfa581e
No related branches found
No related tags found
1 merge request!2Dev preferences
......@@ -73,15 +73,15 @@ public class PidBlock extends TranslatorBlock
+ " long error = setpoint - input; // get error\n"
+ " out = kp * error; //P output\n\n";
if(integrative) {
functionCode +=" cumError = cumError + error; // compute integral\n";
functionCode +=" cumError = cumError + (error * intervalSecond); // compute integral\n";
if(limited) {
functionCode += " cumError = constrain(cumError, limitLow * 100.0, limitHigh * 100.0); //limit integral against windup\n";
}
functionCode += " out = out + (ki * intervalSecond) * cumError; //I output\n\n";
functionCode += " out = out + (ki * cumError); //I output\n\n";
}
if(derivative) {
functionCode +=" long rateError = error - lastError; // compute derivative\n"
+ " out = out - (kd / intervalSecond) * rateError; //D output\n\n";
functionCode +=" long rateError = (error - lastError) / intervalSecond; // compute derivative\n"
+ " out = out + kd * rateError; //D output\n\n";
}
if(limited) {
functionCode +=" out = constrain(out, limitLow, limitHigh); //limit output\n\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