It's just a game!
It's just a game!
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.
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.
You recalculate the D term every iteration, so it doesn’t matter?
The ugly truth about the I term is that in practice people very often leave it at zero. We sometimes call these controllers PD controllers.
Especialy in a game where you don’t have sticky actuators and miscalibrated sensors this is usually more than enough for hapiness.
PIDs sound cool though. I should try em.