Skip to content
Andreas Nicolai edited this page Mar 8, 2019 · 22 revisions

FMICodeGenerator wiki

User Guide

The readme.md file (see main project page) holds an introduction to the tool and the usage.

API

To use the FMUCodeGenerator functionality from other software, you can use the Python-API provided by the Python library. Basically, you create an instance of class FMIGenerator(), specify its attributes and call the member function generate(). As simple as that :-)

# import FMIGenerator class and data types
from FMIGenerator import *

# create instance of FMIGenerator class
fmiGen = FMIGenerator()

# specify attributes
fmiGen.modelName = "MyFirstFMU"
fmiGen.description = "My first auto-generated FMU. Awesome, right?"
fmiGen.targetPath = "../fmus" # relative path to current working directory or absolute file path

# add variables to export
v = VarDef("InputVar1", "continuous", "input", "exact", "Real") # valueRef will be given automatically
v.startValue = 15
fmiGenerator.variables.append(v)

# now generate the FMU
fmiGen.generate()

FMU Compliance Checker Testing Procedure

The FMUs created by the FMIGenerator are only backbones and lack specific functionality. To test the correct export, we will follow this procedure:

  1. define an FMU with given parameters and variables according to the defined test scenario (see below)
  2. generate the FMU directory with the FMIGenerator
  3. add C++-Code into FMU source stub
  4. build and deploy .fmu file
  5. run file through compliance checker

Test Scenarios

State-less P-controller

  • input var: real, continuous, T (temperature in K)
  • output var: real, continuous, W (heating power in W)
  • parameter: real, fixed, k_p (P-control constant)

Logic:

 W = k_p * T

State-less digital controller with dead-band

  • input var: real, continuous, T (temperature in K)
  • output var: real, continuous, W (heating power in W)
  • parameter: real, fixed, T_low (heating on)
  • parameter: real, fixed, T_high (heating off)
  • parameter: real, fixed, delay (min time in [s] between switching events)

Logic:

 T < T_low and t_since_last_switch > delay:
     switch heating on, remember last switch time
 T > T_high and t_since_last_switch > delay:
     switch heating off, remember last switch time
Clone this wiki locally