I haven't done PID for a looong time but the best method for tuning PID loops is to look at the frequency response, somewhat along these lines: <a href="https://eng.libretexts.org/Bookshelves/Industrial_and_Systems_Engineering/Book%3A_Chemical_Process_Dynamics_and_Controls_(Woolf)/09%3A_Proportional-Integral-Derivative_(PID)_Control/9.04%3A_PID_tuning_via_Frequency_Responses_with_Bode_Plots" rel="nofollow">https://eng.libretexts.org/Bookshelves/Industrial_and_System...</a><p>This is much much better than the rules of thumb of increasing the proportional gain until the system becomes unstable etc. etc. You can tell what your gain and phase margins actually are which is difficult otherwise so you can push the correct parameters to the limit while maintaining margin.<p>There are also other approaches that rely on modelling the system and calculating the parameters based on the model... That can work but tends to be iffy for real world systems in my experience...
The old ship steering analogy:<p>P: is steering hard because you are off course.<p>I: is steering into the wind to counteract wind drift and into the current to counteract opposing currents as you move toward course.<p>D: is reducing steering input as you close on the intended course
Please also see "PID without a PHD" (I am not affiliated with these people):<p><a href="https://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf" rel="nofollow">https://wescottdesign.com/articles/pid/pidWithoutAPhd.pdf</a>
I would be interested to hear people here smarter than me explain why PID is better than some simple explicit control logic made by a person.<p>They work well, but you have to tune it properly and don't have much flexibility to add in prior knowledge of non linearities etc which as a human we know about and know the complexities of.<p>I've found similar things with Kalman filters. Everyone is always keen to go PID, Kalman etc by default, but I've found getting them to behave correctly in complex systems can take ages and maybe never quite get there. Throw them out and do a few really simple explicit logic control steps like you would if you as a human were controlling it and bingo everything works great, the code is understandable by even non programmers as it's explicit and easy to deal with.<p>Don't get me wrong, I use all of the above, but I do find that PID and Kalman etc end up in places where a few if statements end up being just as good.<p>(Seriously not trying to flamebait here... Just never seen this discussed before)
In case anyone else needs it, <a href="https://en.m.wikipedia.org/wiki/PID_controller" rel="nofollow">https://en.m.wikipedia.org/wiki/PID_controller</a>
Control systems (analog) was one of the courses I did poorly in university. And of course, my first job after school was working on (digital) control systems! It turns out digital is a lot easier than analog (to me, at least).<p>A couple things I discovered:<p>- When changing setpoints for your controller it helps to slowly ramp them to prevent disturbing the system. Calculate a (end-start)/steps and apply the delta every loop cycle.<p>- For integral wind-up, I found it more convenient to re-calculate the integral term when hitting a control limit.