user14018421
user14018421

Reputation: 49

How to create FMU slave and initialise FMU in C using Modelica's fmi headers

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.

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

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.

Upvotes: 1

Views: 1050

Answers (2)

Christian Bertsch
Christian Bertsch

Reputation: 588

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

Upvotes: 1

tharrini raj
tharrini raj

Reputation: 21

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.

Upvotes: 1

Related Questions