Adding input for valid parameter in Simscape block

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 Comments

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
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.

Sign in to comment.

 Accepted Answer

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 Comments

thank you for your reply.
I have already looked at the code.
I don't want to change R_air during the simulation. I want to bring different “R_air” into the calculation for several simulations in a row.
If I move R_air into the input section, I cannot create a separate Simscape block from the code or the ssc file with the command “ssc_build(namespace)”.
Matlab issues the following error message:
“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)”
Unfortunately, I have not yet solved the problem, but I have worked around it.
Various parameters are defined at the beginning of the code.
With the following command, I have achieved that R_air is visible and can be entered in the Simscape block and a variable from the Matlab workspace can now be accessed at this point:
parameters (Access=public, ExternalAccess=modify)
I have not been able to generate an input port, but I am able to use a different “R_air” for each simulation run.
Kind regards
Florian Bendel
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
yes, the procedure has worked so far. Thanks for the link. I will take a look at the information.
Kind regards
Florian

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023a

Asked:

on 17 Feb 2025

Commented:

on 25 Feb 2025

Community Treasure Hunt

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

Start Hunting!