| 1 | within Modelica.Blocks; |
|---|
| 2 | package Continuous "Library of continuous control blocks with internal states" |
|---|
| 3 | |
|---|
| 4 | import Modelica.Blocks.Interfaces; |
|---|
| 5 | import Modelica.SIunits; |
|---|
| 6 | extends Modelica.Icons.Library; |
|---|
| 7 | |
|---|
| 8 | annotation ( |
|---|
| 9 | Documentation(info="<html> |
|---|
| 10 | <p> |
|---|
| 11 | This package contains basic <b>continuous</b> input/output blocks |
|---|
| 12 | described by differential equations. |
|---|
| 13 | </p> |
|---|
| 14 | |
|---|
| 15 | <p> |
|---|
| 16 | All blocks of this package can be initialized in different |
|---|
| 17 | ways controlled by parameter <b>initType</b>. The possible |
|---|
| 18 | values of initType are defined in |
|---|
| 19 | <a href=\"Modelica://Modelica.Blocks.Types.Init\">Modelica.Blocks.Types.Init</a>: |
|---|
| 20 | </p> |
|---|
| 21 | |
|---|
| 22 | <table border=1 cellspacing=0 cellpadding=2> |
|---|
| 23 | <tr><td valign=\"top\"><b>Name</b></td> |
|---|
| 24 | <td valign=\"top\"><b>Description</b></td></tr> |
|---|
| 25 | |
|---|
| 26 | <tr><td valign=\"top\"><b>Init.NoInit</b></td> |
|---|
| 27 | <td valign=\"top\">no initialization (start values are used as guess values with fixed=false)</td></tr> |
|---|
| 28 | |
|---|
| 29 | <tr><td valign=\"top\"><b>Init.SteadyState</b></td> |
|---|
| 30 | <td valign=\"top\">steady state initialization (derivatives of states are zero)</td></tr> |
|---|
| 31 | |
|---|
| 32 | <tr><td valign=\"top\"><b>Init.InitialState</b></td> |
|---|
| 33 | <td valign=\"top\">Initialization with initial states</td></tr> |
|---|
| 34 | |
|---|
| 35 | <tr><td valign=\"top\"><b>Init.InitialOutput</b></td> |
|---|
| 36 | <td valign=\"top\">Initialization with initial outputs (and steady state of the states if possibles)</td></tr> |
|---|
| 37 | </table> |
|---|
| 38 | |
|---|
| 39 | <p> |
|---|
| 40 | For backward compatibility reasons the default of all blocks is |
|---|
| 41 | <b>Init.NoInit</b>, with the exception of Integrator and LimIntegrator |
|---|
| 42 | where the default is <b>Init.InitialState</b> (this was the initialization |
|---|
| 43 | defined in version 2.2 of the Modelica standard library). |
|---|
| 44 | </p> |
|---|
| 45 | |
|---|
| 46 | <p> |
|---|
| 47 | In many cases, the most useful initial condition is |
|---|
| 48 | <b>Init.SteadyState</b> because initial transients are then no longer |
|---|
| 49 | present. The drawback is that in combination with a non-linear |
|---|
| 50 | plant, non-linear algebraic equations occur that might be |
|---|
| 51 | difficult to solve if appropriate guess values for the |
|---|
| 52 | iteration variables are not provided (i.e. start values with fixed=false). |
|---|
| 53 | However, it is often already useful to just initialize |
|---|
| 54 | the linear blocks from the Continuous blocks library in SteadyState. |
|---|
| 55 | This is uncritical, because only linear algebraic equations occur. |
|---|
| 56 | If Init.NoInit is set, then the start values for the states are |
|---|
| 57 | interpreted as <b>guess</b> values and are propagated to the |
|---|
| 58 | states with fixed=<b>false</b>. |
|---|
| 59 | </p> |
|---|
| 60 | |
|---|
| 61 | <p> |
|---|
| 62 | Note, initialization with Init.SteadyState is usually difficult |
|---|
| 63 | for a block that contains an integrator |
|---|
| 64 | (Integrator, LimIntegrator, PI, PID, LimPID). |
|---|
| 65 | This is due to the basic equation of an integrator: |
|---|
| 66 | </p> |
|---|
| 67 | |
|---|
| 68 | <pre> |
|---|
| 69 | <b>initial equation</b> |
|---|
| 70 | <b>der</b>(y) = 0; // Init.SteadyState |
|---|
| 71 | <b>equation</b> |
|---|
| 72 | <b>der</b>(y) = k*u; |
|---|
| 73 | </pre> |
|---|
| 74 | |
|---|
| 75 | <p> |
|---|
| 76 | The steady state equation leads to the condition that the input to the |
|---|
| 77 | integrator is zero. If the input u is already (directly or indirectly) defined |
|---|
| 78 | by another initial condition, then the initialization problem is <b>singular</b> |
|---|
| 79 | (has none or infinitely many solutions). This situation occurs often |
|---|
| 80 | for mechanical systems, where, e.g., u = desiredSpeed - measuredSpeed and |
|---|
| 81 | since speed is both a state and a derivative, it is always defined by |
|---|
| 82 | Init.InitialState or Init.SteadyState initializtion. |
|---|
| 83 | </p> |
|---|
| 84 | |
|---|
| 85 | <p> |
|---|
| 86 | In such a case, <b>Init.NoInit</b> has to be selected for the integrator |
|---|
| 87 | and an additional initial equation has to be added to the system |
|---|
| 88 | to which the integrator is connected. E.g., useful initial conditions |
|---|
| 89 | for a 1-dim. rotational inertia controlled by a PI controller are that |
|---|
| 90 | <b>angle</b>, <b>speed</b>, and <b>acceleration</b> of the inertia are zero. |
|---|
| 91 | </p> |
|---|
| 92 | |
|---|
| 93 | </html> |
|---|
| 94 | ")); |
|---|
| 95 | |
|---|
| 96 | block Integrator "Output the integral of the input signal" |
|---|
| 97 | import Modelica.Blocks.Types.Init; |
|---|
| 98 | parameter Real k=1 "Integrator gain"; |
|---|
| 99 | |
|---|
| 100 | /* InitialState is the default, because it was the default in Modelica 2.2 |
|---|
| 101 | and therefore this setting is backward compatible |
|---|
| 102 | */ |
|---|
| 103 | parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.InitialState |
|---|
| 104 | "Type of initialization (1: no init, 2: steady state, 3,4: initial output)" |
|---|
| 105 | annotation(Evaluate=true, |
|---|
| 106 | Dialog(group="Initialization")); |
|---|
| 107 | parameter Real y_start=0 "Initial or guess value of output (= state)" |
|---|
| 108 | annotation (Dialog(group="Initialization")); |
|---|
| 109 | extends Interfaces.SISO(y(start=y_start)); |
|---|
| 110 | |
|---|
| 111 | annotation ( |
|---|
| 112 | Documentation(info="<html> |
|---|
| 113 | <p> |
|---|
| 114 | This blocks computes output <b>y</b> (element-wise) as |
|---|
| 115 | <i>integral</i> of the input <b>u</b> multiplied with |
|---|
| 116 | the gain <i>k</i>: |
|---|
| 117 | </p> |
|---|
| 118 | <pre> |
|---|
| 119 | k |
|---|
| 120 | y = - u |
|---|
| 121 | s |
|---|
| 122 | </pre> |
|---|
| 123 | |
|---|
| 124 | <p> |
|---|
| 125 | It might be difficult to initialize the integrator in steady state. |
|---|
| 126 | This is discussed in the description of package |
|---|
| 127 | <a href=\"Modelica://Modelica.Blocks.Continuous#info\">Continuous</a>. |
|---|
| 128 | </p> |
|---|
| 129 | |
|---|
| 130 | </html> |
|---|
| 131 | "), Icon(coordinateSystem( |
|---|
| 132 | preserveAspectRatio=true, |
|---|
| 133 | extent={{-100,-100},{100,100}}, |
|---|
| 134 | grid={2,2}), graphics={ |
|---|
| 135 | Line(points={{-80,78},{-80,-90}}, color={192,192,192}), |
|---|
| 136 | Polygon( |
|---|
| 137 | points={{-80,90},{-88,68},{-72,68},{-80,90}}, |
|---|
| 138 | lineColor={192,192,192}, |
|---|
| 139 | fillColor={192,192,192}, |
|---|
| 140 | fillPattern=FillPattern.Solid), |
|---|
| 141 | Line(points={{-90,-80},{82,-80}}, color={192,192,192}), |
|---|
| 142 | Polygon( |
|---|
| 143 | points={{90,-80},{68,-72},{68,-88},{90,-80}}, |
|---|
| 144 | lineColor={192,192,192}, |
|---|
| 145 | fillColor={192,192,192}, |
|---|
| 146 | fillPattern=FillPattern.Solid), |
|---|
| 147 | Text( |
|---|
| 148 | extent={{0,-10},{60,-70}}, |
|---|
| 149 | lineColor={192,192,192}, |
|---|
| 150 | textString="I"), |
|---|
| 151 | Text( |
|---|
| 152 | extent={{-150,-150},{150,-110}}, |
|---|
| 153 | lineColor={0,0,0}, |
|---|
| 154 | textString="k=%k"), |
|---|
| 155 | Line(points={{-80,-80},{80,80}}, color={0,0,127})}), |
|---|
| 156 | Diagram(coordinateSystem( |
|---|
| 157 | preserveAspectRatio=true, |
|---|
| 158 | extent={{-100,-100},{100,100}}, |
|---|
| 159 | grid={2,2}), graphics={ |
|---|
| 160 | Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}), |
|---|
| 161 | Line(points={{-100,0},{-60,0}}, color={0,0,255}), |
|---|
| 162 | Line(points={{60,0},{100,0}}, color={0,0,255}), |
|---|
| 163 | Text( |
|---|
| 164 | extent={{-36,60},{32,2}}, |
|---|
| 165 | lineColor={0,0,0}, |
|---|
| 166 | textString="k"), |
|---|
| 167 | Text( |
|---|
| 168 | extent={{-32,0},{36,-58}}, |
|---|
| 169 | lineColor={0,0,0}, |
|---|
| 170 | textString="s"), |
|---|
| 171 | Line(points={{-46,0},{46,0}}, color={0,0,0})})); |
|---|
| 172 | |
|---|
| 173 | initial equation |
|---|
| 174 | if initType == Init.SteadyState then |
|---|
| 175 | der(y) = 0; |
|---|
| 176 | elseif initType == Init.InitialState or |
|---|
| 177 | initType == Init.InitialOutput then |
|---|
| 178 | y = y_start; |
|---|
| 179 | end if; |
|---|
| 180 | equation |
|---|
| 181 | der(y) = k*u; |
|---|
| 182 | end Integrator; |
|---|
| 183 | |
|---|
| 184 | block LimIntegrator "Integrator with limited value of the output" |
|---|
| 185 | import Modelica.Blocks.Types.Init; |
|---|
| 186 | parameter Real k=1 "Integrator gain"; |
|---|
| 187 | parameter Real outMax(start=1) "Upper limit of output"; |
|---|
| 188 | parameter Real outMin=-outMax "Lower limit of output"; |
|---|
| 189 | parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.InitialState |
|---|
| 190 | "Type of initialization (1: no init, 2: steady state, 3/4: initial output)" |
|---|
| 191 | annotation(Evaluate=true, Dialog(group="Initialization")); |
|---|
| 192 | parameter Boolean limitsAtInit = true |
|---|
| 193 | "= false, if limits are ignored during initializiation (i.e., der(y)=k*u)" |
|---|
| 194 | annotation(Evaluate=true, Dialog(group="Initialization")); |
|---|
| 195 | parameter Real y_start=0 |
|---|
| 196 | "Initial or guess value of output (must be in the limits outMin .. outMax)" |
|---|
| 197 | annotation (Dialog(group="Initialization")); |
|---|
| 198 | extends Interfaces.SISO(y(start=y_start)); |
|---|
| 199 | annotation ( |
|---|
| 200 | Documentation(info="<html> |
|---|
| 201 | <p> |
|---|
| 202 | This blocks computes <b>y</b> (element-wise) as <i>integral</i> |
|---|
| 203 | of the input <b>u</b> multiplied with the gain <i>k</i>. If the |
|---|
| 204 | integral reaches a given upper or lower <i>limit</i> and the |
|---|
| 205 | input will drive the integral outside of this bound, the |
|---|
| 206 | integration is halted and only restarted if the input drives |
|---|
| 207 | the integral away from the bounds. |
|---|
| 208 | </p> |
|---|
| 209 | |
|---|
| 210 | <p> |
|---|
| 211 | It might be difficult to initialize the integrator in steady state. |
|---|
| 212 | This is discussed in the description of package |
|---|
| 213 | <a href=\"Modelica://Modelica.Blocks.Continuous#info\">Continuous</a>. |
|---|
| 214 | </p> |
|---|
| 215 | |
|---|
| 216 | <p> |
|---|
| 217 | If parameter <b>limitAtInit</b> = <b>false</b>, the limits of the |
|---|
| 218 | integrator are removed from the initialization problem which |
|---|
| 219 | leads to a much simpler equation system. After initialization has been |
|---|
| 220 | performed, it is checked via an assert whether the output is in the |
|---|
| 221 | defined limits. For backward compatibility reasons |
|---|
| 222 | <b>limitAtInit</b> = <b>true</b>. In most cases it is best |
|---|
| 223 | to use <b>limitAtInit</b> = <b>false</b>. |
|---|
| 224 | </p> |
|---|
| 225 | </html> |
|---|
| 226 | "), Icon(coordinateSystem( |
|---|
| 227 | preserveAspectRatio=true, |
|---|
| 228 | extent={{-100,-100},{100,100}}, |
|---|
| 229 | grid={2,2}), graphics={ |
|---|
| 230 | Line(points={{-80,78},{-80,-90}}, color={192,192,192}), |
|---|
| 231 | Polygon( |
|---|
| 232 | points={{-80,90},{-88,68},{-72,68},{-80,90}}, |
|---|
| 233 | lineColor={192,192,192}, |
|---|
| 234 | fillColor={192,192,192}, |
|---|
| 235 | fillPattern=FillPattern.Solid), |
|---|
| 236 | Line(points={{-90,-80},{82,-80}}, color={192,192,192}), |
|---|
| 237 | Polygon( |
|---|
| 238 | points={{90,-80},{68,-72},{68,-88},{90,-80}}, |
|---|
| 239 | lineColor={192,192,192}, |
|---|
| 240 | fillColor={192,192,192}, |
|---|
| 241 | fillPattern=FillPattern.Solid), |
|---|
| 242 | Line(points={{-80,-80},{20,20},{80,20}}, color={0,0,127}), |
|---|
| 243 | Text( |
|---|
| 244 | extent={{0,-10},{60,-70}}, |
|---|
| 245 | lineColor={192,192,192}, |
|---|
| 246 | textString="I"), |
|---|
| 247 | Text( |
|---|
| 248 | extent={{-150,-150},{150,-110}}, |
|---|
| 249 | lineColor={0,0,0}, |
|---|
| 250 | textString="k=%k")}), |
|---|
| 251 | Diagram(coordinateSystem( |
|---|
| 252 | preserveAspectRatio=true, |
|---|
| 253 | extent={{-100,-100},{100,100}}, |
|---|
| 254 | grid={2,2}), graphics={ |
|---|
| 255 | Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}), |
|---|
| 256 | Text( |
|---|
| 257 | extent={{-54,46},{-4,-48}}, |
|---|
| 258 | lineColor={0,0,0}, |
|---|
| 259 | textString="lim"), |
|---|
| 260 | Line(points={{-100,0},{-60,0}}, color={0,0,255}), |
|---|
| 261 | Line(points={{60,0},{100,0}}, color={0,0,255}), |
|---|
| 262 | Text( |
|---|
| 263 | extent={{-8,60},{60,2}}, |
|---|
| 264 | lineColor={0,0,0}, |
|---|
| 265 | textString="k"), |
|---|
| 266 | Text( |
|---|
| 267 | extent={{-8,-2},{60,-60}}, |
|---|
| 268 | lineColor={0,0,0}, |
|---|
| 269 | textString="s"), |
|---|
| 270 | Line(points={{4,0},{46,0}}, color={0,0,0})})); |
|---|
| 271 | |
|---|
| 272 | initial equation |
|---|
| 273 | if initType == Init.SteadyState then |
|---|
| 274 | der(y) = 0; |
|---|
| 275 | elseif initType == Init.InitialState or |
|---|
| 276 | initType == Init.InitialOutput then |
|---|
| 277 | y = y_start; |
|---|
| 278 | end if; |
|---|
| 279 | equation |
|---|
| 280 | if initial() and not limitsAtInit then |
|---|
| 281 | der(y) = k*u; |
|---|
| 282 | assert(y >= outMin - 0.01*abs(outMin) and |
|---|
| 283 | y <= outMax + 0.01*abs(outMax), |
|---|
| 284 | "LimIntegrator: During initialization the limits have been ignored.\n"+ |
|---|
| 285 | "However, the result is that the output y is not within the required limits:\n"+ |
|---|
| 286 | " y = " + String(y) + ", outMin = " + String(outMin) + ", outMax = " + String(outMax)); |
|---|
| 287 | else |
|---|
| 288 | der(y) = if y < outMin and u < 0 or y > outMax and u > 0 then 0 else k*u; |
|---|
| 289 | end if; |
|---|
| 290 | end LimIntegrator; |
|---|
| 291 | |
|---|
| 292 | block Derivative "Approximated derivative block" |
|---|
| 293 | import Modelica.Blocks.Types.Init; |
|---|
| 294 | parameter Real k=1 "Gains"; |
|---|
| 295 | parameter SIunits.Time T(min=Modelica.Constants.small) = 0.01 |
|---|
| 296 | "Time constants (T>0 required; T=0 is ideal derivative block)"; |
|---|
| 297 | parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.NoInit |
|---|
| 298 | "Type of initialization (1: no init, 2: steady state, 3: initial state, 4: initial output)" |
|---|
| 299 | annotation(Evaluate=true, |
|---|
| 300 | Dialog(group="Initialization")); |
|---|
| 301 | parameter Real x_start=0 "Initial or guess value of state" |
|---|
| 302 | annotation (Dialog(group="Initialization")); |
|---|
| 303 | parameter Real y_start=0 "Initial value of output (= state)" |
|---|
| 304 | annotation(Dialog(enable=initType == Init.InitialOutput, group= |
|---|
| 305 | "Initialization")); |
|---|
| 306 | extends Interfaces.SISO; |
|---|
| 307 | |
|---|
| 308 | output Real x(start=x_start) "State of block"; |
|---|
| 309 | |
|---|
| 310 | annotation ( |
|---|
| 311 | Documentation(info=" |
|---|
| 312 | <HTML> |
|---|
| 313 | <p> |
|---|
| 314 | This blocks defines the transfer function between the |
|---|
| 315 | input u and the output y |
|---|
| 316 | (element-wise) as <i>approximated derivative</i>: |
|---|
| 317 | </p> |
|---|
| 318 | <pre> |
|---|
| 319 | k * s |
|---|
| 320 | y = ------------ * u |
|---|
| 321 | T * s + 1 |
|---|
| 322 | </pre> |
|---|
| 323 | <p> |
|---|
| 324 | If you would like to be able to change easily between different |
|---|
| 325 | transfer functions (FirstOrder, SecondOrder, ... ) by changing |
|---|
| 326 | parameters, use the general block <b>TransferFunction</b> instead |
|---|
| 327 | and model a derivative block with parameters<br> |
|---|
| 328 | b = {k,0}, a = {T, 1}. |
|---|
| 329 | </p> |
|---|
| 330 | |
|---|
| 331 | <p> |
|---|
| 332 | If k=0, the block reduces to y=0. |
|---|
| 333 | </p> |
|---|
| 334 | </HTML> |
|---|
| 335 | "), Icon(coordinateSystem( |
|---|
| 336 | preserveAspectRatio=true, |
|---|
| 337 | extent={{-100,-100},{100,100}}, |
|---|
| 338 | grid={2,2}), graphics={ |
|---|
| 339 | Line(points={{-80,78},{-80,-90}}, color={192,192,192}), |
|---|
| 340 | Polygon( |
|---|
| 341 | points={{-80,90},{-88,68},{-72,68},{-80,90}}, |
|---|
| 342 | lineColor={192,192,192}, |
|---|
| 343 | fillColor={192,192,192}, |
|---|
| 344 | fillPattern=FillPattern.Solid), |
|---|
| 345 | Line(points={{-90,-80},{82,-80}}, color={192,192,192}), |
|---|
| 346 | Polygon( |
|---|
| 347 | points={{90,-80},{68,-72},{68,-88},{90,-80}}, |
|---|
| 348 | lineColor={192,192,192}, |
|---|
| 349 | fillColor={192,192,192}, |
|---|
| 350 | fillPattern=FillPattern.Solid), |
|---|
| 351 | Line(points={{-80,-80},{-80,60},{-70,17.95},{-60,-11.46},{-50,-32.05}, |
|---|
| 352 | {-40,-46.45},{-30,-56.53},{-20,-63.58},{-10,-68.51},{0,-71.96}, |
|---|
| 353 | {10,-74.37},{20,-76.06},{30,-77.25},{40,-78.07},{50,-78.65},{60, |
|---|
| 354 | -79.06}}, color={0,0,127}), |
|---|
| 355 | Text( |
|---|
| 356 | extent={{-30,14},{86,60}}, |
|---|
| 357 | lineColor={192,192,192}, |
|---|
| 358 | textString="DT1"), |
|---|
| 359 | Text( |
|---|
| 360 | extent={{-150,-150},{150,-110}}, |
|---|
| 361 | lineColor={0,0,0}, |
|---|
| 362 | textString="k=%k")}), |
|---|
| 363 | Diagram(coordinateSystem( |
|---|
| 364 | preserveAspectRatio=true, |
|---|
| 365 | extent={{-100,-100},{100,100}}, |
|---|
| 366 | grid={2,2}), graphics={ |
|---|
| 367 | Text( |
|---|
| 368 | extent={{-54,52},{50,10}}, |
|---|
| 369 | lineColor={0,0,0}, |
|---|
| 370 | textString="k s"), |
|---|
| 371 | Text( |
|---|
| 372 | extent={{-54,-6},{52,-52}}, |
|---|
| 373 | lineColor={0,0,0}, |
|---|
| 374 | textString="T s + 1"), |
|---|
| 375 | Line(points={{-50,0},{50,0}}, color={0,0,0}), |
|---|
| 376 | Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}), |
|---|
| 377 | Line(points={{-100,0},{-60,0}}, color={0,0,255}), |
|---|
| 378 | Line(points={{60,0},{100,0}}, color={0,0,255})})); |
|---|
| 379 | protected |
|---|
| 380 | parameter Boolean zeroGain = abs(k) < Modelica.Constants.eps; |
|---|
| 381 | initial equation |
|---|
| 382 | if initType == Init.SteadyState then |
|---|
| 383 | der(x) = 0; |
|---|
| 384 | elseif initType == Init.InitialState then |
|---|
| 385 | x = x_start; |
|---|
| 386 | elseif initType == Init.InitialOutput then |
|---|
| 387 | if zeroGain then |
|---|
| 388 | x = u; |
|---|
| 389 | else |
|---|
| 390 | y = y_start; |
|---|
| 391 | end if; |
|---|
| 392 | end if; |
|---|
| 393 | equation |
|---|
| 394 | der(x) = if zeroGain then 0 else (u - x)/T; |
|---|
| 395 | y = if zeroGain then 0 else (k/T)*(u - x); |
|---|
| 396 | end Derivative; |
|---|
| 397 | |
|---|
| 398 | block FirstOrder "First order transfer function block (= 1 pole)" |
|---|
| 399 | import Modelica.Blocks.Types.Init; |
|---|
| 400 | parameter Real k=1 "Gain"; |
|---|
| 401 | parameter SIunits.Time T(start=1) "Time Constant"; |
|---|
| 402 | parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.NoInit |
|---|
| 403 | "Type of initialization (1: no init, 2: steady state, 3/4: initial output)" |
|---|
| 404 | annotation(Evaluate=true, |
|---|
| 405 | Dialog(group="Initialization")); |
|---|
| 406 | parameter Real y_start=0 "Initial or guess value of output (= state)" |
|---|
| 407 | annotation (Dialog(group="Initialization")); |
|---|
| 408 | |
|---|
| 409 | extends Interfaces.SISO(y(start=y_start)); |
|---|
| 410 | |
|---|
| 411 | annotation ( |
|---|
| 412 | Documentation(info="<HTML> |
|---|
| 413 | <p> |
|---|
| 414 | This blocks defines the transfer function between the input u |
|---|
| 415 | and the output y (element-wise) as <i>first order</i> system: |
|---|
| 416 | </p> |
|---|
| 417 | <pre> |
|---|
| 418 | k |
|---|
| 419 | y = ------------ * u |
|---|
| 420 | T * s + 1 |
|---|
| 421 | </pre> |
|---|
| 422 | <p> |
|---|
| 423 | If you would like to be able to change easily between different |
|---|
| 424 | transfer functions (FirstOrder, SecondOrder, ... ) by changing |
|---|
| 425 | parameters, use the general block <b>TransferFunction</b> instead |
|---|
| 426 | and model a first order SISO system with parameters<br> |
|---|
| 427 | b = {k}, a = {T, 1}. |
|---|
| 428 | </p> |
|---|
| 429 | <pre> |
|---|
| 430 | Example: |
|---|
| 431 | parameter: k = 0.3, T = 0.4 |
|---|
| 432 | results in: |
|---|
| 433 | 0.3 |
|---|
| 434 | y = ----------- * u |
|---|
| 435 | 0.4 s + 1.0 |
|---|
| 436 | </pre> |
|---|
| 437 | |
|---|
| 438 | </HTML> |
|---|
| 439 | "), Icon(coordinateSystem( |
|---|
| 440 | preserveAspectRatio=true, |
|---|
| 441 | extent={{-100,-100},{100,100}}, |
|---|
| 442 | grid={2,2}), graphics={ |
|---|
| 443 | Line(points={{-80,78},{-80,-90}}, color={192,192,192}), |
|---|
| 444 | Polygon( |
|---|
| 445 | points={{-80,90},{-88,68},{-72,68},{-80,88},{-80,90}}, |
|---|
| 446 | lineColor={192,192,192}, |
|---|
| 447 | fillColor={192,192,192}, |
|---|
| 448 | fillPattern=FillPattern.Solid), |
|---|
| 449 | Line(points={{-90,-80},{82,-80}}, color={192,192,192}), |
|---|
| 450 | Polygon( |
|---|
| 451 | points={{90,-80},{68,-72},{68,-88},{90,-80}}, |
|---|
| 452 | lineColor={192,192,192}, |
|---|
| 453 | fillColor={192,192,192}, |
|---|
| 454 | fillPattern=FillPattern.Solid), |
|---|
| 455 | Line(points={{-80,-80},{-70,-45.11},{-60,-19.58},{-50,-0.9087},{-40, |
|---|
| 456 | 12.75},{-30,22.75},{-20,30.06},{-10,35.41},{0,39.33},{10,42.19}, |
|---|
| 457 | {20,44.29},{30,45.82},{40,46.94},{50,47.76},{60,48.36},{70,48.8}, |
|---|
| 458 | {80,49.12}}, color={0,0,127}), |
|---|
| 459 | Text( |
|---|
| 460 | extent={{0,0},{60,-60}}, |
|---|
| 461 | lineColor={192,192,192}, |
|---|
| 462 | textString="PT1"), |
|---|
| 463 | Text( |
|---|
| 464 | extent={{-150,-150},{150,-110}}, |
|---|
| 465 | lineColor={0,0,0}, |
|---|
| 466 | textString="T=%T")}), |
|---|
| 467 | Diagram(coordinateSystem( |
|---|
| 468 | preserveAspectRatio=true, |
|---|
| 469 | extent={{-100,-100},{100,100}}, |
|---|
| 470 | grid={2,2}), graphics={ |
|---|
| 471 | Text( |
|---|
| 472 | extent={{-48,52},{50,8}}, |
|---|
| 473 | lineColor={0,0,0}, |
|---|
| 474 | textString="k"), |
|---|
| 475 | Text( |
|---|
| 476 | extent={{-54,-6},{56,-56}}, |
|---|
| 477 | lineColor={0,0,0}, |
|---|
| 478 | textString="T s + 1"), |
|---|
| 479 | Line(points={{-50,0},{50,0}}, color={0,0,0}), |
|---|
| 480 | Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}), |
|---|
| 481 | Line(points={{-100,0},{-60,0}}, color={0,0,255}), |
|---|
| 482 | Line(points={{60,0},{100,0}}, color={0,0,255})})); |
|---|
| 483 | initial equation |
|---|
| 484 | if initType == Init.SteadyState then |
|---|
| 485 | der(y) = 0; |
|---|
| 486 | elseif initType == Init.InitialState or initType == Init.InitialOutput then |
|---|
| 487 | y = y_start; |
|---|
| 488 | end if; |
|---|
| 489 | equation |
|---|
| 490 | der(y) = (k*u - y)/T; |
|---|
| 491 | end FirstOrder; |
|---|
| 492 | |
|---|
| 493 | block SecondOrder "Second order transfer function block (= 2 poles)" |
|---|
| 494 | import Modelica.Blocks.Types.Init; |
|---|
| 495 | parameter Real k=1 "Gain"; |
|---|
| 496 | parameter Real w(start=1) "Angular frequency"; |
|---|
| 497 | parameter Real D(start=1) "Damping"; |
|---|
| 498 | parameter Modelica.Blocks.Types.Init initType=Modelica.Blocks.Types.Init.NoInit |
|---|
| 499 | "Type of initialization (1: no init, 2: steady state, 3/4: initial output)" |
|---|
| 500 | annotation(Evaluate=true, |
|---|
| 501 | Dialog(group="Initialization")); |
|---|
| 502 | parameter Real y_start=0 "Initial or guess value of output (= state)" |
|---|
| 503 | annotation (Dialog(group="Initialization")); |
|---|
| 504 | parameter Real yd_start=0 |
|---|
| 505 | "Initial or guess value of derivative of output (= state)" |
|---|
| 506 | annotation (Dialog(group="Initialization")); |
|---|
| 507 | |
|---|
| 508 | extends Interfaces.SISO(y(start=y_start)); |
|---|
| 509 | output Real yd(start=yd_start) "Derivative of y"; |
|---|
| 510 | annotation ( |
|---|
| 511 | Documentation(info="<HTML> |
|---|
| 512 | <p> |
|---|
| 513 | This blocks defines the transfer function between the input u and |
|---|
| 514 | the output y (element-wise) as <i>second order</i> system: |
|---|
| 515 | </p> |
|---|
| 516 | <pre> |
|---|
| 517 | k |
|---|
| 518 | y = ---------------------------------------- * u |
|---|
| 519 | ( s / w )^2 + 2*D*( s / w ) + 1 |
|---|
| 520 | </pre> |
|---|
| 521 | <p> |
|---|
| 522 | If you would like to be able to change easily between different |
|---|
| 523 | transfer functions (FirstOrder, SecondOrder, ... ) by changing |
|---|
| 524 | parameters, use the general model class <b>TransferFunction</b> |
|---|
| 525 | instead and model a second order SISO system with parameters<br> |
|---|
| 526 | b = {k}, a = {1/w^2, 2*D/w, 1}. |
|---|
| 527 | </p> |
|---|
| 528 | <pre> |
|---|
| 529 | Example: |
|---|
| 530 | |
|---|
| 531 | parameter: k = 0.3, w = 0.5, D = 0.4 |
|---|
| 532 | results in: |
|---|
| 533 | 0.3 |
|---|
| 534 | y = ------------------- * u |
|---|
| 535 | 4.0 s^2 + 1.6 s + 1 |
|---|
| 536 | </pre> |
|---|
| 537 | |
|---|
| 538 | </HTML> |
|---|
| 539 | "), Icon(coordinateSystem( |
|---|
| 540 | preserveAspectRatio=true, |
|---|
| 541 | extent={{-100,-100},{100,100}}, |
|---|
| 542 | grid={2,2}), graphics={ |
|---|
| 543 | Line(points={{-80,78},{-80,-90}}, color={192,192,192}), |
|---|
| 544 | Polygon( |
|---|
| 545 | points={{-80,90},{-88,68},{-72,68},{-80,88},{-80,90}}, |
|---|
| 546 | lineColor={192,192,192}, |
|---|
| 547 | fillColor={192,192,192}, |
|---|
| 548 | fillPattern=FillPattern.Solid), |
|---|
| 549 | Line(points={{-90,-80},{82,-80}}, color={192,192,192}), |
|---|
| 550 | Polygon( |
|---|
| 551 | points={{90,-80},{68,-72},{68,-88},{90,-80}}, |
|---|
| 552 | lineColor={192,192,192}, |
|---|
| 553 | fillColor={192,192,192}, |
|---|
| 554 | fillPattern=FillPattern.Solid), |
|---|
| 555 | Line(points={{-80,-80},{-72,-68.53},{-64,-39.5},{-56,-2.522},{-48, |
|---|
| 556 | 32.75},{-40,58.8},{-32,71.51},{-24,70.49},{-16,58.45},{-8,40.06}, |
|---|
| 557 | {0,20.55},{8,4.459},{16,-5.271},{24,-7.629},{32,-3.428},{40, |
|---|
| 558 | 5.21},{48,15.56},{56,25.03},{64,31.66},{72,34.5},{80,33.61}}, |
|---|
| 559 | color={0,0,127}), |
|---|
| 560 | Text( |
|---|
| 561 | extent={{0,-10},{60,-70}}, |
|---|
| 562 | lineColor={192,192,192 |
|---|