LabVIEW Handout
LabVIEW Handout
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 .
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.
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.
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.
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.
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 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:
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 .
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.
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.
Result
Running the VI from either Figure 4 or Fi gure 5 should return the plot shown below in Fi gure 6 .
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:
Result
Both the Lab VIEW approach and the hybrid approach should yield the graph shown below in Figure 9.
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:
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.
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:
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.
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.
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 :
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).
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.
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.
The following figure shows the plot that you should see. The red and green lines have been superimp osed on the plot .
[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 .
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)