Simulink Subsystems
2 次查看(过去 30 天)
显示 更早的评论
At present I am working on a Simulation Model containing 2 subsystems in Matlab Simulink: • Subsystem A – generates some data • Subsystem B – reads the generated data from the workspace
Right now each subsystem is in a different Simulink file. I would run Subsystem A first. This data would be saved to the workspace and then I would run Subsystem B which reads the data from the workspace.
I would like to put these two models together in one simulation window. However the problem is that each model runs at a different simulation time. And in order to read the data form the workspace the first simulation must first stop and the variables sent to the workspace.
Is there any way to stop the simulation for the Subsystem A, therefore sending the variables to the workspace. And then Subsystem B would be executed to read from the workspace.
I tried using the trigger and enable blocks but because the simulation does not stop and send the variables to the workspace before Subsystem B is activated, Subsystem B is unable to read the data generated by Subsystem A. I have done some research and it shows that simulation must stop in order to be able to read from the workspace.
Is it therefore possible to have these two subsystems in one file sharing the same space? I would like Subsystem A simulation to start and stop, therefore sending the variable to the workspace and Subsystem B is activated automatically after the variables were sent to the workspace.
Please remember that: • Subsystem B needs the variables generated by Subsystem A • Subsystem B reads from the workspace • Both subsystems have different simulation stop times • Subsystem A must stop first in order to send the variables the workspace
Thank you for any assistance.
0 个评论
回答(3 个)
Fangjun Jiang
2011-7-13
You probably need to explain why is the constrain that Subsystem A needs to be finished before Subsystem B can run. Currently you run them in two separate files. Let's say Subsystem A runs simulation for 10 seconds. So all the data outputs are from 0 to 10. You then run Subsystem B using that data. Time starts from 0 so they match.
Let's say you can run the two Subsystems in one file like you wanted. At time t=10 seconds, you can pause the simulation, log the data to workspace and then continue simulation reading that data back. But the simulation clock stars at t=10 now, the time stamp for the data is 0 from 10. They don't align.
Do you not care about the timing of the data? Do you just want to use Subsystem A to generate the data? What is wrong if you connect two subsystems together and run simulation simultaneously? Maybe you need to use the whole history data of Subsystem A to run Subsystem B.
Again, explain a little bit more about your use case. There might be a better way to do it.
Sreeram Mohan
2011-7-14
In the same lines one could also explore the possibility to use the Simulink Variant Subsystems feature that allows to switch active subsystems based on the condition specified on the base workspace, if the intention is to simulate the subsystems by having them in the same model and as nirmal suggested after this go ahead and use the matlab commands (sim 'start', 'stop' ) to switch the subsystems.
But having said that variant subsystems are available only in the recent releases.
Another option is to have both the models that the user has as variants to a model block and swicth over the active variant and simulate. In that way the control is from the same model but the individual choices live as you have them now (two different models with each a subsystem).
Hope this helps !
--sreeram
0 个评论
Nirmal Gunaseelan
2011-7-13
I cannot think of a way to stop simulation of one part of a Simulink model while the other is running - doesn't seem to follow model based design principles that I'm aware of.
One possible solution for your purpose is to continue to have subsystems A and B in separate models with their start and stop times set. Then, control simulation of these subsystems using Simulink MATLAB API - there are many such as SIM, MODEL etc. that let you do this from a script. So once you run the script,
- Run model A
- Stop model A - will write outputs to workspace
- Check for availability of variables in workspace
- Run model B
This approach is still fully automated, except that you launch a MATLAB script instead of simulating 'a model' directly.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!