How to get the variables bound to block parameters for custom mask subsystem blocks in Simulink?

6 次查看(过去 30 天)
Hello,
I work on a software product built on top of simulink models. Our software fetches data from compiled simulink models using the "CompiledModel" data structure, generated in the .rtw file. We need to retrieve the information of which MATLAB variables are bound to which block parameters for our software.
When binding simple blocks like gain and constant to MATLAB variables, we can easily retrieve that information in the .rtw file, e.g.:
Parameter {
Identifier "vTwo"
LogicalSrc P1
WorkspaceVarName "vTwo"
Protected no
Value SLData(1)
ContainerCGTypeIdx 25
IsGlobal 1
ReferencedBy Matrix(1,4)
[[0, -1, 8, 7];]
GraphicalRef Matrix(1,2)
[[4, 9];]
GraphicalSource [-1, -1]
OwnerSysIdx [0, -1]
VarGroupIdx [2, 1]
WasAccessedAsVariable 1
}
However when binding a MATLAB variable to a block that has a custom mask, the information of which MATLAB variables are bound to parameters of that block are lost. Instead we find in the .rtw file the direct value of the variable. For instance if I use the MOSFET block (official MATLAB block) and bind all of its parameters with different variables as such:
The resulting .rtw file I get from rtwbuild is attached to this post. The only reference to the variables (aVar, bVar, etc.) are in that section:
CollapsedTunableParameters ["aVar", "bVar", "cVar", "dVar", "eVar", "fVar", "gVar"]
GlobalParamsList ["aVar", "bVar", "cVar", "dVar", "eVar", "fVar", "gVar"]
But they are never found elsewhere in the parameter data, so there is no way to know which parameter is bound to which MATLAB variable.
If instead I look for values of the variables, I do find them throughout the file:
SFcnParamSettings {
Ts 2.0e-5
NStates 1
NSwitch 2
NInputs 3
NOutputs 2
Rsw [0.123, 0.345]
SwitchType [1.0, 3.0]
Giv [0.0, 0.0]
I_MeasIdxs [0.0, 0.0]
}
(0.123 is aVar, 0.345 is cVar)
My question is, is there a way to retrieve that MATLAB Variable to Block Parameter mapping information? If that data is completely unretrievable from the CompiledModel data, is there an alternative way to find that data?
Thank you,
Alexander Winter @ OPAL-RT Technologies

回答(1 个)

Aastha
Aastha 2024-10-8
Hi Alexander,
I understand that you want to retrieve the parameters associated with Simulink blocks. To do this, you can use the “get_param” function in MATLAB.
I have assumed that you have set the parameters of a MOSFET block using workspace variables. You can use the “get_param” function to determine the variable names associated with these parameters.
Kindly refer to the example given below to retrieve parameters associated with Simulink blocks:
1. Initialize the workspace variables “aVar”, “bVar”, “cVar”, “dVar” and “eVar” to 1. This can be done using the MATLAB code given below:
aVar = 1;
bVar = 1;
cVar = 1;
dVar = 1;
eVar = 1;
2. Load the Simulink model “example” into memory using the "load_system" function in MATLAB.
load_system('example');
Kindly refer to following MathWorks documentation of “load_system” function for more information:
3. You can find all the block paths in the Simulink model “example” and store it in the variable “blocks” using the "find_system" function in MATLAB.   
blocks = find_system('example');
You may refer to the documentation link of “find_system” function for more information:
4. Subsequently, the “blocks” variable is used as input to the "get_param" function in MATLAB which retrieves the value of the parameter “Rd” for the second block ‘blocks{2}’ in the model.
params = get_param(blocks{2}, 'Rd');
For any further information on “get_param” function, kindly refer to the link of MathWorks documentation mentioned below:
I hope this helps!

类别

Help CenterFile Exchange 中查找有关 Interactive Model Editing 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by