## How to properly tune a PID

There are hundreds of guides on the Internet on how to adjust a PID and they can all be summarized in the following *simple steps*:

- Set K
_{D}and K_{I}to zero and increase K_{P}until the system corrects the error and starts oscillating. That would be the maximum K_{P} - Increase K
_{D}until the K_{P}oscillation stops. - Increase K
_{I}slightly so that the system fully corrects the error.

They seem like three simple and quick steps, but the reality is that in the end it becomes a sort of trying to guess the constants and after hundreds of tests and hours, if you are lucky, you get a relatively stable PID. It is a rather cumbersome task that rarely achieves a completely satisfactory result.

Let's forget about all that and try to obtain K_{P} and K_{D} mathematically.