Programatically test-run a model before RTW build
Afficher commentaires plus anciens
I am working on a script which sets up a few interfaces in a model and then builds it. Normally before running this script, I run my model for a few seconds to make sure there are no errors in the model itself. Since I am about to make this script available to a few others, I would like to automate this check. After searching here, I added a few variants of this code to my script:
try
eval([bdroot '([],[],[],''compile'')'])
SimRslt = get_param(ThisModel, 'SimulationStatus');
eval([bdroot '([],[],[],''term'')'])
catch
SimRslt = 'stopped';
end
if strcmp('stopped', SimRslt)
beep
msgbox(['Unable to compile this model due to a ' ...
'Simulink error. See the Matlab command window ' ...
'for information about the error.'], ...
'Model Error', 'error', 'modal')
return
end
This code caused two problems. First, my model ended up in strange locked-up states after running this script, and I had to type repeated commands to switch between "Compile" and "term" before it would free up.
Secondly, even after I removed this code, my model still seems somehow corrupted. Now after I build, the model's "SimulationStatus" is "stopped", but I still see "T=0.00" in the model's status bar as if its value would be "paused". To get out of this state, I have to send another "compile" command followed by a "term" command, because a "term" command alone gives me an error which says the model "must be compiled before it can be accessed programmatically". But how am I seeing "T=0.00" if it is not compiled?
I would appreciate any tips to fix my model, as well as suggestions for a better way to write my original script.
Réponse acceptée
Plus de réponses (4)
Kaustubha Govind
le 17 Avr 2012
Perhaps you can tell us exactly what error your model runs into that reproduces this behavior with the model appearing to be "paused"? Like TAB, I am unable to reproduce the behavior with a simple test. Also, there may not always be an error reported in the MATLAB command window, so it might be a good idea to capture the exception like so:
try
eval([bdroot '([],[],[],''compile'')'])
SimRslt = get_param(ThisModel, 'SimulationStatus');
eval([bdroot '([],[],[],''term'')'])
catch err
errorMsg = err.message;
SimRslt = 'stopped';
end
if strcmp('stopped', SimRslt)
beep
msgbox(['Unable to compile this model due to a ' ...
'Simulink error: ' errorMsg], ...
'Model Error', 'error', 'modal')
return
end
Jeremy
le 19 Avr 2012
2 commentaires
TAB
le 20 Avr 2012
Please see edited part in my answer.
Kaustubha Govind
le 20 Avr 2012
What do you see in the command window when you run:
eval([bdroot '([],[],[],''compile'')']);get_param(bdroot, 'SimulationStatus'),eval([bdroot '([],[],[],''term'')']);
Titus Edelhofer
le 20 Avr 2012
Hi,
without solving the problem (I guess) I would suggest to modify the code to
feval(ThisModel, [], [], [], 'compile');
and
feval(ThisModel, [], [], [], 'term');
Interesting. I often use the same construct without problems so far. Did you try to add the pause statement? That indeed might help to flush queues ...
Titus
2 commentaires
TAB
le 20 Avr 2012
Using pause() statement to introduce small delay works.
Titus Edelhofer
le 20 Avr 2012
Hi TAB, Jeremy had not yet answered if it works also for him, that was the reason I asked ...
Jeremy
le 20 Avr 2012
0 votes
Catégories
En savoir plus sur Simulink Environment Customization dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!