Live data from Hacker News

PID Controllers in Unity3D (2021)

vazgriz.com

31–40 of 46 posts

Re: PID Controllers in Unity3D (2021)

#31

Earlier quoted context omitted.

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?

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 wa…

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 (2021)

#32
Control theory is also used by databases (probably not as often as it should be). It's great for "self tuning" [1], for example tuning the various cache sizes a database has to maximize throughput under changing workload conditions. Its definitely worth spending the time to understand PID controllers if your an engineer working on databases.

[1] https://www.vldb.org/conf/2006/p1081-storm.pdf

Re: PID Controllers in Unity3D (2021)

#33
post #25

Earlier quoted context omitted.

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 stra…

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.

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 (2021)

#34

Earlier quoted context omitted.

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 wa…

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 ;)

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 (2021)

#35

Control theory is also used by databases (probably not as often as it should be). It's great for "self tuning" [1], for example tuning the various cache sizes a database has to maximize throughput under changing workload conditions. Its definitely worth spending the time to understand PID controllers if your an engineer working on databases. [1] https://www.vldb.org/conf/2006/p1081-storm.pdf

It's worth looking at any time you're doing dynamic alterations to the system.

There's a lot of terrible things people do in ignorance of control theory while trying to come up with solutions in that space.

Re: PID Controllers in Unity3D (2021)

#36

Earlier quoted context omitted.

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 stra…

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?

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 (2021)

#39

Earlier quoted context omitted.

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?

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 anythi…

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 (2021)

#40

My favorite use of a PID controller in Unity was to act as a camera operator for a VR football game. We used cameras for the screen-display (we could either show you the VR player's perspective, or one of several cameras), and for the jumbotron in the stadium. This ended up being really cool for downfield throws. When you bombed the ball 45 yards to a receiver, it could be a little hard to see the action. It was real…

Wouldn't it be better to model imperfections separately rather than rely on PID oscillations? I can see how this can easily fail and cause some dramatic and unnatural camera movements.

Well, yes and no. PID is very simple to integrate in a state loop, so it is simple to implement, and gives the illusion of imperfect tracking very quickly. So I imagine this implementation worked rather well. Because the imperfectness isn't random noise, but it is a model of someone trying to aim something, and they do it imperfectly.

Generally though, It would be pretty trivial to add noise for this stuff. You would probably want some noise on the orientation if you wanted to model more of a camera shake. Perlin noise is my go to if I want to introduce randomness to positions really quickly.

Post reply on HN