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

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!

Respuestas (1)

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 comentarios

I think you cannot modify the parameters with set_param('S_Function_Block','Param_Name','Param_Value'), it provides an error to me.
I can use set_param('S_Function_Block','Parameters', MySFunParameterValues) after loading the model and then saving it, but still it does not have any effect, as the model is already built and the 'RapidAcceleratorUpToDateCheck' is set to 'off'.
Do you have any other solution? Thanks for the answer anyway!
  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.
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Block and Blockset Authoring en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 10 de Sept. de 2020

Comentada:

el 22 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by