필터 지우기
필터 지우기

Simulink Subsystems

조회 수: 7 (최근 30일)
Simone Leon
Simone Leon 2011년 7월 13일
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.

답변 (3개)

Fangjun Jiang
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.
  댓글 수: 1
Simone Leon
Simone Leon 2011년 9월 1일
If i connect the two subsystems togther and run the simulation simultaneously it would not work tus producing an error.
In order for Subsystem B to be simulated, it needs the variables from the workspace for Subsystem A.

댓글을 달려면 로그인하십시오.


Sreeram Mohan
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

Nirmal Gunaseelan
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,
  1. Run model A
  2. Stop model A - will write outputs to workspace
  3. Check for availability of variables in workspace
  4. Run model B
This approach is still fully automated, except that you launch a MATLAB script instead of simulating 'a model' directly.

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by