1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors...

12
ECE-536 DIGITAL CONTROL SYSTEMS Page 1 of 12 MATLAB Control Software Bharat Balagopal, Bharathram Balasubramanian, and Eric Stratton Green Electrical and Computer Engineering Department, North Carolina State University, Raleigh, NC 27695-7911, USA AbstractA Control Software is used for the theoretical design and analysis of various controllers in the analog and digital domains. The software suite had already been built in Matlab by Dr. Charles Phillips and Dr. H.Troy Nagle in the early 90s. This software accepts text input from the user in the Matlab command window. We have modified the programs in the software suite to create a Graphical User Interface (GUI) for the same. A GUI makes the user interaction with software easier and faster when compared to text commands. It gives the user more flexibility and at the same time helps in better visualization. The GUI application of the control software has been built and tested successfully. 1. Introduction The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle, developed a library of MATLAB scripts with the purpose of facilitating control design. Written in 1994, this library implemented a command-line interface for the development of analog and digital controllers along with many general matrix and polynomial calculations. Our team was tasked with revising the scripts for use twelve years after their initial development. After evaluating the script library, it became readily apparent to our team that few changes could be made to the execution of the scripts to improve efficiency, and the gains achievable were incredibly small. Thus, the decision was made to take the project in a different direction; if efforts to reduce the computational time were not worthwhile then we would make the interface more user-friendly. To this end, our team devised a graphical user-interface (GUI) implementation of the functions found in the publisher-provided MATLAB code. This document details the operation of the script library as it was given to us and a brief history of GUI implementations. The report shall go on to illustrate the operation of the GUI developed by our team, provide test cases to evaluate the accuracy of our developed system, and report on the results of these test cases. 2. Overview of Publisher-Developed MATLAB Scripts The MATLAB code provided to our team implemented a command-line interface. The user is asked to enter their name and then asked to choose one of the three main functions: analog control, digital control, and general matrix and polynomial calculations. 2.1 Analog and Digital Control While the user is asked to make a selection between analog and digital control in the main menu, the menu layout and functionality are nearly identical for both; the only difference is the addition of the sample time input for the digital control system. As such, the overviews of these functions are treated here simultaneously. 2.1.1 Classical Control The user is asked to input the plant model, and provided the option to input the plant model in either transfer function format, or as a state-space model. After this is complete, options exist to produce the Nyquist diagram and the Bode Plots from the open-loop representation of the plant model. The user can then select to have a guided development of several controller types: Lag-Lead Controller, PID Controller, and Root-Locus design. In these, the user is asked to supply the desired characteristics of the controlled system, such as phase margin. After designing the controller, the user is allowed to output the controller transfer function (analog or digital as appropriate), and show the closed loop parameters and time response of the controlled system. 2.1.2 Modern Control Just as in the classical control, the user is asked to input the plant model, and provided the option to input the plant model in either transfer function format, or as a state-space model. The user is then allowed to initiate a guided pole- placement controller design, inputting one of many parameters specifying the desired performance of the system. In addition to this, the user can also select the automated design of a system estimator or reduced

Transcript of 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors...

Page 1: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

ECE-536 DIGITAL CONTROL SYSTEMS Page 1 of 12

MATLAB Control Software Bharat Balagopal, Bharathram Balasubramanian, and Eric Stratton Green

Electrical and Computer Engineering Department, North Carolina State University, Raleigh, NC 27695-7911, USA

Abstract— A Control Software is used for the theoretical design and analysis of various controllers in the analog and digital domains. The software suite had already been built in Matlab by Dr. Charles Phillips and Dr. H.Troy Nagle in the early 90s. This software accepts text input from the user in the Matlab command window. We have modified the programs in the software suite to create a Graphical User Interface (GUI) for the same. A GUI makes the user interaction with software easier and faster when compared to text commands. It gives the user more flexibility and at the same time helps in better visualization. The GUI application of the control software has been built and tested successfully.

1. Introduction

The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle, developed a library of MATLAB scripts with the purpose of facilitating control design. Written in 1994, this library implemented a command-line interface for the development of analog and digital controllers along with many general matrix and polynomial calculations. Our team was tasked with revising the scripts for use twelve years after their initial development. After evaluating the script library, it became readily apparent to our team that few changes could be made to the execution of the scripts to improve efficiency, and the gains achievable were incredibly small. Thus, the decision was made to take the project in a different direction; if efforts to reduce the computational time were not worthwhile then we would make the interface more user-friendly. To this end, our team devised a graphical user-interface (GUI) implementation of the functions found in the publisher-provided MATLAB code. This document details the operation of the script library as it was given to us and a brief history of GUI implementations. The report shall go on to illustrate the operation of the GUI developed by our team, provide test cases to evaluate the accuracy of our developed system, and report on the results of these test cases. 2. Overview of Publisher-Developed MATLAB Scripts The MATLAB code provided to our team implemented a command-line interface. The user is asked to enter their name and then asked to choose one of the three main functions: analog control, digital control, and general matrix and polynomial calculations.

2.1 Analog and Digital Control While the user is asked to make a selection between analog and digital control in the main menu, the menu layout and functionality are nearly identical for both; the only difference is the addition of the sample time input for the digital control system. As such, the overviews of these functions are treated here simultaneously. 2.1.1 Classical Control The user is asked to input the plant model, and provided the option to input the plant model in either transfer function format, or as a state-space model. After this is complete, options exist to produce the Nyquist diagram and the Bode Plots from the open-loop representation of the plant model. The user can then select to have a guided development of several controller types: Lag-Lead Controller, PID Controller, and Root-Locus design. In these, the user is asked to supply the desired characteristics of the controlled system, such as phase margin. After designing the controller, the user is allowed to output the controller transfer function (analog or digital as appropriate), and show the closed loop parameters and time response of the controlled system. 2.1.2 Modern Control Just as in the classical control, the user is asked to input the plant model, and provided the option to input the plant model in either transfer function format, or as a state-space model. The user is then allowed to initiate a guided pole-placement controller design, inputting one of many parameters specifying the desired performance of the system. In addition to this, the user can also select the automated design of a system estimator or reduced

Page 2: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

Page 2 of 12 ECE-536 DIGITAL CONTROL SYSTEMS

————————————————————————————————————– order estimator, for use with systems that do not have directly-visible control states. After designing the controller and/or estimator, the user is allowed to output the control/estimator transfer function (analog or digital as appropriate), and show the closed loop parameters and time response of the controlled system. 2.2 General Matrices and Polynomial Calculations These functions serve as a sort of general-purpose “control   calculator”   providing   access   to   calculations  frequently used in the evaluation of control system problems. The partial fraction expansion function allows the user to input a rational polynomial and output the partial fractions to which it is equal. The ‘conversion   between   transfer   function   and   state   space’  converts between the polynomial and matrix expressions of system models. Similarity transformations allow for the conversion of a matrix relative to a basis to a matrix relative to a different basis; allowing different coordinate systems to be used to   model   a   single   system.     “Polynomial   Calculations”  allow for the expansion and reduction between a polynomial and its roots, and for the multiplication of two   polynomials.     Finally,   “Matrix Calculations”  evaluate the inverse, determinant, eigenvalues, and eigenvectors of a square matrix in addition to the product of two matrices. 3. GUI Interface Developmentally speaking, the most intuitive level of communication in humans (and many animals) is based from movements and gestures. Conversely, the highest level of communication, relative to complexity, is considered to be written language.

In  the  1970’s,  the  Xerox  Corporation  developed  one of the first graphical-user interfaces. Prior to this development, the predominant interface between the computer and human operator was through the keyboard. The introduction of the graphical-user interface, and the gesturing device known as a mouse, allowed for the intuitive navigation of menu and file systems through gesturing, rather than the written language interface.

Though the initial effort of the Xerox Corporation was not met with great commercial success the concept was quickly adopted by the Apple Corporation, and the release of the Macintosh computer in 1984 marked the beginning of the personal computer. Today, the majority of operating systems use the GUI as the primary interface, and nearly 50% of the computer

code written for software applications is devoted to the graphical user-interface.

4. Walkthrough of GUI functionality

This section is intended to serve as a tutorial to give the user a brief idea as to how the GUI could be used effectively. Screenshots of various menu screens would be used to illustrate the functioning of the software. To use the GUI the user must have the model of the plant ready; the software package does not feature system identification capabilities. The main menu of the Control Application gives three options to the user, namely: analog feedback control design and analysis, digital feedback control design and analysis, and general matrices and polynomial calculations. The user needs to click the appropriate button in order to proceed to the next screen. Fig 3.1 shows a screenshot of the main menu

Fig 3.1. Screen shot of Main Menu For the purpose of this illustration, let us assume the user wants to design/analyze analog feedback control. The following menu screen gives the option of using classical or modern methods. If the user chooses classical control systems, the following screen gives a variety of options which is depicted in the fig 3.2.

Page 3: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

ECE-536 DIGITAL CONTROL SYSTEMS Page 3 of 12

————————————————————————————————————–

Fig. 3.2. Menu showing options for design and analysis of Analog Feedback Controller using Classical Control Systems. The control software requires the user to input the plant model in order to proceed with the controller design. The plant model could be entered in either state space or transfer function model. Fig 3.3 shows the screen where the user is provided with options for the same.

Fig. 3.3. Menu screen providing the user the option to input either the State Space or Transfer Function Model of the plant. If the user chooses to enter the State Space Model, then the following screen appears with the option of entering the State Space Matrices which when selected displays the tables with number of rows and columns according to the order of the system (which the user must have entered earlier when prompted). The user simply   needs   to   fill   the   tables   and   click   on   “Generate  Transfer   Function”   to   generate   the   transfer   function.  Similarly, if the user has the transfer function of the plant, then the coefficients of the numerator and denominator of the transfer function must be entered when prompted. Fig 3.4 illustrates the example of getting the transfer function from the user.

Fig 3.4. Example screenshot for obtaining Transfer Function Coefficients from the user. It must be noted that the coefficients must be entered in descending order of the power. Once the model   is   entered   and   when   the   user   selects   “Display  State   Space  Matrices”   option, a new window pops up which has the corresponding State Space Matrices. Fig 3.5 illustrates the same.

Fig. 3.5. Pop-up window that generates the State Space Matrices for the transfer function entered by the user. Once the plant model is entered, the user can go back to the control menu and select the desired control model. For illustration purposes let us assume the user wants to design a PID controller. Fig 3.6 is a screenshot of the analog PID controller design menu screen.

Page 4: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

Page 4 of 12 ECE-536 DIGITAL CONTROL SYSTEMS

————————————————————————————————————–

Fig. 3.6. Analog PID Controller Design window The user now needs to enter various parameters such as forward path gain, sensor gain, and desired characteristics such as phase margin, phase margin frequency and select the desired controller. If the user wants a PID controller, the software prompts the user to enter the gain for Integral control as the Integral gain and derivative gain values in PID controller are codependent. This is illustrated in Fig 3.7

Fig. 3.7. Design parameters input by the user The controller transfer function along with the PID gain values are displayed in a pop up window (Fig 3.8)

Fig. 3.8. Pop-up window that generates the controller transfer function and PID Gains These values are stored in memory until the reset button is clicked. Hence the effectiveness of these controller models could be analyzed using the Bode/Nyquist/root locus plots. Fig 3.9 and 3.10 are example screenshots of the frequency response from Bode plot.

Fig. 3.9. Bode Plot for the plant with/without the controller

Page 5: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

ECE-536 DIGITAL CONTROL SYSTEMS Page 5 of 12

————————————————————————————————————–

Fig. 3.10. Pop-up window displaying system frequency response from the Bode plot Similarly the user can design and analyze digital feedback controllers. It must be noted here that the software does not suggest the best control model for a given application. The user needs to decide the desired parameters and choose the right controller. 4. Flowchart of Menu Screens Fig. 4.1, 4.2 and 4.3 depict the hierarchy of Menu screens in the Control Software. They give an idea about the various levels in the software.

Fig. 4.1. The three modules present in Control Software

Fig. 4.2. Menu Screens present in Analog Feedback Control Analysis and Design

Page 6: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

Page 6 of 12 ECE-536 DIGITAL CONTROL SYSTEMS

————————————————————————————————————–

Fig. 4.3. Menu Screens present in Digital Feedback Control Analysis and Design

Fig. 4.3. Menu Screens present in General Matrices and Polynomial Calculations.

Page 7: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

ECE-536 DIGITAL CONTROL SYSTEMS Page 7 of 12

————————————————————————————————————– 5. Presentation of Design Test Cases 5.1 Analog feedback control design and analysis 5.1.1 Bode plot The screenshot in fig. 5.1 is the menu screen for Bode plot with the parameters entered. The plantmodel for verifying the Bode plot is:

G(s) =

In this test case we find the open loop response without the controller.

Fig. 5.1. Testing the bode plot function in the software This is verified to be accurate from example 2 in reference [1] 5.1.2 Nyquist Plot The screenshot in fig. 5.2 is the menu screen for Nyquist plot with the parameters entered. The plantmodel for verifying the Nyquist plot is:

G(s) = ]

In this test case we find the open loop response without the controller.

Fig. 5.2. frequency response using Nyquist plot This is verified to be accurate from reference [2] Fig. 5.3 is the snapshot of the nyquist plot from the reference.

Fig 5.3. Nyquist plot from reference [2] 5.1.3 Phase Lead controller design

In order to test the correctness of the Phase lead controller design (analog controller design) we entered the parameters as shown in fig 5.4.

Page 8: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

Page 8 of 12 ECE-536 DIGITAL CONTROL SYSTEMS

————————————————————————————————————–

Fig. 5.4. Analog controller design- Desired parameters

The software then generated the analog controller model with the transfer fucntion as shown in fig. 5.5. This is verified to be accurate from reference [3]. The snapshot from the refernce proving this is shown in fig. 5.6.

Fig. 5.5. Controller transfer function generated by the software

Fig. 5.6. Snapshot from reference showing the Transfer function of the designed phase lead controller [3] 5.2 Digital feedback control design and analysis For the purpose of testing and validating our control software for digital controllers, we have referred to examples   from   the   textbook,   “Digital  Control   Systems  Analysis   and  Design”   by   Dr.  Charles   Phillips   and  Dr.  H.Troy Nagle. 5.2.1 Lag Controller Design The lag controller design was done for the following system:

When converted to discrete domain with sampling time of 0.05 s,

Fig. 5.7 shows the menu screen for the lag controller design. The desired parameters entered are as mentioned in Sec 8.4, p294, Example 8.1in the text.

Page 9: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

ECE-536 DIGITAL CONTROL SYSTEMS Page 9 of 12

————————————————————————————————————–

Fig. 5.7 Menu screen for Phase-Lag controller design The designed controller generated by the softwatre matched with the solution in the textbook.

Fig 5.8 Screenshot of the phaselag controller transfer function generated in the software 5.2.2 Pole Placement The state space matrices of the plant are as follows:

Fig. 5.8 Screensot from the software where the state space matrices are entered The desired characteristic equation as mentioned in Sec 9.3, p335, Example 9.2 1in the textbook is as follows:

Fig. 5.9 Entering co-efficients of desired characteristic equations.

Fig. 5.10 gain matrix generated by the software

Page 10: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

Page 10 of 12 ECE-536 DIGITAL CONTROL SYSTEMS

————————————————————————————————————– The desired gain matrix result is:

5.2.3 Estimator Design The plant used for testing the estimator design is same as that used for pole placement. The desired characteristic equationas mentioned in Sec 9.3, p350, Example 9.3 in the reference textbook is:

Fig. 5.11 Entering co-efficients of desired characteristic equations.

Fig. 5.12 G and F matrix generated by the software The desired G matrix from the textbook example:

5.2.4 Current Estimator Design The plant used for testing the estimator design is same as that used for pole placement. The desired characteristic equationas mentioned in Sec 9.3, p350, Example 9.3 is as following:

Fig. 5.13 Entering co-efficients of desired characteristic equations.

Fig. 5.14 gain matrix generated by the software The desired estimator GCA matrix result is:

5.3 General Matrices and Polynomial Calculations 5.3.1 Partial Fraction expansion 5.3.1.1 Calculate partial fraction coefficients:

Entering the given X(z) = generated the

following values: Residues=6,-2 ; Poles=2,1 ; Direct term =1 . (The result is proved to be correct from the following task.)

Page 11: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

ECE-536 DIGITAL CONTROL SYSTEMS Page 11 of 12

————————————————————————————————————– 5.3.1.2 Recombine partial fractions:

The above residue, poles and gain values were entered and the numerator and denominator coefficients of the given X(z) were obtained.

5.3.1.3 Calculate the rational function: The following values were entered: Poles: 1,2 Zeros: 0,-1 Gain: 1 This generated the given X(z).

5.3.2 Transfer Function to and from State Space 5.3.2.1 State Space to Transfer Function:

Given State Space Matrices: A =[1 2 -­‐1; 0.5 1 1; 0 -­‐1 2]; B = [1 ; 0.5; -­‐2]; C = [-­‐1 1 -­‐2]; D=0. Transfer Function (from Quiz 1 solutions):

Solution from the Control Software: Numerator Coefficients:

z^3 z^2 z^1 z^0 0 3.5 -10 7.5

Denominator Coefficients: z^3 z^2 z^1 z^0 1 -4 5 -1.5

5.3.2.2 Transfer Function to State Space: Entering the above Transfer Function in the software yielded the following State Space matrices: A=[4 -5 1.5; 1 0 0; 0 1 0]; B=[1 0 0]; C=[3.5 -10 7.5]; D=0 In order to check whether the above solution is correct, these State Space matrices are converted to Transfer Function, which gave the following: Numerator Coefficients:

z^3 z^2 z^1 z^0 0 3.5 -10 7.5

Denominator Coefficients: z^3 z^2 z^1 z^0 1 -4 5 -1.5

Hence this proves that the Transfer function to and from State Space module is accurate.

5.3.3 Similarity Transformation

Matrices that were entered in the Control Software:

P = [3 8 4; 0 7 5; 9 6 2] A=[0 1 0; 0 0 1; -0.12 -0.5 -1.1] B=[0 0 1]' C=[5.8, 10.5, 5] D=0 Transformed  Matrices   (from  ECE  536  Fall   ’12  Lecture 4) is same as the solution from the Control Software: Ap = -0.8520 -3.2787 -2.1027 -1.9350 5.0150 4.0450 4.5090 -5.8210 -5.2630 Bp = 0.2000 -0.2500 0.3500 Cp = 62.4000 149.9000 85.7000 Dp =0

5.3.4 Polynomial Calculations 5.3.4.1 Polynomial from its roots:

The roots entered into the software: r1=4, r2=-2, r3=3 Polynomial obtained my manual calculation is the same as that from the software, which is :

5.3.4.2 Roots of a polynomial:

The coefficients of the polynomial, same as in previous case, were entered into the software and the roots obtained were r1=4, r2=-2, r3=3.

5.3.4.3 Multiplication of two polynomials:

Entered polynomials are p1= and

p2= . The product of the polynomials given by the software (same as manual calculation) =

Page 12: 1. Introduction 2.1 Analog and Digital Control 2.1.1 ...bbalago/REPORT_TEAM_CTRL.pdf · The authors of Digital Control System Analysis and Design, Charles Phillips and Troy Nagle,

Page 12 of 12 ECE-536 DIGITAL CONTROL SYSTEMS

————————————————————————————————————–

5.3.5 Matrix Calculations 5.3.5.1 Inverse of a square matrix:

Input matrix = P = [1 -1; 1 1] . P-1 (from software)= [0.5 0.5; -0.5 0.5] . This is verified to be accurate by manual calculations

5.3.5.2 Determinant of a square matrix: Input matrix = P = [3 4 3; 8 1 3;2 3 7]. Determinant = -140. This is verified to be accurate by manual calculations.

5.3.5.3 Eigenvalues and Eigenvectors : Input matrix = P = [-0.8520 -3.2787 -2.1027; -1.9350 5.0150 4.0450; 4.5090 -5.8210 -5.2630]. Eigenvalues from software: [-0.5994 ; -0.2503 + 0.3706i; -0.2503 - 0.3706i ] . Eigenvalues from class 4 lecture notes: [-0.6000 ; -0.25+ 0.3708i; -0.2500- 0.3708i ]

5.3.5.5 Multiplication of two matrices : Input Matrices: A = [-5 -75 80] ; B =[0.16 0.4 1; 0.64 0.8 1; 0.81 0.9 1] Result from software: Matrix A*Matrix B = [16 10 0] (Verified to be accurate from class 5 lecture notes.)

6. Conclusions After creating the GUI for the control software application we compared our work with the original version in the command window. We realized that it is a lot easier, faster and flexible with the GUI. For example, if we enter a wrong value, in the command window, for any one of the entities of the state space matrices then we will have to abort and re-enter all the matrices all over again, whereas mistakes made while entering numbers in the tables in the GUI could be easily corrected. It also gives the user a better visualization and saves a lot of confusion. We had the opportunity to make some of the programs in the suite more efficient by substituting large codes with inbuilt Matlab® functions that have been created over the years. 7. Acknowledgements We would like to acknowledge Dr. Phillips and Dr. Nagle   for   their   authorship  of   “Digital  Control  Systems  Analysis  and  Design” and the MATLAB code provided within, as our project was directly motivated by their

work. References

[1] Handout e.17 - Examples on bode plots of first and second order systems by Parasuram .

[2] Dr. Matthew M Peet, Illinois Institute of technology, “Systems Analysis and Control” Lecture notes (Lecture 23 – Drawing the Nyquist Plot)

[3] Heikki Koivo, “Design of Phase Lead Compensator” [4] Dr. Charles Phillips and Dr. H.Troy Nagle, “Digital  Control  Systems  Analysis  and  Design” [5] Dr. H.Troy Nagle, “ECE 536- Digital Control Systems” Lecture notes.