News for hackers. Stuff that matters.
Re:PID Controllers in Unity3D by Espressosaurus on Tuesday January 16, 2024 @11:59AM (#39015575)
The interesting thing is that if you can reframe the problem correctly, a PID controller will probably be involved in the closed loop solution. And most of the time you don't even need the derivative term.

The last few systems I've worked on professionally have been nested PI controllers with some filters on the front or back of them. Just needed the correct framing for the problem (the hard part) and it becomes straightforward to solve.

Re:PID Controllers in Unity3D by ncallaway on Tuesday January 16, 2024 @01:30PM (#39016786)
Maybe I'm misunderstanding something, but wouldn't you still want/need a D term unless you have a system with a nearly instant response?

I'd think that even if you stop applying a delta the second you hit the set-point, if you've built up non-trivial inertia, then you'll overshoot the target fairly significantly?

Re:PID Controllers in Unity3D by Espressosaurus on Tuesday January 16, 2024 @03:43PM (#39018864)
It's all a tradeoff of how system response vs. stability and how much overshoot is tolerable.

For the domains I've worked in, with physical components, system response isn't instantaneous, but some level of overshoot is tolerable as long as the system rapidly converges and (this is the important part) cannot end up in a positive feedback scenario. The derivative term tends to amplify noise, which is never what you want.

A little anti-windup, some generous limits around your max extents, and perhaps a gear-shift to switch bandwidths when you approach steady-state, and it's surprising how many problems can be solved with a filter and a PI controller for the closed-loop component of the system. Maybe the actuator is walking you up and down a complicated model space, maybe you've got multiple PIs driving multiple models...but there's a good chance a PI will do a decent job somewhere in the solution.

Use a PID if you want to make more work for yourself.

Specifics will depend on your exact system.

Re:PID Controllers in Unity3D by diracs_stache on Tuesday January 16, 2024 @04:15PM (#39019234)
Control theory doesn't come up much in what I do but as a practitioner are Root Locus ever utilized? I've been unpleasantly surprised to see that exact positive feedback instance existing in places you wouldn't want (things wobbling above earth after a control input). Poles and Zeros felt like a lot of magic until a foray into complex analysis ripped that band aid off ;)
Re:PID Controllers in Unity3D by Espressosaurus on Tuesday January 16, 2024 @04:42PM (#39019550)
Oh yeah, it comes up. It's a way to check for stability and visualize the system. Phase and gain margin have come up more frequently for me, but a lot is going to depend on what you find the most natural way of attacking the problem to be.
Re:PID Controllers in Unity3D by syntaxing on Tuesday January 16, 2024 @01:54PM (#39017221)
It’s actually a pretty common practice in the industry and academic. You can change your system block diagram to have the measured value as some sort of rate of change rather than the value itself (this is a non trivial exercise). In return, your system is more stable and you can get rid of the D constant since it’s another value you need to tune and sometimes causes instability in a control sense. It’s a pretty popular technique in high safety applications like aerospace.
Re:PID Controllers in Unity3D by icegreentea2 on Tuesday January 16, 2024 @01:50PM (#39017142)
D term is complicated and it really depends on the situation. You can usually get away without a D term and have acceptable overshoot as long as you have the right anti-integral windup setup, and your I vs P ratio isn't too high.
Re:PID Controllers in Unity3D by reaperman on Tuesday January 16, 2024 @04:51PM (#39019638)
Everyone will say "depends on the system" but generally the D term is not only not needed, but typically considered counter-productive or even against best practices. PI-loops tend to be much more stable than PID-loops and far easier to successfully tune for an acceptable response. You do get overshoot with a decently tuned PI-loop, but it's not enough to cause problems. A bit of overshoot doesn't tend to hurt anything.

Of course, a "perfectly" tuned PID loop will be "better" - more efficient, faster to reach setpoint, and minimize overshoot. But the effort/engineering time/operation time involved in tuning it, combined with the risks presented by a subtly poorly tuned loop that goes haywire one day when the system paradigm (characteristic) changes...just isn't worth it.

Obviously there are times when you really do need a D term, but I can confidently say that they're not commonly used in HVAC or petrochemical plants. I'm sure there are other domains where the D term is needed, but in my time as a controls engineer I didn't run across them.

Re:PID Controllers in Unity3D by GabeIsko on Tuesday January 16, 2024 @05:15PM (#39019912)
Especially in a video game context, where you can always go in and change how the system works.

A really good way to tell is to consider the relationship between your input and output. PID get's thrown around all the time because a lot of the time you are talking about controlling an accerlation (gas pedal, throttle) to effect a position, so you theoretically need a PID to stand in for a 2nd order differential equation since position and acceleration are two derivatives apart with respect to time. But as you pointed out, you usually can generalize your input and not worry about the D term.

In the video game I'm making, I don't really worry about derivative control, but PID control is mostly there to give the illusion that someone is driving a vehicle rather than it be controlled perfectly by a computer program. I don't want to model out how "skilled" the driver is - all I have to do to give that impression is just give the vehicle better handling.

Re:PID Controllers in Unity3D by polishdude20 on Tuesday January 16, 2024 @10:19PM (#39022831)
Yep, D terms are needed in systems where there isn't a natural dampening or reversing force that will naturally bring the value away from what your output tries to do.

With a heater,once you get to zero error, any overshoot will reduce back the opposite way because heat is always lost.

Re:PID Controllers in Unity3D by Animats on Tuesday January 16, 2024 @03:04PM (#39018324)
The D term is complicated.

Where you do you get the derivative? If you have to differentiate the input, and there is noise, the raw derivative will have huge variations. Then you need a low pass filter before the differentiator. This introduces lag. So you now have both D gain and filter frequency to tune.

See any classical control theory book for the theory on this.

Re:PID Controllers in Unity3D by reaperman on Tuesday January 16, 2024 @04:42PM (#39019543)
Even when tuning PID loops for chemical plants as a controls engineer, myself and my colleagues (across multiple companies) generally just set the D term to zero. If the D term (derivative) was needed, tuning that one loop would often be assigned a whole formal project by itself. When I hear people say "PID loop" I almost always subconsciously translate it to hear "PI loop" in my head unless there's evidence that it's a truly complex system.
Re:PID Controllers in Unity3D by polishdude20 on Tuesday January 16, 2024 @10:17PM (#39022820)
I've had to use the D term recently in a self guided model rocket project.

When the rocket had an angle error it needed to point it's thrust to rotate itself back to 0. There is no built in stopping force that stops the rocket rotating when the thrust is not angled. So a D term was needed in order to take into account how fast the rotation was happening. When it was rotating to 0 degrees of error, it needed that d term to not overshoot. With the d term, the thrust would swing in the opposite direction to prevent it overshooting.