Modifying parameters for S-function in a model which is compiled / run in rapid accelerator mode

2 Ansichten (letzte 30 Tage)
I have a model which includes an S-function block. The model has all the necessary parameter on the model workspace. A function calls the model and runs it with different parameter sets, which works just fine in normal simulation mode, the parameters influence the initial state of the S-function .
However I want to create an exe from the model, so I'm using configureForDeployment before running the simulation. The problem is that in this case the initial state of my S-function is always the same, which refers to the values of the parameters available on the model workspace during building the rapid accelerator target. Same thing happens when I use mcc. Parameters for other blocks get updated normally.
My code is similar to (inside a for cycle):
in = Simulink.SimulationInput('MyModel');
in = in.setVariable('MyParam', MyParam, 'Workspace', in.ModelName);
in = simulink.compiler.configureForDeployment(in);
simRes = sim( in );
How can I modify the S-function parameters between simulation runs in a compiled model / in rapid accelerator mode? Thanks for the help!

Antworten (1)

Fangjun Jiang
Fangjun Jiang am 11 Sep. 2020
Before the configureForDeployment line, use set_param('S_Function_Block','Param_Name','Param_Value') to change the parameter for the S-function block. This might make the model dirty (the model has been modified) so you might also have to save the model before you can run configureForDeployment.
  3 Kommentare
Fangjun Jiang
Fangjun Jiang am 14 Sep. 2020
  1. It depends on the parameter data type to use 'Param_Value' or MySFunParameterValues
  2. The model needs to be re-build after setting the S-Function parameters, which is said in your original question. Why did you comment above that "the model is already built"?
  3. You might also need to run the callback functions of the S-function after you change the S-function parameters. It depends on your S-function.
Iván Miljanovits
Iván Miljanovits am 22 Sep. 2020
2. I do not want to re-build the model for every parameter set. At the very first simulation the .exe is built in the 'raccel' folder, then I want to re-use it basically with different parameters.
3.There are no callback functions defined in the properties of the S-function block.
I managed to run the model correctly in Rapid Accelerator mode in R2018b. When I included the C-sources in the the same folder, after building the rtp the simulation provided different results for different S-function parameters (OK). When I included only the mex64 file, the results were same for any parameter-set (not OK).
I used:
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
parameterSet1 = Simulink.BlockDiagram.modifyTunableParameters(rtp,'MyParam1',6);
out = sim(mdl,'SimulationMode','rapid', 'RapidAcceleratorUpToDateCheck','off', 'RapidAcceleratorParameterSets',parameterSet1);
In R2020a the same method did not work, as if I did not include the mex64 file in the folder, it threw an error, even if the C-source was there.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Deploy Standalone Applications finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by