Clear Filters
Clear Filters

How to make an FMU debugging-friendly in Simulink?

24 views (last 30 days)
We are trying to develop an FMU that is compatible with Simulink. We are using Matlab 2023b+ on Windows x64. The FMU is FMI v3.0 and was originally generated using MSVC 2022 on Windows. The FMU only support co-simulation currently.
We are able to successfully use the FMU using `fmusim`, the executable provided here: https://github.com/modelica/Reference-FMUs . The FMU also correctly works in FMPy https://github.com/CATIA-Systems/FMPy . The FMU also passes the validation check here: https://fmu-check.herokuapp.com/ . However, when we try in Simulink, the simulation stays stuck on t=0.0, i.e. the start. We have added logs to the FMU and are able to see which statement the execution is stuck on, though, the reason for that is not clear.
To solve this, we would like to try to debug by placing breakpoints and view the value of the local variables etc. When trying to use the fmudialog.compileFMUSources we get a few compile errors. How can one better control the exact compile command that is used by compileFMUSources? The FMU depends on third-party libraries that needs to be correctly linked, hence having access to compile command would be helpful. Is there a way to pass the Makefile or CMakeLists to aid with the FMU building? Is there a way to avoid re-compilation since it was recently compiled with MSVC?
Attaching an empty FMU for context here. This is "empty" as in it does include the any numerical processing but includes the FMU piping, stepping, output passing, logging, a third party dependency - curl and CMakeLists as we use it, a README with build instructions. (`python build/build.py x86_64-windows`). Also, includes the resulting FMU in the build folder.
  4 Comments
Chintan
Chintan on 15 Jun 2024
Edited: Chintan on 15 Jun 2024
@Sachin Lodhi Thank you for sharing the resources. I have seen the pages, but they do not give info about how the fmudialog.compileFMUSources() can be given custom compile options, maybe I am missing the link between the FMU block and C caller block. Is the source for the function fmudialog.compileFMUSources available for review or its printing or other options seen somewhere. Also, would you know if it is possible to debug with Visual Studio while running the FMU in Simulink, as our FMU is currently setup to build with MSVC 2022?
@Christian Bertsch Thank you for your response. We generated this using the skeleton and modifying the build instructions from https://github.com/modelica/Reference-FMUs using our custom C code (hand-written). In this sense, it seems our FMU is non-standard (?) since we did not use a model export tool. We have not used FMIKit yet, but appreciate the nudge. I will try and report the results with FMIKit import (will need to downgrade Matlab).
Christian Bertsch
Christian Bertsch on 16 Jun 2024
@Chintan: The FMU can still be standard-compliant. It does not have to be generated by a tool. Using the checkers as a good indication, especially for the validity of the modelDescription.xml.
Importing your FMU with FMIKit in Simulink could be an option. Even though FMIKit states ML/SL Support until 2023a, to my experience this works also in newer versions.
Regarding the native FMU import in ML/SL and recompilation with debug information: I am not sure, whether fmudialog.compileFMUSources considers the Build Confguration that you could provide with your FMU: https://fmi-standard.org/docs/3.0.1/#BuildConfiguration, where you could pass compiler options.

Sign in to comment.

Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!