How to deploy simscape models with tunable block parameters?
6 views (last 30 days)
I have a simscape model that I wish to deploy with simulink complier to create a standalone application. The model contains blocks (specifically revolute joints) that I wish to be able to change properties when it is an executable without using matlab. I can change variables using 'setVariable', but this doesn't work for the block properties of interest. 'setBlockParameter' will change the desired properties but this seems to be incompatible with 'simulink.compiler.configureForDeployment' which won't let the model be rebuilt.
Sample code that doesn't work:
mdl = 'UR10_Motion_Driven_sim' ; % Name of simscape model generated when code is ran
in = Simulink.SimulationInput(mdl) ;
in = in.setVariable('t_max', params.t_max) ; % This is the simulation time and does update
in = in.setBlockParameter([mdl '/Payload'],'Mass','params.mp') ; % This does not update
in = simulink.compiler.configureForDeployment(in) ;
out = sim(in) ;
Without the 'setBlockParameter' command all runs well, but the block parameter is not updated. Is there a work around?
Guy Rouleau on 5 Oct 2020
It looks like you need to enable the display of Simscape run-tim parameter settings in blocks dialog, this cna be done fomr the Simscape preferences.
See this answer: https://www.mathworks.com/matlabcentral/answers/579204-how-to-modify-or-tune-simscape-tunable-parameters-at-simulation-run-time
Yuo can read more in the doc here: https://www.mathworks.com/help/releases/R2020b/physmod/simscape/run-time-parameters.html
Once you se the Mass property of your block to be run-time tunable, you will be able to use setVariable on it.