How to set parameters in an FMU from Matlab Simulink ?

23 ビュー (過去 30 日間)
Chintan
Chintan 2024 年 6 月 14 日
コメント済み: Chintan 2024 年 6 月 15 日
We have an FMU developed using MSVC 2022 for Windows x64. The FMU imports in Simulink nicely and I am able to see the I/O ports as intended. I am also able to access the inputs set from the environment using assigning a constant / signal generator to the input ports.
I would now like to also set the parameters from the workspace. I have tried using several of the callback functions at the model (Simulink) level as well as the block level. However, I am still not able to see the supplied values affect the parameter values inside the FMU. I am testing this by logging the output in various functions. I only want to set the parameters once at the start of simulation and they are defined like so in the modelDescription.xml file:
<Float64 name="LP" valueReference="1" causality="parameter" variability="fixed" initial="exact" description="POS_THICKNESS" declaredType="Length" start=".1320e-3" />
While the default value is already set, we would like the end user to be able to configure it once for every run.
Any guidance with how to debug this would be appreciated.

採用された回答

Sourabh
Sourabh 2024 年 6 月 14 日
編集済み: Sourabh 2024 年 6 月 14 日
Hey Chintan,
You should be able to set the parameters using the following MATLAB commands:
pathToFMUBlock = 'modelName/blockName';
h = getSimulinkBlockHandle(pathToFMUBlock, true);
set_param(h, 'variable_name', 'value');
A couple of things to node:
  • You can only set variables that have the "variability" attribute marked as "fixed" or "tunable".
  • The value for "fixed" variables can only be changed before the start of every simulation
Here are a few helpful documentation pages:
  1. https://www.mathworks.com/help/simulink/slref/set_param.html
  2. https://www.mathworks.com/help/simulink/ug/parameter-values-and-specification-methods.html
  1 件のコメント
Chintan
Chintan 2024 年 6 月 15 日
@Sourabh Thank you for your response. This worked! I had to set the FMU name explicitly to be able to find the handle for, and open_system() and find_system() helped to find the pathToFMUBlock value.
Do you know if this approach can be extended to set the inputs to the FMU block programatically?
Thanks

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by