LabVIEW 开发技术丛书 控制设计与仿真实战篇

Similar documents
Example: Modeling DC Motor Position Physical Setup System Equations Design Requirements MATLAB Representation and Open-Loop Response

Example: DC Motor Speed Modeling

DC Motor Position: System Modeling

Bangladesh University of Engineering and Technology. EEE 402: Control System I Laboratory

System Modeling: Motor position, θ The physical parameters for the dc motor are:

SRV02-Series Rotary Experiment # 1. Position Control. Student Handout

FEEDBACK CONTROL SYSTEMS

Quanser NI-ELVIS Trainer (QNET) Series: QNET Experiment #02: DC Motor Position Control. DC Motor Control Trainer (DCMCT) Student Manual

1 x(k +1)=(Φ LH) x(k) = T 1 x 2 (k) x1 (0) 1 T x 2(0) T x 1 (0) x 2 (0) x(1) = x(2) = x(3) =

R a) Compare open loop and closed loop control systems. b) Clearly bring out, from basics, Force-current and Force-Voltage analogies.

EE 422G - Signals and Systems Laboratory

(b) A unity feedback system is characterized by the transfer function. Design a suitable compensator to meet the following specifications:

Mechatronics Engineering. Li Wen

EEL2216 Control Theory CT1: PID Controller Design

1 (20 pts) Nyquist Exercise

King Saud University

SAMPLE SOLUTION TO EXAM in MAS501 Control Systems 2 Autumn 2015

Positioning Servo Design Example

MAS107 Control Theory Exam Solutions 2008

Inverted Pendulum: State-Space Methods for Controller Design

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

Introduction to Feedback Control

R10 JNTUWORLD B 1 M 1 K 2 M 2. f(t) Figure 1

3 Lab 3: DC Motor Transfer Function Estimation by Explicit Measurement

Classify a transfer function to see which order or ramp it can follow and with which expected error.

ME 3210 Mechatronics II Laboratory Lab 4: DC Motor Characteristics

Lab 3: Model based Position Control of a Cart

6.1 Sketch the z-domain root locus and find the critical gain for the following systems K., the closed-loop characteristic equation is K + z 0.

LABORATORY INSTRUCTION MANUAL CONTROL SYSTEM II LAB EE 693

The basic principle to be used in mechanical systems to derive a mathematical model is Newton s law,

Implementation Issues for the Virtual Spring

Pitch Rate CAS Design Project

QNET DC Motor Control

Appendix A: Exercise Problems on Classical Feedback Control Theory (Chaps. 1 and 2)

CHAPTER 7 : BODE PLOTS AND GAIN ADJUSTMENTS COMPENSATION

Computer Aided Control Design

Digital Control Systems

DIGITAL CONTROL OF POWER CONVERTERS. 3 Digital controller design

sc Control Systems Design Q.1, Sem.1, Ac. Yr. 2010/11

CYBER EXPLORATION LABORATORY EXPERIMENTS

Table of Laplacetransform

PID Control. Objectives

Application Note #3413

Course Summary. The course cannot be summarized in one lecture.

Introduction to Controls

Laboratory Exercise 1 DC servo

School of Mechanical Engineering Purdue University. ME375 ElectroMechanical - 1

School of Mechanical Engineering Purdue University. ME375 Feedback Control - 1

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur

(a) Torsional spring-mass system. (b) Spring element.

LABORATORY INSTRUCTION MANUAL CONTROL SYSTEM I LAB EE 593

Rotary Motion Servo Plant: SRV02. Rotary Experiment #01: Modeling. SRV02 Modeling using QuaRC. Student Manual

Systems Analysis and Control

Experiment 81 - Design of a Feedback Control System

CHAPTER 1 Basic Concepts of Control System. CHAPTER 6 Hydraulic Control System

Lab 3: Quanser Hardware and Proportional Control

ENGG4420 LECTURE 7. CHAPTER 1 BY RADU MURESAN Page 1. September :29 PM

Index. Index. More information. in this web service Cambridge University Press

EDEXCEL NATIONALS UNIT 5 - ELECTRICAL AND ELECTRONIC PRINCIPLES. ASSIGNMENT No. 3 - ELECTRO MAGNETIC INDUCTION

Power System Operations and Control Prof. S.N. Singh Department of Electrical Engineering Indian Institute of Technology, Kanpur. Module 3 Lecture 8

Chapter 2. Classical Control System Design. Dutch Institute of Systems and Control

Massachusetts Institute of Technology Department of Mechanical Engineering Dynamics and Control II Design Project

EC CONTROL SYSTEM UNIT I- CONTROL SYSTEM MODELING

Laboratory 11 Control Systems Laboratory ECE3557. State Feedback Controller for Position Control of a Flexible Joint

AMME3500: System Dynamics & Control

Outline. Classical Control. Lecture 5

Control Systems. University Questions

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Dr Ian R. Manchester Dr Ian R. Manchester AMME 3500 : Root Locus

Answers for Homework #6 for CST P

Control Systems Engineering ( Chapter 8. Root Locus Techniques ) Prof. Kwang-Chun Ho Tel: Fax:

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING BENG (HONS) IN BIOMEDICAL ENGINEERING SEMESTER 1 EXAMINATION 2017/2018 ADVANCED BIOMECHATRONIC SYSTEMS

FATIMA MICHAEL COLLEGE OF ENGINEERING & TECHNOLOGY

Engraving Machine Example

Department of Electrical and Computer Engineering. EE461: Digital Control - Lab Manual

ECE 486 Control Systems

Feedback Control Systems

Root Locus. Motivation Sketching Root Locus Examples. School of Mechanical Engineering Purdue University. ME375 Root Locus - 1

Digital Control: Summary # 7

EXPERIMENTALLY DETERMINING THE TRANSFER FUNCTION OF A SPRING- MASS SYSTEM

Mechatronics Modeling and Analysis of Dynamic Systems Case-Study Exercise

ECE382/ME482 Spring 2005 Homework 7 Solution April 17, K(s + 0.2) s 2 (s + 2)(s + 5) G(s) =

THE REACTION WHEEL PENDULUM

Proportional plus Integral (PI) Controller

Control of Electromechanical Systems

Video 5.1 Vijay Kumar and Ani Hsieh

Rotary Motion Servo Plant: SRV02. Rotary Experiment #11: 1-DOF Torsion. 1-DOF Torsion Position Control using QuaRC. Student Manual

EE C128 / ME C134 Fall 2014 HW 6.2 Solutions. HW 6.2 Solutions

ECE 320 Linear Control Systems Winter Lab 1 Time Domain Analysis of a 1DOF Rectilinear System

Lecture 12. Upcoming labs: Final Exam on 12/21/2015 (Monday)10:30-12:30

CONTROL SYSTEMS ENGINEERING Sixth Edition International Student Version

(Refer Slide Time: 2:11)

Exam. 135 minutes + 15 minutes reading time

ELECTRONICS & COMMUNICATIONS DEP. 3rd YEAR, 2010/2011 CONTROL ENGINEERING SHEET 5 Lead-Lag Compensation Techniques

7.4 STEP BY STEP PROCEDURE TO DRAW THE ROOT LOCUS DIAGRAM

Analysis and Design of Control Systems in the Time Domain


ECE382/ME482 Spring 2005 Homework 6 Solution April 17, (s/2 + 1) s(2s + 1)[(s/8) 2 + (s/20) + 1]

Outline. Classical Control. Lecture 1

State Feedback Controller for Position Control of a Flexible Link

Transcription:

LabVIEW 开发技术丛书 控制设计与仿真实战篇

录目录 Modeling DC Motor Position 1-8 Motor Position PID Control 9-18 Root Locus Design Method for Motor Position Control 19-28 Frequency Design Method for Motor Position Control 29-49 State-Space Design Method for Motor Position Control 50-56 Motor Position Digital Control 57-66 Simulation Modeling for DC Motor Position 67-78

Modeling DC Motor Position 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: Figure 1: DC Motor Circuit and Free Body Diagram 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 University'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 The rotor and shaft are assumed to be rigid 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: 1

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: 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 the output. We can obtain the position by integrating Theta Dot, so we just need to divide the transfer function by s. State-Space Model 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 2

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: Settling time less than 40 milliseconds Overshoot less than 16% No steady-state error No steady-state error due to a disturbance State-Space Model in LabVIEW We can represent the state-space equations in LabVIEW using either a graphical or a hybrid graphical/textual approach. LabVIEW Graphical Approach Begin with a blank VI. Insert the CD Construct State Space Model VI from the Model Construction section of the Control Design palette, and create controls for each of the inputs. Figure 2: Construct State-Space Model Next, add the CD Draw State-Space Equation VI. This will display the state-space equation on the front panel. Create an output for the Equation from the CD Draw State-Space Equation VI. Figure 3: Display State-Space Equation Now add the CD Step Response VI from the Time Response section of the Control Design palette. Create a control for the Time Info input and an indicator for the Step Response Graph output. 3

Figure 4: Step Response VI (Download) This should result in a front panel that looks like this: Hybrid Graphical/MathScript Approach Figure 5: State-Space Front Panel (Download) Alternatively, we can get the same results with a hybrid approach, using the MathScript Node. Begin with a blank VI, and insert a MathScript Node from the Structures palette. Add the following code to your MathScript Node: J=3.2284E-6; b=3.5077e-6; K=0.0274; R=4; L=2.75E-6; 4

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]; motor=ss(a,b,c,d); Then create a State-Space output from the Node, and add the CD Draw State-Space Equation VI and the CD Step Response VI as we did in the graphical approach. Transfer Function in LabVIEW Figure 6: Hybrid Graphical/MathScript Block Diagram (Download) Another option is to represent the transfer function in LabVIEW, instead of using the state-space model. LabVIEW Graphical Approach To represent the transfer function using a LabVIEW graphical approach, begin by inserting the CD Construct Transfer Function Model VI (from the Model Construction section of the Control Design palette) into a blank VI. Create controls for the Numerator, Denominator, and Variables inputs. Figure 7: Construct Transfer Function Equation Next, add the CD Draw Transfer Function Equation VI to the block diagram, and create an indicator for the Equation output. This will display the transfer function equation on the front panel. 5

Figure 8: Draw Transfer Function Equation Now add the CD Step Response VI from the Time Response section of the Control Design palette. Create a control for the Time Info input and an indicator for the Step Response Graph output. Figure 9: Step Response VI (Download) This should result in a front panel that looks like this: Figure 10: Transfer Function Front Panel (Download) 6

Hybrid Graphical/MathScript Approach Alternatively, we can get the same results with a hybrid approach, using the MathScript Node. Begin with a blank VI, and insert a MathScript Node from the Structures palette. Add the following code to your MathScript Node: 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]; motor=tf(num,den); Create a Transfer Function output from the Node, and then add the CD Draw State-Space Equation VI and the CD Step Response VI as we did in the graphical approach. Result Figure 11: Hybrid Graphical/MathScript Block Diagram (Download) Using either the state-space model or the transfer function, you should see the following step response graph on the front panel when you run the VI: 7

Figure 12: Step Response for Open-Loop System 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. 8

Motor Position PID Control PID Design Method for DC Motor Position From the main problem, the dynamic equation in transfer function form is the following: The system schematic looks like: For the original problem setup and the derivation of the above equations, please refer to themodeling DC Motor Position page. With a 1 rad/sec step reference, the design criteria are: Settling time less than 0.04 seconds Overshoot less than 16% No steady-state error No steady-state error due to a disturbance Proportional Control Now let's design a PID controller and add it into the system. Recall that the transfer function for a PID controller is: Let's first try using a proportional controller with a gain of 1.7. LabVIEW Graphical Approach Start by creating a VI to model the transfer function for the motor. For an explanation of how to create this model, refer to the Modeling DC Motor Position page. 9

Figure 1: Construct Motor Transfer Function Next, create a transfer function for the controller. Add a second CD Construct Transfer Function Model VI from the Model Construction section of the Control Design palette. Create controls for the Symbolic Numerator and Variables inputs. Figure 2: Construct Controller Transfer Function Put these models in series using a CD Series VI. Figure 3: Models in Series 10

Now add a CD Feedback VI, and connect the output from the CD Series VI to the Model 1 input of the CD Feedback VI. We use the Feedback VI to determine the closed-loop transfer function. Next, create another transfer function model. Create a constant input for the numerator, and set this equal to 1. Connect this new transfer function to the Model 2 input of the CD Feedback VI. Figure 4: Models in Series with Feedback VI Now add a CD Step Response VI, connect the output from the CD Feedback VI to the input of the CD Step Response VI, and create a Time Response input and a Step Response Graph output for the CD Step Response VI. On the front panel, set the Time Info so that t0 = 0, dt = 0.001, and tf = 0.2. Figure 5: Finished Block Diagram for Proportional Control When you run the VI, you should see the following plot on the front panel: 11

Hybrid Graphical/MathScript Approach Figure 6: Response to Step Input, Kp = 1.7 Alternatively, you can achieve the same results using a hybrid graphical/mathscript approach. Begin by creating a blank VI, and add a MathScript Node. Paste the following code into your MathScript Node: 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]; motor=tf(num,den); Kp=1.7; contr=kp; sys_cl=feedback(contr*motor,1); We use the 'feedback' command to determine the closed-loop transfer function. Create an output called sys_cl, and change its type to a TF Object. Add the CD Step Response VI to your block diagram, and connect the sys_cl output to the Transfer Function Model input of the Step Response VI. Finally, create a control for the Time Response terminal and an indicator for the Step Response Graph output. On the front panel, set t0 to 0, dt to.001, and tf to 0.2. The block diagram should look like this: 12

Figure 7: Proportional Control, Hybrid Approach (Download) Running this VI should result in a graph similar to the one in Figure 6. LabVIEW MathScript Approach To achieve this result using MathScript, open the MathScript Window and paste the above code into the Command Window. Add the following lines of code to the end: t=0:0.001:0.2; step(sys_cl,t) Running this code should result in a graph similar to Figure 6. Step Disturbance Response To look at the step disturbance response for the system, and if you are using a graphical approach, connect the motor and controller models to the inputs of another CD Feedback VI, then create inputs and outputs to the VI as we did before. Figure 8: Block Diagram for Proportional Control with Step Disturbance (Download) If you are using a hybrid or MathScript approach, add the following code to your MathScript Node, and create an output for dist_cl: 13

dist_cl=feedback(motor,contr); All of these methods should result in the following plot: PID Control Figure 9: Response to Step Disturbance, Kp = 1.7 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 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 first try a PI controller to get rid of the disturbance steady state error. LabVIEW Graphical Approach To achieve this with a graphical approach, add on to the VI that we created earlier. Create a control for the Symbolic Denominator input for the controller transfer function VI. Figure 10: PID Control Block Diagram with Step Disturbance (Download) Change your front panel values so that the values for the controller numerator are "Ki Kp" and the values for its denominator are "0 1". Change the controller variables on the front panel so that the variable Kp has a value of 1.7, and Ki has a value of 20. 14

Running this VI should give you the following Step Response plot: Figure 11: Response to Step Input, Kp = 1.7, Ki = 20 Also, you should see the following Step Disturbance plot: Figure 12: Response to Step Disturbance, Kp = 1.7, Ki = 20 The integral control has reduced the steady state error to zero. Hybrid Graphical/MathScript Approach If you are using a hybrid approach, change your MathScript code so that it looks like the following: 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]; motor=tf(num,den); 15

Kp=1.7; Ki=20; contr=tf([kp Ki],[1 0]); sys_cl=feedback(contr*motor,1); Running this VI should result in a similar response to Figure 11. To see what happened to the step disturbance response, add the following code to your MathScript Node: dist_cl=feedback(motor,contr); Change the sys_cl output name to dist_cl and run the VI. You should see a plot similar to Figure 12. Tuning the Gains Although the steady state error has been removed, the settling time is still too long. Let's increase the gains in order to speed up the response. Change Ki to 200 and Kp to 17. Rerun your VI, and you should get plots like these: Figure 13: Response to Step Input, Kp = 17, Ki = 200 Figure 14: Response to Step Disturbance, Kp = 17, Ki = 200 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 adding a derivative term to reduce the overshoot. If you are using a graphical approach, change your front panel values so that the controller numerator has "Ki Kp Kd", the denominator has "0 1", and the variables have Kp = 17, Ki = 200, and Kd = 0.15. To do this with the hybrid approach, make the following changes to your MathScript code: 16

Kp=17; Ki=200; Kd=0.15; contr=tf([kd Kp Ki],[1 0]); sys_cl=feedback(contr*motor,1); You should now get this plot: Figure 15: Response to Step Input, Kp = 17, Ki = 200, Kd = 0.15 And your step disturbance plot should look like this: Figure 16: Response to Step Disturbance, Kp = 17, Ki = 200, Kd = 0.15 We now see that our step response looks really good. It has less than 16% overshoot, the settling time is roughly 40 ms, 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 and rerun your VI. You should get the following plots: 17

Figure 17: Response to Step Input, Kp = 17, Ki = 600, Kd = 0.15 Figure 18: Response to Step Disturbance, Kp = 17, Ki = 600, Kd = 0.15 We now can see that the step response has a settling time of roughly 40 ms, 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 all of our design requirements will be satisfied. 18

Root Locus Design Method for Motor Position Control From the main problem, the dynamic equations in transfer function form are the following: and the system schematic looks like: For the original problem setup and the derivation of the above equations, please refer to themodeling DC Motor Position page. With a 1 rad/sec step reference, the design criteria are: Settling time less than 0.04 seconds Overshoot less than 16% No steady-state error to a reference No steady-state error due to a disturbance Now let's design a controller using the root locus method. Open the MathScript Window (Tools >> MathScript Window) and click on the Script tab to view the Script Editor. Type the following commands in the Script Editor: J=3.2284E-6; b=3.5077e-6; K=0.0274; R=4; L=2.75E-6; num=k; 19

den=[(j*l) ((J*R)+(L*b)) ((b*r)+k^2) 0]; motor=tf(num,den); Drawing the Open-Loop Root Locus The main idea of root locus design is to find the closed-loop response from the open-loop root locus plot. Then by adding zeros and/or poles to the original plant, the closed-loop response will be modified. Let's first view the root locus for the plant. Add the following commands to your MathScript code in the Script Editor: rlocus(motor) sgrid on Now, run your script by clicking on the button with a green arrow at the top of the Script Editor. You should see the root locus plot below: Figure 1: Root Locus - P Control 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 this pole by doing a model reduction. Model Reduction If you have a transfer function which has one (or more) poles to the far left of the dominant poles, you can neglect these poles and the closed-loop response for small gains will not be affected (for large gains, these poles will push the root locus to the right-half plane, causing instability). The correct way to neglect these poles, keeping the DC gain of the transfer function constant, is as follows: 20

Let's see what the poles of the original transfer function are. Enter the following command in the Command Window (bottom left corner of the MathScript Window): roots(den) You should see the following output: ans = 0-59.226-1.4545e+006 We want to neglect the pole at -1.45e6. This can be translated into MathScript code. Replace your code in the Script Editor with the following: 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]; poles=roots(den); den2=deconv(den,[1/max(abs(poles)) 1]); motor=tf(num,den2); Run this script. You can now check that the other poles have not been affected by entering the following code in the Command Window: roots(den2) Now we can draw the root locus of the reduced system. Add the following commands to the end of your code in the Script Editor and re-run it. rlocus(motor) sgrid on 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: 21

Figure 2: Root Locus - P Control 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. Replace your code in the Script Editor with the following: 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]; poles=roots(den); den2=deconv(den,[1/max(abs(poles)) 1]); motor=tf(num,den2); contr=tf(1,[1 0]); 22

rlocus(contr*motor) sgrid on axis([-400 100-200 200]) Note that this adds a 1/s term to the forward loop. Run this script, and you should see the following plot: Figure 3: Root Locus - I Control From this root locus, we can see that the closed-loop system under integral control is never stable, and another controller must be used. Proportional and Integral Control Now, let's modify the integral controller to a PI controller. Using PI instead of I control adds a zero to the open-loop system. We'll place this zero at s=-20. The zero must lie between the open-loop poles of the system in this case so that the closed-loop will be stable. Change the line defining the controller in your script to the following. contr=tf([1 20],[1 0]); Re-run your script, and you should see the following plot: 23

Figure 4: Root Locus - PI Control 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. Proportional, Integral, and Derivative Control In order to pull the root locus further to the left, to make it faster, we need to place a second open-loop zero, resulting in a PID controller. After some experimentation, we can place the two PID zeros at s=-60 and s=-70. Change the line defining the controller in your script to the following: numc=conv([1 60],[1 70]); denc=[1 0]; contr=tf(numc,denc); Re-run your script, and you should obtain the following plot. 24

Figure 5: Root Locus - PID Control 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 its 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. Finding the Gain If you recall, we need the settling time and the overshoot to be as small as possible, particularly because of the effect of the extra zero. Large damping corresponds to points on the root locus near the real axis. A fast response corresponds to points on the root locus far to the left of the imaginary axis. To find the gain corresponding to a point on the root locus, we can use the rlocfind command. We can find the gain and plot the step response using this gain all at once. To do this, enter the following command in the Command Window: [k,poles] = rlocfind(contr*motor) A window titled Interactive Root Locus should appear. In this window, drag either the Gain slider or the red x marks, so that the roots on the loop end up close to the real axis, as shown below. This will ensure that the response will be as fast as possible with as little overshoot as possible. These pole locations would indicate that the response would have almost no overshoot, but you must remember that the zero will add some overshoot. 25

Figure 6: Interactive Root Locus Window When you are satisfied with the pole locations you have chosen, click OK. After doing this, you should see the following output in the Output Window section of the MathScript Window. k = poles = 0.13263-140.53-9.4686i -140.53 + 9.4686i -59.576 + 0i Note that the values returned in your MathScript Output Window may not be exactly the same, but should at least have the same order of magnitude. Next, add the following code to the end of your script, and run it. sys_cl=feedback(k*contr*motor,1); t=0:0.001:.1; step(sys_cl,t) You should get the following step response plot: 26

Figure 7: Response to Step Input with PID 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 the end of your script: dist_cl=feedback(motor,k*contr); step(dist_cl,t) Re-run your script, and you should get the following plot: 27

Figure 8: Response to Step Disturbance with PID You can see that the response to a step disturbance reaches a steady-state value of zero, and in fact, stays within 0.02 (or 2%) after 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 LabVIEW MathScript is used to verify and refine the placement. 28

Frequency Design Method for Motor Position Control Drawing the Original Bode Plot The main idea of frequency-based design is to use the Bode plot of the open-loop transfer function to estimate the closed-loop response. Adding a controller to the system changes the open-loop Bode plot, therefore changing the closed-loop response. Let's first draw the Bode plot for the original open-loop transfer function. LabVIEW Graphical Approach Using the approach that was introduced in the Frequency Response Tutorial, create a transfer function for the system and output the resulting bode plot. Figure 1: Open-Loop Transfer Function - Block Diagram (Download) 29

LabVIEW MathScript Approach Figure 2: Open-Loop Transfer Function - Front Panel (Download) Alternatively, you can achieve the same results using a MathScript approach. Open the MathScript Window (Tools >> MathScript Window) and click on the Script tab to view the Script Editor. Type the following commands in the Script Editor: 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]; motor = tf(num,den); 30

The main idea of frequency-based design is to use the Bode plot of the open-loop transfer function to estimate the closed-loop response. Adding a controller to the system changes the open-loop Bode plot, therefore changing the closed-loop response. Let's first draw the Bode plot for the original open-loop transfer function. Add the following code to the end of your code, and then run the script. Result w=logspace(0,4,101); bode(motor,w) Either approach should result in the following Bode plot: Adding an Integrator Figure 3: Original Open-Loop Transfer Function Now lets add an integrator for zero steady-state error in response to a step disturbance. LabVIEW Graphical Approach Create a second transfer function model to represent the controller. Place the controller model in series with the plant model, and draw the bode plot from the combined system. 31

Figure 4: Adding an Integrator - Block Diagram (Download) 32

LabVIEW MathScript Approach Figure 5: Adding an Integrator - Front Panel (Download) If you are using the MathScript approach, add the following lines to your existing code: numi = 1; deni = [1 0]; contr = tf(numi,deni); bode(contr*motor,w) Result Either approach should result in the following plot: 33

Figure 6: System with Integrator for Zero Steady-State Error Gain and Phase Margin Specifications and Controller Design From the Bode phase plot we can see that there is a pole near 60 rad/sec. We will use a PI controller to put a zero at s=60 to flatten out the phase curve. LabVIEW Graphical Approach Using the previous VI, modify the controller so that the controller transfer function is (s+60)/s. LabVIEW MathScript Approach If you are using the MathScript approach, add the following lines to your script: numpi = [1 60]; denpi = [1 0]; contr = tf(numpi,denpi); bode(contr*motor,w) Result Either approach should result in the following plot: 34

Figure 7: System with PI Controller We want less than a 16% overshoot, so let's compute the damping ratio based on a 16% overshoot. Also the corresponding phase margin is 100 times the damping ratio. From the settling time requirement, we are able to compute the desired bandwidth frequency. We want to have at least 50 degrees of phase margin, therefore the gain should fall between -6 and -7.5 db at some frequency after 250 rad/sec. From the Bode plot we see that we must add about 80 degrees of phase and 60 db of gain at a frequency of 250 rad/sec. The gain plot will then lie between -6 and -7.5 db and after 244 rad/sec. From the previous 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. LabVIEW Graphical Approach Using the previous VI, insert a CD Series VI into the block diagram, between the existing CD Series VI and the CD Bode VI. Create a MathScript node, create a transfer function output called 'contr2', and paste the following code into the node: zeta = -log(.16)/sqrt(pi^2+(log(.16))^2); PM = 100*zeta; wbw = (4/(0.04*zeta))*sqrt((1-2*zeta^2)+sqrt(4*zeta^4-4*zeta^2+2)); a = (1 - sin(pm*pi/180))/(1 + sin(pm*pi/180)); T = 1/(wbw*sqrt(a)); contr2 = tf([t 1],[a*T 1]); 35

Your block diagram should look like this: LabVIEW MathScript Approach Figure 8: Gain and Phase Margin Compensator - Block Diagram (Download) If you are using the MathScript approach, add the following lines to your existing code: zeta = -log(.16)/sqrt(pi^2+(log(.16))^2); PM = 100*zeta; wbw = (4/(0.04*zeta))*sqrt((1-2*zeta^2)+sqrt(4*zeta^4-4*zeta^2+2)); Next, add the following lines to the end of your script: a = (1 - sin(pm*pi/180))/(1 + sin(pm*pi/180)); T = 1/(wbw*sqrt(a)); contr2 = tf([t 1],[a*T 1]); w = logspace(2,3,101); bode(contr*contr2*motor,w) 36

Result Either approach should result in the following plot: Figure 9: System with Lead Compensator 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. LabVIEW Graphical Approach Add an additional transfer function model and put it in series with the previous controller. Create a numeric constant for the numerator, and set its value to 10. 37

LabVIEW MathScript Approach Figure 10: System With Gain of 10 - Block Diagram (Download) Add the following lines to the end of your script: Kp = 10; bode(kp*contr*contr2*motor,w) Result With either approach, you should get the following plot: 38

Figure 11: System with Gain of 10 Let's now check the step response of the closed loop system. LabVIEW Graphical Approach Place a CD Feedback VI on the block diagram, and create a new transfer function with a numerator of 1 (as we did in the tutorial). This Model 1 input for the feedback VI should come from the output of the previous CD Series VI, and the Model 2 input should come from the new transfer function model. Place a CD Step Response VI on the block diagram, and use the output from the feedback VI as the Step Response input. On the front panel, set the time constraints so that t0 = 0, dt = 0.001, and tf = 0.1. 39

Figure 12: Block Diagram for Step Response of System LabVIEW MathScript Approach Type the following code in the Command Window: sys_cl = feedback(kp*contr*contr2*motor,1); t = 0:0.001:0.1; step(sys_cl,t) Result With either approach, you should get the following plot: 40

Figure 13: Step Response of the Closed-Loop System 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. LabVIEW Graphical Approach On the block diagram, change the value of PM in the MathScript Node. Replace the second line of code with: PM = 70; LabVIEW MathScript Approach Add the following lines to the end of your script: PM = 70; a = (1 - sin(pm*pi/180))/(1 + sin(pm*pi/180)); T = 1/(wbw*sqrt(a)); contr2 = tf([t 1],[a*T 1]); w = logspace(2,3,101); bode(contr*contr2*motor,w) Result With either approach, you should get the following plot: 41

Figure 14: System with Phase Margin of 70 Degrees 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. LabVIEW Graphical Approach On the block diagram, find the numeric constant for the numerator of the gain model, which was set to 10. Right-click the constant and change it to a control. On the front panel, change the control to a vertical slider by right-clicking the control and selecting 'Replace'. Run the VI, and change the value from 10 to 5. LabVIEW MathScript Approach Add the following lines to the end of your script: Kp=5; bode(kp*contr*contr2*motor,w) Result With either approach, you should get the following plot: 42

Figure 15: System with Gain of 5 Now let's check the step response again. LabVIEW Graphical Approach The resulting step response should appear on your front panel as you change the gain. LabVIEW MathScript Approach If you are using the MathScript approach, type the following code in the Command Window: sys_cl = feedback(kp*contr*contr2*motor,1); t = 0:0.001:0.1; step(sys_cl) Result With either approach, you should get the following step response:: 43

Figure 16: Step Response of Closed-Loop System 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. LabVIEW Graphical Approach In the MathScript Node on the block diagram, insert the following just above the last line of code: wbw = 300; a = (1 - sin(pm*pi/180))/(1 + sin(pm*pi/180)); T = 1/(wbw*sqrt(a)); LabVIEW MathScript Approach Add the following lines to the end of your script: wbw = 300; a = (1 - sin(pm*pi/180))/(1 + sin(pm*pi/180)); T = 1/(wbw*sqrt(a)); contr2 = tf([t 1],[a*T 1]); w = logspace(2,3,101); bode(contr*contr2*motor,w) Result With either approach, you should get the following plot: 44

Figure 17: System with Higher Bandwidth 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. LabVIEW Graphical Approach Change the gain to 8 using the front panel slider. LabVIEW MathScript Approach Add the following lines to the end of your script: Kp = 8; bode(kp*contr*contr2*motor,w); Result With either approach, you should get the following plot: 45

Figure 18: System with Gain of 8 Now let's check the step response of the closed loop system. LabVIEW Graphical Approach The resulting step response should appear on your front panel as you change the gain. LabVIEW MathScript Approach Type the following code in the Command Window: sys_cl = feedback(kp*contr*contr2*motor,1); t = 0:0.001:0.1; step(sys_cl) Result With either approach, you should get the following step response: 46

Figure 19: Final Step Response of Closed-Loop System Now everything looks good. We have less than 16% overshoot and a settling time of about 40 milliseconds. Final LabVIEW VI The final VI block diagram should look like this: 47

Figure 20: Final Block Diagram (Download) Final MathScript Code The MathScript code below is the simplified version of what was done above. After you run this script, 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; 48

den = [(J*L) ((J*R)+(L*b)) ((b*r)+k^2) 0]; motor = tf(num,den); PM = 70; wbw = 300; a = (1-sin(PM*pi/180))/(1+sin(PM*pi/180)); T = 1/(wbw*sqrt(a)); numpi = [1 60]; denpi = [1 0]; contr = tf(numpi,denpi); contr2 = tf([t 1],[a*T 1]); Kp = 8; w = logspace(2,3,101); bode(kp*contr*contr2*motor,w) sys_cl = feedback(kp*contr*contr2*motor,1); t = 0:0.001:0.1; step(sys_cl) 49

State-Space Design Method for Motor Position Control From the main problem, the dynamic equations in state-space form are the following: For the original problem setup and the derivation of the above equations, please refer to themodeling DC Motor Position page. With a 1 rad reference added to the system, the design criteria are: Settling time less than 0.04 seconds Overshoot less than 16% Zero steady-state error to a step input Zero steady-state error to a step disturbance Open the MathScript Window (Tools >> MathScript Window) and click on the Script tab to view the Script Editor. Type the following commands in the Script Editor: 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]; sys=ss(a,b,c,d); 50

Designing the Full-State Feedback Controller Since all of the state variables in our problem are very easy to measure (simply add an ammeter for current, a tachometer for speed, and a potentiometer for position), we can design a full-state feedback controller for the system without worrying about having to add an observer. The schematic for a full-state feedback system is: 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, LabVIEW will find the controller matrix, Kc, for us. Simply add the following code to the end of your script: 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 state-space equations become: To see the closed-loop response, add the following lines to your existing code: t = 0:0.001:.05; sys_cl=ss(a-b*kc,b,c,d); 51

step(sys_cl,t) When you run the script, you should see the following plot: Disturbance Response Figure 1: Closed-Loop Step Response with Full State Feedback 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 code to your existing script and re-run it. dist_cl=ss(a-b*kc,[0;1/j;0],c,d); step(dist_cl,t) You should see the following plot when you run the script: 52

Figure 2: Disturbance Response with Full State Feedback This is not a zero steady-state error to a disturbance, and we will have to compensate for this. Adding Integral Action We know that if we put an extra integrator in series with the plant it can remove steady-state error to an input. If the integrator comes before the injection of the disturbance, it will cancel the disturbance in steady state. This changes our control structure so it now resembles the following: 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. 53

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 the 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 code to your existing script: Aa = [0 1 0 0 0 0 1 0 0 0 -b/j K/J 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; 54

Kc = place(aa,bau,[p1,p2,p3,p4]); t = 0:0.001:.05; sys_cl = ss(aa-bau*kc,ba,ca,da); step(sys_cl,t) Run your script, and you will get the following output: Figure 3: Step Response - Full State Feedback with Integrator To look at the disturbance response, we apply a similar B matrix as we did previously when simulating the disturbance response. dist_cl = ss(aa-bau*kc,[0 ; 0 ; 1/J ; 0],Ca,Da); step(dist_cl,t) 55

Figure 4: Disturbance Response - Full State Feedback with Integrator We can see that all of the design specifications have been met by this controller. 56

Motor Position Digital Control In this example, the controller will be designed by a Root Locus method. A digital DC motor model can obtain from conversion of analog DC motor model, as we will describe. According to themodeling DC Motor Position page, the open-loop transfer function for DC motor's position is: 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: Settling time: Less than 0.04 seconds Overshoot: Less than 16% Steady-state error: 0 with a step disturbance input Continuous to Discrete Conversion The first step in the design of a discrete-time system is to convert a continuous transfer function to a discrete transfer function. LabVIEW MathScript can be used to convert the above transfer function to a discrete transfer function by using the c2d command. The c2d command requires three arguments: system, a sampling time (T) and a type of hold circuit. In this example we will use the zero-order hold (zoh). From the design requirement, let the sampling time, T, equal 0.001 seconds, which is 1/100 of the required time constant or 1/40 of the required settling time. In LabVIEW, click Tools >> MathScript Window. In the MathScript Window, select the Script tab, and add the following code in the Script Editor: R = 4; L = 2.75E-6; K = 0.0274; J = 3.2284E-6; b = 3.5077E-6; 57

num = K; den = [(J*L) (J*R)+(L*b) (R*b)+(K^2) 0]; motor = tf(num,den) Ts = 0.001; motor_d = c2d(motor, Ts, 'zoh') [numd,dend] = tfdata(motor_d,'v') When you run this script, you should see the following result: Transfer Function Input:1 Output:1 0.001z^2+0.001z+0 --------------------- z^3-1.942z^2+0.942z+0 Sampling time: 0.001000 numd = 0 0.0010389 0.0010214 9.4536e-010 dend = 1-1.9425 0.94249 5.2319e-017 In this result, notice that both the numerator and the denominator of the discrete transfer function have one extra root at z = 0. Also, we can get rid of the leading zero coefficient in the numerator. To do this, we will cancel out the extra pole and zero to avoid numerical problems. Otherwise, LabVIEW will consider both the numerator and denominator to be fourth-order polynomials. Add the following code to the end of your script: numd = numd(2:3); dend = dend(1:3); motor_d = tf(numd,dend,ts) When you run the script, you will find that the discrete transfer function is: 58

θ(z) 0.001z+0.001 ----- = ---------------- V(Z) z^2-1.942z+0.942 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 feedback command. After closing the loop, let's see how the closed-loop stairstep response performs by using thestep and stairs commands. The step command will provide the vector of discrete step signals and the stairs command will connect these discrete signals. Add the following MathScript code at the end of the existing script: sys_cl = feedback(motor_d,1); [x1,t] = step(sys_cl,.5); stairs(t,x1) xlabel('time (seconds)') ylabel('position (rad)') title('stairstep Response: Original') When you run the script, you should see the following plot: Root Locus Design Figure 1: Stairstep Response: Original The main idea of root locus design is to obtain the closed-loop response from the open-loop root locus plot. By adding zeros and poles to the original system, the root locus can be modified, to get a new closed-loop response. First, let's see the root-locus for the system itself. In your script, add the following commands: rlocus(motor_d) title('root Locus of Original System') zgrid(0,0) 59

axis([-2,2,-2,2]) When you run your script, you should see the following plot: Figure 2: Root Locus of Original System 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 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 the extra pole at 1, the root locus will have three poles near 1. Therefore the root locus will move out to the right, and the closed-loop response will be more unstable. Thus, we must add one zero near 1, inside the unit circle, to cancel with one pole and pull the root locus in. We will add a zero at z = 0.95. In general, we must at least add as many poles as zeros for the controller to be causal. Add the following MathScript code to the end of your existing script: numi = [1-0.95]; deni = [1-1]; icontr = tf(numi,deni,ts); Recall from the Digital Control Tutorial page that the zgrid on command can be used to find the desired region (satisfying the design requirements) on the discrete root locus plot. From the design requirement, the settling time is less than 0.04 seconds and the percent overshoot is less than 16%. The formulas for finding the damping ratio and natural frequency are: 60

where OS = the percent overshoot, and Ts = the settling time. The required damping ratio is 0.5 and the natural frequency is 200 rad/sec = 0.2 rad/sample. Add the following code to the end of your script: rlocus(icontr*motor_d); zgrid on title('root Locus of System with Integral Control') axis([-2,2,-2,2]) When you run the script, you should get the following plot: Figure 3: Root Locus of System with Integrated 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 at 0.5 and the natural frequency line at 0.2 cross each other, to satisfy the design requirements. Thus we have to pull the root locus in further 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 zeros near the desired poles. After going through some trial and error, one more pole is added at 0.61 and two zeros are added at 0.76. Add the following code to your script: numc = conv([1-0.76],[1-0.76]); 61

denc = conv([1 0.9831],[1-0.61]); contr = tf(numc,denc,ts); rlocus(icontr*contr*motor_d); zgrid on title('root Locus of Compensated System') axis([-2,2,-2,2]) The system will have a pole at 0.61 instead of -0.98. When you run the script, you should get the following root locus plot: Figure 4: Root Locus of Compensated System From the above root locus plot, we see that the root locus is now in the desired region. Let's find a gain, K, on the root locus plot by using the rlocfind command. Then, we can obtain the stairstep response with the selected gain. Add the following commands to the end of your script: K = rlocfind(icontr*contr*motor_d) sys_cl = feedback(k*icontr*contr*motor_d,1); [x2,t] = step(sys_cl,.05); stairs(t,x2) xlabel('time (seconds)') ylabel('position (rad)') 62

axis([0,0.05,0,1.4]) title('stairstep Response of Compensated System') When you run the script, you should see an Interactive Root Locus window pop up. On the plot, click on the x-axis (Real Axis) values to change the viewing window. Change the left-most x-axis value to 0.2 and the right-most value to 1.1. Next, drag one of the poles to make your plot look like this: Figure 5: Interactive Root Locus to Select Gain The selected gain should be around 330. Click OK. You should now see a plot of the closed-loop compensated response: 63

Figure 6: Stairstep Response of Compensated System From the above closed-loop response, the settling time is about 0.05 seconds, which satisfies the requirement, but the percent overshoot is 22%, which is too large, due to the zeros. 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 will be 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 one pole and two zeros a little further to the right, to pull the root locus in a little bit more. The new pole will be put at 0.7, and two zeros will be at 0.85. Go back to your script, and change only numc and denc, as shown below: numc = conv([1-0.85],[1-0.85]); denc = conv([1 0.9831],[1-0.7]); Again, change the Real Axis limits to 0.2 and 1.1 in the Interactive Root Locus window. Adjust the poles to make your plot look like this: 64

Figure 7: Interactive Root Locus to Select Gain The selected gain should be around 450. Click OK. You should now see a new plot of the closed-loop compensated response: Figure 8: Stairstep Response of Compensated System Now we see that the settling time and percent overshoot meet the design requirements of the system. The settling time is 0.04 seconds and the percent overshoot is about 10%. 65

Let's take a look at a disturbance response of the closed-loop system. We need to cancel the selected gain, the integral transfer function, and the controller's transfer function from the closed-loop transfer function. So add the following code to your script: dist_cl=feedback(motor_d,k*icontr*contr); [x4,t] = step(dist_cl,.25); stairs(t,x4) xlabel('time (seconds)') ylabel('position (rad)') title('stairstep Response of Compensated System') You will have to select the gain again. After that, you should see the following root locus plot: Figure 9: Disturbance Response of Closed-Loop System 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. 66

Simulation Modeling for DC Motor Position 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: Figure 1: DC Motor Circuit and Free Body Diagram 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 University'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 electromotiveforceconstant(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 The rotor and shaft are assumed to be rigid 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: 67

In SI units (which we will use), Kt (armature constant) is equal to Ke (motor constant). Building the Model This system will be modeled by summing the torques acting on the rotor inertia and integrating the acceleration to give the velocity, and integrating velocity to get position. Also, Kirchoff's laws will be applied to the armature circuit. First, we will model the integrals of the rotational acceleration and of the rate of change of armature current. To model these integrals, begin with a blank VI. Create a Simulation Loop, from the Simulation section of the Control Design & Simulation palette. Insert three Integrator blocks (from the Linear Systems section of the Simulation palette) into your model. To create labels, double-click on empty space in your block diagram. Figure 2: Integrator Blocks Next, we will start to model both Newton's law and Kirchoff's law. These laws applied to the motor system give the following equations: 68

The angular acceleration is equal to 1/J multiplied by the sum of two terms (one positive, one negative). Similarly, the derivative of current is equal to 1/L multiplied by the sum of three terms (one positive, two negative). To model this, drag two Summation blocks (from the Signal Arithmetic section of the Simulation palette) into the Simulation Loop. Adjust the inputs on each Sum block to represent the signs of the terms in parentheses above. Drag two Gain blocks into your model (from the Signal Arithmetic section of the Simulation palette). The outputs of each of these Summation blocks will need to be multiplied by the inverses of J and L. We will be entering these values externally. Double-click on each Gain block, and change the Parameter Source from Configuration Dialog Box to Terminal. Attach each one with a wire to the outputs of the Summation blocks. Connect the outputs of the Gain blocks to the inputs of two of the Integrator blocks. Figure 3: Summation and Gain Blocks The Gain blocks should have values of 1/J and 1/L. From the Front Panel, create two Numeric Controls. Title them "J" and "L". On the Block Diagram, insert the Reciprocal block (from the Numeric section of the Programming palette). Connect J and L to separate Reciprocal blocks, and then connect the output of these Reciprocal blocks to the Gain blocks in the Simulation Loop. Figure 4: Inductance and Inertia 69

Next, we need to model the terms from the angular acceleration equation. Recall that Kt (armature constant) is equal to Ke (motor constant). For this reason, we can create a single variable to use for both of these values. Create a Numeric Control on the Front Panel, and title it "K". For the Kt term, create a Gain block and place it to the left of the lower Summation block in the Simulation Loop. Label this block "Kt". Configure it so that its source is from a terminal. Connect the i output from the upper Integrator block to the input of the Gain block that you just created. Then connect K to the gain terminal of the Gain block. To account for damping, create another Numeric Control, and name it "b". Create another Gain block, configure it so that its source is from a terminal, and then connect b to this terminal. Reverse the block (right-click on the block and select "Reverse Terminals"), and then connect theta to its input. Wire the output of the damping block to the negative terminal of the lower Summation block. We have now modeled the inertia equation. Figure 5: Angular Acceleration Equation For the armature current equation, we need to model Ke and R (resistance). Create a Gain block, and configure it so that its source is from a Terminal. Connect K to this terminal, and label the block "Ke". Tap off the d(theta)/dt wire, and connect it to the Ke input. Connect the Ke output to a negative terminal of the upper Summation block. To account for resistance, create another Numeric Control, and name it "R". Create another Gain block, configure it so that its source is from a terminal, and then connect R to this terminal. Reverse the block, and then connect i to its input. Connect the output of this block to the remaining negative terminal on the upper Summation block. 70

Figure 6: Armature Current Equation Now we need to model the source voltage, V, for the system. Insert a Step Signal block from the Signal Generation section of the Simulation palette, and connect it to the positive input of the upper Summation block. Figure 7: Step Signal 71

Double-click on the Step Signal block to configure its settings. Set the initial value to 0, the final value to 1, and the step time to 0.01. Figure 8: Step Signal Configuration Now, set the values for the Numeric Controls on the Front Panel. When you are finished, save these values by clicking the Edit menu and selecting "Make Current Values Default." Figure 9: Front Panel Controls On the Block Diagram, insert a SimTime Waveform block from the Graph Utilities section of the Simulation palette, and connect it to the theta output. 72

Figure 10: Waveform Chart (Download VI) Open-Loop Response To simulate this system, an appropriate simulation time must be set. Double-click on the terminals located on the left side of the Simulation Loop. In the Simulation Timing section at the top of the dialog box, set the initial time to 0 seconds and the final time to 0.3 seconds. 0.3 seconds is long enough to view the open-loop response. For the ODE solver, select 'Runge-Kutta 45'. Close the dialog box. 73

Figure 11: Configure Simulation Parameters Now, switch to the front panel. Right-click on the x-axis of the Waveform Graph, and de-select Auto-Scale X. Double-click on the maximum value of the x-axis (default is 10), and change it to 1. Next, right-click on the y-axis of the Waveform Graph, and de-select Auto-Scale Y. Double-click on the maximum value of the y-axis (default is 1), and change it to 10. When you run the simulation, you should see the following output: Implementing Digital Control Figure 12: Open-Loop Response (Download VI) In the Motor Position Digital Control example, a digital controller was designed with the following transfer function: 74

Starting with the VI that you used for the open-loop response, select all the blocks in your Simulation loop except for the Step Signal block, the Waveform output block, and the Waveform Chart indicator. With these blocks selected, click "Edit" and select "Create Simulation Subsystem". Next, insert two Discrete Zero-Order Hold blocks (from the Discrete Linear Systems section of the Simulation palette). Place one just after the Step Signal input, and the other just before the SimTime Waveform output. Figure 13: Zero-Order Hold Next, insert a Summation block and a Discrete Transfer Function block (from the Discrete Linear Systems section of the Simulation palette). Connect the Summation block and the Transfer Function block in series with the first Zero- Order Hold block. Figure 14: Discrete Transfer Function Double-click on the Discrete Transfer Function block and change the Transfer Function Parameter source to "Terminal". Change the Execution Mode to "Direct". 75

Figure 15: Discrete Transfer Function Configuration Create a MathScript Node outside the Simulation Loop, and paste the following code into the Node: num = 450*conv([1 -.85],[1 -.85]); den = conv([1.98],[1 -.7]); sys = tf(num,den,0.001); Create an output from the Node for the sys variable, and change its data type to "TF object". Connect this transfer function to the Transfer Function terminal of the Discrete Transfer Function block. Figure 16: Create Transfer Function 76

Now, connect the Step Signal block to the positive input of the Summation block. Tap off the output from the second Zero-Order Hold block, and connect that to the negative input of the Summation block. Closed-Loop Response Figure 17: Step Signal Connection (Download VI Subsystem) To simulate this system, an appropriate simulation time must be set. Double-click on the terminals located on the left side of the Simulation Loop. The design requirements included a settling time of less than 0.04 sec, so we simulate for 0.06 sec to view the output. In the Simulation Timing section at the top of the dialog box, set the initial time to 0 seconds, the final time to 0.06 seconds, and the ODE solver to Runge-Kutta 23. Close the dialog box. 77

Figure 18: Configure Simulation Parameters On the front panel, change the window axis values on the Waveform Graph. Change the maximum y-axis value to 1.5 and the maximum x-axis value to 0.05. Now run the VI. You should see the following output: Figure 19: Closed-Loop Response (Download VI Subsystem) 78