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

- Home > Modelica

## 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

Name | Description
--- | ---
CalBayComm | Model calling a Python script to communicate with the CalBay adapter

## Buildings.Utilities.IO.FLEXLAB.CalBayComm

Model calling a Python script to communicate with the CalBay adapter

### 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:

- The script currently does not have valid login or password credentials. The credentials will have to be replaced before communication with the CalBay adapter will succeed.
- To avoid accidental manipulation of controls, the script currently does not include effective commands. The desired commands must be added to the program before it will have any effect.

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 (Icon for classes that are still under construction).

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
Time | samplePeriod | 30 | Sample 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, extrapolation=Modelica.Blocks.Types.Extrapolation.Periodic, smoothness=Modelica.Blocks.Types.Smoothness.ConstantSegments, table=[ -1,12; 119,6; 239,8; 359,9; 479,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

Block for control law

### Information

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

### Parameters

Type | Name | Default | Description
--- | --- | --- | ---
Time | samplePeriod |  | Sample period of component [s]

### Connectors

Type | Name | Description
--- | --- | ---
input RealInput | u | Connector of Real input signal
output RealOutput | y | Connector 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;