Live data from Hacker News

PID Controllers in Unity3D (2021)

vazgriz.com

21–30 of 46 posts

Re: PID Controllers in Unity3D (2021)

#21

One method that solves 99% of your control problems is the Ziegler-Nichols method [1]. It's a shame it's not taught more often. No need to model your system, just increase the P gain until the system oscillates naturally. Measure the oscillation period, and then refer to the tables at [1] to choose the P, I, D gains depending on how you like your system response to look like. [1]: https://en.wikipedia.org/wiki/Ziegle…

You can actually use that method for the remainder constants too. I built an analog motor controller for my control systems lab and the constants were just pots. We would increase the resistance until instability and back off a little. Rinse and repeated for the remainder two pots.

Re: PID Controllers in Unity3D (2021)

#22

One method that solves 99% of your control problems is the Ziegler-Nichols method [1]. It's a shame it's not taught more often. No need to model your system, just increase the P gain until the system oscillates naturally. Measure the oscillation period, and then refer to the tables at [1] to choose the P, I, D gains depending on how you like your system response to look like. [1]: https://en.wikipedia.org/wiki/Ziegle…

ZN tuning is taught in engineering schools in the US. I even had a lab on it. As far as I remember it was kind of painful to work through and didn’t yield that much better results than hand tuning.

Ah I remembered something else… it needs to find the max Kp which in some cases is just not possible (or wise) to attempt with a real world plant.

Re: PID Controllers in Unity3D (2021)

#24

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.

Re: PID Controllers in Unity3D (2021)

#25

I once used a $25 off-the-shelf PID temp controller that came with a type K thermocouple and integrated 12v control line to build an air intake regulator for my meat smoker. I couldn't believe the outcome - 3 hours of fuel turned into 11 hours, and the (logged) temperature stayed between 118.4 and 122 degrees celsius for 10 hours of that. This was outdoors, with all the variance that comes with it, and all I did was…

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.

Re: PID Controllers in Unity3D (2021)

#26

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?

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

#27

One method that solves 99% of your control problems is the Ziegler-Nichols method [1]. It's a shame it's not taught more often. No need to model your system, just increase the P gain until the system oscillates naturally. Measure the oscillation period, and then refer to the tables at [1] to choose the P, I, D gains depending on how you like your system response to look like. [1]: https://en.wikipedia.org/wiki/Ziegle…

On the contrary, ZN is taught is almost every undergrad control course — and not actually used industry. It’s a classic textbook method to demonstrate the concept in simulations but it has many downsides in practice (pushing the system to its boundaries is not a good idea).

Most professionals tune with starting values obtained using model inversion (IMC, direct synthesis) and then hand tune. There is also software like Loop Pro that analyzes the data and proposes tunings.

Re: PID Controllers in Unity3D (2021)

#28

There was a website where you entered little snippets of code IIRC to adjust how a cube moves with friction and then the examples move on to a car moving up a ramp. It was a very sneaky and intuitive way to learn about PID controllers. I think that was posted here on HN but I can't find the link...

Here it is http://janismac.github.io/ControlChallenges/ And discussion https://news.ycombinator.com/item?id=37637006 I dont know how I messed up my first search.

Thank you for sharing, those are awesome exercises.

Re: PID Controllers in Unity3D (2021)

#29

One method that solves 99% of your control problems is the Ziegler-Nichols method [1]. It's a shame it's not taught more often. No need to model your system, just increase the P gain until the system oscillates naturally. Measure the oscillation period, and then refer to the tables at [1] to choose the P, I, D gains depending on how you like your system response to look like. [1]: https://en.wikipedia.org/wiki/Ziegle…

A lot of gaming doesn't really have the luxury of waiting for the oscillation to kick in, in order to then balance the system, though. By the time there's oscillation, it's already too late to fix, you need to preempt the oscillation.

Re: PID Controllers in Unity3D (2021)

#30
post #5

I wrote a super basic 2 axis "autopilot" with Python for X-Plane. The concepts are super simple. Getting the controller tuned properly is not. For a surprisingly large number cases, setting a P value in the 1-3 range and a I value as P/10 works extremely well. I now write Python for my day job. This code was written before that and now that I look at it, it is quite ugly: https://austinsnerdythings.com/2021/10/19/cod…

Writing your PID controller is a few minutes work. Tuning your PID controller is a day job. Most people just don't actually make it their day job =D
Post reply on HN