What's the best way to train PID controllers?

This is borderline non-gamedev but PIDs are commonly used in games so I thought I'd give it a shot.

I've got a few PID controllers in my game, used for things like steering and throttle control. I'm having trouble tuning them accurately. It never feels like I'm getting closer to the optimial solution, and it's very tempting to just leave them "good enough" with the odd oscillation or spike I can't get rid of.

The one controller that's driven me to this post with frustration produces minor oscillations for very very small error inputs. At large inputs it's ok but not very stable.

Does anyone have any tips or resources on how I can train these things more reliably?

-
I don't think controllers are stable. Are you married to the idea of using a PID controller? If not could you explain a specific case in more detail, I might be able to give a more stable solution. – Jonathan Fischoff Jul 29 '10 at 0:15
I'm looking for generic approaches to tuning PID controllers. Do you tune the P, I and D coefficients in a certain order? Do you have to form a closed system to tune or have you done it inside the game environment? – tenpn Jul 29 '10 at 12:01

There's actually a decent article in AI Game Programming Wisdom 2 by Euan Forrester regarding PID Controllers.

I'll just reiterate what he said about tuning the different coefficients:

1. Start with the proportional coefficient (P) - This has the largest effect on the behaviour of the controller. Set the other 2 coeffs to 0 and tune P until you get a rough desired effect.
2. Only vary one coefficient at a time - Get a decent feel for one coefficient to make sure it does approximately what it does while keeping the other 2 constant.
3. Tune the coefficients in real time - The benefits are a bit obvious really. You don't want to recompile everything every time you make a change to a value, that's just common coding sense.
4. (Optional) Have an instant replay feature in place - This will just help in case you observe something really weird happening with your PID values so you can replay the steps up until that point.

He also offers a number of online resources (some of which are dead links so I'll only post the ones that are still available):

Tuning a PID Temperature Controller

Hope that helps

~Ray

-

Recent #AltDevBlogADay article describes PID controllers quite nicely, and the WebGL example on author's site can be useful for fine-tuning the variables.

-

For starters, Wikipedia actually has a good article on how to begin tuning. Without more details it's hard to go into more detail in a response.

-