Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 150

APPLICATION OF MODEL PREDICTIVE CONTROL TO A COUPLED TANK SYSTEM SHUBHAM SRIVASTAVA A DISSERTATION SUBMITTED IN PARTIAL FULFILMENT OF THE REQUIREMENTS

FOR THE DEGREE OF MASTER OF SCIENCE IN COMPUTER CONTROL AND AUTOMATION http://www1.spms.ntu.edu.sg/~tcs/ntu_logo.jpg 2010

ACKNOWLEDGEMENT: I extend my deepest gratitude and sincere thanks to my project supervisor Associ ate Professor Ling Keck Voon for his invaluable support, guidance and motivation tha t led to the successful completion of the project. His continuous encouragement and suggestio ns helped me find a way out of the intricate technical complexities that I came across while working on this project. It was indeed a great opportunity and a great learning experience to wo rk under him. I would like to thank all the staff and lab assistants in the Aerospace Electron ics lab for their consistent support. Finally, I would like to thank all my colleagues and friends who helped me dire ctly or indirectly for the successful completion of this project.

SUMMARY: Model Predictive Control (MPC) is an advanced control methodology that offers an efficient control strategy while dealing with multivariable systems with constra ints. In this dissertation, Coupled Tank System from Kentridge Instruments Pte Ltd has been us ed to implement Model Predictive Control for controlling the level of water in the two tanks. The First Principles method relating to the Mass Balance Equation for volume of water present inside the two tanks has been used to identify the system parameters and consequently develop an appropriate state space model for the Coupled Tank System. Model Vali dation is carried out by comparing the simulated output obtained from the developed model with the actual step test plant output. MPC control law is defined for solving the constrained optimization criterion an d subsequently the controller is implemented by communicating with the system thro ugh NI DAQmx 6024E while the control algorithm runs in MATLAB. The experimental results obtained demonstrate an effective set point tracking abilities and disturbance h andling capabilities of the controller. Finally, tuning of MPC parameters is carried out in order to choose the paramet er values best suited for this application. Constraint handling capability is one of the m ost striking features of MPC methodology that makes it unique in comparison to other conventional cont rol techniques. Experiments are carried out to specifically demonstrate the constrai nt handling capabilities of the controller.

TABLE OF CONTENTS ACKNOWLEDGEMENT ................................................................ ............................................................................ I SUMMARY ........................................................................ .........................................................................II LIST OF FIGURES ................................................................ ................................................................. ...V LIST OF TABLES ................................................................. ................................................................... VII CHAPTER 1 INTRODUCTION ... .. ..1 1.1 MOTIVATION 1.2 OBJECTIVE OF THE THESIS 1.3 THESIS ORGANIZATION .. ... ... . 1 ... ... ...2 . 3

CHAPTER 2 PARAMETER DETERMINATION AND CALIBRATION OF THE COUPLED TANK SYSTEM ... .. .. 4 2.1 OVERVIEW OF THE KENTRIDGE COUPLED TANK SYSTEM. . .. .4 2.1.1 MODES OF OPERATION OF COUPLED TANK SYSYTEM .. 6 2.2 PARAMETER DETERMINATION . .. . ... 6 2.2.1 FIRST PRINCIPLE METHOD OF PARAMETER DETERMINATION .. . 7 2.2.1.1 MASS BALANCE EQUATION .. .. .. ... 8 2.2.1.2 LINEARIZATION ... ... .9 2.2.1.3 DETERMINATION OF PARAMETERS a1, a2 AND a3 .............................. ................12 2.3 STATE SPACE MODEL BASED ON DETERMINED PARAMETERS .. .. .21 2.4 MODEL VALIADTION .. .. 24 2.5 SENSOR AND ACTUATOR CALIBRATIONS . .. ....26 2.5.1 SENSOR CALIBRATIONS ... ... 26 2.5.2 MOTOR CALIBRATIONS .. .....33 CHAPTER 3 MPC IMPLEMENTATION ON COUPLED TANK SYSTEM .. 37 3.1 INTRODUCTION TO MODEL PREDICTIVE CONTROL... ... 37 3.1.1 RECEDING HORIZON CONCEPT .. ...39 3.1.2 SET POINT IMPROVEMENT .. ...39 3.2 THE STATE SPACE MODEL ... . .....40 3.2.1 CHOICE OF APPROPRIATE AUGMENTED STATE SPACE MODEL .. ... .43 3.2.2 MAKING UNBIASED PREDICTIONS .. .44 3.3 SOLVING THE QP PROBLEM .. . 46

3.4 IMPLEMENTATION OF MPC ON THE COUPLED TANK SYSTEM. ... ...47 3.4.1 OPERATING REGION FOR CONTROL ACTION. ... ..48 3.4.2 USE OF MANUAL CONTROL .....49 3.4.3 EXPERIMENTAL SETUP ... ..50 3.4.4 EXPERIMENTAL RESULTS ....52 3.5 DISTURBANCE HANDLING CAPABILITIES OF THE CONTROLLER .56 CHAPTER 4 TUNING OF MPC PARAMETERS AND MPC CONSTRAINT HANDLING CAPABILITIES .. .57 4.1 TUNING OF MPC PARAMETERS .57 4.1.1 TUNING OF PREDICTION HORIZON ... .....57 4.1.2 TUNING OF CONTROL HORIZON ... .. 58 4.1.3 TUNING OF CONTROL WEIGHTING FACTOR 60 4.2 CONSTRAINT HANDLING CAPABILITIES OF THE CONTROLLER ... .. 61 4.2.1 SLEW RATE CONSTRAINTS ... ....61 4.2.2 INPUT CONSTRAINTS ... ..64 4.2.3 OUTPUT CONSTRAINTS ... .. 67 CHAPTER 5 CONCLUSION AND RECOMMENDATIONS FOR PERFORMANCE IMPROVEMENT . ... 69 5.1 CONCLUSION ... .. .69 5.2 RECOMMENDATIONS FOR FURTHER IMPROVEMENTS . ... .70 BIBLIOGRAPHY . .. 72 APPENDICES . ... ..74 APPENDIX A (DATA VALUES OBTAINED FOR SIMULTANEOUS DETERMINATION OF DISCHARGE COEFFICIENTS) ... 74 APPENDIX B (DERIVATION OF MPC CONTROL LAW) ... .76 APPENDIX C (PROGRAM LISTING) .. .... 84

LIST OF FIGURES FIGURE 2.1 KENTRIDGE COUPLED TANK SYSTEM FIGURE 2.2 DYNAMICS OF COUPLED TANK SYSTEM FIGURE 2.3 MODEL VALIDATION RESULTS FIGURE 2.4 LEVEL SENSOR INPUT-OUTPUT ENTITIES FIGURE 2.5 SENSOR 1 CONVERSIONS REGION 1 FIGURE 2.6 SENSOR 1 CONVERSIONS REGION 2 FIGURE 2.7 SENSOR 1 CONVERSIONS REGION 3 FIGURE 2.8 SENSOR 2 CONVERSIONS REGION 1 FIGURE 2.9 SENSOR 2 CONVERSIONS REGION 2 FIGURE 2.10 SENSOR 2 CONVERSIONS REGION 3 FIGURE 2.11 SENSOR 1 CONVERSIONS FOR ALL 3 REGIONS FIGURE 2.12 SENSOR 2 CONVERSIONS FOR ALL 3 REGIONS FIGURE 2.13 MOTOR PUMP INPUT-OUTPUT ENTITIES FIGURE 2.14 MOTOR PUMP 1 CONVERSIONS FIGURE 2.15 MOTOR PUMP 2 CONVERSIONS FIGURE 3.1 STRUCTURE OF MODEL PREDICTIVE CONTROL (FLOWCHART) FIGURE 3.2 RECEDING HORIZON CONCEPT FIGURE 3.3 SET POINT IMPROVEMENT FIGURE 3.4 COMPARISON OF 3 AUGMENTED ATATE SPACE MODELS FIGURE 3.5 USE OF MANUAL CONTROL FIGURE 3.6 MPC IMPLEMENTATION: BLOCK DIAGRAM FIGURE 3.7 EXPERIMENTAL RESULTS FOR MPC IMPLEMENTATION FIGURE 3.8 EXPERIMENTAL RESULTS FOR MPC IMPLEMENTATION FIGURE 3.9 MPC IMPLEMENTATION FOR H1=12cm, H2=13.5cm FIGURE 3.10 MPC IMPLEMENTATION FOR H1=17cm, H2=15cm FIGURE 3.11 MPC IMPLEMENTATION FOR H1=20cm, H2=17cm FIGURE 3.12 DISTURBANCE HANDLING CAPABILITIES OF THE CONTROLLER FIGURE 4.1 EFFECT OF VARIATION OF PREDICTION HORIZON FIGURE 4.2 EFFECT OF VARIATION OF CONTROL HORIZON

FIGURE 4.3 EFFECT OF VARIATION OF CONTROL WEIGHTING FACTOR FIGURE 4.4 CONSTRAINT HANDLING CAPABILITIES SLEW RATE CONSTRAINTS FIGURE 4.4-a SLEW RATE CONSTRAINTS - 1 cm3/sec = .r = 1 cm3/sec FIGURE 4.4-b SLEW RATE CONSTRAINTS - 5 cm3/sec = .r = 5 cm3/sec FIGURE 4.4-c SLEW RATE CONSTRAINTS - 15 cm3/sec = .r = 15 cm3/sec FIGURE 4.4-d SLEW RATE CONSTRAINTS - 20 cm3/sec = .r = 20 cm3/sec FIGURE 4.5 CONSTRAINT HANDLING CAPABILITIES INPUT CONSTRAINTS FIGURE 4.5-a INPUT CONSTRAINTS (0 cm3/sec = r1 = 35.13 cm3/sec; 0 cm3/sec = r2 = 34.11 cm3/sec) FIGURE 4.5-b INPUT CONSTRAINTS (0 cm3/sec = r = 30.94 cm3/sec; 0 cm3/sec = r2 = 30.94 cm3/sec) FIGURE 4.5-c INPUT CONSTRAINTS (0 cm3/sec = r1 = 28.55 cm3/sec; 0 cm3/sec = r2 = 28.47 cm3/sec) FIGURE4.6 CONSTRAINT HANDLING CAPABILITIES OUTPUT CONSTRAINTS FIGURE 4.6-a OUTPUT CONSTRAINTS (0 cm = y1 = 18.23 cm; 0 cm = y2 = 20.85cm) FIGURE 4.6-b OUTPUT CONSTRAINTS (0 cm = y1 = 16.28 cm; 0 cm = y2 = 19.29cm) FIGURE 4.6-b OUTPUT CONSTRAINTS (0 cm = y1 = 15.00 cm; 0 cm = y2 = 18.25cm)

LIST OF TABLES TABLE 2.1 READINGS FOR DISCHARGE COEFFICIENT a1 TABLE 2.2 READINGS FOR DISCHARGE COEFFICIENT a2 TABLE 2.3 READINGS FOR DISCHARGE COEFFICIENT a3 TABLE 2.4 READINGS FOR SIMULATNEOUS DETERMINATION OF a1, a2, a3 TABLE 2.5 COMPARISON OF METHOD 1 AND 2 OF PARAMETER DETERMINATION TABLE 2.6 DIVISION OF REGIONS ON LEVEL SENSORS TABLE 2.7 LEVEL SENSOR 1 CALIBRATIONS TABLE 2.8 LEVEL SENSOR 2 CALIBRATIONS TABLE 2.9 MOTOR 1 CALIBRATIONS TABLE 2.10 MOTOR 2 CALIBRATIONS TABLE 3.1 AUGMENTED STATE SPACE MODELS

Chapter 1- Introduction Looking Ahead: . Motivation . Objective . Organization of the thesis

1.1 Motivation The Kentridge Two Tank system is one of the most commonly available systems representing a coupled Multiple Input Multiple Output (MIMO) system. With 2 inpu ts and 2 outputs, it is the most primitive form of a coupled multivariable system. Level control in a coupled multivariable tank system is challenging due to the following issues1. Multivariable nature causes interaction between the two subsidiary tanks. Hen ce water flows in either of the two directions, depending upon the present water level in the two tanks. 2. System constraints. The capabilities of the dc motors used to pump water, is limited (input

constraints). . The water level in the two tanks have to be maintained at the desired set point within a specified tolerance limit (output constraints)

Normally, control mechanism of such a system would involve a decentralized cont rol action where the system sections are decoupled and separate controllers are desi gned for the decoupled sections. But, the constraints have also to be accounted for. Model Pr edictive Controls forms a suitable alternative because it can handle both the above mentioned issu es effectively provided a sufficiently high computational speed is available. MPC approaches th ese issues in the form of an optimization problem, where an optimal value of control input to be given to the

system is worked out by solving a standard Quadratic Programming (QP) problem [1 , 2, 3, 7] comprising of(a) A cost function which comprises of a linear combination of square of the err or between present output and the set point, and the change in control input. (b) The system constraints. Moreover, the cost function also enjoys the luxury of being formulated so as to suit the particular case, pertaining to the choice of prediction horizon and a weighting factor depicting and deciding the relative importance of the entities in the cost function. Apart from the above mentioned issues, MPC tackles with the disturbances in an effective way to bring back the output to the desired set point. The above mentioned advantages of MPC make it suitable to be used for level cont rol in the Two Tank System which is basically a two input two output (TITO) system and has constraints in the form of maximum voltage rating of the dc motors and user defi ned water level constraints. 1.2 Objective The main objective of this project is to design and implement an MPC controller for level control in the Kentridge Coupled Tank system. The following sub-objectives taken together form the main objective1. Developing a state space system model for the coupled tank system. 2. Design an MPC controller in MATLAB for the developed system model. 3. Experimentally verify the MPC control action on the system by communicating w ith the system through NI DAQmx 6024E. 4. Study and demonstrate the effect of variation of MPC parameters: thereby choo sing appropriate values of MPC parameters. Demonstrate the disturbance handling and constraint handling capabilities of the controller.

1.3 Thesis Organization The thesis has been organized into five chaptersChapter 1 gives the motivation behind using MPC for the given system, main objec tives of the thesis and the thesis organization itself. Chapter 2 gives an Overview of the Kentridge Coupled Tank system upon which the MPC control phenomenon is to be demonstrated. Further, this chapter deals with Param eter determination for the system, model validation, sensor and motor calibrations. T he use of First Principles for determining the state space equations for the system are describe d. Experimental results pertaining to parameter determination, sensor and motor calibration are given. Chapter 3 gives an introduction of Model Predictive Control methodology. This ch apter consists of the experimental results for implementation of MPC for level control in the C oupled Tank System. Experimental results pertaining to three possible augmented state space models and the suitable choice of a particular model, as supported by the experimental results have been mentioned. Further, this chapter shows the controller action in case of simulate d input disturbance. Chapter 4 shows the effect of variation of the three parameters viz., Prediction horizon, Control Horizon and Control input weighting factor ., and gives the proper choice of MPC parameters for the present application. Further, experimental results to demonstrate the co nstraint handling capabilities have been given. Chapter 5 discusses the conclusion reached after the implementation and gives recommendations for further improvement.

C:\Documents and Settings\Administrator\My Documents\My Pictures\tanksys.JPG Chapter 2 Parameter Determination and Calibration of the Coupled Tank System Looking ahead: . Overview of the Kentridge Coupled Tank System . Parameter Determination for the Coupled Tank System . State space model based on determined parameters . Model validation . Sensor calibrations . Actuator (motor pump) calibrations

2.1 Overview of the Kentridge Coupled Tank System Figure 2.1: Coupled tank System (Source-Specification Manual of Coupled Tank Con trol Apparatus PP100 from Kentridge Instruments Pte Ltd)

The Kentridge coupled tank system as shown in figure (2.1) consists of a tower shaped tank mounted over a reservoir that is used to store excess of water [5]. A baffl e plate inside the tank divides the tank into two vertical equal sections. The vertical position of baffle plate can be adjusted by means of a screw provided at the top, and thus the interaction or co upling between the two tank sections (Tank 1 and Tank 2) can be controlled. An inlet is provide d at the top of each tank section to let in a stream of water when driven by means two dc motors , respectively for Tank 1 and Tank 2. Each of the two tanks is fitted with an outlet at the bot tom and the outlet is connected to the reservoir through a small hose. The hose carries manual clam ps that function as valves thereby controlling the rate of flow outward from the two tanks. Overflow drain pipes are also connected near the top of the two tanks, the overf low drains connect back to the reservoir. The coupled tank system has two actuators and two feedback sensors. Actuators -pump motors (0 to 5 volt dc) . Capacitive sensors (output-0 to 5volt dc) The pump motors can be controlled either directly by a PWM signal or an analog voltage (0-5volt). Electronic circuitry provided at the back of tank apparatus converts the analog voltage to a suitable PWM signal before feeding it to the pump motors. Capacitive probes hanging in the centre of the two tanks are used as level sensors, output of these after being p rocessed by signal conditioning circuit, is made available as 0-5 volt dc. A scale is also attached on the front side of the tank so that the water level can also be visually monitored. With the inlet valves (driven by the two motor pumps) being the two inputs to ta nk 1 and tank 2, respectively and the level of water in the two tanks being the desired o utput that is to be controlled, the coupled tank system is thus a two input- two output (TITO) syste m.

2.1.1 Modes of Operation of Coupled Tank System The coupled tank system can be used in either of the two modes. Local mode . Remote mode In Local mode, the inlet to the two tanks can be controlled by the two respectiv e potentiometers provided at the back panel. In REMOTE mode, PWM or analog signal (0-5 volt) is a pplied to the pump motors to drive water into the two tanks through the inlets. The apparatus is used in REMOTE mode and analog voltage, for carrying out all the experiments in this the sis. 2.2 Parameter Determination Various methods are available in literature for determining a System Model [1],[ 6]. Derivation of MPC control law is based on the state space model of the system an d hence, an adequate state space model of the coupled tank system needs to be identified. Th e linearized state space model for the coupled tank system can be determined in either of the two w ays. Performing tests on the plant by applying known input patterns (step test, relay test,etc) and observing the plant outputs. . The First Principle Method [1], wherein the plant dynamics can be represented by a non linear equation based upon the underlying physical and/or chemical phenomeno n. The method of First Principles is used for working out the system model. Later in Section (2.4), model validation is carried out by comparing the simulated output generat ed from the determined model by applying step input, against the actual plant output obtaine d by applying step input to the plant.

2.2.1 First Principle method for parameter determination

The First Principle method for working out the State Space Model is based on th e Mass Balance equation [5] for the volume of water present inside the two tanks. At an y given instant the rate of change of volume of water present inside the tank can be expressed i n terms of the rate at which water flows into the tank through the inlet and the rate at which water flows out of the tank through the outlet valves. The Coupled Tank System dynamics can be visu alized as shown in the Figure (2.2). Figure 2.2 Dynamics of Coupled tank System Where, a1 = discharge coefficient from tank 1. a 2 =discharge coefficient from tank 2. a 3 =discharge coefficient between the two tanks, i.e., coupling coefficient bet ween the two tanks. (a 3 will be positive for H1>H2 and negative for H1<H2). Qi1 = rate of flow of fluid into tank1 ( manifested in the form of control input U1)

Qi2 = rate of flow of fluid into tank2 ( manifested in the form of control input U2) Qo1 = rate of flow of fluid from tank 1 Qo2 = rate of flow of fluid from tank 2 Qo3 = rate of flow of fluid from tank 1 to tank 2 or from tank 2 to tank1 depend ing upon whether H1>H2 or H1<H2, respectively. H1 = operating point in tank 1 (chosen to be equal to the desired set point). H2 = operating point in tank 2 (chosen to be equal to the desired set point). A1= area of cross section of tank1 A2= area of cross section of tank2 2.2.1.1 The Mass Balance Equation At any given time, the height of water in either of the two tanks is related to the water inlet rate, water outlet rate and the tank interactions. (2.1) (2.2) Here, (2.3) (2.4) (2.5) Substituting equations (2.3), (2.4) and (2.5) in equations (2.1) and (2.2), we g et-

(2.6) (2.7) The equations (2.6) and (2.7) represent a non-linear relationship between the wa ter level (H1 and H2 in the two tanks, respectively) and the discharge coefficients. Altho ugh, various methods are available in literature for non linear MPC [20], but if the operatin g point is known and does not change quite often then it is convenient to linearize the system ob tained by first principles around the desired operating point. This makes the process significan tly simpler and the model works well in a region around the chosen operating point. The stretch of operating band in which the linearized system gives a response similar to the actual non l inear system determines the sensitivity of the linearized system. 2.2.1.2 Linearization Considering an incremental change of qi1 and qi2 in the two control inputs respe ctively, which subsequently cause an incremental change in height in the two tanks - h1 a nd h2, respectively. Hence, equations (2.6) and (2.7) can be re-written as . ................ (2.8) ...................... (2.9)

Now, subtracting equation (2.6) from (2.8) and (2.7) from (2.9) we have(2.10) Similarly, (2.11) Knowing that as per Binomial expansion(2.12) For , we can approximate this as (2.13) Now, putting the approximations given by equation (2.13) in equations (2.10) and (2.11) and rearranging we get(2.14) (2.15) Where, qi1=q1 and qi2=q2 Putting the above two equations together we have-

= + . (2.16) . (2.17) Where, q1=input to tank1 (rate at which water is pumped into tank 1 cm3/sec) q2=input to tank2 (rate at which water is pumped into tank 2 cm3/sec) y1= output for tank1 (incremental change in height h1 of water from the operatin g point height H1, in tank 1 -cm) y2= output for tank2 (incremental change in height h2 of water from the operatin g point height H2, in tank 2 -cm) Now, assuming q1 = u1, q2 = u2 h1=x1, h2=x2 (2.18) The continuous time state space equations of this two input- two output (TITO) s ystem can be represented as= + . (2.19)

. (2.20) 2.2.1.3 Determination of the parameters a1, a2 and a3As obvious from the continuous time state space equations of the model given by (2.19) and (2.20), the following parameters need to be determined for working out the s tate space matrices(i) Area of cross section of the two tanks, A1 and A2, respectively, which are measured =32cm2. (ii) Operating points H1 and H2. These are user defined values and depend upon what the set point is. These are defined each time the algorithm starts. (iii) Discharge coefficients Hence, basically the 3 discharge coefficients need to be determined. Correctness of the identified model is very crucial to MPC performance as the co mputations for output predictions involve the use of model at each sampling instant. Therefore, proper model identification needs to be done, which implies that the parameters should be determined carefully. The following two methods have been adopted to carry out for determination of th e discharge coefficients(i) Method 1 - Conventional method of determining each of the 3 discharge coeffi cients separately [5], by making some mechanical adjustments in the coupled tank system. (ii) Method 2 - Simultaneous determination of the 3 discharge coefficients Linear least squares method of approximation is used to determine the parameter s [3].

Method 1: can be determined by making the following arrangements in the tank system. Inlet to tank =0, i.e., Qi1 = Qi2 =0 for determining , respectively. . Qo3 =0. i.e., the baffle between the two tanks is fully closed so that no water leaks to or from either sides, in other words the interaction/coupling between the two tanks is stopped. Once, the above two arrangements are made, the mass balance equation (3.6) and ( 3.7) for tank 1 (and similar for tank 2) come out to be as follows (2.21) (2.22) Rearranging these and integrating from H1 (0) to H1 (T) and H2 (0) and H2 (T) fo r tank 1 and tank 2, respectively we get(2.23) (2.24) Solving we get(2.25) (2.26) Procedure: The mechanical adjustments as specified above are made. For determini ng the discharge coefficient, a number of readings are taken for H1 (0) and H1 (T) with the corresponding time T. Similarly, for determining the discharge coefficient, a nu mber of

readings are taken for H2 (0) and H2 (T) with the corresponding time T. and are determined as per equations (2.25) and (2.26). S.No. Initial Height H1(0) cm Final Height H1(T) cm Time taken for descent (T) sec Discharge coefficient 1 15 5 24 4.365 2 20 10 21 3.991 3 10 4 17 4.375 4 12 5 19 4.136 5

25 10 28 4.200

Table 2.1: Readings for determination of discharge coefficient ()avg = 4.213. S.No. Initial Height H2(0) cm Final Height H2(T) cm Time taken for descent (T) sec Discharge coefficient 1 15 5 22 4.761 2 20 10 18 4.656 3 10 4 15 4.958

4 12 5 17 4.622 5 25 10 25 4.704

Table 2.2: Readings for determination of discharge coefficient ()avg= 4.740 Determining discharge coefficient can be determined by making the following arrangements. Outflow for each of the two tanks is closed, i.e, Q01 = Q02 =0. And Q03 .0, i.e, baffle is raised to allow coupling to happen.

. The inlet to each of the tanks is closed. Qi1 = Qi2 =0. Here, one of the inlets can be opened to let some fluid inside so that readings can be taken. Once, the above two arrangements are made, the mass balance equation (2.6) and ( 2.7) for tank 1 (and similar for tank 2) come out to be as follows (2.27) (2.28) Now, with A1=A2=A (say), combining the equations (2.27) and (2.28) and integrati ng between the limits (H1-H2) (0) and (H1-H2) (T) = (2.29) Solving, we get(2.30) Again, the water level in the two tanks for various values of (H1-H2) (0) and (H 1-H2) (T) with the corresponding time T is noted down and tabulated as shown in table (2.3). Th e discharge coefficient is determined using equation (2.30) S.No. Initial difference in Height (H1H2)(0) cm Final Difference in Height (H1H2)(T) cm Time taken for descent (T) sec Discharge coefficient (Coupling coefficient) 1 15 0 6 20.655 2 12 0

4 27.710 3 22 0 5.5 27.289 4 25 0 6.5 24.615 5 30 0 8.5 20.646

Table 2.3: Readings for determination of discharge coefficient ()avg = 24.183

Method 2: Simultaneous determination of discharge coefficients- a1, a2 and a3. The Mass ba lance equations for the system dynamics as given by equations (2.6) and (2.7) (2.6) (2.7) Now, closing the input to the two tanks renders. And also. A1=A2=A(say) . for we have and Substituting these in equations (2.6) and (2.7) and rearranging, we get-. = (2.31) = (2.32) Now, (i) The above two equations (2.31) and (2.32) are linear with respect to the par ameters a1, a2 and a3. (ii) can be approximated as forward or backward difference of two consecutive readings for and , respectively. Backward difference methodi.e., and

Forward Difference method and and have been calculated by using the backward difference method. Procedure adoptedA number of readings are taken for height (H1) in tank 1 and height (H2) in tank 2 at intervals of . All the readings can be assembled in the form of matrix according to equations (2.31) and (2.32), as followsFrom equation (2.31) (2.33) Similarly from equation (2.32) (2.34) The equations (2.31) and (2.32) and thus the equations (2.33) and (2.34) hold si multaneously. Hence, writing the equations (2.33) and (2.34) jointly-

(2.35) In the above equation (2.35) let, = , and = With the above assumptions equation (2.35) can be re-written as-

(2.36) The values of parameters a1, a2 and a3 can be worked out using linear least squa re solution for the above equation. = (T)-1 T => (2.37) (100 readings are taken full set of readings are put up in the Appendix-A) S.No. H1 H2

.H1

1 17.6008 16.4072 4.1953 4.0506 1.0925 -0.1368 -0.0666 2 17.5974 16.4069 4.1949

4.0505 1.0911 -0.0335 -0.0036

3 17.5876 16.4045 4.1938

4.0502 1.0877 -0.0982 -0.0241 4 17.5803 16.3996 4.1929 4.0496 1.0866 -0.0732 -0.0492 5 17.5753 16.4013 4.1923 4.0499 1.0835 -0.0498 0.0178 6 17.5640 16.3934 4.1909

4.0489 1.0819 -0.1135 -0.0796 7 17.5626 16.3972 4.1908 4.0493 1.0796 -0.0137 0.0378 8 17.5488 16.3886 4.1891 4.0483 1.0771 -0.1386 -0.0857 9 17.5480 16.3920 4.1890 4.0487 1.0752 -0.0072 0.0344 10 17.5344

16.3850 4.1874 4.0478 1.0721 -0.1367 -0.0698 11 17.5318 16.3854 4.1871 4.0479 1.0707 -0.0258 0.0035 12 17.5202 16.3820 4.1857 4.0475 1.0669 -0.1155 -0.0339 13 17.5136 16.3779 4.1849 4.0470 1.0657 -0.0665 -0.0407

14 17.5072 16.3794 4.1842 4.0471 1.0620 -0.0635 0.0143 15 17.4960 16.3721 4.1828 4.0462 1.0601 -0.1126 -0.0726 16 17.4933 16.3758 4.1825 4.0467 1.0571 -0.0268 0.0367 17 17.4791 16.3671 4.1808 4.0456 1.0545

-0.1417 -0.0866 18 17.4778 16.3708 4.1806 4.0461 1.0521 -0.0134 0.0372 19 17.4634 16.3634 4.1789 4.0452 1.0488 -0.1440 -0.0746 20 17.4602 16.3648 4.1785 4.0453 1.0466 -0.0314 0.0140 21 17.4474 16.3606 4.1770

4.0448 1.0425 -0.1283 -0.0416 22 17.4401 16.3576 4.1761 4.0444 1.0405 -0.0727 -0.0303 23 17.4321 16.3587 4.1752 4.0446 1.0361 -0.0801 0.0115 24 17.4200 16.3520 4.1737 4.0438 1.0335 -0.1207 -0.0675 25 17.4161

16.3556 4.1733 4.0442 1.0298 -0.0392 0.0363

Table 2.4: Readings for simultaneous determination of a1, a2 and a3

The values of discharge coefficients thus calculated come out to bea1 = 4.0993 a2 = 4.3702 a3 = 25.2952 Values obtained by linear least squares method in comparison with those obtained by conventional method Method Parameter Conventional method (Method 1) Linear least squares method (Method 2) a1 4.213 4.0993 a2 4.740 4.3702 a3 24.183 25.1952

Table 2.5: Comparison of results from Method 1 and Method 2 As seen from the value of discharge coefficients obtained from Method 1 and Meth od 2 (shown in table 2.5), the corresponding values of the three discharge coefficien ts are close but not the same. As a result, the model so identified will be slightly different in both the cases and consequently the MPC performance will be different due to model uncertainty. If model identified by method 1 is better than that identified by method 2, then MPC perf ormance corresponding to method 1 will be better, and vice versa. Later, in chapter 3, i t will be shown through experimental results that zero tracking error can be obtained by an appr opriate choice of augmented state space model, even if the model is slightly incorrect representat ion of the actual plant. The state space matrices obtained by using parameter values from method 1 and me thod 2 are presented in the next section.

2.3 State space model based on determined parameters Recalling the continuous time state space model from equations (2.19) and (2.20) = + (2.19) (2.20) Assuming, = Ap , Bp, = Cp and = , = The state space equations can be expressed in the standard form as follows= + Bp (2.38) (2.39) In equations (2.38) and (2.39) assuming= , = U, and = Y

Where all,, U and Y will be 2 dimensional vector. The equations (2.38) and (2.39 ) with the above assumptions can be re-written as= Ap.X + Bp.U (2.40) Y = Cp.X (2.41) Equations (2.40) and (2.41) represent the continuous time state space equations for the two inputtwo output coupled tank system. Now, with the values of all the ingredient parameters known, the values of the s tate space matrices given by equations (2.40) and (2.41) can be worked out . A1=A2=32 cm2. . Discharge coefficients a1=4.213, a2=4.740 and a3=24.183 (Method 1) . Discharge coefficients a1=4.0993, a2=4.3702 and a3=25.1952 (Method 2) . Operating points H1 and H2. These can be chosen to be any value between 0 to 30c m as per the tank capacity. The only limitation in choosing the operating points i s thatthe difference in H1 and H2 cannot be more than 5cm. This limitation arises beca use of limitation in pumping rate of the motor pumps and the coupling between the tw o tanks. The maximum pumping rate (r) delivered by each of the two motors at 5 vol ts comes out to be 36 cm3/sec. i.e., 0 cm3/sec = r = 36 cm3/sec. (2.42) Hence, the maximum difference in height H1 and H2 can be maintained if one of th e motor pumps is working is at its full capacity (36 cm3/sec) while the other motor pump is off (0 cm3/sec). This corresponds to a maximum difference of 5 cm as observed from expe riments performed. Choosing H1= H2=15 cm for working out the state space matrices.

State space matrices with respect to parameters determined by Method 1: Ap= Bp = Cp= (2.43-a) The continuous time state space equations (2.40) and (2,41) are discretized usin g a sampling time Ts = 0.5 sec. The discretized state space matrices come out to be as followsAd= Bd = Cd= (2.44-a) State space matrices with respect to parameters determined by Method 2: Ap= Bp = Cp= (2.43-b) The continuous time state space equations (2.40) and (2.41) are discretized usin g a sampling time Ts = 0.5 sec. The discretized state space matrices come out to be as follows-

Ad= Bd = Cd= (2.44-b) 2.4 Model Validation As mentioned earlier in section (2.2), step test also forms a suitable method fo r determining the system model. Here, Model Validation is carried out by comparing the simulat ed output generated by applying step input signal to the system model determined by method 1 and that generated by system model determined by method 2, against the actual output gene rated by applying the same step input signal to the actual plant. Procedure: 1. Step input of step 0.5 volts (step change in rate = 4.7688cm^3/sec) is applie d to motor pump 1. The output (water level) in the two tanks is allowed to settle at the ne w steady state.

2. While maintaining the input to motor pump 1 unchanged, a step input of 0.5 vo lts=( step change in rate = 4.9013cm^3/sec) is applied to motor pump 2 and the output in bo th the tanks is allowed to settle to new steady state value.

As shown in the figure (2.3), the system model determined by both, method 1 and method 2, represents the actual system quiet closely. System model determined by Method 1 represents the actual system better than that determined by method 2. Hence, in all future expe riments, the system model determined by method 1 is considered.

050010001500200025002345678910Output tank1 (cm) Samples step test data (actual plant) simulated data from plant model (method 1) simulated data from plant model (method 2) 0500100015002000250012345678910Output tank2 (cm) Samples step test data (actual plant) simulated data from plant model (method 1) simulated data from plant model (method 2) 0500100015002000250078910111213STEP INPUT tank1 (cm) Samples step input to motor pump 1 0500100015002000250066.577.588.599.51010.511STEP INPUT tank2 (cm) Samples step input to motor pump 2 Output tank 1 Output tank 2 Output tank 2

Input tank 1

Input tank 2

Figure 2.3 Model Validation

2.5 Sensor and Actuator Calibrations: As shown in the figure (2.4), the input for the Capacitive Level Sensors is the level of water in the respective tanks, while its output is analog voltage in the range of 0 to 5 volt dc. Input to motor pumps in analog voltage (0 to 5 volts), while output is rate of flow of wa ter given in cm3/sec. 2.5.1 Sensor Calibrations Figure 2.4: Input-output entities for Level Sensors The MPC control algorithm needs to update the states (as defined by state space model) at each sampling instant and incorporates these in making future predictions ove r the prediction horizon (Np). The values received from the level sensors through the Data Acquis ition Card (NI DAQmx 6024E) are analog voltages (0-5volt dc). Hence, these have to be suitably converted to the corresponding height (water level) value (0-30cm) in order to be suitably in corporated in the control algorithm. Major issues in calibrations: (i) The input-output relationship for both the sensors is almost but not entirel y linear. Higher order input-output relationship equations need to be considered for great er accuracy. (ii) The input-output relationship (linear or non-linear) is not consistent thro ughout the length of the sensors. For this reason, calibrations are worked out by specifyin g virtual regions of the sensors as shown in figure (2.6)

Level Sensor 1: Level Sensor 2: Region 1 0 to 11 cm 0 to 10 cm Region 2 11 cm to 20 cm 10 cm to 19 cm Region 3 20 cm to 30 cm 19 cm to 30 cm

Table 2.6: Division of Regions along the length of level sensors Procedure: Calibrations are done separately for the two sensors, as both have sl ightly different input-output relationship. Water level is maintained at various levels, the heig ht of water is read manually using the scale attached to the tank system and the corresponding volta ge value is read from the DAQ. Readings thus obtained, have been tabulated as shown in Table (2.7 ) and Table (2.8) for level sensor 1 and level sensor 2, respectively. Region 1 Region 2 Region 3 Water level (cm) Voltage (volts) Water level (cm) Voltage (volts) Water level (cm) Voltage

(volts) 3.5 0.8083 11.4 1.9563 20.0 3.2291 3.8 0.8323 12.3 2.0665 20.4 3.2932 4.1 0.8739 13.4 2.2340 21.0 3.3912 4.8 0.9567 14.6 2.4153 21.5 3.4634 5.6 1.0600 15.7 2.6003 22.0

3.5419 6.5 1.1686 16.7 2.7550 22.5 3.6071 7.0 1.2509 17.6 2.8753 23.0 3.6772 7.8 1.3626 18.7 3.0508

8.6 1.4803 19.7 3.2112

9.2 1.5746

10.0 1.6617

11.0 1.7980

11.8 1.9563

Table 2.7: Calibrations for Level Sensor 1

Region 1 Region 2 Region 3 Water level (cm) Voltage (volts) Water level (cm) Voltage (volts) Water level (cm) Voltage (volts) 2.9 0.2308 10.6 1.9563 19.5 3.2291 3.0 0.2749 11.6 2.0665 19.9 3.2932 3.4 0.3290 12.6 2.2340 20.2 3.3912

3.5 0.3725 13.7 2.4153 20.8 3.4634 3.8 0.4118 14.5 2.6003 21.5 3.5419 4.4 0.5214 15.7 2.7550 21.8 3.6071 5.1 0.7066 16.9 2.8753 22.5 3.6772 6.2 1.0412 17.9 3.0508

7.0 1.2354 18.9 3.2112

7.8 1.3748

8.5 1.4969

9.2 1.6354

10.6 1.8880

Table 2.8: Calibrations for Level Sensor 2

304050607080901001101200.811.21.41.61.82 y = 0.014*x + 0.3y = 2e-005*x2 + 0.011*x + 0.4y = - 1.3e-007*x3 + 4.9e-005*x2 + 0.0087*x + 0.44y = 2.4e-008*x4 - 7.5e-006*x3 + 0.00085*x2 - 0.028*x + 1data 1 linear quadratic cubic 4th degree 0.811.21.41.61.8230405060708090100110120130 y = 73*x - 22y = - 7.8*x2 + 94*x - 35y = 3.2*x3 - 21*x2 + 1.1e+002*x - 42y = - 5 4*x4 + 3e+002*x3 - 6.2e+002*x2 + 6.3e+002*x - 2e+002data 1 linear quadratic cubic 4th degree 1.822.22.42.62.833.23.43.6100120140160180200220240 y = 65*x - 12y = - 1.1*x2 + 71*x - 19y = 3.8*x3 - 30*x2 + 1.5e+002*x - 81y = - 2 2*x4 + 2.3e+002*x3 - 8.8e+002*x2 + 1.6e+003*x - 9.8e+002data 1 linear quadratic cubic 4th degree 1101201301401501601701801902001.822.22.42.62.833.23.43.6 y = 0.015*x + 0.19y = 4.1e-006*x2 + 0.014*x + 0.28y = - 2e-007*x3 + 0.0001*x2 0.00057*x + 1data 1 linear quadratic cubic Level Sensor 1 conversions: Region 1Figure 2.5: Sensor 1 conversions-region1 Height to voltage conversion

Voltage to height conversion

Region 2Figure 2.6: Sensor 1 conversions-region2 Voltage to height conversion

Height to voltage conversion

3.23.253.33.353.43.453.53.553.63.653.7195200205210215220225230235 y = 67*x - 16y = 17*x2 - 54*x + 1.9e+002y = 10*x3 - 91*x2 + 3.2e+002*x - 2.4e+00 2y = - 1.2e+002*x4 + 1.6e+003*x3 - 8.5e+003*x2 + 2e+004*x - 1.7e+004data 1 linear quadratic cubic 4th degree 2002052102152202252303.23.253.33.353.43.453.53.553.63.653.7 y = 0.015*x + 0.25y = - 5.8e-005*x2 + 0.04*x - 2.4data 1 linear quadratic 2030405060708090100110-0.500.511.522.5 y = 0.022*x - 0.41y = - 5.2e-005*x2 + 0.029*x - 0.59y = - 1.9e-006*x3 + 0.00032* x2 + 0.006*x - 0.17y = 9.6e-008*x4 - 2.7e-005*x3 + 0.0027*x2 - 0.089*x + 1.1data 1 linear quadratic cubic 4th degree 0.20.40.60.811.21.41.61.822030405060708090100110120 y = 44*x + 19y = 5.4*x2 + 34*x + 22y = 10*x3 - 27*x2 + 63*x + 16y = - 16*x4 + 78 *x3 - 1.2e+002*x2 + 1.1e+002*x + 7.2data 1 linear quadratic cubic 4th degree Region 3Figure 2.7: Sensor 1 conversions-region3 Level Sensor 2 conversions: Voltage to height conversion

Height to voltage conversion

Region 1Height to voltage conversion

Voltage to height conversion

Figure 2.8: Sensor 2 conversions-region1

1001101201301401501601701801901.61.822.22.42.62.833.23.43.6 y = 0.019*x - 0.13y = - 6.2e-006*x2 + 0.021*x - 0.26y = - 3.6e-007*x3 + 0.00015* x2 - 0.0023*x + 0.84data 1 linear quadratic cubic 1.822.22.42.62.833.23.43.6100110120130140150160170180190200 y = 52*x + 6.8y = 0.88*x2 + 48*x + 13y = 2.8*x3 - 22*x2 + 1.1e+002*x - 38y = 5.9 *x4 - 60*x3 + 2.3e+002*x2 - 3.2e+002*x + 2.4e+002data 1 linear quadratic cubic 4th degree 1952002052102152202253.53.63.73.83.944.14.24.3 y = 0.019*x - 0.075y = 6e-005*x2 - 0.0063*x + 2.5data 1 linear quadratic 3.53.63.73.83.944.14.24.3180190200210220230240 y = 53*x + 4.5y = - 9.8*x2 + 1.3e+002*x - 1.4e+002y = 28*x3 - 3.4e+002*x2 + 1.4e +003*x - 1.8e+003y = 3.2e+002*x4 - 5e+003*x3 + 2.9e+004*x2 - 7.4e+004*x + 7.1e+0 04data 1 linear quadratic cubic 4th degree Region 2Figure 2.9: Sensor 2 conversions-region2 Height to voltage conversion

Voltage to height conversion

Region 3Figure 2.10: Sensor 2 conversions-region3 Height to voltage conversion

Voltage to height conversion

22.533.544.51214161820222426283032height in tank 1-cm Voltage generated - volts region1single linear fitregion 2region 3 05010015020025030000.511.522.533.544.55voltage generated by sensor 1-volts height in tank 1-mm region1 single linear fitregion 2region 3 050100150200250300-10123456voltage generated by sensor 2-volts height in tank 2-mm region 1 single linear fitregion 2region 3 22.533.544.5510121416182022242628height in tank 2-cm Voltage generated - volts region 1 sing;e linear fitregion 2region 3 The inconsistency in the sensor conversions from one region to the other can be better observed by plotting the linear conversion functions for all the 3 regions simultaneously . Figure 2.11: Sensor 1 conversions for all 3 regions Sensor 1: voltage to height conversion

Sensor 1: Height to voltage conversion

Figure 2.12: Sensor 2 conversions for all 3 regions Sensor 2: Height to voltage conversion

Sensor 2: voltage to height conversion

2.5.2 Motor Calibrations Figure 2.13: Input-output entities for Motor Pumps Major issues in Motor Calibrations(i) Motor calibrations are comparatively simpler with respect to sensor calibrat ions. Here too, calibrations are carried out separately for pump motor 1 and pump motor 2. (ii) In order to determine the volume of water flowing into the tanks per unit t ime for a given analog voltage fed to the motor, the outlet valves for both the tanks are closed. Procedure: DAQ output lines are initialized and analog voltage is fed to the pum p motors (separately for both) in steps of 0.5 volt for a sufficiently long time (10-20 s ec) for each iteratively increasing voltage. After the level in both the tanks settles to a s teady state value for the present voltage step, the level of water is read manually from the attached scale. The readings thus obtained, have been tabulated in table (2.9) and table (2.10) for motor pum p 1 and 2, respectively. The process is repeated for each step voltage. Then, the area of c ross of the tanks and the time for reaching the present steady state being known, the volume of wa ter and the rate at which it is pumped (r) pumped into the tanks can be calculated as followsTotal volume of water pumped in (V) = . Area of cross section (A)

Rate of flow (r) = (2.45) Calibrations for Motor Pump 1 S.No. Applied Voltage (volts) Initial level in Tank 1 (L1i) -cm Initial level in Tank 2 (L2i) - cm Final level in Tank 1 (L1f) -cm Final level in Tank 2 (L2f) cm Total increase in level [(L1f- L1i) + (L2fL2i) ] -cm Time (sec) Rate of flow (r) cm^3/sec 1 0.5 2.0 2.0 2.0 2.0 0

20 0 2 0.75 2.0 2.0 2.9 2.9 1.8 20 2.79 3 1.00 2.9 2.9 4.5 4.5 3.2 20 4.96 4 1.25 4.5 4.5 7.1 7.1 5.2 20 8.06 5

1.50 7.1 7.1 10.5 10.5 6.8 20 10.54 6 1.75 10.5 10.5 14.6 14.6 8.2 20 12.71 7 2.00 14.6 14.6 19.6 19.6 10.0 20 15.5 8 2.25 2.0 2.0

4.7 4.7 5.4 10 16.74 9 2.50 4.7 4.7 7.7 7.7 6.0 10 18.6 10 2.75 7.7 7.7 11.0 11.0 6.6 10 20.46 11 3.00 11.0 11.0 14.6 14.6 7.2

10 22.32 12 3.25 14.6 14.6 18.5 18.5 7.8 10 24.18 13 3.50 18.5 18.5 22.9 22.9 8.8 10 27.28 14 3.75 22.9 22.9 27.5 27.5 9.2 10 28.52 15

4.00 15.0 15.0 20.0 20.0 10.0 10 31.00 16 4.25 5.0 5.0 10.2 10.2 10.4 10 32.24 17 4.50 10.2 10.2 15.8 15.8 11.2 10 34.72

Table 2.9: Calibrations for Motor Pump 1

Calibrations for Motor Pump 2 S.No. Applied Voltage (volts) Initial level in Tank 1 (L1i) -cm Initial level in Tank 2 (L2i) - cm Final level in Tank 1 (L1f) -cm Final level in Tank 2 (L2f) cm Total increase in level [(L1f- L1i) + (L2fL2i) ] -cm Time (sec) Rate of flow (r) cm^3/sec 1 0.5 2 2 2 2 0 10

0 2 0.75 2 2 2 2 0 10 0 3 1.00 2 2 2.2 2.2 0.4 10 1.24 4 1.25 2.2 2.2 2.7 2.7 1 10 3.10 5 1.50

2.7 2.7 3.6 3.6 1.8 10 5.58 6 1.75 3.6 3.6 5.0 5.0 2.8 10 8.68 7 2.00 5.0 5.0 6.8 6.8 3.6 10 11.16 8 2.25 6.8 6.8 9.1

9.1 4.6 10 14.26 9 2.50 9.1 9.1 11.8 11.8 5.4 10 16.74 10 2.75 2.0 2.0 5.0 5.0 6.0 10 18.60 11 3.00 5.0 5.0 8.5 8.5 7.0 10

21.70 12 3.25 8.5 8.5 12.3 12.3 7.6 10 23.56 13 3.50 12.3 12.3 16.5 16.5 8.4 10 26.04 14 3.75 16.5 16.5 21.0 21.0 9.0 10 27.94 15 4.00

21.0 21.0 25.9 25.9 9.8 10 30.38 16 4.25 5.0 5.0 10.2 10.2 10.4 10 32.24 17 4.50 10.2 10.2 15.7 15.7 11.0 10 34.10

Table 2.10: Calibrations for Motor Pump 2 Input-output conversion equations worked out based on the obtained readings are shown in figure (2.14) and figure (2.15) for pump motor 1 and 2, respectively.

0510152025303500.511.522.533.544.55 y = 0.12*x + 0.35y = 0.00061*x2 + 0.096*x + 0.47y = - 3.3e-005*x3 + 0.0023*x2 + 0.073*x + 0.52y = - 3.1e-007*x4 - 1.1e-005*x3 + 0.0019*x2 + 0.077*x + 0.52y = 2. 9e-007*x5 - 2.6e-005*x4 + 0.00077*x3 - 0.008*x2 + 0.12*x + 0.49y = - 5.6e-009*x6 + 8.8e-007*x5 - 4.9e-005*x4 + 0.0012*x3 - 0.011*x2 + 0.13*x + 0.49data 1 linear quadratic cubic 4th degree 5th degree 6th degree 0.511.522.533.544.5-50510152025303540 y = 8.4*x - 2.8y = - 0.37*x2 + 10*x - 4.6y = 0.21*x3 - 2*x2 + 14*x - 6.5y = - 0. 04*x4 + 0.62*x3 - 3.3*x2 + 16*x - 7.2y = - 0.11*x5 + 1.3*x4 - 5.7*x3 + 9.8*x2 + 3.7*x - 3.6y = 0.083*x6 - 1.4*x5 + 8.6*x4 - 27*x3 + 41*x2 - 18*x + 1.7y = 0.12*x 7 - 1.9*x6 + 13*x5 - 45*x4 + 83*x3 - 83*x2 + 52*x - 13data 1 linear quadratic cubic 4th degree 5th degree 6th degree 7th degree 051015202530350.511.522.533.544.55 y = 0.11*x + 0.77y = 7.6e-005*x2 + 0.1*x + 0.78y = 6.5e-005*x3 - 0.0032*x2 + 0.1 5*x + 0.72y = - 5.3e-006*x4 + 0.00042*x3 - 0.011*x2 + 0.2*x + 0.68y = 5e-007*x5 - 4.7e-005*x4 + 0.0017*x3 - 0.026*x2 + 0.26*x + 0.65y = - 2.9e-008*x6 + 3.5e-006 *x5 - 0.00016*x4 + 0.0037*x3 - 0.042*x2 + 0.3*x + 0.64data 1 linear quadratic cubic 4th degree 5th degree 6th degree 0.511.522.533.544.5-505101520253035 y = 9.3*x - 7.1y = 0.06*x2 + 9*x - 6.8y = - 0.51*x3 + 3.9*x2 + 0.87*x - 2.3y = 0 .3*x4 - 3.5*x3 + 14*x2 - 12*x + 2.8y = - 0.13*x5 + 1.9*x4 - 11*x3 + 29*x2 - 26*x + 6.9y = - 0.017*x6 + 0.13*x5 + 0.39*x4 - 6.5*x3 + 23*x2 - 21*x + 5.8data 1 linear quadratic cubic 4th degree 5th degree 6th degree Motor 1conversions Figure 2.14: Motor 1 conversions Motor 2conversions Rate to voltage conversion

Voltage to rate conversion

Rate to voltage conversion

Voltage to rate conversion

Figure 2.15: Motor 2 conversions

Chapter 3 MPC Implementation on Coupled Tank System Looking Ahead: . Introduction to Model Predictive Control. . The State Space Model. . Implementation of MPC on the Coupled Tank System . Disturbance Handling capabilities of MPC

3.1 Introduction to Model Predictive Control Model Predictive Control (MPC) is a control methodology wherein an appropriate system model is used to predict the future plant output over a user defined pred iction horizon and consequently an optimal control input sequence over a control horizon is determi ned by solving an optimization problem that minimizes the error function (difference between se t point and predicted output, over the prediction horizon) while respecting the system const raints. The first input of the control input sequence determined by the optimization algorithm is applied to the actuator and the remaining control inputs are neglected. The new plant output/st ate is observed and the whole process is repeated at each sampling instant. The system model used for predicting the future output over the prediction horiz on is the State Space Model. The major advantage of MPC methodology lies in the fact that it can handle multivariable system very efficiently while handling the system input and output constraints.MPC provides good tracking of the output and an efficient way to dea l with input and output disturbance. This enables the algorithm to operate the plant very near to the system constraints [1], and hence the plant delivers a near optimal performance. The ov erall functioning of the MPC can summarized in the following steps-

algo2 (i) Given the present plant output/state, the system model is used to predict th e future output over the prediction horizon (Np). (ii) The system constraints and tracking error are formulated into cost function which is solved as an optimization problem, and the optimal control input sequence is determined over the control horizon (Nc). (iii) The first input of the optimal control input sequence is applied to the ac tuator and the remaining are neglected. (iv) New plant output(s)/state(s) are observed and the whole process is repeated . Structural Overview Of MPC algorithm is shown in figure (3.1).

Figure 3.1 : Structure of MPC

3.1.1 The receding horizon concept: MPC is also commonly known as Receding Horizon Control because only the first input of the control horizon long control sequence is actually applied to the ac tuator in place, and the remaining control inputs are neglected[1]. The process repeats at each sampl ing instant and hence the control horizon receeds by one at each iteration. Figure 3.2 : Receding Horizon Concept 3.1.2 Set point improvement: Model predictive control methodology allows the luxury to choose the set point n ear to the specified constraint. Normally, the plant should not be operated near the constr aint to be able to deal with unexpected disturbances. But, if the control action is good enough to deal with unexpected disturbances, as it is with MPC, the plant can be operated very near to the specified constraints [1]. Hence optimal performance can be achieved.

This is illustrated in the Figure 3.3. The system output (a) has high variance to disturbance and hence, the set point has to be as far as possible from the constraint. Syste m output (b) shows slightly better control action. Using predictive control allows to choose set po int near the constraint, as in (c). Figure 3.3 : Set point improvement [1] 3.2 The State Space Model: The formulation of control law in MPC methodology is based on linear discrete ti me state space model of the system. The continuous time state space equations (as per equ ations 2.40 and 2.41) = Ap.X + Bp.U (2.40) Y = Cp.X (2.41) are discretised using a sampling time Ts to obtain the discrete time state space model-

X (k+1) = Ad .X (k) + Bd.U (k) (3.1-a) Y (k) = Cd.X (k) (3.1-b) Where, X (k) is n. dimensional state vector. U (k) is m. dimensional input vector. Y (k) is p. dimensional output vector Ad = discrete time state matrix of order n x n. Bd = discrete time input matrix of order n x m. Cd = discrete time output matrix of order p x n. For the present application of two input-two output coupled tank system, the vec tor dimensions and order of state space matrices will be given as X (k) is 2 dimensional state vector representing the incremental height of water (h1 and h2) in tank 1 and tank 2, respectively U (k) is 2 dimensional input vector representing the rate of flow of water (r1 a nd r2) into tank 1 and tank 2, respectively. Y (k) is 2 dimensional output vector representing the incremental height of wate r (h1 and h2) in tank 1 and tank 2, respectively. Ad = discrete time state matrix of order 2 x 2. Bd = discrete time input matrix of order 2 x 2. Cd = discrete time output matrix of order 2 x 2. Alternatively, state space model with incremental input can be used. This has th e advantage of eliminating steady state error and to achieve offset free tracking. The cost function so formulated is used to penalize the incremental input (.u) rather than the inp ut (u) itself. From the discrete time state space equations (3.1-a) and (3.1-b), we can write-

, and Incorporating these in the discrete time state space equations, following 3 augm ented state space models can be worked out(a) Model 1-

= . + [Cd 0]. (3.2) (b) Model 2-

= . + [Cd I]. (3.3) (c) Model 3-

= . + [0 I]. (3.4) All these 3 augmented state space model can be re-written in a generalized form with state vector represented by . (k) and the sate space matrices represented by A, B and C . . (k+1) = A . (k) + B .U (k) (3.5) Y (k) = C . (k) (3.6) The state vector . (k) and the state space matrices A, B and C will be given as shown in table (3.1)

Model 1 Model 2 Model 3 State space matrix A

State space matrix B

State space matrix C [Cd 0] [Cd I] [0 I] State vector . (k)

Table 3.1: Augmented state space models Of the above 3 augmented models, the Model 2 and Model 3 produce offset free tra cking even if the model is inaccurate and/or disturbances are present. Experimental results su pporting this fact are given in the next section. 3.2.1 Choice of Appropriate Augmented State Space Model Choice of an appropriate augmented state space model is crucial to the performan ce of the controller. Identifying a system model which is an exact replica of the actual p lant is quiet difficult. Hence, proper selection ensures offset free tracking [1] of the set p oint even if there are errors in the system modelling. The aim of using the augmented state space equation is to incorporate the increm ental input instead of the input itself, in the cost function.

The cost function for deriving MPC control law is given as (Please refer Appendi x for detailed derivation of the cost function) J=2 + . 2 (3.7) If instead, the incremental input was not used, then the cost function would hav e been-

J =2 + . 2 (3.8) Now, for the cost function given by equation (3.8), the entities - tracking erro r and U control input will not be simultaneously equal to zero most of the time. In fact , and U=0 will be inconsistent most of the time. Hence, the cost minimization will not be optimal and will be equal to the norm of and U. Alternatively, if the cost function given by equation (3.7) is used, the conditi on 0 and .U=0 can be satisfied simultaneously in steady state. Hence, optimal cost minimization (J=0) can be achieved. 3.2.2Making Unbiased PredictionsIn steady state, predictions will be unbiased ify(k)ss (model) = y(k)ss(plant) (3.9) Predictions based on Model 1C= [Cd 0] and . (k) = Hence, Y (k) = C. . (k) . Y(k) = [Cd 0] , in steady state X(k) = Xss and U(k) = Uss . Y(k)ss(model) = Cd. Xss (3.10) Then, equation (3.10) will hold true only if model is accurate. Hence, model 1 i s sensitive to modeling error. Now, considering Model 3-

C=[0 I] and . (k) = . Predictions are made according to the equation Y (k) = C. . (k). Then, in steady state Y (k)plant = Yss . Y(k) = =[0 I] . Y (k)ss(model) = 0. .Xss + I.Yss (plant) . Y(k)ss(model) = Yss(plant) (3.11) Similarly, with Sate Space Model 2Y (k)ss(model) = Cp. .Xss + I.Yss (plant) (3.12) Now, for the case of coupled tank system, when control input is not zero, ripple s exist on the surface of water in the tank. Hence, even in steady state .Xss. 0. Therefore, fr om equation (3.12) Y (k)ss(model) = Yss(plant) may or may not be true. Hence, the augmented state space model 3, as given by equation (3.4) will be the most suitable option to be used in the present case of coupled tank system. Experimental resul ts highlighting this fact have been shown in the figure (3.4).

0501001501213141516171819output tank 2 - Y2 (cm) Samplesoutput - TANK 2 model 1model 2model 3 * set point 050100150-505101520253035Control input U2 (cm3/sec) Samplescontrol input-TANK 2 model 1model 2model 3 * 0501001501111.51212.51313.51414.51515.516output tank 1 Y1 (cm) Samplesoutput - TANK 1 model 1model 2model 3* set point 050100150051015202530Control input U1 (cm3/sec) Samplescontrol input-TANK 1 model 1model 2model 3 * Figure 3.4: Comparison of 3 Augmented State Space Models All further experiments have been carried out using the augmented state space mo del 3 given by equation (3.4). 3.3. Solving the Quadratic Programming Problem The MPC control law is formulated as a Quadratic Programming (QP) problem [3] ba sed on the discrete time state space equations of the system model. The QP problem a ims at minimizing the cost functionmin T.Q. + cT (3.13-a) subjected to the constraints E = g (3.13-b) Tank 1-

Tank 2-

(Refer Appendix B for detailed derivation of MPC control law) The control algorithm for solving the above QP problem was implemented in MATLAB . Many algorithms are available in literature concerning optimization problems [1, 3, 10, 17], Interior point method (IPM) and Active Set Method (ASM) being the most common. A long with these, MATLAB provides a function quadprog for solving standard quadratic programm ing problem, and this was employed to solve the MPC optimization. The following comm and in MATLAB is used to generate the optimal control input sequence.U = quadprog (Q, c, E, g) 3.4 Implementation of MPC for level control in the Coupled Tank SystemMPC is to be implemented for level control in the coupled tank system, for which the system constraints (input slew rate, input and output constraints) have to be ac counted for. The controller should generate optimal control input by solving the QP problem so as to drive the water level to the desired set point and should provide efficient disturbance ha ndling. Major Issues in Implementation of MPC on Coupled Tank System Before the controller is implemented on the coupled tank system, the following t wo issues need to be looked into. Operating region for the control action . Use of Manual Control to drive the water level inside the operating region.

3.4.1 Operating Region for the control action Recalling from section 2.1.1.2 in chapter 2, the process model was developed fro m the nonlinear Mass Balance Equations expressing the height of water in the two tanks as a function of the discharge coefficients (a1, a3 and a3) and area of cross-section of the tank s (A1 and A2). (2.6) (2.7) After linearizing this model around the operating point (desired set point) H1 a nd H2 for tank 1 and tank 2, respectively the linearized model obtained was given as(2.14) (2.15) Where all the symbols used are same as defined in chapter 2. The overall non linear system can thus be represented as pieces of regions in wh ich the linear approximation is valid [8]. The only issue concerning this linearized mod el is that it represents the actual system correctly only in a small region (Operating Band) a round the chosen operating points H1 and H2. Now, if initially the level of water in the 2 tanks rests near the bottom and it is supposed to track a set point far away (outside the range of va lidity of the linear approximation) from the current water level. In this case the system identified is not valid during the course of output going from initial level to the operating region and hence, the control action thus produced might be undesirable.

3.4.2 Use of Manual Control In order to deal with such a situation, manual control is used to bring the outp ut in the two tanks into the Operating band and then the MPC control action is allowed to take over (as shown in figure 3.5). The stretch of the operating region determines the sensitivity o f the plant model. As observed from experiments performed on the Coupled tank System, the linearize d model represents the actual non linear system to a good extent within a region of 5-6 cm around the chosen operating points H1 and H2. Procedure: Before starting the MPC control action, the present level of water is read from the level sensors by initializing the DAQ. If the level is found to be outside the o perating region corresponding to the desired set points, manual control is switched ON till the level reaches within the operating region and then MPC control action takes over. Or else, if the initial sensor readings depict the water level already inside the operating region, manual cont rol is not used. Figure 3.5: Use of Manual control to drive the water level inside the Operating region

3.4.3 Experimental Setup The block diagram for implementation of closed loop MPC on the coupled tank syst em is shown in the figure (3.6) Figure 3.6: Implementation of Closed loop control on the Coupled Tank System Block Diagram The closed loop MPC is implemented on the coupled tank system by communicating w ith the system through NI DAQmx 6024E, while the control algorithm runs in MATLAB (V ersion R 2009). The analog input and output lines of the DAQ are initialized simultaneo usly in order to send the control signals to the pump motors and the input lines are used to read the present water level, with both these tasks performed during each sampling time while the optim al control signal is also generated simultaneously in the same iteration. The state space model given by equation (3.4) is used. The limitations of motor pump capacity of 0-36 cm3/sec is incorporated as input constraints and the optimal co ntrol law with

constraints is implemented by solving the QP problem using quadprog. function ava ilable in MATLAB. The figure (3.7) shows in detail, the experimental set up for implementation of closed loop MPC on the Coupled Tank System. Figure 3.7: Experimental Setup for Implementation of MPC on Coupled Tank System

3.4.4 Experimental results MPC control action is implemented for the following valuesSet point tank 1 (H1) = 15 cm; Set point tank 2 (H2) =18 cm Constraints(i) Input constraints (limitations of pumping rate mps 1 and 2, respectively) r1 and r2 of the two motor pu

Motor1- 0 cm3/sec = r1 = 35.1363 cm3/sec Motor2- 0 cm3/sec = r2 = 34.1162 cm3/sec (ii) Slew rate constraints (.r1 and .r2)-5 cm3/sec = .r1 = 15 cm3/sec -5 cm3/sec = .r2 = 15 cm3/sec (iii) Output constraints (Y)0 cm = y1 = 18.23 cm 0 cm = y2 = 20.85 cm ; where y1 and y2 represent the water level in tank 1 and t ank2, respectively. The discrete time state space matrices as work out to be as followsAd= Bd = , Cd=

02040608010012014016018010121416Output tank1 (cm) Samples020406080100120140160180051015Control input U1 (cm3/sec) Samples 0204060801001201401601801214161820Output tank2 (cm) Samples0204060801001201401601802426283032Control input U2 (cm3/sec) Samples Implementation ResultsFigure 3.8: MPC implementation results As seen from the experimental results in figure (3.8), the controller is able to track the desired set points in the 2 tanks, while respecting the specified input, output and slew rat e constraints. In the above implementation of MPC, the following MPC parameters were usedPrediction horizon (Np)=30; Control Horizon (Nc)=10 ;bControl weighting factor ( .) =3.5. The choice of appropriate MPC parameters is also very crucial to controller perf ormance and has been dealt with in greater detail in chapter 4 under the topic Tuning parameters . Implementation Results for other set points Tank 2-

Tank 1-

The system model developed from First Principles of Mass balance equations is d ependent on the choice of operating points (H1 and H2) around which the linearization has to be carried out. Hence system model identified will be different for different set of operat ing points. Also, as

05010015068101214Output tank1 (cm) Samples050100150010203040Control input U1 (cm3/sec) Samples 050100150810121416Output tank2 (cm) Samples050100150010203040Control input U2 (cm3/sec) Samples discussed in chapter 2, the sensor calibrations are not consistent throughout th eir respective lengths. The program running in MATLAB has been so designed that it carries out the linearization each time new pair of operating points is specified. The choice of the set point also determines the choice of the sensor input-output conversion equation depending u pon the region (region 1, 2 or 3) in which the set point falls. All these issues have been take n care off in the program in order to make the control mechanism robust in terms of the choice of operating point. Experimental results for choice of few other randomly chosen pair of operating p oints are shown in figures (3.9), (3.10) and (3.11). (a) H1=12 cm, H2=13.5 cm

Tank 2-

Tank 1-

Figure 3.9: MPC implementation for H1-12cm, H2=13.5cm

05010015014161820Output tank1 (cm) Samples050100150010203040Control input U1 (cm3/sec) Samples 05010015012141618Output tank2 (cm) Samples050100150-2002040Control input U2 (cm3/sec) Samples 0501001501618202224Output tank1 (cm) Samples050100150010203040Control input U1 (cm3/sec) Samples 0501001501516171819Output tank2 (cm) Samples050100150-2002040Control input U2 (cm3/sec) Samples (b) H1=17cm , H2=15cm

Tank 1-

Tank 2-

Figure 3.10: MPC implementation for H1-12cm, H2=13.5cm (c) H1=20cm, H2=17cm

Tank 2-

Tank 1-

Figure 3.11: MPC implementation for H1-12cm, H2=13.5cm

05010015020025030012141618Output tank1 (cm) Samples05010015020025030005101520Control input U1 (cm63/sec) Samples 0501001502002503001214161820Output tank2 (cm) Samples0501001502002503002224262830Control input U2 (cm3/sec) Samples 3.5 Disturbance Handling Capabilities of MPC Disturbances are very common in all systems. These may occur in the form of fluc tuations of input voltage or sudden change of system output as a result of interaction wi th an external environmental source. An efficient controller should be such that it reacts appr opriately to such disturbances and brings back the system output to the desired set point. In the present implementations, a constant input disturbance is simulated and ap plied to the motor pumps such that the MPC control algorithm remains unknown of this disturba nce and resorts to compensatory action once it starts receiving undesired values from th e level sensors. A constant input disturbance of -0.5 volt (which corresponds to a drop of 5 cm3 /sec in the flow rate from the motor pumps) is simulated and applied to Motor 1. After the d isturbance recedes and the output is brought back to the desired set point in both the tank s, a similar constant input disturbance is applied to Motor 2. The experimental results as sh own in the figure (3.12) demonstrate efficient disturbance handling capabilities of the controller . The controller brings back the water level to the specified set point and while doing so it tak es care of the fact that the constraints are not violated. Tank 2-

Tank 1-

Figure 3.12: Disturbance handling capabilities of the Controller

Chapter 4- Tuning of MPC parameters and MPC Constraint Handling Capabilities Looking Ahead: . Tuning of MPC parameters (Np, Nc and .) . Constraint Handling Capabilities of the controller 4.1 Tuning of MPC parameters Proper choice of MPC tuning parameters viz., prediction horizon (Np), control ho rizon (Nc) and the control weighting factor (.) is crucial to the performance of the contro ller. The effect of variation of the three MPC parameters is studied one at a time keeping the other two constant. 4.1.1 Tuning the Prediction Horizon (Np) The prediction horizon (Np) signifies how far into the future the control algori thm looks for making the predictions pertaining to the system output, based upon the syste m model. The control law then aims at minimizing the error between the predicted output and t he desired reference trajectory over the prediction horizon. Prediction horizon (Np) also i nfluences the closed loop system response; short prediction horizon may lead to response havin g some oscillations around the set point before finally settling down to the desired se t point. The effect of variation of the prediction horizon (Np) is analyzed by keeping th e other two parameters constantControl Horizon (Nc) = 7; Control weighting factor (.) =1.5. Prediction horizon tuning results are shown in the figure (4.1)

02040608010012014016018011.51212.51313.51414.51515.516output tank 1 Y1 (cm) Samplesoutput - TANK 1 : Nc=7,lambda=1.5 Np=11Np=20Np*=30Np=50Np=70Np=100 020406080100120140160180-202468101214control input-TANK1 : Nc=7 , lambda= 1.5 Np=11Np=20Np*=30Np=50Np=70Np=100 02040608010012014016018013141516171819output tank 2 Y2 (cm) Samplesoutput - TANK 2 : Nc=7,lambda=1.5 Np=11Np=20Np*=30Np=50Np=70Np=100 02040608010012014016018022242628303234Control input U2 (cm3/sec) Samplescontrol input-TANK 2 : Nc=7,lambda=1.5 Np=11Np=20Np*=30Np=50Np=70Np=100 T Figure 4.1: Effect of variation of Prediction Horizon (Np) As obvious from the experimental results shown in figure (4.1), a higher predict ion horizon causes lesser overshoot and the output settles to the desired set point faster than that with smaller prediction horizon. As per the present application of Coupled Tank Syste m is concerned, Np=30 would be an appropriate choice. 4.1.2 Tuning the Control Horizon (Nc) Tank 1-

Tank 2-

The computational load on the MPC algorithm is directly proportional the magnit ude of control horizon (Nc). The control horizon (Nc) determines the number of control steps that will be calculated in order to achieve the control objective of minimizing the tracki ng error over the

020406080100120140160180-20246810121416Control input U1 (cm3/sec) Samplescontrol input-TANK 1 : Np=30,lambda=1.5 Nc=2Nc=7Nc*=10Nc=15Nc=25 02040608010012014016018016182022242628303234Control input U2 (cm3/sec) Samplescontrol input-TANK 2 : Np=30,lambda=1.5 Nc=2Nc=7Nc*=10Nc=15Nc=25 prediction horizon. The control horizon should not be more than the prediction h orizon (Np). Increasing the control horizon beyond a certain limit (usually about one-third o f the prediction horizon) does not do any favor to the system performance, but only adds to the c omputational load. Effect of variation of control horizon (Nc) is analyzed by keeping the other two parameters constant at the following valuesPrediction horizon (Np) =30; Control Weighting factor (.) =1.5. Figure 4.2: Effect of variation of the control horizon (Nc) Tank 2-

Tank 1-

As obvious from the experimental results shown in figure (4.2), increasing cont rol horizon above 10 does not cause any improvement in the performance but only adds to the computational

02040608010012014016018011.51212.51313.51414.51515.51616.5output tank 1 Y1 (cm) Samplesoutput - TANK 1 : Np=30, Nc=10 lambda=1.5lambda*=3.5lambda=7lambda=15lambda=50lambda=100 020406080100120140160180-4-202468101214Control input U1 (cm3/sec) Samplescontrol input-TANK 1 : Np=30,Nc=10 lambda=1.5lambda*=3.5lambda=7lambda=15lambda=50lambda=100 02040608010012014016018013141516171819output tank 2 Y2 (cm) Samplesoutput - TANK 2 : Np=30, Nc=10 lambda=1.5lambda*=3.5lambda=7lambda=15lambda=50lambda=100 020406080100120140160180232425262728293031Control input U2 (cm3/sec) Samplescontrol input-TANK 2 : Np=30,Nc=10 lambda=1.5lambda*=3.5lambda=7lambda=15lambda=50lambda=100 load. Hence, control horizon (Nc) =10 would be an appropriate choice for the pre sent application. 4.1.3 Tuning the Control Weighting Factor (.) The control weighting factor (.) determines the relative importance between the tracking error and the control input. Higher the value of ., higher will be the weightage towards minimizing the control signal with respect to the tracking error in the cost fun ction. Hence, as a result of high value of control weighting factor (.) , the system will be more s luggish and will take a long time to settle down to the desired set point. Figure 4.3: Effect of variation of Control Weighting Factor (.) Tank 2-

Tank 1-

Increasing . on other hand also helps in improving the robustness of a system h aving model mismatch [9]. Therefore, a compromised value of . should be chosen. As per the present application, . =3.5 seems to be an appropriate choice as per the experimental re sults shown in the figure (4.3). 4.2 Constraint Handling Capabilities of the Controller Ability to respect the system constraints is one the most unique features of MPC methodology. Almost all practical systems come with certain constraints. Actuato rs can have constraints in terms of limited operating range and slew rate constraints depend ing upon the response time of systems. In general, the following three types of constraints [ 2] are known to exist commonly(i) Slew rate constraints (.r). (ii) Input constraint (r). (iii) Output constraints (y). 4.2.1 Slew rate constraintsNeed for considering and imposing slew rate constraintsThe motors used to pump in water into the tanks operate in the range of 0-5volts . The motor is able to handle a step increase or decrease of 5 volts. i.e, -5 = .u = 5 works well for the motor. But, this range of voltage change corresponds to a sudden change of rate of infl ow of water of 35cm3/sec. -36 cm3/sec = .r = 36 cm3/sec Considering the worst case of rise in voltage from 0 to 5volt will cause 36cm3 of water to be pumped into the tank in 1 second. This creates a splash on the surface of wat er, which might lead to a false sensor reading, which further might even correspond to a value o utside the output

02040608010012014016018010111213Output tank1 (cm) Samples02040608010012014016018005101520Control input U1 (cm3/sec) Samples 0204060801001201401601801011121314Output tank2 (cm) Samples02040608010012014016018015202530Control input U2 (volts) Samples constraint boundary. Such a situation might lead to the QP problem producing an infeasible solution. Hence, although a low pass filter has been incorporated, but still thi s situation should be avoided by limiting .r to a value that does not produce a reasonably high turbul ence on the water surface. Constraint of -15 cm3/sec = .r = 15 cm3/sec, works pretty well for the given sys tem. This corresponds to voltage constraints of -1.5volt = .u = 1.5 volts. Constraint handling capability of MPC controllerSimulated constant input disturbance is introduced into one of the motor pumps a nd the ability of the controller to bring back the output to the set point within the specified co nstraints is analyzed. .r constraints ranging from [-1 cm3/sec to 1 cm3/sec] to [-20 cm3/sec to 20cm3/sec], have been implemented. The results as shown in figures (4.4-a), (4.4-b), (4.4-c) and (4.4-d) demonstrate that along with .r constraints, the other two constraints pertaining to input (u) and output (y), are also accounted for. (a) -1 cm3/sec = .r = 1 cm3/sec Tank 1-

Tank 2-

Figure 4.4-a: Slew rate constraints - 1 cm3/sec = .r = 1 cm3/sec

02040608010012014016018010111213Output tank1 (cm) Samples02040608010012014016018005101520Control input U1 (cm3/sec) Samples 0204060801001201401601801011121314Output tank2 (cm) Samples02040608010012014016018015202530Control input U2 (volts) Samples 02040608010012014016018010111213Output tank1 (cm) Samples020406080100120140160180010203040Control input U1 (cm3/sec) Samples 02040608010012014016018010121416Output tank2 (cm) Samples020406080100120140160180010203040Control input U2 (cm3/sec) Samples (b) -5 cm3/sec = .r = 5 cm3/sec Tank 1-

Tank 2-

Figure 4.4-b: Slew rate constraints - 5 cm3/sec = .r = 5 cm3/sec (c) -15 cm3/sec = .r = 15 cm3/sec Tank 2-

Tank 1-

Figure 4.4-c: Slew rate constraints - 15 cm3/sec = .r = 15 cm3/sec

02040608010012014016018010111213Output tank1 (cm) Samples020406080100120140160180010203040Control input U1 (cm3/sec) Samples 02040608010012014016018010121416Output tank2 (cm) Samples020406080100120140160180010203040Control input U2 (cm3/sec) Samples (d) -20 cm3/sec = .r = 20 cm3/sec Tank 1-

Tank 2-

Figure 4.4-d: Slew rate constraints - 20 cm3/sec = .r = 20 cm3/sec Figure 4.4: Constraint Handling Capabilities (Slew rate constraints) 4.2.2 Input (u) constraintsThe input constraints for the motor are: 0 volt = u = 5 volt. But, for safety re asons and also because the tank system starts reverberating at voltage higher than 4.5 vol t, the voltage constraints actually imposed are: 0 volt = u = 4.5 volt. This translates to rate constraints ofMotor1- 0 cm3/sec = r1 = 35.1363 cm3/sec Motor2- 0 cm3/sec = r2 = 34.1162 cm3/sec Slew rate and output constraints are maintained at the following levels-5 cm3/sec = .r = 5 cm3/sec

02040608010012014016018010111213Output tank1 (cm) Samples020406080100120140160180010203040Control input U1 (cm3/sec) Samples 02040608010012014016018010121416Output tank2 (cm) Samples020406080100120140160180010203040Control input U2 (cm3/sec) Samples 0 cm = y1 = 12.6 cm 0 cm = y2 = 14.3 cm Experimental results demonstrating the constraint handling capabilities of the c ontroller pertaining to the specified input constraints are shown in figures (4.5-a), (4.5 -b) and (4.5-c). (a) 0 cm3/sec = r1 = 35.1363 cm3/sec ; 0 cm3/sec = r2 = 34.1162 cm3/sec Tank 1-

Tank 2-

Figure 4.5-a: Input constraints (0 cm3/sec = r1 = 35.1363 cm3/sec; 0 cm3/sec = r 2 = 34.1162 cm3/sec)

02040608010012014016018010111213Output tank1 (cm) Samples020406080100120140160180010203040Control input U1 (cm3/sec) Samples 02040608010012014016018010121416Output tank2 (cm) Samples020406080100120140160180010203040Control input U2 (cm3/sec) Samples 02040608010012014016018010111213Output tank1 (cm) Samples0204060801001201401601800102030Control input U1 (cm3/sec) Samples 02040608010012014016018010121416Output tank2 (cm) Samples0204060801001201401601800102030Control input U2 (cm3/sec) Samples (b) 0 cm3/sec = r1 = 30.94 cm3/sec ; 0 cm3/sec = r2 = 30.94 cm3/sec Tank 1-

Tank 2-

Figure 4.5-b: Input constraints ((0 cm3/sec = r1 = 30.94 cm3/sec; 0 cm3/sec = r2 = 30.94 cm3/sec)) (c) 0 cm3/sec = r1 = 28.5571 cm3/sec ; 0 cm3/sec = r2 = 28.4770 cm3/sec

Figure 4.5-c: Input constraints (0 cm3/sec = r1 = 28.5571 cm3/sec; 0 cm3/sec = r 2 = 28.4770 cm3/sec) Tank 1-

Tank 2-

Figure 4.5: Constraint Handling Capabilities (Input Constraints)

020406080100120140160180101520Output tank1 (cm) Samples020406080100120140160180051015Control input U1 (cm3/sec)Samples 02040608010012014016018010152025Output tank2 (cm) Samples020406080100120140160180253035Control input U2 (cm3/sec) Samples 4.2.3 Output (y) constraintsThe capability of the mpc controller to handle output constraints can be demonst rated if a loosely tuned controller is able to keep the plant output (precisely its oversho ot) below the maximum value given by the constraint. Overshoot and thus constraint violation c an be avoided by properly tuning the controller, but here loose tuning is done just for the sa ke of demonstrating its ability to respect the constraints. MPC parameters chosen- Np=10, Nc=5, .=1. Slew rate and input (u) constraints are chosen as follows-5 cm3/sec = .r = 15 cm3/sec 0 cm3/sec = r1 = 35.1363 cm3/sec; 0 cm3/sec = r2 = 34.1162 cm3/sec Experimental results demonstrating the constraint handling capabilities of the c ontroller pertaining to the specified output constraints are shown in figures (4.6-a), (4. 6-b) and (4.6-c). (a) 0 cm = y1 = 18.23 cm ; 0 cm = y2 = 20.85 cm

Tank 2-

Tank 1-

Figure 4.6-a: Output constraints (0 cm = y1 = 18.23 cm; 0 cm = y2 = 20.85 cm)

0204060801001201401601801012141618Output tank1 (cm) Samples020406080100120140160180051015Control input U1 (cm3/sec) Samples 0204060801001201401601801214161820Output tank2 (cm) Samples020406080100120140160180253035Control input U2 (cm3/sec) Samples 0204060801001201401601801112131415Output tank1 (cm) Samples020406080100120140160180051015Control input U1 (cm3/sec) Samples 0204060801001201401601801214161820Output tank2 (cm) Samples0204060801001201401601802628303234Control input U2 (cm3/sec) Samples (b) 0 cm = y1 = 16.28 cm ; 0 cm = y2 = 19.29 cm Tank 2-

Tank 1-

Figure 4.6-b: Output constraints (0 cm = y1 = 16.28 cm; 0 cm = y2 = 19.29 cm) (c) 0 cm = y1 = 15.00 cm ; 0 cm = y2 = 18.25 cm Tank 2-

Tank 1-

Figure 4.6-c: Output constraints (0 cm = y1 = 15.00 cm; 0 cm = y2 = 18.25 cm) Figure 4.6: Constraint Handling Capabilities -Output constraints

Chapter 5 Conclusion and Recommendations for further Improvements Looking Ahead: . Conclusions reached after implementation of MPC on the Coupled Tank System . Recommendations and scope for further improvements

5.1 Conclusion From the experimental results obtained, it is concluded that MPC has been implem ented successfully for level control in the Coupled Tank System, which was the primary objective of the project. MPC therefore, comes out to be a suitable control methodology for s et point tracking and its inherent capability to account for system constraints proves to be like the icing on a cake. The system state space model was developed using the Mass balance equations for volume of water contained in the tank. The non linear equations thus obtained were line arized around the desired operating point and consequently the discrete time state space model for the system was developed. Augmented state space model (Model 3 Eq. 2.4) with incremental in put instead of the input itself is used in the implementations in order to ensure offset fre e tracking of the set point. Further, a constant input disturbance was introduced in the two motor pumps and the ability of the controller to bring back the outputs in the two tanks to the desired set point was demonstrated. Experiments were carried out for tuning of MPC parameters viz, the prediction horizon (Np), control horizon (Nc) and the control weighting factor (.), and a p roper choice of MPC parameters was made for the present application. Choice of an appropriate au gmented state space model with incremental inputs and the MPC parameters is crucial to the con troller performance and hence should be chosen properly.

Ability to account for system constraints is the most unique feature of MPC met hodology. Experiments were carried out by imposing stringent constraints (input, output an d input slew rate constraints) in the control algorithm and ability of the controller to track the output to the desired set point while respecting the specified constraints was demonstrated. 5.2 Recommendations and Scope for Further Improvements As per the developments in this project, the following recommendations are sugge sted for further improvements(d) First Principle Method relating was used to develop the system model by line arizing the Mass Balance equations around the desired operating point. The system model so developed correctly represents the actual plant only in a small region around th e set point. As an alternative to this approach of First Principle Method, various oth er methods available in literature like Step Test or Relay Test might be used to de velop the state space model. The output matrix C. in the state space model might not co me out to be an Identity or a Diagonal matrix as it was in case of First Principle Method. Hence, an observer design will have to be carried out and included in the contro l algorithm.

(e) As a result of the recommended Step Test method and consequent output matrix C. not being an Identity matrix, one could also explore into finding suitable methods t o convert the output C matrix into an Identity matrix (probably by some similarity transformations), thereby eliminating the need of observer design.

(f) In the present implementations, small constant input disturbances are applie d to the motor pumps in order to demonstrate the disturbance handling capabilities of the controller. In practice, disturbances might not always be constant and might als o be large enough to drive the output outside the specified constraints. This might l ead to an infeasible solution (especially while working with quadprog function for solving t

he

QP problem) or the solution produced might not be optimal. In order to tackle la rge disturbances a method of Dynamic constraint specification could be adopted and included in the control mechanism.

(g) The present project does not analyze the Robustness of the control phenomeno n with respect to modelling errors. This could be one of the major areas in which work could be done in order to develop a model that closely approximates the actual plant.

BIBLIOGRAPHY [1] J.M. Maciejowski, Predictive Control with Constraints Prentice Hall, pp.36-70, 74-99, 2002 [2] Liuping Wang, Model Predictive Control System Design and Implementation using MATLAB , Springer London, pp.47-81, 2009 [3] Stephen Boyd, Lieven Vandenberghe Convex Optimization , Cambridge University Press , pp.127-155, 291-305, 2009. [4] Model Predictive Control Toolbox [Online]. Available: www.mathworks.com. [5] Kentridge Instruments Pte Ltd, Specification Manual of Coupled Tank Control Apparatus PP100 from Kentridge Instruments Pte Ltd , Part I, pp.8-23. [6] J.P. Nortan, An introduction to Identification , Academic Press New York, pp.23 -39, 59-83, 1986. [7] Camacho and Bordons, Model Predictive Control (2nd Ed.) , Springer, pp.167-192, 2004. [8] Leyla zkan, Mayuresh V. Kothare and Christos Georgakis, Model Predictive Contr ol for non-linear systems using piece wise linear model , Department of Chemical Engineering , Chemical Process Modelling and Control Research Centre, Lehigh University, October 2001. [9] J.H. Lee and Z.H. Yu, Tuning of Model Predictive Controllers for Robust perfo rmance , Computers in Chemical Engineering, 1994. [10] Wu Xuepei, Embedded Implementation of Model Predictive Control MSc Thesis, School of EEE, Nanyang Technological University, 2009. [11] Matthew S. Elliott and Bryan P. Rasmussen, A Model-Based Predictive Supervis ory Controller for Multi-Evaporator HVAC Systems , American Control Conference Hyatt Regency Riverfront, St. Louis, MO, USA, 2009. [12] Nandar Lynn, An application of Model Predictive Control MSc Thesis, School of EEE, Nanyang Technological University, 2008.

[13] Cai Yuebin, Multivariable Predictive Control of a distillation column , MSc Th esis, School of EEE, Nanyang Technological University, 2002. [14] Rawlings, James Blake, Model predictive control: theory and design , Nob Hill Pub., 2009. [15] Lee, Kah Hwee, Model predictive control of a multi-tank system, School of El ectrical and Electronic Engineering, Nanyang Technological University, 2000. [16] Stephen Boyd, Video Lectures on Convex Optimization [Online] Available: www.stanford.edu. [17] P. Skrabanek, D. Honc, Fast Optimization Algorithm for Constrained Model Pre dictive Control , University of Pardubice, Faculty of Electrical Engineering and Informati cs Department of Process Control. [18] Kuo, Benjamin C, Automatic control systems 8th ed. , pp.273-290, 1930. [19] National Instruments, NI 6023E/6024E/6025E Family Specification Sheet . [20] Allgower, Frank, Nonlinear Model Predictive Control , Progress in Systems and Control Theory, vol.26, Ascona, Switzerland, pp.23-42, 129-142, June 1998.

Appendix A: Data values obtained for method 2 of simultaneous determination of discharge coefficients a1, a2 and a3. H1 H2

.H1

17.6008 17.5974 17.5876 17.5803 17.5753 17.5640 17.5626 17.5488 17.5480 17.5344 17.5318 17.5202 17.5136 17.5072 17.4960 17.4933 17.4791 17.4778 17.4634 17.4602 17.4474 17.4401 17.4321 17.4200 17.4161 17.4006 17.3983 17.3823 17.3788 17.3643 17.3574 17.3481 17.3364 17.3319 17.3170 17.3149 17.2995 17.2971 17.2848 17.2816 17.2741

17.2665 17.2640 17.2524 17.2525 17.2392 17.2393 17.2277 16.4072 16.4069 16.4045 16.3996 16.4013 16.3934 16.3972 16.3886 16.3920 16.3850 16.3854 16.3820 16.3779 16.3794 16.3721 16.3758 16.3671 16.3708 16.3634 16.3648 16.3606 16.3576 16.3587 16.3520 16.3556 16.3470 16.3507 16.3431 16.3447 16.3404 16.3379 16.3382 16.3312 16.3344 16.3258 16.3296 16.3214 16.3234 16.3180 16.3159 16.3154 16.3089 16.3119 16.3032 16.3070 16.2983 16.3006 16.2943 4.1953 4.1949 4.1938

4.1929 4.1923 4.1909 4.1908 4.1891 4.1890 4.1874 4.1871 4.1857 4.1849 4.1842 4.1828 4.1825 4.1808 4.1806 4.1789 4.1785 4.1770 4.1761 4.1752 4.1737 4.1733 4.1714 4.1711 4.1692 4.1688 4.1671 4.1662 4.1651 4.1637 4.1632 4.1614 4.1611 4.1593 4.1590 4.1575 4.1571 4.1562 4.1553 4.1550 4.1536 4.1536 4.1520 4.1520 4.1506 4.0506 4.0505 4.0502 4.0496 4.0499 4.0489 4.0493 4.0483 4.0487 4.0478 4.0479 4.0475 4.0470 4.0471

4.0462 4.0467 4.0456 4.0461 4.0452 4.0453 4.0448 4.0444 4.0446 4.0438 4.0442 4.0431 4.0436 4.0427 4.0429 4.0423 4.0420 4.0421 4.0412 4.0416 4.0405 4.0410 4.0400 4.0402 4.0396 4.0393 4.0392 4.0384 4.0388 4.0377 4.0382 4.0371 4.0374 4.0366 1.0925 1.0911 1.0877 1.0866 1.0835 1.0819 1.0796 1.0771 1.0752 1.0721 1.0707 1.0669 1.0657 1.0620 1.0601 1.0571 1.0545 1.0521 1.0488 1.0466 1.0425 1.0405 1.0361 1.0335 1.0298

1.0264 1.0235 1.0194 1.0169 1.0119 1.0097 1.0049 1.0026 0.9987 0.9956 0.9926 0.9890 0.9868 0.9833 0.9827 0.9791 0.9786 0.9758 0.9743 0.9724 0.9700 0.9689 0.9661 -0.1368 -0.0335 -0.0982 -0.0732 -0.0498 -0.1135 -0.0137 -0.1386 -0.0072 -0.1367 -0.0258 -0.1155 -0.0665 -0.0635 -0.1126 -0.0268 -0.1417 -0.0134 -0.1440 -0.0314 -0.1283 -0.0727 -0.0801 -0.1207 -0.0392 -0.1549 -0.0230 -0.1608 -0.0350 -0.1441 -0.0691 -0.0938 -0.1168 -0.0447 -0.1493 -0.0208

-0.1539 -0.0240 -0.1227 -0.0320 -0.0753 -0.0761 -0.0246 -0.1161 0.0013 -0.1327 0.0006 -0.1161 -0.0666 -0.0036 -0.0241 -0.0492 0.0178 -0.0796 0.0378 -0.0857 0.0344 -0.0698 0.0035 -0.0339 -0.0407 0.0143 -0.0726 0.0367 -0.0866 0.0372 -0.0746 0.0140 -0.0416 -0.0303 0.0115 -0.0675 0.0363 -0.0855 0.0367 -0.0761 0.0162 -0.0432 -0.0255 0.0033 -0.0702 0.0324 -0.0865 0.0381 -0.0822 0.0205 -0.0543 -0.0209 -0.0050 -0.0653 0.0305 -0.0868 0.0376 -0.0863 0.0227

-0.0634

17.2254 17.2171 17.2101 17.2070 17.1958 17.1956 17.1825 17.1827 17.1700 17.1679 17.1587 17.1522 17.1483 17.1371 17.1364 17.1232 17.1231 17.1100 17.1082 17.0984 17.0924 17.0874 17.0769 17.0756 17.0624 17.0625 17.0497 17.0482 17.0374 17.0322 17.0266 17.0166 17.0149 17.0021 17.0022 16.9889 16.9881 16.9770 16.9727 16.9663 16.9572 16.9552 16.9424 16.9425 16.9295 16.9291 16.9173 16.9139 16.9059 16.8977 16.8949 16.8824 16.2926 16.2911 16.2851 16.2871 16.2785 16.2820

16.2729 16.2757 16.2689 16.2685 16.2660 16.2608 16.2624 16.2540 16.2576 16.2486 16.2514 16.2439 16.2438 16.2403 16.2357 16.2367 16.2288 16.2319 16.2226 16.2257 16.2176 16.2178 16.2139 16.2099 16.2104 16.2028 16.2059 16.1967 16.2000 16.1915 16.1925 16.1873 16.1841 16.1839 16.1765 16.1789 16.1698 16.1731 16.1646 16.1660 16.1602 16.1574 16.1560 16.1492 16.1514 16.1418 4.1504 4.1493 4.1485 4.1481 4.1468 4.1468 4.1452 4.1452 4.1437 4.1434 4.1423 4.1415 4.1411

4.1397 4.1396 4.1380 4.1380 4.1364 4.1362 4.1350 4.1343 4.1337 4.1324 4.1323 4.1307 4.1307 4.1291 4.1289 4.1276 4.1270 4.1263 4.1251 4.1249 4.1234 4.1234 4.1218 4.1217 4.1203 4.1198 4.1190 4.1179 4.1177 4.1161 4.1161 4.1145 4.1145 4.1131 4.1127 4.1117 4.1107 4.1103 4.1088 4.0364 4.0362 4.0355 4.0357 4.0347 4.0351 4.0340 4.0343 4.0335 4.0334 4.0331 4.0325 4.0327 4.0316 4.0321 4.0310 4.0313 4.0304 4.0304 4.0299

4.0294 4.0295 4.0285 4.0289 4.0277 4.0281 4.0271 4.0271 4.0266 4.0262 4.0262 4.0253 4.0257 4.0245 4.0249 4.0239 4.0240 4.0233 4.0229 4.0229 4.0220 4.0223 4.0212 4.0216 4.0205 4.0207 4.0200 4.0196 4.0195 4.0186 4.0189 4.0177 0.9658 0.9623 0.9618 0.9591 0.9578 0.9558 0.9537 0.9524 0.9493 0.9484 0.9448 0.9441 0.9412 0.9397 0.9374 0.9352 0.9336 0.9306 0.9298 0.9263 0.9256 0.9223 0.9209 0.9186 0.9164 0.9148 0.9122

0.9112 0.9075 0.9068 0.9035 0.9021 0.8994 0.8974 0.8957 0.8930 0.8920 0.8886 0.8881 0.8845 0.8836 0.8811 0.8789 0.8771 0.8746 0.8735 0.8701 0.8698 0.8660 0.8652 0.8622 0.8606 -0.0227 -0.0835 -0.0699 -0.0312 -0.1115 -0.0022 -0.1311 0.0019 -0.1270 -0.0208 -0.0925 -0.0647 -0.0385 -0.1122 -0.0075 -0.1315 -0.0016 -0.1303 -0.0179 -0.0989 -0.0599 -0.0495 -0.1056 -0.0123 -0.1327 0.0017 -0.1285 -0.0148 -0.1082 -0.0519 -0.0557 -0.1007 -0.0168 -0.1278

0.0016 -0.1331 -0.0084 -0.1113 -0.0425 -0.0639 -0.0913 -0.0205 -0.1279 0.0012 -0.1300 -0.0043 -0.1180 -0.0334 -0.0799 -0.0820 -0.0286 -0.1248 -0.0169 -0.0152 -0.0597 0.0204 -0.0861 0.0343 -0.0904 0.0274 -0.0676 -0.0046 -0.0250 -0.0513 0.0157 -0.0840 0.0360 -0.0899 0.0278 -0.0747 -0.0012 -0.0346 -0.0464 0.0101 -0.0790 0.0305 -0.0924 0.0303 -0.0810 0.0027 -0.0395 -0.0398 0.0050 -0.0763 0.0317 -0.0923 0.0327 -0.0849 0.0103 -0.0525 -0.0319 -0.0015 -0.0747

0.0242 -0.0904 0.0330 -0.0856 0.0145 -0.0585 -0.0275 -0.0139 -0.0686 0.0222 -0.0958

Appendix (B) Derivation of MPC Control Law Referring to the augmented state space equations (3.5) and (3.6) from chapter 3. (k+1) = A . (k) + B .U (k) (3.5) Y (k) = C . (k) (3.6) Predictions using the state space model: By iterating the equation (3.6) and substituting (3.5) at each iteration, we obt ain(k+1) = C . (k+1), substituting 3.5 into this (k+1) = C {A . (k) + B .U (k)} => Y (k+1) = CA . (k) +C B .U (k) Similarly, (k+2) = C . (k+1) = C *A . (k+1) + B .U (k+1)+ = CA . (k+1) +C B .U (k+1) = CA *A . (k) + B .U (k)+ +C B .U (k+1) (k+2) = CA2 . (k) + CAB .U (k) +C B .U (k+1) The predicted output after n. such iterations, will thus be given as follows-

(k+N) = CAN . (k+ (3.14) These can be written collectively in the form of matrix as follows. (k+ (3.15)

In the above equation (3.15) let= F and Hence, equation (3.15) becomesF . (k+ G (3.16) Optimization criteria without constraints: The optimization criterion aims at finding an MPC control law such that . the future predicted output () over the prediction horizon (Np) should follow th e desired reference output trajectory (), and . the incremental control input () over the control horizon (Nc) , required to ach ieve this should also be minimized. The cost function J. is formulated so as to account for the above two issues. Fur ther, the gradient of cost function with respect to the incremental control input can be e quated to zero to get the optimal control law J=2 + . 2 (3.17) Where, . Denotes the weighting factor that decides the relative importance between the tracking error (-) and the incremental control input (). Equation (3.17) can be re-written in matrix notationJ = ()T () + . T (3.18)

Substituting equation (3.16) in equation (3.18)-

J = ()T () + . T

Assuming we haveJ = ()T () + . T, rearranging we getJ = T(GTG + .I) + 2 T GT () + ()T() (3.19) The gradient J will be given asJ = 2 (GTG + .I) + 2 GT () (3.20) Equating the gradient to zero for the minimal control input = (GTG + .I)-1GT (), putting back the value of = (GTG + .I)-1GT ( (3.21) Now, as per receding horizon concept, only the first of the incremental control input, is considered and the remaining are discarded. (GTG + .I)-1GT ( , and this can be re-written as = K1 w (k) - K2 (3.22) Where, K1 = (GTG + .I)-1GT K2 = (GTG + .I)-1GT = ,w (k) w (k) . w (k)-T , is the reference output trajectory.

Equation (3.21) is the unconstrained optimal control law and equation (3.22) is the receding horizon control law. Optimization criterion with constraints Constraint handling capability is a unique feature of MPC that allows generating an optimal control input while respecting the constraints. Constraints are highly important as all practical systems come with constraints. The system actuators will have a range of operati on and finite slew rate, depending upon its response time. Along with these, there might also be user defined constraints on the process output. Generally, the following three types of const raints exist (i) Input constraints (u). umin = (k + i/k) = umax i=0,1,2 Nc-1

(ii) Input slew rate constraints (.u). .umin = . (k + i/k) = .umax i=0, 1, 2 (iii) Output constraints (y). ymin = (k + i/k) = ymax i=0, 1, 2, . Np-1 All the constraints are assembled in a standard form E = g (3.23) (i) Input Constraints umin = (k + i/k) = umax i=0,1,2 We know that. = u (k) u (k-1) Nc-1 Nc-1

. u(k) = . + u(k-1) . u(k+1) = . (k+1) + u(k)

= . (k+1) + . + u (k-1) Hence, over the control horizon (Nc), this can be written as= u (k-1) + (3.24) Assuming= S1 and = S2 We haveU = S1 u (k-1) + S2 (3.25) Hence, the constraint equation can be written asUmin = [S1 u (k-1) + S2] = Umax (3.26) Where, Umin =[umin umin umin Umax =[umax umax umax umin]T umax]T

Input constraint equation can hence be written separately for upper and lower bo undsS2 = Umax - S1 u (k-1) (3.27-a) -S2 = -Umin + S1 u (k-1) (3.27-b)

(ii) Incremental Input Constraints .umin = . (k + i/k) = .umax i=0, 1, 2 Nc-1 Expressing the constraints over the control horizonUmin = = Umax Thus, = Umax (3.28-a) - = -Umin (3.28-b) (iii) Output Constraints ymin = (k + i/k) = ymax i=0, 1, 2, . Np-1

Expressing over the prediction horizonYmin = = Ymax Recalling from equation (3.16) F . (k+ G , putting this in output constraint equationYmin = F . (k+ G = Ymax Rearranging we getG = Ymax - F . (k (3.29-a) -G = -Ymin + F . (k) (3.29-b)

The equations (3.27), (3.28) and (3.29) can be assembled together in a standard form as per equation (3.23) we get= (3.30) Comparing this with equation (3.23) we haveE = and g = (3.31) Optimal Control LawNow, recalling from equation (3.17), the MPC cost function is given asJ=2 + . 2 (3.17) This can be re-written asJ = T(GTG + .I) + 2 T GT () + ()T() (3.19) The MPC control law can be formulated as a Quadratic Programming (QP) problem [3 ] as followsmin T.Q. + cT (3.32-a) subjected to E = g (3.32-b)

Where, Q= (GTG + .I), c = GT () = GT () . E and g are given as per equation (2.24).

Appendix (C)

Program Listing

1. Program for initializing DAQ analog input and output lines

(a) MATLAB function for analog output lines

function [analog_output]=analog_output_tomotor(tank1data,tank2data,samplingrate) % configuring daq for as output, both channels- ao0 and a01.......... clear ao; ao=analogoutput('nidaq','Dev1'); channelout=addchannel(ao,0:1); set(ao,'SampleRate',samplingrate); set(ao,'TriggerType','Manual'); putdata(ao,[tank1data tank2data]); start(ao); trigger(ao); analog_output = [tank1data tank2data]; pause(0.02); %...................................................................... (b) MATLAB function for DAQ analog input lines

function[sensordata]=sensor_reading_volts(samplingrate,samples_trigger) %.......initializing daq input channel for acquiring the data......... clear ai; wait_time=(samples_trigger/samplingrate)+0.05; ai=analoginput('nidaq','Dev1'); channelin=addchannel(ai,0:1); set(ai,'SampleRate',samplingrate); set(ai,'SamplesPerTrigger',samples_trigger); set(ai,'TriggerType','Immediate'); start(ai); wait(ai,wait_time); %pause(wait_time); data2=getdata(ai); sensordata=data2; %pause(0.5) %---each element of data2/sensordata represent the initial height % in tank1 and tank2, respectively.............................

2. Main program

clear all; clc; tic; setpoint_height_tank1=150; setpoint_height_tank2=180; W1=setpoint_height_tank1/10; W2=setpoint_height_tank2/10; manualcontrol=0; %.....denotes that manual control is not required if (min(setpoint_height_tank1,setpoint_height_tank2)>10) manualcontrol=1; %.....denotes that manual control is required end if (manualcontrol==1) manualcontrol=manual_control(W1,W2); end clear all; %.......specifying MPC parameters........................... N1=1; N2=31; Nc=10; Np=N2-N1; lambda=3.5; %........................................................... %......specifying set point for the two tanks............... setpoint_height_tank1=150; setpoint_height_tank2=180; W1=setpoint_height_tank1/10; W2=(setpoint_height_tank2)/10; %........................................................... %....specifying tank parameters and evaluating linearized system model %matrices............................................................. alpha1 = 4.213; alpha2 = 4.740; alpha3 = 24.183; A1=32; A2=32;

[Ap,Bp,Cp,Dp]=sysmatrix_Ac(W1,W2,A1,A2,alpha1,alpha2,alpha3); sys=ss(Ap,Bp,Cp,Dp); sys_dc=c2d(sys,0.5); [Ad Bd Cd Dd]=ssdata(sys_dc); [phi G]= prediction_multivariable_model(Ad,Bd,Cd,N1,N2,Nc,3); %.................................................................... %--------constarint equation formulation (Ez<=g)---------%---S2 matrix formulation----------------------------------S2=zeros((2*Nc),(2*Nc)); for p= 1:2:(2*Nc-1) for q=1:2:p S2(p:p+1,q:q+1)=eye(2,2); end end %--------end of S2 matrix calculation----------------------%----S1 matrix calculation---------------------------------S1=[]; for k=1:2:(2*Nc-1) S1=[S1;eye(2,2)]; end %----------------end of S1 determination-------------------%--initializing daq for taking 1st sensor readings --------samplingrate = 30; samples_trigger = 30; [sensordata]=sensor_reading_volts(samplingrate,samples_trigger); sensordata=mean(sensordata(21:30,:)); [converted_value_tank1]=conversion_reg(sensordata(1,1),1,0,3); [converted_value_tank2]=conversion_reg(sensordata(1,2),1,2,3); Xm = [(converted_value_tank1/10);(converted_value_tank2/10)]; %---sensordata represents the height in volts in the two tanks--Uplant=[1.5;3.5];Yplant=[(converted_value_tank1/10);(converted_value_tank2/10)]; Uk=Uplant; Yk=Yplant; U1data=[];Y1data=[];U2data=[];Y2data=[]; Xdata=[];w1data=[];w2data=[];tdata=[]; U_min=0*ones(2*Nc,1); U_max=35*ones(2*Nc,1); %..corresponding to 5 volt for motor

deltaU_min=-0.5*(2*Nc,1); deltaU_max=1.5*ones(2*Nc,1); Y_min1=zeros(Np,1); Y_min2=zeros(Np,1); Y_min=zeros((2*Np),1); for ay = 1:2:((2*Np)-1) Y_min(ay) = Y_min1((ay+1)/2); end for ax = 2:2:(2*Np) Y_min(ax) = Y_min2(ax/2); end Y_max1=(W1+1)*ones(Np,1); Y_max2=(W2+1)*ones(Np,1); Y_max=zeros((2*Np),1); for by = 1:2:((2*Np)-1) Y_max(by) = Y_max1((by+1)/2); end for bx = 2:2:(2*Np) Y_max(bx) = Y_max2(bx/2); end R1=W1*ones(Np,1); % reference output trajectory tank1 R2=W2*ones(Np,1); % reference output trajectory tank2 R=zeros((2*Np),1); for cy = 1:2:((2*Np)-1) R(cy) = R1((cy+1)/2); end for cx = 2:2:(2*Np) R(cx) = R2(cx/2); end % initial state vector, with initial height in each tank Ef=[0;0;(converted_value_tank1/10);(converted_value_tank2/10)]; w1=W1; % reference output-----------w2=W2; % reference output-----------I=eye(2*Nc,2*Nc); %------J matrix formulation----------------J=[-S2;S2;-I;I;-G;G]; %J=[-I;I]; Q=(G'*G)+(lambda*eye(size(G'*G))); iter_start=1; iter_end=180;

for k=iter_start:iter_end if (k==45 || k==85 || k==125 || k==165) clear ao; clear ai; daqreset; end g=[((-U_min)+(S1*Uk));(U_max-(S1*Uk));-deltaU_min;deltaU_max;((phi*Ef)-Y_min);(( -phi*Ef)+Y_max)]; c=G'*((phi*Ef) - R); %delta_U=qpsoft(Q,c,J,g); %[delta_U iteration] = ASMfunction(Q,c,J,g); delta_U=quadprog(Q,c,J,g); %[delta_U iter miu]=IPMfunction(Q,c,J,g); Uapplied=delta_U(1:2,1); Uplant=Uplant + Uapplied; Uk=Uplant; %....introducing constant input disturbance in motor 1 if ((k>=90)&&(k<=105)) Uk_output=Uplant + [-1.0;0.0]; %..................................................... %...introducing constant input disturbance in motor 2 elseif (k==180) && (k<=195) Uk_output=Uplant + [0.0;-2.5]; %..................................................... else Uk_output=Uplant; end tank1data = Uk_output(1,1); tank2data = Uk_output(2,1); %......sending control input to motor thru DAQ.................. [converted_value_motor1]=conversion_motor(tank1data,1,3); [converted_value_motor2]=conversion_motor(tank2data,3,1); [analog_output]=analog_output_tomotor(converted_value_motor1,converted_value_mot or2,samplingrate); Yk=Xm; Xm_old = Xm ;

%......now read new values and update xm and Yplant................. [sensordata]=sensor_reading_volts(samplingrate,samples_trigger); sensordata=mean(sensordata(21:30,:)); [converted_value_tank1]=conversion_reg(sensordata(1,1),1,0,3); [converted_value_tank2]=conversion_reg(sensordata(1,2),1,2,3); Xm = [(converted_value_tank1/10);(converted_value_tank2/10)]; tdata = [tdata; k-1]; w1data = [w1data; w1];w2data = [w2data; w2]; Y1data = [Y1data; Yk(1,1)]; U1data = [U1data; Uk(1,1)]; Y2data = [Y2data; Yk(2,1)]; U2data = [U2data; Uk(2,1)]; Yk = (phi*Ef) + (G*delta_U); Yplant = Yk (1:2,1); Ef = [Xm-Xm_old;Xm]; end %.......low pass filter................................ noisy_signal1=Y1data; [flt_signal_tank1]=lowpassfilter(noisy_signal1); flt_signal_tank1=flt_signal_tank1(1:iter_end,:); noisy_signal2=Y2data; [flt_signal_tank2]=lowpassfilter(noisy_signal2); flt_signal_tank2=flt_signal_tank2(1:iter_end,:); %...................................................... figure subplot(211),plot(tdata,w1data,tdata,Y1data),ylabel('Output tank1 (mm) '),xlabel ('Samples'); hold on grid; subplot(212),stairs(tdata,U1data),ylabel('Control input U1 (volts)'),xlabel('Sam ples'); hold on subplot(212),stairs(tdata(89:105),U1data(89:105),'r'),ylabel('Control input U1 ( volts)'),xlabel('Samples'); grid; figure subplot(211),plot(tdata,w2data,tdata,Y2data),ylabel('Output tank2 (mm)'),xlabel( 'Samples'); hold on grid; subplot(212),stairs(tdata,U2data),ylabel('Control input U2 (volts)'),xlabel('Sam ples'); hold on subplot(212),stairs(tdata(179:195),U2data(179:195),'r'),ylabel('Control input U2 (volts)'),xlabel('Samples'); grid; toc; pause; %delete(ao); clear ao; %delete(ai); clear ai;

daqreset; %pause(0.25); [analog_output]=analog_output_tomotor(0,0,samplingrate); 3. Other functions used in Main program

(a) prediction_multivariable_model function

function [phi,G]= prediction_multivariable_model(Ad,Bd,Cd,N1,N2,Nc,model) Np=N2-N1; if (model==1) [r1,c1]=size(Cd); [c1,cb]=size(Bd); A=eye(c1+r1,c1+r1); A(1:c1,1:c1)=Ad; A(1:c1,c1+1:c1+r1)=Bd; B=zeros(c1+r1,cb); B(1:c1,:)=Bd; B(c1+1:c1+r1,:)=eye(size(Bd)); C=zeros(r1,c1+r1); C(:,(1:c1))=Cd; elseif(model==2) [r1,c1]=size(Cd); [c1,cb]=size(Bd); A=eye(c1+r1,c1+r1); A(1:c1,1:c1)=Ad; A(c1+1:c1+r1,1:c1)=Cd; B=zeros(c1+r1,cb); B(1:c1,:)=Bd; %B(c1+1:c1+r1,:)=eye(size(Bp)); C=zeros(r1,c1+r1); C(:,(1:c1))=Cd; C(:,c1+1:c1+r1)=eye(size(Cd)); else [r1,c1]=size(Cd); [c1,cb]=size(Bd); A=eye(c1+r1,c1+r1); A(1:c1,1:c1)=Ad; A(c1+1:c1+r1,1:c1)=Cd*Ad; B=zeros(c1+r1,cb);

B(1:c1,:)=Bd; B(c1+1:c1+r1,:)=Cd*Bd; C=zeros(r1,c1+r1); C(:,(c1+1):c1+r1)=eye(r1,r1); end [phi_r,phi_c]=size(C*A); phi=zeros((Np*phi_r),phi_c); phi(1:phi_r,:)=C*A; for k=(phi_r+1):phi_r:((Np*phi_r)-phi_r+1) phi(k:(k+1),:)=phi(k-2:k-1,:)*A; end [G_r,G_c]=size(C*B); G=zeros((Np*G_r),(Nc*G_c)); G(1:G_r,1:G_c)=C*B; for k=(G_r+1):G_r:((Np*G_r)-1) p=((k-G_r-1)/G_r)+1; G(k:(k+G_r-1),1:G_c)= C*(A^(p))*B; end for k = (G_c+1):G_c:((Nc*G_c)-G_c+1) shift=(G_r*(k-G_c-1)/G_c)+G_r; G(:,k:(k+G_c-1))=circshift(G(:,1:G_c),shift); G(1:shift,k:(k+G_c-1))=zeros(shift,G_c); end (b) sysmatrix_Ac function function [Ap,Bp,Cp,Dp]=sysmatrix_Ac(W1,W2,A1,A2,alpha1,alpha2,alpha3) temp_variable = sqrt(abs(W1-W2)); if (abs(W1-W2)<=1) temp_variable = 1; alpha3=0; end if((W1-W2)< -1) alpha3=-alpha3; end a11 = -((alpha1/sqrt(W1))+(alpha3/temp_variable))/(2*A1);

a12 = alpha3/(2*A1*(temp_variable)); a21 = alpha3/(2*A2*(temp_variable)); a22 = -((alpha2/sqrt(W2))+(alpha3/temp_variable))/(2*A2); Ap = [a11 a12;a21 a22]; Bp = [(1/A1) 0;0 (1/A2)]; Cp = eye(2); Dp = zeros(2,2); (c) Sensor input-output conversion function : conversion_reg function function[converted_value]=conversion_reg(value,reg,selection,type) if (reg==1) if (selection==0) voltage=value; if (type==1) height_tank1 = (73*voltage)-22; elseif (type==2) height_tank1 = -(7.8*(voltage^2)) + (94*voltage) -35; elseif (type==3) height_tank1 = (3.2*(voltage^3))-(21*(voltage^2))+((1.1e+002)*voltage)-42; elseif (type==4) height_tank1 = -(54*(voltage^4))+((3e+002)*(voltage^3))((6.2e+002)*(voltage^2))+((6.3e+002)*voltage)-(2e+002); end converted_value = height_tank1; elseif (selection==1) height = value; if (type==1) voltage_tank1 = (0.014*height)+0.30; elseif (type==2) voltage_tank1 = ((2e-005)*(height^2))+(0.011*height)+0.40; elseif (type==3) voltage_tank1 = -((1.3e-007)*(height^3))+((4.9e-005)*(height^2))+(0.0087*height) +0.44; elseif (type==4) voltage_tank1 = ((2.4e-008)*(height^4))-((7.5e-006)*(height^3))+(0.00085*(height ^2))(0.028*height)+ 1.00; end converted_value = voltage_tank1; elseif (selection==2) voltage=value; if (type==1)

height_tank2 = (44*voltage)+19; elseif (type==2) height_tank2 = (5.4*(voltage^2)) + (34*voltage) +12; elseif (type==3) height_tank2 = (10*(voltage^3))-(27*(voltage^2))+(63*voltage)+16; elseif (type==4) height_tank2 = -(16*(voltage^4))+(78*(voltage^3))((1.2e+002)*(voltage^2))+((1.1e+002)*voltage)+7.2; end converted_value = height_tank2; elseif (selection==3) height = value; if (type==1) voltage_tank2 = (0.022*height)-0.41; elseif (type==2) voltage_tank2 = -((5.2e-005)*(height^2))+(0.029*height)-0.59; elseif (type==3) voltage_tank2 = -((1.9e-006)*(height^3))+(0.00032*(height^2))+(0.006*height)-0.1 7; elseif (type==4) voltage_tank2 = ((9.6e-008)*(height^4))-((2.7e-005)*(height^3))+(0.0027*(height^ 2))(0.089*height)+1.1; end converted_value = voltage_tank2; end elseif(reg==2) if (selection==0) voltage=value; if (type==1) height_tank1 = (65*voltage)-12; elseif (type==2) height_tank1 = -(1.1*(voltage^2)) + (71*voltage) -19; elseif (type==3) height_tank1 = (3.8*(voltage^3))-(30*(voltage^2))+((1.5e+002)*voltage)-81; elseif (type==4) height_tank1 = -(22*(voltage^4))+((2.3e+002)*(voltage^3))((8.8e+002)*(voltage^2))+((1.6e+003)*voltage)-(9.8e+002); end converted_value = height_tank1; elseif (selection==1) height = value; if (type==1) voltage_tank1 = (0.015*height)+0.19; elseif (type==2) voltage_tank1 = ((4.1e-006)*(height^2))+(0.014*height)+0.28;

elseif (type==3) voltage_tank1 = -((2e-007)*(height^3))+(0.0001*(height^2))-(0.00057*height)+ 1.0 0; end converted_value = voltage_tank1; elseif (selection==2) voltage=value; if (type==1) height_tank2 = (52*voltage)+6.8; elseif (type==2) height_tank2 = (0.88*(voltage^2)) + (48*voltage) +13; elseif (type==3) height_tank2 = (2.8*(voltage^3))-(22*(voltage^2))+((1.1e+002)*voltage)-38; elseif (type==4) height_tank2 = (5.9*(voltage^4))-(60*(voltage^3))+((2.3e+002)*(voltage^2))((3.2e+002)*voltage)+(2.4e+002); end converted_value = height_tank2; elseif (selection==3) height = value; if (type==1) voltage_tank2 = (0.019*height)-0.13; elseif (type==2) voltage_tank2 = -((6.2e-006)*(height^2))+(0.021*height)-0.26; elseif (type==3) voltage_tank2 = -((3.6e-007)*(height^3))+(0.00015*(height^2))-(0.0023*height)+0. 84; end converted_value = voltage_tank2; end elseif(reg==3) if (selection==0) voltage=value; if (type==1) height_tank1 = (67*voltage)-16; elseif (type==2) height_tank1 = (17*(voltage^2)) - (54*voltage) + (1.9e+002); elseif (type==3) height_tank1 = (10*(voltage^3))-(91*(voltage^2))+((3.2e+002)*voltage)-(2.4e+002) ; elseif (type==4) height_tank1 = -((1.2e+002)*(voltage^4))+((1.6e+003)*(voltage^3))((8.5e+003)*(voltage^2))+((2e+004)*voltage)-(1.7e+004); end

converted_value = height_tank1; elseif (selection==1) height = value; if (type==1) voltage_tank1 = (0.015*height)+0.25; elseif (type==2) voltage_tank1 = -((5.8e-005)*(height^2))+(0.04*height)- 2.4; end converted_value = voltage_tank1; elseif (selection==2) voltage=value; if (type==1) height_tank2 = (53*voltage)+4.5; elseif (type==2) height_tank2 = -(9.8*(voltage^2)) + ((1.3e+002)*voltage) - (1.4e+002); elseif (type==3) height_tank2 = (28*(voltage^3))-((3.4e+002)*(voltage^2))+((1.4e+003)*voltage)-(1 .8e+003); elseif (type==4) height_tank2 = ((3.2e+002)*(voltage^4))-((5e+003)*(voltage^3))+((2.9e+004)*(volt age^2))((7.4e+004)*voltage)+(7.1e+004); end converted_value = height_tank2; elseif (selection==3) height = value; if (type==1) voltage_tank2 = (0.019*height)-0.075; elseif (type==2) voltage_tank2 = ((6e-005)*(height^2))-(0.0063*height)+ 2.5; end converted_value = voltage_tank2; end end (d) motor input-output conversion function : conversion_motor function

function[converted_value]=conversion_motor(value,selection,type) if (selection==0) voltage=value;

if (type==1) rate_motor1 = (8.4*voltage)-2.8; elseif (type==2) rate_motor1 = -(0.37*(voltage^2)) + (10*voltage) -4.6; elseif (type==3) rate_motor1 = (0.21*(voltage^3))-(2*(voltage^2))+(14*voltage)-6.5; elseif (type==4) rate_motor1 = -(0.04*(voltage^4))+(0.62*(voltage^3))-(3.3*(voltage^2))+(16*volta ge)-7.2; elseif (type==5) rate_motor1= -(0.11*(voltage^5))+(1.3*(voltage^4))(5.7*(voltage^3))+(9.8*(voltage^2))+(3.7*voltage)-3.6; elseif (type==6) rate_motor1= (0.083*(voltage^6))-(1.4*(voltage^5))+(8.6*(voltage^4))(27*(voltage^3))+(41*(voltage^2))-(18*voltage) + 1.7; end converted_value = rate_motor1; if (value <=0.5) converted_value =0.00; else converted_value = rate_motor1; end elseif (selection==1) rate = value; if (type==1) voltage_motor1 = (0.12*rate)+0.35; elseif (type==2) voltage_motor1 = (0.00061*(rate^2))+(0.096*rate)+0.47; elseif (type==3) voltage_motor1 = -((3.3e-005)*(rate^3))+(0.0023*(rate^2))+(0.073*rate)+0.52; elseif (type==4) voltage_motor1 = -((3.1e-007)*(rate^4))-((1.1e005)*(rate^3))+(0.0019*(rate^2))+(0.077*rate)+0.52; elseif (type==5) voltage_motor1 = ((2.9e-007)*(rate^5))-((2.6e-005)*(rate^4))+(0.00077*(rate^3))(0.008*(rate^2))+(0.12*rate)+0.49; elseif (type==6) voltage_motor1 = -((5.6e-009)*(rate^6))+((8.8e-007)*(rate^5)) -((4.9e005)*(rate^4))+(0.0012*(rate^3))-(0.011*(rate^2))+(0.13*rate)+0.49; end converted_value = voltage_motor1; elseif (selection==2) voltage=value; if (type==1) rate_motor2 = (9.3*voltage)-7.1;

elseif (type==2) rate_motor2 = (0.06*(voltage^2)) + (9*voltage) -6.8; elseif (type==3) rate_motor2 = -(0.51*(voltage^3))+(3.9*(voltage^2))+(0.87*voltage)-2.3; elseif (type==4) rate_motor2 = (0.3*(voltage^4))-(3.5*(voltage^3))+(14*(voltage^2))-(12*voltage)+ 2.8; elseif (type==5) rate_motor2= -(0.13*(voltage^5))+(1.9*(voltage^4))-(11*(voltage^3))+(29*(voltage ^2))(26*voltage)+6.9; elseif (type==6) rate_motor2= -(0.017*(voltage^6))+(0.13*(voltage^5))+(0.39*(voltage^4))(6.5*(voltage^3))+(23*(voltage^2))-(21*voltage) + 5.8; end converted_value = rate_motor2; if (value <=0.5) converted_value =0.00; else converted_value = rate_motor2; end elseif (selection==3) rate = value; if (type==1) voltage_motor2 = (0.11*rate)+0.77; elseif (type==2) voltage_motor2 = ((7.6e-005)*(rate^2))+(0.1*rate)+0.78; elseif (type==3) voltage_motor2 = ((6.5e-005)*(rate^3))+(0.0032*(rate^2))+(0.15*rate)+0.72; elseif (type==4) voltage_motor2 = -((5.3e-006)*(rate^4))+(0.00042*(rate^3))-(0.011*(rate^2))+(0.2 *rate)+0.68; elseif (type==5) voltage_motor2 = ((5e-007)*(rate^5))-((4.7e-005)*(rate^4))+(0.0017*(rate^3))(0.026*(rate^2))+(0.26*rate)+0.65; elseif (type==6) voltage_motor2 = -((2.9e-008)*(rate^6))+((3.5e-006)*(rate^5)) (0.00016*(rate^4))+(0.0037*(rate^3))-(0.042*(rate^2))+(0.3*rate)+0.64; end converted_value = voltage_motor2; end

You might also like