Question about the I term in the PID

Using I with the PID causes the error to sum and then change the output,
when does this sum resets?
Is a new set point enough to reset it?

I want to know this in order to use the same PID loop to set the system to several set points sequentially.

According to conventional control theory, you shouldn’t have to because, in general, you move, say, an arm up (which causes a positive integral term), then you’ll move it down (offsetting back to 0). However, when dealing with real systems, a phenomenon known as integral windup occurs ( It’s most noticeable when your motors go into saturation and just accumulate integral error. Theoretical motors don’t have any saturation point, but real motors…well, you can feed in more gain, but once they’re in saturation, they’re not going any faster. In the wiki link, they outline a few ways to prevent the phenomenon. It’s generally system dependent, so try them out and see what works best for your system.

By the way, I’m not the author of the code for the PID, and because it is written using lots of scalars, and contains many features, I also find it hard to read. But here is what it looks like to me.

On the initial call and when the reset input is true, the integral accumulation is zeroed.

If the I term is zero, the accumulation is forced to zero.

If the P, I, or D terms are changed, the accumulator isn’t zeroed, but it is adjusted based on the error term, the P coefficient and the derivative term. I believe this is the bumpless feature that allows you to tune the coefficients without causing the controller to oscillate as badly.

Finally, when the controller is saturated, when the output value is at the max or min value that you indicated were acceptable, the integral accumulation is adjusted by the proportional term to avoid windup.

The best way to observe the effect of these features is to open one of the plant examples that show the PID in use. You can force the situations above and that will give you something to debug or play with. You can also read about it here

Greg McKaskle