Sbhs New Manual
sbhs-new-manual
User Manual: Pdf
Open the PDF directly: View PDF .
Page Count: 318
Download | |
Open PDF In Browser | View PDF |
Documentation for Single Board Heater System Rakhi R Rupak Rokade Inderpreet Arora Kannan M. Moudgalya Kaushik Venkata Belusonti IIT Bombay October 24, 2015 Contents List of Scilab Code 1 2 3 7 Block diagram explanation of Single Board Heater System 1.1 Microcontroller . . . . . . . . . . . . . . . . . . . . . . 1.1.1 PWM for heat and speed control . . . . . . . . . 1.1.2 Analog to Digital conversion . . . . . . . . . . . 1.2 Instrumentation amplifier . . . . . . . . . . . . . . . . . 1.3 Communication . . . . . . . . . . . . . . . . . . . . . . 1.3.1 Serial port communication . . . . . . . . . . . . 1.3.2 Using USB for Communication . . . . . . . . . 1.4 Display and Resetting the setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 11 12 14 14 15 16 16 16 Performing a Local Experiment on Single Board Heater System 2.1 Using SBHS on a Windows OS . . . . . . . . . . . . . . . . . 2.1.1 Installing Drivers and Configuring COM Port . . . . . 2.1.2 Steps to Perform a Local Experiment . . . . . . . . . 2.2 Using Single Board Heater System on a Linux System . . . . 2.3 Summary of procedure to perform a local experiment . . . . . 2.4 Scilab Code under common files . . . . . . . . . . . . . . . . . . . . . . 20 21 21 22 24 27 28 Using Single Board Heater System, Virtually! 3.1 Introduction to Virtual Labs at IIT Bombay . . . . . . . . . . . . . . . . . . 3.2 Evolution of SBHS virtual labs . . . . . . . . 3.3 Current Hardware Architecture . . . . . . . . 3.4 Current Software Architecture . . . . . . . . 3.5 Conducting experiments using the Virtual lab 3.5.1 Registration, Login and Slot Booking 1 . . . . . . . . . . . . . . . . 34 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 35 38 39 39 41 3.5.2 3.6 4 5 6 7 Configuring proxy settings and executing python based client . . . . . . . . . . . . . . . . . . . . . . . . . . . 3.5.3 Executing scilab code . . . . . . . . . . . . . . . . . . 3.5.4 Conducting experiments over virtual labs through ARM based computer . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 43 46 47 Identification of Transfer Function of a Single Board Heater System through Step Response Experiment 4.1 Conducting Step Test on SBHS locally . . . . . . . . . . . . . . 4.2 Conducting Step Test on SBHS, virtually . . . . . . . . . . . . 4.3 Identifying First Order and Second Order Transfer Functions . . 4.3.1 Determination of First Order Transfer Function . . . . . 4.3.2 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . 4.4 Determination of Second Order Transfer Function . . . . . . . . 4.4.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.6 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 51 52 53 53 55 56 57 58 58 Identification of Transfer Function of a Single Board Heater System through Ramp Response Experiment 5.1 Conducting Ramp Test on SBHS locally . . . . . . . . . . . . . 5.2 Conducting Ramp Test on SBHS, virtually . . . . . . . . . . . . 5.3 Identifying First Order Transfer Function . . . . . . . . . . . . 5.3.1 Procedure . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.5 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 69 69 71 72 75 75 Frequency Response Analysis of a Single Board the Application of Sine Wave 6.1 Conducting Sine Test on SBHS locally . . . . 6.2 Conducting Sine Test on SBHS, virtually . . 6.3 Frequency Analysis of sine test data . . . . . 6.3.1 Procedure . . . . . . . . . . . . . . . 6.4 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . 81 84 84 85 88 92 Controlling Single Board Heater System using PID controller 7.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 100 2 Heater System by . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8 7.1.1 Proportional Control Action . . . . . . . . . . . . . . . 7.1.2 Integral Control Action . . . . . . . . . . . . . . . . . . 7.1.3 Derivative Control Action . . . . . . . . . . . . . . . . Ziegler-Nichols Rule for Tuning PID Controllers . . . . . . . . 7.2.1 First Method . . . . . . . . . . . . . . . . . . . . . . . 7.2.2 Second Method . . . . . . . . . . . . . . . . . . . . . . PI Controller using Trapezoidal Approximation . . . . . . . . . 7.3.1 Implementing locally . . . . . . . . . . . . . . . . . . . 7.3.2 Implementing virtually . . . . . . . . . . . . . . . . . . Implementing PI Controller using Backward Difference Approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.4.1 Implementing locally . . . . . . . . . . . . . . . . . . . 7.4.2 Implementing virtually . . . . . . . . . . . . . . . . . . Implementing PI Controller using Forward Difference Approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.5.1 Implementing locally . . . . . . . . . . . . . . . . . . . 7.5.2 Implementing virtually . . . . . . . . . . . . . . . . . . Implementing PID Controller using Backward Difference Approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.6.1 Implementing locally . . . . . . . . . . . . . . . . . . . 7.6.2 Implementing virtually . . . . . . . . . . . . . . . . . . Implementing PID Controller using Trapezoidal Approximation for Integral Mode and Backward Difference Approximation for the Derivative Mode . . . . . . . . . . . . . . . . . . . . . . . . 7.7.1 Implementing locally . . . . . . . . . . . . . . . . . . . 7.7.2 Implementing virtually . . . . . . . . . . . . . . . . . . Implementing PID Controller with Filtering using Backward Difference Approximation . . . . . . . . . . . . . . . . . . . . . . 7.8.1 Implementing locally . . . . . . . . . . . . . . . . . . . 7.8.2 Implementing virtually . . . . . . . . . . . . . . . . . . Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.9.1 Scilab code for serial communication . . . . . . . . . . 7.9.2 Scilab code for PI controller . . . . . . . . . . . . . . . 7.9.3 Scilab code for PID controller . . . . . . . . . . . . . . Two Degrees of Freedom (2-DOF) Controller 8.1 Introduction to 2-DOF Controller . . . . . . . . . . . . . . . . . 8.2 2-DOF Controller Design using the Pole Placement Method [5] . 3 101 102 102 103 103 105 107 109 109 110 111 112 113 114 115 116 117 118 119 120 122 122 124 125 126 126 127 129 135 135 138 8.3 8.4 8.5 8.6 8.7 8.8 9 2-DOF Pole Placement Controller Design and Implementation using SBHS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8.3.1 Procedure to calculate 2DOF parameters using scilab . Implementing 2DOF controller locally . . . . . . . . . . . . . . 8.4.1 Implementing 2-DOF Controller on SBHS, Virtually . . Performing pure simulation of 2DOF controller . . . . . . . . . Scilab Code for Local Experiment . . . . . . . . . . . . . . . . Scilab Code for Virtual Experiment . . . . . . . . . . . . . . . Scilab Codes Common for both Local and Virtual Experiments . PRBS Modeling and Implementation of Pole Placement Controller 9.1 PRBS Modelling . . . . . . . . . . . . . . . . . . . . . . . . . 9.1.1 Issues with Step Test and an Alternate Approach . . . . 9.2 Conducting PRBS Test on SBHS locally . . . . . . . . . . . . . 9.3 Conducting PRBS Test on SBHS, virtually . . . . . . . . . . . . 9.4 Determination of Discrete Time Transfer Function models . . . 9.5 Determination of First order Discrete time Transfer Function . . 9.6 Determination of Second order Discrete time Transfer Function . 9.7 Implementing 2DOF pole-placement controller using PRBS model, virtually . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.8 Implementing 2DOF pole-placement controller using PRBS model, locally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.9 Scilab Local codes . . . . . . . . . . . . . . . . . . . . . . . . 9.9.1 Identification codes . . . . . . . . . . . . . . . . . . . . 9.9.2 Controller codes . . . . . . . . . . . . . . . . . . . . . 9.10 Scilab Virtual codes . . . . . . . . . . . . . . . . . . . . . . . . 9.10.1 Identification codes . . . . . . . . . . . . . . . . . . . . 9.10.2 Controller codes . . . . . . . . . . . . . . . . . . . . . 10 Implementing Internal Model Controller for First Order System on a Single Board Heater System 10.1 IMC Design for Single Board Heater System . . . . . . . . . . 10.2 Step for Designing IMC for Stable Plant . . . . . . . . . . . . . 10.2.1 Implementing IMC locally . . . . . . . . . . . . . . . . 10.2.2 Implementing IMC virtually . . . . . . . . . . . . . . . 10.3 Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 141 143 144 144 145 145 166 169 175 175 176 178 179 181 182 184 186 188 188 188 193 197 197 203 207 207 209 213 213 214 11 Design and Implementation of Self Tuning PI and PID Controllers on Single Board Heater System 11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2.1 Why a Self Tuning Controller? . . . . . . . . . . . . . . 11.2.2 The Approach Followed . . . . . . . . . . . . . . . . . 11.2.3 Direct synthesis . . . . . . . . . . . . . . . . . . . . . . 11.3 Ziegler Nichols Tuning . . . . . . . . . . . . . . . . . . . . . . 11.4 Step Test Experiments and Parmeter Estimation . . . . . . . . . 11.4.1 Step Test Experiment . . . . . . . . . . . . . . . . . . . 11.4.2 Conventional Controller Design . . . . . . . . . . . . . 11.4.3 Self Tuning Controller Design . . . . . . . . . . . . . . 11.5 PID controller theory . . . . . . . . . . . . . . . . . . . . . . . 11.5.1 PI Controller . . . . . . . . . . . . . . . . . . . . . . . 11.5.2 PID Controller . . . . . . . . . . . . . . . . . . . . . . 11.5.3 Self Tuning Controller . . . . . . . . . . . . . . . . . . 11.6 Set Point Tracking . . . . . . . . . . . . . . . . . . . . . . . . 11.6.1 PI Controller Designed by Direct Synthesis . . . . . . . 11.6.2 PI Controller using Ziegler Nichols Tuning . . . . . . . 11.6.3 PID Controller using Ziegler Nichols Tuning . . . . . . 11.6.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 11.7 Disturbance Rejection . . . . . . . . . . . . . . . . . . . . . . . 11.7.1 PI Controller Designed by Direct Synthesis . . . . . . . 11.7.2 PI Controller using Ziegler Nichols Tuning . . . . . . . 11.7.3 PID Controller using Ziegler Nichols Tuning . . . . . . 11.7.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . 11.8 Conducting experiments locally . . . . . . . . . . . . . . . . . 11.9 Conducting experiments virtually . . . . . . . . . . . . . . . . . 11.10Scilab Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.10.1 Conventional Controller, local . . . . . . . . . . . . . . 11.10.2 Self Tuning Controller, local . . . . . . . . . . . . . . . 11.10.3 Conventional Controller, virtual . . . . . . . . . . . . . 11.10.4 Fan Disturbance in PI Controller . . . . . . . . . . . . . 11.10.5 Self Tuning Controller, local . . . . . . . . . . . . . . . 217 217 217 217 219 219 221 222 222 225 226 228 228 229 231 232 233 235 238 239 240 240 243 246 248 248 249 251 252 255 260 260 264 12 Model Predictive Control in Single Board Heater System using SCILAB 12.1 MPC theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268 268 5 12.2 Implementing MPC . . . . . . . . . . . . . . . . . . . . . . . 12.3 Experiments conducted to implement MPC . . . . . . . . . . 12.4 Sample run to implement MPC . . . . . . . . . . . . . . . . . 12.4.1 Positive Step Change to Set Point and Fan . . . . . . . 12.4.2 Negative Step Change to Set Point and Fan . . . . . . 12.5 Effect of Tuning parameters: Weighting factors, We and Wu . 12.5.1 Positive Step Change and (We, Wu)=(1,1) . . . . . . . 12.5.2 Positive Step Change and (We, Wu)=(10,10) . . . . . 12.5.3 Positive Step Change and (We, Wu)=(40,40) . . . . . 12.5.4 Negative Step Change and (We,Wu)=(1,1) . . . . . . . 12.5.5 Negative Step Change and (We, Wu)=(10,10) . . . . . 12.5.6 Negative Step Change and (We, Wu)=(40,40) . . . . . 12.6 For different We and Wu factors . . . . . . . . . . . . . . . . 12.6.1 We =100 and Wu = 2 . . . . . . . . . . . . . . . . . . 12.6.2 We = 2 and Wu = 100 . . . . . . . . . . . . . . . . . 12.6.3 We =10 and Wu = 100 . . . . . . . . . . . . . . . . . 12.6.4 We =100 and Wu = 10 . . . . . . . . . . . . . . . . . 12.6.5 Conclusion on Weighting factor experiments . . . . . 12.7 Effect of Control Horizon Paramter, q . . . . . . . . . . . . . 12.7.1 For positive step change in Set point and Fan speed . 12.7.2 For negative step change in Set point and Fan speed . . 12.7.3 Conclusion on the effect of Control Horizon parameter 12.8 Implementing MPC locally . . . . . . . . . . . . . . . . . . . 12.9 Implementing MPC virtually . . . . . . . . . . . . . . . . . . 12.10Conclusion for MPC project . . . . . . . . . . . . . . . . . . 12.11Acknowledgement . . . . . . . . . . . . . . . . . . . . . . . 12.12General Information on Experiments for this Project . . . . . . 12.13Scilab Code . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 271 272 272 275 277 278 280 282 284 286 288 289 290 292 294 295 298 298 299 305 310 311 311 312 313 313 315 List of Scilab Code 2.1 2.2 2.3 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 5.1 5.2 5.3 5.4 5.5 5.6 5.7 6.1 6.2 6.3 6.4 6.5 6.6 6.7 6.8 comm.sci . . . . init.sci . . . . . . plotting.sci . . . . label.sci . . . . . costf 1.sci . . . . firstorder.sce . . . costf 2.sci . . . . order 2 heater.sci secondorder.sce . ser init.sce . . . . step test.sci . . . stepc.sce . . . . . steptest.sci . . . . ramp test.sci . . . label.sci . . . . . cost.sci . . . . . . cost approx.sci . ramptest.sci . . . ramptest.sce . . . ramp virtual.sce . sine test.sci . . . sinetest.sce . . . sinetest.sci . . . . sine2.sce . . . . . lable.sci . . . . . bodeplot.sce . . . labelbode.sci . . . TFbode.sce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 30 31 58 59 60 61 62 62 63 64 64 65 75 76 76 77 77 78 78 92 94 94 95 96 96 97 98 6.9 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.13 8.14 8.15 8.16 8.17 8.18 8.19 8.20 8.21 8.22 8.23 8.24 8.25 8.26 9.1 9.2 comparison.sce . . ser init.sci . . . . . pi ta.sci . . . . . . pi bda.sci . . . . . pi fda.sci . . . . . pid bda.sci . . . . . pid ta bda.sci . . . pid filter.sci . . . . pid bda virtual.sce pid bda virtual.sci . twodof para.sce . . twodof.sci . . . . . start.sce . . . . . . cindep.sci . . . . . clcoef.sci . . . . . colsplit.sci . . . . . cosfil ip.sci . . . . indep.sci . . . . . . left prm.sci . . . . makezero.sci . . . . move sci.sci . . . . polsize.sci . . . . . polyno.sci . . . . . rowjoin.sci . . . . . seshft.sci . . . . . . t1calc.sci . . . . . . twodof para.sce . . twodof.sce . . . . twodof.sci . . . . . myc2d.sci . . . . . desired.sci . . . . . polmul.sci . . . . . polsplit3.sci . . . . pp im.sci . . . . . xdync.sci . . . . . zpowk.sci . . . . . ser init.sce . . . . . costfunction.sci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 126 127 127 128 129 130 131 132 133 145 151 153 153 154 155 156 156 158 161 161 162 162 163 164 165 166 167 168 169 170 170 171 172 173 174 188 189 9.3 9.4 9.5 9.6 9.7 9.8 9.9 9.10 9.11 9.12 9.13 9.14 9.15 9.16 9.17 9.18 9.19 9.20 9.21 10.1 10.2 10.3 10.4 11.1 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.10 11.11 11.12 11.13 11.14 11.15 optimize.sce . . . . . prbs.sci . . . . . . . prbstest.sci . . . . . . second order.sci . . . start.sce . . . . . . . prbs.sce . . . . . . . prbs pp.sci . . . . . . ser init.sce . . . . . . start.sce . . . . . . . twodof para.sce . . . costfunction.sci . . . optimize.sce . . . . . prbs.sci . . . . . . . prbstest.sci . . . . . . prbstest.sce . . . . . second order.sci . . . prbs.sce . . . . . . . prbscontrol-virtual.sci twodof para.sce . . . ser init.sce . . . . . . imc.sci . . . . . . . . imc virtual.sce . . . . imc virtual.sci . . . . ser init.sce . . . . . . pi bda dist.sci . . . . pi bda.sci . . . . . . pid bda dist.sci . . . pid bda.sci . . . . . . pi bda tuned dist.sci pi bda tuned.sci . . . pid bda tuned dist.sci pid bda tuned.sci . . pi bda dist.sci . . . . pi bda.sci . . . . . . pid bda dist.sci . . . pid bda.sci . . . . . . pi bda tuned dist.sci pi bda tuned.sci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 191 192 192 193 193 194 195 195 195 197 198 200 201 201 202 203 203 204 214 214 215 216 251 252 253 253 254 255 257 258 259 260 261 262 263 264 264 11.16 11.17 12.1 12.2 12.3 pid bda tuned dist.sci pid bda tuned.sci . . mpc.sci . . . . . . . mpc init local.sce . . mpc local.sci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265 266 315 315 316 Chapter 1 Block diagram explanation of Single Board Heater System Figure1.1 shows the block diagram of ‘Single Board Heater System’(SBHS). Microcontroller ATmega16 is used at the heart of the setup. The microcontroller can be programmed with the help of an In-system programmer port(ISP) available on the board. The setup can be connected to a computer via two serial communication ports namely RS232 and USB. A particular port can be selected by setting the jumper to its appropriate place. The communication between PC and setup takes place via a serial to TTL interface. The µC operates the Heater and Fan with the help of separate drivers. The driver comprises of a power MOSFET. A temperature sensor is used to sense the temperature and feed to the µC through an Instrumentation Amplifier. Some required parameter values are also displayed along with some LED indications. 1.1 Microcontroller Some salient features of ATmega16 are listed below: 1. 32 x 8 general purpose registers. 2. 16K Bytes of In-System Self-Programmable flash memory 3. 512 Bytes of EEPROM 4. 1K Bytes of internal Static RAM (SRAM) 11 Figure 1.1: Block Diagram 5. Two 8-bit Timer/Counters 6. One 16-bit Timer/Counter 7. Four PWM channels 8. 8-channel,10-bit ADC 9. Programmable Serial USART 10. Up to 16 MIPS throughput at 16 MHz Microcontroller plays a very important role. It controls every single hardware present on the board, directly or indirectly. It executes various tasks like, setting up communication between PC and the equipment, controlling the amount of current passing through the heater coil, controlling the fan speed, reading the temperature, displaying some relevant parameter values and various other necessary operations. 1.1.1 PWM for heat and speed control The Single Board Heater System contains a Heater coil and a Fan. The heater assembly consists of an iron plate placed at a distance of about 3.5mm from a 12 Figure 1.2: Pulse Width Modulation (A): On time is 90% of the total time period, (B): ON time is 10% of total time period nichrome coil. When current passes through the coil it gets heated and in turn raises the temperature of the iron plate. Altering the heat generated by the coil and also the speed at which the fan is operated, are the objectives of our prime interest. The amount of power delivered to the Fan and Heater can be controlled in various ways. The technique used here is called as PWM (abbreviation of Pulse Width Modulation)technique. PWM is a process in which the duty cycle of the square wave is modulated. Duty cycle = T ON T (1.1) Where T ON is the ON time of the wave corresponding to the HIGH state of logic and T is the total time period of the wave. Power delivered to the load is proportional to T ON time of the signal. This is used to control the current flowing through the heating element and also speed of the fan. An internal timer of the microcontroller is used to generate a square wave. The ON time of the square wave depends on a count value set in the internal timer. The pulse width of the waveform can be varied accordingly by varying this count value. Thus, PWM waveform is generated at the appropriate pin of the microcontroller. This generated PWM waveform is used to control the power delivered to the load (Fan and Heater). A MOSFET is used to switch at the PWM frequency which indirectly controls the power delivered to the load. A separate MOSFET is used to control the power delivered to each of the two loads. The timer is operated at 244Hz. 13 1.1.2 Analog to Digital conversion As explained earlier, the heat generated by the heater coil is passed to the iron plate through convection. The temperature of this plate is measured by using a temperature sensor AD590. Some of the salient features of AD590 include: 1. Linear current output: 1µA/K 2. Wide range: -55°C to +150°C 3. Sensor isolation from the case 4. Low cost The output of AD590 is then fed to the microcontroller through an Instrumentation Amplifier. The signal obtained at the output of the Instrumentation Amplifier is in analog form. It should be converted in to digital form before feeding as an input to the microcontroller. ATmega16 features an internal 8-channel , 10 bit successive approximation ADC (analog to digital converter) with 0-Vcc(0 to Vcc) input voltage range, which is used for converting the output of Instrumentation Amplifier. An interrupt is generated on completion of analog to digital conversion. Here, ADC is initialize to have 206 µs of conversion time . Digital data thus obtained is sent to the computer via serial port as well as for further processing required for the on-board display. 1.2 Instrumentation amplifier Instrumentation Amplifiers are often used in temperature measurement circuits in order to boost the output of the temperature sensors. A typical three Op-Amp Instrumentation amplifier is shown in the figure 1.3. The Instrumentation Amplifiers (IAs) are mostly preferred, where the sensor is located at a remote place and therefore is susceptible to signal attenuation, due to their very low DC offsets, high input impedance, very high Common mode rejection ratio (CMRR). The IAs have a very high input impedance and hence do not load the input signal source. IC LM348 is used to construct a 3 Op-Amp IA. IC LM348 contains a set of four Op-Amps. Gain of the amplifier is given by equation 1.2 ( ) 2R f R2 Vo = 1+ (1.2) V2 − V1 Rg R1 14 Figure 1.3: 3 Op-Amp Instrumentation Amplifier Figure 1.4: Jumper arrangement The value of Rg is kept variable to change the overall gain of the amplifier. The signal generated by AD590 is in µA/°K. It is converted to mV/°K by taking it across a 1 KΩ resistor. The °K to°C conversion is done by subtracting 273 from the °K result. One input of the IA is fed with the mV/°K reading and the other with 273 mV. The resulting output is now in mV/°C. The output of the IA is fed to the microcontroller for further processing. 1.3 Communication The set up has the facility to use either USB or RS232 for communication with the computer. A jumper is been provided to switch between USB and RS232. The voltages available at the TXD terminal of microcontroller are in TTL (transistor- 15 Figure 1.5: RS232 cable transistor logic). However, according to RS232 standard voltage level below -5V is treated as logic 1 and voltage level above +5V is treated as logic 0. This convention is used to ensure error free transmission over long distances. For solving this compatibility issue between RS232 and TTL, an external hardware interface IC MAX202 is used. IC MAX202 is a +5V RS232 transreceiver. 1.3.1 Serial port communication Serial port is a full duplex device i.e. it can transmit and receive data at the same time. ATmega16 supports a programmable Universal Synchronous and Asynchronous Serial Receiver and Transmitter (USART). Its baud rate is fixed at 9600 bps with character size set to 8 bits and parity bits disabled. 1.3.2 Using USB for Communication After setting the jumper to USB mode connect the set up to the computer using a USB cable at appropriate ports as shown in the figure 1.8. To make the setup USB compatible, USB to serial conversion is carried out using IC FT232R. Note that proper USB driver should be installed on the computer. 1.4 Display and Resetting the setup The temperature of the plate, percentage values of Heat and Fan and the machine identification number (MID) are displayed on LCD connected to the microcon16 Figure 1.6: Serial port Figure 1.7: USB communication 17 Figure 1.8: USB PORT Figure 1.9: Display troller. As shown in figure 1.9, numerals below TEMP indicate the actual temperature of the heater plate in °C. Numerals below HEA and FAN indicate the respective percentage values at which heater and fan are being operated. Numerals below MID corresponds to the device identification number. The set up could be reset at any time using the reset button shown in figure 1.10. Resetting the setup takes it to the standby mode where the heater current is forced to be zero and fan speed is set to the maximum value. Although these reset values are not displayed on the LCD display these are preloaded to the appropriate units. 18 Figure 1.10: Reset 19 Chapter 2 Performing a Local Experiment on Single Board Heater System This chapter explains the procedure to use Single Board Heater System locally with Scilab i.e. when you are physically accessing SBHS using your computer. An open loop experiment, step test is used for demonstrating this procedure. The process however remains the same for performing any other experiment explained in this document, unless specified otherwise. Hardware and Software Requirements For working with the Single Board Heater system, following components are required: 1. SBHS with USB cable and power cable. 2. PC/Laptop with Scilab software installed. Scilab can be downloaded from: http://www.scilab.org 3. FTDI Virtual Com Port driver corresponding to the OS on your PC. Linux users do not need this. The driver can be downloaded from: http://www.ftdichip.com/Drivers/VCP.htm 20 2.1 Using SBHS on a Windows OS This section deals with the procedure to use SBHS on a Windows Operating System. The Operating System used for this document is Windows 7, 32-bit OS. If you are using some other Operating System or the steps explained in section 2.1.1 are not sufficient to understand, refer to the official document available on the main ftdi website at www.ftdichip.com. On the left hand side panel, click on ’Drivers’. In the drop-down menu, choose ’VCP Drivers’. Then on the web page page, click on ’Installation Guides’ link. Choose the required OS document. We would now begin with the procedure. 2.1.1 Installing Drivers and Configuring COM Port After powering ON the SBHS and plugging in the USB cable to the PC (check the jumper settings on the board are set to USB communication) for the very first time, the Welcome to Found New Hardware Wizard dialog box will pop up. Select the option Install from a list or specific location. Choose Search for best driver in these locations. Check the box Include this location in the search. Click on Browse. Specify the path where the driver is copied as explained earlier (item no.3) and install the driver by clicking Next. Once the wizard has successfully installed the driver, the SBHS is ready for use. Please note that this procedure should be repeated twice. Now, the communication port number assigned to the computer port to which the Single Board Heater System is connected, via an RS232 or USB cable should be identified. For identifying this port number, right click on My Computer and click on Properties. Then, select the Hardware tab and click on Device Manager. The list of hardware devices will be displayed. Locate the Ports(COM & LPT) option and click on it. The various communication ports used by the computer will be displayed. If the SBHS is connected via RS232 cable, then look for Communications Port(COM1) else look for USB Serial Port. For RS232 connection, the port number mostly remains COM1. For USB connection it may change to some other number. Note the appropriate COM number. This process is illustrated in figure 2.1 Scilab must be installed on your computer. We recommend the use of scilab5.3.3. This is because all the codes are created and tested using scilab-5.3.3. These codes may very well work in higher versions of scilab but one cannot use the same codes back again in scilab-5.3.3. This is because a software is always backward compatible, never forward compatible. Scilab for windows or linux can be down21 Figure 2.1: Checking Communication Port number loaded from scilab.org. However, if scilab-5.3.3 for your OS is not available on scilab.org then one can download it from sbhs.os-hardware.in/downloads. Installation of scilab on windows is very straight-forward. After you download the .exe file one has to double click on it and proceed with the instructions given by the installer. All default options will work. However, note that scilab on windows requires internet connection during installation. 2.1.2 Steps to Perform a Local Experiment Go to sbhs.os-hardware.in/downloads. Let us take a look at the downloads page. There are two versions of the scilab code. One which can be used with SBHS locally i.e. when you are physically accessing SBHS using your computer and another to be used for accessing SBHS virtually. This section expects you to download the local version. On extracting the file that you will download, you will get a folder scilab codes local. We shall refer to this folder as local for simplicity. This folder will contain many folders named after the experiment. You will also find a directory named common-files. We are going to use the folder named Step test. 1. Launch Scilab from start menu or double click the Scilab icon on the desktop (if any). Before executing any scripts which are dependent on other files 22 or scripts, one needs to change the working directory of Scilab. This will set the directory path in Scilab from where the other necessary files should be loaded. To change the directory, click on file menu and then choose ”Change directory”. This can also be performed by typing cdfolder path. Change the directory to the folder Step test. There is another quicker way to make sure you are in the required working directory. Open the experiment folder. Double click on the scilab file you want to execute. Doing so will automatically launch scilab and also automatically change the working directory. To know your working directory at any time, execute the command pwd in the scilab console. 2. Next, we have to load the content of common-files directory. Notice that this directory is just outside the Step test directory. The common-files directory has several functions written in .sci files. These functions are required for executing any experiment. To load these functions type getd folder path. The folder path argument will be the complete path to common-files directory. Since this directory is just outside our Step test directory, the command can be modified to getd ..\common files So now we have all functions loaded. 3. Next we have to load the serial communication toolbox. For doing so we have to execute the loader.sce file present in the common-files directory. To do so execute the command exec ..\common files\loader.sce or exec folder path\loader.sce. 4. Next, click on editor from the menu bar to open the Scilab editor or simply type editor on the Scilab console and open the file ser init.sce. Change the value of the variable port2 to the COM number identified for the connected SBHS. For example, one may enter ’COM5’ as the value for port2. Notice that there is no space between COM and 5 and COM5 is in single quotes. Keep all other parameters untouched. Execute this .sce file by clicking on the execute button available on the menu bar of scilab editor window. The message COM Port Opened is displayed on successful implementation. If there are any errors, reconnecting the USB cable and/or restarting Scilab may help. 5. Next we have to load the function for the step test experiment. This function is written in step test.sci file. Since we do not have to make any 23 changes in this file we can directly execute it from scilab console without opening it. Run the command exec step test.sci in scilab console. The results are illustrated in figure 2.2. 6. Next, type Xcos on the Scilab console or click on Applications and select Xcos to open Xcos environment. Load the step test.xcos file from the File menu. The Xcos interface is shown in figure 2.4. The block parameters can be set by double clicking on the block. To run the code click on Simulation menu and click on Start. After executing the code in Xcos successfully the plots as shown in figure 2.5 will be generated. Note that the values of fan and heater given as input to the Xcos file are reflected on the board display. 7. To stop the experiment click on the Stop option on the menu bar of the Xcos environment. All of the activities mentioned above, from getd ..\common files untill starting the xcos simulation, are coded in a file named start.sce. Executing this file will do all necessary things automatically with just click of a button. This file however assumes three things. These are 1. The location of common-files directory is not changed 2. The current working directory is correct 3. The port number mentioned in ser init.sce is correct 2.2 Using Single Board Heater System on a Linux System This section deals with the procedure to use SBHS on a Linux Operating System. The Operating System used for this document is Ubuntu 12.04. For Linux users, the instructions given in section 2.1 hold true with a few changes as below: On a linux system, Scilab-5.3.3 can be either installed from available package manager (synaptic in case of Ubuntu) or its portable version can be downloaded from scilab.org or http://sbhs.os-hardware.in/downloads. If installed from a package manager then scilab can be launched by opening a terminal (Alt+Ctrl+T) and executing the command sudo scilab. If one downloads 24 Figure 2.2: Expected responses seen on the console Figure 2.3: Executing script files 25 Figure 2.4: Xcos Interface Figure 2.5: Plot obtained after executing step test.xcos 26 Figure 2.6: Checking the port number in linux (1) the portable version then first the file has to unpacked. This can be done by right clicking on it and choosing Extract here. Then one has to open the terminal and change the directory to scilab/bin. Then the command sudo ./scilab must be executed to launch scilab. Note that scilab must always be launched with sudo permisions to be able to communicate with the SBHS. FTDI COM port drivers are not required for connecting the SBHS to the PC. After plugging in the USB cable to the PC, check the serial port number by typing ls /dev/ttyUSB* on the terminal, refer Fig.2.6. Note down this number and change the value of the variable port1 inside the ser init.sce file, refer Fig.2.3. Except for these changes rest all of the steps mentioned in Section 2.1.2 can be followed. 2.3 Summary of procedure to perform a local experiment This section sumarrizes and only lists the required commands/activities to be done in the given order to do a local experiment. It doesnot explain the expected results etc. The procedure is common for both windows as well as linux users. However, make sure you have reffered to the earlier sections of this chapter for clarity. 1. Step1: Change/ensure scilab working directory to Step test. Command pwd can be used to know the present working directory of scilab 2. Step2: Load the functions available in common files directory by executing the command getd ..\common files 27 3. Step3: Load the serial communication toolbox by executing the command exec ..\common files\loader.sce 4. Step4: Ensure correct communication port number in the ser init.sce file and execute it. Execution can be done using the command exec ser init.sce 5. Step5: Load step test function by executing command exec step test.sci 6. Step6: Launch Xcos code for step test and execute it. This can be done using the command xcos step test.xcos 7. Step7: Execute this xcos code by clicking on the start button available on the menubar of xcos window. Let the execution run for sufficient time, until the output reaches a steadstate or untill sufficient data is collected. Note that advance users can always make use to start.sce file for quickly performing the experiments. 2.4 Scilab Code under common files Scilab Code 2.1 comm.sci 1 2 3 m=1; f u n c t i o n [ temp ] = comm ( h e a t , f a n ) global h e a t d i s p fandisp tempdisp sampling time m name h a n d l f i l e n a m e 4 5 6 7 8 9 10 11 12 13 14 i f h e a t <0 h e a t =0 end i f h e a t >100 h e a t =100 end i f f a n <0 f a n =0 end i f f a n >100 28 f a n =100 15 16 end 17 18 w r i t e s e r i a l ( handl , a s c i i (254) ) ; w r i t e s e r i a l / / Input Heater , a c c e p t s s t r i n g s ; c o n v e r t 254 i n t o so i t s s t r i n g e q u i v a l e n t 19 20 21 22 23 w r i t e s e r i a l ( handl w r i t e s e r i a l ( handl w r i t e s e r i a l ( handl w r i t e s e r i a l ( handl sleep (100) ; , , , , ascii ascii ascii ascii ( heat ) ) ; (253) ) ; ( fan ) ) ; (255) ) ; / / Input / / To Fan read Temp Read s e r i a l 24 25 temp = a s c i i ( r e a d s e r i a l ( h a n d l ) ) ; r e t u r n s a string , / / so c o n v e r t i t s i t to i n t e g e r ( a s c i i ) e q u i v a l e n t 26 temp = temp ( 1 ) + 0 . 1 * temp ( 2 ) ; decimal eg : 27 28 29 30 / / c o n v e r t p o i n t s 40.7 e p o c h= g e t d a t e ( ’ s ’ ) ; dt=getdate ( ) ; ms= d t ( 1 0 ) ; e p o c h =( e p o c h * 1 0 0 0 )+ms ; 31 32 A = [m, h e a t , f a n , temp , e p o c h ] ; 33 34 f d f h = f i l e ( ’ open ’ , f i l e n a m e , ’ unknown ’ ) ; 35 36 f i l e ( ’ l a s t ’ , fdfh ) 37 38 w r i t e ( f d f h , A, ’ ( 7 ( f 1 5 . 1 , 3 x ) ) ’ ) ; 39 40 f i l e ( ’ close ’ , fdfh ) ; 41 29 to temp with 42 43 m=m+1; endfunction Scilab Code 2.2 init.sci 1 2 3 global filename m function s t a t u s = i n i t ( port ) global handl filename 4 5 OS = g e t o s ( ) ; 6 7 8 9 10 11 12 13 14 15 i f OS == s t r i n g ( ’ L i n u x ’ ) port num = p o r t ( 1 ) ; handl = o p e n s e r i a l ( port num , ” 9600 , n , 8 , 0 ” ) else port val = port (2) ; num=p a r t ( p o r t v a l , 4 : $ ) ; p o r t n u m = s t r t o d ( num ) ; handl = o p e n s e r i a l ( port num , ” 9600 , n , 8 ” ) end 16 17 18 19 20 21 i f ( a s c i i ( h a n d l ) ˜= [ ] ) s t a t u s = s t r i n g ( ’COM PORT OPENED ’ ) else s t a t u s = s t r i n g ( ’ERROR : Check p o r t number o r USB connection ’ ) end 22 23 m = 1; 24 25 26 27 28 29 30 31 dt = getdate ( ) ; year = dt (1) ; month = d t ( 2 ) ; day = d t ( 6 ) ; hour = dt ( 7 ) ; minutes = dt (8) ; seconds = dt (9) ; 32 30 33 34 35 36 f i l e 1 = s t r c a t ( s t r i n g ( [ y e a r month day h o u r m i n u t e s s e c o n d s ] ) , ’− ’ ) ; string txt ; filename = strcat ([ file1 , ” txt ” ] , ’ . ’ ) ; 37 38 endfunction Scilab Code 2.3 plotting.sci 1 f u n c t i o n [ ] = p l o t t i n g ( var , low lim , h i g h l i m ) 2 3 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p sampling time m 4 5 6 7 8 9 10 t i m e T i t l e = ”No . o f s a m p l e s w i t h s a m p l i n g t i m e = ” +string ( sampling time ) i f low lim ˜=[] & high lim ˜=[] heat min = low lim (1) fan min = low lim (2) temp min = l o w l i m ( 3 ) time min = low lim (4) 11 heat max = high lim ( 1 ) fan max = h i g h l i m ( 2 ) temp max = h i g h l i m ( 3 ) time max = h i g h l i m ( 4 ) 12 13 14 15 16 17 18 19 20 21 else heat min = 0 fan min = 0 temp min = 20 time min = 0 22 23 24 25 26 h e a t m a x = 100 f a n m a x = 100 temp max = 100 t i m e m a x = 1000 31 27 end 28 29 30 31 32 33 34 i f l e n g t h ( v a r ) ==3 heat = var (1) ; fan = var (2) ; temp = v a r ( 3 ) ; 35 36 37 38 39 h e a t d i s p =[ h e a t d i s p ; h e a t ] ; subplot (311) ; x t i t l e ( ” ” , t i m e T i t l e , ” Heat i n p e r c e n t a g e ” ) p l o t 2 d ( h e a t d i s p , r e c t =[ t i m e m i n , h e a t m i n , time max , h e a t m a x ] , s t y l e =1) 40 41 42 43 44 f a n d i s p =[ f a n d i s p ; f a n ] ; subplot (312) ; x t i t l e ( ” ” , t i m e T i t l e , ” Fan i n p e r c e n t a g e ” ) p l o t 2 d ( f a n d i s p , r e c t =[ t i m e m i n , f a n m i n , time max , f a n m a x ] , s t y l e =2) 45 46 47 48 49 t e m p d i s p =[ t e m p d i s p ; temp ] ; subplot (313) x t i t l e ( ” ” , t i m e T i t l e , ” T e m p e r a t u r e ( deg celcius )”) p l o t 2 d ( t e m p d i s p , r e c t =[ t i m e m i n , temp min , time max , temp max ] , s t y l e =5) 50 51 52 e l s e i f l e n g t h ( v a r ) == 4 53 54 55 56 57 heat = var (1) ; fan = var (2) ; temp = v a r ( 3 ) ; s e t p o i n t = var (4) ; 58 59 60 h e a t d i s p =[ h e a t d i s p ; h e a t ] ; subplot (311) ; 32 61 62 x t i t l e ( ” ” , t i m e T i t l e , ” Heat i n p e r c e n t a g e ” ) p l o t 2 d ( h e a t d i s p , r e c t =[ t i m e m i n , h e a t m i n , time max , h e a t m a x ] , s t y l e =1) 63 64 65 66 67 f a n d i s p =[ f a n d i s p ; f a n ] ; subplot (312) ; x t i t l e ( ” ” , t i m e T i t l e , ” Fan i n p e r c e n t a g e ” ) p l o t 2 d ( f a n d i s p , r e c t =[ t i m e m i n , f a n m i n , time max , f a n m a x ] , s t y l e =2) 68 69 70 71 72 73 74 t e m p d i s p =[ t e m p d i s p ; temp ] ; s e t p o i n t d i s p =[ s e t p o i n t d i s p ; s e t p o i n t ] subplot (313) x t i t l e ( ” ” , t i m e T i t l e , ” T e m p e r a t u r e ( deg celcius )”) p l o t 2 d ( t e m p d i s p , r e c t =[ t i m e m i n , temp min , time max , temp max ] , s t y l e =5) p l o t 2 d ( s e t p o i n t d i s p , r e c t =[ t i m e m i n , temp min , time max , temp max ] , s t y l e =1) 75 76 77 end endfunction 33 Chapter 3 Using Single Board Heater System, Virtually! 3.1 Introduction to Virtual Labs at IIT Bombay The concept of virtual laboratory is a brilliant step towards strengthening the education system of an university/college, a metropolitan area or even an entire nation. The idea is to use the ICT i.e. Information and Communications Technology, mainly the Internet for imparting education or exchange of educational information. Virtual Laboratory mainly focuses on providing the laboratory facility, virtually. Various experimental set-ups are hooked up to the internet and made available to use for the external world. Hence, anybody can connect to that equipment over the internet and carry out various experiments pertaining to it. The beauty of this idea is that a college who cannot afford to have some experimental equipments can still provide laboratory support to their students through virtual lab, and all that will cost it is a fair Internet connection! Moreover, the laboratory work does not ends with the college hours, one can always use the virtual lab at any time and at any place assuming the availability of an internet connection. A virtual laboratory for SBHS is launched at IIT Bombay. Here is the url to access it: vlabs.iitb.ac.in/sbhs/. A set of 36 SBHS are made available to use over the internet 24× 7. These individual kits are made available to the users on hourly basis. We have a slot booking mechanism to achieve this. Since there are 36 SBHS connected with an hours slot for 24 hrs a day, we have 864 one hour slots a day. This means that 864 individual users can access the SBHS in a day for an hour. 34 Figure 3.1: SBHS virtual laboratory with remote access using LabVIEW This also means that up to 6048 users can use the SBHS for an hour in a week and 181440 in a month! A web page is hosted which is the first interface to the user. The user registers/logs in himself/herself here. The user is also supposed to book a slot for accessing the SBHS. A database server maintains a record of the data generated through the web interface. A python script is hosted on the server side and it helps in connecting the user with the corresponding SBHS placed remotely. A free and open source scientific computing Software, Scilab, is used by the user for implementing the experiment on SBHS, in terms of simple Scilab coding. 3.2 Evolution of SBHS virtual labs In [4], the control algorithm is implemented at the server end and the remote student just keys in the parameters, as shown in Figure 3.1. LabVIEW was used for the implementation of the same. The server end consisted of a computer connected with an SBHS with a full blown copy of LabVIEW installed on it. The client has a LabVIEW run time engine available for free download from the National Instruments website. A few LabVIEW algorithms/experiments were hosted on the server. The client accesses these algorithm/experiment over the Internet using a web browser by entering appropriate parameters. 35 Figure 3.2: SBHS virtual laboratory with remote access and live data sharing using LabVIEW It was realized that the learning experience is not complete for this structure. This is because the server hosts some pre-built LabVIEW algorithms and a user can only access these few algorithms. The user can in no way change the program and can only input experimental parameters. Hence, we came up with a new architecture as shown in the Figure 3.2 that used full blown copies of LabVIEW at both server and client ends. This idea uses the DataSocket technology of LabVIEW. Since now the client is having a complete LabVIEW installation on his/her computer she can now implement her own algorithms. Thus this architecture did provide a complete learning experience to the students. There are some shortcomings as well: • LabVIEW is expensive and students may not be able to afford to buy it. It is also prohibitively expensive for the Government to distribute it. • We used the LabVIEW version 8.04, which had restricted scripting language. It was tedious to create new control algorithms in it. This made us shift to free and open source (FOSS) software. We replaced LabVIEW with Java and Scilab as shown in Figure 3.3. Scilab at the server end is 36 Figure 3.3: SBHS virtual laboratory using open source software used for communicating with SBHS. Scilab at the client end is used for implementing the algorithms. Java is used at both the server as well as client end for communication over the Internet thereby connecting the client with the server. For the above solution, we need a dedicated copy of scilab running at the server end for every SBHS. One way to do this is to host it on multiple computers with unique IPs. Hence the number of SBHS we want to host requires as many computer’s and public IPs thereby making it expensive. Moreover, it also limits its scalability. The other way to do this is to host multiple java and scilab servers on the same computer. Hosting many copies of Scilab simultaneously requires a powerful computer for the server. For these reasons we decided to take scilab off the server computer and to use java alone to communicate with the SBHS directly. Java also communicates with the client computer. We connected seven SBHS systems to a USB port through a serial port hub. This architecture was implemented on a Windows Operating System. We faced the following difficulties in this solution. • When we connected more than one serial hub to a PC, the port ID could not be retrieved correctly. Port ID information is required if we want a student to use the same SBHS for all their experiments during different sessions. • The experiments required time stamping of the data communicated to and from the server. But this time stamping was not linear and suffered instability. 37 Figure 3.4: Virtual control lab hardware architecture This made us to completely switch to FOSS with Ubuntu Linux as the OS and is the current structure of the Virtual lab as shown in Figure 3.6 3.3 Current Hardware Architecture The current hardware architecture of the virtual single-board heater system lab involves 36 single-board heater systems connected to the server via multiple 7 and 10-port USB hubs. The server computer is connected to a high speed internetwork and has enough processing capability to host data acquisition, database, and web servers. It has been successfully tested for the undergraduate Process Control course and the graduate Digital Control and Embedded systems courses conducted at IIT Bombay as well as few workshops over the internet. Currently, this architecture is integrated with a cameras on each SBHS to facilitate live video streaming. This gives the user a feel of remote hands-on. 38 Figure 3.5: Home page of SBHS V Labs 3.4 Current Software Architecture The current software architecture of this virtual SBHS control lab is shown in Figure 3.6. The server computer runs Ubuntu Linux 12.04.2 OS. It hosts a ApacheMySQL server. The SBHS server is based on Python-Django framework and is linked to Apache server using Apache’s WSGI module. The MySQL database server has the details of all the registered users, their slot details, authentication keys to allow remote access, etc. As shown in Figure ??, the Python-Django server has pages for registration, login, slot booking etc. [9]. On the client end, control algorithms are running in Scilab and a python based client application communicates with virtual labs server over the Internet. The steps to be performed before and during each experiment are explained next. 3.5 Conducting experiments using the Virtual lab This section explains the procedure to use Single Board Heater System remotely using Scilab i.e. when you are accessing SBHS remotly using your computer over 39 Client Computer Server Computer SBHS 1 SBHS 2 SBHS 36 Python based Client MySQL Database Server USB HUBS scilabread file Python Django Server scilabwrite file Scilab Apache Web Server Internet Web Browser Figure 3.6: Current Architecture of SBHS Virtual Labs the virtual labs platform. An open loop experiment, step test is used for demonstrating this procedure. The process however remains the same for performing any other experiment explained in this section, unless specified otherwise. Let us first see the required files to be downloaded and installations to be done. Scilab is required to be installed on your computer. Please refer to Section 2.1.1 and Section 2.2 for the procedure to install scilab on Windows and Linux system, respectively. SBHS scilab code for your OS, under the section SBHS Virtual Code, must be downloaded from http://sbhs.os-hardware.in/downloads. For example, if you are using a 32-bit linux operating system then you should download the file SBHS Scilab codes for Linux - (32 bit). The code downloaded will be in zip format. After the zip is unpacked, you will see scilab experiment folders such as Step test, Ramp Test, pid controller etc. We will be using the Step test folder. Do not alter the directory structure. If you want to copy or move an experiment outside the directory then make sure you also copy the common files folder. The common files folder must always be one directory outside the experiment folder. Now given that you have scilab installed and working and the required scilab code downloaded, let us see the step-by-step procedure to do a remote experiment. 40 Figure 3.7: Show Video 3.5.1 Registration, Login and Slot Booking Go to the website sbhs.os-hardware.in and click on the Virtual labs link available on the left hand side. The home page of Virtual labs is illustrated in Fig 3.5. If you are a first time user, click on the link Login/Register. Fill out the registration form and submit it. If the registration form is submitted successfully, you will receive an activation link on your registered Email id. Use this link to complete the registration process. If you skip this step you will not be able to login. Registration is a one time process and need not be repeated more than once. After completing registration login with your username and password. You should now get the options to Book Slot, Delete Slot etc. View/Delete slot option allows you to delete your booked slots. This option however will work only for slots booked for the future. You cannot delete a past or the current slot. Download log files option gives you the facility to download your experiment log files. Clicking on it will give you a list of all of the experiments you had performed. Show video option can be used to see the live video feed of your SBHS. Web cameras are mounted on every SBHS. You can see the display of your SBHS as shown in Fig. 3.7. Clicking on the Book slot option will allow you to book an experiment time slot. Slots are of 55 minutes duration. Click on the Book slot option. If the current slot is free, Book now option will appear. Click on it. Else you have to book an advance slot for the next hour or any other future time using the calender that appears on this page. There is a limit to how many slots one can book in a day. We are allowing only two non-consecutive slots, per user, to be booked in a day. However, there is no limit to how many current slots you book and use. Book an 41 Figure 3.8: Slot booking experiment slot. Once you successfully book a slot a Slot booked successfully message highlighted in green color will appear on the top side. This is shown in Fig. 3.8. It will automatically take you to the View/Delete slot page. 3.5.2 Configuring proxy settings and executing python based client After booking a slot, the web activity is over. You may close the web browser unless you need it open to see live video feed of your SBHS. The next step is to establish the communication link between the server and your computer. A python based application is created which handles the network communication. Let us first see how to do the proxy settings if you are behind a proxy network. Open the folder common files. Open the file config. This files contains various arguments whose values must be eneterd to configure proxy. Do not change the contents of config file if • You are accessing from inside IIT Bombay OR • You are accessing from outside IIT Bombay and using an open network 42 such as at home OR using a mobile internet Change the contents of config file if • You are outside IIT Bombay and using a proxy network such as at an institute, office etc. If you have to put the proxy details, first change the argument use proxy = Yes (Y should be capital in Yes and N should be capital in No). Fill in the other details as per your proxy network. If your proxy network allows un-authenticated login then make the argument proxy username and proxy password blank. This proxy setting has to done only once. Open the Step test folder. Double click on the file run. This will open the client application as shown in Fig. 3.9. Note that for first time execution, it will take a minute to open the client application. It will show various parameters related to the experiment such as SBHS connection, Client version, User login and Experiment status. The green indicators show that the corresponding activity is correct or functional. Here it says that the Client application is been able to connect to the server and the client version being used is the latest. The User login and Experiment status is showing red and will turn green after a registered username and password is entered. If the SBHS is offline or there are some other issues, the corresponding error will be displayed and the respective indicator will turn red. Enter your registered username and password and press login. You should get the message Ready to execute scilab code. The application also shows the value of iteration, heat, fan, temperature and time remaining for experimentation. It also shows the name of log file created for the experiment. 3.5.3 Executing scilab code Inside the StepTest folder, if on a windows system, double click on the file stepc.sce. This should automatically launch scilab and also open the stepc.sce in the scilab editor. It will also automatically change the scilabs working directory. On a linux system, launch scilab manually. Then change the scilab working directory to the folder StepTest. This can be done by clicking on File menu and then selecting change current directory. Next, execute the command getd ../common files. Scilab command getd is used to load all functions defined in all .sci files inside a specified folder. Here we have some important function files inside the ../common files directory. Executing this command will load all of 43 Figure 3.9: Python Client 44 Figure 3.10: stepc.sce file the functions that the experiment needs. Open the file stepc.sce using the Open option inside File menu. The file is shown in Fig. 3.10 The experiment sampling time can be set inside the stepc.sce file. You may want to change it to a higher value if your network is slow. The default value of 1 second works fine in most cases. On the menu bar, click on Execute option and choose option file with echo. This will execute the scilab code. If the network is working fine, an xcos diagram will open automatically. If it doesnt open then see the scilab console for error messages. If you get a No network connection error message then try executing the scilab code again. The xcos diagram is for the step test experiment as shown in Fig. 3.11. You can set the value of the heat and fan. Keep the default values. On the menu bar of the xcos window, click on start button. This will execute the xcos diagram. If there is no error, you will get a graphic window with three plots. It will show the value of Heat in % Fan in % and ..temperature in degree celcius as shown in Fig. 3.12. After sufficient time of experimentation click on the stop button to stop the experiment. Go to the StepTest folder. Here you will find a logs folder. This folder will have another folder named after your username. It will have the log file for your experiment. Read the log file name as YearMonthDate hours minutes seconds.txt. This log file contains all the values 45 Figure 3.11: Xcos for step test of heat fan and temperature. It can be used for further analysis. 3.5.4 Conducting experiments over virtual labs through ARM based computer This section talks about accessing the SBHS virtual labs using an ARM based computer. These ARM based computers could be netbooks, laptops or even tablets running a Linux operting system. Let us see the additional steps to be follwed for using over an ARM computer. 1. The scilab codes are separate for windows, linux and ARM based linux. Download the scilab code from http://sbhs.os-hardware.in/downloads. You need to download the file against the label SBHS Scilab codes for ARM under the SBHS Virtual Code section. The name of the file downloaded will be sbhs codes arm. This will be a zip file. Extract its connets in order to use it. 2. Open a terminal by pressing the Alt+Ctrl+T keys together. Change the directory to sbhs codes arm directory using the cd command. For example, 46 Figure 3.12: Output of Step Test if the sbhs codes arm folder is saved on the desktop, the command will look like cd Desktop/sbhs codes arm 3. Execute the command chmod +x install.sh 4. Then execute the command ./install.sh. It may ask you to enter the sudo password. Hence, this step requires you to know the sudo password of the computer you are using. 5. With these steps done, now follow the instructions explained in Section 3.5 throughout its subsections. Note that you need NOT download SBHS Scilab codes for Linux - (32 bit) file while refering to this section. This is because all scilab codes are included inside the sbhs codes arm directory 3.6 Summary This section summarizes the process to perform an experiment on SBHS using virtual lab interface. This section assumes that the user has already created an account and booked a slot as explained in section 3.5.1. It also assumes that the proxy settings are already done as explained in section 3.5.2. The user should follow these steps within the booked slot time. • Step1: Open the StepTest experiment directory • Step2: Double-click on the file run. Expect the SBHS cient application to open. 47 • Step3: Enter the username and password inside the SBHS cient application and press login button. Expect the message Ready to execute scilab code • Step4: Switch to the StepTest experiment directory and double-click on the file stepc.sce. This will launch scilab and also open the file stepc.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to StepTest and then open the stepc.sce file in the scilab editor. • Step5 Switch to the scilab console and execute the command getd ../ common files • Step6: Execute the file stepc.sce. Expect the step test xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. • Step7: Execute the step test xcos daiagram. You may change the input parameters, if required, before executing. Expect a plot window to open automatically showing three graphs. • Step8: Stop the Xcos simulation after the experiment is completed properly. 48 Chapter 4 Identification of Transfer Function of a Single Board Heater System through Step Response Experiment The aim of this experiment is to perform step test on a Single Board Heater System and to identify system transfer function using step response data. The target group is anyone who has basic knowledge of control engineering. We have used Scilab and Xcos as an interface for sending and receiving data. Xcos diagram is shown in figure 4.1. Heater current and fan speed are the two inputs for this system. They are given in percentage of maximum. These inputs can be varied by setting the properties of the input block’s properties in Xcos. The plots of their amplitude versus number of collected samples are also available on the scope windows. The output temperature profile, as read by the sensor, is also plotted. The data acquired in the process is stored on the local drive and is available to the user for further calculations. In the step test.xcos file, open the heater block’s parameters to apply a step change of say 10 percent to the heater at operating point of 30 percent of heater after 250 seconds. The block parameters of the step input block will have Step time = 250, Initial value = 30 and Final value = 40. Keep the fan input constant at 50 percent. Start the experiment and let it continue until you see the temperature reach the steady state. The step test data file will be saved in Step test folder. The name of the file will be the date and time at which the experiment was conducted. A sample data file is provided in the same folder. The sample data file is named as step-data-local.txt and step-data-virtual.txt. Refer to the one de49 Figure 4.1: Xcos for this experiment 1.0 2.0 . . 820.0 821.0 30.0 30.0 40.0 40.0 50.0 50.0 50.0 50.0 29.3 29.5 1412400132192.0 1412400133044.0 37.0 37.2 1412400950197.0 1412400951202.0 Table 4.1: Step data obtained after performing local Step Test 50 Figure 4.2: Graph shows heater current, fan speed and output temperature pending on wheather you are performing a local or a virtual experiment. Referring to the data file thus obtained as shown in table 4.2, the first column in this table denotes samples. The second column in this table denotes heater in percentage. It starts at 30 and increases with a step size of 10 units. The third column denotes the fan in percentage. It has been held constant at 50 percent. The fourth column refers to the value of temperature. The fifth column denotes time stamp. The virtual data file will havel four time stamp columns apart from first 3 columns. These four time stamp columns are client departure, server arrival, server departure and client arrival. These can be used for advanced control algorithms. These additional time stamps exist in virtual mode because of the presense of network delay. 4.1 Conducting Step Test on SBHS locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is exactly the same for this section. The response is as shown in figure 4.2. The output data file is as shown 51 Figure 4.3: Step test Virtual experiment response in Table 4.2 4.2 Conducting Step Test on SBHS, virtually The detailed procedure to perform a local experiment is explained in Chapter3. A summary of the same is provided in section 3.5 It is exactly the same for this section. The virtual experiment response is shown in figure 4.3. The corresponding data file is shown in table 4.2. The time stamps shown are cut short for better viewing. This data file can be found in StepTest folder for virtual experiments. The name of this file is step-data-virtual.txt. 52 0 0 100 29.30 14...8080 14...8955 14...8993 14...8158 0.10000E+01 1 30 50 29.00 14...9364 14...0246 14...0263 14...9442 0.10000E+01 . . 711 40 50 36.20 14...9375 14...0280 14...0297 14...9437 0.71100E+03 712 40 50 36.10 14...0370 14...2673 14...2691 14...1834 0.71200E+03 Table 4.2: Step data obtained after performing virtual Step Test 4.3 Identifying First Order and Second Order Transfer Functions In this section we shall determine the first and second order transer function model using the data obtained after performing step test experiment. Please note that this procedure is common for data obtained using both local and virtual experiments. 4.3.1 Determination of First Order Transfer Function Identification of the transfer function of a system is important as it helps us to represent the physical system mathematically. Once the transfer function is obtained, one can acquire the response of the system for various inputs without actually applying them to the system. Consider the standard first order transfer function given below C(s) R(s) 1 G(s) = τs + 1 G(s) = (4.1) (4.2) Rewriting the equation, we get C(s) = R(s) τs + 1 (4.3) A step is given as input to the first order system. The Laplace transform of a step function is 1s . Hence, substituting R(s) = 1s in equation 4.3, we obtain C(s) = 1 1 τs + 1 s 53 (4.4) Solving C(s) using partial fraction expansion, we get C(s) = 1 1 − s s+ 1 τ (4.5) Taking the Inverse Laplace transform of equation 4.5, we get −t c(t) = 1 − e τ (4.6) From the above equation it is clear that for t=0, the value of c(t) is zero. For t= ∞, c(t) approaches unity. Also, as the value of ‘t ’becomes equal to τ, the value of c(t) becomes 0.632. τ is called the time constant and represents the speed of response of the system. But it should be noted that, smaller the time constantfaster the system response. By getting the value of τ, one can identify the transfer function of the system. Consider the system to be first order. We try to fit a first order transfer function of the form G(s) = K τs + 1 (4.7) to the Single Board Heater System. Because the transfer function approach uses deviation variables, G(s) denotes the Laplace transform of the gain of the system between the change in heater current and the change in the system temperature. Let the change in the heater current be denoted by ∆u. We denote both the time domain and the Laplace transform variable by the same lower case variable. Let the change in temperature be denoted by y. Let the current change by a step of size u. Then, we obtain the following relation between the current and the temperature. y(s) = G(s)u(s) K ∆u y(s) = τs + 1 s (4.8) (4.9) Note that ∆ u is the height of the step and hence is a constant. On inversion, we obtain −t y(s) = K[1 − e τ ]∆u 54 (4.10) 4.3.2 Procedure 1. Download the Analysis folder from the sbhs website. It will be available under downloads section. Download the file for SBHS Analysis Code (local & virtual). The name of the file is scilab codes analysis. The download will be in zip format. Extrat the downloaded zip file. You will get a folder scilab codes analysis. 2. Open the scilab codes analysis folder and then locate and open the folder Step Analysis. 3. Open the Kp-tau-order1 folder. 4. Copy the step test data file to the folder Kp-tau-order1. 5. Change the Scilab working directory to Kp-tau-order1 folder under Step Analysis folder. 6. Open the file firstorder.sce in scilab editor and enter the name of the data file (with extention) in the filename field. 7. Save and run this code and obtain the plot as shown in figure 4.4. This code uses the routines label.sci and costf 1.sci The results presented are obtained for the data file step-data-virtual.txt. This data file is present under the Step Test directory for local experiments.The plot thus obtained is reasonably good. See the Scilab plot to get the values of τ and K. The figure 4.4 shows a screen shot of the same. We obtain τ = 58.64, K = 0.23. The transfer function obtained here is at the operating point of 30 percentage of heat. If the experiment is repeated at a different operating point, the transfer function obtained will be different. The gain will correspondingly be more at a higher operating point. This means that the plant is faster at higher temperature. Thus the transfer function of the plant varies with the operating point. Let the transfer function we obtain in this experiment be denoted as G s . We obtain G s (s) = 0.23 58.64s + 1 55 (4.11) Figure 4.4: Output of the Scilab code firstorder.sce for data file step-data-local.txt 4.4 Determination of Second Order Transfer Function In this section, we explore the efficacy of a second order model of the form G(s) = K (τ1 s + 1)(τ2 s + 1) (4.12) The response of the system to a step input of height ∆u is given by y(s) = K ∆u (τ1 s + 1)(τ2 s + 1) s (4.13) Splitting into partial fraction expansion, we obtain y(s) = K τ1 τ2 s+ 1 τ1 1 ! s+ 1 τ2 != 56 A + s B 1 s+ τ1 + C s+ 1 τ2 Through Heaviside expansion method, we determine the coefficients: A=K Kτ1 τ1 − τ2 Kτ2 C= τ1 − τ2 B=− On substitution and inversion, we obtain " # 1 −t/τ1 −t/τ2 y(t) = K 1 − τ1 e − τ2 e τ1 − τ2 (4.14) We have to determine three parameters K, τ1 and τ2 through optimization. Once again, we follow a procedure identical to the first order model. The only difference is that we now have to determine three parameters. Scilab code secondorder.sce calculates the gain and two time constants. 4.4.1 Procedure 1. Download the Analysis folder from the sbhs website. It will be available under downloads section. Download the file for SBHS Analysis Code (local & virtual). The name of the file is scilab codes analysis. The download will be in zip format. Extrat the downloaded zip file. You will get a folder scilab codes analysis. 2. Open the scilab codes analysis folder and then locate and open the folder Step Analysis. 3. Open the Kp-tau-order2 folder. 4. Copy the step test data file to the folder Kp-tau-order2. 5. Change the Scilab working directory to Kp-tau-order2 folder under Step Analysis folder. 6. Open the file secondorder.sce in scilab editor and enter the name of the data file (with extention) in the filename field. 7. Save and run this code and obtain the plot as shown in figure 4.5. 57 Figure 4.5: Output of the Scilab code secondorder.sce G s (s) = 0.235 (57.39s + 1)(1s + 1) (4.15) The fit is much better now. In particular, the initial inflexion is well captured by this second order transfer function. 4.5 Discussion We summarize our findings now. For the first order analysis, the gain is 0.23 and the time constant τ is 58.64 seconds. For the second order analysis, the initial inflexion is well captured with the two time constants τ1 =57.39, τ2 = 1 and gain = 0.235. Negative steps can also be introduced to make the experiment more informative. One need not keep a particular input constant. By varying both the inputs, one can imagine it to be like a step varying disturbance signal. 4.6 Scilab Code Scilab Code 4.1 label.sci 1 / / Updated (9 −12 −06) , w r i t t e n 58 by I n d e r p r e e t Arora 2 / / Input font arguments : t i t l e , xlabel , y l a b e l and t h e i r s i z e s 3 4 5 6 7 8 9 10 11 f u n c t i o n l a b e l ( tname , t f o n t , l a b e l x , l a b e l y , x y f o n t ) a = get ( ” c u r r e n t a x e s ” ) x t i t l e ( tname , l a b e l x , l a b e l y ) xgrid t = a. title ; t . font size = tfont ; / / T i t l e f o n t s i z e t . f o n t s t y l e = 2; / / T i t l e f o n t s t y l e t . t e x t = tname ; 12 13 14 15 u = a . x label ; u . f o n t s i z e = xyfont ; / / L a b e l u . f o n t s t y l e = 2; / / L a b e l f o n t font v = a . y label ; v . f o n t s i z e = xyfont ; / / L a b e l v . f o n t s t y l e = 2; / / L a b e l f o n t font s i z e s t y l e 16 17 18 19 s i z e s t y l e 20 21 / / a . l a b e l f o n t s i z e = 3; 22 23 endfunction ; Scilab Code 4.2 costf 1.sci 1 2 3 4 5 6 function [ f , g , ind ] = c o s t f 1 (x , ind ) kp = x ( 1 ) ; t a u = x ( 2 ) ; y p r e d i c t i o n = kp * ( 1 − exp ( − t / t a u ) ) ; f = ( norm ( y− y p r e d i c t i o n , 2 ) ) ˆ 2 ; g = numdiff ( f u n c 1 , x ) ; endfunction 7 8 9 10 11 12 function f = func 1 ( x ) kp = x ( 1 ) ; t a u = x ( 2 ) ; y p r e d i c t i o n = kp * ( 1 − exp ( − t / t a u ) ) ; f = ( norm ( y− y p r e d i c t i o n , 2 ) ) ˆ 2 ; endfunction 59 Scilab Code 4.3 firstorder.sce 1 2 mode ( 0 ) f i l e n a m e = ” step −data − l o c a l . t x t ” 3 4 5 6 7 8 9 10 11 clf exec ( ’ c o s t f 1 . s c i ’ ) ; exec ( ’ l a b e l . s c i ’ ) ; d a t a = fscanfMat ( f i l e n a m e ) ; time = data ( : , 5) ; h e a t e r = int ( data ( : , 2) ) ; fan = in t ( data ( : , 3) ) ; temp = d a t a ( : , 4 ) ; 12 13 14 len = length ( heater ) ; 15 16 17 time1 = time − time ( 1 ) ; time2 = time1 /1000; 18 19 20 21 22 len = length ( heater ) ; h e a t e r s 1 = [ h e a t e r ( 1 ) ; h e a t e r ( 1 : l e n −1) ] ; del heat = heater − heaters1 ; i n d = f i n d ( d e l h e a t >1) ; 23 24 s t e p i n s t a n t = i n d ( $ ) −1; 25 26 27 28 29 30 31 32 t = time2 ( s t e p i n s t a n t : len ) ; t = t − t (1) ; H = heater ( s t e p i n s t a n t : len ) ; F = fan ( s t e p i n s t a n t : len ) ; T = temp ( s t e p i n s t a n t : l e n ) ; T = T − T(1) ; d e l t a u = h e a t e r ( s t e p i n s t a n t + 1 )− h e a t e r ( step instant ) ; 33 60 34 / / f i n d i n g Kp and Tem per atur e 35 36 37 38 Tau between Heater (H) and ( T ) y = T; / / t e m p e r a t u r e global ( ’y ’ , ’ t ’ ) ; x0 = [ . 3 4 0 ] ; / / [ f , xopt , gopt ] = optim ( costf 1 , ’ b ’ , [ 0 . 1 0 . 1 ] , [ 5 100] , x0 , ’ ar ’ ) 39 40 41 42 43 44 45 46 47 48 49 50 51 52 [ f , x o p t ] = optim ( c o s t f 1 , x0 ) ; l s t e r r =sqrt ( f ) ; kp = x o p t ( 1 ) ; tau = xopt (2) ; y p r e d i c t i o n = kp * ( 1 − exp ( − t / t a u ) ) ; plot2d ( t , y p r e d i c t i o n ) ; plot2d ( t , y ) ; t i t l e = ’ F i r s t O r d e r model w i t h t a u = ’ ; t i t l e = t i t l e +string ( tau ) ; t i t l e = t i t l e + ’ , Kp= ’+ s t r i n g ( kp / d e l t a u ) ; t i t l e = t i t l e + ’ , E r r o r = ’+ s t r i n g ( l s t e r r ) + ’ ’ ; l a b e l ( t i t l e , 4 , ’ t i m e ( s ) ’ , ’ Change i n t e m p e r a t u r e (K) ’ ,4) ; kp = kp / d e l t a u tau Scilab Code 4.4 costf 2.sci 1 2 3 4 5 6 7 8 9 10 11 12 13 function [ f , g , ind ] = c o s t f 2 (x , ind ) kp = x ( 1 ) ; t a u 1 = x ( 2 ) ; t a u 2 = x ( 3 ) ; y p r e d i c t i o n = kp * d e l t a u * ( 1 − . . . ( t a u 1 * exp ( −( t ) / t a u 1 ) − t a u 2 * exp ( −( t ) / t a u 2 ) ) . . . / ( tau1 −tau2 ) ) ; f = ( norm ( T− y p r e d i c t i o n , 2 ) ) ˆ 2 ; g = numdiff ( f u n c 2 , x ) ; endfunction ; function f = func 2 ( x ) kp = x ( 1 ) ; t a u 1 = x ( 2 ) ; t a u 2 = x ( 3 ) ; y p r e d i c t i o n = kp * d e l t a u * ( 1 − . . . ( t a u 1 * exp ( −( t ) / t a u 1 ) − t a u 2 * exp ( −( t ) / t a u 2 ) ) . . . / ( tau1 −tau2 ) ) ; 61 14 15 f = ( norm ( T− y p r e d i c t i o n , 2 ) ) ˆ 2 ; endfunction ; Scilab Code 4.5 order 2 heater.sci 1 2 3 f u n c t i o n l s t e r r = o r d e r 2 ( t , H, T , l i m i t s , no ) x0 = [ 2 200 1 5 0 ] ; / / d e l t a u = u (2) − u (1) ; u = u − u (1) ; y = y − y (1) ; 4 5 d e l t a u = H( 2 ) −H( 1 ) ; 6 7 8 9 10 11 12 13 14 15 [ f , x o p t , g o p t ] = optim ( c o s t f 2 , ’ b ’ , [ 0 2 1 ] , [ 1 8 300 3 5 0 ] , x0 , ’ a r ’ , 2 0 0 , 2 0 0 ) kp = x o p t ( 1 ) ; t a u 1 = x o p t ( 2 ) ; t a u 2 = x o p t ( 3 ) ; l s t e r r = sqrt ( f ) ; y p r e d i c t i o n = kp * d e l t a u * ( 1 − . . . ( t a u 1 * exp ( −( t ) / t a u 1 ) − t a u 2 * exp ( −( t ) / t a u 2 ) ) . . . / ( tau1 −tau2 ) ) ; format ( ’ v ’ , 6 ) ; o r d = [ T y p r e d i c t i o n ] ; x = [ t t t ] ; / / xbasc () ; plot2d ( t , T) ; 16 17 18 19 20 21 22 23 plot2d ( t , y p r e d i c t i o n ) ; t i t l e = ’ C o m p a r i s o n o f model w i t h d a t a ( t a u 1 = ’ t i t l e = t i t l e + s t r i n g ( t a u 1 ) + ’ , t a u 2 = ’+ s t r i n g ( t a u 2 ) t i t l e = t i t l e + ’ , K= ’+ s t r i n g ( kp ) t i t l e = t i t l e + ’ , e r r o r = ’+ s t r i n g ( l s t e r r ) + ’ ) ’ l a b e l ( t i t l e , 4 , ’ t i m e ( s ) ’ , ’ Change i n t e m p e r a t u r e (K) ’ ,4) ; endfunction ; Scilab Code 4.6 secondorder.sce 1 2 3 4 mode ( 0 ) f i l e n a m e = ” step −data − l o c a l . t x t ” ; clf exec ( ’ c o s t f 2 . s c i ’ ) ; 62 5 6 exec ( ’ l a b e l . s c i ’ ) ; exec ( ’ o r d e r 2 h e a t e r . s c i ’ ) ; 7 8 9 10 11 12 13 d a t a = fscanfMat ( f i l e n a m e ) ; time = data ( : , 5 ) ; h e a t e r = int ( data ( : , 2) ) ; fan = in t ( data ( : , 3) ) ; temp = d a t a ( : , 4 ) ; 14 15 16 17 / / t i m e s =[ t i m e ( 1 ) ; time (1: $ −1) ]; time1 = time − time ( 1 ) ; time2 = time1 /1000; 18 19 20 / / find where the step change happens 21 22 23 24 25 len = length ( heater ) ; h e a t e r s 1 = [ h e a t e r ( 1 ) ; h e a t e r ( 1 : l e n −1) ] ; del heat = heater − heaters1 ; i n d = f i n d ( d e l h e a t >1) ; 26 27 28 29 30 31 32 33 s t e p i n s t a n t = i n d ( $ ) −1; t = time2 ( s t e p i n s t a n t : len ) ; t = t − t (1) ; H = heater ( s t e p i n s t a n t : len ) ; F = fan ( s t e p i n s t a n t : len ) ; T = temp ( s t e p i n s t a n t : l e n ) ; T = T − T(1) ; 34 35 / / l i m i t s 36 / / 37 l s t e r r = o r d e r 2 ( t , H, T , ) l i m i t s = [0 ,0 ,500 ,10]; = no = 1 0 0 0 0 ; [400 ,0 ,900 ,26]; Scilab Code 4.7 ser init.sce 1 2 mode ( 0 ) global filename 63 / / f i r s t no = 5 0 0 0 ; / / s e c o n d step step 3 / / ** S a m p l i n g Time * * / / 4 sampling time = 1; 5 / / / / / / / * * * * / / / / / / / / / 6 m=1; 7 8 9 p o r t 1 = ’ / dev / ttyUSB0 ’ ; / / F o r p o r t 2 = ’COM2 ’ ; / / F o r w i n d o w s l i n u x u s e r s u s e r s 10 11 12 res= i n i t ([ port1 port2 ]) ; disp ( res ) Scilab Code 4.8 step test.sci 1 2 3 mode ( 0 ) f u n c t i o n temp = s t e p t e s t ( h e a t , f a n ) temp = comm ( h e a t , f a n ) ; 4 5 p l o t t i n g ( [ h e a t f a n temp ] , [ 2 0 0 25 0 ] , [ 5 0 100 40 1000]) 6 7 8 m=m+1; endfunction Scilab Code 4.9 stepc.sce 1 2 mode ( 0 ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 3 4 / / ********************** 5 s a m p l i n g t i m e =1; 6 / / * * * * * * * * * * * * * * * * * * * * * * / / 7 / / In seconds . F r a c t i o n s are allowed exec ( ” s t e p t e s t . s c i ” ) ; 8 9 ok = i n i t ( ) ; 10 11 i f ok ˜= [ ] through / / ( ie open xcos only if r e p l y has come from 64 communication s e r v e r ) is xcos ( ’ s t e p t e s t . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 12 13 14 15 16 end Scilab Code 4.10 steptest.sci 1 function [ stop ] = s t e p t e s t ( heat , fan ) 2 3 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 4 p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 25 0 ] , [ 1 0 0 100 50 1000]) 5 6 endfunction 65 Chapter 5 Identification of Transfer Function of a Single Board Heater System through Ramp Response Experiment The aim of this experiment is to perform ramp test on a Single Board Heater System and to identify system transfer function using ramp response data. The target group is anyone who has basic knowledge of control engineering. We have used Scilab and Xcos as an interface for sending and receiving data. Xcos diagram is shown in figure 5.1. Heater current and fan speed are the two inputs for this system. They are given in percentage of maximum. These inputs Figure 5.1: Xcos for ramp test experiment 66 Figure 5.2: Screen shot of ramp test experiment 67 1.0 2.0 . 999.0 1000.0 30.0 30.0 50.0 50.0 100.0 100.0 28.1 50.0 50.0 1416462726532.0 28.1 1416462727574.0 47.6 1416463723533.0 47.6 1416463724533.0 Table 5.1: Ramp data obtained after performing local Step Test can be varied by setting the properties of the input block’s properties in Xcos. The plots of their amplitude versus number of collected samples are also available on the scope windows. The output temperature profile, as read by the sensor, is also plotted. The data acquired in the process is stored on the local drive and is available to the user for further calculations. In the ramp test.xcos file, open the heater block’s parameters to give a ramp input to the system with some value for slope. For this experiment, we have chosen slope = 0.1. Double click on the ramp input block labled as Heater input. Change the following values in the respective fields: slope = 0.1, start time = 200, initial output = 20. Keep the fan constant at 100. The ramp test data file will be saved in Ramp Test folder. The name of the file will be the date and time at which the experiment was conducted. A sample data file is provided in the same folder. The sample data file is named as ramp-data-local.txt and ramp-data-virtual.txt. Refer to the one depending on wheather you are performing a local or a virtual experiment. Referring to the data file thus obtained as shown in table 6.2, the first column in this table denotes samples. The second column in this table denotes heater in percentage. It starts at 30 and increases with a step size of 10 units. The third column denotes the fan in percentage. It has been held constant at 50 percent. The fourth column refers to the value of temperature. The fifth column denotes time stamp. The virtual data file will have four time stamp columns apart from first 3 columns. These four time stamp columns are client departure, server arrival, server departure and client arrival. These can be used for advanced control algorithms. These additional time stamps exist in virtual mode because of the presense of network delay. 68 5.1 Conducting Ramp Test on SBHS locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is Ramp test 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec ramp test.sci 6. Step6: Load Xcos code for ramp test using the command exec ramp test.xcos 7. Step7: Same 5.2 Conducting Ramp Test on SBHS, virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is RampTest. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the RampTest experiment directory and double-click on the file ramptest.sce. This will launch scilab and also open the file ramptest.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to RampTest and then open the RampTest file in the scilab editor. 5. Step5: Same 69 Figure 5.3: Ramp test Virtual experiment response 6. Step6: Execute the file ramptest.sce. Expect the ramp test xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the ramptest xcos diagram. 8. Step8: Same The virtual experiment response is shown in figure 5.3. The corresponding data file is shown in table 6.2. The time stamps shown are cut short for better viewing. This data file can be found in RampTest folder for virtual experiments. The name of this file is step-data-virtual.txt. 70 0 0 100 28.80 14...8993 14...0301 14...0318 14...9040 0.10000E+01 1 30 50 28.80 14...2861 14...4172 14...4189 14...2908 0.10000E+01 . . 617 66 50 39.10 14...7141 14...8476 14...8494 14...7188 0.61700E+03 618 66 50 39.10 14...8120 14...9456 14...9473 14...8167 0.61800E+03 Table 5.2: Ramp data obtained after performing virtual Ramp Test 5.3 Identifying First Order Transfer Function In this section we shall determine the first order transer function model using the data obtained after performing step test experiment. Please note that this procedure is common for data obtained using both local and virtual experiments. Identification of the transfer function of a system is important as it helps us to represent the physical system mathematically. Once the transfer function is obtained, one can acquire the response of the system for various inputs without actually applying them to the system. Consider the standard first order transfer function given below C(s) R(s) K G(s) = τs + 1 G(s) = (5.1) (5.2) Combining the previous two equations, we get ( R(s) C(s) = K τs + 1 ) (5.3) Let us consider the case of giving a ramp input to this first order system. The Laplace transform of a ramp function with slope = υ is sυ2 . Substituting R(s) = sυ2 in equation 5.3, we obtain K υ τs + 1 s2 A B C = + 2+ s s τs + 1 C(s) = 71 (5.4) (5.5) Solving C(s) using Heaviside expansion approach, we get ( ) 1 τ τ2 C(s) = Kυ 2 − + s s τs + 1 Taking the Inverse Laplace transform of the above equation, we get o n −t c(t) = Kυ t − τ + τe τ (5.6) (5.7) The difference between the reference and output signal is the error signal e(t). Therefore, e(t) = r(t) − c(t) (5.8) e(t) = Kυt − Kυt + Kυτ − Kυτe −t τ −t τ e(t) = Kυτ(1 − e ) (5.9) (5.10) Normalizing equation 5.10 for t >> τ, we get e(t) = τ (5.11) This means that the error in following the ramp input is equal to τ for large value of t [7]. Hence, smaller the time constant τ, smaller the steady state error. 5.3.1 Procedure 1. Download the Analysis folder from the sbhs website. It will be available under downloads section. Download the file for SBHS Analysis Code (local & virtual). The name of the file is scilab codes analysis. The download will be in zip format. Extrat the downloaded zip file. You will get a folder scilab codes analysis. 2. Open the scilab codes analysis folder and then locate and open the folder Ramp Analysis. 3. Copy the ramp test data file to this folder. 4. Change the Scilab working directory to Ramp Analysis 5. Open the file ramp virtual.sce in scilab editor and enter the name of the data file (with extention) in the filename field. 72 Figure 5.4: Output of the Scilab code ramp virtual.sce 73 Figure 5.5: Scilab console after executing coderamp virtual.sce 74 6. Save and run this code and obtain the plot as shown in figure 5.4. This code uses the routines label.sci and costf 1.sci The results presented are obtained for the data file ramp-data-virtual.txt. This data file is present under the Ramp Test directory for local experiments. The plot thus obtained is reasonably good. See the Scilab console to get the values of τ and K. It is as shown in figure 5.5 The figure 5.4 shows a screen shot of the same. We obtain τ = 78.92, K = 0.22. The transfer function obtained here is at the operating point of enterValue percentage of heat. If the experiment is repeated at a different operating point, the transfer function obtained will be different. The gain will correspondingly be more at a higher operating point. This means that the plant is faster at higher temperature. Thus the transfer function of the plant varies with the operating point. Let the transfer function we obtain in this experiment be denoted as G s . We obtain G s (s) = 5.4 0.22 78.92s + 1 (5.12) Discussion We summarize our findings now. The experiment has been performed by varying the heater current and keeping the fan speed constant. However, the user is encouraged to experiment using different combinations of fan speed and heater current. Negative ramp can also be used to make the experiment more informative. It is not necessary to keep a particular input constant. For example, you can try giving a ramp input to the disturbance signal, i.e., the fan input. The system can also be treated as a second order system. This consideration is necessary as it increases the accuracy of the acquired transfer function [6]. The necessary codes are listed in the section 5.5. 5.5 Scilab Code Scilab Code 5.1 ramp test.sci 1 mode ( 0 ) 75 2 3 f u n c t i o n temp = r a m p t e s t ( h e a t , f a n ) temp = comm ( h e a t , f a n ) ; 4 p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 20 0 ] , [ 1 0 0 100 50 1000]) 5 6 7 8 m=m+1; endfunction Scilab Code 5.2 label.sci 1 mode ( −1) ; 2 / / 3 / / Updated Input font (9 −12 −06) , w r i t t e n arguments : t i t l e , by xlabel I n d e r p r e e t , y l a b e l and Arora t h e i r s i z e s 4 5 6 7 8 9 10 11 12 f u n c t i o n l a b e l ( tname , t f o n t , l a b e l x , l a b e l y , x y f o n t ) a = get ( ” c u r r e n t a x e s ” ) x t i t l e ( tname , l a b e l x , l a b e l y ) xgrid t = a. title ; t . font size = tfont ; / / T i t l e f o n t s i z e t . f o n t s t y l e = 2; / / T i t l e f o n t s t y l e t . t e x t = tname ; 13 14 15 16 u = a . x label ; u . f o n t s i z e = xyfont ; / / L a b e l u . f o n t s t y l e = 2; / / L a b e l f o n t font v = a . y label ; v . f o n t s i z e = xyfont ; / / L a b e l v . f o n t s t y l e = 2; / / L a b e l f o n t font s i z e s t y l e 17 18 19 20 21 22 / / a . l a b e l f o n t s i z e = 3; 23 24 endfunction ; Scilab Code 5.3 cost.sci 76 s i z e s t y l e 1 2 3 4 5 6 function f = func 1 ( x ) k = x (1) ; tau = x (2) ; y p r e d i c t i o n = k * ( t + t a u * ( exp ( − t / t a u ) − 1 ) ) ; f = ( norm ( y − y p r e d i c t i o n , 2 ) ) ˆ 2 ; endfunction 7 8 9 10 11 12 13 14 function [ f , g , ind1 ] = cost ( x , ind1 ) k = x (1) ; tau = x (2) ; y p r e d i c t i o n = k * ( t + t a u * ( exp ( − t / t a u ) − 1 ) ) ; f = ( norm ( y − y p r e d i c t i o n , 2 ) ) ˆ 2 ; g = numdiff ( f u n c 1 , x ) ; endfunction Scilab Code 5.4 cost approx.sci 1 2 3 4 5 6 function f = func approx ( x ) k = x (1) ; tau = x (2) ; y p approx = k *( t approx − tau ) ; f = ( norm ( y a p p r o x − y p a p p r o x , 2 ) ) ˆ 2 ; endfunction 7 8 9 10 11 12 13 14 function [ f , g , ind ] = cost approx (x , ind ) k = x (1) ; tau = x (2) ; y p approx = k *( t approx − tau ) ; f = ( norm ( y a p p r o x − y p a p p r o x , 2 ) ) ˆ 2 ; g = numdiff ( f u n c a p p r o x , x ) ; endfunction Scilab Code 5.5 ramptest.sci 1 function [ stop ] = ramptest ( heat , fan ) 2 3 [ s t o p , temp ] = comm ( h e a t , f a n ) ; l i n e 77 / / Never e d i t t h i s p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 25 0 ] , [ 1 0 0 100 50 1000]) 4 5 6 endfunction Scilab Code 5.6 ramptest.sce 1 2 mode ( 0 ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 3 4 5 6 7 / / ********************** s a m p l i n g t i m e =1; / / In seconds . F r a c t i o n s are allowed / / * * * * * * * * * * * * * * * * * * * * * * / / exec ( ” r a m p t e s t . s c i ” ) ; 8 9 ok = i n i t ( ) ; 10 i f ok ˜= [ ] 11 / / through xcos only if communication r e p l y has come from is s e r v e r ) xcos ( ’ r a m p t e s t . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 12 13 14 15 16 ( ie open end Scilab Code 5.7 ramp virtual.sce 1 mode ( −1) ; 2 3 / / f i l e n a m e path of = ”20 Apr2012 the saved 15 data 10 35 . t x t ”; f i l e 5 f i l e n a m e =” ramp− d a t a − l o c a l . t x t ” ; slope = 0.1; / / c h a n g e t h i s t o t h e 6 i n d 1 =3; 4 used 7 8 / / Ramp in the / / complete e x p e r i m e n t A n a l y s i s exec ( ’ c o s t a p p r o x . s c i ’ ) ; 78 slope t h a t you have 9 10 exec ( ’ c o s t . s c i ’ ) ; exec ( ’ l a b e l . s c i ’ ) ; 11 12 13 14 15 16 d a t a = fscanfMat ( f i l e n a m e ) ; time = data ( : , 5) ; h e a t e r = int ( data ( : , 2) ) ; fan = in t ( data ( : , 3) ) ; temp = d a t a ( : , 4 ) ; 17 18 19 20 21 22 len = length ( heater ) ; h e a t e r s 1 = [ h e a t e r ( 1 ) ; h e a t e r ( 1 : $ −1) ] ; d e l h e a t = abs ( h e a t e r − h e a t e r s 1 ) ; ind = find ( del heat >.5) ; 23 24 25 26 27 t = t i m e ( i n d ( 2 ) : i n d ( $ −1) ) ; t=t /1000 H = h e a t e r ( i n d ( 2 ) : i n d ( $ −1) ) ; T = temp ( i n d ( 2 ) : i n d ( $ −1) ) ; 28 29 30 t = t − t (1) ; T = T − T(1) ; 31 32 33 34 y = T; x0 = [ . 5 1 0 0 ] global ( ’y ’ , ’ t ’ ) ; 35 36 37 38 [ f , x o p t ] = optim ( c o s t , x0 ) ; kp = x o p t ( 1 ) / s l o p e tau = xopt (2) 39 40 41 len = length ( t ) ; halfway = c e i l ( len / 2 ) ; 42 43 44 45 t approx = t ( halfway : len ) ; y approx = y ( halfway : len ) ; global ( ’ y approx ’ , ’ t approx ’ ) ; 46 79 47 48 49 [ f a p p r o x , x o p t a p p r o x ] = optim ( c o s t a p p r o x , x0 ) ; kp approx = xopt approx (1) / slope ; tau approx = xopt approx (2) ; 50 51 52 53 54 55 56 57 58 59 / / Display and Plot d i s p ( ’ kp = ’ ) ; d i s p ( kp ) ; disp ( ’ tau = ’ ) ; disp ( tau ) ; disp ( ’ kp approx = ’ ) ; disp ( kp approx ) ; disp ( ’ tau approx = ’ ) ; disp ( tau approx ) ; 60 61 62 63 64 65 66 y p = kp * s l o p e * ( t + t a u * ( exp ( − t / t a u ) − 1 ) ) ; y p approx = kp approx * slope *( t approx − tau approx ) ; y p approx = y p approx ’ ; plot2d ( t , [ y p , T ] ) ; l a b e l ( ’ Showing F i r s t O r d e r Model and E x p e r i m e n t a l R e s u l t s f o r kp and t a u ’ , 4 , ’ Time ( s ) ’ , ’ Change i n Temperature ( Predicted , Actual ) ’ ,4) ; legend ( [ ’ Predicted ’ ; ’ Actual ’ ] ) ; 80 Chapter 6 Frequency Response Analysis of a Single Board Heater System by the Application of Sine Wave The aim of this experiment is to do a frequency response analysis of a Single Board Heater System by the application of sine wave. The target group is anyone who has basic knowledge of control engineering. We have used Scilab and Xcos as an interface for sending and receiving data. Xcos diagram is shown in figure 6.1. The heater current is varied sinusoidally. They are given in percentage of maximum. These inputs can be varied by setting the properties of the input block’s properties in Xcos. A provision is made to set the parameters related to it like frequency, amplitude and offset. The temperature profile thus obtained is the output. In this experiment we are applying a sine change in the heater current by keeping the fan speed constant. After application of sine change, wait for sufficient amount of time to allow the temperature to reach a steady-state. The plots of their amplitude versus number of collected samples are also available on the scope windows. The output temperature profile, as read by the sensor, is also plotted. The data acquired in the process is stored on the local drive and is available to the user for further calculations. In the sine test.xcos file, open the sinusoid generator block’s parameters to set the value of sine magnitude and frequency. For the experiment results shown, we have chosen Magnitude = 10, Frequency = 2 ∗ 3.14 ∗ 0.007. Note that the frequency is to be put in rad/sec. We keep the Phase = 0. There is also a provision to give the sine input with an offset in amplitude. This can be set using the Offset block. We have choosen offset of 20. The time at which the sine input 81 Figure 6.1: Xcos for local Sine Test is given after the experiment is started can also be set. This can be done using the Initial Time block. Open the Initial Time block’s parameters. To make the sine input appear after 200 samples of start of the experiment, keep Step time = 200, Initial Value = 0 and Final Value = 1. The initial value and final value will never change for any other value of step time. The sine test data file will be saved in Sine Test folder. The name of the file will be the date and time at which the experiment was conducted. A sample data file is provided in the same folder. The sample data file is named as sine-data-local.txt and sine-data-virtual.txt. Refer to the one de1.0 20.0 2.0 20.0 . 13093.0 28.5 13094.0 28.5 50.0 50.0 20.0 50.0 50.0 1416642805261.0 20.0 1416642806332.0 26.6 26.6 1416656557353.0 1416656558363.0 Table 6.1: Data obtained after application of sine input of 0.007Hz 82 Figure 6.2: Plot for sine input 0.007Hz 83 pending on wheather you are performing a local or a virtual experiment. Referring to the data file thus obtained as shown in table 6.1, the first column in this table denotes samples. The second column in this table denotes heater in percentage. It starts at 20 and then varies sinosoidally. The third column denotes the fan in percentage. It has been held constant at 50 percent. The fourth column refers to the value of temperature. The fifth column denotes time stamp. The virtual data file will have four time stamp columns apart from first 3 columns. These four time stamp columns are client departure, server arrival, server departure and client arrival. These can be used for advanced control algorithms. These additional time stamps exist in virtual mode because of the presense of network delay. 6.1 Conducting Sine Test on SBHS locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is Sine test 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load sine test function by executing command exec sine test.sci 6. Step6: Load Xcos code for sine test using the command exec sine test.xcos 7. Step7: Same 6.2 Conducting Sine Test on SBHS, virtually The detailed procedure to perform a local experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 84 0 0 100 28.80 14...4739 14...6427 14...6445 14...4786 0.10000E+01 1 20 50 28.90 14...5247 14...6938 14...6956 14...5294 0.10000E+01 . . 999 18 50 31.00 14...2253 14...3973 14...3990 14...2299 0.99900E+03 1000 19 50 31.00 14...3268 14...4989 14...5007 14...3315 0.10000E+04 Table 6.2: Sine data obtained after performing virtual Sine Test 1. Step1: The working directory is SineTest. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the SineTest experiment directory and double-click on the file sinetest.sce. This will launch scilab and also open the file sinetest.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to SineTest and then open the sinetest.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file sinetest.sce. Expect the sine test xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the sinetest xcos diagram. 8. Step8: Same The virtual experiment response is shown in figure 6.3. The corresponding data file is shown in table 6.1. The time stamps shown are cut short for better viewing. This data file can be found in SineTest folder for virtual experiments. The name of this file is sine-data-virtual.txt. 6.3 Frequency Analysis of sine test data Frequency response of a system means its steady-state response to a sinusoidal input. For obtaining a frequency response of a system, we vary the frequency of 85 Figure 6.3: Sine test Virtual experiment response 86 the input signal over a spectrum of interest. The analysis is useful and simple because it can be carried out with the available signal generators and measuring devices. Let us see the theory and procedure. Please note that this procedure is common for data obtained using both local and virtual experiments. Consider a sinusoidal input U(t) = Asinωt (6.1) The Laplace transform of the above equation yields U(s) = s2 Aω + ω2 (6.2) Consider the standard first order transfer function given below G(s) = K Y(s) = U(s) s + 1 (6.3) Replacing the value of U(s) from equation 6.2, we get KAω (τs + 1)(s2 + ω2 ) " # KA ωτ2 τsω ω = 2 2 − + ω τ + 1 τs + 1 s2 + ω2 s2 + ω2 Y(s) = (6.4) (6.5) Taking Laplace Inverse, we get i KA h −t y(t) = 2 2 ωτe τ − ωτcos(ωt) + sin(ωt) ω τ +1 (6.6) −t The above equation has an exponential term e τ . Hence, for large value of time, its value will approach to zero and the equation will yield a pure sine wave. One can also use trigonometric identities to make the equation look more simple. " # KA y(t) = √ sin(ωt) + φ (6.7) ω2 τ2 + 1 where, φ = −tan−1 (ωτ) (6.8) 87 By observing the above equation, one can easily make out that for a sinusoidal input the output is also sinusoidal but has some phase difference. Also, the amplitude of the output signal, Â, has become a function of the input signal frequency, ω. KA Â = √ ω2 τ2 + 1 (6.9) The amplitude ratio (AR) can be calculated by dividing both sides by the input signal amplitude A. AR = Â K = √ A ω2 τ2 + 1 (6.10) Dividing the above equation by the process gain K yields the normalized amplitude ratio (ARn ) ARn = 1 AR = √ K ω2 τ2 + 1 (6.11) Because the process steady state gain is constant, the normalized amplitude ratio is often used for frequency response analysis [8]. 6.3.1 Procedure Now let us calculate amplitude ratio and phase difference. 1. Download the Analysis folder from the sbhs website. It will be available under downloads section. Download the file for SBHS Analysis Code (local & virtual). The name of the file is scilab codes analysis. The download will be in zip format. Extrat the downloaded zip file. You will get a folder scilab codes analysis. 2. Open the scilab codes analysis folder and then locate and open the folder Sine Analysis. 3. Copy the sine test data file to this folder. 4. Change the Scilab working directory to Sine Analysis 88 Figure 6.4: Amplitude ratio and Phase difference for local data file 5. Open the file sine-analysis.sce in scilab editor and enter the name of the data file (with extention) in the filename field. 6. Put the value of frequency f for the calculation of amplitude ratio and phase difference and execute it. Here f means input frequency. 7. Expect the values of amplitude ratio and phase difference on the scilab console. The results shown are for the data file sine-data-local.txt. It could be seen from figure 6.4 that the amplitude ratio turns out to be −0.915dB and phase difference to be −57.267°. The plot thus obtained is shown in figure 6.5 Repeat this calculation over a range of frequencies and note down the values of amplitude ratio in dB and phase difference. Input these values for the appropriate frequencies into the Scilab code TFbode.sce and execute it to get a Bode plot of the plant which is illustrated in figure 6.6. Bode plot can be obtained directly from the plant’s second order transfer function [6] with the help of Scilab code TFbode.sce, as shown in figure 6.7. A visual 89 Figure 6.5: Plot of Input and Output vs time 90 Figure 6.6: Bode plot obtained from the plant 91 Figure 6.7: Bode plot obtained through plant’s transfer function comparison of the two Bode plots can be done to validate the Bode diagram obtained from the plant. To compare the two plots, we plot it on the same graph as shown in figure 6.8 6.4 Scilab Code Scilab Code 6.1 sine test.sci 1 2 3 mode ( 0 ) f u n c t i o n temp = s i n e t e s t ( h e a t , f a n ) temp = comm ( h e a t , f a n ) ; 4 92 Figure 6.8: Comparison of Bode plots 93 p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1000]) 5 6 7 8 m=m+1; endfunction Scilab Code 6.2 sinetest.sce 1 2 mode ( 0 ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 3 4 / / ********************** 5 s a m p l i n g t i m e =1; 6 / / * * * * * * * * * * * * * * * * * * * * * * / / 7 / / In seconds . F r a c t i o n s are allowed exec ( ” s i n e t e s t . s c i ” ) ; 8 9 ok = i n i t ( ) ; 10 i f ok ˜= [ ] 11 through ( ie open xcos only if r e p l y has come from communication is s e r v e r ) xcos ( ’ s i n e t e s t . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 12 13 14 15 16 / / end Scilab Code 6.3 sinetest.sci 1 function [ stop ] = s i n e t e s t ( heat , fan ) 2 3 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 4 p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 25 0 ] , [ 1 0 0 100 50 1000]) 5 6 endfunction 94 Scilab Code 6.4 sine-analysis.sce 1 2 mode ( 0 ) ; filename= ’ sine0035 − l o c a l . t x t ’ ; name 3 4 5 6 7 s i n g l e / / Enter the data f i l e quotes f =0.0035; / / E n t e r t h e f r e q u e n c y d a t a 6 =f s c a n f M a t ( f i l e n a m e ) ; data7=data6 ( 2 : $ , : ) ; exec ( ’ l a b e l b o d e . s c i ’ ) ; T = data7 ( : , 5 ) ; fan = data7 ( : , 3 ) ; fan 8 in / / T is time , fan is speed u = data7 ( : , 2 )−data7 (1 ,2) ; y = data7 ( : , 4 )−data7 (1 ,4) ; / / u is current , y is t e m p e r a t u r e 9 10 11 12 13 14 15 period= c e i l ( 1 / f ) ; p= l e n g t h ( u ) ; s a m p l i n g = T ( 2 ) −T ( 1 ) ; / / s a m p l i n g t i m e sampling = sampling /1000; i n d e x = round ( ( p e r i o d ) / s a m p l i n g ) ; / / c d u r a t i o n 16 17 18 19 of is and is r e l a t i v e and i n p u t for l a s t l a s t cycle index to in for l a s t terms o u t p u t in the cycle cycle d e t e r m i n i n g of i n p u t max ( index cycle ) l a s t / / d e t e r m i n i n g cycle of max i n p u t ( index cycle ) of terms of / / c o n v e r s i o n complete p o i n t e r 2 = p o i n t e r 2 + ( p− i n d e x ) ; data data index of index p e r i o d / / c o n v e r s i o n complete of p e r i o d A m p l i t u d e r a t i o d B = 20 * l o g 1 0 ( y ( p o i n t e r 2 ) / u ( p o i n t e r 1 ) ) / / To 24 index to r e l a t i v e for 23 a l c u l a t i n g waveform p o i n t e r 1 = p o i n t e r 1 + ( p− i n d e x ) ; for 22 of [ max temp , p o i n t e r 2 ] = max ( temp ) ; a m p l i t u d e 21 cycle t i m e s =T ( $− i n d e x : $ ) ; temp = y ( $− i n d e x : $ ) ; / / o u t p u t f o r l a s t h e a t e r = u ( $− i n d e x : $ ) ; / / i n p u t f o r l a s t [ m a x h e a t e r , p o i n t e r 1 ] = max ( h e a t e r ) ; / / a m p l i t u d e 20 l a s t find gain in dB P h a s e d i f f e r e n c e = 360 * f * ( p o i n t e r 1 − p o i n t e r 2 ) * s a m p l i n g / / phase d i f f e r e n c e in d e g r e e s 95 25 / / P h a s e d i f f e r e n c e = −(( p o i n t e r 1 − p o i n t e r 2 ) / ( 1 / f ) ) *360 26 27 28 29 30 31 32 d e l T = T−T ( 1 ) ; del T = del T /1000; plot2d ( del T , [ u y ] ) ; l a b e l ( ’ P l o t o f s i n e i n p u t i n h e a t e r and t h e c o r r e s p o n d i n g t e m p e r a t u r e p r o f i l e ’ , 4 , ’ Time ( s ) ’ , ’ Change i n t e m p e r a t u r e and h e a t e r ’ , 4 ) ; / / legend ([ ’ Heater ’; ’ Temperature ’ ] ) ; Scilab Code 6.5 label.sci 1 / / Updated 2 / / Input font 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (9 −12 −06) , w r i t t e n arguments : t i t l e , by xlabel I n d e r p r e e t , y l a b e l and 2 3 t h e i r s i z e s f u n c t i o n l a b e l ( tname , t f o n t , l a b e l x , l a b e l y , x y f o n t ) a = get ( ” c u r r e n t a x e s ” ) x t i t l e ( tname , l a b e l x , l a b e l y ) xgrid t = a. title ; t . font size = tfont ; / / T i t l e f o n t s i z e t . f o n t s t y l e = 2; / / T i t l e f o n t s t y l e t . t e x t = tname ; u = a . x label ; u . f o n t s i z e = xyfont ; / / L a b e l f o n t s i z e u . f o n t s t y l e = 2; / / L a b e l f o n t s t y l e v = a . y label ; v . f o n t s i z e = xyfont ; / / L a b e l f o n t s i z e v . f o n t s t y l e = 2; / / L a b e l f o n t s t y l e / / a . l a b e l f o n t s i z e = 3; endfunction ; Scilab Code 6.6 bodeplot.sce 1 Arora / / b o d e p l o t exec ( ’ l a b e l b o d e . s c i ’ ) ; x =[0.001 ,0.0035 ,0.004 ,0.005 ,0.006 ,0.007 ,... 96 4 5 6 0.008 ,0.009 ,0.01 ,0.02 ,0.03 ,0.04]; / / I n p u t f r e q u e n c y ( y =[ −3.87 , −5.67 , −7.53 , −7.53 , −8.17 , −8.64 ,... −8.87 , −8.90 , −9.11 , −13.55 , −15.39 , −16.47]; / / A m p l i t u d e Hz ) r a t i o ( dB ) 7 8 9 10 11 subplot (2 ,1 ,1) ; p l o t 2 d ( x , y , r e c t = [ 0 . 0 0 1 , − 2 0 , 0 . 0 4 , 0 ] , l o g f l a g =” l n ” ) ; xgrid ( ) ; y =[ −25.2 , −28.98 , −33.11 , −41.4 , −60.48 , −70.56 ,... −77.76 , −87.48 , −90 , −129.6 , −151.2 , −172.8]; / / P h a s e d i f f e r e n c e ( degree ) 12 13 14 15 16 17 18 title = ’’ l a b e l ( t i t l e , 4 , ’Hz ’ , ’ A m p l i t u d e r a t i o i n dB ’ , 4 ) ; subplot (2 ,1 ,2) ; p l o t 2 d ( x , y , r e c t = [ 0 . 0 0 1 , − 1 8 0 , 0 . 0 4 , − 2 0 ] , l o g f l a g =” l n ” ) ; l a b e l ( t i t l e , 4 , ’ ’ , ’ Phase d i f f e r e n c e ’ ,4) ; subplot (2 ,1 ,2) ; xgrid ( ) ; 19 20 / / s= poly (0 , ’ s ’) 21 / / h= s y s l i n ( ’ c ’ , ( 0 . 4 7 5 / ( 1 2 4 . 8 2 7 * s ˆ2+57.26* s +1) ) ) 22 / / bode ( h , 0 . 0 0 1 , 0 . 0 4 ) ; Scilab Code 6.7 labelbode.sci 1 / / Updated 2 / / Input font (9 −12 −06) , w r i t t e n arguments : t i t l e , by xlabel I n d e r p r e e t , y l a b e l and Arora t h e i r s i z e s 3 4 5 6 7 8 9 10 11 12 13 f u n c t i o n l a b e l ( tname , t f o n t , l a b e l x , l a b e l y , x y f o n t ) a = get ( ” c u r r e n t a x e s ” ) x t i t l e ( tname , l a b e l x , l a b e l y ) xgrid t = a. title ; t . font size = tfont ; / / T i t l e f o n t s i z e t . f o n t s t y l e = 2; / / T i t l e f o n t s t y l e t . t e x t = tname ; u = a . x label ; u . f o n t s i z e = xyfont ; / / L a b e l f o n t s i z e 97 14 15 16 17 18 19 u . f o n t s t y l e = 2; / / L a b e l f o n t v = a . y label ; v . f o n t s i z e = xyfont ; / / L a b e l v . f o n t s t y l e = 2; / / L a b e l f o n t / / a . l a b e l f o n t s i z e = s t y l e font s i z e s t y l e 3; endfunction ; Scilab Code 6.8 TFbode.sce 1 2 3 s=p o l y ( 0 , ’ s ’ ) d t =10; / / d e l a y / / h= s y s l i n ( ’ c ’ , ( ( 0 . 5 1 0 / ( 6 5 . 4 9 * s +1) ) ) ) / / t r a n s f e r f u n c t i o n 4 5 time using f i r s t order pade ’ a p p r o x i m a t i o n t f = ( ( 0 . 4 7 5 / ( 3 6 * s +1) ) * (( − d t / 2 ) * s + 1 / ( d t / 2 ) * s +1) ) ; bode ( h , 0 . 0 0 1 , 1 0 ) ; Scilab Code 6.9 comparison.sce 1 2 3 4 s=p o l y ( 0 , ’ s ’ ) ; frq = [0.001 ,0.0035 ,0.004 ,0.005 ,0.006 ,0.007 ,... 0.008 ,0.009 ,0.01 ,0.02 ,0.03 ,0.04]; / / I n p u t f r e q u e n c y d t =10; / / d e l a y t i m e ( Hz ) 5 6 t f = ( ( 0 . 4 7 5 / ( 3 6 * s +1) ) * (( − d t / 2 ) * s + 1 / ( d t / 2 ) * s +1) ) ; 7 h= s y s l i n ( ’ c ’ , t f ) ; t r a n s f e r f u n c t i o n using pade ’ / / a p p r o x i m a t i o n 8 9 10 11 12 13 [ f r q 1 , r e p ]= r e p f r e q ( h , f r q ) ; [ dB1 , p h i 1 ]= dbphi ( r e p ) ; t i t l e = ’ From a c t u a l p l a n t d a t a ’ ; dB = [ − 3 . 8 7 , − 5 . 6 7 , − 7 . 5 3 , − 7 . 5 3 , − 8 . 1 7 , − 8 . 6 4 , . . . −8.87 , −8.90 , −9.11 , −13.55 , −15.39 , −16.47]; / / A m p l i t u d e r a t i o ( dB ) 14 15 phi = [ −25.2 , −28.98 , −33.11 , −41.4 , −60.48 ,... −70.56 , −77.76 , −87.48 , −90 , −129.6 , −151.2 , −172.8]; / / Phase d i f f e r e n c e ( degree ) 16 17 bode ( [ f r q ] , [ dB ; dB1 ] , [ p h i ; p h i 1 ] ) l e g e n d ( [ ’ P l a n t d a t a ’ ; ’ $ \ f r a c { 0 . 4 2 } { 3 6 s +1} e ˆ { − 10 s } $ ’ ] ) 98 18 19 / / t r a n s f e r f u n c t i o n using pade ’ 99 a p p r o x i m a t i o n Chapter 7 Controlling Single Board Heater System using PID controller The aim of this experiment is to apply a PID controller to the Single Board Heater System. The target group is anyone who has basic knowledge of control engineering. Scilab is used with Xcos as an interface for sending and receiving data. This interface is shown in figure 7.1. Heater current and fan speed are the two inputs to the system. The inputs are provided in percentage of maximum output. The parameters related to PID controller (K, τi , τd ) can be set in Xcos. In this experiment, the fan speed is kept constant. The output temperature profile, read by the sensor, is also plotted. The data acquired in the process is stored on the local drive and is available to the user for further calculations. 7.1 Theory A PID controller tries to minimize the error between measured variable and the setpoint by calculating the error and then taking a suitable corrective action. Note that the output of interest is called the measured variable or process variable, the difference between the setpoint and the measured variable is called the error and the control action taken to minimize the error is given as input to the process in the form of the manipulated variable. A PID controller does not simply add or subtract the error in order to calculate control action but instead uses three distinct control features, namely, Proportional, Integral and Derivative. Thus, a PID controller has three separate parameters. 100 Figure 7.1: Xcos interface for this experiment 7.1.1 Proportional Control Action This parameter generates a control action based on the current value of the error. In a more simplified sense, if the error is +2, the control action is -2. The proportional action can be generated by multiplying the error with a proportional constant- K p . Mathematical representation of the same is given below, P = K p e(t) (7.1) where, P is the proportional output K p is the proportional gain e(t) is the error signal The value of K p is very important. A large value of K p may lead to instability of the system. In contrast, a smaller value of KP may decrease the controller’s sensitivity towards error. The problem involved in using only proportional action is that the control action will never settle down to its target value and will always retain a steady-state error. 101 7.1.2 Integral Control Action This parameter generates a control action depending on the history of errors. It means that the action is based on the sum of the recent errors. It is proportional to both the magnitude as well as duration of the error. The summation of the error over a period of time gives a value of the offset that should have been corrected previously. The integral action can thus be generated by multiplying this accumulated error with an integral gain Ki . Mathematical representation of the same is given below. Z t I = Ki e(t)dt (7.2) 0 where, I is the integral output Ki is the integral gain (Ki = K p /τi , where, τi is the integral time) The integral action tends to accelerate the control action. However, since it looks only at the past values of the error, there is always a possibility of it causing the present values to overshoot the setpoint values. 7.1.3 Derivative Control Action As the name suggests, a derivative parameter generates a control action by calculating the rate of change of error. A derivative action is thus generated by multiplying the value of rate of change of error with a derivative gain Kd . Mathematical representation of the same is given below. d (7.3) D = Kd e(t) dt where, D is the derivative output Kd is the derivative gain (Kd = K p /τd , where, τd is the derivative time) The derivative action slows down the rate of change of the controller output. A derivative controller is quite useful when the error is continuously changing with time. One should, however, avoid using it alone. This is because there is no output when the error is zero and when the rate of change of error is constant. When all the above control actions are summed up and used together, the final equation becomes Z t d PID = K p e(t) + Ki e(t)dt + Kd e(t) (7.4) dt 0 102 The above equation represents an ideal form of PID controller. This means that the integral controller can be used independently. However, it is not a good decision since, the integral action begins only after the error exits for some amount of time. The proportional controller however begins as soon as the error starts existing. Hence, the integral controller is often used in conjunction with a proportional controller. This is popularly known as PI controller and the equation for Proportional Integral action becomes, Z t PI = K p e(t) + K p /τi e(t)dt (7.5) 0 ( ) Z t = K p e(t) + (1/τi ) e(t)dt (7.6) 0 Similarly, as discussed before, independent use of derivative controller is also not desirable. Moreover, if the process contains high frequency noise then the derivative action will tend to amplify the noise. Hence, derivative controller is also used in conjunction with Proportional or Proportional Integral controller popularly known as PD or PID, respectively. Therefore the equation for Proportional Derivative action becomes, d PD = K p e(t) + K p τd e(t) dt ) ( d = K p e(t) + τd e(t) dt Finally, writing the equation for PID controller, ) ( Z d 1 t PID = K e(t) + e(t)dt + τd e(t) τi 0 dt 7.2 (7.7) (7.8) (7.9) Ziegler-Nichols Rule for Tuning PID Controllers There are many rules to tune a PID controller. We shall see the two popular methods suggested by Ziegler-Nichols. 7.2.1 First Method Ziegler-Nichols rule determines the values of gain K, integral time τi and derivative time τd based on the step response characteristics of a given plant. In this 103 Figure 7.2: Reaction curve [5] method, one can experimentally obtain the response of a plant to a step input, as shown in figure 7.2. This method is applicable only when the response to the step input exhibits S-shaped curve [7]. As shown in figure 7.2, by drawing the tangent line at the inflection point and determining the intersection of the tangent line with the time axis and the line c(t) = K ,we get two constants, namely, delay time L and time constant T . Ziegler and Nichols suggested to set the values of K, τi , τd according to the formula shown in table 7.1. Notice that the PID controller tuned by the ZieglerNichols rule gives, ! 1 + Td s (7.10) Gc (s) = K p 1 + Ti s ! T 1 + 0.5Ls (7.11) = 1.2 1 + L 2Ls 2 s + L1 = 0.6T (7.12) s Thus, the PID controller has a pole at the origin and double zeros at s = −1/L. 104 Type of controller K τi τd P 1 RL ∞ 0 PI 0.9 RL 3L 0 PID 1.2 RL 2L 0.5L Table 7.1: Ziegler-Nichols tuning rule based on step response of plant K τi τd P 0.5Ku ∞ 0 PI 0.45Ku 1 P 0.2 u 0 PID 0.6Ku 0.5Pu 0.125Pu Type of controller Table 7.2: Ziegler-Nichols tuning rule for instability tuning method 7.2.2 Second Method The second method is also known as ‘instability method ’[6]. This is a closed loop method in which the integral and derivative gains of the PID controller are made zero with a unity value for proportional gain. A setpoint change is made and the temperature profile is observed for some time. The temperature would most likely maintain a steady-state with some offset. The gain is increased to a next distinct value (say 2) with a change in the setpoint. The procedure is repeated until the temperature first varies with sustained oscillations. It is necessary that the output (temperature) should have neither under damped nor over damped oscillations. At this particular frequency of sustained oscillations, the corresponding value of K p is noted and is called as the critical gain Kcr . The corresponding period of oscillation is known as Pcr . Refer to figure 7.3. The various P, PI and PID parameters are then calculated with the help of table 7.2. Using the Ziegler-Nichols method explained earlier, the following values were obtained. Refer to figure 7.4. 105 Figure 7.3: Ziegler-Nichols instability tuning method Figure 7.4: Refer to ‘Step Test’experiment [6] 106 L=6 s T = 193 s For PI K = 6.031 τi = 18 For PID K=8 τi = 12 τd = 3 While performing the experiment, fine tunning of K, τi , τd may be required. 7.3 PI Controller using Trapezoidal Approximation Figure 7.5 shows Xcos diagram for implementing PI controller. The PI controller in continuous time is given by, ( ) Z 1 t u(t) = K e(t) + e(t)dt (7.13) τi 0 On taking the Laplace transform,we obtain ( ) 1 e(t) u(t) = K 1 + τi s (7.14) By mapping controller given in equation 7.14 to the discrete time domain using trapezoidal approximation ) ( Ts z + 1 u(n) = K 1 + e(n) 2τi z − 1 107 (7.15) Figure 7.5: Xcos for PI controller available as pi ta virtual.xcos On cross multiplying, we obtain ( ) Ts (z − 1)u(n) = K (z − 1) + (z + 1) e(n) 2τi (7.16) We divide by z and then by using shifting theorem, we obtain ) Ts Ts u(n) − u(n − 1) = K e(n) − e(n − 1) + e(n) + e(n − 1) 2τi 2τi ( (7.17) The PI controller is usually written as u(n) = u(n − 1) + s0 e(n) + s1 e(n − 1) (7.18) where ! Ts s0 = K 1 + 2τi ! Ts s1 = K −1 + 2τi (7.19) (7.20) 108 7.3.1 Implementing locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is pid controller 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec pi ta.sci 6. Step6: Load Xcos code for ramp test using the command exec pi ta.xcos 7. Step7: Same The output of Xcos is shown in figure 7.6. Figure shows three plots. First sub plot shows setpoint and output temperature profile. Second sub plot shows control effort and third sub plot shows error between setpoint and plant output. 7.3.2 Implementing virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is pid controller. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the PID controller experiment directory and double-click on the file pi ta virtual.sce. This will launch scilab and also open the file pi ta virtual.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to 109 Figure 7.6: PI controller (Trapezoidal Approximation) output pid controller and then open the pi ta virtual.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file pi ta virtual.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the PI controller xcos diagram. 8. Step8: Same 7.4 Implementing PI Controller using Backward Difference Approximation The PI controller in continuous time is given by ) ( Z 1 t e(t)dt u(t) = K e(t) + τi 0 110 (7.21) On taking the Laplace transform, we obtain ( ) 1 u(t) = K 1 + e(t) τi s (7.22) By mapping controller given in equation 7.22 to the discrete time domain using Backward difference approximation: ) Ts z u(n) = K 1 + e(n) τi z − 1 ( (7.23) On cross multiplying, we get ( ) Ts (z − 1)u(n) = K (z − 1) + (z) e(n) τi (7.24) We divide by z and then by using shifting theorem, we obtain ( ) Ts u(n) − u(n − 1) = K e(n) − e(n − 1) + e(n) τi (7.25) The PI controller is usually written as u(n) = u(n − 1) + s0 e(n) + s1 e(n − 1) (7.26) where Ts s0 = K 1 + τi s1 = −K 7.4.1 ! (7.27) (7.28) Implementing locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is pid controller 111 Figure 7.7: PI controller (Backward Difference Approximation) output 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec pi bda.sci 6. Step6: Load Xcos code for ramp test using the command exec pi bda.xcos 7. Step7: Same The Xcos output is shown in figure 7.7. Figure shows three plots. First sub plot shows setpoint and output temperature profile. Second sub plot shows control effort and third sub plot shows error between setpoint and plant output. 7.4.2 Implementing virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is pid controller. Open this directory. 112 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the PID controller experiment directory and double-click on the file pi bda virtual.sce. This will launch scilab and also open the file pi bda virtual.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to pid controller and then open the pi bda virtual.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file pi bda virtual.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the PI controller xcos diagram. 8. Step8: Same 7.5 Implementing PI Controller using Forward Difference Approximation The PI controller in continuous time is given by ) ( Z 1 t e(t)dt u(t) = K e(t) + τi 0 (7.29) On taking the Laplace transform, we obtain ( ) 1 u(t) = K 1 + e(t) τi s (7.30) By mapping controller given in equation 7.30 to the discrete time domain using forward difference formula, we get ( ) Ts 1 u(n) = K 1 + e(n) τi z − 1 113 (7.31) On cross multiplying, we get ( ) Ts (z − 1)u(n) = K (z − 1) + e(n) τi We divide by z and then by using shifting theorem, we get ( ) Ts u(n) − u(n − 1) = K e(n) − e(n − 1) + e(n − 1) τi (7.32) (7.33) The PI controller is usually written as u(n) = u(n − 1) + s0 e(n) + s1 e(n − 1) (7.34) where s0 = K (7.35) s1 = K −1 + 7.5.1 Ts τi ! (7.36) Implementing locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is pid controller 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec pi fda.sci 6. Step6: Load Xcos code for ramp test using the command exec pi fda.xcos 7. Step7: Same The Xcos output is shown in figure 7.8. Figure shows three plots. First sub plot shows setpoint and output temperature profile. Second sub plot shows control effort and third sub plot shows error between setpoint and plant output. 114 Figure 7.8: PI controller implementation (Forward Difference Approximation) 7.5.2 Implementing virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is pid controller. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the PID controller experiment directory and double-click on the file pi fda virtual.sce. This will launch scilab and also open the file pi fda virtual.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to pid controller and then open the pi fda virtual.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file pi fda virtual.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 115 Figure 7.9: Xcos for PID controller available as pid bda virtual.xcos 7. Step7: Execute the PI controller xcos diagram. 8. Step8: Same 7.6 Implementing PID Controller using Backward Difference Approximation Figure 7.9 shows Xcos diagram for implementing PID controller. The PID controller in continuous time is given by ) ( Z 1 t de(t) u(t) = K e(t) + e(t)dt + τd τi 0 dt (7.37) On taking the Laplace transform, we obtain ( ) 1 u(t) = K 1 + + τd s e(t) τi s 116 (7.38) By mapping controller given in equation 7.38 to the discrete time domain using backward difference formula, we get ) τd z − 1 Ts z + e(n) u(n) = K 1 + τi z − 1 T s z ( (7.39) On cross multiplying, we obtain ) T s 2 τd 2 (z − z)u(n) = K (z − z) + z + (z − 1) e(n) τi Ts ( 2 2 (7.40) We divide by z2 and by using shifting theorem, we get ( u(n) − u(n − 1) = K e(n) − e(n − 1) + Ts e(n) τi τd + [e(n) − 2e(n − 1) + e(n − 2)] Ts ) (7.41) The PID controller is usually written as u(n) = u(n − 1) + s0 e(n) + s1 e(n − 1) + s2 e(n − 2) (7.42) where T s τd + s0 = K 1 + τi T s " # τd s1 = K −1 − 2 Ts " # τd s2 = K Ts " 7.6.1 # (7.43) (7.44) (7.45) Implementing locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is pid controller 117 Figure 7.10: PID controller (Backward Difference Approximation) output 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec pid bda.sci 6. Step6: Load Xcos code for ramp test using the command exec pid bda.xcos 7. Step7: Same The output of Xcos is shown in figure 7.10. Figure shows three plots. First sub plot shows setpoint and output temperature profile. Second sub plot shows control effort and third sub plot shows error between setpoint and plant output. 7.6.2 Implementing virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 118 1. Step1: The working directory is pid controller. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the PID controller experiment directory and double-click on the file pid bda virtual.sce. This will launch scilab and also open the file pid bda virtual.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to pid controller and then open the pid bda virtual.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file pid bda virtual.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the PI controller xcos diagram. 8. Step8: Same 7.7 Implementing PID Controller using Trapezoidal Approximation for Integral Mode and Backward Difference Approximation for the Derivative Mode The PID controller in continuous time is given by ) ( Z de(t) 1 t e(t)dt + τd u(t) = K e(t) + τi 0 dt (7.46) On taking the Laplace transform, we obtain ( ) 1 u(t) = K 1 + + τd s e(t) τi s 119 (7.47) By mapping controller given in equation 7.47 to the discrete time domain using trapezoidal approximation for integral mode and backward difference approximation for the derivative mode, we get ) T s z + 1 τd z − 1 + e(n) u(n) = K 1 + 2τi z − 1 T s z ( (7.48) On cross multiplying, we obtain ) Ts 2 τd 2 (z − z)u(n) = K (z − z) + (z + z) (z − 1) e(n) 2τi Ts ( 2 2 (7.49) We divide by z2 and then by using shifting theorem, we get ( Ts e(n) + e(n − 1) 2τi ) τd + [e(n) − 2e(n − 1) + e(n − 2)] Ts u(n) − u(n − 1) = K e(n) − e(n − 1) + (7.50) The PID controller is usually written as u(n) = u(n − 1) + s0 e(n) + s1 e(n − 1) + s2 e(n − 2) (7.51) where # T s τd s0 = K 1 + + 2τi T s # " τd Ts s1 = K −1 + −2 2τi Ts τd s2 = K Ts " 7.7.1 (7.52) (7.53) (7.54) Implementing locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is pid controller 120 Figure 7.11: PID controller (TA - BDA) implementation 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec pid ta bda.sci 6. Step6: Load Xcos code for ramp test using the command exec pid ta bda.xcos 7. Step7: Same The Xcos output is shown in figure 7.11. Figure shows three plots. First sub plot shows setpoint and output temperature profile. Second sub plot shows control effort and third sub plot shows error between setpoint and plant output. 121 7.7.2 Implementing virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is pid controller. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the PID controller experiment directory and double-click on the file pid ta bda virtual.sce. This will launch scilab and also open the file pid ta bda virtual.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to pid controller and then open the pid ta bda virtual.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file pid ta bda virtual.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the PI controller xcos diagram. 8. Step8: Same Due to the introduction of derivative action, control effort shows lots of fluctuations. By using filtered form of PID, we can make derivative mode implementable. 7.8 Implementing PID Controller with Filtering using Backward Difference Approximation Figure 7.12 shows Xcos diagram for implementing PID controller with filtering. 122 Figure 7.12: Xcos for PID controller with filtering available as pidN virtual.xcos PID filtered form is given by ) 1 τd s e(t) u(t) = K 1 + + τi s 1 + τNd s ( (7.55) where N is large number of the order of 100. By maping controller given in equation 7.55 to the discrete time domain using backward difference formula, we get −1 T 1 τ (1 − z ) s d e(n) u(n) = K 1 + + (7.56) −1 −1 ) τi 1 − z 1 + τd (1−z N ! Ts 1 Nr1 (1 − z−1 ) u(n) = K 1 + + e(n) (7.57) τi 1 − z−1 1 + r1 z−1 where r 1 = − τd N τd N + Ts (7.58) On cross multiplying, we obtain (1 − z−1 )(1 + r1 z−1 )u(n) = K[(1 − z−1 )(1 + r1 z−1 ) Ts τd + (1 + r1 z−1 ) + (1 − z−1 )2 ]e(n) τi Ts 123 (7.59) Simplifying and then by using shifting theorem, we obtain u(n) + (r1 − 1)u(n − 1) " # Ts −r1 u(n − 2) = K 1 + − Nr1 e(n) τi " # Ts + K r1 (1 + + 2N) − 1 e(n − 1) τi − K [r1 (1 + N)] e(n − 2) (7.60) Hence u(n) = r1 u(n − 2) − (r1 − 1)u(n − 1) + s0 e(n) + s1 e(n − 1) + s2 e(n − 2) (7.61) where " # Ts s0 = K 1 + − Nr1 τi " # Ts s1 = K r1 (1 + + 2N) − 1 τi s2 = −K [r1 (1 + N)] 7.8.1 (7.62) (7.63) (7.64) Implementing locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is pid controller 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec pid filter.sci 124 Figure 7.13: PID controller (with filtering) implementation 6. Step6: Load Xcos code for ramp test using the command exec pidN.xcos 7. Step7: Same The Xcos output is shown in figure 7.13. Figure shows three plots. First sub plot shows setpoint and output temperature profile. Second sub plot shows control effort and third sub plot shows error between setpoint and plant output. By comparing figure 7.10 and figure 7.13, it is clear that introduction of filtered form of PID reduces fluctuations in control effort. 7.8.2 Implementing virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is pid controller. Open this directory. 2. Step2: Same 3. Step3: Same 125 4. Step4: Switch to the PID controller experiment directory and double-click on the file pid filter virtual.sce. This will launch scilab and also open the file pid filter virtual.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to pid controller and then open the pid filter virtual.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file pid filter virtual.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the PI controller xcos diagram. 8. Step8: Same 7.9 7.9.1 Scilab Code Scilab code for serial communication Scilab Code 7.1 ser init.sci used for serial communication 1 2 3 4 5 6 mode ( 0 ) global filename m / / ** S a m p l i n g Time * * / / sampling time = 1; / / / / / / / * * * * / / / / / / / / / m=1; 7 8 9 p o r t 1 = ’ / dev / ttyUSB0 ’ ; / / F o r p o r t 2 = ’COM2 ’ ; / / F o r w i n d o w s 10 11 12 res= i n i t ([ port1 port2 ]) ; disp ( res ) 126 l i n u x u s e r s u s e r s 7.9.2 Scilab code for PI controller Scilab Code 7.2 pi ta.sci 1 2 3 mode ( 0 ) f u n c t i o n temp = p i t a ( s e t p o i n t , f a n , K, T i ) global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name temp h e a t i n f a n i n C0 u o l d u new e o l d e new 4 5 6 Ts= s a m p l i n g t i m e ; e new = s e t p o i n t − temp ; 7 8 9 10 S0=K(1+ Ts / ( 2 * T i ) ) ; S1=K* ( −1+( Ts / ( 2 * T i ) ) ) ; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 11 12 13 14 u o l d = u new ; e o l d = e new ; 15 16 17 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 18 19 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 20 21 22 m=m+1; endfunction Scilab Code 7.3 pi bda.sci 1 / / g l o b a l f a n d i s p temp heat tempdisp fan x s a m p l i n g name t i m e m h e a t d i s p Ts 2 3 4 mode ( 0 ) f u n c t i o n temp = p i b d a ( s e t p o i n t , f a n , K, T i ) 127 5 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name temp h e a t i n f a n i n C0 u o l d u new e o l d e new 6 7 8 Ts = s a m p l i n g t i m e ; e new = s e t p o i n t − temp ; 9 10 11 12 S0=K( 1 + ( Ts / T i ) ) ; S1=−K; 13 14 15 16 u new = u o l d + S0 * e new+ S1 * e o l d ; 17 18 19 20 u o l d = u new ; e o l d = e new ; 21 22 23 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 24 25 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 26 27 28 m=m+1; endfunction Scilab Code 7.4 pi fda.sci 1 2 3 mode ( 0 ) f u n c t i o n temp = p i f d a ( s e t p o i n t , f a n , K, T i ) global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name temp h e a t i n f a n i n C0 u o l d u new e o l d e new 4 5 6 Ts= s a m p l i n g t i m e ; e new = s e t p o i n t − temp ; 128 7 8 9 10 11 S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 12 13 14 u o l d = u new ; e o l d = e new ; 15 16 h e a t = u new ; 17 temp = comm ( h e a t , f a n ) ; 18 19 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 20 21 22 23 m=m+1; endfunction 7.9.3 Scilab code for PID controller Scilab Code 7.5 pid bda.sci 1 mode ( 0 ) 2 3 4 f u n c t i o n [ temp ] = p i d b d a ( s e t p o i n t , f a n , K, Ti , Td ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 5 6 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 7 8 e new = s e t p o i n t − temp ; 9 10 Ts= s a m p l i n g t i m e ; 11 12 13 S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; 129 14 S2=K * ( Td / Ts ) ; 15 16 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 17 18 19 20 u o l d = u new ; e old old = e old ; e o l d = e new ; 21 22 23 24 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 25 26 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 27 28 29 m=m+1; endfunction Scilab Code 7.6 pid ta bda.sci 1 2 mode ( 0 ) 3 4 5 f u n c t i o n [ temp ] = p i d t a b d a ( s e t p o i n t , f a n , K, Ti , Td ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 6 7 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 8 9 e new = s e t p o i n t − temp ; 10 11 Ts= s a m p l i n g t i m e ; 12 13 14 15 16 S0=K * ( 1 + ( Ts / ( 2 * T i ) ) +( Td / Ts ) ) ; S1=K* ( −1+( Ts / ( 2 * T i ) ) −(2 * Td / Ts ) ) ; S2 =(K* Td / Ts ) ; u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 130 17 18 19 20 u o l d = u new ; e old old = e old ; e o l d = e new ; 21 22 23 h e a t = u new ; 24 25 temp = comm ( h e a t , f a n ) ; 26 27 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 28 29 30 m=m+1; endfunction Scilab Code 7.7 pid filter.sci 1 mode ( 0 ) 2 3 4 f u n c t i o n temp = p i d ( s e t p o i n t , f a n , K, Ti , Td , N) global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name temp h e a t i n f a n i n C0 u o l d u new e o l d e new e o l d o l d r 1 u o l d o l d 5 6 7 Ts = s a m p l i n g t i m e ; e new = s e t p o i n t − temp ; 8 9 r 1 = −(( Td / N) / ( ( Td / N) +Ts ) ) ; 10 11 12 13 S0=K * ( 1 + ( Ts / T i ) −(N* r 1 ) ) ; S1=K * ( ( r 1 * ( 1 + ( Ts / T i ) +(2 *N) ) ) −1) ; S2=−K* r 1 * (1+N) ; 14 15 u new = r 1 * u o l d o l d −( r1 −1) * u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 16 17 u old old = u old ; 131 18 19 20 u o l d = u new ; e old old = e old ; e o l d = e new ; 21 22 23 h e a t = u new ; 24 temp = comm ( h e a t , f a n ) ; 25 26 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 27 28 29 30 m=m+1; endfunction Scilab Code 7.8 pid bda virtual.sce 1 2 mode ( 0 ) ; / / For s c i l a b command to 5 . 1 . 1 open or lower s c i c o s v e r s i o n diagrams users i n s t e a d , use of s c i c o s xcos 3 4 g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 5 6 / / ********************** 7 s a m p l i n g t i m e =1; 8 / / * * * * * * * * * * * * * * * * * * * * * * / / / / In seconds . F r a c t i o n s are allowed 9 10 exec ( ” p i d b d a v i r t u a l . s c i ” ) ; 11 12 ok = i n i t ( ) ; 13 14 i f ok ˜= [ ] through 15 16 17 18 / / ( ie open xcos only if r e p l y has come from xcos ( ’ p i d b d a v i r t u a l . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 132 communication s e r v e r ) is 19 end Scilab Code 7.9 pid bda virtual.sci 1 mode ( 0 ) ; 2 / / PI 3 / / Heater 4 / / Fan C o n t r o l l e r i n p u t i n t r o d u c e at i n p u t is 5 / / Range 6 / / Te mper atur e Fan t r a p e z o i d a l passed c o n t r o l is c o n s t a n t of using passed as e f f o r t as i n p u t a p p r o x i m a t i o n . argument to u ( n ) i n p u t argument which is kept l e v e l i n p u t is :20 to 252 read 7 8 f u n c t i o n [ s t o p ] = p i d b d a v i r t u a l ( s e t p o i n t , f a n , K, Ti , Td ) 9 10 g l o b a l temp h e a t C0 u o l d u new e o l d e new f d f h f d t f n c r fncw m e r r c o u n t s t o p q h e a t d i s p f a n d i s p tempdisp s e t p o i n t d i s p l i m i t s m x sampling time e old old 11 12 e new = s e t p o i n t − temp ; 13 14 15 16 17 18 Ts =1; S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 19 20 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 21 22 h e a t =u new ; 23 24 25 26 u o l d = u new ; e old old = e old ; e o l d = e new ; 27 133 28 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 29 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 30 31 endfunction 134 Chapter 8 Two Degrees of Freedom (2-DOF) Controller In this chapter, we discuss the implementation of a 2-DOF controller using the SBHS. We also cover the basics of 2-DOF controller theory and design. 8.1 Introduction to 2-DOF Controller Controllers are broadly divided into two categories: feedback and feed forward controllers. Feed forward controllers are those that take control action before a disturbance affects the plant. But this requires an ability to sense the disturbance accurately. Moreover, exact knowledge of the plant is also needed. As a result, a feed forward control strategy is rarely used alone. A feedback control strategy is shown in figure 8.1. The reference r and the output y are continuously compared to generate error e, which is fed to the controller Gc (z), to take appropriate control action. u is the controller output that is fed to the plant. Unlike feed forward controllers, exact knowledge of the plant G(z) and the disturbance v is not necessary in this case. Feedback controllers are further classified as One Degree of Freedom (1-DOF) controllers and Two Degrees of Freedom (2-DOF) controllers. Degree of freedom refers to the number of parameters that are free to vary in a system. A higher degree of freedom controller makes the plant less susceptible to disturbances. 135 v e r Gc (z) u G(z) y − Figure 8.1: Feed back control strategy The expression for output, Y(z) of the system shown in figure 8.1 is given by Y(z) = G(z)Gc (z) 1 R(z) + V(z) 1 + G(z)Gc (z) 1 + G(z)Gc (z) (8.1) This expression can be written in mixed notation [5] as y(n) = G(z)Gc (z) 1 r(n) + v(n) 1 + G(z)Gc (z) 1 + G(z)Gc (z) (8.2) T (z) = G(z)Gc (z) 1 , S (z) = 1 + G(z)Gc (z) 1 + G(z)Gc (z) (8.3) Let, Therefore, y(n) = T (z)r(n) + S (z)v(n) (8.4) The controller has to track the reference input as well as eliminate the effect of external disturbance. So ideally, we want T = 1 and S = 0. But, it is not possible to achieve both the requirements simultaneously using this control strategy. This control strategy is called One Degree of Freedom, abbreviated as 1-DOF. A Two Degrees of Freedom controller is as shown in figure 8.2. Here, Gb and G f together constitute the controller. Gb is in the feedback path and is used to eliminate the effect of disturbances, whereas G f is in the feed forward path and is used to help the output track the reference input. The expression for control effort u in figure 8.2 is given by u(n) = r(n)G f − y(n)Gb 136 (8.5) d H v r Gf u − y G Gb Figure 8.2: 2DOF feed back control strategy Let Gb = Sc Tc ,Gf = Rc Rc (8.6) where Rc , S c and T c are polynomials in z−1 . We get Rc (z)u(n) = T c (z)r(n) − S c (z)y(n) (8.7) Consider a plant whose model is given by A(z)y(n) = z−k B(z)u(n) + v(n) Substituting equation 8.7 in equation 8.8, we get −k B Ay(n) = z T c r(n) − S c y(n) + v(n) Rc (8.8) (8.9) Solving for y(n), R A + z−k BS BT c c c r(n) + v(n) y(n) = z−k Rc Rc 137 (8.10) This can also be written as y(n) = z−k Rc BT c r(n) + v(n) φcl φcl (8.11) where φcl is the closed loop characteristic polynomial given by φcl = Rc (z)A(z) + z−k B(z)S c (z) (8.12) We want the following conditions to be satisfied while designing a controller. 1. The zeros of φcl should be inside the unit circle, so that the closed-loop system becomes stable 2. The value of z−k BT c must be close to unity, so that reference tracking is φcl achieved 3. The value of Rc must be as small as possible to achieve disturbance rejecφcl tion We shall now see the pole placement controller approach to design a 2-DOF controller. 8.2 2-DOF Controller Design using the Pole Placement Method [5] A 2-DOF pole placement controller is shown in figure 8.3. We will not consider the effect of external disturbance in the design. The controller will be designed for setpoint tracking. We want the desired output, Ym , of the system to be related to the setpoint R in the following manner: Ym (z) = γz−k Br R(z) φcl (8.13) φcl is the desired closed loop characteristic polynomial obtained from the desired region analysis. Please refer to [5] for more information on desired region analysis. γ is chosen such that Ym equals the setpoint at steady-state. Therefore γ is given by, γ= 138 φcl (1) Br (1) (8.14) r γ T c (z) Rc (z) u − G = z−k B(z) A(z) y S c (z) Rc (z) Figure 8.3: 2-DOF pole placement controller Simplifying the block diagram shown in figure 8.3 yields Y = γz−k BT c R ARc + z−k BS c (8.15) We have dropped the argument of z for convenience We want the output Y of the system to be equal to the desired output Ym . Equating equations 8.13 and 8.15 we get Br BT c = −k ARc + z BS c φcl (8.16) We can expect some cancelations between the numerator and the denominator polynomials in the LHS, thereby making degBr < degB. But the cancelations, if any, must be between stable poles and zeros. One should avoid the cancelation of an unstable pole with an unstable zero. Let us split the factors of the numerator and denominator polynomials, B and A, of the plant into good and bad factors. Therefore, we write A and B as A = Ag Ab , B = Bg Bb (8.17) We also define Rc , S c and T c as Rc = Bg R1 S c = Ag S 1 T c = Ag T 1 139 (8.18) (8.19) (8.20) Hence, equation 8.16 becomes Br Bg Bb Ag T 1 = g b g −k g b g A A B R1 + z B B A S 1 φcl (8.21) After cancelling out the common factors, we obtain Bb T 1 Br = b −k b A R1 + z B S 1 φcl (8.22) Bb T 1 = Br (8.23) Ab R1 + z−k Bb S 1 = φcl (8.24) We obtain, Equation 8.24 is known as the Aryabhatta’s identity and can be used to solve for R1 and S 1 . One can choose T 1 in many ways. If we choose T 1 = S 1 the 2-DOF controller is reduced to a 1-DOF controller. Let us choose T 1 = 1. Therefore equation 8.23 becomes Bb = Br (8.25) The expression for γ now becomes γ= φcl(1) Bb (1) (8.26) and the desired closed loop transfer function will be Ym (z) Bb = γz−k R(z) φcl (8.27) One can see that the open loop plant model imposes two limitations on the closed loop transfer function. 1. The bad portion of the open loop model cannot be canceled out and it appears in the closed loop model. 2. The open loop plant delay cannot be removed or minimized, i.e., the closed loop model cannot be made faster than the open loop model. 140 8.3 2-DOF Pole Placement Controller Design and Implementation using SBHS We obtain a first order transfer function of the plant using the step test approach. Refer to the chapter on Step Test using SBHS for more details. The model obtained is G(s) = 0.42 35.61s + 1 (8.28) with a time constant of τ = 35.6s and gain K = 0.42 After discretization with sampling time = 1 s, we obtain G(z) = 0.0116304z−1 1 − 0.9723086z−1 (8.29) Refer to the Scilab code myc2d.sci 1 . We shall now define good and bad factors as Ag = 1 − 0.9723086z−1 Ab = 1 Bg = 0.0116304 Bb = 1 Let us now define the transient specifications. We choose Rise Time =100 s and Overshoot ()= 5%. Number of samples in one rise time (Nr ), [5], is calculated as Rise time Sampling time = 100 π ∴, ω = 2Nr = 0.015708 Nr ≤ 1 Go the folder dc inside the 2dof controller folder. Now go to the folder scilab and locate myc2d.sci 141 and ρ ≤ ω/π = 0.98513 The closed loop characteristic polynomial is given by, φcl = 1 − 2ρcosωz−1 + ρ2 z−2 = 1 − 1.9700229z−1 + 0.9704870z−2 Refer to the Scilab code desired.sci to calculate Nr , ω, ρ and φcl . The code is available in the same location as myc2d.sci. But according to equation 8.24, Ab R1 + z−k Bb S 1 = φcl Recall that we have not considered external disturbance in the block diagram shown in figure 8.3. However, we can still up to some extent take care of the disturbances. This is achieved by using the Internal Model Principle. If a model of step is present inside the loop, step disturbances can be rejected [5]. We can apply this by forcing Rc to have this term. A step model is given by 1(z) = 1 1 = −1 1−z ∆ Therefore, Rc = Bg ∆R1 ∆ has a root which lies on the unit circle. Hence it has to be treated as a bad part and should not be canceled out. Hence, we should make sure that all of the occurrences of R1 have this term. Therefore, φcl = Ab ∆R1 + z−k Bb S 1 142 (8.30) Hence, Ab ∆R1 + z−k Bb S 1 = 1 − 1.9700229z−1 + 0.9704870z−2 (8.31) is expression is known as the Aryabhatta Identity and is solved using rigorous matrix calculations. The explanation of this operation is not considered here. Refer to [5] for more details on Aryabhatta’s Identity. Refer to the Scilab code pp im.sci, which is used to split the denominator and numerator polynomials of the plant transfer function into good and bad factors, and solving the Aryabhatta’s Identity given in equation 8.31. On solving equation 8.31, we get Rc = 0.0116304 − 0.0229175z−1 + 0.0112871z−2 S c = 0.0004641 − 0.0004512z−1 T c = 1 − 0.9723z−1 γ = 0.0004641 All the above calculations are incorporated into a single Scilab code named twodof para.sce 2 . 8.3.1 Procedure to calculate 2DOF parameters using scilab The procedure explained here is applicable to both virtual as well as local experiments. The following steps must be executed properly to calculate the controller parameters. 1. Change the directory to 2dof controller. 2. Execute the command getd dc/scilab in the scilab console. 3. Open the Scilab code twodof para.sce. Define the variable TFcont with first order transfer function (or second order transfer function) of your SBHS. Execute the Scilab code. With this, the 2-DOF controller parameters have been calculated. Figure 8.6 shows the calculated 2-DOF controller parameters on the Scilab console. 4. Open the Scilab code twodof.sci. Make sure that the first order control law (or second order control law in case of second order plant transfer function) is uncommented and the second order control law (or first order control law in case of second order transfer function) is commented. 2 All the Scilab codes are given at the end of this chapter in the section 8.6 143 8.4 Implementing 2DOF controller locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is 2dof controller 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load 2DOF controller function by executing command exec twodof.sci. Make sure the correct order of control law is choosen in this file as explained in section 8.3.1 6. Step6: Load Xcos code for 2DOF controller using the command exec twodof.xcos. In the twodof.xcos Xcos file, change the setpoint to the desired value. Make sure the period of the clock block is the same as the sampling time used for discretisation. The Xcos diagram is shown in figure 8.7. 7. Step7: Same 8.4.1 Implementing 2-DOF Controller on SBHS, Virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is 2dof controller. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the 2dof controller experiment directory and double-click on the file twodof.sce. This will launch scilab and also open the file twodof.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to 2dof controller and then open the twodof.sce file in the scilab editor. 144 5. Step5: Same 6. Step6: Execute the file twodof.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the PI controller xcos diagram. 8. Step8: Same 8.5 Performing pure simulation of 2DOF controller You can also use the Xcos file twodof simulation.xcos, shown in figure 8.4, to simulate your controller before implementing on SBHS. This will help you validate your controller. You need to execute getd dc/scilab and then execute the file twodof para.sce. Now run twodof simulation.xcos. Figure 8.5 shows the simulation results. Note that, execution of this Xcos file is not mandatory for performing a virtual experiment. The performance of the controller is shown in figure 8.8. It is seen that the output (temperature) tracks the setpoint irrespective of the step changes in the fan speed. We see that the overshoot turns out to be 6% and rise time turns out to be 60 seconds, which is acceptable. 8.6 Scilab Code for Local Experiment Scilab Code 8.1 twodof para.sce 1 2 3 4 5 mode ( 0 ) s=%s ; z=%z ; g l o b a l Rc Sc Tc gamm / / TFcont = s y s l i n ( ’ c ’ , −280.14/(( s −31.32) *( s +100) *( s +31.32) ) ) ; 6 / / TFcont second 7 8 = s y s l i n ( ’ c ’ , 0 . 6 6 7 / ( ( 7 3 . 5 * s +1) *(1* s +1) ) ) / / order T F c o n t = s y s l i n ( ’ c ’ , 0 . 6 6 8 / ( 7 5 . 0 1 3 * s +1) ) SScont = t f 2 s s ( TFcont ) ; 145 / / f i r s t order Figure 8.4: Xcos diagram for simulating 2-DOF controller 146 Figure 8.5: Simulation results after executing twodof simulation.xcos 9 10 11 / / TFdisc = s s 2 t f ( SScont ) ; Ts = 0 . 5 ; [ B , A, k ] = myc2d ( SScont , Ts ) ; 12 13 14 15 / / p o l y n o m i a l s are r e t u r n e d [ Ds , num , den ] = s s 2 t f ( S S c o n t ) ; num = c l e a n ( num ) ; den = c l e a n ( den ) ; 16 17 18 19 / / T r a n s i e n t s p e c i f i c a t i o n s r i s e = 35; epsilon = 0.05; p h i = d e s i r e d ( Ts , r i s e , e p s i l o n ) ; 20 21 22 23 / / C o n t r o l l e r design Delta = [1 −1]; [ Rc , Sc , Tc , gamm ] = pp im ( B , A, k , p h i ) ; / / with i n t e g r a l 24 25 / / 26 st = 0.0001; S e t t i n g up s i m u l a t i o n / / d e s i r e d p a r a m e t e r s change 147 in h , for in b a s i c . cos m. Figure 8.6: Scilab output for twodof para.sce 148 Figure 8.7: Xcos diagram for 2-DOF controller 149 Figure 8.8: Implementation of 2-DOF controller 150 27 28 t i n i t = 0; / / t final = 0.5; s i m u l a t i o n / / s t a r t s i m u l a t i o n time end time 29 30 31 / / S e t t i n g up s i m u l a t i o n p a r a m e t e r s for c 32 33 34 [ Tc1 , Rc1 ] = c o s f i l i p ( Tc , Rc ) ; [ Sc2 , Rc2 ] = c o s f i l i p ( Sc , Rc ) ; / / Tc / Rc / / Sc / Rc 35 36 37 [ Bp ] = c o s f i l i p ( B , 1 ) ; [ Ap ] = c o s f i l i p (A, 1 ) ; 38 39 40 41 42 [ Tcp1 , Tcp2 ] = c o s f i l i p ( Tc , 1 ) ; / / [ Np , Rcp ] = c o s f i l i p (N, Rc ) ; / / 1 / [ Scp1 , Scp2 ] = c o s f i l i p ( Sc , 1 ) ; / / [ Cp , Dp ] = c o s f i l i p ( C , D) ; / / C / D Tc / 1 Rc Sc /1 43 44 / / Rc1 = Rc ( 1 ) ; Rc2 = Rc ( 2 ) ; Rc3 = Rc ( 3 ) ; Rc4 = Rc ( 4 ) ; 45 / / Sc1 = Sc ( 1 ) ; Sc2 = Sc ( 2 ) ; 46 / / Sc3 = Sc ( 3 ) ; 47 / / Tc1 = Tc ( 1 ) ; Tc2 = Tc ( 2 ) ; 48 49 50 51 52 s s c l . cos N var = 0 ; x I n i t i a l = [0 0 0 ] ; N = 1 ; C = 0 ; D = 1 ; / / Tc3 = Tc ( 3 ) ; d i s p ( Rcp , ’ Rc = ’ ) d i s p ( Scp1 , ’ Sc = ’ ) d i s p ( Tcp1 , ’ Tc = ’ ) d i s p ( gamm , ’gamma = ’ ) 53 54 55 56 / / u o l d o l d 57 / / u old = 58 / / r o l d o l d 59 / / r o l d = 60 / / y o l d o l d 61 / / y old = = 1; = 1; = 1; 1; 1; 1; Scilab Code 8.2 twodof.sci 151 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = t w o d o f ( s e t p o i n t , f a n ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 4 5 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 6 7 g l o b a l temp u o l d o l d u o l d r o l d o l d r o l d y o l d o l d y o l d u new h e a t r n e w y new 8 9 Ts= s a m p l i n g t i m e ; 10 11 12 13 r new = s e t p o i n t ; y new = temp ; e t = s e t p o i n t −temp ; 14 15 / / u new = ( 1 / Rc ( 1 ) ) * ( gamm * Tc ( 1 ) * r + r old − Sc ( 3 ) * y o l d o l d ) ; / / second r o l d y u o l d o l d * Tc ( 3 ) * gamm o l d o l d − order − new + gamm * Tc ( 2 ) * Sc ( 1 ) * y Rc ( 2 ) * u old c o n t r o l law new − − Sc ( 2 ) * Rc ( 3 ) * 16 17 u new = ( 1 / Rc ( 1 ) ) * ( gamm * Tc ( 1 ) * r n e w + gamm* Tc ( 2 ) * r o l d −Sc ( 1 ) * y new −Sc ( 2 ) * y o l d −Rc ( 2 ) * u o l d − Rc ( 3 ) * u old old ) ; / / f i r s t o r d e r c o n t r o l law 18 19 20 21 22 23 24 u u r r y y old old old old old old old = u old ; = u new ; old=r old ; = r new ; old=y old ; = y new ; 25 26 27 28 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 29 30 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 152 100 40 1 0 0 0 ] ) 31 32 33 m=m+1; endfunction Scilab Code 8.3 start.sce 1 2 3 getd . . / common files / g e t d dc / s c i l a b exec . . / common files / l o a d e r . sce 4 5 exec s e r i n i t . sce 6 7 8 exec twodof para . sce exec twodof . s c i 9 10 xcos twodof . xcos Scilab Code 8.4 cindep.sci 1 / / Updated −−−− No 2 / / f u n c t i o n 3 / / used are 4 / / be / / 6 = cindep ( + YN = is The dependent and if sent in C . S , gap ) a l l rows aim is so on 9 10 11 12 13 14 15 the l a s t of how . to check if the l a s t the The b f u n c t i o n b = c i n d e p ( S , gap ) 7 8 except to i n d e p e n d e n t . r e s t is b XD assumed row 5 in change i f argn ( 2 ) == 1 gap = 1 . 0 e8 ; end e p s = 2 . 2 2 0 4 e −016; [ rows , c o l s ] = s i z e ( S ) ; i f rows > c o l s ind = 0; else 153 c o e f f i c i e n t s of dependence s i g m a = svd ( S ) ; l e n = l e n g t h ( sigma ) ; i f ( s i g m a ( l e n ) / s i g m a ( 1 ) <= ( e p s * max ( i , c o l s ) ) ) ind = 0; / / not i n d e p e n d e n t else i f o r ( s i g m a ( 1 : l e n −1) . / s i g m a ( 2 : l e n )>=gap ) ind = 0; / / not dependent else ind = 1; / / i n d e p e n d e n t end end 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 end i f ind b = []; else b = S ( rows , : ) / S ( 1 : rows − 1 , : ) ; b = m a k e z e r o ( b , gap ) ; end endfunction Scilab Code 8.5 clcoef.sci 1 / / Updated 2 / / H . 3 / / Modified −−−−− No Kwakernaak , by change July , Kannan 1990 Moudgalya in Nov . 4 5 f u n c t i o n [ P , degP ] = c l c o e f (Q, degQ ) 6 7 [ rQ , cQ ] = p o l s i z e (Q, degQ ) ; 8 9 10 11 12 13 14 15 16 i f and ( and (Q==0) ) P = z e r o s ( rQ , cQ ) ; degP = 0 ; else P = Q; degP = degQ ; r P = rQ ; cP = cQ ; j = degP +1; w h i l e j >= 0 X = P ( : , ( j −1) * cP +1: j * cP ) 154 1992 17 18 19 20 21 22 23 24 25 26 i f max ( sum ( abs (X’ ) ) ) < ( 1 e −8) * max ( sum ( abs ( P ) ) ) P = P ( : , 1 : ( j −1) * cP ) ; degP = degP −1; else j = 0; end j = j −1; end end endfunction Scilab Code 8.6 colsplit.sci 1 / / c o l s p l i t 2 / / The 3 / / 4 / / 5 / / command = [ P1 , d e g P 1 , P2 , d e g P 2 ] produces two c o n s i s t s of p1 columns columns of p o l y n o m i a l the of P c o l s p l i t ( P , d e g P , p1 , p 2 ) matrix P1 and P2 . P1 f i r s t and P2 c o n s i s t s of the r e m a i n i n g p2 P . 6 7 / / H . Kwakernaak , July , 1990 8 9 10 f u n c t i o n [ P1 , degP1 , P2 , degP2 ] = c o l s p l i t ( P , degP , p1 , p2 ) 11 12 13 14 15 16 i f isempty (P) P1 = [ ] ; P2 = [ ] ; degP1 = 0 ; degP2 = 0 ; return ; end 17 18 19 20 21 22 23 [ rP , cP ] = p o l s i z e ( P , degP ) ; i f p1 < 0 | p1 > cP | p2 < 0 | p2 > cP | p1+p2 ˜= cP e r r o r ( ’ c o l s p l i t : I n c o n s i s t e n t numbers o f c o l u m n s ’ ) ; end r P 1 = r P ; r P 2 = r P ; cP1 = p1 ; cP2 = p2 ; degP1= degP ; degP2 = degP ; 155 24 25 26 27 28 29 30 31 32 33 34 35 36 i f p1 == 0 P1 == [ ] ; P2 = P ; e l s e i f p2 == 0 P1 = P ; P2 = [ ] ; else P1 = z e r o s ( rP1 , ( degP1 +1) * cP1 ) ; P2 = z e r o s ( rP2 , ( degP2 +1) * cP2 ) ; f o r i = 1 : degP +1 P1 ( : , ( i −1) * cP1 +1: i * cP1 ) = P ( : , ( i −1) * cP + 1 : ( i −1) * cP+cP1 ) ; P2 ( : , ( i −1) * cP2 +1: i * cP2 ) = P ( : , ( i −1) * cP+cP1 +1: i * cP ) ; end end endfunction ; Scilab Code 8.7 cosfil ip.sci 1 / / 2 / / Input 3 / / polynomials 4 / / powers of 6 / / Scicos blocks 7 / / with Updated (31 −7 −07) arguments ’ co are numerator e f f i c i e n t s in and d e n o m i n a t o r a s c e n d i n g z ˆ −1 5 p o s i t i v e need i n p u t powers of p o l y n o m i a l s z 8 9 f u n c t i o n [ nume , deno ] = c o s f i l i p ( num , den ) 10 11 12 13 14 [ Nn , Nd ] = p o l y n o ( num , ’ z ’ ) ; [ Dn , Dd ] = p o l y n o ( den , ’ z ’ ) ; nume = Nn * Dd ; deno = Nd * Dn ; 15 16 endfunction ; Scilab Code 8.8 indep.sci 156 1 / / 2 / / f u n c t i o n 3 / / d e t e r m i n e s 4 / / 5 f u n c t i o n b = i n d e p ( S , gap ) Updated p r e v i o u s The −−−− No b = change indep (S , gap ) the rows f i r s t of S . c o e f f i c i e n t s of row t h a t dependence is is dependent on the r e t u r n e d in b 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 i f argn ( 2 ) == 1 gap = 1 . 0 e8 ; end [ rows , c o l s ] = s i z e ( S ) ; ind = 1; i = 2; e p s = 2 . 2 2 0 4 e −016; w h i l e i n d & i <= rows s i g m a = svd ( S ( 1 : i , : ) ) ; l e n = l e n g t h ( sigma ) ; i f ( s i g m a ( l e n ) / s i g m a ( 1 ) < ( e p s * max ( i , c o l s ) ) ) i n d =0; else s h s i g = [ sigma ( 2 : l e n ) ; sigma ( l e n ) ] ; i f o r ( ( s i g m a . / s h s i g ) > gap ) ind = 0; else ind = 1; i = i +1; end end 28 29 30 end i f ind b =[]; 31 32 33 else c = S( i , : ) /S (1: i −1 ,:) ; c = m a k e z e r o ( c , gap ) ; b = [−c 1 ] ; 34 35 36 37 end 157 38 endfunction Scilab Code 8.9 left prm.sci 1 / / f u n c t i o n 2 / / l e f t 3 / / 4 / / 5 / / job 6 / / t h i s 7 / / 8 / / = [ B , degB , A , degA , Y , degY , X , degX ] . . . p r m ( N , degN , D , degD , job , g a p ) does t h a t t h r e e d i f f e r e n t ’ job ’ t a k e s = t h i n g s a c c o r d i n g to i n t e g e r s 1. is the d e f a u l t . It is always done for a l l jobs . −1 −1 −1 Given ND , r e t u r n s coprime B and A where = ND A B 9 / / It is enough if one sends the f i r s t four i n p u t arguments 10 / / e i t h e r 1 11 / / e n t r y for If gap 12 / / job 13 / / f i r s t 14 / / job is = 15 / / used / / a f t e r 17 / / 18 / / 19 / / 20 / / 21 / / 22 / / or a to be sent , then one can send n u l l job 2. solve = 16 r e q u i r e d for = job 1 and then solve XA + YB = I 3. in s o l v i n g f i n d i n g XD + coprime YN = C f a c t o r i z a t i o n , data are r e t u r n e d c o n v e n t i o n : the v a r i a b l e with p r e f i x deg stand for d e g r e e s of the c o r r e s p o n d i n g p o l y n o m i a l m a t r i c e s i n p u t : N : r i g h t 23 / / D : 24 / / N 25 / / gap : is f r a c t i o n r i g h t and D numerator f r a c t i o n are not v a r i a b l e p o l y n o m i a l d e n o m i n a t o r n e c c e s s a r i l y used to zero 1 . 0 e +8 158 matrix p o l y n o m i a l matrix coprime e n t r i e s ; d e f a u l t value 26 / / 27 / / o u t p u t 28 / / b 29 / / X and A are l e f t coprime are s o l u t i o n s num . and den . p o l y n o m i a l m a t r i c e s and for Y job = to A r y a b h a t t a i d e n t i t y , only 2 30 31 32 33 34 35 36 37 38 39 f u n c t i o n [ B , degB , A, degA , Y, degY , X, degX ] = l e f t p r m (N, degN , D, degD , j o b , gap ) i f argn ( 2 ) == 4 | argn ( 2 ) == 5 gap = 1 . 0 e8 ; end / / pause i f argn ( 2 ) == 4 , j o b = 1 ; end [ F , degF ] = r o w j o i n (D, degD , N, degN ) ; [ Frows , F b c o l s ] = p o l s i z e ( F , degF ) ; block 40 F c o l s = F b c o l s * ( degF +1) ; columns 41 42 43 45 Fbcols / / a c t u a l of = F T1 = [ ] ; p r = [ ] ; degT1 = 0 ; T1rows = 0 ; s h f t = 0 ; S=F ; s e l = o n e s ( Frows , 1 ) ; T 1 b c o l s =1; a b a r = ( F b c o l s + 1 ) : Frows ; / / a s u p e r of 44 / / columns b a r B−C . Chang w h i l e i s e m p t y ( T1 ) | T1rows < Frows − F b c o l s Srows = Frows * T 1 b c o l s ; / / m a x a c t u a l columns of r e s u l t 46 47 48 49 50 51 [ T1 , T1rows , s e l , p r ] = . . . t 1 c a l c ( S , Srows , T1 , T1rows , s e l , pr , Frows , F b c o l s , a b a r , gap ) ; [ T1rows , T 1 c o l s ] = s i z e ( T1 ) ; i f T1rows < Frows − F b c o l s T1 = [ T1 z e r o s ( T1rows , Frows ) ] ; T1bcols = T1bcols + 1; / / max . block columns 52 of r e s u l t degT1 = degT1 + 1 ; / / r e s u l t 53 s h f t = s h f t +Fbcols ; 159 degree of S = seshft (S ,F , shft ) ; s e l = [ s e l ; s e l ( Srows −Frows +1: Srows ) ] ; rowvec = ( T 1 b c o l s −1) * Frows +( F b c o l s +1) : T 1 b c o l s * Frows ; a b a r = [ a b a r rowvec ] ; / / A s u p e r b a r 54 55 56 57 of end 58 59 B−C . c h a n g end 60 61 62 63 64 65 66 67 [ B , degB , A, degA ] = c o l s p l i t ( T1 , degT1 , F b c o l s , Frows − Fbcols ) ; [ B , degB ] = c l c o e f ( B , degB ) ; B = −B ; [A, degA ] = c l c o e f (A, degA ) ; / / pause i f j o b == 2 S = S( mtlb logical ( sel ) ,:) ; / / 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 columns [ redSrows , S c o l s ] = s i z e ( S ) ; C = [ eye ( Fbcols , Fbc ols ) zeros ( Fbcols , Scols − Fbcols ) ] ; / / append with zeros T2 = C / S ; T2 = m a k e z e r o ( T2 , gap ) ; T2 = m o v e s c i ( T2 , f i n d ( s e l ) , Srows ) ; [X, degX , Y, degY ] = c o l s p l i t ( T2 , degT1 , F b c o l s , Frows − Fbcols ) ; [X, degX ] = c l c o e f (X, degX ) ; [Y, degY ] = c l c o e f (Y, degY ) ; e l s e i f j o b == 3 Y = S; degY = s e l ; X = degT1 ; degX = F b c o l s ; else i f j o b ˜= 1 e r r o r ( ’ Message from l e f t p r m : no l e g a l j o b number s p e c i f i e d ’ ) end 160 85 86 end endfunction Scilab Code 8.10 makezero.sci 1 / / Updated 2 / / f u n c t i o n 3 / / where B B = makezero (B , gap ) is a v e c t o r and gap a c t s as a t o l e r a n c e 4 5 f u n c t i o n B = m a k e z e r o ( B , gap ) 6 7 8 9 10 11 i f argn ( 2 ) == 1 gap = 1 . 0 e8 ; end temp = B( f i n d (B) ) ; temp = − g s o r t ( − abs ( temp ) ) ; in 12 13 14 15 16 17 18 19 20 d e s c e n d i n g / / non / / zero e n t r i e s a b s o l u t e of v a l u e s B s o r t e d order l e n = l e n g t h ( temp ) ; r a t i o = temp ( 1 : l e n −1) . / temp ( 2 : l e n ) ; / / e a c h m i n i n d = min ( f i n d ( r a t i o >gap ) ) ; i f ˜ isempty ( min ind ) o u r e p s = temp ( m i n i n d +1) ; z e r o i n d = f i n d ( abs (B)<= o u r e p s ) ; B( z e r o i n d ) = z e r o s ( 1 , l e n g t h ( z e r o i n d ) ) ; end endfunction r a t i o >1 Scilab Code 8.11 move sci.sci 1 / / f u n c t i o n 2 / / Moves 3 / / decided 4 / / The 5 / / r e s u l t matrix i n f o r m a t i o n and b is by matrix max b on the = to number to i n d i c e s of sci ( b , nonred , max matrix where r e s u l t augumented move w i l l r e s u l t with sci ) the move , of nonred . have as many rows as b has columns . with zeros columns ; 161 to have nonred number of 6 / / The columns decided by of b put i n t o those of r e s u l t as nonred . 7 8 9 10 11 12 13 f u n c t i o n r e s u l t = move sci ( b , nonred , max sci ) [ brows , b c o l s ] = s i z e ( b ) ; b = [ b z e r o s ( brows , l e n g t h ( n o n r e d ) − b c o l s ) ] ; r e s u l t = z e r o s ( brows , m a x s c i ) ; r e s u l t ( : , nonred ’ ) = b ; endfunction Scilab Code 8.12 polisize.sci 1 / / 2 3 Updated −−−− / / f u n c t i o n [ rQ , cQ ] = / / FUNCTION p o l s i z e TO 4 / / OF A 5 / / 6 / / H . Kwakernaak , No POLYNOMIAL change p o l s i z e (Q , degQ ) DETERMINE THE DIMENSIONS MATRIX August , 1990 7 8 f u n c t i o n [ rQ , cQ ] = p o l s i z e (Q, degQ ) 9 10 11 12 13 14 15 16 [ rQ , cQ ] = s i z e (Q) ; cQ = cQ / ( degQ +1) ; i f abs ( round ( cQ ) −cQ ) > 1 e −6 error ( ’ p o l s i z e : Degree of i n p u t i n c o n s i s t e n t with number o f c o l u m n s ’ ) ; else cQ = round ( cQ ) ; end endfunction Scilab Code 8.13 polyno.sci 1 / / Updated (1 −8 −07) 2 / / O p e r a t i o n s : 3 / / Polynomial 4 / / F l i p p i n g of 5 / / V a r i a b l e −−−−−−− s ’ or d e f i n i t i o n c o e f f i c i e n t s passed as ’z ’) 162 i n p u t argument ( e i t h e r ’ 6 / / 7 / / to 9 / / P o l y n o m i a l s 10 / / be Both num files , get and rid den of are used n e g a t i v e mostly powers of used in s c i c o s z 8 f l i p p e d with powers of s need to only 11 12 13 14 15 16 17 18 19 f u n c t i o n [ p o l y n u , p o l y d e ] = p o l y n o ( zc , a ) zc = clean ( zc ) ; polynu = poly ( zc ( length ( zc ) : −1:1) , a , ’ c o e f f ’ ) ; i f a == ’ z ’ p o l y d e = %z ˆ ( l e n g t h ( z c ) − 1 ) ; else polyde = 1; end 20 21 / / Scicos ( 4 . 1 ) F i l t e r block shouldn ’ t have c o n s t a n t / c o n s t a n t i f t y p e ( p o l y n u ) ==1 & t y p e ( p o l y d e ) ==1 i f a == ’ z ’ p o l y n u = %z ; p o l y d e = %z ; else p o l y n u = %s ; p o l y d e = %s ; end ; end ; 22 23 24 25 26 27 28 29 30 endfunction Scilab Code 8.14 rowjoin.sci 1 / / Updated 2 / / f u n c t i o n 3 / / MATLAB 4 / / MATRICES / / H . −−−−−−−− No [P , degP ] FUNCTION change = r o w j o i n ( P1 , d e g P 1 , P2 , d e g P 2 ) rowjoin TO SUPERPOSE TWO POLYNOMIAL 5 6 Kwakernaak , July , 1990 7 8 f u n c t i o n [ P , degP ] = r o w j o i n ( P1 , degP1 , P2 , degP2 ) 163 9 10 11 12 13 14 [ rP1 , cP1 ] = p o l s i z e ( P1 , degP1 ) ; [ rP2 , cP2 ] = p o l s i z e ( P2 , degP2 ) ; i f cP1 ˜= cP2 e r r o r ( ’ r o w j o i n : I n c o n s i s t e n t numbers o f c o l u m n s ’ ) ; end 15 16 17 18 19 20 21 r P = r P 1+r P 2 ; cP = cP1 ; i f degP1 >= degP2 degP = degP1 ; else degP = degP2 ; end 22 23 24 25 26 27 28 29 30 31 32 i f i s e m p t y ( P1 ) P = P2 ; e l s e i f i s e m p t y ( P2 ) P = P1 ; else P = z e r o s ( rP , ( degP +1) * cP ) ; P ( 1 : rP1 , 1 : ( degP1 +1) * cP1 ) = P1 ; P ( r P 1 +1: rP , 1 : ( degP2 +1) * cP2 ) = P2 ; end endfunction Scilab Code 8.15 seshft.sci 1 / / Updated 2 / / −−−−−−−− No C = s e s h f t (A , B , N) and B matrices f u n c t i o n 3 / / given 4 / / A change , r e t u r n s e a s t by N cols 5 7 8 9 10 = [ < −A−> 0 s h i f t e d 6 C f u n c t i o n C = s e s h f t (A, B , N) [ Arows , A c o l s ] = s i z e (A) ; [ Brows , B c o l s ] = s i z e (B) ; i f N >= 0 B = [ z e r o s ( Brows , N) B ] ; 164 0 <−B − >] with B 11 12 13 14 15 16 17 18 19 20 21 22 23 Bcols = Bcols + N; elseif N < 0 A = [ z e r o s ( Arows , abs (N) ) A ] ; A c o l s = A c o l s +abs (N) ; end i f Acols < Bcols A = [A z e r o s ( Arows , B c o l s −A c o l s ) ] ; e l s e i f Acols > Bcols B = [B z e r o s ( Brows , Acols − B c o l s ) ] ; end C = [A B]; endfunction Scilab Code 8.16 t1calc.sci 1 / / Updated 2 / / f u n c t i o n 3 / / t 1 c a l c ( S , S r o w s , T1 , T 1 r o w s , s e l , p r , F r o w s , F b c o l s 4 / / c a l c u l a t e s 5 / / r e d u n d a n t = [ T1 , T 1 r o w s , s e l , p r ] . . . , abar , gap ) rows 6 / / with are the row c o e f f i c i e n t i n f o r m a t i o n matrix is kept T1 in sel : r e d u n d a n t marked zeros . The u n d e l e t e d rows are marked with ones . 7 8 9 f u n c t i o n [ T1 , T1rows , s e l , p r ] = t 1 c a l c ( S , Srows , T1 , T1rows , s e l , pr , Frows , F b c o l s , a b a r , gap ) b = 1; / / v e c t o r of primary red . rows 10 11 12 13 w h i l e ( T1rows < Frows − F b c o l s ) & o r ( s e l ==1) & ˜ isempty ( b ) S = clean (S) ; b = i n d e p ( S ( m t l b l o g i c a l ( s e l ) , : ) , gap ) ; / / s e l e c t e d 14 15 rows of S i f ˜ isempty ( b ) b = clean ( b ) ; 165 send b = m o v e s c i ( b , f i n d ( s e l ) , Srows ) ; j = length ( b ) ; w h i l e ˜ ( b ( j ) & o r ( a b a r == j ) ) / / 16 17 18 nonzero l a r g e s t e n t r y j = j −1; 19 pick / / b e l o n g i n g to of c o e f f . abar if ˜ j f p r i n t f ( ’ \ nMessage from t 1 c a l c , c a l l e d from l e f t p r m \ n \ n ’ ) error ( ’ Denominator i s n o n i n v e r t i b l e ’) end 20 21 22 23 end i f ˜ o r ( j < p r & pmodulo ( pr , Frows ) == pmodulo ( j , Frows ) ) / / p r ( 2 ) , p r ( 1 ) T1 = [ T1 ; b ] ; / / c o n d i t i o n 24 25 26 is not v i o l a t e d T1rows = T1rows +1; 27 / / a c c e p t / / e l s e / / update t h i s v e c t o r end 28 don ’ t a c c e p t pr = [ pr ; j ] ; 29 prime 31 32 33 info end 34 36 row w h i l e j <= Srows sel ( j ) = 0; j = j + Frows ; end 30 35 red end endfunction 8.7 Scilab Code for Virtual Experiment Scilab Code 8.17 twodof para.sce 1 2 mode ( 0 ) g l o b a l Rc Sc Tc gamm u o l d o l d u o l d r o l d o l d r o l d 166 3 4 5 y o l d o l d y o l d u new r n e w y new s=%s ; z=%z ; / / TFcont = s y s l i n ( ’ c ’ , 0 . 5 9 3 / ( ( 4 7 . 2 1 * s +1) * ( 1 . 3 7 3 * s +1) ) ) ; / / second 6 7 8 9 10 / / TFcont = order s y s l i n ( ’ c ’ , 0 . 5 9 4 / ( 4 9 . 1 9 * s +1) ) / / f i r s t T F c o n t = s y s l i n ( ’ c ’ , 0 . 4 2 / ( 3 5 . 6 1 * s +1) ) ; SScont = t f 2 s s ( TFcont ) ; Ts = 1 ; [ B , A, k ] = myc2d ( SScont , Ts ) ; / / f i r s t order 11 12 13 14 / / p o l y n o m i a l s are r e t u r n e d [ Ds , num , den ] = s s 2 t f ( S S c o n t ) ; num = c l e a n ( num ) ; den = c l e a n ( den ) ; 15 16 17 18 / / T r a n s i e n t s p e c i f i c a t i o n s r i s e = 100; e p s i l o n = 0 . 0 5 ; p h i = d e s i r e d ( Ts , r i s e , e p s i l o n ) ; 19 20 21 22 / / C o n t r o l l e r design Delta = [1 −1]; [ Rc , Sc , Tc , gamm ] = pp im ( B , A, k , p h i , D e l t a ) ; / / with i n t e g r a l 23 24 25 26 27 28 29 30 / / u u r r y y i n i t i a l old old old old old old v a l u e s old = 0; = 0; old = 0; = 0; old = 0; = 0; Scilab Code 8.18 twodof.sce 1 2 mode ( 0 ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s s a m p l i n g t i m e m h e a t temp 3 167 order 4 / / ********************** 5 s a m p l i n g t i m e =1; 6 / / * * * * * * * * * * * * * * * * * * * * * * / / 7 8 9 / / In seconds . F r a c t i o n s are allowed g e t d ( ’ dc / s c i l a b ’ ) ; exec ( ” twodof para . sce ” ) exec ( ” twodof . s c i ” ) ; 10 11 ok = i n i t ( ) ; 12 i f ok ˜= [ ] 13 through ( ie open xcos only if communication r e p l y has come from is s e r v e r ) xcos ( ’ twodof . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 14 15 16 17 18 / / end Scilab Code 8.19 twodof.sci 1 2 function [ s t o p ] = twodof ( s e t p o i n t , fan ) g l o b a l temp u o l d o l d u o l d r o l d o l d r o l d y o l d o l d y o l d u new h e a t r n e w y new 3 4 5 6 r new = s e t p o i n t ; y new = temp ; / / u new * r = o l d ( 1 / Rc ( 1 ) ) * ( gamm * Tc ( 1 ) * r + r o l d o l d * Tc ( 3 ) * gamm (2) * y old − (3) * u o l d o l d ) ; / / second Sc ( 3 ) * y o l d o l d − order new − + gamm * Tc ( 2 ) Sc ( 1 ) * y new Rc ( 2 ) * u old c o n t r o l law − − Sc Rc 7 8 9 10 u new = ( 1 / Rc ( 1 ) ) * ( gamm * Tc ( 1 ) * r n e w + gamm* Tc ( 2 ) * r o l d −Sc ( 1 ) * y new −Sc ( 2 ) * y o l d −Rc ( 2 ) * u o l d − Rc (3) * u old old ) ; / / f i r s t o r d e r c o n t r o l l a w h e a t = u new ; [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / N e v e r e d i t t h i s l i n e 11 p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 25 0 ] , [ 1 0 0 100 50 1000]) ; 168 12 u u r r y y 13 14 15 16 17 18 old old old old old old old = u old ; = u new ; old=r old ; = r new ; old=y old ; = y new ; 19 20 endfunction 8.8 Scilab Codes Common for both Local and Virtual Experiments Scilab Code 8.20 myc2d.sci 1 / / Updated (26 −7 −07) 2 / / 9.2 3 / / f u n c t i o n [B ,A , k ] 4 / / Produces numerator = and in of myc2d (G , Ts ) d e n o m i n a t o r of d i s c r e t e t r a n s f e r 5 / / 6 / / 7 / / f u n c t i o n G is not Ts powers c o n t i n u o u s z ˆ{ −1} t r a n s f e r f u n c t i o n ; time allowed is the sampling time , a l l in c o n s i s t e n t u n i t s 8 / / User 9 / / −−−−−− d e f i n e d f u n c t i o n 10 11 12 13 14 15 16 17 18 d e l a y s f u n c t i o n [ B , A, k ] = myc2d (G, Ts ) H = s s 2 t f ( d s c r (G, Ts ) ) ; num1 = c o e f f (H( ’num ’ ) ) ; den1 = c o e f f (H( ’ den ’ ) ) ; / / − − − − − − − − − − − − − A = den1 ( l e n g t h ( den1 ) : − 1 : 1 ) ; num2 = num1 ( l e n g t h ( num1 ) : − 1 : 1 ) ; / / f l i p n o n z e r o = m t l b f i n d ( num1 ) ; f i r s t n z = nonzero ( 1) ; 169 time are 19 20 21 B = num2 ( f i r s t n z : l e n g t h ( num2 ) ) ; k = l e n g t h ( den1 ) − l e n g t h ( num1 ) ; endfunction / / −−−−−−−−−−−−− Scilab Code 8.21 desired.sci 1 / / Updated (26 −7 −07) 2 / / 9.4 3 f u n c t i o n [ p h i , d p h i ] = d e s i r e d ( Ts , r i s e , e p s i l o n ) 4 5 6 7 Nr = r i s e / Ts ; omega = %pi / 2 / Nr ; r h o = e p s i l o n ˆ ( omega / %pi ) ; p h i = [ 1 −2 * r h o * c o s ( omega ) r h o ˆ 2 ] ; d p h i = l e n g t h ( p h i ) −1; endfunction ; Scilab Code 8.22 polmul.sci 1 / / 2 / / polmul 3 / / The 4 / / 5 / / Updated / / 7 / / 8 / / = [C , degA ] produces the A*B p o l y n o m i a l H . change command p r o d u c t 6 −−−−−− No p o l m u l ( A , degA , B , degB ) p o l y n o m i a l of C t h a t e q u a l s the the m a t r i c e s Kwakernaak , matrix July , A and B . 1990 9 10 11 12 13 14 15 16 f u n c t i o n [ C , degC ] = p o l m u l (A, degA , B , degB ) [ rA , cA ] = p o l s i z e (A, degA ) ; [ rB , cB ] = p o l s i z e ( B , degB ) ; i f cA ˜= rB error ( ’ polmul : I n c o n s i s t e n t dimensions of i n p u t matrices ’ ) ; end 17 18 degC = degA+degB ; 170 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 C = []; f o r k = 0 : degA+degB mi = 0 ; i f k−degB > mi mi = k−degB ; end ma = degA ; i f k < ma ma = k ; end Ck = z e r o s ( rA , cB ) ; f o r i = mi : ma Ck = Ck + A ( : , i * cA + 1 : ( i +1) * cA ) *B ( : , ( k− i ) * cB + 1 : ( k− i +1) * cB ) ; end C = [C Ck ] ; end endfunction Scilab Code 8.23 polsplit3.sci 1 / / Updated (18 −7 −07) 2 / / 9.11 3 / / f u n c t i o n [ goodpoly 4 / / S p l i t s s c a l a r a = , badpoly ] p o l y n o m i a l p o l s p l i t 3 ( fac , a ) z ˆ{ −1} of i n t o good and bad 5 / / f a c t o r s . Input is a p o l y n o m i a l in i n c r e a s i n g degree of 6 / / 7 / / z ˆ{ −1}. F a c t o r s a 8 / / 9 / / O p t i o n a l t h a t have i n p u t is a , where r o o t s o u t s i d e a <= a c i r c l e 1. of r a d i u s or with good . n e g a t i v e If a is r o o t s not w i l l be s p e c i f i e d c a l l e d , i t bad w i l l be and the assumed r e s t as 1. 10 11 12 13 f u n c t i o n [ goodpoly , badpoly ] = p o l s p l i t 3 ( fac , a ) i f argn ( 2 ) == 1 , a = 1 ; end i f a >1 e r r o r ( ’ good p o l y n o m i a l a l s o i s u n s t a b l e ’ ) ; end 171 14 15 16 fac1 = poly ( fac ( length ( fac ) : −1:1) , ’ z ’ , ’ c o e f f ’ ) ; r t s = roots ( fac1 ) ; r t s = r t s ( length ( r t s ) : −1:1) ; 17 18 19 20 21 22 / / e x t r a c t good and bad r o o t s b a d i n d e x = m t l b f i n d ( ( abs ( r t s )>=a − 1 . 0 e −5) | ( r e a l ( r t s ) < −0.05) ) ; badpoly = c o e f f ( poly ( r t s ( badindex ) , ’ z ’ ) ) ; g o o d i n d e x = m t l b f i n d ( ( abs ( r t s ) = −0.05) ) ; goodpoly = c o e f f ( poly ( r t s ( goodindex ) , ’ z ’ ) ) ; 23 24 25 26 27 28 29 30 31 32 / / s c a l e by e q u a t i n g the l a r g e s t terms [m, i n d e x ] = max ( abs ( f a c ) ) ; goodbad = c o n v o l ( g o o d p o l y , b a d p o l y ) ; goodbad = goodbad ( l e n g t h ( goodbad ) : − 1 : 1 ) ; f a c t o r 1 = f a c ( i n d e x ) / goodbad ( i n d e x ) ; goodpoly = goodpoly * f a c t o r 1 ; goodpoly = goodpoly ( length ( goodpoly ) : −1:1) ; badpoly = badpoly ( length ( badpoly ) : −1:1) ; endfunction ; Scilab Code 8.24 pp im.sci 1 / / Updated (27 −7 −07) 2 / / 9.8 3 / / f u n c t i o n [ Rc , Sc , Tc , gamma , p h i t ] = pp im (B , A , k , phi , Delta ) / / C a l c u l a t e s 5 / / −−−−−− 6 f u n c t i o n [ Rc , Sc , Tc , gamm ] = pp im ( B , A, k , p h i , D e l t a ) 4 2 − DOF pole placement c o n t r o l l e r . 7 8 9 10 / / S e t t i n g up and s o l v i n g A r y a b h a t t a 11 12 i d e n t i t y [ Ag , Ab ] = p o l s p l i t 3 (A) ; dAb = l e n g t h ( Ab ) − 1 ; [ Bg , Bb ] = p o l s p l i t 3 (B) ; dBb = l e n g t h ( Bb ) − 1 ; [ zk , dzk ] = zpowk ( k ) ; 13 172 14 15 16 17 [N, dN ] dDelta [D, dD ] dphi = = p o l m u l ( Bb , dBb , zk , dzk ) ; = l e n g t h ( D e l t a ) −1; = p o l m u l ( Ab , dAb , D e l t a , d D e l t a ) ; l e n g t h ( p h i ) −1; 18 19 [ S1 , dS1 , R1 , dR1 ] = xdync (N, dN , D, dD , p h i , d p h i ) ; 20 21 22 23 24 / / D e t e r m i n a t i o n of c o n t r o l law Rc = c o n v o l ( Bg , c o n v o l ( R1 , D e l t a ) ) ; Sc = c o n v o l ( Ag , S1 ) ; Tc = Ag ; gamm = sum ( p h i ) / sum ( Bb ) ; endfunction ; Scilab Code 8.25 xdync.sci 1 / / Updated 2 / / f u n c t i o n 3 / / −−−− No change [ Y , degY , X , degX , B , degB , A , degA ] = xdync (N , degN , D , degD , C , degC , g a p ) given row 4 / / c o e f f i c i e n t i n f o r m a t i o n s o l v e s XD + YN matrix in T1 , primary 16 April r e d u n d a n t sel , = C 5 6 / / c a l l i n g 7 / / f u n c t i o n order changed on 2005. [ B , degB , A , degA , Y , degY , X , degX ] Old = order : xdync (N , degN , D , degD , C , degC , g a p ) 8 9 10 11 12 f u n c t i o n [Y, degY , X, degX , B , degB , A, degA ] = xdync (N, degN , D, degD , C , degC , gap ) i f argn ( 2 ) == 6 gap = 1 . 0 e +8; end 13 14 [ F , degF ] = r o w j o i n (D, degD , N, degN ) ; 15 16 [ Frows , F b c o l s ] = p o l s i z e ( F , degF ) ; / / Fbcols = block columns 17 18 [ B , degB , A, degA , S , s e l , degT1 , F b c o l s ] = l e f t p r m (N, degN , D , degD , 3 , gap ) ; 173 19 / / if i s s o l n ( D , degD , C , degC , B , degB , A , degA ) [ Crows , C c o l s ] = s i z e (C) ; [ Srows , S c o l s ] = s i z e ( S ) ; S = clean (S) ; S = S( mtlb logical ( sel ) ,:) ; T2 = [ ] ; 20 21 22 23 24 25 f o r i = 1 : Crows , Saug = s e s h f t ( S , C( i , : ) , 0 ) ; b = c i n d e p ( Saug ) ; b = m o v e s c i ( b , f i n d ( s e l ) , Srows ) ; T2 =[ T2 ; b ] ; end 26 27 28 29 30 31 32 [X, degX , Y, degY ] = c o l s p l i t ( T2 , degT1 , F b c o l s , Frows − Fbcols ) ; 33 34 35 36 37 38 [X, degX ] = c l c o e f (X, degX ) ; [Y, degY ] = c l c o e f (Y, degY ) ; Y = c l e a n (Y) ; X = c l e a n (X) ; endfunction Scilab Code 8.26 zpowk.sci 1 / / 2 / / 9.6 3 / / −−−−−− Updated (26 −7 −07) 4 5 6 7 8 f u n c t i o n [ zk , dzk ] = zpowk ( k ) zk = z e r o s ( 1 , k +1) ; zk ( 1 , k +1) = 1 ; dzk = k ; endfunction 174 Chapter 9 PRBS Modeling and Implementation of Pole Placement Controller The aim of this chapter is to do PRBS testing on Single Board Heater System by the application of PRBS signal and to design a pole-placement controller. The target group is anyone who has basic knowledge of control engineering. The first half of this chapter is dedicated to do system identification of the SBHS system using the response obtained for a PRBS (Pseudo Random Binary Sequence) input. In the second half, a pole-placement controller is designed using this model and implemented on SBHS. 9.1 PRBS Modelling Similar to Chapter 4 and 5, we will find the transfer function model of SBHS. But there are two major differences. First difference is that we will give a Pseudo Random Binary Sequence to the heater input of SBHS and the second difference is that we will find the discrete time transfer function. A Pseudo Random Binary Sequence is nothing but a signal whose amplitude varies between two limits randomly at any given time. An illustration of the same is given in figure 9.4. A PRBS signal can be easily generated using the rand() function in Scilab. Scilab code to generate the PRBS signal is given at the end of this chapter. We have used Scilab with Xcos as an interface for sending and receiving data. This interface is shown in figure 9.1. Heater current and fan speed are the two 175 Figure 9.1: Xcos for PRBS testing experiment inputs to the system. The heater current is varied with a PRBS signal. A provision is made to set the parameters like PRBS amplitude and offset value. A provision is also made to time the occurance of the PRBS input using a step block. The value of step time in the step block has to be chosen carefully. Sufficient amount of time should be given to allow the temperature to reach a steady-state before the PRBS signal is applied. In this experiment we are keeping the fan speed constant at 50%. The temperature profile thus obtained is the output. 9.1.1 Issues with Step Test and an Alternate Approach SBHS is an example of a heater. Suppose you are working in a full scale plant. Current control system designed to control one of the heaters of the plant is lousy and your supervisor asks you to design a new controller from scratch. The first step you need to do is identification of the heater transfer function. The catch is, the plant is currently operational. You can’t shut the plant down to identify the heater transfer function. You have to do it while the heater is operating in the plant. You might think of giving the heater a positive step and measuring the 176 response in the controlled temperature. This will increase the temperature of the component being heated for the period of time step is applied. However, if the process is sensitive to temperature of the component (distillation, for example), it will go off the desired course and the output of the whole plant will be affected and will be undesirable. There is an alternate approach which is widely used in industry. The input given to the heater for identification is not step, but a pseudo-random binary sequence (PRBS). The concept behind PRBS is that the input is perturbed in such a way that the time average of the input is the value at which it is being operated currently. Thus, some positive and some negative steps can be given. This results in some positive and some negative changes in the temperature which leads to the time average of the performance of the plant remaining the same. Thus, PRBS testing can be done in a working plant without affecting the plant performance unlike step testing. A typical PRBS and corresponding plant output is shown in figure 9.2 Figure 9.2: PRBS testing input and output [Image source: CL 686 Advanced Process Control, Spring 2013-14 lecture slides. Prof. S. C. Patwardhan, IIT Bombay] 177 1.0 2.0 . 999.0 1000.0 50.0 50.0 50.0 50.0 40.0 40.0 36.4 36.2 50.0 50.0 1417298828422.0 1417298828525.0 42.9 42.9 1417298933585.0 1417298933694.0 Table 9.1: PRBS local experiment data 9.2 Conducting PRBS Test on SBHS locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is prbs/identification 2. Step2: Load the functions available in common files directory by executing the command getd ..\..\common files 3. Step3: Same 4. Step4: Same 5. Step5: Load prbstest function by executing command exec prbstest.sci. Load prbs signal generation function by executing command exec prbs.sci 6. Step6: Load Xcos code for prbs test using the command exec prbstest.xcos 7. Step7: Same The response is as shown in figure 9.3. The data file thus obtained is as shown in the Table 9.1. This data file is available for reference in the directory prbs/identification with name prbs-data-local.txt 178 Figure 9.3: PRBS Local response 9.3 Conducting PRBS Test on SBHS, virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is prbs/identification. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the working experiment directory and double-click on the file prbstest.sce. This will launch scilab and also open the file prbstest.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to prbs/identification and then open the prbstest.sce file in the scilab editor. 5. Step5: Load the functions available in common files directory by executing the command getd ..\..\common files 179 0 0 100 28.40 14...1731 14...4105 14...4123 14...1763 0.10000E+01 1 50 50 28.30 14...4706 14...7078 14...7096 14...4738 0.10000E+01 . . 983 40 50 36.70 14...6728 14...9131 14...9148 14...6759 0.98300E+03 984 40 50 36.50 14...7712 14...0115 14...0133 14...7743 0.98400E+03 Table 9.2: PRBS data obtained after performing virtual PRBS Test Figure 9.4: A Pseudo Random Binary Sequence 6. Step6: Execute the file prbstest.sce. Expect the prbs test xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the prbstest xcos diagram. 8. Step8: Same The virtual experiment response is shown in figure 9.5. The corresponding data file is shown in table 9.2. The time stamps shown are cut short for better viewing. This data file can be found in prbs/identification folder for virtual experiments. The name of this file is prbs-data-virtual.txt. 180 Figure 9.5: PRBS testing response for virtual experiment 9.4 Determination of Discrete Time Transfer Function models System identification is carried out to identify the transfer function between the input signal to the system and output from the system. Firstly, a transfer function with unknown parameters is assumed. The system is given a known input and its response is obtained and then the values of the unknown parameters is chosen such that the sum of squares of the errors is minimized. Here, the error is the difference between the actual output and the output predicted by the transfer function model assumed. For the given SBHS system, we assume a second order transfer function: G(z) = b1 + b2 z−1 z−d 1 + a1 z−1 + a2 z−2 (9.1) The unknown parameters a1 , a2 , b1 , b2 and d are to be obtained through the response of the system to the known inputs. a1 , a2 , b1 , b2 are real numbers and d is the plant delay which is an integer. For these model parameters estimation, we use a pseudo random binary sequence (PRBS) input. Since the optimization over discrete variables (d in this case) is a very difficult routine for computers, we assume a value for d and then optimize over a1 , a2 , b1 , b2 . The optimization 181 Figure 9.6: PRBS first order fit problem, then, becomes: (bˆ1 , bˆ2 , aˆ1 , aˆ2 ) = argmin N X b1 ,b2 ,a1 ,a2 i=0 (y(k) − ŷ(k))2 (9.2) ˆ is the Here, y(k) is the output obtained from the system- so it is known. y(k) estimated output using y the model assumed, which can be written as a difference equation: ŷ(k) = −a1 ŷ(k − 1) − a2 ŷ(k − 2) + b1 u(k − d) + b2 u(k − 1 − d) 9.5 (9.3) Determination of First order Discrete time Transfer Function 1. Download the Analysis folder from the sbhs website. It will be available under downloads section. Download the file for SBHS Analysis Code (local & virtual). The name of the file is scilab codes analysis. 182 Figure 9.7: PRBS first order model The download will be in zip format. Extrat the downloaded zip file. You will get a folder scilab codes analysis. 2. Open the scilab codes analysis folder and then locate and open the folder Step Analysis. 3. Inside this folder, locate and open the folder Discrete-order1 4. Copy the prbs test data file to this folder. 5. Start scilab and change the working directory to Discrete-order1 6. Open the file optimize.sce in scilab editor and enter the name of the data file (with extention) in the filename field. 7. Save and run this code and obtain the plot as shown in figure 9.6. This plot will also show the first order discrete time transfer function’s coefficients a1 and b1. 8. The values are also shown on scilab console as shown in figure 9.7 183 The results presented are obtained for the data file prbs-data-virtual.txt. This data file is present under the prbs directory for virtual experiments.The plot thus obtained is reasonably good. See the Scilab plot to get the values of a1 and b1. The figure 9.6 shows a screen shot of the same. We obtain a1 = -0.97, b1= 0.004. The transfer function obtained here is at the operating point of 50 percentage of heat. If the experiment is repeated at a different operating point, the transfer function obtained will be different. The gain will correspondingly be more at a higher operating point. This means that the plant is faster at higher temperature. Thus the transfer function of the plant varies with the operating point. Let the transfer function we obtain in this experiment be denoted as G(z). We obtain G(z) = 9.6 0.004 z−5 1 − 0.97z−1 (9.4) Determination of Second order Discrete time Transfer Function 1. Download the Analysis folder from the sbhs website. It will be available under downloads section. Download the file for SBHS Analysis Code (local & virtual). The name of the file is scilab codes analysis. The download will be in zip format. Extrat the downloaded zip file. You will get a folder scilab codes analysis. 2. Open the scilab codes analysis folder and then locate and open the folder Step Analysis. 3. Inside this folder, locate and open the folder Discrete-order2 4. Copy the prbs test data file to this folder. 5. Start scilab and change the working directory to Discrete-order2 6. Open the file optimize.sce in scilab editor and enter the name of the data file (with extention) in the filename field. 7. Save and run this code and obtain the plot as shown in figure 9.8. This plot will also show the second order discrete time transfer function’s coefficients a1, a2, b1 and b2. 184 Figure 9.8: PRBS second order fit 8. The values are also shown on scilab console as shown in figure 9.9 The results presented are obtained for the data file prbs-data-virtual.txt. This data file is present under the prbs directory for virtual experiments.The plot thus obtained is reasonably good. See the Scilab plot to get the values of a1, a2, b1 and b2. The figure 9.8 shows a screen shot of the same. We obtain a1 = -1.82, a2= 0.833, b1 = 0.0017, b2= -0.00086, . The transfer function obtained here is at the operating point of 50 percentage of heat. If the experiment is repeated at a different operating point, the transfer function obtained will be different. The gain will correspondingly be more at a higher operating point. This means that the plant is faster at higher temperature. Thus the transfer function of the plant varies with the operating point. Let the transfer function we obtain in this experiment be denoted as G(z). We obtain 0.0017 − 0.00086z−1 −5 z G(z) = 1 − 1.826z−1 + 0.833z−2 185 (9.5) Figure 9.9: PRBS second order model 9.7 Implementing 2DOF pole-placement controller using PRBS model, virtually For deriving the Two degrees of freedom control law, please refer to the chapter 8.2 The controller was designed for the given transient conditions, rise time = 10 sec, overshoot = 0.1. The experimental result and performance of the controller for setpoint temperature change from 38.00 to 43.00 degree C, i.e. 5 degree C positive step change, has been shown below in Fig 9.10. The controller designed is not derived for the model explained in earlier sections. The parameters for the 2-DOF pole-placement controller obtained are shown here T c = 1 − 1.9444137z−1 + 0.9447818z−2 S c = 0.0337719 − 0.0656666z−1 + 0.0319071z−2 Rc = 10−9 (4377900 − 12034140z−1 + 11094713z−2 − 3436740.5z−3 + 3.469D−09 z−4 − 147850.06z−5 + 146117.57z−6 ) γ = 0.0337719 As can be observed from the graph of temperature vs. time (third subplot) in Fig 9.10, the overshoot criteria was satisfied very easily. The rise time criteria is observed to be more than 30 sec. This can be satisfied with experimentation. The paramenters are computed by the file twodof para.sce. 186 Figure 9.10: 2dof controller response The steps to be followed to conduct PRBS test experiment virtually remains same as explained in section 3.5. only for the following differences • Step1: The working directory is prbs/controller. Open this directory. • Step2: Same • Step3: Same • Step4: Switch to the controller experiment directory and double-click on the file prbs.sce. This will launch scilab and also open the file prbs.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to controller and then open the prbs.sce file in the scilab editor. • Step5: Load the functions available in common files directory by executing the command getd ..\..\common files • Step6: Execute the file prbs.sce. Expect the prbs test xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. The values of Rc, Sc, Tc and γ are to be entered in the xcos diagram. • Step7: Execute the prbstest xcos diagram. 187 • Step8: Same 9.8 Implementing 2DOF pole-placement controller using PRBS model, locally The step by step procedure for conducting an experiment locally remains same as explained in section 2.3 with the following changes 1. Step1: The working directory is prbs/controller 2. Step2: Load the functions available in common files directory by executing the command getd ..\..\common files 3. Step3: Same 4. Step4: Same 5. Step5: Load prbstest function by executing command exec prbs pp.sci. 6. Step6: Load Xcos code for prbs test using the command exec prbs pp.xcos. The values of Rc, Sc, Tc and γ are to be entered in the xcos diagram. 7. Step7: Same 9.9 Scilab Local codes 9.9.1 Identification codes Scilab Code 9.1 ser init.sce 1 2 3 mode ( 0 ) global filename m / / ** S a m p l i n g Time * * / / 4 sampling time = 1; 5 / / / / / / / * * * * / / / / / / / / / 6 m=1; 188 7 8 9 p o r t 1 = ’ / dev / ttyUSB0 ’ ; / / F o r p o r t 2 = ’COM2 ’ ; / / F o r w i n d o w s l i n u x u s e r s u s e r s 10 11 12 res= i n i t ([ port1 port2 ]) ; disp ( res ) Scilab Code 9.2 costfunction.sci 1 2 3 4 5 6 7 8 9 function [ f , g , ind ] = c o s t f u n c t i o n (x , ind ) global delay ; y prediction = second order (u , x) ; i f s i z e ( y ) ˜= s i z e ( y p r e d i c t i o n ) t h e n y prediction = y prediction ’; end f = ( norm ( y− y p r e d i c t i o n , 2 ) ) ˆ 2 ; g = numdiff ( f u n c 1 , x ) ; endfunction 10 11 12 13 14 15 16 17 18 function f = func 1 ( x ) global delay ; y prediction = second order (u , x) ; i f s i z e ( y ) ˜= s i z e ( y p r e d i c t i o n ) t h e n y prediction = y prediction ’; end f = ( norm ( y− y p r e d i c t i o n , 2 ) ) ˆ 2 ; endfunction Scilab Code 9.3 optimize.sce 1 2 3 4 mode ( 0 ) ; / / Change f i l e n a m e here f i l e n a m e = ” 30 A p r 2 0 1 4 1 2 3 0 5 0 . t x t ” ; clf 5 6 7 8 exec ( ’ c o s t f u n c t i o n . s c i ’ ) ; exec ( ’ l a b e l . s c i ’ ) ; 189 9 exec ( ’ s e c o n d o r d e r . s c i ’ ) ; 10 11 12 d a t a = fscanfMat ( f i l e n a m e ) ; 13 14 time = data ( : , 1) ; 15 16 h e a t e r = int ( data ( : , 2) ) ; 17 18 fan = in t ( data ( : , 3) ) ; 19 20 temp = d a t a ( : , 4 ) ; 21 22 23 24 25 26 27 28 ss op pt = heater (2) ; f o r i =2: l e n g t h ( h e a t e r ) i f h e a t e r ( i ) ˜= s s o p p t t h e n startTime = i ; break end end 29 30 31 32 time1 = time − time ( 1 ) ; time2 = time1 /1000; 33 34 35 36 baseheat = heater (5) ; heater = heater ( startTime : length ( heater ) ) ; heater = heater − baseheat ; 37 38 len = length ( heater ) ; 39 40 41 temp = temp ( s t a r t T i m e : l e n g t h ( temp ) ) ; temp = temp − temp ( 1 ) ; 42 43 44 time = time2 ( s t a rt T im e : length ( time ) ) ; time = time − time (1) ; 45 46 t = time ; 190 47 48 y = temp ; u = heater ; 49 50 51 52 53 x0 = [ 0 . 2 0 . 2 0 . 5 0 . 5 ] ; / / C h a n g e i n delay = 5; / / Change delay here global delay ; [ f , x o p t ] = optim ( c o s t f u n c t i o n , x0 ) ; i t i a l guess here 54 55 56 57 58 a1 a2 b1 b2 = = = = xopt (1) xopt (2) xopt (3) xopt (4) 59 60 y pred = second order ( u , xopt ) ; 61 62 63 64 65 i f s i z e ( y ) ˜= s i z e ( y p r e d ) t h e n y pred = y pred ’ ; end e r r = norm ( y − y p r e d ) / norm ( y ) 66 68 p l o t ( t , y , ”+” ) ; plot ( t , y pred , ”k” ) ; 69 / / p l o t ( t , 67 u /10 , ” r ”) ; 70 71 l a b e l ( ’ Showing Second O r d e r Model and E x p e r i m e n t a l R e s u l t s ’ , 4 , ’ Time ( s ) ’ , ’ Change i n t e m p e r a t u r e (K) ’ ,4) ; Scilab Code 9.4 prbs.sci 1 2 3 4 5 6 7 8 f u n c t i o n u=PRBS ( a c t i v e ) i f a c t i v e == 0 t h e n u = 0; else g l o b a l PRBSu PRBScount ; i f PRBSu == [ ] t h e n PRBSu = 1 ; PRBScount = 3 0 ; 191 9 10 11 12 13 14 15 16 17 18 19 end i f PRBScount == 0 t h e n PRBSu = −1 * PRBSu ; PRBScount = i n t ( rand ( ) * 4 0 ) +10; else PRBScount = PRBScount − 1 ; end u = PRBSu ; g l o b a l PRBSu PRBScount ; end endfunction Scilab Code 9.5 prbstest.sci 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = p r b s t e s t ( h e a t , f a n ) global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 4 5 6 temp = comm ( h e a t , f a n ) ; 7 8 p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1000]) 9 10 11 m=m+1; endfunction Scilab Code 9.6 second order.sci 1 2 3 4 5 6 7 8 f u n c t i o n y = s e c o n d o r d e r ( u , params ) / / Do not change a1 = p a r a m s ( 1 ) a2 = p a r a m s ( 2 ) b1 = p a r a m s ( 3 ) b2 = p a r a m s ( 4 ) global delay ; / / a n y t h i n g ; ; ; ; End 192 here 9 / / / 10 You should w r i t e your code below t h i s l i n e N= l e n g t h ( u ) ; 11 12 13 / / D e f i n i n g y 14 / / from up t =0 i n d i c e s v e c t o r t = delay −1 , to i =1 up to y =0 , i = delay / / F i r s t 16 =0 , nonzero i . e . / / After 18 20 21 in o u t p u t s c i l a b is only i n p u t u t h a t y ( i ) can be / / 23 y = ? 24 endfunction Scilab Code 9.7 start.sce getd . . / . . / common files / exec . . / . . / common files / loader . sce 2 4 6 7 exec s e r i n i t . sce exec prbs . s c i exec p r b s t e s t . s c i 8 9 at 0 due at d e f i n e d 22 5 y to i n p u t u at t i =1 as f o l l o w s f o r i = d e l a y + 2 : 1 :N y ( i ) =−a1 * y ( i −1)−a2 * y ( i −2)+b1 * u ( i − d e l a y ) +b2 * u ( i −1− d e l a y ) ; end 19 3 s c i l a b y ( d e l a y +1) = b1 * u ( 1 ) ; 17 1 in y ( 1 : 1 : delay ) = 0; 15 25 is so xcos p r b s t e s t . xcos 9.9.2 Controller codes Scilab Code 9.8 start.sce 193 1 2 mode ( 0 ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 3 4 g l o b a l s c n s c d t c n t c d r c n r c d gamm 5 6 g e t d ” dc / s c i l a b ” 7 8 9 10 11 12 13 / / ********************** s a m p l i n g t i m e =1; / / In seconds . F r a c t i o n s are allowed / / * * * * * * * * * * * * * * * * * * * * * * / / exec ( ” p r b s t e s t − v i r t u a l . s c i ” ) ; exec ( ” twodof para . sce ” ) ; / / exec (” s b h s c o n t r o l . sci ”) ; 14 15 16 17 / / [ scn , scd , t c n , t c d , rcn , rcd , gamm ] = s b h s c o n t r o l () 18 19 ok = i n i t ( ) ; 20 i f ok ˜= [ ] 21 through open xcos only if r e p l y has come from communication s e r v e r ) xcos ( ’ p r b s t e s t − v i r t u a l . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 22 23 24 25 26 / / ( ie end Scilab Code 9.9 prbs pp.sce 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = p r b s p p ( h e a t , f a n , s e t p o i n t ) global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 4 5 6 temp = comm ( h e a t , f a n ) ; 194 is 7 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 8 9 10 11 m=m+1; endfunction Scilab Code 9.10 ser init.sce 1 2 3 mode ( 0 ) global filename m / / ** S a m p l i n g Time * * / / 4 sampling time = 1; 5 / / / / / / / * * * * / / / / / / / / / 6 m=1; 7 8 9 p o r t 1 = ’ / dev / ttyUSB0 ’ ; / / F o r p o r t 2 = ’COM2 ’ ; / / F o r w i n d o w s l i n u x u s e r s 10 11 12 res= i n i t ([ port1 port2 ]) ; disp ( res ) Scilab Code 9.11 start.sce 1 2 3 getd . . / . . / common files / g e t d dc / s c i l a b exec . . / . . / common files / l o a d e r . sce 4 5 6 exec s e r i n i t . sce exec prbs pp . s c i 7 8 exec twodof para . sce 9 10 xcos prbs pp . xcos Scilab Code 9.12 twodof para.sce 195 u s e r s 1 2 3 4 5 mode ( 0 ) g l o b a l Rc Sc Tc gamm g l o b a l s c n s c d t c n t c d r c n r c d gamm s=%s ; z=%z ; 6 7 8 Ts = s a m p l i n g t i m e ; 9 10 11 12 13 / / T r a n s f e r f u n c t i o n A = [ 1 −1.87 0 . 8 7 ] ; B= [ 0 . 0 0 2 0 − 0 . 0 0 1 5 ] ; k = 3; 14 15 16 17 18 r i s e = 10; epsilon = 0.1; Nr = r i s e / Ts ; 19 20 / / 21 / / r i s e 22 p h i = d e s i r e d ( Ts , r i s e , e p s i l o n ) ; T r a n s i e n t = 10; s p e c i f i c a t i o n s e p s i l o n = 0 . 0 5 ; 23 24 25 26 / / C o n t r o l l e r design Delta = [1 −1]; [ Rc , Sc , Tc , gamm ] = pp im ( B , A, k , p h i ) ; / / with i n t e g r a l 27 28 29 30 31 / / S e t t i n g up s i m u l a t i o n st = 0.0001; / / t i n i t = 0; / / t final = 0.5; d e s i r e d p a r a m e t e r s change s i m u l a t i o n / / in s t a r t s i m u l a t i o n end for h , in b a s i c . cos m. time time 32 33 34 / / S e t t i n g up s i m u l a t i o n p a r a m e t e r s for 35 36 37 c s s c l . cos N var = 0 ; x I n i t i a l = [0 0 0 ] ; N = 1 ; C = 0 ; D = 1 ; [ Tc1 , Rc1 ] = c o s f i l i p ( Tc , Rc ) ; [ Sc2 , Rc2 ] = c o s f i l i p ( Sc , Rc ) ; 38 196 / / Tc / Rc / / Sc / Rc 39 40 [ Bp ] = c o s f i l i p ( B , 1 ) ; [ Ap ] = c o s f i l i p (A, 1 ) ; 41 42 43 44 45 [ Tcp1 , Tcp2 ] = c o s f i l i p ( Tc , 1 ) ; / / [ Np , Rcp ] = c o s f i l i p (N, Rc ) ; / / 1 / [ Scp1 , Scp2 ] = c o s f i l i p ( Sc , 1 ) ; / / [ Cp , Dp ] = c o s f i l i p ( C , D) ; / / C / D Tc / 1 Rc Sc /1 46 47 / / Rc1 = Rc ( 1 ) ; Rc2 = Rc ( 2 ) ; Rc3 = Rc ( 3 ) ; Rc4 = Rc ( 4 ) ; 48 / / Sc1 = Sc ( 1 ) ; Sc2 = Sc ( 2 ) ; 49 / / Sc3 = Sc ( 3 ) ; 50 / / Tc1 = Tc ( 1 ) ; Tc2 = Tc ( 2 ) ; 51 / / Tc3 = Tc ( 3 ) ; 52 53 54 55 Rcp Scp1 Tcp1 gamm 56 57 58 59 60 61 s c n = p o l y ( Sc ( l e n g t h ( Sc ) : − 1 : 1 ) , ’ z ’ , ’ c o e f f ’ ) ; t c n = p o l y ( Tc ( l e n g t h ( Tc ) : − 1 : 1 ) , ’ z ’ , ’ c o e f f ’ ) ; r c n = p o l y ( Rc ( l e n g t h ( Rc ) : − 1 : 1 ) , ’ z ’ , ’ c o e f f ’ ) ; 62 63 64 65 s c d = z ˆ ( l e n g t h ( Sc ) −1) ; r c d = z ˆ ( l e n g t h ( Rc ) −1) ; t c d = z ˆ ( l e n g t h ( Tc ) −1) ; 9.10 Scilab Virtual codes 9.10.1 Identification codes Scilab Code 9.13 costfunction.sci 1 2 3 function [ f , g , ind ] = c o s t f u n c t i o n (x , ind ) global delay ; y prediction = second order (u , x) ; 197 4 5 6 7 8 9 i f s i z e ( y ) ˜= s i z e ( y p r e d i c t i o n ) t h e n y prediction = y prediction ’; end f = ( norm ( y− y p r e d i c t i o n , 2 ) ) ˆ 2 ; g = numdiff ( f u n c 1 , x ) ; endfunction 10 11 12 13 14 15 16 17 18 function f = func 1 ( x ) global delay ; y prediction = second order (u , x) ; i f s i z e ( y ) ˜= s i z e ( y p r e d i c t i o n ) t h e n y prediction = y prediction ’; end f = ( norm ( y− y p r e d i c t i o n , 2 ) ) ˆ 2 ; endfunction Scilab Code 9.14 optimize.sce 1 mode ( 0 ) ; 2 / / f i l e n a m e = ” prbs . t x t ”; 3 / / f i l e n a m e = ”29 Apr2014 17 03 57 . t x t ”; / / f i l e n a m e = ”30 Apr2014 12 30 50 . t x t ”; 4 5 6 / / Change f i l e n a m e here f i l e n a m e = ” 02 May2014 16 23 16 . t x t ” ; clf 7 8 9 10 exec ( ’ c o s t f u n c t i o n . s c i ’ ) ; exec ( ’ l a b e l . s c i ’ ) ; exec ( ’ s e c o n d o r d e r . s c i ’ ) ; 11 / / data = 12 / / h e a t e r 1 13 / / len 14 / / h e a t e r 15 16 17 / / h e a t e r 18 / / 19 / / time 20 / / = f s c a n f M a t ( f i l e n a m e ) ; = i n t ( data (: , 2) ) ; l e n g t h ( h e a t e r 1 ) ; n e w = [ h e a t e r 1 (1) ; h e a t e r 1 ( 1 : len −1) ] ; / / d e l h e a t e r = heater1 − h e a t e r / / ind = find ( d e l = = h e a t e r n e w ; >1) ; h e a t e r 1 ( ind (2) : len ) ; d a t a ( ind (2 ) : len , 5) ; 198 21 / / fan 22 / / temp = i n t ( d a t a ( ind (2 ) : len , = d a t a ( ind (2 ) : len , 3) ) ; 4) ; 23 24 25 d a t a = fscanfMat ( f i l e n a m e ) ; 26 27 time = data ( : , 5) ; 28 29 h e a t e r = int ( data ( : , 2) ) ; 30 31 fan = in t ( data ( : , 3) ) ; 32 33 temp = d a t a ( : , 4 ) ; 34 35 36 37 38 39 40 41 ss op pt = heater (2) ; f o r i =2: l e n g t h ( h e a t e r ) i f h e a t e r ( i ) ˜= s s o p p t t h e n startTime = i ; break end end 42 43 44 45 time1 = time − time ( 1 ) ; time2 = time1 /1000; 46 47 48 49 baseheat = heater (5) ; heater = heater ( startTime : length ( heater ) ) ; heater = heater − baseheat ; 50 51 len = length ( heater ) ; 52 53 54 temp = temp ( s t a r t T i m e : l e n g t h ( temp ) ) ; temp = temp − temp ( 1 ) ; 55 56 57 time = time2 ( s t a rt T im e : length ( time ) ) ; time = time − time (1) ; 58 199 59 60 61 t = time ; y = temp ; u = heater ; 62 63 64 65 66 x0 = [ 0 . 2 0 . 2 0 . 5 0 . 5 ] ; / / C h a n g e i n delay = 5; / / Change delay here global delay ; [ f , x o p t ] = optim ( c o s t f u n c t i o n , x0 ) ; i t i a l guess here 67 68 69 70 71 a1 a2 b1 b2 = = = = xopt (1) xopt (2) xopt (3) xopt (4) 72 73 y pred = second order ( u , xopt ) ; 74 75 76 77 78 i f s i z e ( y ) ˜= s i z e ( y p r e d ) t h e n y pred = y pred ’ ; end e r r = norm ( y − y p r e d ) / norm ( y ) 79 81 p l o t ( t , y , ”+” ) ; plot ( t , y pred , ”k” ) ; 82 / / p l o t ( t , 80 u /10 , ” r ”) ; 83 84 l a b e l ( ’ Showing Second O r d e r Model and E x p e r i m e n t a l R e s u l t s ’ , 4 , ’ Time ( s ) ’ , ’ Change i n t e m p e r a t u r e (K) ’ ,4) ; Scilab Code 9.15 prbs.sci 1 2 3 4 5 6 7 f u n c t i o n u=PRBS ( a c t i v e ) i f a c t i v e == 0 t h e n u = 0; else g l o b a l PRBSu PRBScount ; i f PRBSu == [ ] t h e n PRBSu = 1 ; 200 8 9 10 11 12 13 14 15 16 17 18 19 PRBScount = 3 0 ; end i f PRBScount == 0 t h e n PRBSu = −1 * PRBSu ; PRBScount = i n t ( rand ( ) * 4 0 ) +10; else PRBScount = PRBScount − 1 ; end u = PRBSu ; g l o b a l PRBSu PRBScount ; end endfunction Scilab Code 9.16 prbstest.sci 1 function [ stop ] = p r b s t e s t ( heat , fan ) 2 3 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 4 p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 25 0 ] , [ 1 0 0 100 50 1000]) ; 5 6 endfunction Scilab Code 9.17 prbstest.sce 1 2 mode ( 0 ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 3 4 5 6 7 8 / / ********************** s a m p l i n g t i m e =1; / / In seconds . / / * * * * * * * * * * * * * * * * * * * * * * / / exec ( ” p r b s t e s t . s c i ” ) ; exec ( ” prbs . s c i ” ) ; 9 10 ok = i n i t ( ) ; 11 201 F r a c t i o n s are allowed i f ok ˜= [ ] 12 through ( ie open xcos only if communication r e p l y has come from is s e r v e r ) xcos ( ’ p r b s t e s t . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 13 14 15 16 17 / / end Scilab Code 9.18 second order.sci 1 2 3 4 5 6 7 8 f u n c t i o n y = s e c o n d o r d e r ( u , params ) / / Do not change a1 = p a r a m s ( 1 ) a2 = p a r a m s ( 2 ) b1 = p a r a m s ( 3 ) b2 = p a r a m s ( 4 ) global delay ; / / a n y t h i n g here ; ; ; ; End 9 10 11 / / / You should w r i t e your code below t h i s l i n e N= l e n g t h ( u ) ; 12 13 / / D e f i n i n g y 14 / / from up t =0 i n d i c e s 15 16 18 19 20 21 t = delay −1 , to i =1 up to i = delay / / F i r s t nonzero i . e . in o u t p u t s c i l a b is only i n p u t u in s c i l a b y at 0 due at to i n p u t u at t i =1 / / After t h a t y ( i ) can be d e f i n e d as f o l l o w s f o r i = d e l a y + 2 : 1 :N y ( i ) =−a1 * y ( i −1)−a2 * y ( i −2)+b1 * u ( i − d e l a y ) +b2 * u ( i −1− d e l a y ) ; end / / y = ? 24 25 is so y ( d e l a y +1) = b1 * u ( 1 ) ; 22 23 y =0 , y ( 1 : 1 : delay ) = 0; =0 , 17 v e c t o r endfunction 202 9.10.2 Controller codes Scilab Code 9.19 prbs.sce 1 2 mode ( 0 ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 3 4 g l o b a l s c n s c d t c n t c d r c n r c d gamm 5 6 g e t d ” dc / s c i l a b ” 7 8 9 10 11 12 13 / / ********************** s a m p l i n g t i m e =1; / / In seconds . F r a c t i o n s are allowed / / * * * * * * * * * * * * * * * * * * * * * * / / exec ( ” p r b s c o n t r o l − v i r t u a l . s c i ” ) ; exec ( ” twodof para . sce ” ) ; / / exec (” s b h s c o n t r o l . sci ”) ; 14 15 16 17 / / [ scn , scd , t c n , t c d , rcn , rcd , gamm ] = s b h s c o n t r o l () 18 19 ok = i n i t ( ) ; 20 i f ok ˜= [ ] 21 through ( ie open xcos only if r e p l y has come from communication s e r v e r ) xcos ( ’ p r b s c o n t r o l − v i r t u a l . xcos ’ ) ; else d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 22 23 24 25 26 / / end Scilab Code 9.20 prbscontrol-virtual.sci 1 f u n c t i o n [ s t o p , temp ] = p r b s t e s t ( h e a t , f a n , s e t p ) 203 is g l o b a l s c n s c d t c n t c d r c n r c d gamm 2 3 [ s t o p , temp ] = comm ( h e a t , f a n ) ; 4 / / Never e d i t t h i s l i n e p l o t t i n g ( [ h e a t f a n temp ] , [ 0 0 25 0 ] , [ 1 0 0 100 50 1000]) 5 6 7 endfunction Scilab Code 9.21 twodof para.sce 1 2 3 4 5 6 mode ( 0 ) g l o b a l Rc Sc Tc gamm g l o b a l s c n s c d t c n t c d r c n r c d gamm s=%s ; z=%z ; / / / / TFcont = s y s l i n ( ’ c ’ , −280.14/(( s −31.32) *( s +100) *( s +31.32) ) ) ; 7 / / TFcont = 8 / / / / TFcont 9 / / SScont s y s l i n ( ’ c ’ , 0 . 5 9 3 / ( ( 4 7 . 2 1 * s +1) * ( 1 . 3 7 3 * s +1) ) ) / / second order = s y s l i n ( ’ c ’ , 0 . 5 9 4 / ( 4 9 . 1 9 * s +1) ) / / f i r s t order 10 = t f 2 s s ( TFcont ) ; / / / / TFdisc = s s 2 t f ( SScont ) ; 11 / / Ts 12 / / [B ,A , k ] = 13 / / 14 / / / / p o l y n o m i a l s 15 / / [ Ds , num , d e n ] 16 / / num 1; = = myc2d ( SScont , Ts ) ; are = r e t u r n e d s s 2 t f ( SScont ) ; c l e a n ( num ) ; den = for Part clean ( den ) ; 17 18 Ts = s a m p l i n g t i m e ; 19 20 21 22 23 / / T r a n s f e r f u n c t i o n A = [ 1 −1.9529968 0 . 9 5 3 1 2 6 9 ] ; B= [ 0 . 0 0 5 7 3 8 4 − 0 . 0 0 5 7 3 5 5 ] ; k = 3; 24 204 − B 25 / / T r a n s f e r 26 / / B = [ 0 . 0 0 4 3 7 7 9 27 / / A = [1 28 / / k = 5; f u n c t i o n for Part − A −0.0043266]; −1.9444137 0 . 9 4 4 7 8 1 8 ] ; 29 30 31 32 r i s e = 10; epsilon = 0.1; Nr = r i s e / Ts ; 33 34 / / 35 / / r i s e 36 p h i = d e s i r e d ( Ts , r i s e , e p s i l o n ) ; T r a n s i e n t = 10; s p e c i f i c a t i o n s e p s i l o n = 0 . 0 5 ; 37 38 39 40 / / C o n t r o l l e r design Delta = [1 −1]; [ Rc , Sc , Tc , gamm ] = pp im ( B , A, k , p h i ) ; / / with i n t e g r a l 41 42 43 44 45 / / S e t t i n g up s i m u l a t i o n st = 0.0001; / / t i n i t = 0; / / t final = 0.5; d e s i r e d p a r a m e t e r s change s i m u l a t i o n / / in s t a r t s i m u l a t i o n for h , in b a s i c . cos m. time end time 46 47 48 / / S e t t i n g up s i m u l a t i o n p a r a m e t e r s for c 51 [ Tc1 , Rc1 ] = c o s f i l i p ( Tc , Rc ) ; [ Sc2 , Rc2 ] = c o s f i l i p ( Sc , Rc ) ; / / Tc / Rc / / Sc / Rc 52 53 54 [ Bp ] = c o s f i l i p ( B , 1 ) ; [ Ap ] = c o s f i l i p (A, 1 ) ; 55 56 57 58 59 c l . cos N var = 0 ; x I n i t i a l = [0 0 0 ] ; N = 1 ; C = 0 ; D = 1 ; 49 50 s s [ Tcp1 , Tcp2 ] = c o s f i l i p ( Tc , 1 ) ; / / [ Np , Rcp ] = c o s f i l i p (N, Rc ) ; / / 1 / [ Scp1 , Scp2 ] = c o s f i l i p ( Sc , 1 ) ; / / [ Cp , Dp ] = c o s f i l i p ( C , D) ; / / C / D Tc / 1 Rc Sc /1 60 61 / / Rc1 = Rc ( 1 ) ; Rc2 = Rc ( 2 ) ; Rc3 = Rc ( 3 ) ; Rc4 = Rc ( 4 ) ; 62 / / Sc1 = Sc ( 1 ) ; Sc2 = Sc ( 2 ) ; 205 63 / / Sc3 = Sc ( 3 ) ; 64 / / Tc1 = Tc ( 1 ) ; Tc2 = Tc ( 2 ) ; 65 / / Tc3 = Tc ( 3 ) ; 66 67 68 69 Rcp Scp1 Tcp1 gamm 70 71 72 73 74 75 s c n = p o l y ( Sc ( l e n g t h ( Sc ) : − 1 : 1 ) , ’ z ’ , ’ c o e f f ’ ) ; t c n = p o l y ( Tc ( l e n g t h ( Tc ) : − 1 : 1 ) , ’ z ’ , ’ c o e f f ’ ) ; r c n = p o l y ( Rc ( l e n g t h ( Rc ) : − 1 : 1 ) , ’ z ’ , ’ c o e f f ’ ) ; 76 77 78 79 s c d = z ˆ ( l e n g t h ( Sc ) −1) ; r c d = z ˆ ( l e n g t h ( Rc ) −1) ; t c d = z ˆ ( l e n g t h ( Tc ) −1) ; 206 Chapter 10 Implementing Internal Model Controller for First Order System on a Single Board Heater System This experiment aims to implement an Internal Model Controller for first order systems on a Single Board Heater System. The target group is anyone possessing basic knowledge of control engineering. Scilab is used with Xcos as an interface for sending and receiving data. This interface is shown in figure 10.1. Fan speed and heater current are the two inputs to the system. For this experiment, the heater current is the control effort or manipulated variable. The fan input is considered to be the external disturbance. 10.1 IMC Design for Single Board Heater System Internal Model Controller contains explicit model of plant [5]. The closed loop system can be stabilized with the use of a stable open loop transfer function and a stable controller. The IMC is mainly used for stable plants. Let the transfer function of the stable plant be denoted by G p (z) and its model is denoted by G(z). Hence y(n) = G(z)u(n) + ξ(n) where: y(n) = plant output 207 (10.1) Figure 10.1: Xcos interface for this experiment ξ e r G Q (z) u y G p (z) − G(z) ȳ Figure 10.2: IMC feedback configuration 208 − ξ e r G Q (z) u G p (z) y ξ̄ G(z) Figure 10.3: Feedback configuration u(n) = plant input ξ(n) = noise For noise rejection with y=0, we require G Q = G−1 p and G = G p , i.e., for stable G Q we require an approximate inverse of G. Also, for internal stability, transfer function between any two points in the feedback loop must be stable [5]. 10.2 Step for Designing IMC for Stable Plant IMC design refers to obtaining a realizable G Q that is stable and approximately inverse of G. This can be achieved by inverting the delay free plant model so that G Q is realizable. For non-minimum phase part of the plant, reciprocal polynomial is used for stable controller. Negative real part of the plant should be replaced with the steady state equivalent of that part to avoid oscillatory nature of control effort. Low pass filter must be used to avoid the high frequency components because of the model mismatch. The SBHS is modeled asG = Z −1 0.01163 1 − 0.9723Z −1 (10.2) Inverting delay free plant, we get A 1 − 0.9723Z −1 = B 0.01163 209 (10.3) Comparing plant model with equation G = Z −1 Bg B− Bnm+ A (10.4) We get, Bg = 0.01163 B− = 1 Bnm+ = 1 (10.5) (10.6) (10.7) A = 1 − 0.9723Z −1 (10.8) For the stable system, internal model controller is given by A Gf Bg B−s Bnm+ r 1 − 0.9723Z −1 1 − α GQ = 0.01163 1 − αZ −1 GQ = (10.9) (10.10) Now, Gc = GQ 1 − GG Q (10.11) 1−0.9723Z −1 1−α u 0.01163 1−αZ −1 = e 1 − Z −1 0.01163 −1 1−0.9723Z −1 1−α−1 0.01163 1−αZ 1−0.9723Z (10.12) After simplifying, we get 1 − α 1 − 0.9723Z −1 u = e 0.01163 1 − Z −1 u 1 − 0.9723Z −1 =b e 1 − Z −1 (10.13) (10.14) where, b= 1−α 0.01163 (10.15) 210 Figure 10.4: Experimental results with IMC for α = 0.92 Hence, u(n) = u(n − 1) + b[e(n) − 0.9723e(n − 1)] (10.16) The output of Xcos is shown in figure 10.4. Figure shows three plots. First sub plot shows setpoint and output temperature profile. Second sub plot shows control effort and third sub plot shows error between setpoint and plant output. The same experiment result for α = 0.85 is as shown in fig 10.5. By comparing the two graphs, we can say that for α = 0.92 the response of the controller is sluggish. For α = 0.85, the controller starts responding quickly and no overshoots are seen in the temperature profile. 211 Figure 10.5: Experimental results with IMC for α = 0.85 212 10.2.1 Implementing IMC locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is imc controller 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load ramp test function by executing command exec imc.sci 6. Step6: Load Xcos code for ramp test using the command exec imc.xcos 7. Step7: Same 10.2.2 Implementing IMC virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is imc controller. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the IMC experiment directory and double-click on the file imc.sce. This will launch scilab and also open the file imc.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to imc controller and then open the imc.sce file in the scilab editor. 5. Step5: Same 213 6. Step6: Execute the file imc.sce. Expect the IMC controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the IMC controller xcos diagram. 8. Step8: Same 10.3 Scilab Code Scilab Code 10.1 ser init.sce 1 2 3 4 5 6 mode ( 0 ) global filename m / / ** S a m p l i n g Time * * / / sampling time = 1; / / / / / / / * * * * / / / / / / / / / m=1; 7 8 9 p o r t 1 = ’ / dev / ttyUSB0 ’ ; / / F o r p o r t 2 = ’COM2 ’ ; / / F o r w i n d o w s l i n u x u s e r s u s e r s 10 11 12 res= i n i t ([ port1 port2 ]) ; disp ( res ) Scilab Code 10.2 imc.sci 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = imc ( s e t p o i n t , f a n , a l p h a ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 4 5 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 6 7 8 e new = s e t p o i n t − temp ; b =((1 − a l p h a ) / 0 . 0 1 1 6 3 ) ; 9 214 10 u new = u o l d + b * ( e new − ( 0 . 9 7 2 3 * e o l d ) ) ; 11 12 13 14 u o l d = u new ; e o l d = e new ; 15 16 17 h e a t = u new ; 18 temp = comm ( h e a t , f a n ) ; 19 20 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 21 22 23 24 m=m+1; endfunction Scilab Code 10.3 imc virtual.sce 1 2 mode ( 0 ) ; / / For s c i l a b command to 5 . 1 . 1 open or lower s c i c o s v e r s i o n diagrams users i n s t e a d , use of s c i c o s xcos 3 4 g l o b a l f d f h f d t f n c r fncw m e r r c o u n t y l i m i t s sampling time m 5 6 / / ********************** 7 s a m p l i n g t i m e =1; 8 / / * * * * * * * * * * * * * * * * * * * * * * / / / / In seconds . F r a c t i o n s are allowed 9 10 exec ( ” i m c v i r t u a l . s c i ” ) ; 11 12 ok = i n i t ( ) ; 13 14 i f ok ˜= [ ] through 15 16 / / ( ie open xcos only if r e p l y has come from x c o s ( ’ imc . x c o s ’ ) ; else 215 communication s e r v e r ) is d i s p ( ”NO NETWORK CONNECTION! ” ) ; return 17 18 19 end Scilab Code 10.4 imc virtual.sci 1 mode ( 0 ) 2 3 4 f u n c t i o n [ s t o p ] = i m c v i r t u a l ( s e t p o i n t , fan , a l p h a ) 5 6 g l o b a l temp h e a t C0 u o l d u new e o l d e new f d f h f d t f n c r fncw m e r r c o u n t s t o p q h e a t d i s p f a n d i s p tempdisp s e t p o i n t d i s p l i m i t s m x sampling time e old old 7 8 e new = s e t p o i n t − temp ; 9 10 11 b =((1 − a l p h a ) / 0 . 0 1 1 6 3 ) ; u new = u o l d + b * ( e new − ( 0 . 9 7 2 3 * e o l d ) ) ; 12 13 14 15 16 h e a t =u new ; u o l d = u new ; e o l d = e new ; 17 18 19 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 20 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 21 22 endfunction 216 Chapter 11 Design and Implementation of Self Tuning PI and PID Controllers on Single Board Heater System 11.1 Introduction This chapter presents design and implementation of Self Tuning PI and PID controllers on Single Board Heater System done by Mr. Vikas Gayasen.1 When a plant is wired in a close loop with a PID controller, the parameters- Kc , τi and τd determine the variation of the manipulated input that is given to the controller. This, in turn, determines the variation of the controlled variable, when a set point is given. Suitable values of these parameters can be found out when plant transfer function is known. However, with large changes in the controlled variable, there may be appreciable changes in the plant transfer function itself. Therefore, it is needed to dynamically update the controller parameters according to the transfer function. 11.2 Theory 11.2.1 Why a Self Tuning Controller? The transfer function of SBHS is assumed as 1 Copyright: Mr. Vikas Gayasen, student of Prof. Kannan Moudgalya, IIT Bombay for Process Control course, 2010 217 ∆T = Kp Kf ∆H + ∆F τp s + 1 τf s + 1 (11.1) ∆T: Temperature change ∆F: Fan input change ∆H: Heater input change The values of K p , K f , τ s and τ f can be found by conducting step test experiments. Using these values, the parameters (Kc , τi and τd ) of the PID controller can be defined using methods like Direct Synthesis of Ziegler Nichols Tuning. However, when the apparatus is used in over a large range of temperature, the values of the plant parameters (K p , K f , τ s and τ f ) may change. The new values would give new values of PID controller parameters. However, in a conventional PID controlled system, the parameters Kc ,τi and τd are defined beforehand and are not changed when the system is working. Therefore, we might have a situation in which the PID controller is working with unsuitable values that may not give the desired performance.Therefore, it becomes necessary to change or update the values of the PID parameters so that the plant gives the optimum performance. 218 11.2.2 The Approach Followed Variable Description: • Manipulated Variable: Heater Input • Disturbance Variable: Fan Input • Controlled Variable: Temperature Several open loop step test experiments were performed (giving step changes in the heater input) and the values of K p and τ p were found from the results of each experiment by fitting the Inverse Laplace transform of the assumed transfer function with the experimental data. These values were plotted with respect to the corresponding average temperatures. From these plots, correlations were found for both K p and τ p as functions of temperature. From correlations of K p and τ p , the PID parameters were calculated as functions of temperature. Thus, in the new PID controller, the values of Kc , τi and τd were calculated using the temperature of the system. For the calculation of PID settings, two approaches: Direct Synthesis and Ziegler-Nichols Tuning were followed. 11.2.3 Direct synthesis Loop Circuit.jpg Figure 11.1: Closed loop circuit We have V(s) = Gc (s)G(s) 1 + Gc (s)G(s) 219 (11.2) where V(s) : Overall closed-loop transfer function Gc (s) : Controller transfer function G(s) : System transfer function. Therefore, Gc (s) = V(s) 1 G(s) 1 − V(s) (11.3) Let the desired closed loop transfer function be of the form 1 (τcl s + 1) Kp G(s) = (τ ps + 1) V(s) = (11.4) (11.5) By using the equations for G(s) and V(s), we get G(c) = Kc (1 + 1 ) τs (11.6) where, Kc = 1 (τ p /τcl ) Kp τi = τ p (11.7) (11.8) When K p and τ p are known as a function of time, the values of Kc and τi can be found as functions of temperature as well. 220 11.3 Ziegler Nichols Tuning For Ziegler Nichols Tuning, we use the step response of the open loop experiment. Figure 11.2: Tangent approach to Ziegler Nichols Tuning P PI PID Kc 1/RL 0.9/RL 1.2/RL τi τd 3L 2L .5L Table 11.1: Ziegler Nichols PID Settings Table 11.1 gives the PID settings. In this approach too, for every open step test, K and τ are found and correlated as function of average temperature and PID settings are then found as functions of temperature. Note: For a first order transfer function we assume • Kp ≈ K • τp ≈ τ 221 Figure 11.3: Step response for heater reading from 10 to 15 11.4 Step Test Experiments and Parmeter Estimation Several open loop step test experiments were conducted and the values of the open loop parameters were found by curve fitting. 11.4.1 Step Test Experiment 11.4.1.1 Step change in heater reading from 10 to 15 222 Figure 11.4: Step response for heater reading from 10 to 15 in terms of deviation 11.4.1.2 Step Change in Heater Reading from 20 to 25 Figure 11.5: Step response for Heater Reading from 20 to 25 223 Figure 11.6: Step response for heater reading from 20 to 25 in terms of deviation 11.4.1.3 Step Change in Heater Reading from 30 to 35 Figure 11.7: Step response for heater reading from 30 to 35 224 Figure 11.8: Step response for heater reading from 30 to 35 in terms of deviation 11.4.1.4 The Open Loop Parameters Initial Heater Reading Final Heater Reading Average Temperature(0 C) K p 10 15 31.57 0.41 20 25 36.00 0.50 30 35 41.79 0.58 Table 11.2: Open loop parameters It can be seen from the graphs that there is a lag of approximately 6 seconds in each experiment. 11.4.2 Conventional Controller Design 1. PI Controller using Ziegler Nichols Tuning with the results of the first step test experiment: • Kc = 19.75 • τi = 18 225 τp 53.37 52.64 49.21 2. PID Controller using Ziegler Nichols Tuning with the results of the first step test experiment: • Kc = 26.327 • τi = 12 • τd = 3 3. PI Controller Using Direct Synthesis with the results of the second step test experiment (τcl is taken as τ p /2): • Kc = 4.02 • τi = 52.645 11.4.3 Self Tuning Controller Design The graphs showing the variation of Kp and τ p are shown below: Figure 11.9: Variation of K p with temperature 226 Figure 11.10: Variation of τ p with temperature 1. PI Controller using Ziegler Nichols Tuning: L=6 R = (0.016×T-0.114)/(66.90-0.415×T) where T is the temperature Kc = 0.9(66.90-0.415T)/6(0.016T-0.114) = (60.21 - 0.3735T)/(0.096T - 0.684) τi = 3 × 6 = 18 2. PID Controller using Ziegler Nichols Tuning: L=6 R = (0.016 × T-0.114)/(66.90-0.415 × T) where T is the temperature K = 1.2(66.90-0.415T)/6(0.016T-0.114) = (80.28 - 0.498T)/(0.096T - 0.684) τi = 2 × 6 = 12 τd = 0.5×6 = 3 3. PI Controller using Direct Synthesis (τcl is taken as τ p /2): 227 K = 2/(0.016×T-0.114) τi = (66.90-0.415×T) where T is the temperature 11.5 PID controller theory 11.5.1 PI Controller Figure 11.11: Xcos diagram for PI controller The PI Controller in continuous time is given by " # Z 1 t u(t) = K e(t) + e(t)dt τi 0 On taking Laplace transform, we obtain " # 1 u(s) = K 1 + e(s) τi s 228 (11.9) (11.10) By mapping equation 11.10 to discrete time interval using Backward Difference Approximation, we get # " Ts z e(n) (11.11) u(n) = K 1 + τi z − 1 On cross multiplication, we obtain " # Ts (z − 1) × u(n) = K (z − 1) + (z) e(n) τi We divide by z, and using the shifting theorem, we obtain " # Ts u(n) − u(n − 1) = K e(n) − e(n − 1) + e(n) τi (11.12) (11.13) The PI Controller is usually written as u(n) = u(n − 1) + s0 e(n) + s1 e(n − 1) (11.14) where, Ts s0 = K 1 + τi s1 = −K 11.5.2 ! PID Controller The PID Controller in continuous time is given by " # Z 1 t de(t) u(t) = K e(t) + e(t)dt + τd τi 0 dt On taking Laplace Transform, we obtain # " 1 + τd s e(s) u(s) = K 1 + τi s (11.15) (11.16) By mapping equation 11.16 to discrete time interval by using the Trapezoidal Approximation for integral mode and Backward Difference Approximation for derivative mode, we get " # Ts z τd z − 1 u(n) = K 1 + + e(n) (11.17) τi z − 1 T s z 229 Figure 11.12: Xcos diagram for PID controller On cross multiplication, we obtain " # Ts 2 τd 2 2 2 (z − z) × u(n) = K (z − z) + (z ) + (z − 1) e(n) τi Ts (11.18) We divide by z, and using the shifting theorem, we obtain " # Ts τd u(n) − u(n − 1) = K e(n) − e(n − 1) + e(n) + {e(n) − 2e(n − 1) + e(n − 1)} τi Ts (11.19) The PID Controller is usually written as u(n) = u(n − 1) + s0 e(n) + s1 e(n − 1) + s2 e(n − 2) 230 (11.20) where, T s τd + s0 = K 1 + τi T s " # τd s1 = K −1 − 2 Ts " # τd s2 = K Ts 11.5.3 ! (11.21) (11.22) (11.23) Self Tuning Controller Figure 11.13: Xcos diagram for self tuning controller The parameters of the controller are determined dynamically using the temperature values for every sampling time. For this, the formulae derived in section 11.4.3 are used. The formulae for the control effort are same as the conventional PI and PID controllers. So the PI/PID settings are calculated for every sampling 231 time and the control effort is calculated thereafter using the formulae derived for conventional controllers. 11.6 Set Point Tracking The main aim of the controller is to track the set point and to reject disturbances. When the set point of the controlled variable (temperature in this case) is changed, the controller should work in such a manner that the actual temperature follows the set point as close as possible. In this project, several experiments were conducted with the self tuning and conventional PI/PID Controllers. Table 11.3 shows the set point changes given during the various experiments that were conducted with conventional and self tuning controllers designed using several methods. Conventional Controller Direct Synthesis PI 320 C to 370 C 350 C to 450 C Ziegler Nichols PI 320 C to 370 C 350 C to 450 C 400 C to 450 C Ziegler Nichols PID 310 C to 450 C 320 C to 370 C Self Tuning Controller 320 C to 370 C 350 C to 450 C 320 C to 370 C 350 C to 450 C 350 C to 450 C 320 C to 460 C 320 C to 370 C Table 11.3: Set point changes in experiments conducted for set point tracking 232 11.6.1 PI Controller Designed by Direct Synthesis The results of the experiments carried out for the self tuning PI controller using direct synthesis method are shown. The upper plot shows the variations of the set point temperature (the black line) and the actual temperature (the green line) in the SBHS. The lower plot shows the control effort. Figure 11.14: Result for self tuning controller designed using Direct Synthesis for set point going from 320 C to 370 C Although there is a small overshoot, the controller is able to make the actual temperature follow the set point temperature quiet closely. Looking at higher values of set point changes, the result for set point change going from 350 C to 450 C is shown. Figure 11.15: Result for self tuning controller designed using Direct Synthesis for set point going from 350 C to 450 C For a higher set point change also, the controller is able to make the temperature follow the set point closely. Notice the abrupt change in the control effort as soon as the step change in the set point is encountered. 233 For comparison, results of experiments done with conventional PI controller designed using the Direct Synthesis method are also shown. Figure 11.16: Result for conventional controller designed using Direct Synthesis for set point going from 320 C to 370 C Figure 11.17: Result for conventional controller designed using Direct Synthesis for Set Point going from 350 C to 450 C As it can been seen from the graph, the self tuning controller stabilised the temperature faster. 234 11.6.2 PI Controller using Ziegler Nichols Tuning The results of the of the experiments carried out for the self tuning PI controller using Ziegler Nichols tuning method are shown. The upper plot shows the variations of the set point temperature (the black line) and the actual temperature (the green line) in the SBHS. The lower plot shows the control effort. Figure 11.18: Result for self tuning controller designed using Ziegler Nichols Tuning for set point going from 320 C to 370 C Although there are oscillations, the temperature remains near the set point. The result for a higher value of set point change is also shown. Figure 11.19: Result for self tuning controller designed using Ziegler Nichols Tuning for set point going from 350 C to 450 C For this experiment, the controller is able to make the temperature follow the set point closely. The fluctuations may be due to noises and the surrounding conditions.The plot for result of an experiment with another value of set point change is also shown. In this experiment too, the controller is able to keep the temperature close to the set point and it stabilises fast. 235 Figure 11.20: Result for self tuning controller designed using Ziegler Nichols Tuning for set point going from 400 C to 450 C For comparison, results of experiments done with conventional PI controller designed using the Ziegler Nichols method are also shown. Figure 11.21: Result for conventional controller designed using Ziegler Nichols Tuning for set point going from 320 C to 370 C 236 Figure 11.22: Result for conventional controller designed using Ziegler Nichols Tuning for set point going from 350 C to 450 C Figure 11.23: Result for conventional controller designed using Ziegler Nichols Tuning for set point going from 400 C to 450 C For set point change from 400 C to 450 C, the self tuning controller showed small oscillations, but the conventional controller shows bigger oscillations. 237 11.6.3 PID Controller using Ziegler Nichols Tuning The results of the of the experiments carried out for the self tuning PID controller using Ziegler Nichols tuning method are shown. The upper plot shows the variations of the set point temperature (the black line) and the actual temperature (the purple line) in the SBHS. The lower plot shows the control effort. Figure 11.24: Result for self tuning PID controller designed using Ziegler Nichols Tuning for set point going from 320 C to 370 C Figure 11.25: Result for self tuning PID controller designed using Ziegler Nichols Tuning for set point going from 320 C to 460 C From the graph it can be seen that for both the experiments, the self tuning PID controller is able to keep the temperature close to the set point and the stabilisation is also fast. For comparison, plots for experiments conducted with conventional PID controller designed using Ziegler Nichols method are also shown. From the graph, we can see that the conventional PID controller is not able to make the temperature close to the set point when the set point value is 450 C. The self tuning PID controller had successfully brought the temperature to 450 C. 238 Figure 11.26: Result for conventional PID controller designed using Ziegler Nichols Tuning for set point going from 320 C to 370 C Figure 11.27: Result for conventional PID controller designed using Ziegler Nichols Tuning for set point going from 310 C to 450 C 11.6.4 Conclusion The self tuning PI controller is able to accomplish the aim of keeping the temperature as close as possible to the set point. Although it may show some initial overshoot or oscillation for some values of set point change, the time needed for stabilisation is low. There may also some cases where the conventional controller shows bigger oscillations than the self tuning controller. The PI controllers, both conventional and self tuning, show oscillations for some values of set point change. To eliminate the oscillations, when we use the PID Controller, the self tuning design definately seems to be a better option because for higher values of set point change, the self tuning PID controller shows a better performance than the conventional controller as seen in section 11.6.3. 239 11.7 Disturbance Rejection Apart from tracking the set point, the system should also be able to reject disturbances. There may be several factors influencing the controlled variable and not all of them can be manipulated. Therefore, it becomes necessary for the controller to not let the changes in the non-manipulated variables to affect the controlled variable. This is called Disturbance Rejection. In this system, the disturbance variable is the fan input. Therefore, the controller has to work in such a way that changes in the fan input does not affect the temperature in the SBHS. In this project, several experiments were conducted with the self tuning and conventional PI/PID Controllers. Table 11.4 shows the fan input changes given during the various experiments that were conducted with conventional and self tuning controllers designed using several methods. Conventional Controller Direct Synthesis PI 50 to 100 100 to 50 Ziegler Nichols PI 50 to 100 100 to 50 Ziegler Nichols PID 50 to 100 100 to 50 Self Tuning Controller 50 to 100 100 to 50 50 to 100 100 to 50 50 to 100 100 to 50 Table 11.4: Fan input changes in experiments conducted for Disturbance Rejection 11.7.1 PI Controller Designed by Direct Synthesis The results of the experiments carried out for the self tuning PI controller using Direct Synthesis method are shown. The upper plot shows the variations of the set point temperature (the black line) and the actual temperature (the green line) in the SBHS. The second plot shows the control effort and the third shows the fan input. The change in the fan input introduces a small dent in the temperature. However, the controller brings the temperature back to the set point. Notice the slight change in the controller behaviour on encountering the fan input change. The time taken for stabilising back is also low. 240 Figure 11.28: Results for fan input change from 50 to 100 for self tuning PI Controller designed using Direct Synthesis Here, results for fan input change from 100 to 50 are also shown. Figure 11.29: Results for fan input change from 100 to 50 for self tuning PI controller designed using Direct Synthesis In this figure also, the temperature clearly increases a bit when the step change in the fan input is encountered. However, it quickly stabilises back and continues to be close to the set point. From the above two results, it is clear that the self tuning controller designed with Direct Syntheis has successfully rejected the disturbance. For comparison, results of the disturbance change for conventional PI Controller designed with direct synthesis are also shown. 241 Figure 11.30: Results for the fan input change from 50 to 100 to conventional PI controller designed using Direct Synthesis 242 Figure 11.31: Results for the fan input change from 100 to 50 to conventional PI controller designed using Direct Synthesis 11.7.2 PI Controller using Ziegler Nichols Tuning The results of the experiments carried out for the self tuning PI controller using Ziegler Nichols method are shown. The upper plot shows the variations of the set point temperature (the black line) and the actual temperature (the green line) in the SBHS. The second plot shows the control effort and the third shows the fan input. Even on encountering the fan input change, the temperature remains close to the set point. Notice the change in the controller behaviour on encountering the fan input change. 243 Figure 11.32: Results for Fan Input change from 50 to 100 given to Self Tuning PI Controller designed using Ziegler Nichols method Here, result for the fan input going from 100 to 50 is also shown. Here, a change in the control effort can be noticed. This change has been brought by the PI Controller to keept the temperature close to the set point. From the above two results, it is clear that the self tuning controller designed with direct syntheis has successfully rejected the disturbance. 244 Figure 11.33: Results for fan input change from 100 to 50 given to self tuning PI controller designed using Ziegler Nichols method For comparison, corresponding results are also shown for conventional PI controllers designed using Ziegler Nichols tuning. 245 Figure 11.34: Results for the fan input change from 50 to 100 to conventional PI controller designed using Ziegler Nichols tuning 11.7.3 PID Controller using Ziegler Nichols Tuning The results of the experiments carried out for the self tuning PID controller using Ziegler Nichols method are shown. The upper plot shows the variations of the set point temperature (the black line) and the actual temperature (the purple line) in the SBHS. The second plot shows the control effort and the third shows the fan input. In this system also, on encountering the fan input change, the temperature remains close to the set point. Notice the change in the control effort profile when the change in the fan input is given. 246 Figure 11.35: Results for the fan input change from 100 to 50 to conventional PI controller designed using Ziegler Nichols tuning Here, result for the fan input going from 100 to 50 is also shown. In this figure also, the temperature clearly increses a bit when the step change in the fan input is encountered. However, it quickly stabilises back and continues to be close to the set point. 247 Figure 11.36: Results for Fan Input change from 50 to 100 given to Self tuning PID Controller designed using Ziegler Nichols method For comparison, corresponding results are also shown for conventional PID controllers designed using Ziegler Nichols tuning. 11.7.4 Conclusion We see that the self tuning controller manages to keep the temperature close to the set point temperature, even when the change in fan input is encountered. This shows that it can reject the disturbances quite nicely. 11.8 Conducting experiments locally Under the local folder locate Self tuning controller folder. You will see two folders ConventionalTuning Vikas and SelfTuning Vikas. These two directories will contain four more folders, two for PI and two for PID. The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is one of the four experiments you want to do. For example virtual/Self tuning controller/SelfTuning Vikas /PIControllerFandisturbance 248 Figure 11.37: Results for fan input change from 100 to 50 given to self tuning PID controller designed using Ziegler Nichols method 2. Step2: Load the functions available in common files directory by executing the command getd ..\..\..\common files 3. Step3: Same 4. Step4: Same 5. Step5: Load required function by using exec command. For example, exec pi bda tuned dist.sce if you want to run the PI Controller Fan disturbance experiment. 6. Step6: Load Xcos code for corresponding experiment using xcos command. For example exec pi tuned dist.xcos 7. Step7: Same 11.9 Conducting experiments virtually Under the local folder locate Self tuning controller folder. You will see two folders ConventionalTuning Vikas and SelfTuning Vikas. These two directories will contain four more folders, two for PI and two for PID. 249 Figure 11.38: Results for the fan input change from 50 to 100 to conventional PID controller designed using Ziegler Nichols tuning The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 1. Step1: The working directory is one of the four experiments you want to do. For example virtual/Self tuning controller/SelfTuning Vikas /PIControllerFandisturbance 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the working experiment directory and double-click on the .sce file corresponding to the experiment you want to perform. For example, pi bda tuned dist.sce if you want to run the PI Controller Fan disturbance experiment. This will launch scilab and also open the file in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to corresponding experiment and then open the .sce file in the scilab editor. 5. Step5: Load the functions available in common files directory by executing the command getd ..\..\..\common files 250 Figure 11.39: Results for the fan input change from 100 to 50 to conventional PID controller designed using Ziegler Nichols tuning 6. Step6: Execute the .sce file. Expect the corresponding xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the xcos diagram. 8. Step8: Same 11.10 Scilab Codes Scilab Code 11.1 ser init.sce 1 2 3 mode ( 0 ) global filename / / ** S a m p l i n g Time * * / / 4 sampling time = 1; 5 / / / / / / / * * * * / / / / / / / / / 6 m=1; 7 8 9 p o r t 1 = ’ / dev / ttyUSB0 ’ ; / / F o r p o r t 2 = ’COM2 ’ ; / / F o r w i n d o w s 251 l i n u x u s e r s u s e r s 10 11 12 res= i n i t ([ port1 port2 ]) ; disp ( res ) 11.10.1 Conventional Controller, local 11.10.1.1 Fan Disturbance in PI Controller Scilab Code 11.2 pi bda dist.sci 1 2 mode ( 0 ) / / g l o b a l temp f a n d i s p 3 4 heat tempdisp f u n c t i o n temp = global heatdisp sampling time u new e o l d e fan x s a m p l i n g t i m e m h e a t d i s p name p i b d a d i s t ( s e t p o i n t , f a n , K, T i ) fandisp tempdisp s e t p o i n t d i s p m name temp h e a t i n f a n i n C0 u o l d new 5 6 7 Ts = s a m p l i n g t i m e ; e new = s e t p o i n t − temp ; 8 9 10 11 S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d + S0 * e new + S1 * e o l d ; 12 13 14 15 u o l d = u new ; e o l d = e new ; 16 17 18 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 19 20 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 21 22 23 m=m+1; endfunction 252 11.10.1.2 Set Point Change in PI Controller Scilab Code 11.3 pi bda.sci 1 2 3 mode ( 0 ) f u n c t i o n temp = global heatdisp sampling time u new e o l d e p i b d a ( s e t p o i n t , f a n , K, T i ) fandisp tempdisp s e t p o i n t d i s p m name temp h e a t i n f a n i n C0 u o l d new 4 5 6 Ts = s a m p l i n g t i m e ; e new = s e t p o i n t − temp ; 7 8 9 10 S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 11 12 13 14 u o l d = u new ; e o l d = e new ; 15 16 17 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 18 19 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 20 21 22 m=m+1; endfunction 11.10.1.3 Fan Disturbance to PID Controller Scilab Code 11.4 pid bda dist.sci 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = p i d b d a d i s t ( s e t p o i n t , f a n , K, Ti , Td ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 253 4 5 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 6 7 e new = s e t p o i n t − temp ; 8 9 Ts= s a m p l i n g t i m e ; 10 11 12 13 S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 14 15 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 16 17 18 19 u o l d = u new ; e old old = e old ; e o l d = e new ; 20 21 22 23 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 24 25 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 26 27 28 m=m+1; endfunction 11.10.1.4 Set Point Change in PID Controller Scilab Code 11.5 pid bda.sci 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = p i d b d a ( s e t p o i n t , f a n , K, Ti , Td ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 4 254 5 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 6 7 e new = s e t p o i n t − temp ; 8 9 Ts= s a m p l i n g t i m e ; 10 11 12 13 S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 14 15 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 16 17 18 19 u o l d = u new ; e old old = e old ; e o l d = e new ; 20 21 22 23 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 24 25 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 26 27 28 m=m+1; endfunction 11.10.2 Self Tuning Controller, local 11.10.2.1 Fan Discturbance to PI Controller Scilab Code 11.6 pi bda tuned dist.sci 1 2 mode ( 0 ) / / g l o b a l f a n d i s p 3 4 temp heat tempdisp fan x s a m p l i n g t i m e m h e a t d i s p name f u n c t i o n temp = p i b d a t u n e d d i s t ( s e t p o i n t , f a n ) global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p 255 s a m p l i n g t i m e m name temp h e a t i n f a n i n C0 u o l d u new e o l d e new 5 6 Ts = s a m p l i n g t i m e ; 7 / / L = 6; 8 / / R = ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) / ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; / / K = 9 10 / / Ti 0 . 9 / ( R*L ) ; = 3* L ; 11 12 / / the above is the z i e g l e r n i c h o l s p a r t 13 14 15 16 K = 2 / ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) ; T i = ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; 17 18 / / the above is the d i r e c t s y n t h e s i s p a r t 19 20 21 22 23 e new = s e t p o i n t − temp ; S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 24 25 26 27 u o l d = u new ; e o l d = e new ; 28 29 h e a t = u new ; 30 31 temp = comm ( h e a t , f a n ) ; 32 33 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 34 35 36 m=m+1; endfunction 256 11.10.2.2 Set Point Change to PI Controller Scilab Code 11.7 pi bda tuned.sci 1 2 3 mode ( 0 ) f u n c t i o n temp = global heatdisp sampling time u new e o l d e pi bda tuned ( setpoint , fan ) fandisp tempdisp s e t p o i n t d i s p m name temp h e a t i n f a n i n C0 u o l d new 4 5 Ts = s a m p l i n g t i m e ; 6 7 / / L = 6; 8 / / R = ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) / ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; 9 / / K = 0 . 9 / ( R*L ) ; 10 / / Ti = 3* L ; 11 12 13 / / The above is the Z i e g l e r n i c h o l s p a r t . 14 15 16 17 K = 2 / ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) ; T i = ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; / / The above is the d i r e c t s y n t h e s i s p a r t 18 19 e new = s e t p o i n t − temp ; 20 21 22 23 S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 24 25 26 u o l d = u new ; e o l d = e new ; 27 28 29 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 30 31 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 257 32 33 34 m=m+1; endfunction 11.10.2.3 Fan Disturbance to PID Controller Scilab Code 11.8 pid bda tuned dist.sci 1 mode ( 0 ) 2 3 4 f u n c t i o n [ temp ] = p i d b d a t u n e d d i s t ( s e t p o i n t , f a n ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 5 6 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 7 8 9 10 11 12 L = 6; R = ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) / ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; K = 1 . 2 / ( R* L ) T i = 2*L ; Td = 0 . 5 * L ; 13 14 15 e new = s e t p o i n t − temp ; 16 17 Ts= s a m p l i n g t i m e ; 18 19 20 21 S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 22 23 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 24 25 26 27 u o l d = u new ; e old old = e old ; e o l d = e new ; 28 258 29 30 31 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 32 33 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 34 35 36 m=m+1; endfunction 11.10.2.4 Set Point Change to PID Controller Scilab Code 11.9 pid bda tuned.sci 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = p i d b d a t u n e d ( s e t p o i n t , f a n ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 4 5 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name 6 7 8 9 10 11 L = 6; R = ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) / ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; K = 1 . 2 / ( R* L ) T i = 2*L ; Td = 0 . 5 * L ; 12 13 14 e new = s e t p o i n t − temp ; 15 16 Ts= s a m p l i n g t i m e ; 17 18 19 20 S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 21 22 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 259 23 24 25 26 u o l d = u new ; e old old = e old ; e o l d = e new ; 27 28 29 30 h e a t = u new ; temp = comm ( h e a t , f a n ) ; 31 32 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 33 34 35 m=m+1; endfunction 11.10.3 Conventional Controller, virtual 11.10.4 Fan Disturbance in PI Controller Scilab Code 11.10 pi bda dist.sci 1 f u n c t i o n [ s t o p ] = p i b d a d i s t ( s e t p o i n t , f a n , K, T i ) 2 3 4 g l o b a l u o l d u new e o l d e new S0 S1 temp e new = s e t p o i n t − temp ; 5 6 7 8 9 Ts= s a m p l i n g t i m e ; S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d + S0 * e new + S1 * e o l d ; 10 11 h e a t =u new ; 12 13 14 u o l d = u new ; e o l d = e new ; 15 16 [ s t o p , temp ] = comm ( h e a t , f a n ) ; l i n e 260 / / Never e d i t t h i s 17 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 18 19 endfunction 11.10.4.1 Set Point Change in PI Controller Scilab Code 11.11 pi bda.sci 1 f u n c t i o n [ s t o p ] = p i b d a ( s e t p o i n t , f a n , K, T i ) 2 3 4 5 g l o b a l u o l d u new e o l d e new S0 S1 temp 6 7 e new = s e t p o i n t − temp ; 8 9 10 11 Ts= s a m p l i n g t i m e ; 12 13 14 15 S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 16 17 18 h e a t =u new ; 19 20 21 22 u o l d = u new ; 23 24 e o l d = e new ; 25 26 27 28 [ s t o p , temp ] = comm ( h e a t , f a n ) ; l i n e 261 / / Never e d i t t h i s 29 30 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 31 32 33 34 endfunction 11.10.4.2 Fan Disturbance to PID Controller Scilab Code 11.12 pid bda dist.sci 1 2 f u n c t i o n [ s t o p ] = p i d b d a d i s t ( s e t p o i n t , f a n , K, Ti , Td ) g l o b a l u o l d u new e o l d e o l d o l d e new S0 S1 temp 3 4 5 e new = s e t p o i n t − temp ; Ts= s a m p l i n g t i m e ; 6 7 8 9 S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 10 11 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 12 13 14 15 16 17 h e a t =u new ; u o l d = u new ; e old old = e old ; e o l d = e new ; 18 19 20 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 21 22 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 262 23 24 25 endfunction 11.10.4.3 Set Point Change in PID Controller Scilab Code 11.13 pid bda.sci 1 2 f u n c t i o n [ s t o p ] = p i d b d a ( s e t p o i n t , f a n , K, Ti , Td ) g l o b a l u o l d u new e o l d e o l d o l d e new S0 S1 temp 3 4 5 e new = s e t p o i n t − temp ; Ts= s a m p l i n g t i m e ; 6 7 8 9 S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 10 11 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 12 13 14 15 16 17 h e a t =u new ; u o l d = u new ; e old old = e old ; e o l d = e new ; 18 19 20 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 21 22 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 23 24 25 endfunction 263 11.10.5 Self Tuning Controller, local 11.10.5.1 Fan Discturbance to PI Controller Scilab Code 11.14 pi bda tuned dist.sci 1 function [ stop ] = p i b d a t u n e d d i s t ( setpoint , fan ) 2 3 g l o b a l u o l d u new e o l d e new S0 S1 temp 4 5 6 K = 2 / ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) ; T i = ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; 7 8 e new = s e t p o i n t − temp ; 9 10 11 12 13 Ts= s a m p l i n g t i m e ; S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 14 15 h e a t =u new ; 16 17 18 u o l d = u new ; e o l d = e new ; 19 20 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 21 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 22 23 endfunction 11.10.5.2 Set Point Change to PI Controller Scilab Code 11.15 pi bda tuned.sci 1 function [ stop ] = pi bda tuned ( setpoint , fan ) 2 264 3 g l o b a l u o l d u new e o l d e new S0 S1 temp 4 5 6 K = 2 / ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) ; T i = ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; 7 8 e new = s e t p o i n t − temp ; 9 10 11 12 13 Ts= s a m p l i n g t i m e ; S0=K * ( 1 + ( ( Ts / T i ) ) ) ; S1=−K; u new = u o l d +( S0 * e new ) +( S1 * e o l d ) ; 14 15 h e a t =u new ; 16 17 18 u o l d = u new ; e o l d = e new ; 19 20 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 21 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 22 23 endfunction 11.10.5.3 Fan Disturbance to PID Controller Scilab Code 11.16 pid bda tuned dist.sci 1 function [ stop ] = p i d b d a t u n e d d i s t ( setpoint , fan ) 2 3 g l o b a l u o l d u new e o l d e o l d o l d e new S0 S1 temp 4 5 6 7 8 9 L = 6; R = ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) / ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; K = 1 . 2 / ( R* L ) T i = 2*L ; Td = 0 . 5 * L ; 265 10 e new = s e t p o i n t − temp ; 11 12 Ts= s a m p l i n g t i m e ; S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 13 14 15 16 17 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 18 19 h e a t =u new ; 20 21 u o l d = u new ; e old old = e old ; e o l d = e new ; 22 23 24 25 [ s t o p , temp ] = comm ( h e a t , f a n ) ; 26 / / Never e d i t t h i s l i n e p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 27 28 29 endfunction 11.10.5.4 Set Point Change to PID Controller Scilab Code 11.17 pid bda tuned.sci 1 function [ stop ] = pid bda tuned ( setpoint , fan ) 2 g l o b a l u o l d u new e o l d e o l d o l d e new S0 S1 temp 3 4 L = 6; R = ( 0 . 0 1 6 * temp − 0 . 1 1 4 ) / ( 6 6 . 9 0 − 0 . 4 1 5 * temp ) ; K = 1 . 2 / ( R* L ) T i = 2*L ; 5 6 7 8 9 / / Kc and t a u i c a l c u l a t e d 266 10 Td = 0 . 5 * L ; 11 12 e new = s e t p o i n t − temp ; 13 14 15 16 17 Ts= s a m p l i n g t i m e ; S0=K * ( 1 + ( Ts / T i ) +( Td / Ts ) ) ; S1=K * ( −1 −((2 * Td ) / Ts ) ) ; S2=K * ( Td / Ts ) ; 18 19 u new = u o l d + S0 * e new + S1 * e o l d + S2 * e o l d o l d ; 20 21 22 h e a t =u new ; 23 24 25 26 u o l d = u new ; e old old = e old ; e o l d = e new ; 27 28 [ s t o p , temp ] = comm ( h e a t , f a n ) ; / / Never e d i t t h i s l i n e 29 p l o t t i n g ( [ h e a t f a n temp s e t p o i n t ] , [ 0 0 30 0 ] , [ 1 0 0 100 50 1 0 0 0 ] ) 30 31 endfunction 267 Chapter 12 Model Predictive Control in Single Board Heater System using SCILAB This chapter presents Model Predictive Control in Single Board Heater System done by Mr. Pratik Behera.1 12.1 MPC theory An equivalent quadratic programming (QP) formulation for constrained DMC (as given in LQG MPC notes by Prof Sachin Patwardhan) is given as follows 1 minU f U f (k)T HU f (k) + F T U f (k) 2 (12.1) AU f (k) ≤ b (12.2) Subject to where (12.3) 1 Copyright: Mr.Pratik Behera 268 " Iqm −Iqm # " UH −U L # A= b= Also, we have outputs and manipulated variables related to state variables by x(k + 1) = Φx(k) + Γ(k) + w(k) y(k) = Cx(k) + v(k) (12.4) (12.5) (12.6) φ is represented by matrix A in the code, Γ is represented as matrix B and C is represented as C matrix in the code. 12.2 Implementing MPC There are three main codes, which are being used for this experiment. mpc init.sce is the code which opens the xcos window, wherein, we have step block for the setpoint for temperature and the fan speed. Once the values have been entered into the xcos window and the simulation is started, the scifunc block of xcos calls the function mpc.sci after every sampling time. The mpc.sci in turn calls mpc run.sci every time it is called by scifunc block. The mpc run.sci code optimizes manipulated variable (heater) over control horizon and returns only the first manipulated variable (heater) value. This new heater value is then sent to the heater of the SBHS to control the temperature at the set point. When mpc init.sce is executed in scilab, an xcos window opens up. The xcos window has two step input blocks. The first step input block on the left side, is for the Temperature set point and the second step input block is for the fan (disturbance variable). Also the sampling time can be entered via clock block present on the xcos. For all the experiments done for this project, sampling time of 1 second was used (entered via clock block of xcos). Refer to the figure below for a clear picture of the xcos. 269 Figure 12.1: Screenshot of the xcos window with step input blocks labeled After entering the values in the input step block, the simulation can be started. This opens up a graph, which shows the values of Temperature-set-point, fan and the actual temperature at each time instant during the simulation. Other codes that were used other than mpc run.sci for conducting this experiment are mpc init.sce and mpc.sci. Both these codes were originally taken from Moodle (Process controls course for SBHS assignment). Please note that, both these codes were slightly modified to work with our MPC. The only changes done in the original codes are: • addition of global variables p,q and xk old (p is the prediction horizon, q is the control horizon, xk old represents the last value of an internal state) • initialization of p, q and xk old • removal of some unnecessary lines (ie, lines not relevant to MPC implementation) 270 12.3 Experiments conducted to implement MPC Experiments were performed as shown in table above for implementation of MPC. We carried out experiments in which both positive and negative step changes were given to Set point and Fan (disturbance variable) and the output response was obtained by application of MPC. We also have performed several experiments to study the effect of change in the values of q (control horizon) and tuning parameters - error and manipulated variable weighting factors. The details of the experiments mentioned in this report has been tabulated in the table given in the next page. The first column of the table represents the experiment version (or number). For all the outputs and their figures, we have mentioned only their experiment version (or number) to tag them. Also note that the data files for these experiments are also named as per their experiment version number. p and q mentioned in the table represents the prediction and control horizon respectively. Please note: For all the above experiments and graphs, we adhered to: • Scilab Version: 5.2.2 • SBHS number: 12 (remotely accessed) • Sampling time: 1 second For graphs: Until and unless mentioned, Graphic 1 represents the Temperature set point, Graphic 2 represents the Fan and Graphic 3 represents the Temperature. Also, please note that there are two types of graphs. The first graph, containing Graphic 1, Graphic 2 and Graphic 3 were directly obtained via mscope of xcos. The graph following this in all the experiments is the temperature and heater value graphs, which were obtained from the data (from the text file downloaded from the server after each experiment). 271 Figure 12.2: Experiments performed All the experiments mentioned in this report has been labeled as shown in this table. This table is just a summary of all the parameters that was used for the corresponding experiment. Details on the inputs and a description of the output observed for each case has been mentioned in the corresponding section of each experiment. 12.4 Sample run to implement MPC 12.4.1 Positive Step Change to Set Point and Fan Let us consider an experiment, wherein, a positive step change of 5◦ C (from 35◦ C to 40◦ C) was provided to set point at time t=250 s and a step change to fan was provided at t = 500 s, from 100 to 150. 272 Figure 12.3: Xcos output for positive Step Change to Set Point and Fan 273 Figure 12.4: Temperature and Heater plot As can, be seen above, when, the temperature set point is raised to 40 from 30, at t=250 s, the value of the heater increases, so that it can heat up the plant upto the required set point. Similarly, when the fan speed is increased at t=500s, the heater value increases yet again to maintain the same constant temperature of the SBHS blade. 274 12.4.2 Negative Step Change to Set Point and Fan Let us consider experiment 2.1, wherein, a negative step change of 5◦ C (from 42◦ C to 37◦ C) was provided to set point at time t=250 s and a step change to fan was provided at t = 500 s, from 150 to 100. Figure 12.5: Xcos output for negative Step Change to Set Point and Fan 275 Figure 12.6: Temperature and Heater plot As can be seen from the graphs above, when the temperature set point drops at t=250 s, the value of the heater too falls, so that the plant (SBHS blade) can cool down to the required set point. Similarly, when the fan speed was decreased at t=500s, the heater value decreased yet again to maintain the same constant temperature of the SBHS blade. 276 12.5 Effect of Tuning parameters: Weighting factors, We and Wu We also, conducted several experiments in order the study the effect of the value of Weighting factors (both error,We and manipulated variable,Wu). We used weighting factors to be 1, 10 and 40 for both positive and negative step changes to both set point and fan (as has been summarized in Table 1). Also, experiments were done for different values of We and Wu. The results have been shown in the following graph. 277 12.5.1 Positive Step Change and (We, Wu)=(1,1) Figure 12.7: Xcos output for positive Step Change and (We, Wu)=(1,1) Here we can clearly see the expected output. Providing a positive step to temperature set point at 250 seconds, increased heater value as per the control effort put in by MPC. A positive step in fan at 500 seconds, decreased the temperature below its set point and hence heater value increased to take the temperature close to its setpoint. 278 Figure 12.8: Temperature and Heater plot As can be clearly seen, the heater graph follows the expected trend that we talked of in the last page. Also, note that the temperature variation can be clearly seen from this graph. This graph shows the result for the case, where we had same weighting factors for both error and manipulated variables (We and Wu). We will now see if changing both of these is going to have any effect on the control behavior. So, we now try an experiment with both We and Wu increased to 10. 279 12.5.2 Positive Step Change and (We, Wu)=(10,10) Figure 12.9: Xcos output for positive Step Change and (We, Wu)=(10,10) Using the same logic as has been explained in the last section, we expected to see similar temperature and heater value profiles for the positive step change in temperature set point and the fan. (Heater graph is shown in the next page along with the temperature on an expanded scale). In this experiment, we increased We and Wu both to 10 from 1 and wish to observe if this changes the response of the plant. 280 Figure 12.10: Temperature and heater plot The results here are almost the same as that mentioned in the last section (where We and Wu both were 1). So, we can for the time being keep in mind that We and Wu isn’t actually much affected the output. We now will carry out the experiment for even higher We and Wu (say 40) and see if it really does affect the output much. 281 12.5.3 Positive Step Change and (We, Wu)=(40,40) Figure 12.11: Xcos for positive Step Change and (We, Wu)=(40,40) 282 Figure 12.12: Temperature and heater plot Even the results with We and Wu as 40 doesn’t show much difference. They are more or less similar looking as the last two experiment’s results. 283 12.5.4 Negative Step Change and (We,Wu)=(1,1) Figure 12.13: Xcos for negative Step Change and (We, Wu)=(1,1) Here we expect somewhat similar results as was the case with positive step in temperature set point. 284 Figure 12.14: Temperature and heater plot We can very clearly make out that the results follow the trends as was explained for the negative step input in the section 5.2 285 12.5.5 Negative Step Change and (We, Wu)=(10,10) Figure 12.15: Xcos for negative Step Change and (We, Wu)=(10,10) 286 Figure 12.16: Temperature and heater plot 287 12.5.6 Negative Step Change and (We, Wu)=(40,40) Figure 12.17: Xcos for negative Step Change and (We, Wu)=(40,40) 288 Figure 12.18: Temperature and heater plot 12.6 For different We and Wu factors We very clearly see that using the same values of We and Wu is not making much difference in the control response. So, will now be trying different values for We and Wu. 289 12.6.1 We =100 and Wu = 2 Figure 12.19: Output for We =100 and Wu = 2 Here, we have used We as 100 and Wu as 2. The response after the positive step in temperature set point is slightly oscillatory. The temperature very well stabilzes at the required setpoint. The settling time observed is fairly low. 290 Figure 12.20: Temperature and heater plot Now having seen the results of this experiment, we would like to check the possible effect of reversing the values of We and Wu. So, we conduct the next experiment, in which we have We as 2 and Wu as 100. 291 12.6.2 We = 2 and Wu = 100 Figure 12.21: Output for We = 2 and Wu = 100 With increase in Wu, we observe that the temperature stabilzes at the required stepoint, but the settling time for reaching that setpoint increases. Also, the response is not oscillatory. This result can be very clearly seen in the following temperature and heater graph. 292 Figure 12.22: Temperature and heater plot 293 12.6.3 We =10 and Wu = 100 Having seen the effect of low We and high Wu (in the last section), we would like to see what happens if We is slightly increased keeping Wu the same. For this we increase the value of We to 10 and keep Wu at constant 100. Figure 12.23: Output for We =10 and Wu = 100 We observe that this experiments performs better than in the last section (where We was 2). It is slighly oscillatory and also, the settling time decreased much as compared to last experiment. 294 Figure 12.24: Temperature and heater plot 12.6.4 We =100 and Wu = 10 We now do a similar study for the case of Wu. We increase the value of Wu to 10, keeping We constant at 100. 295 Figure 12.25: Output for We =100 and Wu = 10 As is clear from the figure, we see slightly lesser oscillations compared to the case when We was 100 and Wu was 2. Settling time more or less remained the same. 296 Figure 12.26: Temperature and heater plot 297 12.6.5 Conclusion on Weighting factor experiments For experiments with same values of We and Wu: • Not much difference was seen in heater value trends and temperature value trends for all the experiments performed above. • Reason for this will be clear from the discussion on the trends mentioned below (for experiments with different values of We and Wu) For experiments with different values of We and Wu: • Keeping We as large (around 100) and Wu as small (2) shows better performance as compared to the case when the values are kept the other way around. • With We very small (say around 1-2), oscillations are less, and the settling time observed was found to be more. • With increase in We, the oscillations were observed to increase and the settling time was found to reduce and hence, better control was observed. • So, with increase in We, any error is quickly dealt with, because with increase in We, we are actually increasing the significance of change of temperature in deciding the control action. • With increase in Wu, oscillations reduced and the settling time was found to increase and hence, less preferred. So, the best performance is obtained for the cases with high We and low Wu. 12.7 Effect of Control Horizon Paramter, q We also tried to study the effect of change of control horizon (q) on the response of the SBHS to step change in Setpoint and disturbance variable. Generally the value of q (control parameter) is taken somewhere between 2 to 5. So, we performed our SBHS experiment for values of q as 2, 3 and 4 (as suggested by Mr Prashant Gupta). Both positive and negative step change experiments for temperature set point and 298 disturbance variable (fan) was performed for the sake of completeness. The results obtained thereby has been mentioned in form of graphs in this section. The overall conclusion over these experiments has been mentioned in the conclusion of this part. 12.7.1 For positive step change in Set point and Fan speed Figure 12.27: Xcos putput for positive step change with q=2 299 Figure 12.28: Temperature and heater plot 300 Figure 12.29: Xcos putput for positive step change with q = 3 301 Figure 12.30: Temperature and heater plot 302 Figure 12.31: Xcos putput for positive step change with q = 4 303 Figure 12.32: Temperature and heater plot 304 12.7.2 For negative step change in Set point and Fan speed Figure 12.33: Xcos putput for negative step change with q = 2 305 Figure 12.34: Temperature and heater plot 306 Figure 12.35: Xcos putput for negative step change with q = 3 307 Figure 12.36: Temperature and heater plot 308 Figure 12.37: Xcos putput for negative step change with q = 4 309 Figure 12.38: Temperature and heater plot 12.7.3 Conclusion on the effect of Control Horizon parameter • The effect of change in q isn’t very distinct in the experiments performed. • While we are calculating the optimized value of manipulated variable at a time, the number of manipulated input moves is increasing as we are increasing the q value. • But, only the first value of the optimized manipulated variable vector is used for control. 310 • Increase in q is only increasing the length of the manipulated variable vector which is to be optimized. • Since, only the first value of manipulated variable vector is used, which itself lies in some specified range, the effect of changing q isn’t very significant for SBHS. • Also, SBHS system is a simple system with very few variables (as compared to real life industrial systems). • Ideally, the value of q is to be maintained at 3 or 4. 12.8 Implementing MPC locally The detailed procedure to perform a local experiment is explained in Chapter2. A summary of the same is provided in section 2.3 It is same for this section with following changes. 1. Step1: The working directory is mpc 2. Step2: Same 3. Step3: Same 4. Step4: Same 5. Step5: Load mpc function by executing command exec mpc init local.sci 6. Step6: Load Xcos code for mpc experiment using the command xcos mpc.xcos 7. Step7: Same 12.9 Implementing MPC virtually The detailed procedure to perform a virtual experiment is explained in Chapter3. A summary of the same is provided in section 3.5. It is same for this section with following changes. 311 1. Step1: The working directory is mpc. Open this directory. 2. Step2: Same 3. Step3: Same 4. Step4: Switch to the MPC experiment directory and double-click on the file mpc.sce. This will launch scilab and also open the file mpc.sce in the scilab editor. Linux users will have to launch scilab manually. They also have to change the working directory to mpc and then open the mpc.sce file in the scilab editor. 5. Step5: Same 6. Step6: Execute the file mpc.sce. Expect the PI controller xcos diagram to open automatically. If this doesnt happen, check the scilab console for error message. 7. Step7: Execute the MPC controller xcos diagram. 8. Step8: Same 12.10 Conclusion for MPC project The objective of this project, ie, implementing Model Predictive Control in Single Board Heater System using Scilab was successfully achieved. Several experiments were successfully performed using the developed SCILAB MPC algorithm for both positive and negative step changes in both temperature-set-point and the disturbance variable (fan). In addition to the above objective, we also tried studying the effect of weighting factors (tuning parameter) and control horizon parameter. We observed and concluded that increase in values of We (error weighting factor), increases oscillations and decreases settling time, while decrease in We leads to opposite effect. Wu (manipulated variable weighting factor), on the other hand has an opposite effect. It decreases oscillations and increases settling time with increase in its value. Hence, better control is obtained for high value of We and low value of Wu. Thus, with this project, we were able to implement MPC successfully and also 312 were able to comment on the general preferred tuning parameters (weighting factors for error and manipulated variable). 12.11 Acknowledgement Firstly, I (Pratik Behera)would like to thank Prof Moudgalya Kannan, for giving me this opportunity to undertake MPC project on SBHS. This project, which involved implementing Model Predictive Control in SBHS using SCILAB, was very interesting and provided an excellent learning opportunity. For developing the MPC algorithm, lecture notes on Model Predictive Control by Prof. Sachin Patwardhan too were extremely helpful. Also, I got to learn a lot from the speaking tutorials of SCILAB and LaTeX, which had to be referred to for the completion of this project. Over and above this, it was very encouraging to see the experiments working perfectly with the developed Model Predictive Control algorithm. I would also like to sincerely thank Mr Prashant Gupta, without whom, this project would not have been splendidly completed. I would like to thank him for the time he spent explaining the concepts, clearing the doubts and suggestions for the experiments to implement MPC. 12.12 General Information on Experiments for this Project All the experiments for this project was performed remotely on SBHS, using a sampling time of 1 second. Basic codes (mpc init.sce and mpc.sci) was taken from moodle for this course. Code for implementing MPC was written in scilab and has been mentioned in the report. Scilab Version used: 5.2.2 SBHS number: 12 (remotely used) Sampling time: 1 second For graphs: Until and unless mentioned, Graphic 1 represents the Temperature set point, Graphic 2 represents the Fan and Graphic 3 represents the Temperature. Initially, open loop experiment was performed, and Plant Transfer function was obtained. For the open loop experiment, a step change in heater from 15 to 25 units at t =200 seconds was provided (sampling time 1s). The response data 313 was fitted to a first order transfer function with a time delay and the following was observed: Kp=0.37, time constant = 45s and delay = 7s. Using the above, we obtained the plant transfer function: Gp = 0.37 −7s e 1 + 45s (12.7) Scilab Method to calculate State Space matrices State space matrices for a transfer function can be calculated as follows using Scilab: 1 2 3 s=p o l y ( 0 , ’ s ’ ) ; T F c o n t= s y s l i n ( ’ c ’ , [ kp * ( 1 − 0 . 5 * D) / ( t a u * s +1) / ( 1 + 0 . 5 * D) ] ) ; S S c o n t= t f 2 s s ( T F c o n t ) ; SScont (in the last line above), has the value of the required State Space matrices. (Please note: Time delays can not be directly handled in Scilab. So, for systems with delays, we will have to use alternate approach. Pade’s approximation for time delay being one of the approach.) The transfer function which we dervied for our SBHS was very close to the transfer function derived in an earlier attempt. So, using the values of A, B and C which were already calculated by him previously, we obtain the following exact values: 0.9780 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 A = 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 314 B = C= 12.13 h 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0079 i Scilab Code Scilab Code 12.1 mpc.sci 1 2 f u n c t i o n [ s t o p ] = mpc ( Tsp , f a n ) g l o b a l f d f h f d t f n c r fncw m e r r c o u n t s t o p p q x k o l d h e a t temp h e a t o l d 3 h e a t = mpc run ( temp , h e a t o l d , Tsp ) ; 4 5 [ s t o p , temp ] = comm ( h e a t , f a n ) ; 6 / / Never e d i t t h i s l i n e p l o t t i n g ( [ h e a t f a n temp Tsp ] , [ 0 40 25 0 ] , [ 1 0 0 70 50 1 0 0 0 ] ) ; 7 8 heat old = heat ; 9 10 11 12 return endfunction Scilab Code 12.2 mpc init local.sce 1 / / 2 / / use For of s c i l a b s c i c o s 5 . 1 . 1 command or to lower open xcos 315 v e r s i o n s c i c o s users , diagrams i n s t e a d 3 4 g l o b a l e r r c o u n t y p q x k o l d Tsp h e a t s f a n temp h e a t 5 6 7 8 9 10 11 12 p = 40; / / p r e d i c t i o n h o r i z o n q = 4; / / c o n t r o l h o r i z o n xk old = zeros (8 ,1) ; Tsp =1; h e a t s =1; f a n =1; temp =1; 13 14 15 exec ( ” mpc local . s c i ” ) ; e x e c ( ” mpc run . s c i ” ) ; Scilab Code 12.3 mpc local.sci 1 2 3 mode ( 0 ) f u n c t i o n [ temp ] = mpc ( Tsp , f a n ) g l o b a l temp h e a t i n f a n i n C0 u o l d u new e o l d e new e old old 4 5 6 7 global h e a t d i s p fandisp tempdisp s e t p o i n t d i s p s a m p l i n g t i m e m name / / h e a t s = 1; u new = mpc run ( temp , h e a t s , Tsp ) ; 8 9 10 h e a t = u new ; 11 12 temp = comm ( h e a t , f a n ) ; 13 14 p l o t t i n g ( [ h e a t f a n temp Tsp ] , [ 0 0 20 0 ] , [ 1 0 0 100 40 1 0 0 0 ] ) 15 16 17 m=m+1; endfunction 316 Bibliography [1] Fossee moodle. http://www.fossee.in/moodle/. Seen on 10 May 2011. [2] Spoken tutorials. http://spoken-tutorial.org/Study Plans Scilab. Seen on 10 May 2011. [3] K. M. Moudgalya. Introducing National Mission on Education through ICT. http://www.spoken-tutorial.org/NMEICT-Intro, 2010. [4] K. M. Moudgalya and Inderpreet Arora. A Virtual Laboratory for Distance Education. In Proceedings of 2nd Int. conf. on Technology for Education, T4E, IIT Bombay, India, 1–3 July 2010. IEEE. [5] Kannan M. Moudgalya. Digital Control. John Wiley and Sons, 2009. [6] Kannan M. Moudgalya. Identification of transfer function of a single board heater system through step response experiments. 2009. [7] Katsuhiko Ogata. Modern Control Engineering. Prentice-Hall of India, 2005. [8] Dale E. Seborg, Thomas F. Edgar, and Duncan A. Mellichamp. Process Dynamics and Control. John Wiley and Sons, 2nd edition, 2004. [9] Virtual labs project. Single board heater system. learn.in/web sbhs. Seen on 11 May 2011. 317 http://www.co-
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.4 Linearized : No Page Count : 318 Producer : pdfTeX-1.40.10 Creator : TeX Create Date : 2015:10:24 16:20:38+05:30 Modify Date : 2015:10:24 16:20:38+05:30 Trapped : False PTEX Fullbanner : This is pdfTeX, Version 3.1415926-1.40.10-2.2 (TeX Live 2009/Debian) kpathsea version 5.0.0EXIF Metadata provided by EXIF.tools