1

I'm creating a simple FMI demo system to try out FMI where I have 1 simulator connected to an FMU which computes the state of the system (represented as a number calculated from a closed-form equation) and another FMU that controls the system via a parameter in the closed-form equation. So the system looks something like

FMU-system <--> Simulator <--> FMU-control

In every iteration, I'm updating the system state based on 1 equation, and passing it to the control, which returns a parameter to be passed to the system.

I'm using FMI 2.0.3, and have read the specification. Right now I have 3 files, 1 to act as a simulator and 2 to act as the FMUs. But I'm having difficulties with the implementation of the FMUs and the initialisation of the simulator.

To initialise the FMU, my understanding is I need to call fmi2Instantiate which has this signature.

  • fmi2Component fmi2Instantiate(fmi2String instanceName, fmi2Type fmuType, fmi2String fmuGUID, fmi2String fmuResourceLocation, const fmi2CallbackFunctions* functions, fmi2Boolean visible, fmi2Boolean loggingOn);

But I don't know what to pass in the function for the GUID, resource location and callback function. How should I implement the callback function and initialisation?

Then to implement the FMU, my understanding is I need to implement fmi2SetReal, fmi2GetReal and fmi2DoStep, but I can't figure out how to implement them in terms of code. These are the signatures

  • fmi2Status setReal(fmi2Component c, fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
  • fmi2Status getReal(fmi2Component c, fmi2ValueReference vr[], size_t nvr, fmi2Real value[])
  • fmi2Status doStep(fmi2Component c, fmi2Real currentCommunicationPoint, fmi2Real communicationStepSize, fmi2Boolean noSetFMUStatePriorToCurrentPoint)

But I can't figure out how to implement these functions. Is fmi2Component c meaningless here? And I suppose I have to do the system state computation for the FMU-system in doStep. How should I update the state and pass the code here?

Sorry if this is too many questions but I was trying to look for a tutorial too and I couldn't find any.

2 Answers2

1

https://github.com/traversaro/awesome-fmi

This is a curated list of Functional Mock-up Interface (FMI) libraries, tools and resources.

There are non commercial tools available. Check them out, you will get idea to implement these functions for your application.

1

A good starting point to implement FMI support are the open source Reference FMUs (which recently also got a simple FMU simulator) and fmpy: