Simple example: You want to control torque with a PID to reach a target angular velocity. What if the player suddenly negates the target angular velocity (by going from left arrow key press to right arrow key press for example).
How do you handle the I and D term then?
What if the player can also use a gamepad and go from left to right gradually?
The fundamental problem is that the error accumulates while you try to reach the target. But then the target suddenly changes. Do you just drop the previous error? Do you create an upper bound on the error? Or something else? This is the question no PID post ever answers.
I don't say, that this is impossible, but just that PID's in this context are harder to use than they first appear.
Yes drop the “previous error” by setting the integral to zero when the setpoint changes such that the sign of the error changes.
If the derivative is on the error when the setpoint is changed all of the sudden the error is increasing instead of decreasing so it works as desired.
There are many books on control systems that cover different forms of the PID algorithm and what applications they suit.
I prefer the velocity form or double derivative form for the simplicity of managing the integrator and applying real world limits on maximum and minimum outputs and rate of change of output. I basically never need such a fast response that it is worth bothering with D.
A mathematics professor solved the differential equations governing my processes so now I can calculate the exact correct gains for critical damping and simulate the response for different limitations such as input sensor resolution and measurement delays. It is wonderful.
How do you handle the I and D term then?
What if the player can also use a gamepad and go from left to right gradually?
The fundamental problem is that the error accumulates while you try to reach the target. But then the target suddenly changes. Do you just drop the previous error? Do you create an upper bound on the error? Or something else? This is the question no PID post ever answers.
I don't say, that this is impossible, but just that PID's in this context are harder to use than they first appear.