| 1 | within Modelica; |
|---|
| 2 | package Blocks "Library of basic input/output control blocks (continuous, discrete, logical, table blocks)" |
|---|
| 3 | import SI = Modelica.SIunits; |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | extends Modelica.Icons.Library2; |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | annotation(preferedView="info", |
|---|
| 10 | Window( |
|---|
| 11 | x=0.03, |
|---|
| 12 | y=0.05, |
|---|
| 13 | width=0.21, |
|---|
| 14 | height=0.48, |
|---|
| 15 | library=1, |
|---|
| 16 | autolayout=1), |
|---|
| 17 | Icon( |
|---|
| 18 | Rectangle(extent=[-32, -6; 16, -35], style(color=0)), |
|---|
| 19 | Rectangle(extent=[-32, -56; 16, -85], style(color=0)), |
|---|
| 20 | Line(points=[16, -20; 49, -20; 49, -71; 16, -71], style(color=0)), |
|---|
| 21 | Line(points=[-32, -72; -64, -72; -64, -21; -32, -21], style(color=0)), |
|---|
| 22 | Polygon(points=[16, -71; 29, -67; 29, -74; 16, -71], style( |
|---|
| 23 | color=0, |
|---|
| 24 | fillColor=0, |
|---|
| 25 | fillPattern=1)), |
|---|
| 26 | Polygon(points=[-32, -21; -46, -17; -46, -25; -32, -21], style( |
|---|
| 27 | color=0, |
|---|
| 28 | fillColor=0, |
|---|
| 29 | fillPattern=1))), Documentation(info="<html> |
|---|
| 30 | <p> |
|---|
| 31 | This library contains input/output blocks to build up block diagrams. |
|---|
| 32 | </p> |
|---|
| 33 | |
|---|
| 34 | <dl> |
|---|
| 35 | <dt><b>Main Author:</b> |
|---|
| 36 | <dd><a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a><br> |
|---|
| 37 | Deutsches Zentrum für Luft und Raumfahrt e. V. (DLR)<br> |
|---|
| 38 | Oberpfaffenhofen<br> |
|---|
| 39 | Postfach 1116<br> |
|---|
| 40 | D-82230 Wessling<br> |
|---|
| 41 | email: <A HREF=\"mailto:Martin.Otter@dlr.de\">Martin.Otter@dlr.de</A><br> |
|---|
| 42 | </dl> |
|---|
| 43 | <p> |
|---|
| 44 | Copyright © 1998-2007, Modelica Association and DLR. |
|---|
| 45 | </p> |
|---|
| 46 | <p> |
|---|
| 47 | <i>This Modelica package is <b>free</b> software; it can be redistributed and/or modified |
|---|
| 48 | under the terms of the <b>Modelica license</b>, see the license conditions |
|---|
| 49 | and the accompanying <b>disclaimer</b> |
|---|
| 50 | <a href=\"Modelica://Modelica.UsersGuide.ModelicaLicense\">here</a>.</i> |
|---|
| 51 | </p> |
|---|
| 52 | </HTML> |
|---|
| 53 | ", revisions="<html> |
|---|
| 54 | <ul> |
|---|
| 55 | <li><i>June 23, 2004</i> |
|---|
| 56 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br> |
|---|
| 57 | Introduced new block connectors and adapated all blocks to the new connectors. |
|---|
| 58 | Included subpackages Continuous, Discrete, Logical, Nonlinear from |
|---|
| 59 | package ModelicaAdditions.Blocks. |
|---|
| 60 | Included subpackage ModelicaAdditions.Table in Modelica.Blocks.Sources |
|---|
| 61 | and in the new package Modelica.Blocks.Tables. |
|---|
| 62 | Added new blocks to Blocks.Sources and Blocks.Logical. |
|---|
| 63 | </li> |
|---|
| 64 | <li><i>October 21, 2002</i> |
|---|
| 65 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a> |
|---|
| 66 | and <a href=\"http://www.robotic.dlr.de/Christian.Schweiger/\">Christian Schweiger</a>:<br> |
|---|
| 67 | New subpackage Examples, additional components. |
|---|
| 68 | </li> |
|---|
| 69 | <li><i>June 20, 2000</i> |
|---|
| 70 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a> and |
|---|
| 71 | Michael Tiller:<br> |
|---|
| 72 | Introduced a replaceable signal type into |
|---|
| 73 | Blocks.Interfaces.RealInput/RealOutput: |
|---|
| 74 | <pre> |
|---|
| 75 | replaceable type SignalType = Real |
|---|
| 76 | </pre> |
|---|
| 77 | in order that the type of the signal of an input/output block |
|---|
| 78 | can be changed to a physical type, for example: |
|---|
| 79 | <pre> |
|---|
| 80 | Sine sin1(outPort(redeclare type SignalType=Modelica.SIunits.Torque)) |
|---|
| 81 | </pre> |
|---|
| 82 | </li> |
|---|
| 83 | <li><i>Sept. 18, 1999</i> |
|---|
| 84 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br> |
|---|
| 85 | Renamed to Blocks. New subpackages Math, Nonlinear. |
|---|
| 86 | Additional components in subpackages Interfaces, Continuous |
|---|
| 87 | and Sources. </li> |
|---|
| 88 | <li><i>June 30, 1999</i> |
|---|
| 89 | by <a href=\"http://www.robotic.dlr.de/Martin.Otter/\">Martin Otter</a>:<br> |
|---|
| 90 | Realized a first version, based on an existing Dymola library |
|---|
| 91 | of Dieter Moormann and Hilding Elmqvist.</li> |
|---|
| 92 | </ul> |
|---|
| 93 | </html>")); |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | package Examples |
|---|
| 97 | "Library of examples to demonstrate the usage of package Blocks" |
|---|
| 98 | |
|---|
| 99 | extends Icons.Library; |
|---|
| 100 | |
|---|
| 101 | model PID_Controller "Demonstrate usage of the Continuous.LimPID controller" |
|---|
| 102 | extends Modelica.Icons.Example; |
|---|
| 103 | parameter Modelica.SIunits.Angle driveAngle=1.57 |
|---|
| 104 | "Reference distance to move"; |
|---|
| 105 | Modelica.Blocks.Continuous.LimPID PI( |
|---|
| 106 | k=100, |
|---|
| 107 | Ti=0.1, |
|---|
| 108 | yMax=12, |
|---|
| 109 | Ni=0.1, |
|---|
| 110 | initType=Modelica.Blocks.Types.Init.SteadyState, |
|---|
| 111 | limitsAtInit=false, |
|---|
| 112 | controllerType=Modelica.Blocks.Types.SimpleController.PI) |
|---|
| 113 | annotation (extent=[-56,-20; -36,0]); |
|---|
| 114 | Modelica.Mechanics.Rotational.Inertia inertia1(initType=Modelica.Mechanics. |
|---|
| 115 | Rotational.Types.Init.InitialAngleAcceleration) |
|---|
| 116 | annotation (extent=[2,-20; 22,0]); |
|---|
| 117 | annotation ( |
|---|
| 118 | Diagram( |
|---|
| 119 | Rectangle(extent=[-99,48; -32,8], style(color=1, rgbcolor={255,0,0})), |
|---|
| 120 | Text( |
|---|
| 121 | extent=[-98,59; -31,51], |
|---|
| 122 | style(color=1, rgbcolor={255,0,0}), |
|---|
| 123 | string="reference speed generation"), |
|---|
| 124 | Text( |
|---|
| 125 | extent=[-98,-46; -60,-52], |
|---|
| 126 | style(color=1, rgbcolor={255,0,0}), |
|---|
| 127 | string="PI controller"), |
|---|
| 128 | Line(points=[-76,-44; -57,-23], style( |
|---|
| 129 | color=1, |
|---|
| 130 | rgbcolor={255,0,0}, |
|---|
| 131 | arrow=1)), |
|---|
| 132 | Rectangle(extent=[-25,6; 99,-50], style(color=1, rgbcolor={255,0,0})), |
|---|
| 133 | Text( |
|---|
| 134 | extent=[4,14; 71,7], |
|---|
| 135 | style(color=1, rgbcolor={255,0,0}), |
|---|
| 136 | string="plant (simple drive train)")), |
|---|
| 137 | Coordsys( |
|---|
| 138 | extent=[-100,-100; 100,100], |
|---|
| 139 | grid=[1,1], |
|---|
| 140 | scale=0), |
|---|
| 141 | experiment(StopTime=4), |
|---|
| 142 | experimentSetupOutput, |
|---|
| 143 | Documentation(info="<html> |
|---|
| 144 | |
|---|
| 145 | <p> |
|---|
| 146 | This is a simple drive train controlled by a PID controller: |
|---|
| 147 | </p> |
|---|
| 148 | |
|---|
| 149 | <ul> |
|---|
| 150 | <li> The two blocks \"kinematic_PTP\" and \"integrator\" are used to generate |
|---|
| 151 | the reference speed (= constant acceleration phase, constant speed phase, |
|---|
| 152 | constant deceleration phase until inertia is at rest). To check |
|---|
| 153 | whether the system starts in steady state, the reference speed is |
|---|
| 154 | zero until time = 0.5 s and then follows the sketched trajectory.</li> |
|---|
| 155 | |
|---|
| 156 | <li> The block \"PI\" is an instance of \"Blocks.Continuous.LimPID\" which is |
|---|
| 157 | a PID controller where several practical important aspects, such as |
|---|
| 158 | anti-windup-compensation has been added. In this case, the control block |
|---|
| 159 | is used as PI controller.</li> |
|---|
| 160 | |
|---|
| 161 | <li> The output of the controller is a torque that drives a motor inertia |
|---|
| 162 | \"inertia1\". Via a complöiant spring/damper component, the load |
|---|
| 163 | inertia \"inertia2\" is attached. A constant external torque of 10 Nm |
|---|
| 164 | is acting on the load inertia.</li> |
|---|
| 165 | </ul> |
|---|
| 166 | |
|---|
| 167 | <p> |
|---|
| 168 | The PI controller settings included \"limitAtInit=false\", in order that |
|---|
| 169 | the controller output limits of 12 Nm are removed from the initialization |
|---|
| 170 | problem. |
|---|
| 171 | </p> |
|---|
| 172 | |
|---|
| 173 | <p> |
|---|
| 174 | The PI controller is initialized in steady state (initType=SteadyState) |
|---|
| 175 | and the drive shall also be initialized in steady state. |
|---|
| 176 | However, it is not possible to initialize \"inertia1\" in SteadyState, because |
|---|
| 177 | \"der(inertia1.phi)=inertia1.w=0\" is an input to the PI controller that |
|---|
| 178 | defines that the derivative of the integrator state is zero (= the same |
|---|
| 179 | condition that was already defined by option SteadyState of the PI controller). |
|---|
| 180 | Furthermore, one initial condition is missing, because the absolute position |
|---|
| 181 | of inertia1 or inertia2 is not defined. The solution shown in this examples is |
|---|
| 182 | to initialize the angle and the angular acceleration of \"inertia1\". |
|---|
| 183 | </p> |
|---|
| 184 | |
|---|
| 185 | <p> |
|---|
| 186 | In the following figure, results of a typical simulation are shown: |
|---|
| 187 | </p> |
|---|
| 188 | |
|---|
| 189 | <p> |
|---|
| 190 | <img src=\"../Images/Blocks/PID_controller.png\"><br> |
|---|
| 191 | <img src=\"../Images/Blocks/PID_controller2.png\"> |
|---|
| 192 | </p> |
|---|
| 193 | |
|---|
| 194 | <p> |
|---|
| 195 | In the upper figure the reference speed (= integrator.y) and |
|---|
| 196 | the actual speed (= inertia1.w) are shown. As can be seen, |
|---|
| 197 | the system initializes in steady state, since no transients |
|---|
| 198 | are present. The inertia follows the reference speed quite good |
|---|
| 199 | until the end of the constant speed phase. Then there is a deviation. |
|---|
| 200 | In the lower figure the reason can be seen: The output of the |
|---|
| 201 | controller (PI.y) is in its limits. The anti-windup compensation |
|---|
| 202 | works reasonably, since the input to the limiter (PI.limiter.u) |
|---|
| 203 | is forced back to its limit after a transient phase. |
|---|
| 204 | </p> |
|---|
| 205 | |
|---|
| 206 | </html>")); |
|---|
| 207 | Modelica.Mechanics.Rotational.Torque torque |
|---|
| 208 | annotation (extent=[-25,-20; -5,0]); |
|---|
| 209 | Modelica.Mechanics.Rotational.SpringDamper spring(c=1e4, d=100, |
|---|
| 210 | initType=Modelica.Mechanics.Rotational.Types.Init.SteadyState, |
|---|
| 211 | stateSelection=Modelica.Blocks.Types.StateSelection.Prefer) |
|---|
| 212 | annotation (extent=[32,-20; 52,0]); |
|---|
| 213 | Modelica.Mechanics.Rotational.Inertia inertia2(J=2) |
|---|
| 214 | annotation (extent=[60,-20; 80,0]); |
|---|
| 215 | Modelica.Blocks.Sources.KinematicPTP kinematicPTP(startTime=0.5, deltaq={ |
|---|
| 216 | driveAngle}) annotation (extent=[-92,20; -72,40]); |
|---|
| 217 | Modelica.Blocks.Continuous.Integrator integrator(initType=Modelica.Blocks. |
|---|
| 218 | Types.Init.InitialState) annotation (extent=[-63,20; -43,40]); |
|---|
| 219 | Modelica.Mechanics.Rotational.Sensors.SpeedSensor speedSensor |
|---|
| 220 | annotation (extent=[22,-50; 2,-30]); |
|---|
| 221 | Modelica.Mechanics.Rotational.ConstantTorque loadTorque(tau_constant=10) |
|---|
| 222 | annotation (extent=[98,-15; 88,-5]); |
|---|
| 223 | equation |
|---|
| 224 | connect(spring.flange_b,inertia2. flange_a) |
|---|
| 225 | annotation (points=[52,-10; 60,-10], style(color=0, rgbcolor={0,0,0})); |
|---|
| 226 | connect(inertia1.flange_b, spring.flange_a) |
|---|
| 227 | annotation (points=[22,-10; 32,-10], style(color=0, rgbcolor={0,0,0})); |
|---|
| 228 | connect(torque.flange_b, inertia1.flange_a) |
|---|
| 229 | annotation (points=[-5,-10; 2,-10], style(color=0, rgbcolor={0,0,0})); |
|---|
| 230 | connect(kinematicPTP.y[1], integrator.u) annotation (points=[-71,30; -65,30], |
|---|
| 231 | style(color=74, rgbcolor={0,0,127})); |
|---|
| 232 | connect(speedSensor.flange_a, inertia1.flange_b) |
|---|
| 233 | annotation (points=[22,-40; 22,-10], style(color=0, rgbcolor={0,0,0})); |
|---|
| 234 | connect(loadTorque.flange, inertia2.flange_b) |
|---|
| 235 | annotation (points=[88,-10; 80,-10], style(color=0, rgbcolor={0,0,0})); |
|---|
| 236 | connect(PI.y, torque.tau) annotation (points=[-35,-10; -27,-10], style( |
|---|
| 237 | color=74, rgbcolor={0,0,127})); |
|---|
| 238 | connect(speedSensor.w, PI.u_m) annotation (points=[1,-40; -46,-40; -46,-22], |
|---|
| 239 | style(color=74, rgbcolor={0,0,127})); |
|---|
| 240 | connect(integrator.y, PI.u_s) annotation (points=[-42,30; -37,30; -37,11; |
|---|
| 241 | -67,11; -67,-10; -58,-10], style(color=74, rgbcolor={0,0,127})); |
|---|
| 242 | end PID_Controller; |
|---|
| 243 | |
|---|
| 244 | model ShowLogicalSources |
|---|
| 245 | "Show logical sources and demonstrate their diagram animation" |
|---|
| 246 | extends Modelica.Icons.Example; |
|---|
| 247 | Sources.BooleanTable table(table={2,4,6,8}) |
|---|
| 248 | annotation(extent=[-60,-100; -40,-80]); |
|---|
| 249 | Sources.BooleanConstant const annotation(extent=[-60,60; -40,80]); |
|---|
| 250 | Sources.BooleanStep step(startTime=4) annotation(extent=[-60,20; -40,40]); |
|---|
| 251 | Sources.BooleanPulse pulse(period=1.5) annotation(extent=[-60,-20; -40,0]); |
|---|
| 252 | annotation(Diagram, |
|---|
| 253 | experiment(StopTime=10), |
|---|
| 254 | experimentSetupOutput, |
|---|
| 255 | Documentation(info="<html> |
|---|
| 256 | <p> |
|---|
| 257 | This simple example demonstrates the logical sources in |
|---|
| 258 | <a href=\"Modelica://Modelica.Blocks.Sources\">Modelica.Blocks.Sources</a> and demonstrate |
|---|
| 259 | their diagram animation (see \"small circle\" close to the output connector). |
|---|
| 260 | The \"booleanExpression\" source shows how a logical expression can be defined |
|---|
| 261 | in its parameter menu refering to variables available on this level of the |
|---|
| 262 | model. |
|---|
| 263 | </p> |
|---|
| 264 | |
|---|
| 265 | </html>")); |
|---|
| 266 | Sources.SampleTrigger sample( |
|---|
| 267 | period=0.5) annotation(extent=[-60,-60; -40,-40]); |
|---|
| 268 | Sources.BooleanExpression booleanExpression( |
|---|
| 269 | y=pulse.y and step.y) |
|---|
| 270 | annotation(extent=[20,20; 80,40]); |
|---|
| 271 | end ShowLogicalSources; |
|---|
| 272 | |
|---|
| 273 | model LogicalNetwork1 "Example for a network of logical blocks" |
|---|
| 274 | |
|---|
| 275 | extends Modelica.Icons.Example; |
|---|
| 276 | Sources.BooleanTable table2(table={1,3,5,7}) annotation(extent=[-80,-20; -60,0]); |
|---|
| 277 | Sources.BooleanTable table1(table={2,4,6,8}) annotation(extent=[-80,20; -60,40]); |
|---|
| 278 | Logical.Not Not1 annotation(extent=[-40,-20; -20,0]); |
|---|
| 279 | |
|---|
| 280 | annotation(Diagram, |
|---|
| 281 | experiment(StopTime=10), |
|---|
| 282 | experimentSetupOutput, |
|---|
| 283 | Documentation(info="<html> |
|---|
| 284 | <p> |
|---|
| 285 | This example demonstrates a network of logical blocks. Note, that |
|---|
| 286 | the Boolean values of the input and output signals are visualized |
|---|
| 287 | in the diagram animation, by the small \"circles\" close to the connectors. |
|---|
| 288 | If a \"circle\" is \"white\", the signal is <b>false</b>. It a |
|---|
| 289 | \"circle\" is \"green\", the signal is <b>true</b>. |
|---|
| 290 | </p> |
|---|
| 291 | </html>")); |
|---|
| 292 | Logical.And And1 annotation(extent=[0,-20; 20,0]); |
|---|
| 293 | Logical.Or Or1 annotation(extent=[40,20; 60,40]); |
|---|
| 294 | Logical.Pre Pre1 annotation(extent=[-40,-60; -20,-40]); |
|---|
| 295 | equation |
|---|
| 296 | |
|---|
| 297 | connect(table2.y, Not1.u) annotation(points=[-59,-10; -42,-10], style( |
|---|
| 298 | color=5, rgbcolor={255,0,255})); |
|---|
| 299 | connect(And1.y, Or1.u2) annotation(points=[21,-10; 28,-10; 28,22; 38,22], |
|---|
| 300 | style(color=5, rgbcolor={255,0,255})); |
|---|
| 301 | connect(table1.y, Or1.u1) annotation(points=[-59,30; 38,30], style(color= |
|---|
| 302 | 5, rgbcolor={255,0,255})); |
|---|
| 303 | connect(Not1.y, And1.u1) annotation(points=[-19,-10; -2,-10], style(color= |
|---|
| 304 | 5, rgbcolor={255,0,255})); |
|---|
| 305 | connect(Pre1.y, And1.u2) annotation(points=[-19,-50; -10,-50; -10,-18; -2, |
|---|
| 306 | -18], style(color=5, rgbcolor={255,0,255})); |
|---|
| 307 | connect(Or1.y, Pre1.u) annotation(points=[61,30; 68,30; 68,-70; -60,-70; |
|---|
| 308 | -60,-50; -42,-50], style(color=5, rgbcolor={255,0,255})); |
|---|
| 309 | |
|---|
| 310 | end LogicalNetwork1; |
|---|
| 311 | |
|---|
| 312 | annotation (Documentation(info="<html> |
|---|
| 313 | <p> |
|---|
| 314 | This package contains example models to demonstrate the |
|---|
| 315 | usage of package blocks. |
|---|
| 316 | </p> |
|---|
| 317 | </HTML> |
|---|
| 318 | ")); |
|---|
| 319 | |
|---|
| 320 | model BusUsage "Demonstration of signal bus usage" |
|---|
| 321 | extends Modelica.Icons.Example; |
|---|
| 322 | |
|---|
| 323 | annotation (Documentation(info="<html> |
|---|
| 324 | <p><b>Signal bus concept</b></p> |
|---|
| 325 | <p> |
|---|
| 326 | In technical systems, such as vehicles, robots or satellites, many signals |
|---|
| 327 | are exchanged between components. In a simulation system, these signals |
|---|
| 328 | are usually modelled by signal connections of input/output blocks. |
|---|
| 329 | Unfortunately, the signal connection structure may become very complicated, |
|---|
| 330 | especially for hierarchical models. |
|---|
| 331 | </p> |
|---|
| 332 | |
|---|
| 333 | <p> |
|---|
| 334 | The same is also true for real technical systems. To reduce complexity |
|---|
| 335 | and get higher flexibility, many technical systems use data buses to |
|---|
| 336 | exchange data between components. For the same reasons, it is often better |
|---|
| 337 | to use a \"signal bus\" concept also in a Modelica model. This is demonstrated |
|---|
| 338 | at hand of this model (Modelica.Blocks.Examples.BusUsage): |
|---|
| 339 | </p> |
|---|
| 340 | |
|---|
| 341 | <p align=\"center\"> |
|---|
| 342 | <img src=\"../Images/Blocks/BusUsage.png\"> |
|---|
| 343 | </p> |
|---|
| 344 | |
|---|
| 345 | <ul> |
|---|
| 346 | <li> Connector instance \"controlBus\" is a hierarchical connector that is |
|---|
| 347 | used to exchange signals between different components. It is |
|---|
| 348 | defined as \"expandable connector\" in order that <b>no</b> central definition |
|---|
| 349 | of the connector is needed but is automatically constructed by the |
|---|
| 350 | signals connected to it (see also Modelica specification 2.2.1).</li> |
|---|
| 351 | <li> Input/output signals can be directly connected to the \"controlBus\". When |
|---|
| 352 | connecting, it is optionally possible that a <b>label</b> is displayed |
|---|
| 353 | at the connecting line, that contains the name of the variable on the controlBus |
|---|
| 354 | to which the signal is connected. </li> |
|---|
| 355 | <li> A component, such as \"part\", can be directly connected to the \"controlBus\", |
|---|
| 356 | provided it has also a bus connector, or the \"part\" connector is a |
|---|
| 357 | sub-connector contained in the \"controlBus\". </li> |
|---|
| 358 | </ul> |
|---|
| 359 | |
|---|
| 360 | <p> |
|---|
| 361 | The control and sub-control bus icons are provided within Modelica.Icons. |
|---|
| 362 | In <a href=\"Modelica://Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces\">Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces</a> |
|---|
| 363 | the buses for this example are defined. Both the \"ControlBus\" and the \"SubControlBus\" are |
|---|
| 364 | <b>expandable</b> connectors that do not define any variable. For example, |
|---|
| 365 | <a href=\"Modelica://Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces.ControlBus#text\">Interfaces.ControlBus</a> |
|---|
| 366 | is defined as: |
|---|
| 367 | </p> |
|---|
| 368 | <pre> <b>expandable connector</b> ControlBus |
|---|
| 369 | <b>extends</b> Modelica.Icons.ControlBus; |
|---|
| 370 | <b>annotation</b> (Icon(Rectangle(extent=[-20, 2; 22, -2], |
|---|
| 371 | style(rgbcolor={255,204,51}, thickness=2)))); |
|---|
| 372 | <b>end</b> ControlBus; |
|---|
| 373 | </pre> |
|---|
| 374 | <p> |
|---|
| 375 | Note, the \"annotation\" in the connector is important since the color |
|---|
| 376 | and thickness of a connector line are taken from the first |
|---|
| 377 | line element in the icon annotation of a connector class. Above, a small rectangle in the |
|---|
| 378 | color of the bus is defined (and therefore this rectangle is not |
|---|
| 379 | visible). As a result, when connecting from an instance of this |
|---|
| 380 | connector to another connector instance, the connecting line has |
|---|
| 381 | the color of the \"ControlBus\" with double width (due to \"thickness=2\"). |
|---|
| 382 | </p> |
|---|
| 383 | |
|---|
| 384 | <p> |
|---|
| 385 | An <b>expandable</b> connector is a connector where the content of the connector |
|---|
| 386 | is constructed by the variables connected to instances of this connector. |
|---|
| 387 | For example, if \"sine.y\" is connected to the \"controlBus\", the following |
|---|
| 388 | menu pops-up in Dymola: |
|---|
| 389 | </p> |
|---|
| 390 | |
|---|
| 391 | <p align=\"center\"> |
|---|
| 392 | <img src=\"../Images/Blocks/BusUsage2.png\"> |
|---|
| 393 | </p> |
|---|
| 394 | |
|---|
| 395 | <p> |
|---|
| 396 | The \"Add variable/New name\" field allows the user to define the name of the signal on |
|---|
| 397 | the \"controlBus\". When typing \"realSignal1\" as \"New name\", a connection of the form: |
|---|
| 398 | </p> |
|---|
| 399 | |
|---|
| 400 | <pre> <b>connect</b>(sine.y, controlBus.realSignal1) |
|---|
| 401 | </pre> |
|---|
| 402 | |
|---|
| 403 | <p> |
|---|
| 404 | is generated and the \"controlBus\" contains the new signal \"realSignal1\". Modelica tools |
|---|
| 405 | may give more support in order to list potential signals for a connection. |
|---|
| 406 | For example, in Dymola all variables are listed in the menu that are contained in |
|---|
| 407 | connectors which are derived by inheritance from \"controlBus\". Therefore, in |
|---|
| 408 | <a href=\"Modelica://Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces.InternalConnectors\">BusUsage_Utilities.Interfaces.InternalConnectors</a> |
|---|
| 409 | the expected implementation of the \"ControlBus\" and of the \"SubControlBus\" are given. |
|---|
| 410 | For example \"Internal.ControlBus\" is defined as: |
|---|
| 411 | </p> |
|---|
| 412 | |
|---|
| 413 | <pre> <b>expandable connector</b> StandardControlBus |
|---|
| 414 | <b>extends</b> BusUsage_Utilities.Interfaces.ControlBus; |
|---|
| 415 | |
|---|
| 416 | <b>import</b> SI = Modelica.SIunits; |
|---|
| 417 | SI.AngularVelocity realSignal1 \"First Real signal\"; |
|---|
| 418 | SI.Velocity realSignal2 \"Second Real signal\"; |
|---|
| 419 | Integer integerSignal \"Integer signal\"; |
|---|
| 420 | Boolean booleanSignal \"Boolean signal\"; |
|---|
| 421 | StandardSubControlBus subControlBus \"Combined signal\"; |
|---|
| 422 | <b>end</b> StandardControlBus; |
|---|
| 423 | </pre> |
|---|
| 424 | |
|---|
| 425 | <p> |
|---|
| 426 | Consequently, when connecting now from \"sine.y\" to \"controlBus\", the menu |
|---|
| 427 | looks differently: |
|---|
| 428 | </p> |
|---|
| 429 | <p align=\"center\"> |
|---|
| 430 | <img src=\"../Images/Blocks/BusUsage3.png\"> |
|---|
| 431 | </p> |
|---|
| 432 | <p> |
|---|
| 433 | Note, even if the signals from \"Internal.StandardControlBus\" are listed, these are |
|---|
| 434 | just potential signals. The user might still add different signal names. |
|---|
| 435 | </p> |
|---|
| 436 | |
|---|
| 437 | </html>"), Diagram, |
|---|
| 438 | experiment(StopTime=2), |
|---|
| 439 | experimentSetupOutput); |
|---|
| 440 | public |
|---|
| 441 | Modelica.Blocks.Sources.IntegerStep integerStep( |
|---|
| 442 | height=1, |
|---|
| 443 | offset=2, |
|---|
| 444 | startTime=0.5) annotation (extent=[-60,-40; -40,-20], |
|---|
| 445 | rotation=0); |
|---|
| 446 | Modelica.Blocks.Sources.BooleanStep booleanStep(startTime=0.5) |
|---|
| 447 | annotation ( |
|---|
| 448 | extent=[-58,0; -38,20], rotation=0); |
|---|
| 449 | Modelica.Blocks.Sources.Sine sine(y(redeclare type SignalType = |
|---|
| 450 | Modelica.SIunits.AngularVelocity)) |
|---|
| 451 | annotation (extent=[-60,40; -40,60], |
|---|
| 452 | rotation=0); |
|---|
| 453 | |
|---|
| 454 | Modelica.Blocks.Examples.BusUsage_Utilities.Part part |
|---|
| 455 | annotation (extent=[-60,-80; -40,-60]); |
|---|
| 456 | Modelica.Blocks.Math.Gain gain |
|---|
| 457 | annotation(extent=[-40,70; -60,90], rotation=0); |
|---|
| 458 | protected |
|---|
| 459 | BusUsage_Utilities.Interfaces.ControlBus controlBus |
|---|
| 460 | annotation (extent=[50,-10; 10,30], rotation=90); |
|---|
| 461 | equation |
|---|
| 462 | |
|---|
| 463 | connect(sine.y, controlBus.realSignal1) annotation ( |
|---|
| 464 | points=[-39,50; 0,50; 0,14; 30,14; 30,10], |
|---|
| 465 | style(color=74, rgbcolor={0,0,127}), |
|---|
| 466 | Text( |
|---|
| 467 | string="%second", |
|---|
| 468 | index=1, |
|---|
| 469 | extent=[6,3; 6,3], |
|---|
| 470 | style(color=0, rgbcolor={0,0,0}))); |
|---|
| 471 | connect(booleanStep.y, controlBus.booleanSignal) annotation ( |
|---|
| 472 | points=[-37,10; 30,10], |
|---|
| 473 | style(color=5, rgbcolor={255,0,255}), |
|---|
| 474 | Text( |
|---|
| 475 | string="%second", |
|---|
| 476 | index=1, |
|---|
| 477 | extent=[6,3; 6,3], |
|---|
| 478 | style(color=0, rgbcolor={0,0,0}))); |
|---|
| 479 | connect(integerStep.y, controlBus.integerSignal) annotation ( |
|---|
| 480 | points=[-39,-30; 0,-30; 0,4; 30,4; 30,10], |
|---|
| 481 | style(color=45, rgbcolor={255,127,0}), |
|---|
| 482 | Text( |
|---|
| 483 | string="%second", |
|---|
| 484 | index=1, |
|---|
| 485 | extent=[6,3; 6,3], |
|---|
| 486 | style(color=0, rgbcolor={0,0,0}))); |
|---|
| 487 | connect(gain.u, controlBus.realSignal1) annotation ( |
|---|
| 488 | points=[-38,80; 20,80; 20,16; 26,16; 26,10; 30,10], |
|---|
| 489 | style(color=74, rgbcolor={0,0,127}), |
|---|
| 490 | Text( |
|---|
| 491 | string="%second", |
|---|
| 492 | index=1, |
|---|
| 493 | extent=[6,3; 6,3], |
|---|
| 494 | style(color=0, rgbcolor={0,0,0}))); |
|---|
| 495 | connect(part.subControlBus, controlBus.subControlBus) annotation ( |
|---|
| 496 | points=[-40,-70; 30,-70; 30,2], |
|---|
| 497 | style( |
|---|
| 498 | color=6, |
|---|
| 499 | rgbcolor={255,204,51}, |
|---|
| 500 | thickness=2), |
|---|
| 501 | Text( |
|---|
| 502 | string="%second", |
|---|
| 503 | index=1, |
|---|
| 504 | extent=[6,3; 6,3], |
|---|
| 505 | style(color=0, rgbcolor={0,0,0}))); |
|---|
| 506 | end BusUsage; |
|---|
| 507 | |
|---|
| 508 | package BusUsage_Utilities |
|---|
| 509 | "Utility models and connectors for the demonstration example Modelica.Blocks.Examples.BusUsage" |
|---|
| 510 | annotation (preferedView="info",Documentation(info="<html> |
|---|
| 511 | <p> |
|---|
| 512 | This package contains utility models and bus definitions needed for the |
|---|
| 513 | <a href=\"Modelica://Modelica.Blocks.Examples.BusUsage\">BusUsage</a> example. |
|---|
| 514 | </p> |
|---|
| 515 | </html>"), Diagram); |
|---|
| 516 | package Interfaces "Interfaces specialised for this example" |
|---|
| 517 | |
|---|
| 518 | expandable connector ControlBus |
|---|
| 519 | "Empty control bus that is adapted to the signals connected to it" |
|---|
| 520 | extends Modelica.Icons.SignalBus; |
|---|
| 521 | |
|---|
| 522 | annotation ( |
|---|
| 523 | Icon(Rectangle(extent=[-20, 2; 22, -2], style(rgbcolor={255,204,51}, thickness=2))), |
|---|
| 524 | Diagram, |
|---|
| 525 | Documentation(info="<html> |
|---|
| 526 | <p> |
|---|
| 527 | This connector defines the \"expandable connector\" ControlBus that |
|---|
| 528 | is used as bus in the |
|---|
| 529 | <a href=\"Modelica://Modelica.Blocks.Examples.BusUsage\">BusUsage</a> example. |
|---|
| 530 | Note, this connector is \"empty\". When using it, the actual content is |
|---|
| 531 | constructed by the signals connected to this bus. |
|---|
| 532 | </p> |
|---|
| 533 | </html>")); |
|---|
| 534 | |
|---|
| 535 | end ControlBus; |
|---|
| 536 | |
|---|
| 537 | expandable connector SubControlBus |
|---|
| 538 | "Empty sub-control bus that is adapted to the signals connected to it" |
|---|
| 539 | extends Modelica.Icons.SignalSubBus; |
|---|
| 540 | |
|---|
| 541 | annotation (defaultComponentPrefixes="protected", |
|---|
| 542 | Icon(Rectangle(extent=[-20, 2; 22, -2], style(rgbcolor={255,204,51}, thickness=2))), |
|---|
| 543 | Documentation(info="<html> |
|---|
| 544 | <p> |
|---|
| 545 | This connector defines the \"expandable connector\" SubControlBus that |
|---|
| 546 | is used as sub-bus in the |
|---|
| 547 | <a href=\"Modelica://Modelica.Blocks.Examples.BusUsage\">BusUsage</a> example. |
|---|
| 548 | Note, this connector is \"empty\". When using it, the actual content is |
|---|
| 549 | constructed by the signals connected to this bus. |
|---|
| 550 | </p> |
|---|
| 551 | </html>")); |
|---|
| 552 | |
|---|
| 553 | end SubControlBus; |
|---|
| 554 | |
|---|
| 555 | package InternalConnectors |
|---|
| 556 | "Internal definitions that are usually not utilized (only indirectly via the expandable connectors)" |
|---|
| 557 | expandable connector StandardControlBus |
|---|
| 558 | "Used to build up the standard control bus (do not use this connector)" |
|---|
| 559 | extends |
|---|
| 560 | Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces.ControlBus; |
|---|
| 561 | |
|---|
| 562 | import SI = Modelica.SIunits; |
|---|
| 563 | SI.AngularVelocity realSignal1 "First Real signal (angular velocity)"; |
|---|
| 564 | SI.Velocity realSignal2 "Second Real signal"; |
|---|
| 565 | Integer integerSignal "Integer signal"; |
|---|
| 566 | Boolean booleanSignal "Boolean signal"; |
|---|
| 567 | StandardSubControlBus subControlBus "Combined signal"; |
|---|
| 568 | |
|---|
| 569 | annotation ( |
|---|
| 570 | Icon(Rectangle(extent=[-20, 2; 22, -2], style(rgbcolor={255,204,51}, thickness=2))), |
|---|
| 571 | Diagram, |
|---|
| 572 | Documentation(info="<html> |
|---|
| 573 | <p> |
|---|
| 574 | This connector is used to show default signals that might be added |
|---|
| 575 | to the |
|---|
| 576 | <a href=\"Modelica://Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces.ControlBus\">ControlBus</a>. |
|---|
| 577 | </p> |
|---|
| 578 | </html>")); |
|---|
| 579 | |
|---|
| 580 | end StandardControlBus; |
|---|
| 581 | |
|---|
| 582 | expandable connector StandardSubControlBus |
|---|
| 583 | "Used to build up the standard sub-control bus (do not use this connector)" |
|---|
| 584 | extends |
|---|
| 585 | Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces.SubControlBus; |
|---|
| 586 | |
|---|
| 587 | Real myRealSignal; |
|---|
| 588 | Boolean myBooleanSignal; |
|---|
| 589 | |
|---|
| 590 | annotation (defaultComponentPrefixes="protected", |
|---|
| 591 | Icon(Rectangle(extent=[-20, 2; 22, -2], style(rgbcolor={255,204,51}, thickness=2))), |
|---|
| 592 | Documentation(info="<html> |
|---|
| 593 | <p> |
|---|
| 594 | This connector is used to show default signals that might be added |
|---|
| 595 | to the |
|---|
| 596 | <a href=\"Modelica://Modelica.Blocks.Example |
|---|