A completely revised version of these tutorials has recently been published as a CD-ROM by Addison-Wesley (now Prentice Hall). The new version has been updated for Matlab 5 and expanded to include Simulink tutorials. Please contact Prentice Hall for more information; request ISBN 0-201-47700-9.
A site license of the new version is available for users at the University of Michigan.
Welcome to the Control Tutorials for Matlab. We invite you to read more about the tutorials. They are
designed to help you learn how to use Matlab for the analysis and design of automatic control systems. They cover the basics of Matlab, the most common classical control design techniques (PID, root locus, and frequency response), as well as some modern (state-space) control design. The flow of the tutorials is given by the image map above: each tutorial is a white box. There are also four examples which are followed through the tutorials (each example page is indicated in the image map by a blue dot). Throughout the tutorials, you will find links at the bottom of each page to all of the tutorials as well as links to similar examples. Links are also given to come back to this page (Home), to the complete index, and to the list of Matlab commands.
We envision that you will follow along with these tutorials by running Matlab in one window and the tutorials in another. You should be able to run most of the Matlab programs by copying and pasting between windows. You may also find the tutorials helpful as an on-line reference while doing homework assignments or for reviewing concepts before exams. There are anonymous feedback forms at the bottom of each tutorial and example; we are interested to hear how you use the tutorials and your suggestions for improvements.
Assuming you have no prior experience with Matlab, the first tutorial, Matlab Basics, is recommended.
Copyright (C) 1996 by the Regents of the University of Michigan. 8/18/97 CJC
Matlab is an interactive program for numerical computation and data visualization; it is used extensively
by control engineers for analysis and design. There are many different toolboxes available which extend the basic functions of Matlab into different application areas; in these tutorials, we will make extensive use of the Control Systems Toolbox. Matlab is supported on Unix, Macintosh, and Windows environments; a student version of Matlab is available for personal computers. For more information on Matlab, contact the Mathworks.
The idea behind these tutorials is that you can view them in one window while running Matlab in another window. You should be able to re-do all of the plots and calculations in the tutorials by cutting and pasting text from the tutorials into Matlab or an m-file.
Vectors
Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between brackets, and set it equal to a variable. For example, to create the vector a, enter into the Matlab command window (you can "copy" and "paste" from your browser into Matlab to make it easy): a = [1 2 3 4 5 6 9 8 7] Matlab should return: a = 1 2 3 4 5 6 9 8 7 Let's say you want to create a vector with elements between 0 and 20 evenly spaced in increments of 2 (this method is frequently used to create a time vector): t = 0:2:20 t = 0 2 4 6 8 10 12 14 16 18 20 Manipulating vectors is almost as easy as creating them. First, suppose you would like to add 2 to each of the elements in vector 'a'. The equation for that looks like: b = a + 2 b = 3 4 5 6 7 8 11 10 9 Now suppose, you would like to add two vectors together. If the two vectors are the same length, it is easy. Simply add the two as shown below: c = a + b c = 4 6 8 10 12 14 20 18 16 Subtraction of vectors of the same length works exactly the same way.
Functions
To make life easier, Matlab includes many standard functions. Each function is a block of code that accomplishes a specific task. Matlab contains all of the standard functions such as sin, cos, log, exp, sqrt, as well as many others. Commonly used constants such as pi, and i or j for the square root of -1, are also incorporated into Matlab. sin(pi/4)
ans = 0.7071 To determine the usage of any function, type help [function name] at the Matlab command window. Matlab even allows you to write your own functions with the function command; follow the link to learn how to write your own functions and see a listing of the functions we created for this tutorial.
Plotting
It is also easy to create plots in Matlab. Suppose you wanted to plot a sine wave as a function of time. First make a time vector (the semicolon after each statement tells Matlab we don't want to see all the values) and then compute the sin value at each time. t=0:0.25:7; y = sin(t); plot(t,y)
The plot contains approximately one period of a sine wave. Basic plotting is very easy in Matlab, and the plot command has extensive add-on capabilities. I would recommend you visit the plotting page to learn more about it.
Polynomials
In Matlab, a polynomial is represented by a vector. To create a polynomial in Matlab, simply enter each coefficient of the polynomial into the vector in descending order. For instance, let's say you have the following polynomial:
To enter this into Matlab, just enter it as a vector in the following manner x = [1 3 -15 -2 9] x = 1 3 -15 -2 9 Matlab can interpret a vector of length n+1 as an nth order polynomial. Thus, if your polynomial is missing any coefficients, you must enter zeros in the appropriate place in the vector. For example,
would be represented in Matlab as: y = [1 0 0 0 1] You can find the value of a polynomial using the polyval function. For example, to find the value of the above polynomial at s=2, z = polyval([1 0 0 0 1],2) z = 17 You can also extract the roots of a polynomial. This is useful when you have a high-order polynomial such as
Finding the roots would be as easy as entering the following command; roots([1 3 -15 -2 9])
Let's say you want to multiply two polynomials together. The product of two polynomials is found by taking the convolution of their coefficients. Matlab's function conv that will do this for you. x = [1 2]; y = [1 4 8]; z = conv(x,y) z = 1 6 16 16 Dividing two polynomials is just as easy. The deconv function will return the remainder as well as the result. Let's divide z by y and see if we get x. [xx, R] = deconv(z,y) xx = 1 R = 0 0 0 0 As you can see, this is just the polynomial/vector x from before. If y had not gone into z evenly, the remainder vector would have been something other than zero. If you want to add two polynomials together which have the same order, a simple z=x+y will work (the vectors x and y must have the same length). In the general case, the user-defined function, polyadd can be used. To use polyadd, copy the function into an m-file, and then use it just as you would any other function in the Matlab toolbox. Assuming you had the polyadd function stored as a m-file, and you wanted to add the two uneven polynomials, x and y, you could accomplish this by entering the command: z = polyadd(x,y) x = 1 y = 1 z = 1 5 10 4 8 2 2
Matrices
Entering matrices into Matlab is the same as entering a vector, except each row of elements is separated by a semicolon (;) or a return: B = [1 2 3 4;5 6 7 8;9 10 11 12] B = 1 5 9 2 6 10 3 7 11 4 8 12
B = [ 1 2 3 4 5 6 7 8 9 10 11 12] B = 1 2 3 4 5 6 7 8 9 10 11 12 Matrices in Matlab can be manipulated in many ways. For one, you can find the transpose of a matrix using the apostrophe key: C = B' C = 1 5 9 2 6 10 3 7 11 4 8 12 It should be noted that if C had been complex, the apostrophe would have actually given the complex conjugate transpose. To get the transpose, use .' (the two commands are the same if the matix is not complex). Now you can multiply the two matrices B and C together. Remember that order matters when multiplying matrices. D = B * C D = 30 70 110 70 174 278 110 278 446
= C * B D =
107 122 137 152 122 140 158 176 137 158 179 200 152 176 200 224 Another option for matrix manipulation is that you can multiply the corresponding elements of two matrices using the .* operator (the matrices must be the same size to do this). E = [1 2;3 4] F = [2 3;4 5] G = E .* F
E = 1 3 F = 2 4 G = 2 6 12 20 If you have a square matrix, like E, you can also multiply it by itself as many times as you like by raising it to a given power. E^3 ans = 37 54 81 118 If wanted to cube each element in the matrix, just use the element-by-element cubing. E.^3 ans = 1 8 27 64 You can also find the inverse of a matrix: X = inv(E)
http://www.engin.umich.edu/group/ctm/basic/basic.html (7 de 10) [07/04/2003 07:15:17 p.m.]
2 4
3 5
X = -2.0000 1.5000 or its eigenvalues: eig(E) ans = -0.3723 5.3723 There is even a function to find the coefficients of the characteristic polynomial of a matrix. The "poly" function creates a vector that includes the coefficients of the characteristic polynomial. p = poly(E) p = 1.0000 -5.0000 -2.0000 1.0000 -0.5000
Remember that the eigenvalues of a matrix are the same as the roots of its characteristic polynomial: roots(p)
Printing
Printing in Matlab is pretty easy. Just follow the steps illustrated below: Macintosh To print a plot or a m-file from a Macintosh, just click on the plot or m-file, select Print under the File menu, and hit return. Windows To print a plot or a m-file from a computer running Windows, just selct Print from the File menu in the window of the plot or m-file, and hit return. Unix To print a plot on a Unix workstation enter the command:
print -P<printername> If you want to save the plot and print it later, enter the command: print plot.ps Sometime later, you could print the plot using the command "lpr -P plot.ps" If you are using a HP workstation to print, you would instead use the command "lpr -d plot.ps" To print a m-file, just print it the way you would any other file, using the command "lpr -P <name of m-file>.m" If you are using a HP workstation to print, you would instead use the command "lpr -d plot.ps<name of m-file>.m"
B B = 1 2 3 4 5 6 7 8 9 You can also have more that one statement on a single line, so long as you separate them with either a semicolon or comma. Also, you may have noticed that so long as you don't assign a variable a specific operation or result, Matlab with store it in a temporary variable called "ans".
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital | Examples
8/11/97 dmt
Modeling Tutorial
Train system Free body diagram and Newton's law State-variable and output equations Matlab representation
Matlab can be used to represent a physical system or a model. To begin with, let's start with a review of how to represent a physical system as a set of differential equations.
Train system
In this example, we will consider a toy train consisting of an engine and a car. Assuming that the train only travels in one direction, we want to apply control to the train so that it has a smooth start-up and stop, along with a constant-speed ride. The mass of the engine and the car will be represented by M1 and M2, respectively. The two are held together by a spring, which has the stiffness coefficient of k. F represents the force applied by the engine, and the Greek letter, mu (which will also be represented by the letter u), represents the coefficient of rolling friction.
From Newton's law, you know that the sum of forces acting on a mass equals the mass times its acceleration. In this case, the forces acting on M1 are the spring, the friction and the force applied by the engine. The forces acting on M2 are the spring and the friction. In the vertical direction, the gravitational force is canceled by the normal force applied by the ground, so that there will be no acceleration in the vertical direction. The equations of motion in the horizontal direction are the followings:
Let the output of the system be the velocity of the engine. Then the output equation will become:
1. Transfer function
To find the transfer funciton of the system, first, take Laplace transforms of above state-variable and output equations.
Using these equations, derive the transfer function Y(s)/F(s) in terms of constants. When finding the transfer function, zero initial conditions must be assumed. The transfer function should look like the one shown below.
2. State-space
Another method to solve the problem is to use the state-space form. Four matrices A, B, C, and D characterize the system behavior, and will be used to solve the problem. The state-space form that were manipulated from the state-variable and the output equations is shown below.
Matlab representation
Now we will show you how to enter the equations derived above into an m-file for Matlab. Since Matlab can not manipulate symbolic variables, let's assign numerical values to each of the variables. Let q M1 = 1 kg q M2 = 0.5 kg
http://www.engin.umich.edu/group/ctm/model/model.html (3 de 5) [07/04/2003 07:17:44 p.m.]
Create an new m-file and enter the following commands. M1=1; M2=0.5; k=1; F=1; u=0.002; g=9.8; Now you have one of two choices: 1) Use the transfer function, or 2) Use the state-space form to solve the problem. If you choose to use the transfer function, add the following commands onto the end of the m-file which you have just created. num=[M2 M2*u*g 1]; den=[M1*M2 2*M1*M2*u*g M1*k+M1*M2*u*u*g*g+M2*k M1*k*u*g+M2*k*u*g]; If you choose to use the state-space form, add the following commands at the end of the m-file, instead of num and den matrices shown above. 0 1 0 0; -k/M1 -u*g k/M1 0; 0 0 0 1; k/M2 0 -k/M2 -u*g]; B=[ 0; 1/M1; 0; 0]; C=[0 1 0 0]; D=[0]; See the Matlab basics tutorial to learn more about entering matrices. A=[
User Feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
Using Newton's law, modeling equations for this system becomes: (1)
where u is the force from the engine. For this example, let's assume that
Design requirements
The next step in modeling this system is to come up with some design criteria. When the engine gives a 500 Newton force, the car will reach a maximum velocity of 10 m/s (22 mph). An automobile should be able to accelerate up to that speed in less than 5 seconds. Since this is only a cruise control system, a 10% overshoot on the velocity will not do much damage. A 2% steady-state error is also acceptable for the same reason. Keeping the above in mind, we have proposed the following design criteria for this problem: Rise time < 5 sec Overshoot < 10% Steady state error < 2%
Matlab representation
1. Transfer Function
To find the transfer function of the above system, we need to take the Laplace transform of the modeling equations (1). When finding the transfer function, zero initial conditions must be assumed. Laplace transforms of the two equations are shown below.
Since our output is the velocity, let's substitute V(s) in terms of Y(s)
To solve this problem using Matlab, copy the following commands into an new m-file:
m=1000; b=50; u=500; num=[1]; den=[m b]; These commands will later be used to find the open-loop response of the system to a step input. But before getting into that, let's take a look at another representation, the state-space.
2. State-Space
We can rewrite the first-order modeling equation (1) as the state-space model.
To use Matlab to solve this problem, create an new m-file and copy the following commands: m = 1000; b = 50; u = 500; A = [-b/m]; B = [1/m]; C = [1]; D = 0; Note: It is possible to convert from the state-space representation to the transfer function or vise versa using Matlab. To learn more about the conversion, click Conversion
Open-loop response
Now let's see how the open-loop system responds to a step input. Add the following command onto the end of the m-file written for the tranfer function (the m-file with num and den matrices) and run it in the Matlab command window: step (u*num,den) You should get the following plot:
To use the m-file written for the state-space (the m-file with A, B, C, D matrices), add the following command at the end of the m-file and run it in the Matlab command window: step (A,u*B,C,D) You should get the same plot as the one shown above. From the plot, we see that the vehicle takes more than 100 seconds to reach the steady-state speed of 10 m/s. This does not satisfy our rise time criterion of less than 5 seconds.
The transfer function in the plant is the transfer function derived above {Y(s)/U(s)=1/ms+b}. The controller will to be designed to satisfy all design criteria. Four different methods to design the controller are listed at the bottom of this page. You may choose on PID, Root-locus, Frequency response, or State-space.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
q q q q
and the block diagram of an typical unity feedback system is shown below.
The design criteria for this problem are: Rise time < 5 sec Overshoot < 10% Steady state error < 2%
To see the original problem setup, see Cruise Control Modeling page. Recall from the PID tutorial page, the transfer function of a PID controller is
Proportional control
The first thing to do in this problem is to find a closed-loop transfer function with a proportional control (Kp) added. By reducing the block diagram, the closed-loop transfer function with a proportional controller becomes:
Recall from the PID tutorial page, a proportional controller (Kp) decreases the rise time. This is what we need, if you refer to the Cruise Control Modeling page. For now, let Kp equals 100 and see what happens to the response. Create an new m-file and enter the following commands. kp=100; m=1000; b=50; u=10; num=[kp]; den=[m b+kp]; t=0:0.1:20; step(u*num,den,t) axis([0 20 0 10]) Running this m-file in the Matlab command window should give you the following step response.
Note: You can use the Matlab command cloop to find the closed-loop response directly from the open-loop transfer function. If you choose to do so, change the m-file to the following and run it in the command window. You should get the same plot as the one shown above. kp=100; m=1000; b=50; u=10; num=[1]; den=[m b]; [numc,denc]=cloop(kp*num,den,-1); t = 0:0.1:20; step (u*numc,denc,t) axis([0 20 0 10]) As you can see from the plot, both the steady-state error and the rise time do not satisfy our design criteria. You can increase the proportional gain (Kp) to improve the system output. Change the existing m-file so that Kp equal 10000 and rerun it in the Matlab command window. You should see the following plot.
The steady-state error has dropped to near zero and the rise time has decreased to less than 0.5 second. However, this response is unrealistic because a real cruise control system generally can not change the speed of the vehicle from 0 to 10 m/s in less than 0.5 second. The solution to this problem is to choose a proportional gain (Kp) that will give a reasonable rise time, and add an integral controller to eliminate the steady-state error.
PI control
The closed-loop transfer function of this cruise control system with a PI controller is:
Recall from the PID tutrial page, an addition of an integral controller to the system eliminates the steady-state error. For now, let Kp equals 600 and Ki equals 1 and see what happens to the response. Change your m-file to the following. kp = 600; ki = 1; m=1000; b=50; u=10; num=[kp ki]; den=[m b+kp ki]; t=0:0.1:20; step(u*num,den,t)
axis([0 20 0 10]) Note: If you choose to obtain the closed-loop response directly from the open-loop transfer function, enter the following commands instead of the ones shown above: kp=600; ki=1; m=1000; b=50; u=10; num=[1]; den=[m b]; num1=[kp ki]; den1=[1 0]; num2=conv(num,num1); den2=conv(den,den1); [numc,denc]=cloop(num2,den2,-1); t=0:0.1:20; step(u*numc,denc,t) axis([0 20 0 10]) Whichever the m-file you run, you should get the following output:
Now adjust both the proportional gain (Kp) and the integral gain (Ki) to obtain the desired response. When you adjust the integral gain (Ki), we suggest you to start with a small value since large (Ki) most likely unstabilize the response. With Kp equals 800 and Ki equals 40, the step response will look like the following:
As you can see, this step response meets all design criteria.
PID control
For this particular example, no implementation of a derivative controller was needed to obtain a required output. However, you might want to see how to work with a PID control for the future reference. The closed-loop transfer function for this cruise control system with a PID controller is.
Let Kp equals 1, Ki equals 1, and Kd equals 1 and enter the following commands into an new m-file. kp=1; ki=1; kd=1; m=1000; b=50; u=10; num=[kd kp ki]; den=[m+kd b+kp ki]; t=0:0.1:20; step(u*num,den,t) axis([0 20 0 10]) Running this m-file should give you the step response of the system with PID controller. Adjust all of Kp, Kd, and Ki until you obtain satisfactory results. We will leave this as an exercise for you to work on.
Suggestion: Usually choosing appropriate gains require trial and error processes. The best way to attack this tedious process is to adjust one variable (Kp, Kd, or Ki) at a time and observe how changing one variable influences the system output. The characteristics of Kp, Kd, and Ki are summarized in the PID Tutorial page.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
A common actuator in control systems is the DC motor. It directly provides rotary motion and, coupled with wheels or drums and cables, can provide transitional motion. The electric circuit of the armature and the free body diagram of the rotor are shown in the following figure:
For this example, we will assume the following values for the physical parameters. These values were derived by experiment from an actual motor in Carnegie Mellon's undergraduate controls lab. * moment of inertia of the rotor (J) = 0.01 kg.m^2/s^2 * damping ratio of the mechanical system (b) = 0.1 Nms * electromotive force constant (K=Ke=Kt) = 0.01 Nm/Amp
http://www.engin.umich.edu/group/ctm/examples/motor/motor.html (1 de 5) [21/11/2003 05:42:23 p.m.]
* electric resistance (R) = 1 ohm * electric inductance (L) = 0.5 H * input (V): Source Voltage * output (theta): position of shaft * The rotor and shaft are assumed to be rigid The motor torque, T, is related to the armature current, i, by a constant factor Kt. The back emf, e, is related to the rotational velocity by the following equations:
In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant). From the figure above we can write the following equations based on Newton's law combined with Kirchhoff's law:
1. Transfer Function
Using Laplace Transforms, the above modeling equations can be expressed in terms of s.
By eliminating I(s) we can get the following open-loop transfer function, where the rotational speed is the output and the voltage is the input.
2. State-Space
In the state-space form, the equations above can be expressed by choosing the rotational speed and electric current as the state variables and the voltage as an input. The output is chosen to be the rotational speed.
Design requirements
First, our uncompensated motor can only rotate at 0.1 rad/sec with an input voltage of 1 Volt (this will be demonstrated later when the open-loop response is simulated). Since the most basic requirement of a motor is that it should rotate at the desired speed, the steady-state error of the motor speed should be less than 1%. The other performance requirement is that the motor must accelerate to its steady-state speed as soon as it turns on. In this case, we want it to have a settling time of 2 seconds. Since a speed faster than the reference may damage the equipment, we want to have an overshoot of less than 5%. If we simulate the reference input (r) by an unit step input, then the motor speed output should have: q Settling time less than 2 seconds q Overshoot less than 5% q Steady-state error less than 1%
Create a new m-file and enter the following commands: J=0.01; b=0.1; K=0.01; R=1; L=0.5; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];
Now let's see how the original open-loop system performs. Add the following commands onto the end of the m-file and run it in the Matlab command window: step(num,den,0:0.1:3) title('Step Response for the Open Loop System') You should get the following plot:
From the plot we see that when 1 volt is applied to the system, the motor can only achieve a maximum speed of 0.1 rad/sec, ten times smaller than our desired speed. Also, it takes the motor 3 seconds to reach its steady-state speed; this does not satisfy our 2 seconds settling time criterion.
2. State-Space
We can also represent the system using the state-space equations. Try the following commands in a new m-file. J=0.01; b=0.1; K=0.01; R=1; L=0.5; A=[-b/J -K/L
K/J -R/L];
B=[0 1/L]; C=[1 0]; D=0; step(A, B, C, D) Run this m-file in the Matlab command window, and you should get the same output as the one shown above.
User feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
Physical Setup
A common actuator in control systems is the DC motor. It directly provides rotary motion and, coupled with wheels or drums and cables, can provide transitional motion. The electric circuit of the armature and the free body diagram of the rotor are shown in the following figure:
For this example, we will assume the following values for the physical parameters. These values were derived by experiment from an actual motor in Carnegie Mellon's undergraduate controls lab. * moment of inertia of the rotor (J) = 3.2284E-6 kg.m^2/s^2 * damping ratio of the mechanical system (b) = 3.5077E-6 Nms * electromotive force constant (K=Ke=Kt) = 0.0274 Nm/Amp * electric resistance (R) = 4 ohm * electric inductance (L) = 2.75E-6 H * input (V): Source Voltage * output (theta): position of shaft
System Equations
The motor torque, T, is related to the armature current, i, by a constant factor Kt. The back emf, e, is related to the rotational velocity by the following equations:
In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant). From the figure above we can write the following equations based on Newton's law combined with Kirchhoff's law:
1. Transfer Function
Using Laplace Transforms the above equations can be expressed in terms of s.
By eliminating I(s) we can get the following transfer function, where the rotating speed is the output and the voltage is an input.
However during this example we will be looking at the position, as being the output. We can obtain the position by integrating Theta Dot, therefore we just need to divide the transfer function by s.
2. State Space
These equations can also be represented in state-space form. If we choose motor position, motor speed, and armature current as our state variables, we can write the equations as follows:
Design requirements
We will want to be able to position the motor very precisely, thus the steady-state error of the motor position should be zero. We will also want the steady-state error due to a disturbance, to be zero as well. The other performance requirement is that the motor reaches its final position very quickly. In this case, we want it to have a settling time of 40ms. We also want to have an overshoot smaller than 16%. If we simulate the reference input (R) by a unit step input, then the motor speed output should have: q Settling time less than 40 milliseconds q Overshoot less than 16% q No steady-state error q No steady-state error due to a disturbance
From the plot we see that when 1 volt is applied to the system, the motor position changes by 6 radians, six times greater than our desired position. For a 1 volt step input the motor should spin through 1 radian. Also, the motor doesn't reach a steady state which does not satisfy our design criteria
2. State Space
We can put the state space equations into Matlab by defining the system's matrices as follows: J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; A=[0 1 0 0 -b/J K/J 0 -K/L -R/L]; B=[0 ; 0 ; 1/L]; C=[1 0 0]; D=[0]; The step response is obtained using the command step(A,B,C,D) Unfortunately, Matlab responds with
Error in ==> /usr/local/lib/matlab/toolbox/control/step.m On line 84 ==> dt = t(2)-t(1); There are numerical scaling problems with this representation of the dynamic equations. To fix the problem, we scale time by tscale = 1000. Now the output time will be in milliseconds rather than in seconds. The equations are given by tscale = 1000; J=3.2284E-6*tscale^2; b=3.5077E-6*tscale; K=0.0274*tscale; R=4*tscale; L=2.75E-6*tscale^2; A=[0 1 0 0 -b/J K/J 0 -K/L -R/L]; B=[0 ; 0 ; 1/L]; C=[1 0 0]; D=[0]; The output appears the same as when obtained through the transfer function, but the time vector must be divided by tscale. [y,x,t]=step(A,B,C,D); plot(t/tscale,y) ylabel('Amplitude') xlabel('Time (sec)')
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
http://www.engin.umich.edu/group/ctm/examples/motor2/motor.html (5 de 6) [21/11/2003 05:42:30 p.m.]
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/24/97 WM
Designing an automatic suspension system for a bus turns out to be an interesting control problem. When the suspension system is designed, a 1/4 bus model (one of the four wheels) is used to simplify the problem to a one dimensional spring-damper system. A diagram of this system is shown below:
Where: * body mass (m1) = 2500 kg, * suspension mass (m2) = 320 kg,
http://www.engin.umich.edu/group/ctm/examples/susp/susp.html (1 de 7) [21/11/2003 05:42:43 p.m.]
* spring constant of suspension system(k1) = 80,000 N/m, * spring constant of wheel and tire(k2) = 500,000 N/m, * damping constant of suspension system(b1) = 350 Ns/m. * damping constant of wheel and tire(b2) = 15,020 Ns/m. * control force (u) = force from the controller we are going to design.
Design requirements:
A good bus suspension system should have satisfactory road holding ability, while still providing comfort when riding over bumps and holes in the road. When the bus is experiencing any road disturbance (i.e. pot holes, cracks, and uneven pavement),the bus body should not have large oscillations, and the oscillations should dissipate quickly. Since the distance X1-W is very difficult to measure, and the deformation of the tire (X2-W) is negligible, we will use the distance X1-X2 instead of X1-W as the output in our problem. Keep in mind that this is an estimation. The road disturbance (W) in this problem will be simulated by a step input. This step could represent the bus coming out of a pothole. We want to design a feedback controller so that the output (X1-X2) has an overshoot less than 5% and a settling time shorter than 5 seconds. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate within a range of +/- 5 mm and return to a smooth ride within 5 seconds.
Equations of motion:
From the picture above and Newton's law, we can obtain the dynamic equations as the following:
Find the inverse of matrix A and then multiple with inputs U(s)and W(s) on the right hand side as the following:
When we want to consider input U(s) only, we set W(s) = 0. Thus we get the transfer function G1(s) as the following:
When we want to consider input W(s) only, we set U(s) = 0. Thus we get the transfer function G2(s) as the following:
Also we can express and derive the above equations in state-space form. Even though this approach will express the first two equations above in the standard form of matrix, it will simplify the transfer function without going through any algebra, because we can use a function ss2tf to transform from state-space form to transfer function form for both inputs
'G(s)1' printsys(nump,denp) num1=[-(m1*b2) -(m1*k2) 0 0]; den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2]; 'G(s)2' printsys(0.1*num1,den1)
Open-loop response
We can use Matlab to display how the original open-loop system performs (without any feedback control). Add the following commands into the m-file and run it in the Matlab command window to see the response of unit step actuated force input and unit step disturbance input.Note that the step command will generate the unit step inputs for each input. step(nump,denp)
From this graph of the open-loop response for a unit step actuated force, we can see that the system is under-damped. People sitting in the bus will feel very small amount of oscillation and the steady-state error is about 0.013 mm. Moreover, the bus takes very unacceptably long time for it to reach the steady state or the settling time is very large. The solution to this problem is to add a feedback controller into the system's block diagram. step(0.1*num1,den1)
To see some details, you can change the axis: axis([0 10 -.1 .1])
From this graph of open-loop response for 0.1 m step disturbance, we can see that when the bus passes a 10 cm high bump on the road, the bus body will oscillate for an unacceptably long time(100 seconds) with larger amplitude, 13 cm, than the initial impact. People sitting in the bus will not be comfortable with such an oscillation. The big overshoot (from the impact itself) and the slow settling time will cause damage to the suspension system. The solution to this problem is to add a feedback controller into the system to improve the performance. The schematic of the closed-loop system is the following:
http://www.engin.umich.edu/group/ctm/examples/susp/susp.html (5 de 7) [21/11/2003 05:42:43 p.m.]
From the above transfer functions and schematic, we can draw the bus-system block diagram as the following:
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Examples
6/3/97 PP 8/24/97 WM
For this example, let's assume that M m b mass of the cart mass of the pendulum friction of the cart 0.5 kg 0.5 kg 0.1 N/m/sec
l length to pendulum center of mass 0.3 m I inertia of the pendulum 0.006 kg*m^2 F force applied to the cart x cart position coordinate theta pendulum angle from vertical For the PID, root locus, and frequency response sections of this problem we will be only interested in the control of the pendulums position. This is because the techniques used in these tutorials can only be applied for a single-input-single-output (SISO) system. Therefore, none of the design criteria deal with the cart's position. For these sections we will assume that the system starts at equilibrium, and experiences an impulse force of 1N. The pendulum should return to its upright position within 5 seconds, and never move more than 0.05 radians away from the vertical. The design requirements for this system are: q Settling time of less than 5 seconds. q Pendulum angle never more than 0.05 radians from the vertical. However, with the state-space method we are more readily able to deal with a multi-output system. Therefore, for this section of the Inverted Pendulum example we will attempt to control both the pendulum's angle and the cart's position. To make the design more challenging we will be applying a step input to the cart. The cart should achieve it's desired position within 5 seconds and have a rise time under 0.5 seconds. We will also limit the pendulum's overshoot to 20 degrees (0.35 radians), and it should also settle in under 5 seconds. The design requirements for the Inverted Pendulum state-space example are: q Settling time for x and theta of less than 5 seconds. q Rise time for x of less than 0.5 seconds. q Overshoot of theta less than 20 degrees (0.35 radians).
Summing the forces in the Free Body Diagram of the cart in the horizontal direction, you get the following equation of motion:
Note that you could also sum the forces in the vertical direction, but no useful information would be gained. Summing the forces in the Free Body Diagram of the pendulum in the horizontal direction, you can get an equation for N:
If you substitute this equation into the first equation, you get the first equation of motion for this system: (1) To get the second equation of motion, sum the forces perpendicular to the pendulum. Solving the system along this axis ends up saving you a lot of algebra. You should get the following equation:
To get rid of the P and N terms in the equation above, sum the moments around the centroid of the pendulum to get the following equation:
Combining these last two equations, you get the second dynamic equation: (2) Since Matlab can only work with linear functions, this set of equations should be linearized about theta = Pi. Assume that theta = Pi + ( represents a small angle from the vertical upward direction). Therefore,
cos(theta) = -1, sin(theta) = -, and (d(theta)/dt)^2 = 0. After linearization the two equations of motion become (where u represents the input):
1. Transfer Function
To obtain the transfer function of the linearized system equations analytically, we must first take the Laplace transform of the system equations. The Laplace transforms are:
NOTE: When finding the transfer function initial conditions are assumed to be zero. Since we will be looking at the angle Phi as the output of interest, solve the first equation for X(s),
where,
From the transfer function above it can be seen that there is both a pole and a zero at the origin. These can be canceled and the transfer function becomes:
2. State-Space
After a little algebra, the linearized system equations equations can also be represented in state-space form:
The C matrix is 2 by 4, because both the cart's position and the pendulum's position are part of the output. For the state-space design problem we will be controlling a multi-output system so we will be observing the cart's position from the first row of output and the pendulum's with the second row.
-(M+m)*m*g*l/q
-b*m*g*l/q]
num = 4.5455
den = 1.0000 0.1818 -31.1818 -4.4545 To observe the system's velocity response to an impulse force applied to the cart add the following lines at the end of your m-file: t=0:0.01:5; impulse(num,den,t) axis([0 1 0 60]) Note: Matlab commands from the control system toolbox are highlighted in red. You should get the following velocity response plot:
As you can see from the plot, the response is entirely unsatisfactory. It is not stable in open loop. You can change the axis to see more of the response if you need to convince yourself that the system is unstable.
1. State-Space
Below, we show how the problem would be set up using Matlab for the state-space model. If you copy the following text into a m-file (or into a '.m' file located in the same directory as Matlab) and run it, Matlab will give you the A, B, C, and D matrices for the state-space model and a plot of the response of the cart's position and pendulum angle to a step input of 0.2 m applied to the cart. M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3;
p = i*(M+m)+M*m*l^2; %denominator for the A and B matricies A = [0 1 0 0; 0 -(i+m*l^2)*b/p (m^2*g*l^2)/p 0; 0 0 0 1; 0 -(m*l*b)/p m*g*l*(M+m)/p 0] B = [ 0; (i+m*l^2)/p; 0;
m*l/p] C = [1 0 0 0; 0 0 1 0] D = [0; 0] T=0:0.05:10; U=0.2*ones(size(T)); [Y,X]=lsim(A,B,C,D,U,T); plot(T,Y) axis([0 2 0 100]) You should see the following output after running the m-file:
The blue line represents the cart's position and the green line represents the pendulum's angle. It is obvious from this plot and the one above that some sort of control will have to be designed to improve the dynamics of the system. Four example controllers are included with these tutorials: PID, root locus, frequency response, and state space. Select from below the one you would like to use. Note: The solutions shown in the PID, root locus and frequency response examples may not yield a workable controller for the inverted pendulum problem. As stated previously, when we put this problem into the single-input, single-output framework, we ignored the x position of the cart. The pendulum can be stabilized in an inverted position if the x position is constant or if the cart moves at a constant velocity (no acceleration). Where possible in these examples, we will show what happens to the cart's position when our controller is implemented on the system. We emphasize that the purpose of these examples is to demonstrate design and analysis techniques using Matlab; not to actually control an inverted pendulum.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball & Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/11/97 CJC
Physical setup and system equations Design requirements Transfer function and state-space Matlab representation and open-loop response Closed-loop transfer function
Assume that the aircraft is in steady-cruise at constant altitude and velocity; thus, the thrust and drag cancel out and the lift and weight balance out each other. Also, assume that change in pitch angle does not change the speed of an aircraft under any circumstance (unrealistic but simplifies the problem a bit). Under these assumptions, the longitudinal equations of motion of an aircraft can be written as:
(1)
Please refer to any aircraft-related textbooks for the explanation of how to derive these equations. Also, click Variables to see what each variable represents. For this system, the input will be the elevator deflection angle, and the output will be the pitch angle.
Design requirements
The next step is to set some design criteria. We want to design a feedback controller so that the output has an overshoot of less than 10%, rise time of less than 2 seconds, settling time of less than 10 seconds, and the steady-state error of less than 2%. For example, if the input is 0.2 rad (11 degress), then the pitch angle will not exceed 0.22 rad, reaches 0.2 rad within 2 seconds, settles 2% of the steady-state within 10 seconds, and stays within 0.196 to 0.204 rad at the steady-state. q Overshoot: Less than 10% q Rise time: Less than 2 seconds q Settling time: Less than 10 seconds q Steady-state error: Less than 2%
http://www.engin.umich.edu/group/ctm/examples/pitch/Mpitch.html (2 de 6) [21/11/2003 05:42:59 p.m.]
(2)
These values are taken from the data from one of the Boeing's commercial aircraft.
1. Transfer function
To find the transfer function of the above system, we need to take the Laplace transform of the above modeling equations (2). Recall from your control textbook, when finding a transfer function, zero initial conditions must be assumed. The Laplace transform of the above equations are shown below.
After few steps of algebra, you should obtain the following transfer function.
2. State-space
Knowing the fact that the modeling equations (2) are already in the state-variable form, we can rewrite them into the state-space model.
Since our output is the pitch angle, the output equation is:
From the plot, we see that the open-loop response does not satisfy the design criteria at all. In fact the open-loop response is unstable.
If you noticed, the above m-file uses the numerical values from the transfer function. To use the state-space model, enter the following commands into a new m-file (instead of the one shown above) and run it in the command window. de=0.2; A=[-0.313 56.7 0; -0.0139 -0.426 0; 0 56.7 0]; B=[0.232; 0.0203; 0]; C=[0 0 1]; D=[0]; step(A,B*de,C,D) You should get the same response as the one shown above. Note: It is possible to convert from the state-space to transfer function, or vice versa using Matlab. To learn more about conversions, see Conversions
A controller needs to be designed so that the step response satisfies all design requirements. Four different methods to design a controller are listed at the bottom of this page. You may choose: PID, Root-locus, Frequency response, or State-space.
User Feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
Problem Setup
A ball is placed on a beam, see figure below, where it is allowed to roll with 1 degree of freedom along the length of the beam. A lever arm is attached to the beam at one end and a servo gear at the other. As the servo gear turns by an angle theta, the lever changes the angle of the beam by alpha. When the angle is changed from the vertical position, gravity causes the ball to roll along the beam. A controller will be designed for this system so that the ball's position can be manipulated.
For this problem, we will assume that the ball rolls without slipping and friction between the beam and ball is negligible. The constants and variables for this example are defined as follows: M mass of the ball 0.11 kg R radius of the ball 0.015 m d lever arm offset 0.03 m g gravitational acceleration 9.8 m/s^2 L length of the beam 1.0 m J ball's moment of inertia 9.99e-6 kgm^2 r ball position coordinate alpha beam angle coordinate theta servo gear angle The design criteria for this problem are: q Settling time less than 3 seconds q Overshoot less than 5%
System Equations
The Lagrangian equation of motion for the ball is given by the following:
Linearization of this equation about the beam angle, alpha = 0, gives us the following linear approximation of the system:
The equation which relates the beam angle to the angle of the gear can be approximated as linear by the equation below:
1. Transfer Function
Taking the Laplace transform of the equation above, the following equation is found:
NOTE: When taking the Laplace transform to find the transfer function initial conditions are assumed to be zero.
Rearranging we find the transfer function from the gear angle (theta(s)) to the ball position (R(s)).
It should be noted that the above plant transfer function is a double integrator. As such it is marginally stable and will provide a challenging control problem.
2. State-Space
The linearized system equations can also be represented in state-space form. This can be done by selecting the ball's position (r) and velocity (rdot) as the state variables and the gear angle (theta) as the input. The state-space representation is shown below:
However, for our state-space example we will be using a slightly different model. The same equation for the ball still applies but instead of controlling the position through the gear angle, theta, we will control alpha-doubledot. This is essentially controlling the torque of the beam. Below is the representation of this system:
Note: For this system the gear and lever arm would not be used, instead a motor at the center of the beam will apply torque to the beam, to control the ball's position.
K = (m*g*d)/(L*(J/R^2+m)); num = [-K]; den = [1 0 0]; printsys(num,den) Your output should be: num/den =
0.21 ---------s^2 Now, we would like to observe the ball's response to a step input of 0.25 m. To do this you will need to add the following line to your m-file:
step(0.25*num,den) NOTE: Matlab commands from the control system toolbox are highlighted in red. You should see the following plot showing the balls position as a function of time:
From this plot it is clear that the system is unstable in open-loop causing the ball to roll right off the end of the beam. Therefore, some method of controlling the ball's position in this system is required. Three examples of controller design are listed below for the transfer function problem. You may select from PID, Root Locus, and Frequency Response.
2. State-Space
The state-space equations can be represented in Matlab with the following commands (these equations are for the torque control model). m R g J = = = = 0.111; 0.015; -9.8; 9.99e-6;
H = -m*g/(J/(R^2)+m); A=[0 1 0 0
http://www.engin.umich.edu/group/ctm/examples/ball/ball.html (6 de 8) [21/11/2003 05:43:05 p.m.]
0 0 H 0 0 0 0 1 0 0 0 0]; B=[0;0;0;1]; C=[1 0 0 0]; D=[0]; The step response to a 0.25m desired position can be viewed by running the command below: step(A,B*.25,C,D) Your output should look like the following:
Like the plot for the transfer function this plot shows that the system is unstable and the ball will roll right off the end of the beam. Therefore, we will require some method of controlling the ball's position in this system. The State-Space example below shows how to implement a controller for this type of system. If you are interested in knowing how to convert state-space representations to transfer function representations, and vice versa, please refer to the Conversions page.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Modeling Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
For the original problem setup and the derivation of the above equations, please refer to the Modeling a DC Motor page. With a 1 rad/sec step input, the design criteria are: q Settling time less than 2 seconds
http://www.engin.umich.edu/group/ctm/examples/motor/PID2.html (1 de 7) [21/11/2003 05:43:13 p.m.]
q q
Now let's design a PID controller and add it into the system. First create a new m-file and type in the following commands (refer to the Modeling page for the details of getting these commands). J=0.01; b=0.1; K=0.01; R=1; L=0.5; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)]; Recall that the transfer function for a PID controller is:
Proportional control
Let's first try using a proportional controller with a gain of 100. Add the following code to the end of your m-file: Kp=100; numa=Kp*num; dena=den; To determine the closed-loop transfer function, we use the cloop command. Add the following line to your m-file: [numac,denac]=cloop(numa,dena); Note that numac and denac are the numerator and the denominator of the overall closed-loop transfer function. Now let's see how the step response looks, add the following to the end of your m-file, and run it in the command window: t=0:0.01:5; step(numac,denac,t) title('Step response with Proportion Control') You should get the following plot:
PID control
From the plot above we see that both the steady-state error and the overshoot are too large. Recall from the PID tutorial page that adding an integral term will eliminate the steady-state error and a derivative term will reduce the overshoot. Let's try a PID controller with small Ki and Kd. Change your m-file so it looks like the following. Running this new m-file gives you the following plot. J=0.01; b=0.1; K=0.01; R=1; L=0.5; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)]; Kp=100; Ki=1; Kd=1; numc=[Kd, Kp, Ki]; denc=[1 0]; numa=conv(num,numc); dena=conv(den,denc);
Now we see that the response is much faster than before, but the large Ki has worsened the transient response (big overshoot). Let's increase Kd to reduce the overshoot. Go back to the m-file and change Kd to 10. Rerun it and you should get this plot:
So now we know that if we use a PID controller with Kp=100, Ki=200, Kd=10, all of our design requirements will be satisfied.
User feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | PID | Modeling | Root Locus | Frequency Response | State Space | Digital Control | Examples
For the original problem setup and the derivation of the above equations, please refer to the Modeling a DC Motor page. With a 1 rad/sec step reference, the design criteria are: q Settling time less than 0.04 seconds q Overshoot less than 16% q No steady-state error q No steady-state error due to a disturbance
http://www.engin.umich.edu/group/ctm/examples/motor2/PID2.html (1 de 10) [21/11/2003 05:43:19 p.m.]
Now let's design a PID controller and add it into the system. First create a new m-file and type in the following commands(refer to main problem for the details of getting those commands). J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0]; Recall that the transfer function for a PID controller is:
Proportional control
Let's first try using a proportional controller with a gain of 1.7. Add the following code to the end of your m-file: Kp=1.7; numcf=[Kp]; dencf=[1]; numf=conv(numcf,num); denf=conv(dencf,den); To determine the closed-loop transfer function, we use the cloop command. Add the following line to your m-file: [numc,denc]=cloop(numf,denf); Note that numc and denc are the numerator and the denominator of the overall closed-loop transfer function. Now let's see how the step response looks. Add the following to the end of your m-file, and run it in the command window: t=0:0.001:0.2; step(numc,denc,t) You should get the following plot:
Now lets take a look at the step disturbance response. Add the following to the end of your m-file, and run it in the command window: numdcl=conv(numc,1); dendcl=conv(denc,Kp); step(numdcl,dendcl,t); You should get the following plot:
PID control
From the plots above we see that although the steady-state error looks good the settling time is too large, as is the overshoot. We also see that the steady-state error to a disturbance is large. Recall from PID tutorial page that adding an integral term will eliminate the steady-state error and a derivative term will reduce the overshoot. Let's first try a PI controller to get rid of the disturbance steady state error. Change your m-file so it looks like: J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0]; Kp=1.7; Ki=20; numcf=[Kp Ki]; dencf=[1 0]; numf=conv(numcf,num); denf=conv(dencf,den); [numc,denc]=cloop(numf,denf,-1); t=0:0.001:0.4; step(numc,denc,t)
http://www.engin.umich.edu/group/ctm/examples/motor2/PID2.html (4 de 10) [21/11/2003 05:43:19 p.m.]
Lets see what happened to the step disturbance response, add the following to your m-file: figure numdcl=conv(numc,dencf); dendcl=conv(denc,numcf); step(numdcl,dendcl,t); You should get the following plot:
Now we see that the response is faster than before, but the large Ki has worsened the transient response (big overshoot). Let's now try a PID controller to reduce the overshoot. Go back to the m-file and make the following changes to look at the step response. Kp=17; Ki=200; Kd=0.15; numcf=[Kd Kp Ki]; dencf=[1 0]; numf=conv(numcf,num); denf=conv(dencf,den); [numc,denc]=cloop(numf,denf,-1); t=0:0.001:0.1; step(numc,denc,t) Rerun it and you should get this plot:
We now see that our step response looks really good, it has less than 16% overshoot and the settling time is roughly 40ms, and there is no steady-state error. However the step disturbance response is now really slow. Lets increase Ki to speed up the disturbance response. Change Ki to 600 in your m-file and rerun the file. You should get the following plots:
We now can see that the step response has a settling time of roughly 40ms, it has less than 16% overshoot, and it has no steady state error. The step disturbance response also has no steady state error. So now we know that if we use a PID controller with Kp=17, Ki=600, Kd=.15,
http://www.engin.umich.edu/group/ctm/examples/motor2/PID2.html (9 de 10) [21/11/2003 05:43:19 p.m.]
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | PID | Modeling | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/24/97 WM
For the original problem setup and the derivation of the above equations and schematic, please refer to the bus modeling page. We want to design a feedback controller so that when the road disturbance (W) is simulated by a unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less than 5%. For example, when the bus runs onto a 10 cm
high step, the bus body will oscillate within a range of +/- 5 mm and will stop oscillating within 5 seconds. The system model can be represented in Matlab by creating a new m-file and entering the following commands (refer to main problem for the details of getting those commands). m1=2500; m2=320; k1 = 80000; k2 = 500000; b1 = 350; b2 = 15020; nump=[(m1+m2) b2 k2] denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2] num1=[-(m1*b2) -(m1*k2) 0 0] den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2] numf=num1; denf=nump;
where KP is the proportional gain, KI is the integral gain, and KD is the derivative gain. Let's assume that we will need all three of these gains in our controller. To begin, we might start with guessing a gain for each: KP=208025, KI=832100 and KD=624075. This can be implemented into Matlab by adding the following code into your m-file: KD=208025; KP=832100; KI=624075; numc=[KD,KP,KI]; denc=[1 0]; Now let's simulate the response of the system (the distance X1-X2) to a step disturbance on the road. From the schematic above we can find the transfer function from the road disturbance W to the output(X1-X2):
This transfer function can be modeled in Matlab by adding the following code into your m-file: numa=conv(conv(numf,nump),denc); dena=conv(denf,polyadd(conv(denp,denc),conv(nump,numc))); Note that the function "polyadd" is not a standard function in Matlab; you will need to copy it to a new m-file to use it. Click here for more information on defining new functions in Matlab. Refer to the bus modeling page, nump = denf as we can see in the matlab command above. Thus we can simplified this transfer function to be the following: numa=conv(numf,denc); dena=polyadd(conv(denp,denc),conv(nump,numc));
From the graph, the percent overshoot = 9%, which is 4% larger than the requirement, but the settling time is satisfied, less than 5 seconds. To choose the proper gain that yields reasonable output from the beginning, we start with choosing a pole and two zeros for PID controller. A pole of this controller must be at zero and one of the zeros has to be very close to the pole at the origin, at 1. The other zero, we will put further from the first zero, at 3, actually we can adjust the second-zero's position to get the system to fulfill the requirement. Add the following command in the m-file, so you can adjust the second-zero's location and choose the gain to have a rough idea what gain you should use for KD,KP, and KI. z1=1; z2=3; p1=0; numc=conv([1 z1],[1 z2]) denc=[1 p1] num2=conv(nump,numc); den2=conv(denp,denc); rlocus(num2,den2) title('root locus with PID controller') [K,p]=rlocfind(num2,den2) you should see the closed-loop poles and zeros on the s-plane like this and you can choose the gain and dominant poles on the graph by yourself:
We will explain root locus method in more detail in the "Root Locus" page.
To compare this graph with the graph of low-gain PID controller, you can change the axis: axis([0 5 -.01 .01])
Now we see that the percent overshoot and settling time meet the requirements of the system. The percent overshoot is about 5% of the input's amplitude and settling time is 2 seconds less than 5 seconds from requirement.
For this problem, it turns out that the PID design method adequately controls the system. This can been seen by looking at the root locus plot. Such a task can be achieved by simply changing only the gains of a PID controller. Feel free to play around with all three of the parameters,KD,KP and KI, as we suggested, but you will most likely get the response to have either large percent overshoot or very long settling time. But if you do find a good PID design, please email us with your results! We are always interested in different ways to solve our examples; we may include your solution in a future version of these tutorials.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Examples
6/20/97 PP 8/24/97 WM
where,
The design criteria (with the pendulum receiving a 1N impulse force from the cart) are: q Settling time of less than 5 seconds. q Pendulum should not move more than 0.05 radians away from the vertical. To see how this problem was originally set up, consult the inverted pendulum modeling page.
Open-loop Representation
The first thing to do when using PID control in Matlab is to find the transfer function of the system and to check to see if it makes sense. The transfer function found from the Laplace transforms for the output Phi (the pendulum's angle) can be set up using Matlab by inputting the numerator and denominator as vectors. Create an m-file (or a '.m' file located in the same directory as Matlab) and copy the following text to model the transfer function: M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3; %simplifies input
-(M+m)*m*g*l/q
-b*m*g*l/q]
0.1818
-31.1818
-4.4545
It will be easier to determine the appropriate transfer function to enter into Matlab if we first rearrange
http://www.engin.umich.edu/group/ctm/examples/pend/invPID.html (2 de 10) [21/11/2003 05:43:31 p.m.]
denc = 1.0000 4.7273 -26.6363 0.0910 0 Now we can begin the actual control of this system. First let's see what the impulse response looks like with the numbers we already have. Enter the following code to the end of your m-file: t=0:0.01:5; impulse(numc,denc,t) axis([0 1.5 0 40]) You should get the following velocity response plot from the impulse disturbance:
This response is still not stable. Let's start by increasing the proportional control to the system. Increase the k variable to see what effect it has on the response. If you set k=100, and set the axis to axis([0, 2.5, -0.2, 0.2]), you should get the following velocity response plot:
The settling time is acceptable at about 2 seconds. Since the steady-state error has already been reduced to zero, no more integral control is needed. You can remove the integral gain constant to see for yourself that the small integral control is needed. The overshoot is too high, so that must be fixed. To alleviate this problem, increase the kd variable. With kd=20, you should get a satisfactory result. You should now see the following velocity response plot:
As you can see, the overshoot has been reduced so that the pendulum does not move more than 0.05 radians away from the vertical. All of the design criteria have been met, so no further iteration is needed.
The feedback loop represents the controller we have designed for the pendulum's. The transfer function from the cart's position to the impulse force, with the PID feedback controller which we designed, is given as follows:
Recall that den1=den2 if the pole/zero at the origin that was cancelled is added back in. So the transfer function from X to F can be simplified to:
Now that we have the transfer function for the entire system, let's take a look at the response. First we need the transfer function for the cart's position. To get this we need to go back to the laplace transforms of the system equations and find the transfer function from X(s) to U(s). Below is this transfer function:
where,
For more about the Laplace transform please refer to the inverted pendulum modeling page. The pole/zero at the origin cancelled out of the transfer function for Phi, has been put back in. So that now den1 = den2, making calculations easier. Now, create a new m-file and run it in the command window: M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3; %simplifies input
q = (M+m)*(i+m*l^2)-(m*l)^2; num1 = [m*l/q 0 0]; den1 = [1 b*(i+m*l^2)/q num2 = [(i+m*l^2)/q den2 = den1 kd = 20; k = 100; ki = 1; numPID = [kd k ki]; denPID = [1 0]; 0
-(M+m)*m*g*l/q -m*g*l/q];
-b*m*g*l/q
0];
As you can see, the cart moves in the negative direction with a constant velocity. So although the PID controller stabilizes the angle of the pendulum, this design would not be feasible to implement on an actual physical system.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball & Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
The input (elevator deflection angle, delta e) will be 0.2 rad (11 degrees), and the output is the pitch angle (theta). The design requirements are q Overshoot: Less than 10% q Rise time: Less than 2 seconds q Settling time: Less than 10 seconds q Steady-state error: Less than 2% To see the original problem setup, please refer to the Pitch Controller Modeling page. Recall from the PID Tutorial page, the transfer function of a PID controller is:
We will implement combinations of proportional (Kp), integral (Ki), and derivative (Kd) controllers in an unity feedback system shown below to study the system output.
Proportional control
The first thing in solving this problem using PID control is to find a closed-loop transfer function with a proportional control (Kp). A closed-loop transfer function can be obtained either by hand or using the Matlab function called cloop. Either way, you should obtain the closed-loop transfer function as:
Note: Matlab cannot manipulate symbolic variables. To use the function cloop, enter the following commands to an m-file and run it in the Matlab command window. You should obtain the numerical coefficients of numerator and denominator of the closed-loop transfer function. Kp=[1]; %Enter any numerical value for the proportional gain num=[1.151 0.1774]; num1=conv(Kp,num); den1=[1 0.739 0.921 0]; [numc,denc]=cloop (num1,den1) For now, let the proportional gain (Kp) equal 2 and observe the system behavior. We will use the closed-loop transfer function derived by hand. Enter the following commands into a new m-file and run it in the Matlab command window. You should obtain the step response similar to the one shown below: de=0.2; Kp=2; numc=Kp*[1.151 0.1774]; denc=[1 0.739 1.151*Kp+0.921 0.1774*Kp]; t=0:0.01:30; step (de*numc,denc,t)
As you see, both the overshoot and the settling time need some improvement.
PD control
Recall from the PID Tutorial page, the derivative controller will reduce both the overshoot and the settling time. Let's try a PD controller. The closed-loop transfer function of the system with a PD controller is:
Using the commands shown below and with several trial-and-error runs, a proportional gain (Kp) of 9 and a derivative gain (Kd) of 4 provided the reasonable response. To comfirm this, change your m-file to the following and run it in the Matlab command window. You should obtain the step response similar to the one shown below: de=0.2; Kp=9; Kd=4; numc=[1.151*Kd 1.151*Kp+0.1774*Kd 0.1774*Kp]; denc=[1 0.739+1.151*Kd 0.921+1.151*Kp+0.1774*Kd 0.1774*Kp]; t=0:0.01:10; step (de*numc,denc,t)
http://www.engin.umich.edu/group/ctm/examples/pitch/PIDpitch.html (3 de 6) [21/11/2003 05:43:38 p.m.]
This step response shows the rise time of less than 2 seconds, the overshoot of less than 10%, the settling time of less than 10 seconds, and the steady-state error of less than 2%. All design requirements are satisfied.
PID Control
Even though all design requirements were satisfied with the PD controller, the integral controller (Ki) can be added to reduce the sharp peak and obtain smoother response. After several trial-and-error runs, the proportional gain (Kp) of 2, the integral gain (Ki) of 4, and the derivative gain (Kd) of 3 provided smoother step response that still satisfies all design requirements. To cofirm this, enter the following commands to an m-file and run it in the command window. You should obtain the step response shown below: Note: This time we are going to use the function cloop to find the closed-loop transfer function, and then obtain the step response. de=0.2; Kp=2; Kd=3; Ki=4; numo=[1.151 0.1774]; deno=[1 0.739 0.921 0]; numpid=[Kd Kp Ki]; denpid=[1 0];
Comments
1. To find appropriate gains (Kp, Kd, and Ki), you can use the table shown in PID Tutorial page; however, please keep in your mind that changing one gain might change the effect of the other two. As a result, you may need to change other two gains as you change one gain. 2. Our system with a PI controller do not provide the desired response; thus, a PI Control section was omitted from this page. You may confirm this by using the m-file shown in PID Control section, and set Kd equals to zero.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Control | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
Example: Solution to the Ball & Beam Problem Using PID Control
Closed-loop Representation Proportional Control Proportional-Derivative Control
The open-loop transfer function of the plant for the ball and beam experiment is given below:
The design criteria for this problem are: q Settling time less than 3 seconds q Overshoot less than 5% To see the derivation of the equations for this problem refer to the ball and beam modeling page.
Closed-loop Representation
The block diagram for this example with a controller and unity feedback of the ball's position is shown below:
First, we will study the response of the system shown above when a proportional controller is used. Then, derivative and/or integral control will be added if necessary. Recall, that the transfer function for a PID controller is:
Proportional Control
The closed-loop transfer function for proportional control with a proportional gain (kp) equal to 100, can be modeled by copying the following lines of Matlab code into an m-file (or a '.m' file located in the same directory as Matlab) m R g L d J = = = = = = 0.111; 0.015; -9.8; 1.0; 0.03; 9.99e-6; %simplifies input
[numc, denc] = cloop(numP, den) NOTE: Matlab commands from the control system toolbox are highlighted in red. You numerator and denominator should be:
numc = 0 0 0.2100
denc = 1.0000 0 0.2100 Now, we can model the system's response to a step input of 0.25 m. Add the following line of code to your m-file and run it: step(0.25*numc,denc) You should get the following output:
As, you can see the addition of proportional gain does not make the system stable. Try changing the value of kp and note that the system remains unstable.
Proportional-Derivative Control
Now, we will add a derivative term to the controller. Copy the following lines of code to an m-file and run it to view the system's response to this control method.
m R g L d J
= = = = = =
K = (m*g*d)/(L*(J/R^2+m)); num = [-K]; den = [1 0 0]; kp = 10; kd = 10; numPD = [kd kp];
numh = conv(num, numPD); [numc, denc] = cloop(numh, den); t=0:0.01:5; step(0.25*numc,denc,t) Your plot should be similar to the following:
Now the system is stable but the overshoot is much too high and the settling time needs to go down a bit. From the PID tutorial page in the section on characteristics of P, I, and D controllers, we see that by
http://www.engin.umich.edu/group/ctm/examples/ball/bbPID.html (4 de 7) [21/11/2003 05:43:43 p.m.]
increasing kd we can lower overshoot and decrease the settling time slightly. Therefore, make kd = 20 in your m-file and run it again. Your output should be:
The overshoot criterion is met but the settling time needs to come down a bit. To decrease the settling time we may try increasing the kp slightly to increase the rise time. The derivative gain (kd) can also be increased to take off some of the overshoot that increasing kp will cause. After playing with the gains a bit, the following step response plot can be achieved with kp = 15 and kd = 40:
As you can see from the above plot all the control objectives have been met without the use of an integral controller (settling time for this example is considered achieved when the response is less than 2% of it's final value). Remember, that for a control problem there is more than one solution for the problem. For other methods of controlling the ball and beam example, see the root locus, frequency response, and state-space links below.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball & Beam
Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
Example: Solution to the Cruise Control Problem Using Root Locus Method
Proportional Controller Lag controller
The open-loop transfer function for this problem is:
where
q q q q
The design criteria are: Rise time < 5 sec Overshoot < 10% Steady state error < 2% To see the original problem setup, refer to Cruise Control Modeling page.
Proportional controller
Recall from the Root-Locus Tutorial page, the root-locus plot shows the locations of all possible closed-loop poles when a single gain is varied from zero to infinity. Thus, only a proportional controller (Kp) will be considered to solve this problem. Then, the closed-loop transfer function becomes:
Also, from the Root-Locus Tutorial, we know that the Matlab command called sgrid should be used to find an acceptable region of the root-locus plot. To use the sgrid, both the damping ratio (zeta) and the natural frequency (Wn) need to be determined first. The following two equations will be used to find the damping ratio and the natural frequency:
where Wn=Natural frequency zeta=Damping ratio Tr=Rise time Mp=Maximum overshoot One of our design criteria is to have a rise time of less than 5 seconds. From the first equation, we see that the natural frequency must be greater than 0.36. Also using the second equation, we see that the damping ratio must be greater than 0.6, since the maximum overshoot must be less than 10%. Now, we are ready to generate a root-locus plot and use the sgrid to find an acceptable region on the root-locus. Create an new m-file and enter the following commands. hold off; m = 1000; b = 50; u = 10; numo=[1]; deno=[m b]; figure hold; axis([-0.6 0 -0.6 0.6]); rlocus (numo,deno) sgrid(0.6, 0.36) [Kp, poles]=rlocfind(numo,deno) figure hold;
http://www.engin.umich.edu/group/ctm/examples/cruise/ccRL.html (2 de 7) [21/11/2003 05:43:52 p.m.]
numc=[Kp]; denc=[m (b+Kp)]; t=0:0.1:20; step (u*numc,denc,t) axis ([0 20 0 10]) Running this m-file should give you the following root-locus plot.
The two dotted lines in an angle indicate the locations of constant damping ratio (zeta=0.6); the damping ratio is greater than 0.6 in between these lines and less than 0.6 outside the lines. The semi-ellipse indicates the locations of constant natural frequency (Wn=0.36); the natural frequency is greater than 0.36 outside the semi-ellipse, and smaller than 0.36 inside. If you look at the Matlab command window, you should see a prompt asking you to pick a point on the root-locus plot. Since you want to pick a point in between dotted lines (zeta>0.6) and outside the semi-ellipse (Wn>0.36), click on the real axis just outside the semi-ellipse (around -0.4). You should see the gain value (Kp) and pole locations in the Matlab command window. Also you should see the closed-loop step response similar to the one shown below.
With the specified gain Kp (the one you just picked), the rise time and the overshoot criteria have been met; however, the steady-state error of more than 10% remained.
Lag controller
To reduce the steady-state error, a lag controller will be added to the system. The transfer function of the lag controller is:
If you read the "Lag or Phase-Lag Compensator using Root-Locus" section in Lead and Lag Compensator page, the pole and the zero of a lag controller need to be placed close together. Also, it states that the steady-state error will be reduce by a factor of Zo/Po. For these reasons, let Zo equals -0.3
http://www.engin.umich.edu/group/ctm/examples/cruise/ccRL.html (4 de 7) [21/11/2003 05:43:52 p.m.]
and Po equals -0.03. Create an new m-file, and enter the following commands. hold off; m = 1000; b = 50; u = 10; Zo=0.3; Po=0.03; numo=[1 Zo]; deno=[m b+m*Po b*Po]; figure hold; axis ([-0.6 0 -0.4 0.4]) rlocus(numo,deno) sgrid(0.6,0.36) [Kp, poles]=rlocfind(numo,deno) figure t=0:0.1:20; numc=[Kp Kp*Zo]; denc=[m b+m*Po+Kp b*Po+Kp*Zo]; axis ([0 20 0 12]) step (u*numc,denc,t) Running this m-file should give you the root-locus plot similar to the following:
In the Matlab command window, you should see the prompt asking you to select a point on the root-locus plot. Once again, click on the real axis around -0.4. You should have the following response.
As you can see, the steady-state error has been reduced to near zero. Slight overshoot is a result of the zero added in the lag controller.
Now all of the design criteria have been met and no further iterations will be needed.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
CTM Example: Root Locus Design Method for DC Motor Speed Control
For the original problem setup and the derivation of the above equations, please refer to the Modeling a DC Motor page.
CTM Example: Root Locus Design Method for DC Motor Speed Control
With a 1 rad/sec step reference, the design criteria are: q Settling time less than 2 seconds q Overshoot less than 5% q Steady-state error less than 1% Now let's design a controller using the root locus method. Create a new m-file and type in the following commands (refer to main problem for the details of getting those commands). J=0.01; b=0.1; K=0.01; R=1; L=0.5; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];
CTM Example: Root Locus Design Method for DC Motor Speed Control
CTM Example: Root Locus Design Method for DC Motor Speed Control
poles = -6.0000 + 2.0511i -6.0000 - 2.0511i Note that the values returned in your Matlab command window may not be exactly the same, but should at least have the same order of magnitude. You should also get the following plot:
As you can see, the system is overdamped and the settling time is about one second, so the overshoot and settling time requirements are satisfied. The only problem we can see from this plot is the steady- state error of about 50%. If we increase the gain to reduce the steady-state error, the overshoot becomes too large (Try this yourself). We need to add a lag controller to reduce the steady-state error.
This can be done by changing your m-file to look like the following:
CTM Example: Root Locus Design Method for DC Motor Speed Control
J=0.01; b=0.1; K=0.01; R=1; L=0.5; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)]; z1=1; p1=0.01; numa = [1 z1]; dena = [1 p1]; numb=conv(num,numa); denb=conv(den,dena); rlocus(numb,denb) sgrid(.8,0) sigrid(2.3) title('Root Locus with a lag controller') numa and dena are the numerator and denominator of the controller, and numb and denb are the numerator and denominator of the overall open-loop transfer function. You should get the following root locus, which looks very similar to the original one:
CTM Example: Root Locus Design Method for DC Motor Speed Control
Your gain should be about 20. As you can see the response is not quite satisfactory. You may also note that even though the gain was selected to correlate with a position close to the damping criterion, the overshoot is not even close to five percent. This is due to the effect of the lag controller kicking in at a later time than the plant. (its pole is slower). What this means is that we can go beyond the dotted lines that represent the limit, and get the higher gains without worrying about the overshoot . Rerun your m-file, place the gain just above the white, dotted line. Keep trying until you get a satisfactory response. It should look similar to the following (we used a gain of around 50):
CTM Example: Root Locus Design Method for DC Motor Speed Control
The steady-state error is smaller than 1%, and the settling time and overshoot requirements have been met. As you can see, the design process for root locus is very much a trial and error process. That is why it is nice to plot the root locus, pick the gain, and plot the response all in one step. If we had not been able to get a satisfactory response by choosing the gains, we could have tried a different lag controller, or even added a lead controller.
User feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
CTM Example: Root Locus Design Method for DC Motor Speed Control
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/29/96 YS 8/24/97 WM
For the original problem setup and the derivation of the above equations, please refer to the Modeling a
DC Motor page. With a 1 rad/sec step reference, the design criteria are: q Settling time less than 0.04 seconds q Overshoot less than 16% q No steady-state error q No steady-state error due to a disturbance Now let's design a controller using the root locus method. Create a new m-file and type in the following commands (refer to main problem for the details of getting those commands). J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0];
If you look at the axis scales on this plot, one open-loop pole is very far to the left (further than -1x10^6). This pole does not affect the closed loop dynamics unless very large gains are used, where the system becomes unstable. We will ignore it by changing the axes to zoom in to just the lower-gain portion of the root locus (Click here for more info.) Add the following command to your m-file and re-run it. axis([-400 100 -200 200]) You should obtain the following plot in which you can see that the closed-loop system will be stable for small gains.
We can see from this plot that the closed-loop poles are never fast enough to meet the settling time requirement (that is, they never move to the left of the sigma=100 vertical line). Also, recall that we need an integrator in the controller (not just in the system) to remove steady-state error due to a disturbance.
Integral Control
Now, let's try using integral control to remove steady-state error to a disturbance. Modify your m-file so it looks like: J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0]; numcf=[1]; dencf=[1 0]; numf=conv(numcf,num); denf=conv(dencf,den); rlocus(numf,denf) sgrid(.5,0) sigrid(100) axis([-400 100 -200 200])
Note that this adds a 1/s term to the forward loop. In this m-file, we are ignoring the fast pole, and just zooming in to the low-gain portion of the root locus. Run this m-file and you will obtain the following plot.
From this root locus we can see that the closed-loop system under integral control is never stable, and another controller must be used.
Now, we have managed to stabilize the system with zero steady-state error to a disturbance, but the system will still not be fast enough.
Now, we can see that two of the closed-loop poles loop around well within both the settling time and percent overshoot requirements. The third closed loop pole moves from the open-loop pole at s=-59.2 to the open loop zero at s=-60. This closed-loop pole nearly cancels with the zero (which remains in the closed loop transfer function) because it is so close. Therefore, we can ignore it's effect. However, the other open-loop zero also remains in the closed-loop, and will affect the response, slowing it down, and adding overshoot. Therefore, we have to be conservative in picking where on the root locus we want the closed-loop poles to lie.
After doing this, you should see the following output in the Matlab command window. selected_point = -1.3943e+02+ 1.8502e+01i
k = 0.1309
poles = 1.0e+06 * -1.4542 -0.0001 + 0.0000i -0.0001 - 0.0000i -0.0001 Note that the values returned in your Matlab command window may not be exactly the same, but should at least have the same order of magnitude. You should also get the following step response plot:
As you can see, the system has an overshoot of approximately 15%, a settling time of approximately 0.04 seconds, and no steady-state error. Let's now look at the disturbance response by computing the closed-loop disturbance transfer function and plotting its step response. Add the following lines to your m-file: numdcl=conv(numc,dencf); dendcl=conv(denc,numcf); step(numdcl,dendcl,t); Re-run your m-file, selecting the same point on the root locus, and you will get the following plot.
You can see that the disturbance reaches a steady-state value of zero, and in fact, stays within 0.02 (or 2%) afte 0.04 seconds. Therefore, all the design requirements have been met. In this example, we placed zeros on the root locus to shape it the way we wanted. While some trial-and error is necessary to place the zeros, it is helpful to understand how the root locus is drawn, and Matlab is used to verify and refine the placement.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/7/97 JL 8/24/97 WM
CTM Example: Root Locus Design Method For Bus Suspension System
Example: Root Locus Design Method for the Bus Suspension System
Plotting the root locus Adding a notch filter Finding the gain from the root locus Plotting closed-loop response
From the main problem, the dynamic equations in transfer function form are the following:
For the original problem setup and the derivation of the above equations and schematic, please refer to the bus modeling page.
CTM Example: Root Locus Design Method For Bus Suspension System
If you are interested in running an animation of this example based on the control techniques used in the root locus tutorial please go to the bus suspension animation page after completing this tutorial. We want to design a feedback controller so that when the road disturbance (W) is simulated by a unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate within a range of +/- 5 mm and will stop oscillating within 5 seconds. The system model can be represented in Matlab by creating a new m-file and entering the following commands (refer to main problem for the details of getting those commands). m1=2500; m2=320; k1 = 80000; k2 = 500000; b1 = 350; b2 = 15020; nump=[(m1+m2) b2 k2] denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2] num1=[-(m1*b2) -(m1*k2) 0 0] den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2] numf=num1; denf=nump; We are now ready to design a controller using the root locus design method. First let's see what the open loop poles of the system are: R=roots(denp) Matlab should return: R = -23.9758 +35.1869i -23.9758 -35.1869i -0.1098 + 5.2504i -0.1098 - 5.2504i Therefore the dominant poles are the roots -0.1098+/-5.2504i, which are close to the complex axis with a small damping ratio.
CTM Example: Root Locus Design Method For Bus Suspension System
Note from the specification, we required the overshoot, %OS, to be less than 5% and damping ratio, zeta, can be find from approximation damping ratio equation, z = -log(%OS/100)/sqrt(pi^2+[log(%OS/100)^2]). The commandsgrid is used to overlay desired percent overshoot line on the close-up root locus, you can find more information from commands list. From the plot above, we see that there are two pair of the poles and zeros that are very close together. These pair of poles and zeros are almost on the imaginary axis, they might make the bus system marginally stable, which might cause a problem. We have to make all of the poles and zeros move into the left-half plane as far as possible to avoid an unstable system. We have to put two zeros very close to the two poles on the imaginary axis of uncompensated system for pole-and-zero cancellation. Moreover, we put another two poles further on the real axis to get fast response.
CTM Example: Root Locus Design Method For Bus Suspension System
Now let's change axis to see the details of the root locus. rlocus(conv(nump,numc),conv(denp,denc)) axis([-40 10 -30 30]) z=-log(0.05)/sqrt(pi^2+(log(0.05)^2)) sgrid(z,0) :
CTM Example: Root Locus Design Method For Bus Suspension System
You should see something similar to the following: selected_point = -2.9428 -13.0435i
K = 1.0678e+08
CTM Example: Root Locus Design Method For Bus Suspension System
-0.0294 + 0.1306i -0.0294 - 0.1306i -0.0292 + 0.0367i -0.0292 - 0.0367i Note that the value returned from your Matlab command window may not be exactly the same, but should at least have the same order of magnitude. This returned value can be used as the gain for the compensator. Add this gain to the system: numc=k*numc; Recall that the schematic of the system is the following:
To obtain the closed-loop transfer function from W to X1-X2, add the following to your m-file: numa=conv(conv(numf,nump),denc); dena=conv(denf,polyadd(conv(denp,denc),conv(nump,numc))); Note that the function "polyadd" is not a Matlab standard function. You will need to copy it to a new m-file to use it. Click here for more information.
CTM Example: Root Locus Design Method For Bus Suspension System
title('closed-loop response to 0.1m high step w/ notch filter') and you should see the following plot:
From this plot we see that when the bus encounters a 0.1 m step on the road, the maximum deviation of the bus body from the wheel (or the road) is about 3.75 mm, and the oscillations settle in 2 seconds. Thus this response is satisfactory. Note: A design problem does not necessarily have an unique answer. Using the root locus method (or any other method) may result in many different compensators. For practice, you may want to go back to the original open-loop root locus and try to find other good ways to add zeros and poles to get a better response. If you are interested in running an animation of the bus suspension example based on the control techniques used in this tutorial please go to the Bus Suspension Animation Page.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
CTM Example: Root Locus Design Method For Bus Suspension System
Modeling | PID | Root Locus | Frequency Response | State Space | Digital | Animation
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Examples
6/25/97 PP 8/24/97 WM
Example: Solution to the inverted pendulum problem using Root Locus method
Transfer functions Root locus design Lead-lag controller What happens to the cart's position?
The transfer function of the plant for this problem is given below:
where,
The design criteria (with the pendulum receiving a 1N impulse force from the cart) are: q Settling time of less than 5 seconds. q Pendulum should not move more than 0.05 radians away from the vertical. To see how this problem was originally set up, consult the inverted pendulum modeling page.
Transfer functions
The rlocus command in Matlab can find the root locus for a system described by state-space equations or by a transfer function. For this problem it will be easier in the long run to use a transfer function (the reason for this will become clear later). The transfer function found from the Laplace transforms for the output Phi (the pendulum's angle) can be set up using Matlab by inputting the numerator and denominator as vectors. Create an m-file (or a '.m' file located in the same directory as Matlab) and copy the following text to model the transfer function: M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3; %simplifies input
-(M+m)*m*g*l/q
-b*m*g*l/q]
3. Block Diagram
The control of this problem is a little different than the standard control problems you may be used to. Since we are trying to control the pendulum's position, which should return to the vertical after the initial disturbance, the reference signal we are tracking should be zero. The force applied to the cart can be added as an impulse disturbance. The schematic for this problem should look like the following.
It will be easier to determine the appropriate transfer function to enter into Matlab if we first rearrange the schematic as follows:
As you can see, one of the roots of the closed-loop transfer function is in the right-half-plane. This means that the system will be unstable. Look back at the root locus to see why. Part of the root locus lies between the origin and the pole in the right-half-plane. No matter what gain you chose, you will always have a closed-loop pole in this region, making your impulse response unstable. To solve this problem, we need to add another pole at the origin so all the zeros and poles at the origin will cancel each other out and multiple roots will be created in this right-half-plane region. The multiple roots can then be drawn into the left-half-plane to complete the design. Add the following to your m-file: p1 = 0; dentemp = [1 p1]; num2 = num; den2 = conv(den, dentemp); rlocus(num2,den2) sigrid(0.92) axis([-10 10 -10 10]) You should get the following root locus plot with multiple roots in the right-half-plane:
Now we can begin trying to draw the branches of the root locus into the left half plane. Enter the following two commands into the command window: roots(num2) roots(den2) If you are using the laplace transform transfer function, you should get the following output in the Matlab command window, ans = 0 ans = 0 -5.6041 5.5651 -0.1428 As you can see there are four poles and only one zero. This means there will be three asymptotes: one along the real axis in the negative direction, and the other two at 120 degree angles from this. For the state-space transfer function there will be one extra pole and zero. This configuration will never have the multiple roots in the left-half-plane. We must reduce the number of asymptotes from three to two by adding one more zero than pole the controller. If just a zero is added, then the intersection of the asymptotes (alpha) would be [(-5.6041+5.5651-0.1428+0+0)-(0+0+z2)]/2.
http://www.engin.umich.edu/group/ctm/examples/pend/invRL.html (5 de 13) [21/11/2003 05:44:15 p.m.]
This means the two asymptotes will leave the real axis at roughly -0.1-(1/2)z2. Making z2 as small as possible (assume near the origin) will not pull the multiple roots far enough into the left-half-plane to meet the design requirements (asymptotes will leave at about -0.1).
Lead-lag controller
The solution to this problem is to add another pole far to the left of the other poles and zeros. To keep the right number of asymptotes, another zero should be added as well. The placement of the added pole and zeros is not important except that the pole should be relatively large and the zeros should be relatively small. Try the m-file below to see what effect the poles and zeros have on the root locus. The polyadd function needs to be copied to the directory you are running Matlab in. M = .5; m = 0.2; b = 0.1; i = 0.006; g = 9.8; l = 0.3; q = (M+m)*(i+m*l^2)-(m*l)^2; num = [m*l/q 0]; den = [1 b*(i+m*l^2)/q z1 p1 z2 p2 = = = = 3; 0; 4; 50; %simplifies input
-(M+m)*m*g*l/q
-b*m*g*l/q];
numlag = [1 z1]; denlag = [1 p1]; numlead = [1 z2]; denlead = [1 p2]; num3 = conv(conv(num, numlead), numlag); den3 = conv(conv(den, denlead), denlag); rlocus(num3,den3) sigrid(0.92) axis([-50 50 -50 50]) figure rlocus(num3,den3) sigrid(0.92) axis([-10 10 -10 10])
http://www.engin.umich.edu/group/ctm/examples/pend/invRL.html (6 de 13) [21/11/2003 05:44:15 p.m.]
[k,poles]=rlocfind(num3,den3) figure numc = conv(conv(num,denlead),denlag); denc = polyadd(k*num3,den3); impulse(numc,denc) axis([0 2 -0.05 0.05]) The poles and zeros were found by trial and error. The only things to keep in mind was that one pole had to be at the origin, the other had to be far to the left, and the two zeros had to be small. Furthermore, I found that if the two zeros were close together and to the right of the farthest left plant pole, the response was better. You should see first the following root locus plot with the zeros and poles listed above:
The second plot should be of the same root locus magnified a little so that the root locus around the origin can be seen.
When prompted to pick a location on the root locus, chose a spot on the multiple roots just before they return to the real axis. Your velocity response to the impulse disturbance should look similar to the following:
The response now meets all of the requirements, so no further iteration is needed.
The feedback loop represents the controller we have designed for the pendulum. The transfer function from the cart's position to the impulse force, with the feedback controller which we designed, is given as follows:
Recall that den1=den2 if the pole/zero at the origin that was canceled is added back in. So the transfer function from X to F can be simplified to:
Transfer Function
Now that we have the transfer function for the entire system, let's take a look at the response. First we need the transfer function for the cart's position. To get this we need to go back to the laplace transforms of the system equations and find the transfer function from X(s) to U(s). Below is this transfer function:
where,
For more about the Laplace transform please refer to the inverted pendulum modeling page. The pole/zero at the origin canceled out of the transfer function for Phi, has been put back in. So that now den1 = den2, making calculations easier. Now, create a new m-file and run it in the command window: M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3; %simplifies input
q = (M+m)*(i+m*l^2)-(m*l)^2; num1 = [m*l/q 0 0]; den1 = [1 b*(i+m*l^2)/q num2 = [(i+m*l^2)/q den2 = den1 z1 p1 z2 p2 = = = = 3; 0; 4; 50; 0
-(M+m)*m*g*l/q -m*g*l/q];
-b*m*g*l/q
0];
numlag = [1 z1]; denlag = [1 p1]; numlead = [1 z2]; denlead = [1 p2]; num3 = conv(conv(num1, numlead), numlag); den3 = conv(conv(den1, denlead), denlag); subplot(1,1,1);rlocus(num3,den3) axis([-10 10 -10 10]) [k,poles]=rlocfind(num3,den3) numc = conv(conv(num1,denlead),denlag);
http://www.engin.umich.edu/group/ctm/examples/pend/invRL.html (11 de 13) [21/11/2003 05:44:15 p.m.]
denc = polyadd(k*num3,den3); t=0:0.01:6; subplot(2,1,1); impulse(numc,denc,t) axis([0 6 -0.05 0.05]) num4 = conv(num2,den3); den4 = polyadd(conv(den1,den3),k*conv(den1,num3)); subplot(2,1,2); impulse(num4,den4,t) axis([0 6 -0.1 0.1]) If you select the point on the root locus you selected before (near the real axis), you should see the following plot:
The top curve represents the pendulum's angle, and the bottom curve represents the cart's position. As
you can see, the cart moves, is stabilized at near zero for almost five seconds, and then goes unstable. It is possible that friction (which was neglected in the modeling of this problem) will actually cause the cart's position to be stabilized. Keep in mind that if this is in fact true, it is due more to luck than to anything else, since the cart's position was not included in the control design.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
The input (elevator deflection angle, delta e) will be 0.2 rad (11 degrees), and the output is the pitch angle (theta). The design requirements are q Overshoot: Less than 10% q Rise time: Less than 2 seconds q Settling time: Less than 10 seconds q Steady-state error: Less than 2% To see the original problem setup, please refer to the Pitch Controller Modeling page.
where, Wn=Natural frequency zeta=Damping ratio Ts=Settling time Tr=Rise time Mp=Maximum overshoot From these three equations, we can determine that the natural frequency (Wn) must be greater than 0.9 and the damping ratio (zeta) must be greater than 0.52. Let's generate a root-locus plot and use the sgrid to find the acceptable region of the locus. Create a new m-file and enter the following commands: num=[1.151 0.1774]; den=[1 0.739 0.921 0]; Wn=0.9; zeta=0.52; rlocus (num,den) sgrid (zeta,Wn) axis ([-1 0 -2.5 2.5]) Run this m-file in the Matlab command window. You should see the root-locus plot similar to the one shown below:
The two dotted lines in an angle indicate the locations of constant damping ratio, and the damping ratio is greater than 0.52 in between these lines. The dotted semi-ellipse indicates the locations of constant natural frequency, and the natural frequency is greater than 0.9 outside the semi-ellipse. As you may noticed, there is no root-locus plotted in our desired region. We need to bring the root-locus in between two dotted lines and outside the semi-ellipse by modifying the controller.
Lead compensator
We need to shift the root-locus more toward the left to get it inside our desired region. If you refer to the Designing Lead and Lag Compensators page, you will notice that the lead compensator can move the root locus to the left. The transfer function of a typical lead compensator is:
q q q
In general, the zero is placed in the neighborhood of the natural frequency criterion, and the pole is placed at a distance 3 to 20 times the value of the zero location. Let's place the zero (Zo) at 0.9 and the pole (Zo) at 20. This time, let Matlab functions conv and cloop determine the closed-loop transfer function with the lead compensator. Enter the following commands to an new m-file and run it in the Matlab command window. You should obtain the following root-locus plot:
http://www.engin.umich.edu/group/ctm/examples/pitch/RLpitch.html (3 de 6) [21/11/2003 05:44:21 p.m.]
num1=[1.151 0.1774]; den1=[1 0.739 0.921 0]; num2=[1 0.9]; den2=[1 20]; num=conv(num1,num2); den=conv(den1,den2); Wn=0.9; zeta=0.52; rlocus (num,den) axis ([-3 0 -2 2]) sgrid (zeta,Wn)
The root-locus has been generated in our desired region. Now, we are ready to pick a gain (K) and generate the step response corresponding to that gain. Add the following commands to the m-file shown above and run it in the command window. You should see a prompt asking you to pick a point on the root-locus plot. Pick a point close to the zero on the natural frequency criterion, say around -1 on real axis. This point should give you the gain around 200. You should see a step response similar to the one shown below. [K, poles]=rlocfind (num,den) de=0.2; [numc,denc]=cloop (K*num,den,-1); step (de*numc,denc)
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Root-Locus Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Control | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
Example: Solution to the Ball & Beam Problem Using Root Locus Method
Open-loop Root Locus Lead Controller Selecting a Gain Plotting the Closed-loop Response
The open-loop transfer function of the plant for the ball and beam experiment is given below:
The design criteria for this problem are: q Settling time less than 3 seconds q Overshoot less than 5% To see the derivation of the equations for this problem refer to the ball and beam modeling page. A schematic of the closed loop system with a controller is given below:
NOTE: Matlab commands from the control system toolbox are highlighted in red. Now, run the m-file and you should see the following root locus plot:
As you can see the system has two poles at the origin which go off to infinity along the imaginary axes. The design criteria can also be plotted onto the root locus using the sgrid command. This command generates a grid of constant damping ratio and natural frequency. The damping ratio and natural frequency were found using the following equation, which relates the them to our percent overshoot (PO) and settling time (Ts) requirements:
Note, that the equation with Ts is found by assuming settled is when the response remains within 2% of it's final value. From these equation damping ratio and natural frequency were found to be 0.7 and 1.9 respectively. sgrid(0.70, 1.9) axis([-5 5 -2 2])
The area between the two dotted diagnol lines represents locations where the percent overshoot is less than 5%. The area outside the curved line represents locations where the setttling time is less than 3 seconds. Note that no region of the plot falls within the design criteria shown be these lines. To remedy this and bring the root locus into the left-hand plane for stability we will try adding a lead-compensator to the system.
Lead Controller
A first order lead compensator tends to shift the root locus into the left-hand plane. For a more detailed description of lead compensators refer to the Lead & Lag Compensator Design page. A lead compensator has the form given below:
where, the magnitude of zo is less than the magnitude of po. Now, let us add the controller to the plant and view the root locus. We will position the zero near the origin to cancel out one of the poles. The pole of our compensator will be placed to the left of the origin to pull the root locus further into the left-hand plane. Add the following lines of Matlab code to your m-file. zo = 0.01; po = 5;
http://www.engin.umich.edu/group/ctm/examples/ball/bbRL.html (4 de 8) [21/11/2003 05:44:26 p.m.]
numlead = [1 zo]; denlead = [1 po]; numl = conv(num,numlead); denl = conv(den,denlead); rlocus(numl,denl) sgrid(0.70, 1.9) Run your m-file in the Matlab command window and you should see the following:
Now, the branches of the root locus are within our design criteria.
Selecting a Gain
Now that we have moved the root locus into the left-hand plane, we may select a gain that will satisfy our design requirements. We can use the rlocfind command to help us do this. Add the following onto the end of your m-file. [kc,poles]=rlocfind(numl,denl) Go to the plot and select a point near those indicated by the cross mark on the plot below:
You should see in the Matlab command window something similar to the following (your numbers will be slightly different): selected_point = -2.4988+ 1.2493i
kc = 37.3131
poles = -2.4950+ 1.2493i -2.4950- 1.2493i -0.0101 Now, we can plot the response with this gain.
From this plot we see that when a 0.25m step input is given to the system both the settling time and percent overshoot design criteria are met. Note: A design problem does not necessarily have a unique answer. Using this method (or any other) may result in many different compensators. Try running your m-file several more times selecting a different point each time and study the effect this has on the step response. For practice you may also want to go back to the original open-loop root locus and try to find other ways to add zeros and poles to get a better response.
User Feedback
http://www.engin.umich.edu/group/ctm/examples/ball/bbRL.html (7 de 8) [21/11/2003 05:44:26 p.m.]
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
q q q q
The design criteria are: Rise time < 5 sec Overshoot < 10% Steady state error < 2% To see the original problem set, see the Cruise Control Modeling page.
In order to use a Bode plot, the open-loop response must be stable. Let Kp equals 1 for now and see how the open-loop response looks like. Create an new m-file and enter the following commands. m = 1000; b = 50; u = 500; Kp=1; numo=[Kp]; deno=[m b]; step (u*numo,deno) Running this m-file in the Matlab command window should give you the following plot.
As you can see, the open-loop system is stable; thus, we can go ahead and generate the Bode plot. Change the above m-file by deleting step command and add in the following command. bode(numo,deno) Running this new m-file should give you the following Bode plot.
http://www.engin.umich.edu/group/ctm/examples/cruise/ccFR.html (2 de 11) [21/11/2003 05:44:52 p.m.]
Proportional controller
Let's see what system characteristics we can determine from the above Bode plot. Recall from the Root-Locus Tutorial, the bandwidth frequency (BW) (the frequency at the gain M(dB)=-6~-7.5dB) is roughly equals to the natural frequency (Wn). Using the equation,
the rise time (Tr) for our system can be determined to be extremely long since the gain shown above do not reach -6~-7.5dB. Moreover, we see from the Root-Locus Tutorial that the damping ratio is roughly equals to the phase margin (in degrees) divided by 100.
Since our phase margin is approximately 155 degrees, the damping ratio will be 1.55. Thus, we know that the system is overdamped (since the damping ratio is greater than 1). Finally, the steady-state error can be found from the following equation:
For our system, since the low frequency gain M(dB) is approximately -35dB, the steady-state error should be 98%. We can confirm these by generating a closed-loop step response.
In terms of the Bode plot, if we can shift the gain upward so that both the bandwidth frequency and the low frequency gain increase, then both the rise time and the steady-state error will improve. We can do that by increasing the proportional gain (Kp). Let's increase the proportional gain (Kp) to ,say, 100 and see what happens. Change the m-file to the following. m = 1000; b = 50; u = 10; Kp=100; numo=[Kp]; deno=[m b]; bode(numo,deno) Running this m-file in the Matlab command window should give you the following Bode plot.
Now, the low frequency gain is about 6dB (magnitude 2) which predicts the steady-state error of 33%. The bandwidth frequency is about 0.1 rad/sec so that the rise time should be around 18 seconds. Let's take a look at the closed-loop step response and confirm these.
As we predicted, both the steady-state error and the rise time have improved. Let's increase the proportional gain even higher and see what happens. Change the m-file to the following and rerun it. You should get the following Bode plot. m = 1000;
Now, the low frequency gain is approximately 20dB (magnitude 10) that predicts the steady-state error of 9%, and the bandwidth frequency is around 0.6 that predicts the rise time of 3 sec (within the desired value). Thus, both the steady-state error and the rise time should have been improved. Again, let's confirm these by generating the closed-loop step response.
If you noticed, the steady-state error will eventually reach the desired value by increasing the proportional gain even higher. However, by the time the steady-state error reaches the desired value, the rise time becomes too fast (unrealistic for the real physical system). Thus, let's leave the Kp as it is and implement a lag controller to handle the steady-state error problem.
Lag controller
If you take a look at the "Lag or Phase-Lag Compensator using Frequency Response"section of the Lead and Lag Compensator page, the lag controller adds gain at the low freqencies while keeping the bandwidth frequency at the same place. This is actually what we need: Larger low frequency gain to reduce the steady-state error and keep the same bandwidth frequency to maintain the desired rise time. The transfer function of the lag controller is shown below.
Now, we need to choose a value for a and T. Recall from the "Lag or Phase-Lag Compensator using Frequency Response" page, the steady-state error will decrease by a factor of a. The value T should be chosen so that two corner frequencies will not be placed close together because transient response gets worse. So let a equals 0.05 and T equals 700 and see what happens. Copy the following m-file and run it in the Matlab command window. You should see the following Bode plot.
Kp=600; numo=[Kp/b]; deno=[m/b 1]; a = 0.05; T=700; numlag = [a*T 1]; denlag = a*[T 1]; newnum = conv(numo,numlag); newden = conv(deno,denlag); bode(newnum,newden) figure [numc,denc]=cloop(newnum,newden); step (u*numc,denc)
Since the low frequency gain has increased while the bandwidth frequency stayed the same, the steady-state error should be reduced and the rise time should stay the same. Let's confirm this by generating a closed-loop step response.
It may be hard to see, but there should be a green, dotted line across just below 10. This line shows the steady-state value of the step, and we can see that the steady-state error has been met. However, the settling time is too long. To fix this, raise the proportional gain to Kp=1500. This gain was chosen from trial-and-error that will not be described here in the interest of length. With this change made, the following Bode and step response plots can be generated.
As you can see, the overshoot is in fact zero, the steady state error is close to zero, the rise time is about 2 seconds, and the settling time is less than 3.5 seconds. The system has now met all of the design requirements. No more iteration is needed.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
For the original problem setup and the derivation of the above equations, please refer to the Modeling a DC Motor page.
With the 1 rad/sec step input, the design criteria are: q Settling time less than 2 seconds q Overshoot less than 5% q Steady-state error less than 1% Create a new m-file and type in the following commands (refer to the main problem for the details of getting those commands). J=0.01; b=0.1; K=0.01; R=1; L=0.5; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];
The settling time is fast enough, but the overshoot and the steady-state error are too high. The overshoot can be reduced by reducing the gain a bit to get a higher phase margin, but this would cause the steady-state error to increase. A lag controller is probably needed.
which should reduce the steady-state error by a factor of 1/0.01 = 100 (but could increase the settling time). Go back and change your m-file so it looks like the following: num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)]; num=50*K; z=1; p=0.1; numa=[1 z]; dena=[1 p];
http://www.engin.umich.edu/group/ctm/examples/motor/freq2.html (5 de 8) [21/11/2003 05:44:59 p.m.]
numb=conv(num,numa); denb=conv(den,dena); bode(numb,denb) Rerun the file and you will get this plot:
The phase margin looks good. The steady-state error is predicted to be about 1/40dB or 1%, as desired. Close the loop and look at the step response. Add the following lines of code to the end of you m-file and rerun. [numc,denc]=cloop(numb, denb, -1); t=0:0.01:10; step(numc,denc,t)
Now you have a step response that meets the design requirements. The steady-state error is less than 1%, the overshoot is about 5%, and the settling time is about 2 seconds.
User feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/28/1996 YS 8/24/97 WM
For the original problem setup and the derivation of the above equations, please refer to the Modeling a DC Motor page. With a 1 rad/sec step reference, the design criteria are: q Settling time less than 40 milliseconds
q q q
Overshoot less than 16% No steady-state error No steady-state error due to a step disturbance
Adding an integrator
Now lets add an integrator for zero steady-state error in response to a step disturbance. Add the following lines to your m-file: numi=1; deni=[1 0]; numiol=conv(num,numi); deniol=conv(den,deni); bode(numiol,deniol,w) You should get the following plot:
From the bode plot we can see that we need 50 more degrees of phase at a frequency of 250 rad/sec. Lets now try a lead compensator to add exactly 50 degrees of phase. Add the following lines to your m-file: a=(1 - sin(PM*pi/180))/(1 + sin(PM*pi/180)); T=1/(wbw*sqrt(a)); numpil = conv([1 60],[T 1]); denpil = conv([1 0],[a*T 1]); numpilol = conv(numpil,num); denpilol = conv(denpil,den); w = logspace(2,3,101); bode(numpilol,denpilol,w)
This new Bode plot now shows that the phase margin is about right at 250 rad/sec, but the gain is too small by about 20 dB. The gain crossover must occur at 240 rad/sec. To bring the gain up by 20 dB we will multiply by a gain of 10. Add the following lines to your m-file: kpid = 10; bode(kpid*numpilol,denpilol,w) You should get the following plot:
Lets now check the step response of the closed loop system. Add the following lines to youe m-file: [numpilcl,denpilcl] = cloop(kpid*numpilol,denpilol,-1); t = 0:0.001:0.1; step(numpilcl,denpilcl) You should get the following plot:
The overshoot is now too large, however the settling time is better than expected. So let's try another design where the phase margin is larger, say around 70 degrees. Add the following lines to your m-file: PM=70; a=(1 - sin(PM*pi/180))/(1 + sin(PM*pi/180)); T=1/(wbw*sqrt(a)); numpil=conv([1 60],[T 1]); denpil=conv([1 0],[a*T 1]); numpilol=conv(numpil,num); denpilol=conv(denpil,den); w=logspace(2,3,101); bode(numpilol,denpilol,w) You should get the following plot:
This new bode plot shows that the phase margin is good at around 250 rad/sec, but the gain is too small by about 14 dB. The gain crossover must occur at 240 rad/sec. To bring the gain up we will multiply by a gain of 5. Add the following lines to your m-file: kpid = 5; bode(kpid*numpilol,denpilol,w) You should get the following plot:
Now lets check the step response again. Add the following lines to your m-file: [numpilcl,denpilcl] = cloop(kpid*numpilol,denpilol,-1); t = 0:0.001:0.1; step(numpilcl,denpilcl) You should get the following step response:
From the step response we now see that the overshoot is fine, but the settling time is too long. Let's try a slightly higher bandwidth. Add the following lines to your m-file: wbw=300; a=(1-sin(PM*pi/180))/(1+sin(PM*pi/180)); T=1/(wbw*sqrt(a)); numpil=conv([1 60],[T 1]); denpil=conv([1 0],[a*T 1]); numpilol=conv(numpil,num); denpilol=conv(denpil,den); w=logspace(2,3,101); bode(numpilol,denpilol,w) You should get the following plot:
This new bode plot shows that the phase margin is about right at a frequency of 250 rad/sec, but the gain is too small by about 18 dB. The gain crossover must occur at 240 rad/sec. To bring the gain up we will multiply by a gain of 8. Add the following lines to your m-file: kpid=8; bode(kpid*numpilol,denpilol,w); You should get the following plot:
Now let's check the step response of the closed loop system. Add the following lines to your m-file: [numpilcl,denpilcl]=cloop(kpid*numpilol,denpilol,-1); t=0:0.001:0.1; step(numpilcl,denpilcl) You should get the following step response:
Now everything looks good. We have less than 16% overshoot and a settling time of about 40 milliseconds.
Note: As you noticed, the frequency response method for this particular problem requires substantial
amount of trial and error runs. The m-file below is the simplified version of what was done above. After you run this m-file, you will get the last two plots shown above. J=3.2284E-6; b=3.5077E-6; K=0.0274; R=4; L=2.75E-6; num=K; den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2) 0]; PM=70; wbw=300; a=(1-sin(PM*pi/180))/(1+sin(PM*pi/180)); T=1/(wbw*sqrt(a));
numpil=conv([1 60],[T 1]); denpil=conv([1 0],[a*T 1]); numpilol=conv(numpil,num); denpilol=conv(denpil,den); kpid=8; w=logspace(2,3,101); bode(kpid*numpilol,denpilol,w) figure [numpilcl,denpilcl]=cloop(kpid*numpilol,denpilol,-1); t=0:0.001:0.1; step(numpilcl,denpilcl)
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 BRN
CTM Example: Frequency Response Design Method For Bus Suspension System
For the original problem and the derivation of the above equations and schematic, please refer to the bus modeling page. We want to design a feedback controller so that when the road disturbance (W) is simulated by a unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate within a range of +/- 5 mm and will stop oscillating within 5 seconds. The system model can be represented in Matlab by creating a new m-file and entering the following commands (refer to the
http://www.engin.umich.edu/group/ctm/examples/susp/freq1.html (1 de 8) [21/11/2003 05:45:13 p.m.]
CTM Example: Frequency Response Design Method For Bus Suspension System
main problem for the details of getting those commands). m1=2500; m2=320; k1 = 80000; k2 = 500000; b1 = 350; b2 = 15020; nump=[(m1+m2) b2 k2] denp=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2] num1=[-(m1*b2) -(m1*k2) 0 0] den1=[(m1*m2) (m1*(b1+b2))+(m2*b1) (m1*(k1+k2))+(m2*k1)+(b1*b2) (b1*k2)+(b2*k1) k1*k2] numf=num1; denf=nump;
For convenience in representing systems with different natural frequencies of the system, we normalize and scale our
CTM Example: Frequency Response Design Method For Bus Suspension System
finding before plotting the Bode plot, so that the low-frequency asymptote of each term is at 0 dB. This normalization by adjusting the gain, K, makes it easier to add the components of the Bode plot. The effect of K is move the magnitude curve up (increasing K) or down (decreasing K) by an amount 20*logK, but the gain, K, has no effect on the phase curve. Therefore from the previous plot, K must be equal to 100 dB or 100,000 to move the magnitude curve up to 0 dB at 0.1 rad/s. Go back to your m-file and add the following line of code to your m-file before the bode command and rerun: nump=100000*nump You should get the following bode plot:
To obtain T and a, the following steps can be used: 1: Determine the positive phase needed : Since we want 140 degrees total, we will need 70 degrees from each controller. 2: Determine the frequency where the phase should be added: In our case this frequency should be 5.0 rad/sec. 3: Determine the constant a from the equation below, this determines the required space between the zero and the pole for the desired maximum phase added.
4: Determine T and aT from the following equations, these determine the corner frequencies so that the maximum phase will be added at the desired frequency.
CTM Example: Frequency Response Design Method For Bus Suspension System
Now let's put our 2-Lead controller into the system and see what the Bode plot looks like. Add the following code to your m-file, and add a % in front of the previous bode command (if there is one): numc=conv([1.13426 1], [1.13426 1]); denc=conv([0.035265 1], [0.035265 1]); margin(conv(nump,numc),conv(denp,denc)) You should get the following Bode plot:
Since the Bode plot has a limited phase range (-360-0), the above plot is a little deceiving. The plot is equivalent to the following: w=logspace(-4,4); [mag,phase,w] = bode(conv(nump,numc),conv(denp,denc),w); subplot(2,1,1); semilogx(w,20*log10(mag)); grid title('Bode plot of system with notch filter') xlabel('Frequency (rad/s)') ylabel('20logM') subplot(2,1,2); semilogx(w,phase); axis([1e-4, 1e4, -180, 360]) grid xlabel('Frequency (rad/s)') ylabel('Phase (degrees)')
CTM Example: Frequency Response Design Method For Bus Suspension System
From this plot we see that the concave portion of the phase plot is above -180 degrees now, and the phase margin is large enough for the design criteria. Let's see how the output (the distance X1-X2) responds to a bump on the road (W). Recall that the schematic of the system is:
CTM Example: Frequency Response Design Method For Bus Suspension System
To obtain the closed-loop transfer function from W to X1-X2, the following commands can be added into the m-file: numa=conv(conv(numf,nump),denc); dena=conv(denf,polyadd(conv(denp,denc),conv(nump,numc))); Note that the function "polyadd" is not a Matlab standard function. You will need to copy it to a new m-file to use it. Click here for more information. Refer to the bus modeling page, nump = denf as we can see in the matlab command above. Thus we can simplified this transfer function to be the following: numa=conv(numf,denc); dena=polyadd(conv(denp,denc),conv(nump,numc));
CTM Example: Frequency Response Design Method For Bus Suspension System
The amplitude of response is a lot smaller than the percent overshoot requirement and the settling time also is less than 5 seconds. Since we can see that an amplitude of the output's response less than 0.0001 m or 1% of input magnitude after 4 seconds. Therefore we can say that the settling time is 4 seconds from the above plot. From the Bode plot above, we see that increasing the gain will increase the crossover frequency and thus make the response faster. We will increase the gain and see if we can get a better response. Go back to your m-file and change numc to numc=4*conv([3.1483 1],[3.1483 1]). Rerun the m-file and you should get the following plot:
CTM Example: Frequency Response Design Method For Bus Suspension System
From this plot we can see that the percent overshoot is about 0.15 mm less than the previous plot's and the settling time also less than 5 seconds. This response is now satisfactory and no more design iteration is needed.
User Feedback
We would liketo hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | Starting | Root Locus | Frequency Response | State Space | Examples
6/25/97 PP 8/24/97 WM
Example: Solution to the Inverted Pendulum Problem Using Frequency Response Method
Open-loop Representation Closed-loop response with no compensation Closed-loop response with compensation What happens to the cart's position?
The transfer function of the plant for this problem is given below:
where,
Note: There is a pole/zero cancellation in this transfer function. In previous examples these were removed from the transfer function. However, in this example they will be left in for reasons that will become clear later. The design criteria (with the pendulum receiving a 1N impulse force from the cart) are:
Settling time of less than 5 seconds. q Pendulum should not move more than 0.05 radians away from the vertical. To see how this problem was originally set up, consult the inverted pendulum modeling page.
q
Note: Before trying to work through this problem, it should be noted that this is a complicated problem to solve with the frequency response method. As you will soon find out, this problem has a pole in the right-half-plane, making it unstable. The frequency response method works best when the system is stable in the open loop. For this reason I would not suggest trying to follow this example if you are trying to learn how to use frequency response. This problem is for people who want to learn how to solve frequency response problems that are more complicated.
Open-loop Representation
The frequency response method uses the bode command in Matlab to find the frequency response for a system described by a transfer function in bode form. The transfer function found from the Laplace transforms for the output Phi (the pendulum's angle) can be set up using Matlab by inputting the numerator and denominator as vectors. Create an m-file (or a '.m' file located in the same directory as Matlab) and copy the following text to model the transfer function: M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3; %simplifies input
-(M+m)*m*g*l/q
-b*m*g*l/q
0]
If you try to model this system in Matlab, you will have all sorts of problems. The best way to use Matlab to solve this problem is to first change the schematic to something that can be modeled much more easily. Rearranging the picture, you can get the following new schematic:
Now we can begin our design. First, we will look at the poles and zeros of this function: x = roots(num) y = roots(den) x = 0 0 y = 0 -5.6041 5.5651 -0.1428 As you already know, we have a pole-zero cancellation at the origin, as well as one positive, real pole in the right-half plane. This means that we will need one anti-clockwise encirclement of -1 in order to have a stable closed-loop system (Z = P + N; P = 1, N = -1). The following m-file will be very useful for designing our controller. Please note that you will need the function polyadd.m to run this m-file. Copy and paste the function from your browser to a m-file in your directory (make sure the function command
http://www.engin.umich.edu/group/ctm/examples/pend/invFR.html (3 de 17) [21/11/2003 05:45:21 p.m.]
starts in the first column of the m-file). Note: Non-standard Matlab commands used in this example are highlighted in green.
function[ ] = pend() clf figure(1) clf %define TF num = [4.5455 den =[1.0000 figure(1)
0 0.1818
0];
%view compensated system bode bode(k*conv(numc,num), conv(denc,den)) %view compensated system nyquist figure(2) subplot (2,1,1) nyquist(k*conv(numc,num), conv(denc,den)) %view compensated CL system impulse response subplot(2,1,2) clnum = conv(num,denc); temp1 = k*conv(numc,num); temp2 = conv(denc, den); clden = polyadd(temp1,temp2); impulse (clnum,clden) Note: Matlab commands from the control system toolbox are highlighted in red. With this m-file we will now view the uncompensated system's Nyquist diagram by setting the controller numerator, denominator and gain equal to one. Enter pend at the command prompt, and enter 1 for numc, denc, and K. You should see the following plots in your screen:
Notice that the nyquist diagram encircles the -1 point in a clockwise fashion. Now we have two poles in the right-half plane (Z= P + N = 1 + 1). We need to add phase in order to get an anti-clockwise
http://www.engin.umich.edu/group/ctm/examples/pend/invFR.html (7 de 17) [21/11/2003 05:45:21 p.m.]
encirclement. We will do this by adding a zero to our controller. For starters, we will place this zero at -1. numc?.........[1 1] denc?.........[1 0] K?............1
as you can see, this wasn't enough phase. The encirclement around -1 is still clockwise. We are going to need to add a second zero. numc?.........conv([1 1],[1 1]) denc?.........[1 0] K?............1
We still have one clockwise encirclement of the -1 point. However, if we add some gain, we can make the system stable by shifting the nyquist plot to the left, moving the anti-clockwise circle around -1, so
http://www.engin.umich.edu/group/ctm/examples/pend/invFR.html (10 de 17) [21/11/2003 05:45:22 p.m.]
As you can see, the system is now stable. We can now concentrate on improving the response. We can modify the poles of the controller in order to do this. We have to keep in mind that small poles (close to the origin) will affect the response at small frequencies, while larger poles (farther from the origin) will affect the response at high frequencies. When designing via frequency response, we are interested in obtaining simple plots, since they will be easier to manipulate in order to achieve our design goal. Therefore, we will use these concepts to 'flatten' the frequency response (bode plot). At the same time, you will notice that the nyquist diagram will take an oval shape. If we try different combinations of poles and gains, we can get a very reasonable response. (Enter the command axis([0 5 -0.05 0.1]) after the pend command.) numc?.........conv([1 1.1],[1 5]) denc?.........[1 0] K?............10
Our response has met our design goals. Feel free to vary the parameters and observe what happens.
The feedback loop represents the controller we have designed for the pendulum. The transfer function from the cart's position to the impulse force, with the frequency response feedback controller which we designed, is given as follows:
Recall that den1=den2 (the two transfer functions G1 and G2 differ in numerator alone), so the transfer function from X to F can be simplified to:
Transfer Function
Now that we have the transfer function for the entire system, let's take a look at the response. First we need the transfer function for the cart's position. To get this we need to go back to the laplace transforms of the system equations and find the transfer function from X(s) to U(s). Below is this transfer function:
where,
For more about the Laplace transform please refer to the inverted pendulum modeling page. The pole/zero at the origin canceled out of the transfer function for Phi, has been put back in. So that now den1 = den2, making calculations easier. Now, create a new m-file and run it in the command window: M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3; %simplifies input
q = (M+m)*(i+m*l^2)-(m*l)^2; num1 = [m*l/q 0 0]; den1 = [1 b*(i+m*l^2)/q num2 = [(i+m*l^2)/q den2 = den1; 0
-(M+m)*m*g*l/q -m*g*l/q];
-b*m*g*l/q
0];
k = 10;
numcontroller = conv([1 1.1],[1 5]); dencontroller = [1 0]; numc = conv(numx,dencontroller); denc = polyadd(conv(dencontroller,den),k*conv(numcontroller,num)); t=0:0.01:100; impulse(numc,denc,t)
As you can see, the cart moves in the negative direction and stabilizes at about -0.18 meters. This design might work pretty well for the actual controller, assuming that the cart had that much room to move in. Keep in mind, that this was pure luck. We were not trying to design to stabilize the cart's position, and the fact that we have is a fortunate side effect.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
The input (elevator deflection angle, delta e) will be 0.2 rad (11 degrees), and the output is the pitch angle (theta). The design requirements are q Overshoot: Less than 10% q Rise time: Less than 5 seconds q Settling time: Less than 10 seconds q Steady-state error: Less than 2% To see the original problem setup, please refer to the Pitch Controller Modeling page.
Open-loop response
Recall from your control textbook that the frequency response design method is most effective for systems with stable open-loop. To check the open-loop stability of our system, create a new m-file, and enter the following commands. Running this m-file in the Matlab command window should give you the step response shown below: de=0.2;
http://www.engin.umich.edu/group/ctm/examples/pitch/FRpitch.html (1 de 11) [21/11/2003 05:45:28 p.m.]
Unfortunately, our system is unstable in open-loop; however, we can still design the feedback system via frequency response method (even though this might not be the easiest way). First, let's generate the open-loop Bode plot and see what it looks like. Change the m-file to the following and re-run it in the Matlab command window. You should see a Bode plot similar to the one shown below: num=[1.151 0.1774]; den=[1 0.739 0.921 0]; bode (num,den)
From our design requirements, we can determine that the natural frequency (Wn) must be greater than 0.9 and the damping ratio (zeta) must be greater than 0.52 (please refer to the Pitch Controller: Root-Locus method for details). Using two equations shown below, we see that the bandwidth frequency and the phase margin must be greater than 0.9 and 52 degrees, respectively.
Tr = Rise time q Wn = Natural frequency q BW = Bandwidth frequency q zeta = Damping ratio q PM = Phase margin Currently, we have the bandwidth frequency of 1 rad/sec and the phase margin of 80 degrees. These values are within our desired region. Let's plot the closed-loop step response and see what it looks like. Delete the bode command from the above m-file and add the following commands. Running this new m-file should give you the following closed-loop step response:
q
step (de*numc,denc,t)
As you can see, the transient response is worse that results in long settling time. We will implement a lead compensator to improve the system response.
Lead Compensator
Referring to the "Lead or phase-lead compensator using frequency response" section of Lead and Lag Compensator page, a lead compensator will add a positive phase to the system. An additional positive phase increases the phase margin; thus, increase damping. The settling time should decrease as a result of this increased damping. The transfer function of a typical first-order lead compensator is
We need to find alead, Tlead and Klead. First, the phase margin requirement and the following equation can be used to find alead
Since we are required to have the phase margin of greater than 52 degrees, the alead must be greater than 8.43. Using this alead, the bandwidth frequency requirement of greater than 0.9 and the following equation leads us to have the Tlead of smaller than 0.382.
http://www.engin.umich.edu/group/ctm/examples/pitch/FRpitch.html (4 de 11) [21/11/2003 05:45:28 p.m.]
Let the Klead equal 0.1, alead equal 10, and Tlead equal 0.3 for now and enter the following commands to an new m-file. num=[1 151 0.1774]; den=[1 0.739 0.921 0]; alead=10; Tlead=0.3; aleadtlead=alead*Tlead; k=0.1; numlead=k*[aleadtlead 1]; denlead=[Tlead 1]; num1=conv(num,numlead); den1=conv(den,denlead); bode(num1,den1) [numc,denc]=cloop(num1,den1,-1); de=0.2; t=0:0.01:10; figure step (de*numc,denc,t) Running this m-file in the Matlab command window gives you the following Bode and step response plots.
Although both bandwidth frequency and phase margin increased, the response still does not satisfy the design requirements. Let's increase alead and decrease Tlead. After several trial and error runs, an alead of 200, Tlead of 0.0025, and Klead of 0.05 , were found which gave the following lead compensator,
provided the desired transient response. To see the step response and the corresponding Bode plot, enter the following commands to an m-file and run it in the command window. You should see both the Bode plot and the step response shown below: num=[1 151 0.1774]; den=[1 0.739 0.921 0]; alead=200; Tlead=0.0025; aleadtlead=alead*Tlead; k=0.05; numlead=k*[aleadtlead 1]; denlead=[Tlead 1]; num1=conv(num,numlead); den1=conv(den,denlead); bode(num1,den1) [numc,denc]=cloop(num1,den1,-1); de=0.2; t=0:0.01:10; figure step (de*numc,denc,t)
If you compare the above Bode plot to the original Bode plot, you see both the phase margin and the bandwidth frequency have increased. Increasing both of them improves the rise time, the overshoot, and the settling time, as seen in the above step response plot. To improve the steady-state error, we will add a lag compensator to the system.
Lag compensator
Referring to the "Lag or phase-lag Compensator using frequency response" section of Lead and Lag Compensator page, a lag compensator reduces the steady-state error. The typical first-order transfer function of a lead compensator is
The steady-state error will be reduced by a factor of alag. From the above step response, we see that the steady-state error is roughly 10%. Thus, alag needs to be approximately 0.1. The Tlag should be greater than alag*Tlag because this compensator must not greatly change the transient response. After several trial and error runs, an alag of 0.1, Tlag of 20, and Klag of 1.5, were found which gave the following lag compensator,
provided the desired response. To see the step response and the corresponding Bode plot, enter the
http://www.engin.umich.edu/group/ctm/examples/pitch/FRpitch.html (8 de 11) [21/11/2003 05:45:28 p.m.]
following commands to an new m-file. Running this m-file in the command window should give you the two plots shown below: num=[1 151 0.1774]; den=[1 0.739 0.921 0]; alead=200; Tlead=0.0025; aleadtlead=alead*Tlead; k=0.05; numlead=k*[aleadtlead 1]; denlead=[Tlead 1]; num1=conv(num,numlead); den1=conv(den,denlead); Tlag=20; alag=0.1; at=alag*Tlag; k2=1.5; numlag=k2/alag*[at 1]; denlag=[Tlag 1]; num2=conv(num1,numlag); den2=conv(den1,denlag); bode (num2,den2) [numc2,denc2]=cloop(num2,den2,-1); figure step (0.2*numc2,denc2,t)
If you see the Bode plot, the low frequency gain has increased while keeping the bandwidth frequency the same. This tells us that steady-state error has reduced while keeping the same rise time. The above step response shows that the steady-state error got eliminated. Now all design requirements are satisfied.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
http://www.engin.umich.edu/group/ctm/examples/pitch/FRpitch.html (10 de 11) [21/11/2003 05:45:28 p.m.]
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
Example: Solution to the Ball & Beam Problem Using Frequency Response Method
Open-loop Bode Plot Phase-Lead Controller Adding More Phase
The open-loop transfer function of the plant for the ball and beam experiment is given below:
The design criteria for this problem are: q Settling time less than 3 seconds q Overshoot less than 5% To see the derivation of the equations for this problem refer to the ball and beam modeling page. A schematic of the closed loop system with a controller is given below:
NOTE: Matlab commands from the control system toolbox are highlighted in red. You should get the following Bode plot:
From this plot we see that the phase margin is zero. Since the phase margin is defined as the change in open-loop phase shift necessary to make a closed-loop system stable this means that our zero phase margin indicates our system is unstable. We want to increase the phase margin and we can use a lead compensator controller to do this. For more information on Phase and Gain margins please refer to the Frequency Response Tutorial.
Phase-Lead Controller
A first order phase-lead compensator has the form given below:
The phase-lead compensator will add positive phase to our system over the frequency range 1/aT and 1/T, which are called the corner frequencies. The maximum added phase for one lead compensator is 90 degrees. For our controller design we need a percent overshoot of 5, which corresponds to a zeta of 0.7. Generally zeta * 100 will give you the minimum phase margin needed to obtain your desired overshoot. Therefore we require a phase margin greater than 70 degrees. To obtain "T" and "a", the following steps can be used. 1. Determine the positive phase needed: We need at least 70 degrees from our controller. 2. Determine the frequency where the phase should be added (center frequency): In our case this is difficult to determine because the phase vs. frequency graph in the bode plot is a flat line. However, we have a relation between bandwidth frequency (wbw) and settling time (refer to the Bandwidth Frequency page for this equation) which tells us that wbw is approximately 1.92 rad/s. Therefore we want a center frequency just before this. For now we will choose 1. 3. Determine the constant "a" from the equation below, this determines the required space between the zero and the pole for the maximum phase added.
where phi refers to the desired phase margin. For 70 degrees, a = 0.0311. 4. Determine "T" and "aT" from the following equations:
For 70 degrees and center frequency (w) = 1, aT = 0.176 and T = 5.67 Now, we can add our lead controller to the system and view the bode plot. Remove the bode command from your m-file and add the following: k=1; numlead = k*[5.67 1]; denlead = [0.176 1]; numl = conv(num,numlead); denl = conv(den,denlead); bode(numl,denl) You should get the following bode plot:
You can see that our phase margin is now 70 degrees. Let's check the closed-loop response to a step input of 0.25m. Add the following to your m-file:
http://www.engin.umich.edu/group/ctm/examples/ball/bbFR.html (4 de 11) [21/11/2003 05:45:35 p.m.]
[numcl,dencl] = cloop(numl,denl); t=0:0.01:5; step(0.25*numcl,dencl,t) You should get the following plot:
Although the system is now stable and the overshoot is only slightly over 5%, the settling time is not satisfactory. Increasing the gain will increase the crossover frequency and make the response faster. Make k = 5, your response should look like:
The response is faster, however, the overshoot is much too high. Increasing the gain further will just make the overshoot worse.
%view compensated system bode plot pmr = pm*pi/180; a = (1 - sin(pmr))/(1+sin(pmr)); T = sqrt(a)/w; aT = 1/(w*sqrt(a)); numlead = k*[aT 1]; denlead = [T 1]; numl=conv(num,numlead); denl=conv(den,denlead); figure bode(numl,denl) %view step response [numcl,dencl]=cloop(numl,denl); t=0:0.01:5; figure step(0.25*numcl,dencl,t)
http://www.engin.umich.edu/group/ctm/examples/ball/bbFR.html (7 de 11) [21/11/2003 05:45:35 p.m.]
With this m-file you can choose the phase margin, center frequency, and gain. Run your m-file with the following values and you should see the plots below on your screen. Phase Margin?.......80 Center Frequency?...1 Gain?...............1
The overshoot is fine but the settling time is just a bit long. Try different numbers and see what happens. Using the following values the design criteria was met. Phase Margin?.......85 Center Frequency?...1.9 Gain?...............2
Note: A design problem does not necessarily have a unique answer. Using this method (or any other) may result in many different compensators. For practice you may want to go back and change the added phase, gain, or center frequency.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
where
q q q q q
The design criteria are: Rise time < 5 sec Overshoot < 10% Steady state error < 2% To see the original problem setup , see Cruise Control Modeling page.
where
q q q
Recall from the State-Space Tutorial page, we should use the technique called "pole placement" to obtain the desired output. Poles of a closed-loop system can be found from the characteristic equation: the determinate of [sI-(A-B*K)] matrix. If desired poles can be placed into the system by designing right control matrix (K), then the desired output can be obtained. In this tutorial, poles will be chosen first, then use Matlab to find the corresponding control matrix (K). Now, we need to determine where to place poles for our system. Since our [sI-(A-B*K)] matrix is 1x1, we have only one pole to place. Let the pole to be at -1.5 (arbitrary). Just as in the State-Space Tutorial, the Matlab function called place will be used to find the control matrix K . Create an new m-file and enter the following commands. m=1000; b=50; t=0:0.1:10; u=500*ones(size(t)); A=[-b/m]; B=[1/m]; C=[1]; D=[0]; x0=[0]; p1=-1.5; K=place(A,B,[p1]) A1=A-B*K; lsim(A1,B,C,D,u,t,x0); Running this m-file in the Matlab command window should give you the control matrix and the
http://www.engin.umich.edu/group/ctm/examples/cruise/ccSS.html (2 de 5) [21/11/2003 05:45:46 p.m.]
As you can see, the rise time is satisfactory, but the steady-state error is too large.
Reference input
Once again from the State-Space Tutorial, scaling factor called Nbar (the schematic is shown below) should be used to eliminate the steady-state error. Unlike the example in the Tutorial, the command rscale is not applicable for our system. Nbar needs to be determined manually.
After several trial-and-error runs, the Nbar equals 30 provided the desired step response. Copy the following commands to an m-file and run it in the Matlab command window. You should get the step response shown below. m=1000; b=50; t=0:0.1:10; u=500*ones(size(t));
A=[-b/m]; B=[1/m]; C=[1]; D=[0]; x0=[0]; p1=-1.5 K=place(A,B,[p1]); Nbar=30; A1=A-B*K; lsim(A1,B*Nbar,C,D,u,t,x0);
As you can see, the steady-state error has been eliminated. The rise time is less than 5 seconds and the overshoot is, in fact, zero. All the design requirements are satisfied.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
For the original problem setup and the derivation of the above equations, please refer to the Modeling a DC Motor page. With a 1 rad/sec reference added to the system, the design criteria are: q Settling time less than 2 seconds q Overshoot less than 5% q Steady-state error less than 1% Create a new m-file and type in the following commands (refer to the main problem for the details of getting these commands). J=0.01; b=0.1; K=0.01; R=1; L=0.5; A=[-b/J
K/J
Recall that the characteristic polynomial for this closed-loop system is the determinant of (sI-(A-BK)) where s is the Laplace variable. Since the matrices A and B*K are both 2x2 matrices, there should be 2 poles for the system. By designing a full-state feedback controller, we can move these two poles anywhere we want them. We shall first try to place them at -5 + i and -5-i (note that this corresponds to a zeta = 0.98 which gives 0.1% overshoot and a sigma = 5 which leads to a 1 sec settling time). Once we come up with the poles we want, Matlab will find the controller matrix,K, for us. Simply add the following code to the end of your m-file : p1 = -5 + i; p2 = -5 - i; K = place(A,B,[p1 p2]); Now look at the schematic above again. We see that after adding the K matrix into the system, the state-space equations become:
We can see the closed-loop response by simply adding the following line to the end of your m-file: t=0:0.01:3; step(A-B*K,B,C,D,1,t) Run your m-file in the command window, You should see the following plot:
We can find this Nbar factor by using the Matlab command rscale: Nbar=rscale(A,B,C,D,K) Note that the function rscale is not a standard function in Matlab. You will have to copy it before you use it. Click here for more information. Now we can plot the step response by adding the following line of code to your m-file: t=0:0.01:10; step(A-B*K,B*Nbar,C,D,1,t) title('Step Response with K Controller and Nbar')
This time, the steady-state error is much less than 1%, and all the other design criteria have been met as well.
User feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/28/1996 YS 8/24/97 WM
CTM Example: State Space Design Method for DC Motor Position Control
For the original problem setup and the derivation of the above equations, please refer to the Modeling DC Motor Position page. With a 1 rad reference added to the system, the design criteria are: q Settling time less than 0.04 seconds q Overshoot less than 16% q Zero steady-state error to a step input q Zero steady-state error to a step disturbance Create a new m-file and type in the following commands (refer to the main problem for the details of getting those commands). J=3.2284E-6; b=3.5077E-6;
CTM Example: State Space Design Method for DC Motor Position Control
K=0.0274; R=4; L=2.75E-6; A=[0 1 0 0 -b/J K/J 0 -K/L -R/L]; B=[0 ; 0 ; 1/L]; C=[1 0 0]; D=[0];
Recall that the characteristic polynomial for this closed-loop system is the determinant of (sI-(A-BKc)) where s is the Laplace variable. Since the matrices A and B*Kc are both 3x3 matrices, there should be 3 poles for the system. By designing a full-state feedback controller, we can move these three poles anywhere we want them. We shall first try to place them at -100 + 100i and -100-100i (note that this corresponds to a zeta = 0.5 which gives 0.16% overshoot and a sigma = 100 which leads to a .04 sec settling time). Once we come up with the poles we want, Matlab will find the controller matrix,Kc, for us. Simply add the following code to the end of your m-file : p1=-100+100i; p2=-100-100i; p3=-200; Kc=place(A,B,[p1,p2,p3]); Now look at the schematic above again. We see that after adding the K matrix into the system, the
http://www.engin.umich.edu/group/ctm/examples/motor2/ss2.html (2 de 8) [21/11/2003 05:45:59 p.m.]
CTM Example: State Space Design Method for DC Motor Position Control
We can see the closed-loop response by simply adding the following line to the end of your m-file: t=0:0.001:.05; step(A-B*Kc,B,C,D,1,t) Run your m-file in the command window, You should see the following plot:
Disturbance Response
In order to get the disturbance response, we must provide the proper input to the system. Physically, a disturbance is a torque which acts on the inertia of the motor. A torque acts as an additive term in the second state equation (which gets divided by J, as do all the other terms in this equation). We can simulate this simply by modifying our closed loop input matrix, B, to have a 1/J in the second row. Add the following line to your m-file and re-run.
CTM Example: State Space Design Method for DC Motor Position Control
step(A-B*Kc,[0;1/J;0],C,D,1,t)
This is not a zero steady-state error to a disturbance, and we will have to compensate for this.
CTM Example: State Space Design Method for DC Motor Position Control
We can model the integrator by augmenting our state equations with an extra state which is the integral of the output. This adds an extra equation which states that the derivative of the integral of theta is theta. This equation will be placed at the top of our matrices. The input, r, now enters the system before the integrator, so it appears in the newly added top equation. The output of the system remains the same.
These equations represent the dynamics of the system before the loop is closed. We will refer to the matrices in this equation as Aa, Ba, Ca, and Da. We will refer to the state vector of the augmented system as xa. Note that the reference, r, does not affect the states (except the integrator state) or the output of the plant - this is expected, since there is no path from the reference to the plant input, u, without implementing the feedback matrix, Kc. In order to find the closed loop equations, we have to look at how the input, u, affects the plant. In this case, it is exactly the same as in the unaugmented equations. Therefore, there is a vector, call it Bau, which replaces Ba when we are treating u as the input. This is just our old B vector with an extra zero added as a first row. Since u=Kc*xa is the input to the plant for the closed loop, but r is the input to the closed loop system, the closed loop equations will depend on both Bau and Ba. The closed loop equations will become:
Now, the integral of the output will be fed back, and will be used by the controller to remove steady state error to a disturbance. We can now redesign our controller. Since we need to place one closed-loop pole for each pole in the plant, we will place another pole at -300, which will be faster than the rest of the poles. Since the closed-loop system matrix depends on Bau, we will use Bau in the place command rather that Ba. Add the following to your m-file: Aa=[0 1 0 0 0 0 1 0 0 0 -b/J K/J
http://www.engin.umich.edu/group/ctm/examples/motor2/ss2.html (5 de 8) [21/11/2003 05:45:59 p.m.]
CTM Example: State Space Design Method for DC Motor Position Control
0 0 -K/L -R/L]; Ba=[ -1 ; 0 ; 0 ; 0]; Bau=[0 ; 0 ; 0 ; 1/L ]; Ca=[0 1 0 0]; Da=[0]; p4=-300; Kc=place(Aa,Bau,[p1,p2,p3,p4]); t=0:0.001:.05; step(Aa-Bau*Kc,Ba,Ca,Da,1,t) Run your m-file (or just these new lines) and you will get the following output.
To look at the disturbance response, we apply a similar B matrix as we did previously when simulating the disturbance response. step(Aa-Bau*Kc,[0 ; 0 ; 1/J ; 0] ,Ca,Da,1,t)
CTM Example: State Space Design Method for DC Motor Position Control
We can see that all of the design specifications have been met by this controller.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
CTM Example: State Space Design Method for DC Motor Position Control
Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control:RL
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/22/1997 JL 8/24/1997 WM
For the original problem setup and the derivation of the above equations, please refer to the Modeling page. We want to design a feedback controller so that when the road disturbance (W) is simulated by a unit step input, the output (X1-X2) has a settling time less than 5 seconds and an overshoot less than 5%. For example, when the bus runs onto a 10 cm high step, the bus body will oscillate within a range of +/- 5 mm and will stop oscillating within 5 seconds. The system model can be represented in Matlab by creating a new m-file and entering the following commands (refer to main problem for the details of getting those commands). We need to define the A, B, C, D matrices by entering the following into the m-file: m1=2500; m2=320; k1 = 80000; k2 = 500000; b1 = 350; b2 = 15020; A=[0 -(b1*b2)/(m1*m2) b2/m2 k2/m2 1 0 0 0 0 ((b1/m1)*((b1/m1)+(b1/m2)+(b2/m2)))-(k1/m1) -((b1/m1)+(b1/m2)+(b2/m2)) -((k1/m1)+(k1/m2)+(k2/m2)) 0 -(b1/m1) 1 0];
The characteristic polynomial for this closed-loop system is the determinant of (sI-(A-B[1,0]'K)). Note that it's not sI-(A-BK) because the controller K can only control the force input u but not the road disturbance W. Recall that our B matrix is a 4 x 2 matrix, and we only need the first column of B to control u. For this example, we have to use integral action to achieve zero steady-state error, so we add an extra state which is become X1, . Since in reality the bus will eventually reach an equilibrium that yields a zero steady-state error. New states Y1, and Y2. Also the state-space matrices, A,B,and C, after adding extra state change to be the following: 0 -(b1/m1) 1 0 0 0 0 0 0
Aa=[0 1 0 -(b1*b2)/(m1*m2) 0 ((b1/m1)*((b1/m1)+(b1/m2)+(b2/m2)))-(k1/m1) b2/m2 0 -((b1/m1)+(b1/m2)+(b2/m2)) k2/m2 0 -((k1/m1)+(k1/m2)+(k2/m2)) 0 0 1 0]; Ba=[0 0 1/m1 (b1*b2)/(m1*m2) 0 -(b2/m2) (1/m1)+(1/m2) -(k2/m2) 0 0]; Ca=[0 0 1 0 0]; Da=[0 0]; Actually, there is a shortcut for matlab to achieve the same result.
Aa Ba Ca Da
= = = =
Add the above matlab code into the m-file. In this case, we treated the problem like PID controller design. The integral control is obtained from the new state. The proportional control is obtained from a gain on Y1 or X1-X2. The direct derivative control for the output isn't possible, since derivative of Y1 or X1-X2 isn't a state. Instead we use the derivative of X1 , which is available for feedback. (While X1 maybe hard to measure, could be obtained by integrating the output of an accelerometer mounted on the bus.) It is similar to adding more damping to velocity of oscillation of the bus. Add the following matlab code for controller K in the m-file: K = [0 2.3e6 5e8 0 8e6] We arrive with this value of matrix with trial and error by adjusting gain for derivative of X1,Y1 and integral of Y1, as we previously mentioned.
We can now obtain the closed-loop response by simply adding the following code into your m-file. Note that we need to multiply B matrix by 0.1 to simulate 0.1 m high step disturbance: t=0:0.01:2; step(Aa-Ba(:,1)*K,-0.1*Ba,Ca,Da,2,t) title('Closed-loop response to a 0.1 m step') Running the m-file in the command window, you should see the following plot:
From the plot we see that the percent overshoot and settling time requirements are satisfied. Moreover the steady-state error approaches zero as well. Therefore, we will determine that the response is satisfactory. Feel free to play around with the gain for matrix K. But you will most likely get the response to have either large percent overshoot or very long settling time. But if you do find a better response, please email us with your results! We are always interested in different ways to solve our examples; we may include your solution in a future version of these tutorials.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Examples
6/25/97 PP 8/24/97 WM
The design criteria for this system with the cart receiving a 0.2 m step input are as follows: q Settling time for x and theta of less than 5 seconds. q Rise time for x of less than 1 second. q Overshoot of theta less than 20 degrees (0.35 radians). q Steady-state error within 2%. As you may have noticed if you went through some of the other inverted pendulum examples the design criteria for this example are different. In the other other examples we were dealing with an impulse and not a step input. Also, we were only concerned with the pendulums angle and disregarded the cart's position in the design of the controller. However, for an inverted pendulum it is unrealistic to consider just the single output system. Using state-space methods it is relatively simple to work with a
http://www.engin.umich.edu/group/ctm/examples/pend/invSS.html (1 de 11) [21/11/2003 05:46:12 p.m.]
multi-output system, so in this example we will design a controller with both the pendulum angle and the cart position in mind. To see how this problem was originally set up, consult the inverted pendulum modeling page. This problem can be solved using full state feedback. The schematic of this type of control system is shown below:
If you are interested in running an animation of this example based on the control techniques used in the state-space tutorial please go to the Inverted Pendulum Animation Page after completing this tutorial.
Open-loop poles
In this problem R represents the commanded step input to the cart. The 4 states represent the position and velocity of the cart and the angle and angular velocity of the pendulum. The output y contains both the position of the cart and the angle of the pendulum. We want to design a controller so that when an step input is given to the system, the pendulum should be displaced, but eventually return to zero (i.e. the vertical) and the cart should move to it's new commanded position. To view the system's open-loop response please refer to the inverted pendulum modeling Page The first step in designing this type of controller is to determine the open-loop poles of the system. Enter the following lines of code into a m-file (or a '.m' file located in the same directory as Matlab): M m b i g l = = = = = = 0.5; 0.2; 0.1; 0.006; 9.8; 0.3;
0;
0 0 0 1; 0 -(m*l*b)/p m*g*l*(M+m)/p 0]; B = [0; (i+m*l^2)/p; 0; m*l/p]; C = [1 0 0 0; 0 0 1 0]; D = [0;0]; p = eig(A) The Matlab command window should output the following text as a result: p = 0 -0.1428 5.5651 -5.6041 As you can see, there is one right-half-plane pole at 5.5651. This should confirm your intuition that the system is unstable in open loop.
LQR design
The next step in the design process is to assume that we have full-state feedback (i.e. that we can measure all four states), and find the vector K which determines the feedback control law. This can be done in a number of ways. If you know the desired closed-loop poles, you can use the place or acker command. Another option is to use the lqr function; this will give you the optimal controller (under certain assumptions; consult your textbook for more details). The lqr function allows you to choose two parameters, R and Q, which will balance the relative importance of the input and state in the cost function that you are trying to optimize. The simplest case is to assume R=1, and Q=C'*C. You may notice that we are using both outputs (the pendulum's angle and the cart's position). Essentially, the lqr method allows for the control of both outputs. In this case, it is pretty easy to do. The controller can be tuned by changing the nonzero elements in the Q matrix to get a desirable response. Note: Matlab commands from the control system toolbox are highlighted in red. To find the structure of Q, enter the following into the Matlab command window: C'*C You should see the following in the command window: ans = 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 The element in the 1,1 position will be used to weight the cart's position and the element in the 3,3 position will be used to weight the pendulum's angle. The input weighting R will remain at 1. Now that we know what the Q matrix should look like we can experiment to find the K matrix that will give us a good controller. We will go ahead and find the K matrix and plot the response all in one step so that changes can be made in the control and be seen automatically in the response. Enter the following text into your m-file: x=1; y=1; Q=[x 0 0 0; 0 0 0 0; 0 0 y 0; 0 0 0 0]; R = 1; K = lqr(A,B,Q,R) Ac = [(A-B*K)]; Bc = [B]; Cc = [C]; Dc = [D]; T=0:0.01:5; U=0.2*ones(size(T)); [Y,X]=lsim(Ac,Bc,Cc,Dc,U,T); plot(T,Y) legend('Cart','Pendulum') You should get the following value for K and a response plot: K = -1.0000 -1.6567 18.6854 3.4594
The curve in green represents the pendulum's angle, in radians and the curve in blue represents the cart's position in meters. As you can see, this plot is not satisfactory. The pendulum and cart's overshoot appear fine, but their settling times need improvement and the cart's rise time needs to go down. As I'm sure you have noticed the cart is not near the desired location but has in fact moved in the other direction. This error will be dealt with in the next section and right now we will focus on the settling and rise times. Go back to your m-file and change the x and y variables to see if you can get a better response. You will find that increasing x makes the settling and rise times go down, and lowers the angle the pendulum moves. Using x=5000 and y=100, the following value of K and step response were found: K = -70.7107 -37.8345 105.5298 20.9238
You may have noted that if you increased x and y even higher, you could improve the response even more. The reason this plot was chosen was because it satisfied the design requirements while keeping x and y as small as possible. In this problem, x and y have been used to describe the relative weight of the tracking error in the cart's position and pendulum's angle versus the control effort. The higher x and y are, the more control effort is used, but the smaller the tracking error. The system response has a settling time under 2 seconds.
Nbar can be found using the user-defined function rscale (copy it to the directory that your m-file is in). Delete the lsim line and copy the following to your m-file and run it to view the step response with Nbar added. Cn=[1 0 0 0]; Nbar=rscale(A,B,Cn,0,K) Bcn=[Nbar*B]; [Y,X]=lsim(Ac,Bcn,Cc,Dc,U,T); plot(T,Y) legend('Cart','Pendulum') Note: Non-standard matlab commands are highlighted in green. A different C had to be used because the rscale function will not work for multiple outputs. However, the Nbar found is correct, as you can see from the output below: Nbar = -70.7107
Now, the steady-state error is within our limits, the rise and settling times are met and the pendulum's overshoot is within range of the design criteria.
Observer design
This response is good, but was found assuming full-state feedback, which most likely will not be a valid assumption. To compensate for this, we will next design a full-order estimator to estimate those states that are not measured. A schematic of this kind of system is shown below, without Nbar:
To begin, we must first find the controller poles. To do this copy the following code to the end of your m-file:
p = eig(Ac) If you changed the weighting factors x and y above to x=5000 and y=100, you should see the following poles in the Matlab command window: p = -8.4910 + 7.9283i -8.4910 - 7.9283i -4.7592 + 0.8309i -4.7592 - 0.8309i We want to design estimator poles that are about 4-10 times as fast as slowest pole, say at -40. We will use the place command in Matlab to find the L vector (note that acker would also work). Remember that the place command cannot have all the desired poles at the same location. Delete from the lsim command on and enter the following text to the end of your m-file to find the L matrix: P = [-40 -41 -42 -43]; L = place(A',C',P)' We are using both outputs (the angle of the pendulum and the position of the cart) to design the observer. The system is not observable using only the angle of the pendulum as output; you can check this in Matlab by computing rank(obsv(A,C(2,:))). This should make sense to you: if you can only measure the angle of the pendulum, you cannot determine what the position of the cart will be. You should see the following in the Matlab window: L = 1.0e+03 * 0.0826 1.6992 -0.0014 -0.0762 -0.0010 -0.0402 0.0832 1.7604
Now we will combine the control-law design with the estimator design to get the compensator. The response should be similar to the one from the control-law design. To set up the compensator copy the following code to the end of your m-file: Ace = [A-B*K B*K; zeros(size(A)) (A-L*C)]; Bce = [ B*Nbar; zeros(size(B))]; Cce = [Cc zeros(size(Cc))]; Dce = [0;0]; T = 0:0.01:5;
http://www.engin.umich.edu/group/ctm/examples/pend/invSS.html (9 de 11) [21/11/2003 05:46:13 p.m.]
U = 0.2*ones(size(T)); [Y,X] = lsim(Ace,Bce,Cce,Dce,U,T); plot(T,Y) legend('Cart','Pendulum') After running this m-file, you should output the following step response simulation plot:
This response is about the same as before. All of the design requirements have been met with the minimum amount of control effort, so no more iteration is needed. As you can see, it is much easier to control multi-input or multi-output systems with the state space method than with any other of the methods. If you are interested in running an animation of the inverted pendulum example based on the control techniques used in this tutorial please go to the Inverted Pendulum Animation Page.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
The input (elevator deflection angle, delta e) will be 0.2 rad (11 degrees), and the output is the pitch angle (theta). The design requirements are q Overshoot: Less than 10% q Rise time: Less than 5 seconds q Settling time: Less than 10 seconds q Steady-state error: Less than 2%
To see the original problem setup, please refer to the Pitch Controller Modeling page. If you are interested in running an animation of this example based on the control techniques used in the state-space tutorial please go to the Pitch Controller Animation page after completing this tutorial.
must have the rank of n. The rank of the matrix is the number of independent rows (or columns). In the same token, for the system to be completely state observable, the observability matrix
must also have the rank of n. Since our controllability matrix and observability matrix are 3x3, the rank for both matrices must be 3. The Matlab command rank can give you the ranks of both matrices. Create a new m-file and enter the following commands: A=[-0.313 -0.0139 0 B=[0.232; 0.0203; 0]; C=[0 0 1]; D=[0]; co=ctrb (A,B); ob=obsv (A,C); 56.7 -0.426 56.7 0; 0; 0];
Controllability=rank(co) Observability=rank(ob) If you run this m-file in the Matlab command window, you should see Controllability = 3 Observability = 3 This proves that our system is both completely state controllable and completely state observable.
where K=Control matrix q x=State matrix (alpha, q, theta) q de=-Kx=input q R=Reference Recall from the State-Space Tutorial page, the "pole placement" technique should be used to find the control matrix (K). Since the determinate of [sI-(A-BK)] matrix is a third-order polynomial, there are three poles we can place.
q
In the State-Space Tutorial, the dominant second-order pole placement method was introduced. However for this example, we will use another method called Linear Quadratic Regulator (LQR) method. This method allows you to find the optimal control matrix that results in some balance between system errors and control effort. Please consult your control textbook for details. To use this LQR method, we need to find three parameters: performance index matrix (R), state-cost matrix (Q), and weighting factor (p). For simplicity, we will choose the performance index matrix equals 1 (R=1), and the state-cost matrix (Q)
equals to C' x C. The weighting factor (p) will be varied as we see the step response. To see the structure of the Q matrix, type in the following commands to an m-file and run it in the Matlab command window (or you can simply type them directly into the command window). C=[0 0 1]; Q=C'*C You should see the following Q matrix in the command window: Q = 0 0 0 0 0 0 0 0 1
Now we are ready to find the control matrix (K) and see the response of the system. First, let the weighting factor (p) equal 50. Enter the following commands to a new m-file and run it in the Matlab command window. t=0:0.1:10; de=0.2*ones(size(t)); yo=[0 0 0]; A=[-0.313 -0.0139 0 B=[0.232; 0.0203; 0]; C=[0 0 1]; D=[0]; p=50; Q=[0 0 0; 0 0 0; 0 0 p]; [K]= lqr (A,B,Q,1) lsim (A-B*K,B,C,D,de,t,yo) After you run this m-file, you should see the step response similar to the one shown below: 56.7 -0.426 56.7 0; 0; 0];
The rise time, overshoot, and settling time looks satisfactory. However, there is a large steady-state error. This can be easily corrected by introducing the feedforwarding scaling factor (Nbar).
Reference input
Unlike other design methods, the full-state feedback system does not compare the output to the reference; instead, it compares all states multiplied by the control matrix (K*x) to the reference (see the schematic shown above). Thus, we should not expect to see the output equal to the input. To obtain the desired output, we need to scale the reference input so that the output equals the reference. This can be easily done by introducing a feed-forwarding scaling factor called Nbar. The basic schematic with the scaling factor (Nbar) is shown below:
We can easily find Nbar from the Matlab function rscale. Since this rscale is a user-defined function, you need to copy and save the rscale m-file to your directory. For further assistance in using user-defined functions, refer to Function. After you have saved the rscale m-file to your directory, enter the following commands to a new m-file and run it in the Matlab command window. You should see the response shown below:
t=0:0.1:10; de=0.2*ones(size(t)); yo=[0 0 0]; A=[-0.313 -0.0139 0 B=[0.232; 0.0203; 0]; C=[0 0 1]; D=[0]; x=50; Q=[0 0 0; 0 0 0; 0 0 x]; [K]= lqr (A,B,Q,1) Nbar = rscale(A,B,C,D,K) lsim (A-B*K,B*Nbar,C,D,de,t,yo) 56.7 -0.426 56.7 0; 0; 0];
Now the steady-state error has been eliminated and all design requirements are satisfied.
If you are interested in running an animation of the pitch controller example based on the control techniques used in this tutorial please go to the Pitch Controller Animation page.
User Feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
State-Space Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Control | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
Example: Solution to the Ball & Beam Problem Using the State-space Design Method
Full-State Feedback Controller Reference Input
The state-space representation of the ball and beam example is given below:
Remember, unlike the previous examples where we controlled the gear's angle to control the beam and ball, here we are controlling alpha-doubledot. By doing this we are essentially controlling a torque applied at the center of the beam by a motor. Therefore, we do not need a gear and lever system. The design criteria for this problem are: q Settling time less than 3 seconds q Overshoot less than 5% To see the derivation of the state-space equations for this problem refer to the ball and beam modeling page. If you are interested in running an animation of this example based on the control techniques used in the state-space tutorial please go to the Ball & Beam Animation Page after completing this tutorial.
Recall, that the characteristic polynomial for this closed-loop system is the determinant of (sI-(A-BK)), where s is the Laplace variable. For our system the A and B*K matrices are both 4x4. Hence, there should be four poles for our system. In designing our full-state feedback controller we can move these poles anywhere we want. For our design we desire an overshoot of less than 5% which corresponds to a zeta of 0.7 (please refer to your textbook for the relationship between overshoot and damping ratio). On a root locus this criterion is represented as a 45 degree line emanating from the origin and extending out into the left-half plane. We want to place our poles on or beneath this line. Our next criterion is a settling time less than 3 seconds, which corresponds to a sigma = 4.6/Ts = 4.6/3 = 1.53, represented by a vertical line at -1.53 on the root locus. Anything beyond this line in the left-half plane is a suitable place for our poles. Therefore we will place our poles at -2+2i and -2-2i. We will place the other poles far to the left for now, so that they will not affect the response too much. To start with place them at -20 and -80. Now that we have our poles we can use Matlab to find the controller (K matrix) by using the place command. Copy the following code to an m-file to model the system and find the K matrix:
NOTE: Matlab commands from the control system toolbox are highlighted in red.
m R g J
= = = =
H = -m*g/(J/(R^2)+m);
A=[0 1 0 0 0 0 H 0 0 0 0 1 0 0 0 0]; B=[0;0;0;1]; C=[1 0 0 0]; D=[0]; p1=-2+2i; p2=-2-2i; p3=-20; p4=-80; K=place(A,B,[p1,p2,p3,p4]) Run your m-file and you should get the following output for the K matrix: place: ndigits= 15 K = 1.0e+03 * 1.8286 1.0286 2.0080 0.1040 After adding the K matrix, the state space equations now become:
We can now simulate the closed-loop response to a 0.25m step input by using the lsim command. Add the following to your m-file: T = 0:0.01:5; U = 0.25*ones(size(T)); [Y,X]=lsim(A-B*K,B,C,D,U,T); plot(T,Y) Run your m-file and you should get the following plot:
From this plot we see that there is a large steady state error for which we will need to add reference input (explained in next section). However, the overshoot and settling time criteria are met. If we wanted to reduce the overshoot further than we would make the imaginary part of the pole smaller than the real part. Also, if we wanted a faster settling time we would move the poles further in the left-half plane. Feel free to experiment with the pole positions to see these trends.
Reference Input
Now we want to get rid of the steady-state error. In contrast to the other design methods, where we feedback the output and compare it to the reference input to compute an error, with a full-state feedback controller we are feeding back both states. We need to compute what the steady-state value of the states should be, multiply that by the chosen gain K, and use a new value as our reference for computing the input. This can be done by adding a constant gain Nbar after the reference. The schematic below shows this relationship:
Nbar can be found using the user-defined function rscale (copy it to the directory that your m-file is in). Copy the following to your m-file and run it to view the step response with Nbar added. Nbar=rscale(A,B,C,D,K) T = 0:0.01:5; U = 0.25*ones(size(T)); [Y,X]=lsim(A-B*K,B*Nbar,C,D,U,T); plot(T,Y) Note: Non-standard Matlab commands used in this example are highlighted in green. Your output should be: place: ndigits= 15 Nbar = 1.8286e+03
Now the steady-state error is gone and all the design criteria are satisfied. Note: A design problem does not necessarily have a unique answer. Using this method (or any other) may result in many different compensators. For practice you may want to go back and try to change the pole positions to see how the system responds. If you are interested in running an animation of the ball & beam example based on the control techniques used in this tutorial please go to the Ball & Beam Animation Page.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
State-space Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball & Beam
http://www.engin.umich.edu/group/ctm/examples/ball/bbSS.html (6 de 7) [21/11/2003 05:46:26 p.m.]
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
where
q q q q
The design requirements are q Rise time: Less than 5 seconds q Overshoot: Less than 10% q Steady-state error: Less than 2%
arguments: Numerator matrix (num), denominator matrix (den), sampling time (Ts), and the 'method'. You should already be familiar with how to enter num and den matrices. The sampling time (Ts), in the unit of sec/sample, should be smaller than 1/(30*BW), where BW is the closed-loop bandwidth frequency. For the method, we will use the zero-order hold ('zoh'). Let the sampling time equals 1/50 sec assuming that the bandwidth frequency is 1 rad/sec. Now enter the following commands to an m-file and run it in the command window. num=[1]; den=[1000 50]; Ts=1/50; [numDz,denDz] = c2dm (num,den,Ts,'zoh') The following matrices should be returned to the command window. numDz = 1.0e-04* 0 denDz = 1.0000 -0.9990 0.1999
Root-Locus in z-plane
Recall from the Digital Control Tutorial, the Matlab function called zgrid should be used to find an acceptable region of the discrete root-locus that gives the desired gain (K). The zgrid requires two arguments: Natural frequency (Wn) and the damping ratio (zeta). These two arguments can be found from the rise time and the overshoot requirements and the following two equations.
where
q q q q
Since our rise time and overshoot requirements are 5 seconds and 10%, respectively, we can determine that the natural frequency (Wn) must be greater than 0.36 rad/sec and the damping ratio (zeta) must be greater than 0.6. Let's generate the root-locus and use the zgrid to find the acceptable region of the root-locus. But before doing that, if you refer to the Digital Control Tutorial, the natural frequency argument for zgrid needs to be in the unit of rad/sample, so let the Wn = 0.36*Ts = 0.0072 rad/sample. Now add the following commands to the above m-file and rerun it. You should get the following plot. Wn=0.0072; zeta=0.6; rlocus (numDz,denDz) zgrid (zeta, Wn) axis ([-1 1 -1 1])
The dotted line on the right, which is very small and can not be seen in this case, indicates the locations of constant natural frequency (Wn), and the natural frequency is greater than 0.0072 outside the line. The other dotted line indicates the locations of constant damping ratio (zeta), and the damping ratio is greater than 0.6 inside the line. In the above plot, you see that the root-locus is drawn in the desired region. Let's find a gain (K) using the Matlab function rlocfind and obtain the corresponding step response. Add the following commands to the above m-file and rerun it in the Matlab command window. [K,poles]=rlocfind (numDz,denDz) [numcDz,dencDz] = cloop (K*numDz,denDz); U=10; [x] = dstep (U*numcDz,dencDz,201); figure t=0:0.05:10; stairs (t,x) In the command window, you should see the prompt asking you to select a point on the root-locus. Click on the root-locus around +0.9. The gain (K) and the pole location should be returned to the command window. Also, you should see the closed-loop stairstep response shown below.
As you noticed, this response satisfies all of the design requirements. But the gain associated with this response is approximately 4500. The system having this large gain (too much control effort) might not be available in a real physical system , even though it is possible in the Matlab simulation. To obtain a desired response with a reasonable control effort, we will modify the discrete controller.
There is a guideline to design digital lead and lag compensators. However, design method described there generally applies for improving the system response. In this this particular problem, we are not going to use the method described in that page and use our own educated analysis to design the compensator. First, we need to reduce the gain (K) while keeping the reasonable response. Recall from your control textbook, the gain (K) equals 0 at poles and infinity at zeros. Thus, if we place the pole inside the desired region and pick a locus near that pole, we should have a reasonable response with smaller gain. Moreover, for the system to be stable, all poles must be placed inside the unit circle.
http://www.engin.umich.edu/group/ctm/examples/cruise/digCCRL.html (5 de 8) [21/11/2003 05:46:34 p.m.]
Consider these two things, we will place the compensator pole somewhere outside the natural frequency requirement and inside the damping ratio requirement, say at +0.6, and the zero at the left of that pole, say at -0.6. The location of this zero can be changed later, if necessary. Now we got the discrete compensator transfer function. Let's generate the root-locus and obtain the step response. Create an new m-file and enter the following commands. num=[1]; den=[1000 50]; Ts=1/50; [numDz,denDz] = c2dm (num,den,Ts,'zoh'); numleadDz=[1 denleadDz=[1 numDnew=conv denDnew=conv Wn=0.0072; zeta=0.6; rlocus (numDnew,denDnew) zgrid (zeta, Wn) axis ([-1 1 -1 1]) [K,poles] = rlocfind (numDnew,denDnew) [numcDnew,dencDnew] = cloop (K*numDnew,denDnew); U=10; [x] = dstep (U*numcDnew,dencDnew,201); figure t=0:0.05:10; stairs (t,x) Running this m-file in the command window give you the following root-locus. 0.6]; -0.6]; (numDz,numleadDz); (denDz,denleadDz);
In the command window, you should be asked to pick a point on the root-locus. Click on the locus near +0.9. You should now have the step response similar to the one shown below.
This response is about the same as what we obtained without the additional controller. However, if you check the command window, the gain has decreased to around 1000. This system satisfies all design requirements with the reasonable control effort. Note: A design problem does not necessarily have a unique answer. For practice, you may try other compensators to obtain a better response than the one shown above.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
CTM Example: Root Locus Design for Digital DC Motor Position Control
where: *electric resistance (R) = 4 ohm *electric inductance (L) = 2.75E-6 H *electromotive force constant (K=Ke=Kt) = 0.0274 Nm/Amp *moment of inertia of the rotor (J) = 3.2284E-6 kg*m^2/s^2 *damping ratio of the mechanical system (b) = 3.5077E-6 Nms *input (V): Source Voltage *output (sigma dot): Rotating speed *The rotor and shaft are assumed to be rigid The design requirements are: q Settling time: Less than 0.04 seconds q Overshoot: Less than 16% q Steady-state error: 0 with a step disturbance input
CTM Example: Root Locus Design for Digital DC Motor Position Control
den = 1.0000 -1.9425 0.9425 0.0000 As noticed in above results, both numerator and denominator of discrete transfer function have one extra root at z = 0. Also, we have to get rid of the leading zero coefficient in the numerator. To do this add the following code to cancel out these extra pole and zero to avoid numerical problem in Matlab. Otherwise it will consider both numerator and denominator to be fourth-order polynomial. numd = numd(2:3); dend = dend(1:3); Therefore, the discrete-time transfer function from the motor position output to the voltage input is:
CTM Example: Root Locus Design for Digital DC Motor Position Control
We would like to see what the closed-loop response of the system looks like when no controller is added. First, we have to close the loop of the transfer function by using the cloop command. After closing the loop, let's see how the closed-loop stairstep response performs by using the dstep and the stairs commands. The dstep command will provide the vector of discrete step signals and stairs command will connect these discrete signals (click here for more information). Add the following Matlab code at the end of previous m-file and rerun it. [numd_cl,dend_cl] = cloop(numd,dend); [x1] = dstep(numd_cl,dend_cl,501); t=0:0.001:0.5; stairs(t,x1) xlabel('Time (seconds)') ylabel('Position (rad)') title('Stairstep Response:Original') You should see the following plot:
CTM Example: Root Locus Design for Digital DC Motor Position Control
To get the zero steady-state error from the closed-loop response, we have to add an integral control. Recall that the integral control in the continuous- time is 1/s. If we use the backward difference approximation for mapping from the s-plane to the z-plane as described by s = 1/(z-1), one pole will be added at 1 on the root locus plot. After adding extra pole at 1, root locus will have three poles near 1, therefore the root locus will move out in the right half. The closed-loop response will be more unstable. Then we must add one zero near 1 and inside the unit circle to cancel out with one pole to pull the root locus in. We will add a pole at z = 0.95. In general, we must at least add as many poles as zeroes for the controller to be causal. Now add the following Matlab commands in to your m-file. numi = [1 -0.95];
CTM Example: Root Locus Design for Digital DC Motor Position Control
deni = [1 -1]; numad = conv(numd,numi); denad = conv(dend,deni); Recall from the Digital Control Tutorial page, the zgrid command should be used to find the desired region, which satisfies the design requirement, on the discrete root locus plot. The zgrid command requires two arguments: the natural frequency (Wn) and the damping ratio (zeta). From the design requirement, the settling time is less than 0.04 seconds and the percent overshoot is less than 16%. We know the formulas for finding the damping ratio and natural frequency as shown:
where: OS: the percent overshoot Ts: the settling time The required damping ratio is 0.5 and the natural frequency is 200 rad/sec, but the zgrid command requires a non-dimensional natural frequency. Therefore Wn = 200*T = 0.2 rad/sample. Add the following Matlab code into the end of your m-file and rerun it. rlocus(numad,denad); zgrid(0.5,0.2) title('Root Locus of system with integral control') You should get the following plot:
CTM Example: Root Locus Design for Digital DC Motor Position Control
From the above root locus plot, we can see that system is unstable at all gains because the root locus is outside the unit circle. Moreover, the root locus should be in the region where the damping ratio line and natural frequency cross each other to satisfy the design requirements. Thus we have to pull the root locus in more by first canceling the zero at approximately -0.98, since this zero will add overshoot to the step response. Then we have to add one more pole and two zeroes near the desired poles. After going through some trial and error to yield the root locus in the desired region, one more pole is added at 0.61 and two zeroes are added at 0.76. Add the following command in your m-file and rerun it in Matlab window. numc = conv([1 -0.76],[1 -0.76]); denc = conv([1 0.98],[1 -0.61]); numoc = conv(numad,numc); denoc = conv(denad,denc); rlocus(numoc,denoc); zgrid(0.5,0.2) title('Root Locus of Compensated System') The denoc will have a pole at 0.61 instead of -0.98. You should get the following root locus plot:
CTM Example: Root Locus Design for Digital DC Motor Position Control
From the above root locus plot, the root locus is drawn in the desired region. Let's find a gain, K, on the root locus plot by using the rlocfind command and obtain the stairstep response with the selected gain. Enter the following commands at the end of your m-file and rerun it. K = rlocfind(numoc,denoc) [numd_cl,dend_cl] = cloop(K*numoc,denoc); [x2] = dstep(numd_cl,dend_cl,251); t=0:0.001:0.25; stairs(t,x2) xlabel('Time (seconds)') ylabel('Position (rad)') title('Stairstep Response of Compensated System') In the Matlab window, you should see the command asking you to select the point on the root-locus plot. You should click on the plot as the following:
CTM Example: Root Locus Design for Digital DC Motor Position Control
The selected gain should be around 330, and it will plot the closed-loop compensated response as follows.
CTM Example: Root Locus Design for Digital DC Motor Position Control
From the above closed-loop response, the settling time is about 0.05 seconds which is satisfy the requirement, but the percent overshoot is 22% which is too large due to the zeroes. If we select the gain to be larger, the requirements will be satisfied. On the other hand, the problem will be unrealistic and a huge actuator is needed, you can try this yourself by picking a larger gain on the previous root locus plot which will yield an unrealistically sudden step response. So we have to move both one pole and two zeroes a little further to the right to pull root locus in a little bit more, new pole will be put at 0.7 and two zeroes should be at 0.85. Go back to your m-file and change only numc and denc as shown below and rerun it in Matlab window. numc = conv([1 -0.85],[1 -0.85]); denc = conv([1 0.98],[1 -0.7]); Then you should see the following root locus plot.
On the new root locus, you should click on the plot to select a new gain as the following:
CTM Example: Root Locus Design for Digital DC Motor Position Control
The selected gain should be around 450, and then it will plot the closed-loop compensated response as follows:
CTM Example: Root Locus Design for Digital DC Motor Position Control
Now we see that the settling time and percent overshoot meet the design require ments of the system. The settling time is 0.04 seconds and the percent overshoot is about 10%. Then let's take a look at a disturbance response of the closed-loop system by canceling the selected gain, the integral transfer function and controller's transfer function from the closed-loop transfer function. So add the following code into your m-file and rerun it. numcld = conv(numd_cl,conv(denc,deni)); dencld = conv(dend_cl,conv(K*numc,numi)); [x4] = dstep(numcld,dencld,251); t=0:0.001:.25; stairs(t,x4) xlabel('Time (seconds)') ylabel('Position (rad)') title('Stairstep Response of Compensated System') Matlab should return the following plot:
We can see that a response to the disturbance is small (3.3% of the disturbance ) and settles within 2% of the disturbance after 0.04 seconds and eventually reaches zero.
CTM Example: Root Locus Design for Digital DC Motor Position Control
User Feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/21/97 PP 8/24/97 WM
Where: * body mass (m1) = 2500 kg, * suspension mass (m2) = 320 kg, * spring constant of suspension system(k1) = 80,000 N/m, * spring constant of wheel and tire(k2) = 500,000 N/m, * damping constant of suspension system(b1) = 350 Ns/m. * damping constant of wheel and tire(b2) = 15,020 Ns/m. * control force (u) = force from the controller we are going to design. The design requirements are: Overshoot: Output (X1-X2) less than 5% of disturbance (W) Settling time: Less than 5 seconds
step(A,.1*B,C,D,2,0:0.0001:.005); This plot shows that the spring, K1 compresses very quickly, and exceeds our requirement of 5mm in response to a .1m step after only a little more than 0.001s. Therefore, we will set T=.0005s in order to give the controller a chance to respond.
Cd =
Dd = 0 0
Adding an Integrator
In this example, we will need to add an integrator to the system in order to drive the steady-state response to zero. We will add this integrator in series with the plant. This will have the effect of adding another state to the plant. We will add the integrator by representing it in state space and the using the series command. This command takes the A,B,C, and D matrices of the two systems to be connected in series as arguments and returns a new set of A,B,C, and D matrices. An integrator in discrete time state space can be represented as a trapezoidal approximation of integration over each sample period as follows:
To add this, add the following commands in your m-file: Ai=1; Bi=1; Ci=T; Di=T/2; [Ada,Bda,Cda,Dda]=series(Ad,Bd,Cd,Dd,Ai,Bi,Ci,Di) Matlab will return a new set of integrator-augmented state matrices, with dimension 5 rather than dimension 4. Unfortunately, the output of these equations is now the new integrated state. We must change the output Cda matrix to output the original output state. Add the following line: Cda=[Cd 0] Since the augmented state is the last state, this outputs the same state as the unaugmented equations.
zeros = 0.9986 + 0.0065i 0.9986 - 0.0065i -0.9929 We will select these three zeros as three of our desired closed-loop poles. One of the other two will be selected at .9992 since a pole there settles in approximately 10000 samples (or 5 seconds). The last pole will be selected at z=.2 since this is sufficiently fast to be insignificant. Add the following code to your m-file: p1=.97+.13i; p2=.97-.13i; p3=-.87; p1=zeros(1); p2=zeros(2); p3=zeros(3); p4=.9992; p5=.5; K=place(Ada,Bda*[1;0],[p1 p2 p3 p4 p5]) Matlab will return the following: place: ndigits= 19 K = 1.0e+09 * 0.0548 0.0000 1.0897 0.0011 0.0009
We can see in this plot, that the overshoot is less than 5mm, and the response settles well within 5 seconds.
User Feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/24/97 JL 8/24/97 WM
where M m b l I mass of the cart 0.5 kg mass of the pendulum 0.5 kg friction of the cart 0.1 N/m/sec length to pendulum center of mass 0.3 m inertia of the pendulum 0.006 kg*m^2
u step force applied to the cart x cart position coordinate phi pendulum angle from vertical Output are the cart displacement (x in meters) and the pendulum deflection angle (phi in radians). The design requirements are q Settling time for x and phi less than 5 seconds q Rise time for x of less than 1 second q Overshoot of phi less than 0.35 rad (20 deg) q Steady-state error of x and phi less than 2%
Discrete state-space
The first thing to do here is to convert the above continuous state-space equations to discrete state-space. To do this, we are going to use the Matlab function called c2dm. To use this c2dm, we need to specify six arguments: four state-space matrices (A, B, C, and D), sampling time (Ts in sec/sample), and the 'method'. You should already be familiar with how to enter A, B, C, and D matrices. The sampling time should be smaller than 1/(30*BW) sec, where BW is the closed-loop bandwidth frequency. The method we will use is the zero-order hold ('zoh'). Assuming that the closed-loop bandwidth frequencies are around 1 rad/sec for both the cart and the pendulum, let the sampling time be 1/100 sec/sample. Now we are ready to use c2dm. Enter the following commands to an m-file. M m b i g l = = = = = = .5; 0.2; 0.1; 0.006; 9.8; 0.3;
p = i*(M+m)+M*m*l^2; %denominator for the A and B matricies A = [0 1 0 -(i+m*l^2)*b/p 0 0 0 -(m*l*b)/p B = [ 0; (i+m*l^2)/p; 0; m*l/p]; 0 (m^2*g*l^2)/p 0 m*g*l*(M+m)/p 0; 0; 1; 0];
C = [1 0 0 0; 0 0 1 0]; D = [0; 0]; Ts=1/100; [F,G,H,J]=c2dm (A,B,C,D,Ts,'zoh') Running this m-file in the Matlab command window gives you the following four matrices.
F = 1.0000 0 0 0 G = 0.0001 0.0182 0.0002 0.0454 H = 1 0 J = 0 0 Now we have obtained the discrete state-space model of the form 0 0 0 1 0 0 0.0100 0.9982 0.0000 -0.0045 0.0001 0.0267 1.0016 0.3119 0.0000 0.0001 0.0100 1.0016
must have the rank of n. The rank of the matrix is the number of independent rows (or columns). In the same token, for the system to be completely state observable, the observability matrix
must also have the rank of n. Since our controllability matrix and observability matrix are '4x4', the rank of both matrices must be 4. The function rank can give you the rank of each matrix. In an new m-file, enter the following commands and run it in the command window. F = [1.0000 0 0 0.0100 0.9982 0.0000 0.0001 0.0267 1.0016 0.0000; 0.0001; 0.0100;
0 G =
-0.0045
0.3119
1.0016];
H =
J =
co = ctrb (F,G); ob = obsv (F,H); Controllability = rank (co) Observability = rank (ob) In the command window, you should see Controllability = 4 Observability = 4 This proves that our discrete system is both completely state controllable and completely state observable.
The next step is to assume that all four state are measurable, and find the control matrix (K). If you refer
to the continuous Inverted Pendulum: State-Space page, the Linear Quadratic Regulator (LQR) method was used to find the control matrix (K). In this digital version, we will use the same LQR method. This method allows you to find the optimal control matrix that results in some balance between system errors and control effort. Please consult your control textbook for details. To use this LQR method, we need to find three parameters: Performance index matrix (R), state-cost matrix (Q), and weighting factors. For simplicity, we will choose the performance index matrix equals 1 (R=1), and the state-cost matrix (Q) equals to H' x H. The weighting factors will be chosen by trial and errors. The state-cost matrix (Q) has the following structure Q = 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
The element in the 1,1 position will be used to weight the cart's position and the element in the 3,3 position will be used to weight the pendulum's angle. The weighting factors for the cart's position and the pendulum's angle will be chosen individually. Now we are ready to find the control matrix (K) and see the response of the system. Enter the following commands to an new m-file and run it in the Matlab command window. You should see the following step response. T=0:0.01:5; U=0.2*ones(size(T)); F = [1.0000 0 0 0 G = 0.0100 0.9982 0.0000 -0.0045 0.0001 0.0267 1.0016 0.3119 0.0000; 0.0001; 0.0100; 1.0016];
[0.0001; 0.0182; 0.0002; 0.0454]; [1 0 [0; 0]; %weighting factor for the cart position %weighting factor for the pendulum angle 0 0 0 1 0; 0];
H =
J =
x=1; y=1;
Q=[x 0 0 0;
http://www.engin.umich.edu/group/ctm/examples/pend/digINVSS.html (6 de 15) [21/11/2003 05:47:00 p.m.]
0 0 0 0; 0 0 y 0; 0 0 0 0]; R = 1; K = dlqr(F,G,Q,R) [Y,X]=dlsim(F-G*K,G,H,J,U); stairs(T,Y) legend('Cart (x)','Pendulum (phi)') Note: The function dlsim is the discrete version of the lsim and has very similar characteristics as dstep.
The curve in green represents the pendulum's angle, in radians, and the curve in blue represents the cart's position in meters. The pendulum's and cart's overshoot appear fine, but their settling times need improvement and the cart's rise time needs to be decreased. Also the cart has, in fact, moved in the opposite direction. For now, we will concentrate on improving the settling times and the rise times, and fix the steady-state error later. Let's increase the weighting factors (x and y) and see if both the settling and rise times decrease. Go back to your m-file and change the x and y to x=5000 and y=100. Running this m-file in the command window gives you the following new step response.
From this plot, we see that all design requirements are satisfied except the steady-state error of the cart position (x). We can easily correct this by introducing a feedforwarding scaling factor (Nbar).
Reference input
Unlike other design methods, the full-state feedback system does not compare the output to the reference; instead, it compares all states multiplied by the control matrix (K*x) to the reference (see the schematic shown above). Thus, we should not expect to see the output equals to the input. To obtain the desired output, we need to scale the reference input so that the output equals to the reference. This can be easily done by introducing a feedforwarding scaling factor called Nbar. The basic schematic with the Nbar is shown below.
Unfortunately, we can not use our user-defined function rscale to find Nbar. But certainly we can find it from trial and errors. After several trials, the Nbar equals to -61.55 provided the satisfactory response. Try the following m-file and obtain the step response shown below.
T=0:0.01:5; U=0.2*ones(size(T)); F = [1.0000 0 0 0 G = 0.0100 0.9982 0.0000 -0.0045 0.0001 0.0267 1.0016 0.3119 0.0000; 0.0001; 0.0100; 1.0016];
H =
J =
x=5000; %weighting factor for the cart position y=100; %weighting factor for the pendulum angle Q=[x 0 0 0 0 0 0 0 0 0 y 0 0; 0; 0; 0];
Notice that the steady-state error of the cart's position have been eliminated. Now we have designed the system that satisfies all design requirements.
Observer design
The above response satisfies all design requirements; however, it was found assuming all states are measurable. This assumption may not be valid for all systems. In this section, we develop a technique for estimating the states of a plant from the information that is available concerning the plant. The system that estimates the states of another system is called an observer. Thus, in this section we will design a full-order state observer to estimate those states that are not measurable. For further explanation on how an observer works, please consult your control textbooks. A basic schematic of the plant-observer system is shown below.
To design the observer, first, we need to find the L matrix. To find the L matrix, we need to find the poles of the system without the observer (the poles of F-G*K). Copy the following commands to an new m-file and run it in the Matlab command window. F = [1.0000 0 0 0 G = 0.0100 0.9982 0.0000 -0.0045 0.0001 0.0267 1.0016 0.3119 0.0000; 0.0001; 0.0100; 1.0016];
H =
J =
x=5000; %weighting factor for the cart position y=100; %weighting factor for the pendulum angle Q=[x 0 0 0 0 0 0 0 0 0 y 0 0; 0; 0; 0];
R = 1; K = dlqr(F,G,Q,R); poles = eig (F-G*K) In the command window, you should see
poles = 0.9156+0.0729i 0.9156-0.0729i 0.9535+0.0079i 0.9535-0.0079i We want to place observer poles so that the observer works a lot faster than the system without the observer. Let's place the observer poles far left of above poles, say, at [-0.3 -0.31 -0.32 -0.33]. These poles can be changed later, if necessary. We will use the Matlab function place to find the L matrix. Enter the following commands to an new m-file and run it. F = [1.0000 0 0 0 H = [1 0 0 0 0.0100 0.9982 0.0000 -0.0045 0 1 0.0001 0.0267 1.0016 0.3119 0; 0]; 0.0000; 0.0001; 0.0100; 1.0016];
P = [-0.3 -0.31 -0.32 -0.33]; L = place (F',H',P)' You should see the following L matrix in the command window. L =
Now we will obtain the overall system response including the observer. Once again, create an new m-file and copy the following code. T=0:0.01:5; U=0.2*ones(size(T)); F = [1.0000 0 0 0 G = 0.0100 0.9982 0.0000 -0.0045 0.0001 0.0267 1.0016 0.3119 0.0000; 0.0001; 0.0100; 1.0016];
H =
J =
x=5000; %weighting factor for the cart position y=100; %weighting factor for the pendulum angle Q=[x 0 0 0 0 0 0 0 0 0 y 0 0; 0; 0; 0];
R = 1; K = dlqr(F,G,Q,R) Nbar = -61.55; L = [2.6310 172.8146 -0.0129 -2.2954 -0.0105; -1.3468; 2.6304; 173.2787;
G*K; (F-L*H)];
Hce = [H zeros(size(H))]; Jce = [0;0]; [Y,X] = dlsim (Fce,Gce,Hce,Jce,U); stairs (T,Y) legend ('cart (x)','pendulum (phi)') After running this m-file, you should get the following step response.
As you noticed, this response is about the same as before, and all of the design requirements have been satisfied.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/21/97 DK
The input (elevator deflection angle, delta e) will be 0.2 rad (11 degrees), and the output is the pitch angle (theta). The design requirements are q Overshoot: Less than 10% q Rise time: Less than 2 seconds q Settling time: Less than 10 seconds
http://www.engin.umich.edu/group/ctm/examples/pitch/digPCSS.html (1 de 9) [21/11/2003 05:47:12 p.m.]
Discrete state-space
The first thing to do here is to convert above continuous state-space model to discrete state-space. To do this, we are going to use the Matlab function called c2dm. To use this c2dm, we need to specify six arguments: Four state-space matrices (A, B, C, and D), sampling time (Ts), and the 'method'. You should already be familiar with how to enter A, B, C, and D matrices. The sampling time should be smaller than 1/(30*BW), where BW is the closed-loop bandwidth frequency. The method we will use is the zero-order hold. From the closed-loop Bode plot, the bandwidth frequency was determined to be approximately 2 rad/sec (see this yourself) . Thus, to be sure we have small enough sampling time, we are going to use the sampling time of 1/100 sec/sample. Now we are ready to use the function c2dm. Enter the following commands to an m-file. A = [ -0.313 -0.0139 0 0.232; 0.0203; 0]; 56.7 -0.426 56.7 0; 0; 0];
B = [
C=[0 0 1]; D=[0]; Ts=1/100; [F,G,H,J] = c2dm (A,B,C,D,Ts,'zoh') Running this m-file in the Matlab command window gives you the following four matrices. F = 0.9968 -0.0001 0 G = 0.0024 0.0002 0.0001
http://www.engin.umich.edu/group/ctm/examples/pitch/digPCSS.html (2 de 9) [21/11/2003 05:47:12 p.m.]
0 0 1
must have the rank of n. The rank of the matrix is the number of independent rows (or columns). In the same token, for the system to be completely state observable, the observability matrix
must also have the rank of n. Since our controllability matrix and observability matrix are 3x3, the rank
http://www.engin.umich.edu/group/ctm/examples/pitch/digPCSS.html (3 de 9) [21/11/2003 05:47:12 p.m.]
of both matrices must be 3. The Matlab function rank can give you the rank of each matrices. In an new m-file, enter the following commands and run it. F = [0.9968 -0.0001 0 G = [0.0024; 0.0002; 0.0001]; H = [0 J = [0]; co = ctrb (F,G); ob = obsv (F,H); Controllability = rank (co) Observability = rank (ob) In the command window, you should see Controllability = 3 Observability = 3 This proves that our discrete system is both completely state controllable and completely state observable. 0 1]; 0.05649 0.9957 0.5658 0 0 1];
where
q q q q
In the continuous Pitch Controller: State-Space page, the Linear Quadratic Regulator (LQR) method was used to find the control matrix (K). In this digital version, we will use the same LQR method. This method allows you to find the optimal control matrix that results in some balance between system errors and control effort. Please consult your control textbook for details. To use this LQR method, we need to find three parameters: Performance index matrix (R), state-cost matrix (Q), and weighting factor (p). For simplicity, we will choose the performance index matrix equals 1 (R=1), and the state-cost matrix (Q) equals to H' x H. The weighting factor (p) will be chosen by trial and errors. The state-cost matrix (Q) has the following structure Q = 0 0 0 0 0 0 0 0 1
Now we are ready to find the control matrix (K) and see the response of the system. First, let the weighting factor (p) equals 50. Enter the following commands to a new m-file and run it in the Matlab command window. t=0:0.01:10; de=0.2*ones(size(t)); F = [0.9968 -0.0001 0 G = [0.0024; 0.0002; 0.0001]; 0.05649 0.9957 0.5658 0 0 1];
H = [0 J = [0]; p=50;
1];
(t,x)
After you run this m-file, you should see the control matrix (K) in the command window and the step response similar to the one shown below.
The rise time, the overshoot, and the settling time look satisfactory. However, there is a large steady-state error. This can be easily corrected by introducing the feedforwarding scaling factor (Nbar).
Reference input
Unlike other design methods, the full-state feedback system does not compare the output to the reference; instead, it compares all states multiplied by the control matrix (K*x) to the reference (see the schematic shown above). Thus, we should not expect to see the output equals to the input. To obtain the desired
http://www.engin.umich.edu/group/ctm/examples/pitch/digPCSS.html (6 de 9) [21/11/2003 05:47:12 p.m.]
output, we need to scale the reference input so that the output equals to the reference. This can be easily done by introducing a feedforwarding scaling factor called Nbar. The basic schematic with the Nbar is shown below.
Unfortunately, we can not use our user-defined function rscale to find Nbar. But certainly we can find it from trial and errors. After several trials, the Nbar equals to 6.95 provided the satisfactory response. Try the following m-file and obtain the stairstep response shown below. t=0:0.01:10; de=0.2*ones(size(t)); F = [0.9968 -0.0001 0 G = [0.0024; 0.0002; 0.0001]; H = [0 J = [0]; p=50; Q = [0 0 0 0 0 0 0 0 p]; [K,S,E] = dlqr (F,G,Q,1) Nbar = 6.95; [x] = dlsim (F-G*K,G*Nbar,H,J,de); stairs (t,x) 0 1]; 0.05649 0.9957 0.5658 0 0 1];
From this plot, we see that the Nbar eliminated the steady-state error. Now all design requirements are satisfied.
Note: Assuming all states are measurable, an observer design will not be explained in this page.
User feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control: SS
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
Digital Control Example: Ball and Beam problem using PID Control
Digital PID controller Discrete transfer function Open-loop response Proportional control Proportional-Derivative control
In this digital control version of the ball and beam experiment, we are going to use the PID control method to design the digital controller. If you refer to the Ball and Beam Modeling page, the open-loop transfer function was derived as
m mass of the ball 0.11 kg g gravitational acceleration 9.8 m/s^2 d lever arm offset 0.03 m L length of the beam 1.0 m R radius of the ball 0.015 m J ball's moment of inertia 9.99e-6 kgm^2 R(s) ball position coordinate (m) theta(s) servo gear angle 0.25 rad The design criteria for this problem are: q Settling time less than 3 seconds
http://www.engin.umich.edu/group/ctm/examples/ball/digBBPID.html (1 de 7) [21/11/2003 05:47:18 p.m.]
As you noticed the above transfer function was written in terms of s. For the digital PID control, we use the following transfer function in terms of z.
Running this m-file in the Matlab command window gives you the following matrices. numDz = 1.0e-0.4 * 0 denDz = 1 -2 1 0.4200 0.4200
Open-loop response
Now we will observe the ball's response to a step input of 0.25 m. To do this, enter the following commands to an new m-file and run it in the command window. You should see the following response. numDz = 0.0001*[0.42 0.42]; denDz = [1 -2 1]; [x] = dstep (0.25*numDz,denDz,251); t=0:0.02:5; stairs(t,x)
From this plot, it is clear that the open-loop system is unstable causing the ball to roll off from the end of the beam.
Proportianal Control
Now we will add the proportional control (Kp) to the system and obtain the closed-loop system response. For now let Kp equal to 100 and see what happens to the response. Enter the following commands to an new m-file and run it in the command window. numDz = 0.0001*[0.42 0.42]; denDz = [1 -2 1]; Kp=100; [numDzC,denDzC]=cloop (Kp*numDz,denDz); [x] = dstep (0.25*numDzC,denDzC,251); t=0:0.02:5; stairs(t,x)
As you can see, the addition of proportional control does not make the system stable. You may try to increase the proportional gain (Kp) and confirm that the system remains unstable.
Proportional-Derivative control
Now we will add a derivative term to the controller. Keep the proportional gain (Kp) equal to 100, and let the derivative gain (Kd) equal to 10. Copy the following code to an new m-file and run it to view the system response. numDz = 0.0001*[0.42 0.42]; denDz = [1 -2 1]; Kp=100; Kd=10; numpd = [Kp+Kd -(Kp+2*Kd) Kd]; denpd = [1 1 0]; numDnew = conv(numDz,numpd); denDnew = conv(denDz,denpd); [numDnewC,denDnewC] = cloop(numDnew,denDnew); [x] = dstep (0.25*numDnewC,denDnewC,251); t=0:0.02:5; stairs(t,x)
http://www.engin.umich.edu/group/ctm/examples/ball/digBBPID.html (5 de 7) [21/11/2003 05:47:18 p.m.]
Now the system is stable, but the rise time is too long. From the PID Tutorial page, we see that the increasing the proportional gain (Kp) will decrease the rise time. Let's increase the proportional gain (Kp) to 1000 and see what happens. Change Kp in the above m-file from 100 to 1000 and rerun it in the command window. You should see the following step response.
As you can see, all of the design requirements are satisfied. For this particular problem, no
implementation of an integral control was needed. But remember there is more than one solution for a control problem. For practice, you may try different P, I and D combinations to obtain a satisfactory response.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/25/97 DK
PID Tutorial
Introduction The three-term controller The characteristics of P, I, and D controllers Example Problem Open-loop step response Proportional control Proportional-Derivative control Proportional-Integral control Proportional-Integral-Derivative control General tips for designing a PID controller
Key Matlab Commands used in this tutorial are: step cloop Note: Matlab commands from the control system toolbox are highlighted in red.
Introduction
This tutorial will show you the characteristics of the each of proportional (P), the integral (I), and the derivative (D) controls, and how to use them to obtain a desired response. In this tutorial, we will consider the following unity feedback system:
Plant: A system to be controlled Controller: Provides the excitation for the plant; Designed to control the overall system behavior
q q q
First, let's take a look at how the PID controller works in a closed-loop system using the schematic shown above. The variable (e) represents the tracking error, the difference between the desired input value (R) and the actual output (Y). This error signal (e) will be sent to the PID controller, and the controller computes both the derivative and the integral of this error signal. The signal (u) just past the controller is now equal to the proportional gain (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the error.
This signal (u) will be sent to the plant, and the new output (Y) will be obtained. This new output (Y) will be sent back to the sensor again to find the new error signal (e). The controller takes this new error signal and computes its derivative and its integral again. This process goes on and on.
Example Problem
Suppose we have a simple mass, spring, and damper problem.
The transfer function between the displacement X(s) and the input F(s) then becomes
http://www.engin.umich.edu/group/ctm/PID/PID.html (3 de 11) [21/11/2003 05:49:07 p.m.]
Let
q q q q
The goal of this problem is to show you how each of Kp, Ki and Kd contributes to obtain q Fast rise time q Minimum overshoot q No steady-state error
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to an unit step input. This corresponds to the steady-state error of 0.95, quite large indeed. Furthermore, the rise time is about one second, and the settling time is about 1.5 seconds. Let's design a controller that will reduce the rise time, reduce the settling time, and eliminates the steady-state error.
Proportional control
From the table shown above, we see that the proportional controller (Kp) reduces the rise time, increases the overshoot, and reduces the steady-state error. The closed-loop transfer function of the above system with a proportional controller is:
Let the proportional gain (Kp) equals 300 and change the m-file to the following: Kp=300; num=[Kp]; den=[1 10 20+Kp]; t=0:0.01:2; step(num,den,t) Running this m-file in the Matlab command window should gives you the following plot.
Note: The Matlab function called cloop can be used to obtain a closed-loop transfer function directly from the open-loop transfer function (instead of obtaining closed-loop transfer function by hand). The following m-file uses the cloop command that should give you the identical plot as the one shown above. num=1; den=[1 10 20]; Kp=300; [numCL,denCL]=cloop(Kp*num,den); t=0:0.01:2; step(numCL, denCL,t) The above plot shows that the proportional controller reduced both the rise time and the steady-state error, increased the overshoot, and decreased the settling time by small amount.
Proportional-Derivative control
Now, let's take a look at a PD control. From the table shown above, we see that the derivative controller (Kd) reduces both the overshoot and the settling time. The closed-loop transfer function of the given system with a PD controller is:
Let Kp equals to 300 as before and let Kd equals 10. Enter the following commands into an m-file and run it in the Matlab command window. Kp=300; Kd=10; num=[Kd Kp]; den=[1 10+Kd 20+Kp]; t=0:0.01:2; step(num,den,t)
This plot shows that the derivative controller reduced both the overshoot and the settling time, and had small effect on the rise time and the steady-state error.
Proportional-Integral control
Before going into a PID control, let's take a look at a PI control. From the table, we see that an integral controller (Ki) decreases the rise time, increases both the overshoot and the settling time, and eliminates the steady-state error. For the given system, the closed-loop transfer function with a PI control is:
http://www.engin.umich.edu/group/ctm/PID/PID.html (7 de 11) [21/11/2003 05:49:07 p.m.]
Let's reduce the Kp to 30, and let Ki equals to 70. Create an new m-file and enter the following commands. Kp=30; Ki=70; num=[Kp Ki]; den=[1 10 20+Kp Ki]; t=0:0.01:2; step(num,den,t) Run this m-file in the Matlab command window, and you should get the following plot.
We have reduced the proportional gain (Kp) because the integral controller also reduces the rise time and increases the overshoot as the proportional controller does (double effect). The above response shows that the integral controller eliminated the steady-state error.
Proportional-Integral-Derivative control
Now, let's take a look at a PID controller. The closed-loop transfer function of the given system with a PID controller is:
After several trial and error runs, the gains Kp=350, Ki=300, and Kd=50 provided the desired response. To confirm, enter the following commands to an m-file and run it in the command window. You should get the following step response. Kp=350; Ki=300; Kd=50;
Now, we have obtained the system with no overshoot, fast rise time, and no steady-state error.
http://www.engin.umich.edu/group/ctm/PID/PID.html (9 de 11) [21/11/2003 05:49:07 p.m.]
User Feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
PID Examples
Cruise Control | Motor Speed | Motor Position | Bus Suspension | Inverted Pendulum | Pitch Controller | Ball and Beam
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State
8/26/97 DK
Closed-Loop Poles
The root locus of an (open-loop) transfer function H(s) is a plot of the locations (locus) of all possible closed loop poles with proportional gain k and unity feedback:
and thus the poles of the closed loop system are values of s such that 1 + K H(s) = 0. If we write H(s) = b(s)/a(s), then this equation has the form:
Let n = order of a(s) and m = order of b(s) [the order of a polynomial is the highest power of s that appears in it]. We will consider all positive values of k. In the limit as k -> 0, the poles of the closed-loop system are a(s) = 0 or the poles of H(s). In the limit as k -> infinity, the poles of the closed-loop system are b(s) = 0 or the zeros of H(s). No matter what we pick k to be, the closed-loop system must always have n poles, where n is the number of poles of H(s). The root locus must have n branches, each branch starts at a pole of H(s) and goes to a zero of H(s). If H(s) has more poles than zeros (as is often the case), m < n and we say that H(s) has zeros at infinity. In this case, the limit of H(s) as s -> infinity is zero. The number of zeros at infinity is n-m, the number of poles minus the number of zeros, and is the number of branches of the root locus that go to infinity (asymptotes). Since the root locus is actually the locations of all possible closed loop poles, from the root locus we can select a gain such that our closed-loop system will perform the way we want. If any of the selected poles are on the right half plane, the closed-loop system will be unstable. The poles that are closest to the imaginary axis have the greatest influence on the closed-loop response, so even though the system has three or four poles, it may still act like a second or even first order system depending on the location(s) of the dominant pole(s).
How do we design a feed-back controller for the system by using the root locus method? Say our design criteria are 5% overshoot and 1 second rise time. Make a Matlab file called rl.m. Enter the transfer function, and the command to plot the root locus: num=[1 7]; den=conv(conv([1 0],[1 5]),conv([1 15],[1 20])); rlocus(num,den) axis([-22 3 -15 15])
On the plot above, the two white dotted lines at about a 45 degree angle indicate pole locations with Zeta = 0.7; in between these lines, the poles will have Zeta > 0.7 and outside of the lines Zeta < 0.7. The semicircle indicates pole locations with a natural frequency Wn = 1.8; inside the circle, Wn < 1.8 and outside the circle Wn > 1.8. Going back to our problem, to make the overshoot less than 5%, the poles have to be in between the two white dotted lines, and to make the rise time shorter than 1 second, the poles have to be outside of the white dotted semicircle. So now we know only the part of the locus outside of the semicircle and in between the two lines are acceptable. All the poles in this location are in the left-half plane, so the closed-loop system will be stable. From the plot above we see that there is part of the root locus inside the desired region. So in this case we need only a proportional controller to move the poles to the desired region. You can use rlocfind command in Matlab to choose the desired poles on the locus: [kd,poles] = rlocfind(num,den) Click on the plot the point where you want the closed-loop pole to be. You may want to select the points indicated in the plot below to satisfy the design criteria.
Note that since the root locus may has more than one branch, when you select a pole, you may want to find out where the other pole (poles) are. Remember they will affect the response too. From the plot above we see that all the poles selected (all the white "+") are at reasonable positions. We can go ahead and use the chosen kd as our proportional controller.
Closed-loop response
In order to find the step response, you need to know the closed-loop transfer function. You could compute this using the rules of block diagrams, or let Matlab do it for you: [numCL, denCL] = cloop((kd)*num, den) The two arguments to the function cloop are the numerator and denominator of the open-loop system. You need to include the proportional gain that you have chosen. Unity feedback is assumed. If you have a non-unity feedback situation, look at the help file for the Matlab function feedback, which can find the closed-loop transfer function with a gain in the feedback loop. Check out the step response of your closed-loop system: step(numCL,denCL)
As we expected, this response has an overshoot less than 5% and a rise time less than 1 second.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
Bode Plots
As noted above, a Bode plot is the representation of the magnitude and phase of G(j*w) (where the frequency vector w contains only positive frequencies). To see the Bode plot of a transfer function, you can use the Matlab bode command. For example, bode(50,[1 9 30 40]) displays the Bode plots for the transfer function:
50 ----------------------s^3 + 9 s^2 + 30 s + 40
Please note the axes of the figure. The frequency is on a logarithmic scale, the phase is given in degrees, and the magnitude is given as the gain in decibels. Note: a decibel is defined as 20*log10 ( |G(j*w| ) Click here to see a few simple Bode plots.
where K is a variable (constant) gain and G(s) is the plant under consideration. The gain margin is defined as the change in open loop gain required to make the system unstable. Systems with greater gain margins can withstand greater changes in system parameters before becoming unstable in closed loop. Keep in mind that unity gain in magnitude is equal to a gain of zero in dB. The phase margin is defined as the change in open loop phase shift required to make a closed loop system unstable. The phase margin also measures the system's tolerance to time delay. If there is a time delay greater than 180/Wpc in the loop (where Wpc is the frequency where the phase shift is 180 deg), the system will become unstable in closed loop. The time delay can be thought of as an extra block in the forward path of the block diagram that adds phase to the system but has no effect the gain. That is, a time delay can be represented as a block with magnitude of 1 and phase w*time_delay (in radians/second). For now, we won't worry about where all this comes from and will concentrate on identifying the gain and phase margins on a Bode plot: The phase margin is the difference in phase between the phase curve and -180 deg at the point corresponding to the frequency that gives us a gain of 0dB (the gain cross over frequency, Wgc). Likewise, the gain margin is the difference between the magnitude curve and 0dB at the point corresponding to the frequency that gives us a phase of -180 deg (the phase cross over frequency, Wpc).
One nice thing about the phase margin is that you don't need to replot the Bode in order to find the new phase margin when changing the gains. If you recall, adding gain only shifts the magnitude plot up. This is the equivalent of changing the y-axis on the magnitude plot. Finding the phase margin is simply the matter of finding the new cross-over frequency and reading off the phase margin. For example, suppose you entered the command bode(50,[1 9 30 40]). You will get the following bode plot:
You should see that the phase margin is about 100 degrees. Now suppose you added a gain of 100, by
entering the command bode(100*50,[1 9 30 40]). You should get the following plot (note I changed the axis so the scale would be the same as the plot above, your bode plot may not be exactly the same shape, depending on the scale used):
As you can see the phase plot is exactly the same as before, and the magnitude plot is shifted up by 40dB (gain of 100). The phase margin is now about -60 degrees. This same result could be achieved if the y-axis of the magnitude plot was shifted down 40dB. Try this, look at the first Bode plot, find where the curve crosses the -40dB line, and read off the phase margin. It should be about -60 degrees, the same as the second Bode plot. We can find the gain and phase margins for a system directly, by using Matlab. Just enter the margin command. This command returns the gain and phase margins, the gain and phase cross over frequencies, and a graphical representation of these on the Bode plot. Let's check it out: margin(50,[1 9 30 40])
Bandwidth Frequency
The bandwidth frequency is defined as the frequency at which the closed-loop magnitude response is equal to -3 dB. However, when we design via frequency response, we are interested in predicting the closed-loop behavior from the open-loop response. Therefore, we will use a second-order system approximation and say that the bandwidth frequency equals the frequency at which the open-loop magnitude response is between -6 and - 7.5dB, assuming the open loop phase response is between -135 deg and -225 deg. For a complete derivation of this approximation, consult your textbook. If you would like to see how the bandwidth of a system can be found mathematically from the closed-loop damping ratio and natural frequency, the relevant equations as well as some plots and Matlab code are given on our Bandwidth Frequency page. In order to illustrate the importance of the bandwidth frequency, we will show how the output changes with different input frequencies. We will find that sinusoidal inputs with frequency less than Wbw (the bandwidth frequency) are tracked "reasonably well" by the system. Sinusoidal inputs with frequency greater than Wbw are attenuated (in magnitude) by a factor of 0.707 or greater (and are also shifted in phase). Let's say that we have the following closed-loop transfer function representing a system:
1 --------------s^2 + 0.5 s + 1 First of all, let's find the bandwidth frequency by looking at the Bode plot: bode (1, [1 0.5 1 ])
Since this is the closed-loop transfer function, our bandwidth frequency will be the frequency corresponding to a gain of -3 dB. looking at the plot, we find that it is approximately 1.4 rad/s. We can also read off the plot that for an input frequency of 0.3 radians, the output sinusoid should have a magnitude about one and the phase should be shifted by perhaps a few degrees (behind the input). For an input frequency of 3 rad/sec, the output magnitude should be about -20dB (or 1/10 as large as the input) and the phase should be nearly -180 (almost exactly out-of-phase). We can use the lsim command to simulate the response of the system to sinusoidal inputs. First, consider a sinusoidal input with a frequency lower than Wbw. We must also keep in mind that we want to view the steady state response. Therefore, we will modify the axes in order to see the steady state response clearly (ignoring the transient response). w= 0.3; num = 1; den = [1 0.5 1 ]; t=0:0.1:100; u = sin(w*t); [y,x] = lsim(num,den,u,t); plot(t,y,t,u)
http://www.engin.umich.edu/group/ctm/freq/freq.html (7 de 15) [21/11/2003 05:49:27 p.m.]
axis([50,100,-2,2])
Note that the output (blue) tracks the input (purple) fairly well; it is perhaps a few degrees behind the input as expected. However, if we set the frequency of the input higher than the bandwidth frequency for the system, we get a very distorted response (with respect to the input): w = 3; num = 1; den = [1 0.5 1 ]; t=0:0.1:100; u = sin(w*t); [y,x] = lsim(num,den,u,t); plot(t,y,t,u) axis([90, 100, -1, 1])
Again, note that the magnitude is about 1/10 that of the input, as predicted, and that it is almost exactly out of phase (180 degrees behind) the input. Feel free to experiment and view the response for several different frequencies w, and see if they match the Bode plot.
Closed-loop performance
In order to predict closed-loop performance from open-loop frequency response, we need to have several concepts clear:
q q
The system must be stable in open loop if we are going to design via Bode plots. If the gain cross over frequency is less than the phase cross over frequency(i.e. Wgc < Wpc), then the closed-loop system will be stable. For second-order systems, the closed-loop damping ratio is approximately equal to the phase margin divided by 100 if the phase margin is between 0 and 60 deg. We can use this concept with caution if the phase margin is greater than 60 deg. For second-order systems, a relationship between damping ratio, bandwidth frequency and settling time is given by an equation described on the bandwidth page.
A very rough estimate that you can use is that the bandwidth is approximately equal to the natural frequency. Let's use these concepts to design a controller for the following system:
q
Where Gc(s) is the controller and G(s) is: 10 ---------1.25s + 1 The design must meet the following specifications: q Zero steady state error. q Maximum overshoot must be less than 40%. q Settling time must be less than 2 secs. There are two ways of solving this problem: one is graphical and the other is numerical. Within Matlab, the graphical approach is best, so that is the approach we will use. First, let's look at the Bode plot. Create an m-file with the following code: num = 10; den = [1.25,1]; bode(num, den)
There are several several characteristics of the system that can be read directly from this Bode plot. First of all, we can see that the bandwidth frequency is around 10 rad/sec. Since the bandwidth frequency is roughly the same as the natural frequency (for a second order system of this type), the rise time is 1.8/BW=1.8/10=1.8 seconds. This is a rough estimate, so we will say the rise time is about 2 seconds. The phase margin for this system is approximately 95 degrees. This corresponds to a damping of PM/100=95/100=0.95. Plugging in this value into the equation relating overshoot and the damping ratio (or consulting a plot of this relation), we find that the damping ratio corresponding to this overshoot is approximately 1%. The system will be close to being overdamped. The last major point of interest is steady-state error. The steady-state error can be read directly off the Bode plot as well. The constant (Kp, Kv, or Ka) are located at the intersection of the low frequency asymptote with the w=1 line. Just extend the low frequency line to the w=1 line. The magnitude at this point is the constant. Since the Bode plot of this system is a horizontal line at low frequencies (slope = 0), we know this system is of type zero. Therefore, the intersection is easy to find. The gain is 20dB (magnitude 10). What this means is that the constant for the error function it 10. Click here to see the table of system types and error functions. The steady-state error is 1/(1+Kp)=1/(1+10)=0.091. If our system was type one instead of type zero, the constant for the steady-state error would be found in a manner similar to the following
Let's check our predictions by looking at a step response plot. This can be done by adding the following two lines of code into the Matlab command window. [numc,denc] = cloop(num,den,-1); step(numc,denc)
As you can see, our predictions were very good. The system has a rise time of about 2 seconds, is overdamped, and has a steady-state error of about 9%. Now we need to choose a controller that will allow us to meet the design criteria. We choose a PI controller because it will yield zero steady state error for a step input. Also, the PI controller has a zero, which we can place. This gives us additional design flexibility to help us meet our criteria. Recall that a PI controller is given by: K*(s+a)
http://www.engin.umich.edu/group/ctm/freq/freq.html (11 de 15) [21/11/2003 05:49:27 p.m.]
Gc(s) = ------s The first thing we need to find is the damping ratio corresponding to a percent overshoot of 40%. Plugging in this value into the equation relating overshoot and damping ratio (or consulting a plot of this relation), we find that the damping ratio corresponding to this overshoot is approximately 0.28. Therefore, our phase margin should be approximately 30 degrees. From our Ts*Wbw vs damping ratio plot, we find that Ts*Wbw ~ 21. We must have a bandwidth frequency greater than or equal to 12 if we want our settling time to be less than 1.75 seconds which meets the design specs. Now that we know our desired phase margin and bandwidth frequency, we can start our design. Remember that we are looking at the open-loop Bode plots. Therefore, our bandwidth frequency will be the frequency corresponding to a gain of approximately -7 dB. Let's see how the integrator portion of the PI or affects our response. Change your m-file to look like the following (this adds an integral term but no proportional term): num = [10]; den = [1.25, 1]; numPI = [1]; denPI = [1 0]; newnum = conv(num,numPI); newden = conv(den,denPI); bode(newnum, newden, logspace(0,2))
Our phase margin and bandwidth frequency are too small. We will add gain and phase with a zero. Let's place the zero at 1 for now and see what happens. Change your m-file to look like the following:
num = [10]; den = [1.25, 1]; numPI = [1 1]; denPI = [1 0]; newnum = conv(num,numPI); newden = conv(den,denPI); bode(newnum, newden, logspace(0,2))
It turns out that the zero at 1 with a unit gain gives us a satisfactory answer. Our phase margin is greater than 60 degrees (even less overshoot than expected) and our bandwidth frequency is approximately 11 rad/s, which will give us a satisfactory response. Although satisfactory, the response is not quite as good as we would like. Therefore, let's try to get a higher bandwidth frequency without changing the phase margin too much. Let's try to increase the gain to 5 and see what happens .This will make the gain shift and the phase will remain the same. num = [10]; den = [1.25, 1]; numPI = 5*[1 1]; denPI = [1 0]; newnum = conv(num,numPI); newden = conv(den,denPI); bode(newnum, newden, logspace(0,2))
That looks really good. Let's look at our step response and verify our results. Add the following two lines to your m-file: [clnum,clden] =cloop(newnum,newden,-1); step(clnum,clden)
As you can see, our response is better than we had hoped for. However, we are not always quite as lucky and usually have to play around with the gain and the position of the poles and/or zeros in order to achieve our design requirements. This tutorial is continued on the Nyquist page (the link is after the feedback form).
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the
http://www.engin.umich.edu/group/ctm/freq/freq.html (14 de 15) [21/11/2003 05:49:28 p.m.]
tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency response | State Space | Digital Control | Examples
8/27/96 LJO
State-space equations
There are several different ways to describe a system of linear differential equations. The state-space representation is given by the equations:
where x is an n by 1 vector representing the state (commonly position and velocity variables in mechanical systems), u is a scalar representing the input (commonly a force or torque in mechanical systems), and y is a scalar representing the output. The matrices A (n by n), B (n by 1), and C (1 by n) determine the relationships between the state and input and output variables. Note that there are n first-order differential equations. State space representation can also be used for systems with multiple inputs and outputs (MIMO), but we will only use single-input, single-output (SISO) systems in these tutorials. To introduce the state space design method, we will use the magnetically suspended ball as an example. The current through
http://www.engin.umich.edu/group/ctm/state/state.html (1 de 12) [21/11/2003 05:49:36 p.m.]
the coils induces a magnetic force which can balance the force of gravity and cause the ball (which is made of a magnetic material) to be suspended in midair. The modeling of this system has been established in many control text books (including Automatic Control Systems by B. C. Kuo, the seventh edition). The equations for the system are given by:
where h is the vertical position of the ball, i is the current through the electromagnet, V is the applied voltage, M is the mass of the ball, g is gravity, L is the inductance, R is the resistance, and K is a coefficient that determines the magnetic force exerted on the ball. For simplicity, we will choose values M = 0.05 Kg, K = 0.0001, L = 0.01 H, R = 1 Ohm, g = 9.81 m/sec^2 . The system is at equilibrium (the ball is suspended in midair) whenever h = K i^2/Mg (at which point dh/dt = 0). We linearize the equations about the point h = 0.01 m (where the nominal current is about 7 amp) and get the state space equations:
where:
is the set of state variables for the system (a 3x1 vector), u is the input voltage (delta V),
and y (the output), is delta h. Enter the system matrices into a m-file. A = [ 0 1 980 0 0 0 B = [0 0 100]; C = [1 0 0 -2.8 -100];
0];
One of the first things you want to do with the state equations is find the poles of the system; these are the values of s where det(sI - A) = 0, or the eigenvalues of the A matrix: poles = eig(A) You should get the following three poles: poles =
31.3050 -31.3050 -100.0000 One of the poles is in the right-half plane, which means that the system is unstable in open-loop. To check out what happens to this unstable system when there is a nonzero initial condition, add the following lines to your m-file, t = 0:0.01:2; u = 0*t; x0 = [0.005 0 0]; [y,x] = lsim(A,B,C,0,u,t,x0); h = x(:,2); %Delta-h is the output of interest plot(t,h) and run the file again.
It looks like the distance between the ball and the electromagnet will go to infinity, but probably the ball hits the table or the floor first (and also probably goes out of the range where our linearization is valid).
Recall that the characteristic polynomial for this closed-loop system is the determinant of (sI-(A-BK)). Since the matrices A and B*K are both 3 by 3 matrices, there will be 3 poles for the system. By using full-state feedback we can place the poles anywhere we want. We could use the Matlab function place to find the control matrix, K, which will give the desired poles. Before attempting this method, we have to decide where we want the closed-loop poles to be. Suppose the criteria for the controller were settling time < 0.5 sec and overshoot < 5%, then we might try to place the two dominant poles at -10 +/- 10i (at zeta = 0.7 or 45 degrees with sigma = 10 > 4.6*2). The third pole we might place at -50 to start, and we can change it later depending on what the closed-loop behavior is. Remove the lsim command from your m-file and everything after it, then add the following lines to your m-file, p1 = -10 + 10i; p2 = -10 - 10i; p3 = -50; K = place(A,B,[p1 p2 p3]); lsim(A-B*K,B,C,0,u,t,x0);
The overshoot is too large (there are also zeros in the transfer function which can increase the overshoot; you do not see the zeros in the state-space formulation). Try placing the poles further to the left to see if the transient response improves (this should also make the response faster). p1 = -20 + 20i; p2 = -20 - 20i; p3 = -100; K = place(A,B,[p1 p2 p3]); lsim(A-B*K,B,C,0,u,t,x0);
This time the overshoot is smaller. Consult your textbook for further suggestions on choosing the desired closed-loop poles. Compare the control effort required (K) in both cases. In general, the farther you move the poles, the more control effort it takes. Note: If you want to place two or more poles at the same position, place will not work. You can use a function called acker which works similarly to place: K = acker(A,B,[p1 p2 p3])
The system does not track the step well at all; not only is the magnitude not one, but it is negative instead of positive! Recall the schematic above, we don't compare the output to the reference; instead we measure all the states, multiply by the gain vector K, and then subtract this result from the reference. There is no reason to expect that K*x will be equal to the desired output. To eliminate this problem, we can scale the reference input to make it equal to K*x_steadystate. This scale factor is often called Nbar; it is introduced as shown in the following schematic:
We can get Nbar from Matlab by using the function rscale (place the following line of code after K = ...). Nbar=rscale(A,B,C,0,K)
http://www.engin.umich.edu/group/ctm/state/state.html (7 de 12) [21/11/2003 05:49:36 p.m.]
Note that this function is not standard in Matlab. You will need to copy it to a new m-file to use it. Click here for more information on using functions in Matlab. Now, if we want to find the response of the system under state feedback with this introduction of the reference, we simply note the fact that the input is multiplied by this new factor, Nbar: lsim(A-B*K,B*Nbar,C,0,u,t)
Observer design
When we can't measure all the states x (as is commonly the case), we can build an observer to estimate them, while measuring only the output y = C x. For the magnetic ball example, we will add three new, estimated states to the system. The schematic is as follows:
The observer is basically a copy of the plant; it has the same input and almost the same differential equation. An extra term compares the actual measured output y to the estimated output ; this will to approach the values of the actual states x. The error dynamics of the cause the estimated states observer are given by the poles of (A-L*C). First we need to choose the observer gain L. Since we want the dynamics of the observer to be much faster than the system itself, we need to place the poles at least five times farther to the left than the dominant poles of the system. If we want to use place, we need to put the three observer poles at different locations. op1 = -100; op2 = -101; op3 = -102; Because of the duality between controllability and observability, we can use the same technique used to find the control matrix, but replacing the matrix B by the matrix C and taking the transposes of each matrix (consult your text book for the derivation): L = place(A',C',[op1 op2 op3])'; The equations in the block diagram above are given for . It is conventional to write the combined . We use equations for the system plus observer using the original state x plus the error state: e = x -
as state feedback u = -K . After a little bit of algebra (consult your textbook for more details), we arrive at the combined state and error equations with the full-state feedback and an observer: At = [A - B*K B*K zeros(size(A)) A - L*C]; Bt = [ B*Nbar zeros(size(B))]; Ct = [ C zeros(size(C))]; To see how the response looks to a nonzero initial condition with no reference input, add the following lines into your m-file. We typically assume that the observer begins with zero initial condition, This gives us that the initial condition for the error is equal to the initial condition of the state. =0.
lsim(At,Bt,Ct,0,zeros(size(t)),t,[x0 x0])
Responses of all the states are plotted below. Recall that lsim gives us x and e; to get compute x-e.
we need to
The blue solid line is the response of the ball position The green solid line is the response of the ball speed The red solid line is the response of the current
, the blue dotted line is the estimated state , the green dotted line is the estimated state .
; ;
We can see that the observer estimates the states quickly and tracks the states reasonably well in the steady-state. The plot above can be obtained by using the plot command.
User Feedback
We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
http://www.engin.umich.edu/group/ctm/state/state.html (11 de 12) [21/11/2003 05:49:36 p.m.]
8/12/97 CJC
Introduction
The figure below shows the typical continuous feedback system that we have been considering so far in this tutorial. Almost all of the continuous controllers can be built using analog electronics.
The continuous controller, enclosed in the dashed square, can be replaced by a digital controller, shown below, that performs same control task as the continuous controller. The basic difference between these controllers is that the digital system operates on discrete signals (or samples of the sensed signal) rather
http://www.engin.umich.edu/group/ctm/digital/digital.html (1 de 13) [21/11/2003 05:49:45 p.m.]
Different types of signals in the above digital schematic can be represented by the following plots.
The purpose of this Digital Control Tutorial is to show you how to work with discrete functions either in transfer function or state-space form to design digital control systems.
For this technique, we will consider the following portion of the digital control system and rearrange as follows.
The clock connected to the D/A and A/D converters supplies a pulse every T seconds and each D/A and A/D sends a signal only when the pulse arrives. The purpose of having this pulse is to require that Hzoh(z) have only samples u(k) to work on and produce only samples of output y(k); thus, Hzoh(z) can be realized as a discrete function. The philosophy of the design is the following. We want to find a discrete function Hzoh(z) so that for a piecewise constant input to the continuous system H(s), the sampled output of the continuous system equals the discrete output. Suppose the signal u(k) represents a sample of the input signal. There are techniques for taking this sample u(k) and holding it to produce a continuous signal uhat(t). The sketch below shows that the uhat(t) is held constant at u(k) over the interval kT to (k+1)T. This operation of holding uhat(t) constant over the sampling time is called zero-order hold.
The zero-order held signal uhat(t) goes through H2(s) and A/D to produce the output y(k) that will be the piecewise same signal as if the continuous u(t) goes through H(s) to produce the continuous output y(t).
Now we will redraw the schematic, placing Hzoh(z) in place of the continuous portion.
By placing Hzoh(z), we can design digital control systems dealing with only discrete functions. Note: There are certain cases where the discrete response does not match the continuous response due to a hold circuit implemented in digital control systems. For information, see Lagging effect associated with the hold.
1. Transfer function
Suppose you have the following continuous transfer function
q q q q
Assuming the closed-loop bandwidth frequency is greater than 1 rad/sec, we will choose the sampling time (Ts) equal to 1/100 sec. Now, create an new m-file and enter the following commands. M=1;
http://www.engin.umich.edu/group/ctm/digital/digital.html (5 de 13) [21/11/2003 05:49:45 p.m.]
b=10; k=20; num=[1]; den=[M b k]; Ts=1/100; [numDz,denDz]=c2dm(num,den,Ts,'zoh') Running this m-file in the command window should give you the following numDz and denDz matrices. numDz = 1.0e-04 * 0 denDz = 1.0000 -1.9029 0.9048 0.4837 0.4678
Note: The numerator and denominator matrices will be represented by the descending powers of z. For more information on Matlab representation, please refer to Matlab representation. Now you have the transfer function in discrete form.
2. State-Space
Suppose you have the following continuous state-space model
The following m-file converts the above continuous state-space to discrete state-space. M=1; b=10; k=20;
A=[0 -k/M
1; -b/M];
B=[ 0; 1/M]; C=[1 0]; D=[0]; Ts=1/100; [F,G,H,J] = c2dm (A,B,C,D,Ts,'zoh') Create an new m-file and copy the above commands. Running this m-file in the Matlab command window should give you the following matrices. F = 0.9990 -0.1903 0.0095 0.9039
G = 0.0000 0.0095
Now you have the discrete time state-space model. Note: For more information on the discrete state-space, please refer to Discrete State-Space.
q q q
The figure below shows the mapping of lines of constant damping ratio (zeta) and natural frequency (Wn) from the s-plane to the z-plane using the expression shown above.
If you noticed in the z-plane, the stability boundary is no longer imaginary axis, but is the unit circle |z|=1. The system is stable when all poles are located inside the unit circle and unstable when any pole is located outside. For analyzing the transient response from pole locations in the z-plane, the following three equations used in continuous system designs are still applicable.
where
q
q q q q
Important: The natural frequency (Wn) in z-plane has the unit of rad/sample, but when you use the equations shown above, the Wn must be in the unit of rad/sec. Suppose we have the following discrete transfer function
Create an new m-file and enter the following commands. Running this m-file in the command window gives you the following plot with the lines of constant damping ratio and natural frequency. numDz=[1]; denDz=[1 -0.3 0.5]; pzmap(numDz,denDz) axis([-1 1 -1 1]) zgrid
From this plot, we see poles are located approximately at the natural frequency of 9pi/20T (rad/sample) and the damping ratio of 0.25. Assuming that we have the sampling time of 1/20 sec (which leads to Wn
http://www.engin.umich.edu/group/ctm/digital/digital.html (10 de 13) [21/11/2003 05:49:45 p.m.]
= 28.2 rad/sec) and using three equations shown above, we can determine that this system should have the rise time of 0.06 sec, the settling time of 0.65 sec and the maximum overshoot of 45% (0.45 more than the steady-state value). Let's obtain the step response and see if these are correct. Add the following commands to the above m-file and rerun it in the command window. You should get the following step response. [x] = dstep (numDz,denDz,51); t = 0:0.05:2.5; stairs (t,x)
As you can see from the plot, all of the rise time, the settling time and the overshoot came out to be what we expected. We proved you here that we can use the locations of poles and the above three equations to analyze the transient response of the system. For more analysis on the pole locations and transient response, see Transient Response.
Discrete Root-Locus
The root-locus is the locus of points where roots of characteristic equation can be found as a single gain is varied from zero to infinity. The characteristic equation of an unity feedback system is
where G(z) is the compensator implemented in the digital controller and Hzoh(z) is the plant transfer function in z. The mechanics of drawing the root-loci are exactly the same in the z-plane as in the s-plane. Recall from
the continuous Root-Locus Tutorial, we used the Matlab function called sgrid to find the root-locus region that gives the right gain (K). For the discrete root-locus analysis, we use the function zgrid that has the same characteristics as the sgrid. The command zgrid(zeta, Wn) draws lines of constant damping ratio (zeta) and natural frequency (Wn). Suppose we have the following discrete transfer function
and the requirements of having damping ratio greater than 0.6 and the natural frequency greater than 0.4 rad/sample (these can be found from design requirements, sampling time (sec/sample) and three equations shown in the previous section). The following commands draws the root-locus with the lines of constant damping ratio and natural frequency. Create an new m-file and enter the following commands. Running this m-file should give you the following root-locus plot. numDz=[1 -0.3]; denDz=[1 -1.6 0.7]; rlocus (numDz,denDz) axis ([-1 1 -1 1]) zeta=0.4; Wn=0.3; zgrid (zeta,Wn)
From this plot, you should realize that the system is stable because all poles are located inside the unit circle. Also, you see two dotted lines of constant damping ratio and natural frequency. The natural frequency is greater than 0.3 outside the constant-Wn line, and the damping ratio is greater than 0.4 inside the constant-zeta line. In this example, we do have the root-locus drawn in the desired region. Therefore, a gain (K) chosen from one of the loci in the desired region should give you the response that satisfies design requirements.
User Feedback
We would like to hear about difficulties you had with the tutorials, suggestions you have for improvement, errors that you found, or any other comments that you have. This feedback is anonymous; include your email address if you want a reply.
Submit Feedback
Reset
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/26/97 DK
CTM: Index
Matlab Basics
Vectors Functions Plotting Polynomials Matrices Using M-files in Matlab Getting help in Matlab
Modeling
Train system Free body diagram and Newton's law State-variable and output equations Matlab representation Examples: Cruise Control, Motor Speed, Motor Position, Bus Suspension, Inverted Pendulum, Pitch Controller, Ball & Beam
PID
http://www.engin.umich.edu/group/ctm/home.text.html (1 de 4) [21/11/2003 05:51:44 p.m.]
CTM: Index
Introduction The three-term controller Characteristics of P, I, and D controllers Open-loop step response Proportional control PD control PI control PID control General tips for designing a PID controller Examples: Cruise Control, Motor Speed, Motor Position, Bus Suspension, Inverted Pendulum, Pitch Controller, Ball & Beam
Root Locus
Closed-loop poles Plotting the root locus of a transfer function Choosing a value of K Closed-loop response Examples: Cruise Control, Motor Speed, Motor Position, Bus Suspension, Inverted Pendulum, Pitch Controller, Ball & Beam
Frequency Response
Bode plot Gain and phase margin Bandwidth frequency Closed-loop performance Nyquist diagram Examples: Cruise Control, Motor Speed, Motor Position, Bus Suspension, Inverted Pendulum, Pitch Controller, Ball & Beam
State Space
State-space equations Control design using pole placement Introducing the reference input Observer design Examples: Cruise Control, Motor Speed, Motor Position, Bus Suspension, Inverted Pendulum, Pitch Controller, Ball & Beam
http://www.engin.umich.edu/group/ctm/home.text.html (2 de 4) [21/11/2003 05:51:44 p.m.]
CTM: Index
Digital Control
Introduction Zero-order hold equivalence Conversion using c2dm Stability and transient response Discrete root-locus Examples: Cruise Control, Motor Speed, Motor Position, Bus Suspension, Inverted Pendulum, Pitch Controller, Ball & Beam
Examples
Cruise Control Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control Motor Speed Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control Motor Position Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control Bus Suspension System Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control Inverted Pendulum Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control Pitch Controller Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control Ball & Beam Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control
Animation
Bus Suspension Inverted Pendulum Pitch Controller Ball & Beam
Commands Extras
Conversions dstep and stairs
http://www.engin.umich.edu/group/ctm/home.text.html (3 de 4) [21/11/2003 05:51:44 p.m.]
CTM: Index
Difference equations and system representations Digital lead and lag Digital steady-state error Discrete pole locations and transient response Functions jgrid | lnyquist1 | nyquist1 | polyadd | rscale | sigrid | wbw Lagging effect associated with the hold Lead/lag lsim mfile Notch filter plot PID Bilinear Approximation Pole/zero cancelation step Steady-state error
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/12/97 CJC
feedback figure for format function grid gtext help hold if imag impulse input inv jgrid legend length linspace lnyquist1 log loglog logspace lqr lsim margin norm nyquist1 obsv ones place plot poly polyadd
Feedback connection of two systems. Create a new figure or redefine the current figure, see also subplot, axis For, next loop Number format (significant digits, exponents) Creates function m-files Draw the grid lines on the current plot Add a piece of text to the current plot, see also text HELP! Hold the current graph, see also figure Conditionally execute statements Returns the imaginary part of a complex number, see also real Impulse response of continuous-time linear systems, see also step, lsim, dlsim Prompt for user input Find the inverse of a matrix Generate grid lines of constant damping ratio (zeta) and settling time (sigma), see also sgrid, sigrid, zgrid Graph legend Length of a vector, see also size Returns a linearly spaced vector Produce a Nyquist plot on a logarithmic scale, see also nyquist1 natural logarithm, also log10: common logarithm Plot using log-log scale, also semilogx/semilogy Returns a logarithmically spaced vector Linear quadratic regulator design for continuous systems, see also dlqr Simulate a linear system, see also step, impulse, dlsim. Returns the gain margin, phase margin, and crossover frequencies, see also bode Norm of a vector Draw the Nyquist plot, see also lnyquist1. Note this command was written to replace the Matlab standard command nyquist to get more accurate Nyquist plots. The observability matrix, see also ctrb Returns a vector or matrix of ones, see also zeros Compute the K matrix to place the poles of A-BK, see also acker Draw a plot, see also figure, axis, subplot. Returns the characteristic polynomial Add two different polynomials
polyval print pzmap rank real rlocfind rlocus roots rscale set series sgrid sigrid size sqrt ss ss2tf ss2zp stairs step subplot text tf tf2ss tf2zp title wbw
Polynomial evaluation Print the current plot (to a printer or postscript file) Pole-zero map of linear systems Find the number of linearly independent rows or columns of a matrix Returns the real part of a complex number, see also imag Find the value of k and the poles at the selected point Draw the root locus Find the roots of a polynomial Find the scale factor for a full-state feedback system Set(gca,'Xtick',xticks,'Ytick',yticks) to control the number and spacing of tick marks on the axes Series interconnection of Linear time-independent systems Generate grid lines of constant damping ratio (zeta) and natural frequency (Wn), see also jgrid, sigrid, zgrid Generate grid lines of constant settling time (sigma), see also jgrid, sgrid, zgrid Gives the dimension of a vector or matrix, see also length Square root Create state-space models or convert LTI model to state space, see also tf State-space to transfer function representation, see also tf2ss State-space to pole-zero representation, see also zp2ss Stairstep plot for discreste response, see also dstep Plot the step response, see also impulse, lsim, dlsim. Divide the plot window up into pieces, see also plot, figure Add a piece of text to the current plot, see also title, xlabel, ylabel, gtext Creation of transfer functions or conversion to transfer function, see also ss Transfer function to state-space representation, see also ss2tf Transfer function to Pole-zero representation, see also zp2tf Add a title to the current plot Returns the bandwidth frequency given the damping ratio and the rise or settling time.
xlabel/ylabel Add a label to the horizontal/vertical axis of the current plot, see also title, text, gtext zeros Returns a vector or matrix of zeros zgrid zp2ss zp2tf Generates grid lines of constant damping ratio (zeta) and natural frequency (Wn), see also sgrid, jgrid, sigrid Pole-zero to state-space representation, see also ss2zp Pole-zero to transfer function representation, see also tf2zp
Copyright
Copyright (C) 1997 by the Regents of the University of Michigan. User agrees to reproduce said copyright notice on all copies of the software made by the recipient. All Rights Reserved. Permission is hereby granted for the recipient to make copies and use this software for its own internal purposes only, under the conditions that this copyright message is retained intact and that no modifications are made to the software. Recipients of this software may not re-distribute this software outside of their own institution. Permission to market this software commercially, to include this product as part of a commercial product, or to make a derivative work for commercial purposes, is explicitly prohibited. All other uses are also prohibited unless authorized in writing by the Regents of the University of Michigan. This software is offered without warranty. The Regents of the University of Michigan disclaim all warranties, express or implied, including but not limited to the implied warranties of merchantability and fitness for any particular purpose. In no event shall the Regents of the University of Michigan be liable for loss or damage of any kind, including but not limited to incidental, indirect, consequential, or special damages.
Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Digital Control | Examples
8/14/97 DT