How do i Import my FMU properly?

14 views (last 30 days)
Nils Reimer
Nils Reimer on 28 Apr 2020
Answered: Kautuk Raj on 11 Dec 2024 at 6:12
Hi, I've seen there are some simular questions but with different errors...nothing helped me so far.
So I've created a new FMU by opening my Project and using the Share option to Export it to FMU. After that, I've closed every window and opened 2 new instances of Matlab.By typing the command
>> shareMATLABForFMUCoSim
it will ready that instance of Matlab for co-simulation.
In the second instance I've opened a new Simulink model, used the ImportFMU block and set its Importdata to my just created fmu.
Running the model gives me then the following errors.
Error in supplied FMU: An error occurred in function 'fmi2ExitInitializationMode' for block 'untitled/FMU' during simulation.
the debug logs give me :
# Debug Logging enabled for block 'untitled/FMU'
Log from FMU: [category:logStatusError, status:fmi2Error] fmi2ExitInitializationMode: Error using containers.Map/subsref
The specified key is not present in this container.
Error in fmuhelper/expand
Error in fmuhelper/expandArray
Error in fmuhelper/setPostInitVariableValue
can you please tell me what i am doing wrong?

Answers (1)

Kautuk Raj
Kautuk Raj on 11 Dec 2024 at 6:12
I also faced the same error when I was trying to export a model to FMU which contained a MATLAB Function Block using bus signals.
I figured out that using non-virtual buses is permitted in the model, the error here is due to the bus object name is not available in the slave session. To resolve this, I followed the steps below:
(1) Add a callback function to load the bus signals: load 'my_mat_file.mat' in "Model Properties > Callbacks > PreLoadFcn", save and then export the model to FMU. This will load the bus signal into the workspace of the slave session where the exported model is simulated.
(2) In the model, add the same callback function to load the Bus_input and Bus_output
(3) In the current MATLAB command window, execute:
>> shareMATLABForFMUCoSim
This command makes the current MATLAB become a slave session for co-simulation.
(4) Open a new MATLAB session, then open the test model with the FMU block. The co-simulation will now run successfully. 
I hope following these steps will help resolve the error.

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!