LBL logo

Buildings.Utilities.IO.FLEXLAB

Package of example models for communication with FLEXLAB using the CalBay interface

Information

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).

Package Content

NameDescription
Buildings.Utilities.IO.FLEXLAB.CalBayComm CalBayComm Model calling a Python script to communicate with the CalBay adapter

Buildings.Utilities.IO.FLEXLAB.CalBayComm Buildings.Utilities.IO.FLEXLAB.CalBayComm

Model calling a Python script to communicate with the CalBay adapter

Buildings.Utilities.IO.FLEXLAB.CalBayComm

Information

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.

Parameters

TypeNameDefaultDescription
TimesamplePeriod30Sample period for communication [s]

Modelica definition

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";
equation 
  connect(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;
equation 
  connect(setPoint.y[1], feedback.u1);
  connect(calBay.yR[1], feedback.u2);
  connect(controller.y, calBay.uR[1]);
  connect(feedback.y, controller.u);
end CalBayComm;

Buildings.Utilities.IO.FLEXLAB.CalBayComm.lightingController Buildings.Utilities.IO.FLEXLAB.CalBayComm.lightingController

Block for control law

Buildings.Utilities.IO.FLEXLAB.CalBayComm.lightingController

Information

Extends from Modelica.Blocks.Interfaces.SISO (Single Input Single Output continuous control block).

Parameters

TypeNameDefaultDescription
TimesamplePeriod Sample period of component [s]

Connectors

TypeNameDescription
input RealInputuConnector of Real input signal
output RealOutputyConnector of Real output signal

Modelica definition

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";
equation 
  connect(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;

Automatically generated Wed Feb 12 08:20:59 2014.