Autotune PID a controller
I would like to automatically tune a PID controller.


Please be more specific here. Do you (1) expect the characteristics of the plant to change over time, or (2) just not have a good model of the plant? 

If (1): the broadest possible way to attack this sort of problem is using adaptive control techniques, but these are also often very difficult to apply practically and require a lot of mathematical background. If you have some sort of system knowledge and some model of the system and how it changes, I recommend gain scheduling, which basically comes up with a new set of PID gains for different regions of the parameter space, and uses some system ID technique (e.g. a Kalman Filter) available from the observable states to estimate which PID to use based on how the system is performing.

If (2): If you don't have a model then you basically have to use an empirical tuning technique. Ziegler-Nichols is almost never used because it's too aggressive, but the comments have some good suggestions. The book by Astrom and Hagglund on PID controllers has tons of these techniques, and is an essential reference for anyone serious about process control. If you do have a model (even a low-fidelity one), you can use everything you know about classical controller design in the frequency domain (transfer functions, root-locus, bode/nyquist plots) to get the relevant controller quality parameters.