# How to design controllers “properly”?

It may sound like the "easy way" to ask it here, but this question (along with a couple others I've posted which were more specific) is the result of years of research on the topic - on and off as it's my least used (and weakest) area of expertise, but still, to say that I have seen many videos PDF and posts. Most of them are too specific in their examples, or it's all too vague.

## Context

I have tuned a couple of PI controllers until now using on line manual methods, but now that I'm struggling with a PID one it is clear that I need to dive back in proper analysis. After all, if I need to design another type of compensator (say phase lead or whatever, even a multivariable controller), there will be no "magic method" to save the day.

## Question

I would like to know what the different methods are to tune a controller assuming the transfer function of the plant is known, and in details how they deal with the following requirements:

1. Settling time
2. Phase and gain margins
3. Overshoot (if not dependent on phase margin)
5. Max controller effort
6. Ideally, max ripple due to disturbances but this one is particularly difficult it seems

## Research

The tools I've seen around are:

1. Root locus. I understand the effect of each root depending on its location (complex exponentials being oscillatory etc.), but I don't get how zeros and poles interact to generate the response. The fact that people ignore zeros for stability confuses me even more.
2. Nyquist. The stability criterions are very obscure in their relationship with the real world, and I haven't seen it being used for anything else.
3. Bode. Quite familiar with it due to electronics, although the concept of phase margin is still a bit vague compared to the gain margin (can't "feel" it).
4. Step response. The easiest to understand, although not sufficient.

I really like this Youtube channel, but it is still a bit vague after watching all the videos. And I never saw all the coefficients of a PID be tuned analytically - I really hoped this thread had the answer but it didn't.

## Application example

I propose to design step by step a PID controller (all 3 coeffs) for a very simple plant, say: $$G(s)=\frac{1}{1+\tau_1 s}\frac{1}{1+\tau_2 s}$$ Where $$\tau_1=650s$$ $$\tau_2=4500s$$ So that settling time < 5h, margins > 14dB and > 30°, s-s error (and ripple if studied) < 0.01%, controller effort < 1. This is a system which is inspired by what I need to control (very simplified), I have taken the numerical values from there.

As far as I know, this would be the first time one gets through an entire PID design online, which is highly beneficial to anyone with the same doubts as me. The question probably can be answered without this step by step, but it would be much much clearer with the example.

• You need to buy a textbook and study it throughout. What kind of answer are you expecting here for such a broad question? – hkBattousai Jan 22 '15 at 19:44
• That's because I looked at many books online and tutorials that I'm asking this question here. I only need a real example (not one where half the job is already done) to pick up on the methodology, or maybe guidelines from experienced people. Textbooks usually are 10 times longer than they should, this is about getting a briefer and summarised answer or a well worked out example. – Mister Mystère Jan 22 '15 at 23:36
• You gave this equation as an example, with 's' terms in tau one and two, is this correct? or are the extra 's' redundant? Which equation do you want? $$G(s)=\frac{1}{1+650 s^2}\frac{1}{1+4500 s^2}$$ $$G(s)=\frac{1}{1+650 s}\frac{1}{1+4500 s}$$ – Andrew Jan 29 '15 at 14:27
• @Andrew: thanks for looking into it. The "s" is actually for "seconds", this is the second equation I'm referring to. – Mister Mystère Jan 29 '15 at 15:08
• The first thing one should consider is: do I know anything specific about the characteristics of this system? PI(D) controllers are for general-purpose control, very suitable when you don't quite know how the system behaves in advance. But if you do, you have a chance to design something that's both simpler and more accurate than a generic PID. Because in the end, PID tuning boils down into trial & error. If it didn't, there would be no need for the integral part. – Lundin Aug 22 '19 at 9:42

Alright, You are asking a fairly complicated question and I will try and answer as best as I can given my background. I am senior student in Electrical Engineering and have focused in control systems. I don't know everything but I can tell you my experience with trying to answer this exact same question in my studies.
TL;DR: I don't know how an equation or method of taking the plant and constraints given and generating a PID controller. However, I do not think the tools you mentioned will help too much and I explain what I would do given your situation.

Where you are:
The research you have done so far seems be the standard for an introductory course on controls at the undergraduate level. These methods of designing controllers are grouped and called "Classical Control". These methods were used predominately pre-cold war and have the advantage of requiring very little computation and very little mathematical analysis. While useful, they severely limit the number of controllers you can create. For example, the root locus plot shows you lines where the poles and zeros can move if you change the gain but you are limited to these lines. I am not an expert on these methods (because I rarely use them) so I can't elaborate on when to use them and when not to. From what I have heard, these methods were still used pretty heavily up until recently because they are faster than more advanced methods and would work fine for simple control problems. These are your desert island control methods- easy to implement and can be done by hand, making them perfect for an undergraduate class where you want to have plenty of material to test students on.

"Properly":
Option 1
So properly designing a controller is hard because there are trade-offs in design, such as speed and stability. I assume you mean you can take the constraints you listed and turn them into a controller that meets them.
Any of the methods mentioned above could be used to create a controller and tested in a simulation or analytically to determine the response characteristics but that is not necessarily easy and the way to improve performance might not be intuitive (I am looking at you Nyquist plots).

How I would do it:
I am a student and so have access to the educational version of Matlab. If someone asked me to design a controller, like your example, I would fire up Matlab and use the following code.

EDU>> s=tf('s');
EDU>> sys=1/((1+650*s)*(1+4500*s))
pidtool(sys)


and the result, the beautiful box below that shows all the parameters I need with sliders that allow me to adjust the characteristics.

There are also options to show controller effort and the bode plot of the system. It took me about 15 min to tune it to meet your specifications, but only because your specifications are pretty aggressive. (I cheated to let control effort go to 1.01 for some time to stop the overshoot).
Or you could just simulate the system with the PID controller added in and tune the parameters in the simulation instead of online.

Option 2
Now if I were to need a more advanced controller, one with multiple inputs and outputs or with a higher order controller I would use what is called State Space or"Modern Control Theory" which I believe came about in the cold war when we started translating Russian mathematics papers. I would advise you to take a look into it because it allows for more options and if I were to design a controller analytically, this is what I would use. Unlike the Classical methods, it has algorithms for placing poles of a function in precise locations allowing most the constraints you have mentioned to be directly calculated.
That said, the algorithms used to calculate these values are still fairly difficult. matlab has the place function which creates a gain matrix that can be combined with the input matrix to force the desired response transient and settling time responses. This doesn't however mention controller effort, which would limit how aggressively you placed your poles. A good example of a similar order system is in the website below which has many different examples and demonstrations of how to use classical and state space design methods. Its a really good website with explanations and many different examples if you can get past the fact that they use matlab for all the math.
http://ctms.engin.umich.edu/CTMS/index.php?example=MotorSpeed&section=ControlStateSpace

http://nptel.ac.in/courses/101108047/module9/Lecture%2021.pdf
http://ocw.mit.edu/courses/aeronautics-and-astronautics/16-30-feedback-control-systems-fall-2010/lecture-notes/MIT16_30F10_lec12.pdf

Recommendation:

1.) If you are going to be designing control systems professionally, I'll tell you what my professors told me. You need matlab. There might be other software out there that can do similar things but matlab has a very complete set of tools in their control system tool box and a good number of tutorials are floating about its the best and you don't have to worry about the math at all.

2.) If this is something that is less important then maybe find someone who can do the design for you real quick in matlab or try out a freeware package. I know scilab has some control toolboxes that might be worth looking into.

3.) Designing by hand is hard. Especially with the number of constraints you have. I would use pole placement to analyze the settling time and overshoot requirements. Steady state error is almost always driven to zero. I would determine phase and gain margins after the fact and hope it wasn't too small. For the controller effort, I have seen plenty of examples of optimal control problems trying to minimize control effort, usually using a Linear Quadratic controller but this is more math. Dr. Radhakant Padhi's slides have some good rules of thumb for pole placement but they are not guarantees.

• Very good answer, thanks. I was referring to underlying methods rather than automated tools, but that's a very good overview. I already use Matlab and just got the control systems toolbox; also recently used state space to represent a plant (though not a controller) so I can relate to all that. Thanks for the links, this looks promising. – Mister Mystère Feb 1 '15 at 1:41

First I agree with hkBattousai that your question is very broad considering all the details of your post, but will try to answer according to your titled question - How to properly design control systems. This will unfortunately not be a complete answer, but I hope it at least gives you a taste. While some systems may be easily controlled using a PID compensator, others may not, so the professional control engineer will approach the problem in a more systematic way.

First you need to define your performance requirements - what it is you want to control, how fast and accurate you want the control, and how much margin you'll accept on stability.

Second you need to understand the physics of the system you are trying to control and express the physics as mathematical equations. This might be possible by just knowing how the system is constructed or it may require measurements - say with a dynamic signal analyzer. This will give you your model. You may want to assume a linear model which can be expressed as a differential equation or set of differential equations. You'll need to decide what variables in the system you are trying to control (outputs) and determine if you can facilitate their measurement with some type of sensor. You also need to figure out what your inputs are and if they require an actuator or interface to apply your control signals.

The linear model can be expressed as either a LaPlace transfer function(s) or as a linear state space system. Using a tool like Matlab Control Systems Toolbox (or paper and pencil if you want to do all the math yourself) you import your model and use one of the tools you outlined above (Bode, Root Locus, etc.). Personally I like to start with Root Locus but also plot the open and closed loop transfer functions as well as the step response. The root locus tool allows you to synthesize a controller on top of your plant model by adding poles and zeros, and dragging them about. And as you drag them you can observe your gain and phase margins from the open loop Bode plots, the closed loop bandwidth and modes from the closed loop Bode, and the rise time, overshoot and settling from the step response.

Once you are satisfied with the design and you've met your requirements you may want to take the model and the controller into a simulation tool. If there are nonlinearities in your system such as saturation for example, you can add them into the simulation and verify that your control still works. In the case of saturation you may need to augment your linear compensator with some form of anti-windup control. When you believe you have a solution its time to move onto the hardware and verify the design by testing.

Some simulation tools like Simulink or VisSim allow you migrate from the conceptual simulation to a hardware in the loop simulation. Otherwise you'll need to build or code your controller and facilitate the sensors, actuators and interfaces to close the loop.

There are a whole lot of other things to consider such as noise sensitivity, disturbance rejection, robustness to plant perturbations, etc. Also the controller solution will need to be reduced to either analog (op-amp), discrete (computer controlled) or even mechanical elements. So you may need to decide things like sampling rates, which if not properly selected can lead to instability or degrade expected performance.

hkBattousai recommended a text book, but I encourage you to enroll in a university program if you are seriously interested. Good Luck!

• Thanks for the answer, it's very informative. It sounds like designing a controller is more about fiddling with poles and zeros and/or values while looking at all the relevant plots at the same time - I thought there were always ways to calculate the controller parameters to meet requirements? – Mister Mystère Feb 1 '15 at 1:44
• You are welcome. This is just one example one might go about designing a control system. There are others approaches - for example Bond Graphs - that deal with the flow of energy. – docscience Feb 1 '15 at 1:49

First, ALL systems are non-linear. Some can be modeled quite accurately as linear systems, and linear control theory can be applied to non-linear systems (otherwise linear control theory would be pretty pointless). When relatively high performance is required, usually some type of gain scheduling is needed. Different types of gain schedulers exist, and some are very theoretical. Often however, the most practical (and testable... important for SW engineers) are piecewise linear schedulers (e.g., select a relatively linear region of operation, design a linear controller to operate in that region, go to the next, etc., ad infinitum). As Andrew stated, controller saturation should be addressed to avoid wind-up.

Second, model-based controllers are only as good as their models, and modeling requires domain knowledge. Even then, some tuning will almost always be needed to eliminate modeling errors. Any moderately complex system (at least ones that you're new to) can take a fairly long time to model with any accuracy. The level of model accuracy needed depends on what level of performance your application demands (i.e., Can you treat the plant as a simple integrator, or do you need to take 2nd and 3rd order effects into account?). The actuator/drive should also be modeled if its response time is anywhere near that of your plant. The same applies to the feedback sensor. In high performance systems, this is often the most expensive part of the whole controller. Some companies don't want to spend the time and money modeling the system. This is fine for simpler systems. However, for complex systems designed by folks not thinking about Controllability (capital 'C' - see "Modern Control Theory" by Brogan), lack of an up-front model makes controller design hugely difficult.

Control engineering is highly interdisciplinary, depending on the application. Simply "buying a textbook" on controls will help you get started, but the actual controller design is often much easier than understanding the plant and developing a decent model.

This is a complicated question that I have asked myself as well. Unfortunately most information in most books on control theory is mostly theoretical and lacking in details on how to actually implement the controller in software and what challenges you will face doing so. Knowing for example that you have to convert your controller not just into z domain but into z^-1 form in order to get proper coefficients and knowing that bilinear (tustin) transform is the way to go to get accurate response in discrete implementation (instead of matlab default zero order hold). It took me many months after I first started studying control theory to actually have enough knowledge and mathematical tools to implement it properly.

There is one book I would like to recommend to you called "Applied Control Theory for Embedded Systems" which does an excellent job tying all of the conventional control theory into the specific domain of embedded systems. I'm not author of the book and I'm not affiliated with the author. The book got some negative reviews on amazon which I think it does not deserve. If you have basic knowledge of the control theory then this book will tie everything together and make it clear to you how to apply it. If not then it can be a bit tedious when the book doesn't go into details. I think that books is absolutely excellent.