Sei sulla pagina 1di 52

Modeling a System

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 constantspeed 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 ro lling frict ion .

Free Body Diagram and Newton's Law


The system can be represented by follo wing Free Body Diagrams .

Figure 1: Free Body Diagrams


Fro m Newton's law, you know that the sum of forces acting on a mass equals the mass times its accelerat ion. 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 d irection, the gravitat ional force is canceled by the normal force applied by the ground, so that there will be no accelerat ion in the vertical direction. The equations of mot ion in the horizontal d irection are the following:

State-variable and Output Equations


This set of system equations can now be manipulated into state-variable form. The state variables are the positions, X1 and X2, and the velocities, V1 and V2; the input is F. The state variable equations will look like the following:

Let the output of the system be the velocity of the engine. Then the output equation will be:

Transfer Function
To find the transfer function of the system, we first take the Lap lace transforms of the differential equations.

The output is Y(s) = V1(s) = s X1(s). The variable X1 should be algebraically eliminated to leave an expression for Y(s)/F(s). When finding the transfer function, zero in itial conditions must be assumed. The transfer function should look like the one shown below.

LabVIEW Graphical Approach


If you choose to use the transfer function, create a blan k VI and add the CD Construct Transfer Function Model VI to your block diagram. This VI is located in the Model Construction section of the Control Design palette. Click the drop-down bo x that shows SISO and select Single-Input Single-Output (Symbolic). To create inputs for this transfer function, right-click on the Symbolic Nu merator terminal and select Create Control. Repeat this for the Sy mbolic Denominator and Variables terminals. These controls will now appe ar on the front panel.

Figure 2: Create Transfer Function

Next, add the CD Draw Transfer Function VI to your block diagram, located in the Model Construction section of the Control Design palette. Connect the Transfer Function Model output from the CD Create Transfer Function Model VI to the Transfer Function Model input on the CD Draw Transfer Function VI. Finally, create an indicator fro m the CD Draw Transfer Function VI. To do this, right-click on the Equation terminal and select CreateIndicator.

Figure 3: Display Transfer Function


Now create a While Loop, located in the Structures palette, and surround all of the code in the block d iagram. Next, right-click on the Loop Condition terminal in the bottom-right corner of the While Loop, and select CreateControl.

Figure 4: Transfer Function with While Loop


With this VI, you can now create a transfer function for the train system. Try changing the numerator and the denominator in the front panel, and observe the effects on the transfer function equation .

Figure 5: Transfer Function Front Panel

State-Space Model

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 which is found from the state-variable and the output equations is shown below.

LabVIEW Graphical Approach


To model the system using the state-space form of the equations, use the CD Construct State-Space Model VI with the CD Draw State-Space Equation VI.

Figure 6: State-Space Model Block Diagram


With this VI, you can now create a state-space model for the train system. Try changing the terms in the front panel, and observe the effects on the state-space model.

Figure 7: State-Space Model Front Panel

Hybrid Graphical/MathScript Approach


Alternatively, you can use a MathScript Node to create the state-space model. To do this, create a blank VI and insert a MathScript Node fro m the Structures palette. Copy and paste the following m-file code into the MathScript Node:

A=[ 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]; sys= ss(A,B,C,D);
Next, right-click on the left border of the MathScript Node and select Add Input. Name the input M1. Repeat this process to create inputs for M2, k, u, and g.

Figure 8: MathScript Node

Right-click on the right border of the MathScript Node and select Add Output to create an o utput called sys. After creating this output, right-click on it and select Choose Data Type Add-ons SS object. Next, right-click on each input and select Create Control.

Figure 9: MathScript Node with Inputs


Add the CD Draw State-Space Equation VI to the block d iagram, and create an equation indicator. Connect the sys output fro m the MathScript Node to the State-Space Model input of the CD Draw State-Space Equation VI. Finally, create a While Loop around the code, and create a control for the Loop Condition terminal.

Figure 10: Using MathScript Node to Create State-Space Equation


With this VI, you can now create a state-space model for the train system. Try changing the terms in the front panel, and observe the effects on the state-space model.

Figure 11: State-Space Equation Front Panel

The Three-Term Controller


Consider the following unity feedback system:

Figure 1: Unity Feedback System Plant: A system to be controlled Controller: Provides the excitation for the plant; Designed to control the overall system behavior
The transfer function of the PID controller looks like the following:

Kp = Proportional gain Ki = Integral gain Kd = Derivative gain


First, let's take a look at how the PID controller works in a c losed-loop system using the schematic shown above. The variable (e) represents the tracking erro r, the difference between the desired input value (R) and the actual output (Y). This erro r signal (e) will be sent to the PID controller, and the controller co mputes 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 erro r plus the integral gain (Ki) times the integral of the error p lus the deriv ative 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 .

The Characteristics of P, I, and D Controllers


A proportional controller (Kp) will have the effect of reducing the rise time and will reduce but never eliminate the steady-state error. An integral control (Ki) will have the effect of eliminating the steady -state error, but it may make the transient response worse. A derivative control (Kd) will have the effect of increasing the stability of the system,

reducing the overshoot, and improving the transient response. Effects of each of controllers Kp, Kd, and Ki on a closed-loop system are summarized in the table shown below.

CL RESPONSE RISE TIME OVERSHOOT SETTLING TIME S-S ERROR Kp Decrease Increase Small Change Decrease Ki Decrease Increase Increase Eliminate Kd Small Change Decrease Decrease Small Change Figure 2: Effect of PID Controllers on Closed-Loop System
Note that these correlations may not be exactly accurate, because Kp, Ki, and Kd are dependent on each other. In fact, changing one of these variables can change the effect of the other two. For this reason, the table should only be used as a reference when you are determin ing the values for Ki, Kp and Kd.

Example Problem
Suppose we have a simp le mass, spring, and damper p roblem.

Figure 3: Mass, Spring, and Damper


The modeling equation of this system is:

Taking the Laplace transform o f the modeling equation, we get:

The transfer function between the displacement X(s) and the input F(s) then becomes:

Let M = 1kg, b = 10 N.s/ m, k = 20 N/ m, and F(s) = 1. If we use these values in the above transfer function, the result is:

The goal of this problem is to show you how each of Kp, Ki and Kd contr ibutes to obtain fast rise time, minimu m overshoot, and no steady-state error.

Open-Loop Step Response


Let's first view the open-loop step response .

LabVIEW Graphical Approach


Create a new blan k VI, and insert the CD Construct Transfer Function Model VI an d the CD Draw Transfer Function Equation VI, fro m the Model Construction section of the Control Design palette. Create controls for the Nu merator and Deno minator terminals of the CD Construct Transfer Function Model VI. Connect the Transfer Function Model output from this VI to the input terminal o f the CD Draw Transfer Function Equation VI. Finally, create an indicator fro m the Equation terminal of the CD Draw Transfer Function VI. Create a While Loop around this code, and create a control for the Loop Con dition terminal. Next, add the CD Step Response VI to the block diagram. Connect the Transfer Function Model output fro m the CD Construct Transfer Function Model VI to the Transfer Function Model input of the CD Step Response VI. Create an indicator fro m the Step Response Graph output of the CD Step Response VI.

Figure 4: Step Response

Hybrid Graphical/MathScript Approach


Alternatively, we can use a MathScript Node with the CD Step Response VI to plot the open -loop step response, by using the following code: plant=tf(nu m,den); Make sure to change the MathScript Node output variable data type to TF object.

Figure 5: Step Reponse Using MathScript Node

Result
Running the VI from either Figure 4 or Fi gure 5 should return the plot shown below in Fi gure 6 .

Figure 6: Step Response Graph


The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to a 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
Fro m the table in Figure 3, 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:

LabVIEW Graphical Approach


Change the CD Construct Transfer Function Model VI to SISO (Sy mbolic) to allow for variables to be used. The resulting block diagram is shown in Figure 7.

Figure 7: Closed-Loop System Using LabVIEW


Now enter in the closed-loop transfer function of the system with a proportional controller. Let the proportional gain (Kp) equal 300.

Hybrid Graphical/MathScript Approach


Alternatively, to achieve this result using a MathScript Node, use the following code:

num=1; den=[1 10 20]; plant=tf(num,den); Kp=300; contr=Kp; sys_cl=feedback(contr*plant,1);

Figure 8: Closed-Loop System Using LabVIEW MathScript


Note: The m-file function called feedback was used to obtain a closed-loop transfer function directly fro m the openloop transfer function (instead of computing closed-loop transfer function by hand).

Result
Both the Lab VIEW approach and the hybrid approach should yield the graph shown below in Figure 9.

Figure 9: Proportional Control


The graph 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. Fro m the table in Figure 3, 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 equal 300 as before and let Kd equal 10.

LabVIEW Graphical Approach


Using the VI fro m Figure 7, modify the input terms on the front panel to add the derivative element to the system.

Hybrid Graphical/MathScript Approach


Alternatively, to achieve this result using a MathScript Node, use the VI fro m Figure 8 with the following code:

num=1; den=[1 10 20]; plant=tf(num,den); Kp=300; Kd=10; contr=tf([Kd Kp],1); sys_cl=feedback(contr*plant,1); Result
Both the Lab VIEW approach and the hybrid approach should yield the graph shown below in Figure 10.

Figure 10: Proportional-Derivative Control


Co mpare the graph in Figure 10 to the graph in Figure 9. The step response plot shows that the derivative controller reduced both the overshoot and the settling time, and had a 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. Fro m 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:

Let's reduce the Kp to 30, and let Ki equal 70.

LabVIEW Graphical Approach


Using the VI fro m Figure 7, modify the input terms on the front panel to add the derivative element to the system.

Hybrid Graphical/MathScript Approach


Alternatively, to achieve this result using a MathScript Node, use the VI fro m Figure 8 with the following code:

num=1; den=[1 10 20]; plant=tf(num,den); Kp=30; Ki=70; contr=tf([Kp Ki],[1 0]); sys_cl=feedback(contr*plant,1);

Result
Both the Lab VIEW approach and the hybrid approach should yield the graph shown below in Figure 11.

Figure 11: Proportional-Integral Control


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 in Figure 11 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.< /p> < h3> Lab VIEW Graphical Approach< /h3> < p> To confirm, test these terms in your VI, using the VI fro m Figure 7.< /p> < h3> Hybrid Graphical/MathScript Approach Alternatively, this result can be achieved with a MathScript Node, by using the VI fro m Figure 8 with the following code:

num=1; den=[1 10 20]; plant=tf(num,den); Kp=350; Ki=300; Kd=50; contr=tf([Kd Kp Ki],[1 0]);

sys_cl=feedback(contr*plant,1);

Result
Both the Lab VIEW approach and the hybrid approach should yield the graph shown below in Figure 12.

Figure 12: Proportional-Integral-Derivative Control


Now, we have obtained a closed-loop system with no overshoot, fast rise time, and no steady-state error.

General Tips for Designing a PID Controller


When you are designing a PID controller for a given system, follow the steps shown below to obtain a desired response.

1. 2. 3. 4. 5.

Obtain an open-loop response and determine what needs to be improved Add a proportional control to improve the rise time Add a derivative control to improve the overshoot Add an integral control to eliminate the steady-state error Adjust each of Kp, Ki, and Kd until you obtain a desired overall response. You can always refer to the table shown in this "PID Tutorial" page to find out which controller controls what characteristics.

Keep in mind that you do not need to implement all three controllers (proportion al, derivative, and integral) into a single system, if not necessary. For example, if a PI controller g ives a good enough response (like the above example), then you don't need to implement a derivative controller on the system. Keep the controller as simp le as possible.

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 :

Figure 1: Closed-Loop System


The closed-loop transfer function is:

Thus, the poles of the closed loop system are values of s such that 1 + K H(s) = 0. If we use the relation H(s) = b(s)/a(s), then the previous equation has the form:

Let n = order o f a(s) and m = o rder 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 -> in fin ity, the poles of the closed-loop system are b (s) = 0 or the zeros of H(s). No matter what we p ick 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) an d 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 infin ity. In this case, the limit o f H(s) as s -> infinity is zero. The nu mber of zeros at infin ity 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).

Plotting the Root Locus of a Transfer Function


Consider an open loop system which has a transfer function of

How do we design a feedback controller for the system by using the root locus method? Say our design criteria are 5% overshoot and 1 second rise time.

LabVIEW Graphical Approach


We can create a VI to plot the root locus, using the CD Root Locus VI fro m the Model Construction section of the Control Design palette.

Figure 2: Plotting Root Locus

Hybrid Graphical/MathScript Approach


Alternatively, you can use a MathScript Node to plot the root locus, using the following code :

num=[1 7]; den=conv(conv([1 0],[1 5]),conv([1 15],[1 20])); sys=tf(num,den);

Figure 3: Plotting Root Locus Using MathScript Node

LabVIEW MathScript Approach


Yet another approach to this problem is to use the MathScript Window. Select Tools MathScript Window, and enter the following code in the Co mmand Window :

num=[1 7]; den=conv(conv([1 0],[1 5]),conv([1 15],[1 20])); sys=tf(num,den); rlocus(sys) axis([-22 3 -15 15])

Result
Using either the Lab VIEW g raphical approach, the Lab VIEW MathScript approach, or the hybrid graphical/MathScript approach should return a plot similar to the one shown below in Figure 4.

Figure 4: Root Locus Plot

Choosing a Value of K from the Root Locus


The plot in Figure 4 above shows all possible closed-loop pole locations for a pure proportional controller. Obviously not all of those closed-loop poles will satisfy our design criteria. To determine what part of the locus is acceptable, we can use the command sgrid on to plot lines of constant damping rat io and natural frequency. In our problem, we need an overshoot less than 5% (which means a damping ratio Zeta of greater than 0.7) and a rise time of 1 second (which means a natural frequency Wn greater than 1.8). Enter the co mmand sgrid on in the MathScript co mmand window and press Enter.

The following figure shows the plot that you should see. The red and green lines have been superimp osed on the plot .

Figure 6: Root Locus Plot with Grid Lines


On the plot above, the diagonal lines indicate constant damping ratios (Zeta), and the semic ircles indicate lines of constant natural frequency (Wn). The red lines superimposed on the graph indicate pole locations with a damping ratio of 0.7. In between these lines, the poles will have Zeta > 0.7 and outside of the lines Zeta < 0.7. The g reen semicircle indicates pole locations with a natural frequency Wn = 1.8; inside the circle, Wn < 1.8 and outside the circle Wn > 1.8. Go ing back to our problem, to make the overshoot less than 5%, the poles have to be in between the two red lines, and to make the rise time shorter than 1 second, the poles have to be outside of the green 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 p lane, so the closed-loop system will be stable. Fro m 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 co mmand in the MathScript Window to choose the desired poles on the locus:

[k,poles] = rlocfind(sys)
Click and drag the closed-loop poles on the plot to designate 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 .

Figure 7: Interactive Root Locus in MathScript Window

Note that since the root locus may have mo re than one branch, when you select a pole, you may want to find out where the other poles are. Remember they will affect the response too. Fro m the plot above we see that all the poles selected are at reasonable positions. We can go ahead and use the chosen k as our proportional controller. Click OK to select these poles.

Closed-Loop Response
In order to find the step response, you need to know the closed -loop transfer function. You could compute this, or let Lab VIEW do it for you in the MathScript Window.

sys_cl= feedback(k*sys,1)
The two arguments to the function feedback are the nu merator and denominator of the open-loop system. You need to include the proportional gain that you have chosen. Unity feedback is assumed. Finally, check out the step response of your closed-loop system.

step(sys_cl)

Figure 8: Closed-Loop Response


As we expected, this response has an overshoot less than 5% and a rise time less than 1 second .

Potrebbero piacerti anche