How can I connect two seperate Simulink models?

I have two Simulink models (Matlab 7.11 and Matlab 6.5) and I want them co-simulate. There is no way in merging them in one Matlab version (given boundary condition). A brief desription of the situation I want to create: model one gets an initialization vector, does some calculations, give the results to model 2 and waits. The latter model waits until it gets the data from model 1, does some calculation as well, gives the solutions back to model one and so on. This should be repeated for every time step. Both Matlab applications will run on the same machine. I have no idea how to realize this. I tried something with UDP, but I found out there are no UDP toolboxes in Matlab 6.5. I don't know how to make the models wait for each other. I hope someone will have some inspiring ideas for me :)
Thank you in advance! :)

Risposte (2)

Kaustubha Govind
Kaustubha Govind il 25 Ott 2012
Why not use the Model block to reference each model? You can connect them in a third top-level model.

3 Commenti

Hmm, is it possible to use Model blocks although one of the models is running in Matlab 6.5 and the other one in Matlab 7.11?
No, but can you not load the model from 6.5 in 7.1?
No, unfortunately not :( (I described the problem, that I can't convert the different model versions in the second answer thread in more detail)

Accedi per commentare.

Azzi Abdelmalek
Azzi Abdelmalek il 26 Ott 2012
Modificato: Azzi Abdelmalek il 26 Ott 2012
Use two scripts in each session of matlab. for example script1
x=load('comunicat')
if x.test==1
sim('model1')
test=0
save cmunicat test
end
while test==0
pause(10)
x=load('comunicat')
test=x.test
end
%
sim('model1') %
...
use the same with script2. The mat file comunicat contain one logical variable. It says which model will run

12 Commenti

I'm not sure if I completely understand your answer. How can I only do one timestep in each model before changing the model and then repeat the whole thing, say like 1000 times?
  • suppose ts is your sample time, set time simulation to ts
  • lunch your two m files in your 2 sessions
  • in file1
test=0
for k=1:1000
while test==0
pause(10)
x=load('comunicat')
%file 1 waits until test=1(when file2 finishs simulation)
test=x.test
end
sim('model1') % use data from model 2, load file or...
test=0
save comunicat test % will trigger model 2
end
Now I got it. Thanks :)
But there is still one problem: I'm not allowed to start Model1 over and over again. It has to be paused after every timestep, send its data to model2, get the results back and resume its calculations with the new values. Is it possible to realize that with something like the following?:
sample_time=0.02;
for sample=1:1000
while test==0
pause(10)
x=load('comunicat')
test=x.test
end
sim('model1',sample*sample_time)
test=0
save comunicat test
end
And another question: what is the purpose of pause(10)?
pause(10)
% will wait 10 secondes before checking a mat file
Azzi Abdelmalek
Azzi Abdelmalek il 26 Ott 2012
Modificato: Azzi Abdelmalek il 26 Ott 2012
But the question is, why make it dificcult when you can work with one model using 2 triggered subsystems
Stefan
Stefan il 26 Ott 2012
Modificato: Stefan il 26 Ott 2012
Yeah, I know that pause will wait a certain amount of time, but do I have to wait? This will strecht the duration of the whole simulation.
I think the problem with two triggered subsystems is that one model is Matlab 6.5, the other one 7.11. Maybe you have any idea to connect and synchronize both?
you can convert your model(matlab 6.5) to (matlab 7.11), have you tried to do it?
Unfortunately that's no option in my case. The model(Matlab 6.5) is too complex to convert it.
Just open it under matlab 7.11, If you've tried to do it, is there error messages
@Azzi Of course I've tried to open it in Matlab 7.11 and there are a lots of error messages. The model is working with .dll-files instead of S-functions. Most of the code behind the model is written for Matlab 6.5 and it would take way too long to convert every single part.
@Lucas Unfortunately Matlab won't do all the work. It's a very complex model, so let's just say it's a given condition to use the model in Matlab 6.5 ;)
Stefan
Stefan il 26 Ott 2012
Modificato: Stefan il 26 Ott 2012
I really thought about converting the model(6.5) and the DLLs&stuff, respectively. But it's just not possible. Even if I would invest the time and go through all the code to convert everything, what needs to be convertet, I don't have the possibility to verify the model. It's already verified in 6.5. So, no converting ;) It's the same with "downgrading" the other model. To make a long story short, because I can't convert the models in either way, I have to build some sort of communication and synchronization between them. I already tried some small-scale test with the code proposed by Azzi above. The problem is, that if I paste a time value smaller than .5 in the pause command, there is an error message
??? Error using ==> load
Unable to read MAT file comunicat.mat: not a binary MAT file.
Try LOAD -ASCII to read as text.
But I can't simulate with a pause duration of 1s for every loop. This would lead to a whole simulations duration of 5.5 hours, just for one run! I guess the error message has something to do with the correct synchronization. Any idea how to deal with that?
Haven't thought about using s-functions yet. Don't know much about them. I will look into it. Thank you for the hint! :)

Accedi per commentare.

Categorie

Scopri di più su Test Model Components in Centro assistenza e File Exchange

Prodotti

Richiesto:

il 25 Ott 2012

Community Treasure Hunt

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

Start Hunting!

Translated by