Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proportional on measurement in PID::Compute seems to modify integral error #139

Open
yzhang2907 opened this issue Oct 19, 2023 · 0 comments

Comments

@yzhang2907
Copy link

I was reading the source code in PID_v1.cpp in conjunction with associated blog posts on Brett's site, and I spotted something interesting.

On line 71-72 of PID_v1.cpp, we have the following:

/*Add Proportional on Measurement, if P_ON_M is specified*/
if(!pOnE) outputSum-= kp * dInput;

To my understanding, kp * dInput is the P term when P_ON_M is specified.

However, if we had P_ON_E specified instead, the P term is added to the output instead of being accumulated into outputSum (lines 77-83):

/*Add Proportional on Error, if P_ON_E is specified*/
double output;
if(pOnE) output = kp * error;
else output = 0;

/*Compute Rest of PID Output*/
output += outputSum - kd * dInput;

In this case, I think kp * error is the P term when we have P_on_E specified.

Why is the P term treated differently when it is proportional on measurement? Why is it being accumulated into outputSum, which seems to be relevant only to the I term?

I am not sure if this is correct and something eclipsed my understanding, or if this is a mistake that should be fixed (if so, I can drop a pull request to fix it). If someone could enlighten me on this question, it would be much appreciated. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant