Adding input for valid parameter in Simscape block

33 ビュー (過去 30 日間)
Florian
Florian 2025 年 2 月 17 日 16:29
コメント済み: Florian 2025 年 2 月 25 日 15:02
Hi all,
I have a question about Simscape blocks. Specifically, this question concerns the “The SI Combustion Cylinder” block.
I have already managed to create my own block that contains the same source code as the original block.
In the block, the gas constant R_air is entered as a “parameter”.
Now I want to define R_air as an “input”, as is done with the “Air-Fuel-Ratio” (AFR), for example. This way, I want to be able to read R_air via the Matlab workspace, as I do with other input values such as the speed or the intake manifold pressure.
When I adapt the program code in the same way as for the AFR, I have the problem that the following error appears when creating my own Simulink library:
“Error using ssc_build
Failed to generate 'UserBib_lib'
Caused by:
Invalid use of value 'R_air'. All entities referenced in this expression must be valid parameters.
• In UserBib.EngineSICombustionCylinderModified2 (line 297)”
In line 297, R_air is used for another formula.
How can I ensure that I can add values like “R_air” to the model via an input port?
I would be very happy to receive a reply.
Kind regards,
Florian
  2 件のコメント
Walter Roberson
Walter Roberson 2025 年 2 月 17 日 16:50
Getting R_air via From Workspace means that R_air would be a signal
But I am getting the hint from "In the block, the gas constant R_air is entered as a “parameter”. " that you are trying to use R_air as a parameter . Parameters are pure numeric objects, with no time components, and so are incompatible with signals
Florian
Florian 2025 年 2 月 18 日 7:14
Hello Walter,
thank you for your answer.
The author of the original “The SI Combustion Cylinder” block intended for this to be the case.
However, I do not intend to change R_air during a simulation run in Simscape. I just want a new R_air to be read in before each simulation run and then for the entire simulation.
And for that I planned to let R_air, just as it is the case with other inputs (Air-Fuel-Ratio), flow into the calculation via an input port. These input ports are connected to constant blocks that access variables from the Matlab workspace.

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

採用された回答

Yifeng Tang
Yifeng Tang 2025 年 2 月 24 日 20:17
I think it's possible. The Simscape code of this block is visible. You may find it in the Description tab of the block dialog box and click on the Source Code. You may save it as a .ssc file, modify the code and implement as a custom block or library block.
You may move "R_air" (line 49) from parameter section to the inputs section (around line 130), and that should give an input port for R_air. You may refer to the documentation on Simscape language syntax and how to use custom components in model:
But, be very careful about the implication of making R an input. For example, does this lead to creating energy out of nowhere? Go through all other equations that involves R (and the varaibles that calculated using R), to make sure.
  3 件のコメント
Yifeng Tang
Yifeng Tang 約20時間 前
If the goal is to use different R value in each run, with R remains a constant within each run, what you are doing sounds like the best approach. Making the R a modifiable parameter and change that parameter when you set up the run.
You may also benefit from setting up Simulink SimulationInput object to manage the runs. See documentation here: https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.html
Florian
Florian 約20時間 前
yes, the procedure has worked so far. Thanks for the link. I will take a look at the information.
Kind regards
Florian

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEngines & Motors についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by