PID integral implementation

Testing and development of Megasquirt 3

Moderators: jsmcortina, muythaibxr

Post Reply
Reverant
Super MS/Extra'er
Posts: 1233
Joined: Sat Apr 15, 2006 12:39 am
Location: Athens, Greece

PID integral implementation

Post by Reverant »

The current code reads:

Code: Select all

Ki = ((((long) error * looptime) / (long)pid_divider) * (long)set_Ki);
The problem with this implementation is that it's essentially a P term (as I understand it, and it certainly acts that way), whereas an I would be more like:

Code: Select all

overall_error += error;

if (overall_error > integral_limit)
    overall_error = integral_limit;

Ki = overall_error * set_Ki;
Thoughts?
The man behind MS Labs
2005 Audi A3 2.0L TFSI DSG AWD - Extreme MS3
2002 Mazda Miata 1.8 6sp - Enhanced MS3 1.4.0, sequential injection, sequential ignition, big turbo, lots of boost
muythaibxr
Site Admin
Posts: 8230
Joined: Thu Oct 14, 2004 12:48 pm

PID integral implementation

Post by muythaibxr »

Incorrect. I have answered this question over and over again. It is done this way because the whole PID equation is being summed with the current output every time through the loop, effectively integrating the whole thing. So you have to take the derivative of the whole thing to make it work.

It does not act like a P term in that over time if there is error it continues to correct.

Depending on what code you look at we use type B or C.

http://bestune.50megs.com/typeABC.htm
Megasquirt is not for use on pollution controlled vehicles. Any advice I give is for off road use only.
Post Reply