Live data from Hacker News

PID Controllers in Unity3D (2021)

vazgriz.com

11–20 of 46 posts

Re: PID Controllers in Unity3D (2021)

#11
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...

Re: PID Controllers in Unity3D (2021)

#12
15 years ago I had to create a display system written in Unity for cinemas, there was a capacitive PID controller I had to interface with - at the time it was impossible in Unity - it was a generic PID which just returned a stream of data, meaning there was no discrete driver for the device.

I ended up writing a program in another language - can't recall which - which interfaced with the controller and linked to unity c# through some obscure windows IPC (I think it was Pipes?).

Fun days in early Unity... nostalgia ;-)

Re: PID Controllers in Unity3D (2021)

#13

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.

Re: PID Controllers in Unity3D (2021)

#14

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…

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

#15
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 really natural to be able to glance up at the jumbotron in the stadium to get a closer view of what's happening downfield.

A small custom little PID controller worked really well for tracking the ball in flight, and giving a more natural "human operated" camera feel than perfectly tracking the ball.

We'd also randomly vary the terms within a set range for different virtual camera operators, so you'd get a little bit of variance in the tracking between different cameras and different play sessions.

Also a lot of pretty fun "bugs" from badly tuned PIDs.

Re: PID Controllers in Unity3D (2021)

#16

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?

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

#17

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

#18
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…

Does that rule-of-thumb assume specific units/value ranges for the input and output signals?

Yes it does, you have to manipulate the expression to make it adimensional. But this rule-of-thumb is only valid for systems whose response time is less than 500ms.

Re: PID Controllers in Unity3D (2021)

#19
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/Ziegler%E2%80%93Nichols_method

Re: PID Controllers in Unity3D (2021)

#20

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...

https://docs.wpilib.org/en/stable/docs/software/advanced-con...

Here's another. These pages interactively go over tuning pid controllers for position, velocity, and position with gravity compensation.

These docs are designed for high schoolers to learn about programming PID.

Post reply on HN