Is is possible to programmatically play a Simulink model and measure its states?

一个人想着一个人 提交于 2020-01-02 08:17:23

问题


I am looking to set up a test set for an existing Simulink model. Ideally I could take full control of the model, explicitly stepping it and measuring the state of any signal on any bus in the model.

As might have been gleaned, this is the precursor of a unit testing system for the model. Being so, I can't really justify changing the model to suit the test, the test must accommodate the model as-is.

The furthest I've got so far is using load_model() to return a handle to the model. From there there seems to be a quite obscure set of functions for accessing the model. I can't see any that relate to accessing states and can't see any further commands that relate to accessing a loaded model.


回答1:


The easiest way is to use the Data Import/Export function within the Simulink Preferences.

Set the checkbox States and it will store every state of your system for every time step in your workspace, also when you pause the simulation or execute it step by step.

Be aware not to set Save simulation output as single object, in this case the access would be more complicated and you need to follow the instructions here.




回答2:


To add to the other answer, you probably want to check this page in the documentation: Control Simulation Using the set_param Command. Of interest are the following commands:

set_param(<model_name>, 'SimulationCommand', 'start')
set_param(<model_name>, 'SimulationCommand', 'pause')
set_param(<model_name>, 'SimulationCommand', 'WriteDataLogs')
set_param(<model_name>, 'SimulationCommand', 'continue')

Replace <model_name> by the path to your model file.



来源:https://stackoverflow.com/questions/19356707/is-is-possible-to-programmatically-play-a-simulink-model-and-measure-its-states

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!