| 1 | within Modelica.Blocks; |
|---|
| 2 | package Discrete |
|---|
| 3 | "Library of discrete input/output blocks with fixed sample period" |
|---|
| 4 | |
|---|
| 5 | extends Modelica.Icons.Library; |
|---|
| 6 | |
|---|
| 7 | annotation (Documentation(info="<html> |
|---|
| 8 | <p> |
|---|
| 9 | This package contains <b>discrete control blocks</b> |
|---|
| 10 | with <b>fixed sample period</b>. |
|---|
| 11 | Every component of this package is structured in the following way: |
|---|
| 12 | </p> |
|---|
| 13 | <ol> |
|---|
| 14 | <li> A component has <b>continuous real</b> input and output signals.</li> |
|---|
| 15 | <li> The <b>input</b> signals are <b>sampled</b> by the given sample period |
|---|
| 16 | defined via parameter <b>samplePeriod</b>. |
|---|
| 17 | The first sample instant is defined by parameter <b>startTime</b>. |
|---|
| 18 | <li> The <b>output</b> signals are computed from the sampled input signals. |
|---|
| 19 | </ol> |
|---|
| 20 | <p> |
|---|
| 21 | A <b>sampled data system</b> may consist of components of package <b>Discrete</b> |
|---|
| 22 | and of every other purely <b>algebraic</b> input/output block, such |
|---|
| 23 | as the components of packages <b>Modelica.Blocks.Math</b>, |
|---|
| 24 | <b>Modelica.Blocks.Nonlinear</b> or <b>Modelica.Blocks.Sources</b>. |
|---|
| 25 | </p> |
|---|
| 26 | |
|---|
| 27 | </HTML> |
|---|
| 28 | ", revisions="<html> |
|---|
| 29 | <ul> |
|---|
| 30 | <li><i>October 21, 2002</i> |
|---|
| 31 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br> |
|---|
| 32 | New components TriggeredSampler and TriggeredMax added.</li> |
|---|
| 33 | <li><i>June 18, 2000</i> |
|---|
| 34 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br> |
|---|
| 35 | Realized based on a corresponding library of Dieter Moormann and |
|---|
| 36 | Hilding Elmqvist.</li> |
|---|
| 37 | </ul> |
|---|
| 38 | </html>")); |
|---|
| 39 | |
|---|
| 40 | block Sampler "Ideal sampling of continuous signals" |
|---|
| 41 | extends Interfaces.DiscreteSISO; |
|---|
| 42 | |
|---|
| 43 | annotation ( |
|---|
| 44 | Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100, |
|---|
| 45 | 100}}), graphics={ |
|---|
| 46 | Ellipse( |
|---|
| 47 | extent={{-25,-10},{-45,10}}, |
|---|
| 48 | lineColor={0,0,127}, |
|---|
| 49 | fillColor={255,255,255}, |
|---|
| 50 | fillPattern=FillPattern.Solid), |
|---|
| 51 | Ellipse( |
|---|
| 52 | extent={{45,-10},{25,10}}, |
|---|
| 53 | lineColor={0,0,127}, |
|---|
| 54 | fillColor={255,255,255}, |
|---|
| 55 | fillPattern=FillPattern.Solid), |
|---|
| 56 | Line(points={{-100,0},{-45,0}}, color={0,0,127}), |
|---|
| 57 | Line(points={{45,0},{100,0}}, color={0,0,127}), |
|---|
| 58 | Line(points={{-35,0},{30,35}}, color={0,0,127})}), |
|---|
| 59 | Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{ |
|---|
| 60 | 100,100}}), graphics={ |
|---|
| 61 | Ellipse( |
|---|
| 62 | extent={{-25,-10},{-45,10}}, |
|---|
| 63 | lineColor={0,0,255}, |
|---|
| 64 | fillColor={255,255,255}, |
|---|
| 65 | fillPattern=FillPattern.Solid), |
|---|
| 66 | Ellipse( |
|---|
| 67 | extent={{45,-10},{25,10}}, |
|---|
| 68 | lineColor={0,0,255}, |
|---|
| 69 | fillColor={255,255,255}, |
|---|
| 70 | fillPattern=FillPattern.Solid), |
|---|
| 71 | Line(points={{-100,0},{-45,0}}, color={0,0,255}), |
|---|
| 72 | Line(points={{45,0},{100,0}}, color={0,0,255}), |
|---|
| 73 | Line(points={{-35,0},{30,35}}, color={0,0,255})}), |
|---|
| 74 | Documentation(info="<HTML> |
|---|
| 75 | <p> |
|---|
| 76 | Samples the continues input signal with a sampling rate defined |
|---|
| 77 | via parameter <b>samplePeriod</b>. |
|---|
| 78 | </p> |
|---|
| 79 | </HTML> |
|---|
| 80 | ")); |
|---|
| 81 | equation |
|---|
| 82 | when {sampleTrigger, initial()} then |
|---|
| 83 | y = u; |
|---|
| 84 | end when; |
|---|
| 85 | end Sampler; |
|---|
| 86 | |
|---|
| 87 | block ZeroOrderHold "Zero order hold of a sampled-data system" |
|---|
| 88 | extends Interfaces.DiscreteSISO; |
|---|
| 89 | output Real ySample(start=0, fixed=true); |
|---|
| 90 | annotation ( |
|---|
| 91 | |
|---|
| 92 | Icon(coordinateSystem( |
|---|
| 93 | preserveAspectRatio=true, |
|---|
| 94 | extent={{-100,-100},{100,100}}, |
|---|
| 95 | grid={2,2}), graphics={Line(points={{-78,-42},{-52,-42},{-52,0},{-26, |
|---|
| 96 | 0},{-26,24},{-6,24},{-6,64},{18,64},{18,20},{38,20},{38,0},{44, |
|---|
| 97 | 0},{44,0},{62,0}}, color={0,0,127})}), |
|---|
| 98 | Documentation(info="<HTML> |
|---|
| 99 | <p> |
|---|
| 100 | The output is identical to the sampled input signal at sample |
|---|
| 101 | time instants and holds the output at the value of the last |
|---|
| 102 | sample instant during the sample points. |
|---|
| 103 | </p> |
|---|
| 104 | </HTML> |
|---|
| 105 | ")); |
|---|
| 106 | equation |
|---|
| 107 | when {sampleTrigger, initial()} then |
|---|
| 108 | ySample = u; |
|---|
| 109 | end when; |
|---|
| 110 | /* Define y=ySample with an infinitesimal delay to break potential |
|---|
| 111 | algebraic loops if both the continuous and the discrete part have |
|---|
| 112 | direct feedthrough |
|---|
| 113 | */ |
|---|
| 114 | y = pre(ySample); |
|---|
| 115 | end ZeroOrderHold; |
|---|
| 116 | |
|---|
| 117 | block FirstOrderHold "First order hold of a sampled-data system" |
|---|
| 118 | extends Interfaces.DiscreteSISO; |
|---|
| 119 | protected |
|---|
| 120 | Real ySample; |
|---|
| 121 | Modelica.SIunits.Time tSample; |
|---|
| 122 | Real c; |
|---|
| 123 | annotation ( |
|---|
| 124 | |
|---|
| 125 | Icon(coordinateSystem( |
|---|
| 126 | preserveAspectRatio=true, |
|---|
| 127 | extent={{-100,-100},{100,100}}, |
|---|
| 128 | grid={1,1}), graphics={Line(points={{-79,-41},{-59,-33},{-40,1},{-20, |
|---|
| 129 | 9},{0,63},{21,20},{41,10},{60,20}}, color={0,0,127}), Line( |
|---|
| 130 | points={{60,19},{81,10}}, color={0,0,255})}), |
|---|
| 131 | Documentation(info="<HTML> |
|---|
| 132 | <p> |
|---|
| 133 | The output signal is the extrapolation through the |
|---|
| 134 | values of the last two sampled input signals. |
|---|
| 135 | </p> |
|---|
| 136 | </HTML> |
|---|
| 137 | ")); |
|---|
| 138 | equation |
|---|
| 139 | when sampleTrigger then |
|---|
| 140 | ySample = u; |
|---|
| 141 | tSample = time; |
|---|
| 142 | c = if firstTrigger then 0 else (ySample - pre(ySample))/samplePeriod; |
|---|
| 143 | end when; |
|---|
| 144 | /* Use pre(ySample) and pre(c) to break potential algebraic loops by an |
|---|
| 145 | infinitesimal delay if both the continuous and the discrete part |
|---|
| 146 | have direct feedthrough. |
|---|
| 147 | */ |
|---|
| 148 | y = pre(ySample) + pre(c)*(time - tSample); |
|---|
| 149 | end FirstOrderHold; |
|---|
| 150 | |
|---|
| 151 | block UnitDelay "Unit Delay Block" |
|---|
| 152 | parameter Real y_start=0 "Initial value of output signal"; |
|---|
| 153 | extends Interfaces.DiscreteSISO; |
|---|
| 154 | |
|---|
| 155 | annotation ( |
|---|
| 156 | |
|---|
| 157 | Documentation(info="<html> |
|---|
| 158 | <p> |
|---|
| 159 | This block describes a unit delay: |
|---|
| 160 | </p> |
|---|
| 161 | <pre> |
|---|
| 162 | 1 |
|---|
| 163 | y = --- * u |
|---|
| 164 | z |
|---|
| 165 | </pre> |
|---|
| 166 | <p> |
|---|
| 167 | that is, the output signal y is the input signal u of the |
|---|
| 168 | previous sample instant. Before the second sample instant, |
|---|
| 169 | the output y is identical to parameter yStart. |
|---|
| 170 | </p> |
|---|
| 171 | |
|---|
| 172 | </HTML> |
|---|
| 173 | "), Icon(coordinateSystem( |
|---|
| 174 | preserveAspectRatio=true, |
|---|
| 175 | extent={{-100,-100},{100,100}}, |
|---|
| 176 | grid={2,2}), graphics={ |
|---|
| 177 | Line(points={{-30,0},{30,0}}, color={0,0,127}), |
|---|
| 178 | Text( |
|---|
| 179 | extent={{-90,10},{90,90}}, |
|---|
| 180 | textString="1", |
|---|
| 181 | lineColor={0,0,127}), |
|---|
| 182 | Text( |
|---|
| 183 | extent={{-90,-10},{90,-90}}, |
|---|
| 184 | textString="z", |
|---|
| 185 | lineColor={0,0,127})}), |
|---|
| 186 | Diagram(coordinateSystem( |
|---|
| 187 | preserveAspectRatio=true, |
|---|
| 188 | extent={{-100,-100},{100,100}}, |
|---|
| 189 | grid={2,2}), graphics={ |
|---|
| 190 | Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}), |
|---|
| 191 | Text( |
|---|
| 192 | extent={{-160,10},{-140,-10}}, |
|---|
| 193 | textString="u", |
|---|
| 194 | lineColor={0,0,255}), |
|---|
| 195 | Text( |
|---|
| 196 | extent={{115,10},{135,-10}}, |
|---|
| 197 | textString="y", |
|---|
| 198 | lineColor={0,0,255}), |
|---|
| 199 | Line(points={{-100,0},{-60,0}}, color={0,0,255}), |
|---|
| 200 | Line(points={{60,0},{100,0}}, color={0,0,255}), |
|---|
| 201 | Line(points={{40,0},{-40,0}}, color={0,0,0}), |
|---|
| 202 | Text( |
|---|
| 203 | extent={{-55,55},{55,5}}, |
|---|
| 204 | lineColor={0,0,0}, |
|---|
| 205 | textString="1"), |
|---|
| 206 | Text( |
|---|
| 207 | extent={{-55,-5},{55,-55}}, |
|---|
| 208 | lineColor={0,0,0}, |
|---|
| 209 | textString="z")})); |
|---|
| 210 | equation |
|---|
| 211 | when sampleTrigger then |
|---|
| 212 | y = pre(u); |
|---|
| 213 | end when; |
|---|
| 214 | |
|---|
| 215 | initial equation |
|---|
| 216 | y = y_start; |
|---|
| 217 | end UnitDelay; |
|---|
| 218 | |
|---|
| 219 | block TransferFunction "Discrete Transfer Function block" |
|---|
| 220 | parameter Real b[:]={1} "Numerator coefficients of transfer function."; |
|---|
| 221 | parameter Real a[:] "Denominator coefficients of transfer function."; |
|---|
| 222 | extends Interfaces.DiscreteSISO; |
|---|
| 223 | output Real x[size(a, 1) - 1](each start=0, each fixed=true) |
|---|
| 224 | "State of transfer function from controller canonical form"; |
|---|
| 225 | protected |
|---|
| 226 | parameter Integer nb=size(b, 1) "Size of Numerator of transfer function"; |
|---|
| 227 | parameter Integer na=size(a, 1) "Size of Denominator of transfer function"; |
|---|
| 228 | Real x1; |
|---|
| 229 | Real xext[size(a, 1)]; |
|---|
| 230 | annotation ( |
|---|
| 231 | |
|---|
| 232 | Documentation(info="<html> |
|---|
| 233 | <p>The <b>discrete transfer function</b> block defines the |
|---|
| 234 | transfer function between the input signal u and the output |
|---|
| 235 | signal y. The numerator has the order nb-1, the denominator |
|---|
| 236 | has the order na-1.</p> |
|---|
| 237 | <pre> b(1)*z^(nb-1) + b(2)*z^(nb-2) + ... + b(nb) |
|---|
| 238 | y(z) = -------------------------------------------- * u(z) |
|---|
| 239 | a(1)*z^(na-1) + a(2)*z^(na-2) + ... + a(na) |
|---|
| 240 | </pre> |
|---|
| 241 | <p>State variables <b>x</b> are defined according to |
|---|
| 242 | <b>controller canonical</b> form. Initial values of the |
|---|
| 243 | states can be set as start values of <b>x</b>.<p> |
|---|
| 244 | <p>Example:</p> |
|---|
| 245 | <pre> Blocks.Discrete.TransferFunction g(b = {2,4}, a = {1,3}); |
|---|
| 246 | </pre> |
|---|
| 247 | <p>results in the following transfer function:</p> |
|---|
| 248 | <pre> 2*z + 4 |
|---|
| 249 | y = --------- * u |
|---|
| 250 | z + 3 |
|---|
| 251 | </pre> |
|---|
| 252 | |
|---|
| 253 | </HTML> |
|---|
| 254 | ", revisions="<html> |
|---|
| 255 | <p><b>Release Notes:</b></p> |
|---|
| 256 | <ul> |
|---|
| 257 | <li><i>November 15, 2000</i> |
|---|
| 258 | by <a href=\"http://www.dynasim.se\">Hans Olsson</a>:<br> |
|---|
| 259 | Converted to when-semantics of Modelica 1.4 with special |
|---|
| 260 | care to avoid unnecessary algebraic loops.</li> |
|---|
| 261 | <li><i>June 18, 2000</i> |
|---|
| 262 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br> |
|---|
| 263 | Realized based on a corresponding model of Dieter Moormann |
|---|
| 264 | and Hilding Elmqvist.</li> |
|---|
| 265 | </ul> |
|---|
| 266 | </html>"), |
|---|
| 267 | Icon(coordinateSystem( |
|---|
| 268 | preserveAspectRatio=true, |
|---|
| 269 | extent={{-100,-100},{100,100}}, |
|---|
| 270 | grid={2,2}), graphics={ |
|---|
| 271 | Line(points={{82,0},{-84,0}}, color={0,0,127}), |
|---|
| 272 | Text( |
|---|
| 273 | extent={{-92,92},{86,12}}, |
|---|
| 274 | lineColor={0,0,127}, |
|---|
| 275 | textString="b(z)"), |
|---|
| 276 | Text( |
|---|
| 277 | extent={{-90,-12},{90,-90}}, |
|---|
| 278 | lineColor={0,0,127}, |
|---|
| 279 | textString="a(z)")}), |
|---|
| 280 | Diagram(coordinateSystem( |
|---|
| 281 | preserveAspectRatio=true, |
|---|
| 282 | extent={{-100,-100},{100,100}}, |
|---|
| 283 | grid={2,2}), graphics={ |
|---|
| 284 | Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}), |
|---|
| 285 | Line( |
|---|
| 286 | points={{40,0},{-44,0}}, |
|---|
| 287 | color={0,0,0}, |
|---|
| 288 | thickness=0.5), |
|---|
| 289 | Text( |
|---|
| 290 | extent={{-54,54},{54,4}}, |
|---|
| 291 | lineColor={0,0,0}, |
|---|
| 292 | textString="b(z)"), |
|---|
| 293 | Text( |
|---|
| 294 | extent={{-54,-6},{56,-56}}, |
|---|
| 295 | lineColor={0,0,0}, |
|---|
| 296 | textString="a(z)"), |
|---|
| 297 | Line(points={{-100,0},{-60,0}}, color={0,0,255}), |
|---|
| 298 | Line(points={{60,0},{100,0}}, color={0,0,255})})); |
|---|
| 299 | equation |
|---|
| 300 | when sampleTrigger then |
|---|
| 301 | /* State variables x are defined according to |
|---|
| 302 | controller canonical form. */ |
|---|
| 303 | x1 = (u - a[2:size(a, 1)]*pre(x))/a[1]; |
|---|
| 304 | xext = vector([x1; pre(x)]); |
|---|
| 305 | x = xext[1:size(x, 1)]; |
|---|
| 306 | y = vector([zeros(na - nb, 1); b])*xext; |
|---|
| 307 | end when; |
|---|
| 308 | /* This is a non-sampled equation and above there are two separate |
|---|
| 309 | when-clauses. This breaks feeback loops without direct terms, |
|---|
| 310 | since in that case y will be independent of x1 (and only dependent |
|---|
| 311 | on pre(x)). |
|---|
| 312 | */ |
|---|
| 313 | /* Corresponding (simpler) version using when-semantics of Modelica 1.3: |
|---|
| 314 | equation |
|---|
| 315 | when sampleTrigger then |
|---|
| 316 | [x; xn] = [x1; pre(x)]; |
|---|
| 317 | [u] = transpose([a])*[x1; pre(x)]; |
|---|
| 318 | [y] = transpose([zeros(na - nb, 1); b])*[x1; pre(x)]; |
|---|
| 319 | end when; |
|---|
| 320 | */ |
|---|
| 321 | end TransferFunction; |
|---|
| 322 | |
|---|
| 323 | block StateSpace "Discrete State Space block" |
|---|
| 324 | parameter Real A[:, size(A, 1)] "Matrix A of state space model"; |
|---|
| 325 | parameter Real B[size(A, 1), :] "Matrix B of state space model"; |
|---|
| 326 | parameter Real C[:, size(A, 1)] "Matrix C of state space model"; |
|---|
| 327 | parameter Real D[size(C, 1), size(B, 2)]=zeros(size(C, 1), size(B, 2)) |
|---|
| 328 | "Matrix D of state space model"; |
|---|
| 329 | |
|---|
| 330 | extends Interfaces.DiscreteMIMO(final nin=size(B, 2), final nout=size(C, 1)); |
|---|
| 331 | output Real x[size(A, 1)] "State vector"; |
|---|
| 332 | |
|---|
| 333 | annotation ( |
|---|
| 334 | |
|---|
| 335 | Documentation(info="<html> |
|---|
| 336 | <p> |
|---|
| 337 | The <b>discrete state space</b> block defines the relation |
|---|
| 338 | between the input u=inPort.signal and the output |
|---|
| 339 | y=outPort.signal in state space form: |
|---|
| 340 | </p> |
|---|
| 341 | <pre> |
|---|
| 342 | x = A * pre(x) + B * u |
|---|
| 343 | y = C * pre(x) + D * u |
|---|
| 344 | </pre> |
|---|
| 345 | <p> |
|---|
| 346 | where pre(x) is the value of the discrete state x at |
|---|
| 347 | the previous sample time instant. |
|---|
| 348 | The input is a vector of length nu, the output is a vector |
|---|
| 349 | of length ny and nx is the number of states. Accordingly |
|---|
| 350 | </p> |
|---|
| 351 | <pre> |
|---|
| 352 | A has the dimension: A(nx,nx), |
|---|
| 353 | B has the dimension: B(nx,nu), |
|---|
| 354 | C has the dimension: C(ny,nx), |
|---|
| 355 | D has the dimension: D(ny,nu) |
|---|
| 356 | </pre> |
|---|
| 357 | <p> |
|---|
| 358 | Example: |
|---|
| 359 | </p> |
|---|
| 360 | <pre> |
|---|
| 361 | parameter: A = [0.12, 2;3, 1.5] |
|---|
| 362 | parameter: B = [2, 7;3, 1] |
|---|
| 363 | parameter: C = [0.1, 2] |
|---|
| 364 | parameter: D = zeros(ny,nu) |
|---|
| 365 | |
|---|
| 366 | results in the following equations: |
|---|
| 367 | [x[1]] [0.12 2.00] [pre(x[1])] [2.0 7.0] [u[1]] |
|---|
| 368 | [ ] = [ ]*[ ] + [ ]*[ ] |
|---|
| 369 | [x[2]] [3.00 1.50] [pre(x[2])] [0.1 2.0] [u[2]] |
|---|
| 370 | [pre(x[1])] [u[1]] |
|---|
| 371 | y[1] = [0.1 2.0] * [ ] + [0 0] * [ ] |
|---|
| 372 | [pre(x[2])] [u[2]] |
|---|
| 373 | </pre> |
|---|
| 374 | </HTML> |
|---|
| 375 | "), Icon(coordinateSystem( |
|---|
| 376 | preserveAspectRatio=true, |
|---|
| 377 | extent={{-100,-100},{100,100}}, |
|---|
| 378 | grid={2,2}), graphics={ |
|---|
| 379 | Text( |
|---|
| 380 | extent={{-90,15},{-15,90}}, |
|---|
| 381 | textString="A", |
|---|
| 382 | lineColor={0,0,127}), |
|---|
| 383 | Text( |
|---|
| 384 | extent={{15,15},{90,90}}, |
|---|
| 385 | textString="B", |
|---|
| 386 | lineColor={0,0,127}), |
|---|
| 387 | Text( |
|---|
| 388 | extent={{-52,28},{54,-20}}, |
|---|
| 389 | textString="z", |
|---|
| 390 | lineColor={0,0,127}), |
|---|
| 391 | Text( |
|---|
| 392 | extent={{-90,-15},{-15,-90}}, |
|---|
| 393 | textString="C", |
|---|
| 394 | lineColor={0,0,127}), |
|---|
| 395 | Text( |
|---|
| 396 | extent={{15,-15},{90,-90}}, |
|---|
| 397 | textString="D", |
|---|
| 398 | lineColor={0,0,127})}), |
|---|
| 399 | Diagram(coordinateSystem( |
|---|
| 400 | preserveAspectRatio=true, |
|---|
| 401 | extent={{-100,-100},{100,100}}, |
|---|
| 402 | grid={2,2}), graphics={ |
|---|
| 403 | Rectangle(extent={{-60,60},{60,-60}}, lineColor={0,0,255}), |
|---|
| 404 | Text( |
|---|
| 405 | extent={{-54,50},{52,-10}}, |
|---|
| 406 | lineColor={0,0,0}, |
|---|
| 407 | fillColor={128,128,128}, |
|---|
| 408 | fillPattern=FillPattern.None, |
|---|
| 409 | textString="zx=Ax+Bu"), |
|---|
| 410 | Text( |
|---|
| 411 | extent={{-56,14},{54,-50}}, |
|---|
| 412 | lineColor={0,0,0}, |
|---|
| 413 | fillColor={192,192,192}, |
|---|
| 414 | fillPattern=FillPattern.Solid, |
|---|
| 415 | textString=" y=Cx+Du"), |
|---|
| 416 | Line(points={{-102,0},{-60,0}}, color={0,0,255}), |
|---|
| 417 | Line(points={{60,0},{100,0}}, color={0,0,255})})); |
|---|
| 418 | equation |
|---|
| 419 | when sampleTrigger then |
|---|
| 420 | x = A*pre(x) + B*u; |
|---|
| 421 | y = C*pre(x) + D*u; |
|---|
| 422 | end when; |
|---|
| 423 | end StateSpace; |
|---|
| 424 | |
|---|
| 425 | block TriggeredSampler "Triggered sampling of continuous signals" |
|---|
| 426 | extends Interfaces.DiscreteBlockIcon; |
|---|
| 427 | parameter Real y_start=0 "initial value of output signal"; |
|---|
| 428 | |
|---|
| 429 | annotation ( |
|---|
| 430 | Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100, |
|---|
| 431 | 100}}), graphics={ |
|---|
| 432 | Ellipse( |
|---|
| 433 | extent={{-25,-10},{-45,10}}, |
|---|
| 434 | lineColor={0,0,127}, |
|---|
| 435 | fillColor={255,255,255}, |
|---|
| 436 | fillPattern=FillPattern.Solid), |
|---|
| 437 | Ellipse( |
|---|
| 438 | extent={{45,-10},{25,10}}, |
|---|
| 439 | lineColor={0,0,127}, |
|---|
| 440 | fillColor={255,255,255}, |
|---|
| 441 | fillPattern=FillPattern.Solid), |
|---|
| 442 | Line(points={{-100,0},{-45,0}}, color={0,0,127}), |
|---|
| 443 | Line(points={{45,0},{100,0}}, color={0,0,127}), |
|---|
| 444 | Line(points={{0,-100},{0,-26}}, color={255,0,255}), |
|---|
| 445 | Line(points={{-35,0},{28,-48}}, color={0,0,127})}), |
|---|
| 446 | Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{ |
|---|
| 447 | 100,100}}), graphics={ |
|---|
| 448 | Ellipse( |
|---|
| 449 | extent={{-25,-10},{-45,10}}, |
|---|
| 450 | lineColor={0,0,255}, |
|---|
| 451 | fillColor={255,255,255}, |
|---|
| 452 | fillPattern=FillPattern.Solid), |
|---|
| 453 | Ellipse( |
|---|
| 454 | extent={{45,-10},{25,10}}, |
|---|
| 455 | lineColor={0,0,255}, |
|---|
| 456 | fillColor={255,255,255}, |
|---|
| 457 | fillPattern=FillPattern.Solid), |
|---|
| 458 | Line(points={{-100,0},{-45,0}}, color={0,0,255}), |
|---|
| 459 | Line(points={{45,0},{100,0}}, color={0,0,255}), |
|---|
| 460 | Line(points={{-35,0},{28,-48}}, color={0,0,255}), |
|---|
| 461 | Line(points={{0,-100},{0,-26}}, color={255,0,255})}), |
|---|
| 462 | Documentation(info="<HTML> |
|---|
| 463 | <p> |
|---|
| 464 | Samples the continuous input signal whenever the trigger input |
|---|
| 465 | signal is rising (i.e., trigger changes from <b>false</b> to |
|---|
| 466 | <b>true</b>) and provides the sampled input signal as output. |
|---|
| 467 | Before the first sampling, the output signal is equal to |
|---|
| 468 | the initial value defined via parameter <b>y0</b>. |
|---|
| 469 | </p> |
|---|
| 470 | </HTML> |
|---|
| 471 | ")); |
|---|
| 472 | Modelica.Blocks.Interfaces.RealInput u "Connector with a Real input signal" |
|---|
| 473 | annotation (Placement( |
|---|
| 474 | transformation(extent={{-140,-20},{-100,20}}, rotation=0))); |
|---|
| 475 | Modelica.Blocks.Interfaces.RealOutput y |
|---|
| 476 | "Connector with a Real output signal" annotation (Placement( |
|---|
| 477 | transformation(extent={{100,-10},{120,10}}, rotation=0))); |
|---|
| 478 | Modelica.Blocks.Interfaces.BooleanInput trigger annotation (Placement( |
|---|
| 479 | transformation( |
|---|
| 480 | origin={0,-118}, |
|---|
| 481 | extent={{-20,-20},{20,20}}, |
|---|
| 482 | rotation=90))); |
|---|
| 483 | equation |
|---|
| 484 | when trigger then |
|---|
| 485 | y = u; |
|---|
| 486 | end when; |
|---|
| 487 | initial equation |
|---|
| 488 | y = y_start; |
|---|
| 489 | end TriggeredSampler; |
|---|
| 490 | |
|---|
| 491 | block TriggeredMax |
|---|
| 492 | "Compute maximum, absolute value of continuous signal at trigger instants" |
|---|
| 493 | |
|---|
| 494 | extends Interfaces.DiscreteBlockIcon; |
|---|
| 495 | annotation ( |
|---|
| 496 | Icon(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{100, |
|---|
| 497 | 100}}), graphics={ |
|---|
| 498 | Ellipse( |
|---|
| 499 | extent={{-25,-10},{-45,10}}, |
|---|
| 500 | lineColor={0,0,127}, |
|---|
| 501 | fillColor={255,255,255}, |
|---|
| 502 | fillPattern=FillPattern.Solid), |
|---|
| 503 | Ellipse( |
|---|
| 504 | extent={{45,-10},{25,10}}, |
|---|
| 505 | lineColor={0,0,127}, |
|---|
| 506 | fillColor={255,255,255}, |
|---|
| 507 | fillPattern=FillPattern.Solid), |
|---|
| 508 | Line(points={{-100,0},{-45,0}}, color={0,0,127}), |
|---|
| 509 | Line(points={{45,0},{100,0}}, color={0,0,127}), |
|---|
| 510 | Line(points={{0,-100},{0,-26}}, color={255,0,255}), |
|---|
| 511 | Line(points={{-35,0},{28,-48}}, color={0,0,127}), |
|---|
| 512 | Text( |
|---|
| 513 | extent={{-86,82},{82,24}}, |
|---|
| 514 | lineColor={0,0,0}, |
|---|
| 515 | textString="max")}), |
|---|
| 516 | Diagram(coordinateSystem(preserveAspectRatio=true, extent={{-100,-100},{ |
|---|
| 517 | 100,100}}), graphics={ |
|---|
| 518 | Ellipse( |
|---|
| 519 | extent={{-25,-10},{-45,10}}, |
|---|
| 520 | lineColor={0,0,255}, |
|---|
| 521 | fillColor={255,255,255}, |
|---|
| 522 | fillPattern=FillPattern.Solid), |
|---|
| 523 | Ellipse( |
|---|
| 524 | extent={{45,-10},{25,10}}, |
|---|
| 525 | lineColor={0,0,255}, |
|---|
| 526 | fillColor={255,255,255}, |
|---|
| 527 | fillPattern=FillPattern.Solid), |
|---|
| 528 | Line(points={{-100,0},{-45,0}}, color={0,0,255}), |
|---|
| 529 | Line(points={{45,0},{100,0}}, color={0,0,255}), |
|---|
| 530 | Line(points={{-35,0},{28,-48}}, color={0,0,255}), |
|---|
| 531 | Line(points={{0,-100},{0,-26}}, color={255,0,255})}), |
|---|
| 532 | Documentation(info="<HTML> |
|---|
| 533 | <p> |
|---|
| 534 | Samples the continuous input signal whenever the trigger input |
|---|
| 535 | signal is rising (i.e., trigger changes from <b>false</b> to |
|---|
| 536 | <b>true</b>). The maximum, absolute value of the input signal |
|---|
| 537 | at the sampling point is provided as output signal. |
|---|
| 538 | </p> |
|---|
| 539 | </HTML> |
|---|
| 540 | ")); |
|---|
| 541 | Modelica.Blocks.Interfaces.RealInput u "Connector with a Real input signal" |
|---|
| 542 | annotation (Placement(transformation( |
|---|
| 543 | extent={{-140,-20},{-100,20}}, rotation=0))); |
|---|
| 544 | Modelica.Blocks.Interfaces.RealOutput y |
|---|
| 545 | "Connector with a Real output signal" annotation (Placement( |
|---|
| 546 | transformation(extent={{100,-10},{120,10}}, rotation=0))); |
|---|
| 547 | Modelica.Blocks.Interfaces.BooleanInput trigger annotation (Placement( |
|---|
| 548 | transformation( |
|---|
| 549 | origin={0,-118}, |
|---|
| 550 | extent={{-20,-20},{20,20}}, |
|---|
| 551 | rotation=90))); |
|---|
| 552 | equation |
|---|
| 553 | when trigger then |
|---|
| 554 | y = max(pre(y), abs(u)); |
|---|
| 555 | end when; |
|---|
| 556 | initial equation |
|---|
| 557 | y = 0; |
|---|
| 558 | end TriggeredMax; |
|---|
| 559 | end Discrete; |
|---|