This package contains a sample model demonstrating the use of Dymola and a Python script to enable hardware-in-the-loop simulation.
Extends from Modelica.Icons.ExamplesPackage (Icon for packages containing runnable examples).Name | Description |
---|---|
CalBayComm | Model calling a Python script to communicate with the CalBay adapter |
This example demonstrates how a Python script and model of a controller can be used to control experiments in the FLEXLAB test cells. It uses an instance of Buildings.Utilities.IO.Python27.Real_Real to communicate with the CalBay adapter. The Python script is located at Buildings/Resources/Python-Sources/CalBayComm.py. The script must be edited before it will effectively communicate with the CalBay adapter. The necessary changes include:
More details describing the necessary changes to the script are provided in the documentation of the script itself.
Note: This model is marked as under construction because the application programming interface for data exchange with the CalBay adaptor of FLEXLAB has not yet been finalized. The model works, however, with the CalBay infrastructure as of October 2013.
Extends from Modelica.Icons.Example (Icon for runnable examples), Modelica.Icons.UnderConstruction.
Type | Name | Default | Description |
---|---|---|---|
Time | samplePeriod | 30 | Sample period for communication [s] |
model CalBayComm "Model calling a Python script to communicate with the CalBay adapter" extends Modelica.Icons.Example; extends Modelica.Icons.UnderConstruction; parameter Modelica.SIunits.Time samplePeriod = 30 "Sample period for communication";Modelica.Blocks.Sources.CombiTimeTable setPoint(tableOnFile=false, table=[0,12; 119,12; 119,6; 239,6; 239,8; 359,8; 359,9; 479,9; 479,10; 599,10; 599,12]) "Setpoint for lights"; Utilities.IO.Python27.Real_Real calBay( functionName="CalBayComm", nDblWri=1, nDblRea=2, moduleName="CalBayComm", final samplePeriod=samplePeriod) "Interface to CalBay communication"; Modelica.Blocks.Math.Feedback feedback "Control error"; lightingController controller(final samplePeriod=samplePeriod) "Controller for light level"; block lightingController "Block for control law" extends Modelica.Blocks.Interfaces.SISO; parameter Modelica.SIunits.Time samplePeriod "Sample period of component"; Modelica.Blocks.Math.Gain gain(k=10); Modelica.Blocks.Nonlinear.Limiter limiter(uMax=100, uMin=1) "Output limiter to constrain control signal"; Modelica.Blocks.Math.Add add; Modelica.Blocks.Discrete.ZeroOrderHold zeroOrderHold( final samplePeriod=samplePeriod) "Zero order hold for feedback"; equationconnect(limiter.y, y); connect(add.y, limiter.u); connect(limiter.y, zeroOrderHold.u); connect(zeroOrderHold.y, add.u2); connect(gain.y, add.u1); connect(u, gain.u); end lightingController ; equationconnect(setPoint.y[1], feedback.u1); connect(calBay.yR[1], feedback.u2); connect(controller.y, calBay.uR[1]); connect(feedback.y, controller.u); end CalBayComm;
Type | Name | Default | Description |
---|---|---|---|
Time | samplePeriod | Sample period of component [s] |
Type | Name | Description |
---|---|---|
input RealInput | u | Connector of Real input signal |
output RealOutput | y | Connector of Real output signal |
block lightingController "Block for control law" extends Modelica.Blocks.Interfaces.SISO; parameter Modelica.SIunits.Time samplePeriod "Sample period of component";Modelica.Blocks.Math.Gain gain(k=10); Modelica.Blocks.Nonlinear.Limiter limiter(uMax=100, uMin=1) "Output limiter to constrain control signal"; Modelica.Blocks.Math.Add add; Modelica.Blocks.Discrete.ZeroOrderHold zeroOrderHold( final samplePeriod=samplePeriod) "Zero order hold for feedback"; equationconnect(limiter.y, y); connect(add.y, limiter.u); connect(limiter.y, zeroOrderHold.u); connect(zeroOrderHold.y, add.u2); connect(gain.y, add.u1); connect(u, gain.u); end lightingController;