Simscape global parameter set and change

18 ビュー (過去 30 日間)
Paul Hermens
Paul Hermens 2025 年 2 月 24 日 9:57
I am working with simulink and simscape inside of it. The gas domain in Simscape is what I use but I kind of need a extra parameter (D) in the gas domain that I can set with the gas properties block. What I did was create a custom gas properties block that has the new extra parameter, but I now want it accessible by other (custom) simcape blocks. I could add an output to the custom gas properties block, which is not really the problem, but I will use it in many simscape components scattered throughout the system/network as it is a global parameter. That is why I want a way to just use the parameter in other block 'inputs'/parameter sections like a value, so instead of 1 or 10 input D and then it resolves to D from gas properties.
I could theoretically make a whole new domain but this means copying all other unchanged components to match that domain instead of foundation.gas.gas which is overkill if you ask me. I also tried using memory blocks in all kind of ways but this does not work either in the easy way I imagined.
Currently the best workaround way seems to have a subsystem with a memory read. Which is coupled with a memory block in the main/top system and a dictionary which then needs to imported to every model using this which holds the original parameter D with not value given. Then set it as initial value in the memory block and adjust using memory write. This seems very unnecessary to me but nowhere can I find any documentation or references that show a better approach. And to match with what my use case is, I need to output the D parameter from the gas properties block into the memory write. So in total 3 blocks and a dictionary, together with many links are necessary to just use a 'global' parameter. I know you could theoretically set values in Matlab, but I want it accessible within Simulink/Simscape as that is where you work and simulate so it is just inconvenient to have multiple places that manage one model.
If anyone knows how to do this better please let me know.
  5 件のコメント
Paul Hermens
Paul Hermens 約17時間 前
A workspace variable is basically what my workaround is right? But if possible I don't want to have to add manually a workspace variable if it can be set global in simscape/simulink without needing to do it manually. For me it is not that much of a problem but if other people will work with this in the future, this could be rather unpleasant and straight up confusing. You would literally need to make a full manual then either for setting workspace variabl(s) and or fully replacing the gas domain like your second approach.
I think I currently use the simulink model workspace but you can't set anything without manually defining it first if I am correct... Which again comes down to struggles that aren't necessary in my opinion. If I could use a simulink memory block that would be way easier and could be put into one of the custom subsystems.
But I think then, the anwer is my way is already the best way unless I want everyone else who would use it to completely change their foundation gas library. Which would then be even harder if you want to update it as you can't really sync that in any way.
Yifeng Tang
Yifeng Tang 約11時間 前
It's easy to define a "Model Workspace" variable as part of your model. Whenever the model is opened, it's available to every block in the model, but not visible in MATLAB base workspace. This variable can have its value defined as part of the model, or using a script embedded in the model (so you can do some calculation instead of just a value). See this page: https://www.mathworks.com/help/simulink/ug/specify-source-for-data-in-model-workspace.html
Basically you define it once in the model, and it's available ... forever. Will this work?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeGas Models についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by