Simulink/S​imscapeMul​tibody, using UDP in parallel, without blocking a simulation?

6 views (last 30 days)
Dear fellow Matlab users
I am creating a model in Simscape Multibody trying to simulte close to realtime. For communicating with a c++ application I am using a udp receive and send block.
The problem is that the udp blocks tend to slow down the simulation drastically. The good thing is they are not necessary for the simulation to function, they are only needed to transfer the data. So from the architecture side is absolutely possible to provide the data with the simscape simulation and transfer them in a separate thread with udp.
The question is now, how do I implement a parallel udp communication in Matlab Simulink? is it possible to deploy some data in a global space and transfer them with a separate udp communication block? can I run both in parallel in one simulation ?
I am asking because it is really hard to find some usefull information on this and I have to say I am a bit frustrated on the general topic of parallelism in Matlab. But maybe it is just that I did not fully get it yet, so I would be glad of any help on the topic.
Thank you for you time
kind regards

Answers (1)

Vasco Lenzi
Vasco Lenzi on 11 Nov 2020
I'm not sure you can because of the nature of the UDB block, but you can try follow this workflow:
if you have good knowledge with C++ you can implement a shared memory block in C++ that writes directly to the C++ application, there is a similar example here:
hope this helps
Vasco
  2 Comments
David Brodmann
David Brodmann on 11 Nov 2020
Dear Vasco
Thank you very much for the response, I will definitely try it out. The shared memmory block sounds really interesting, the project you linked seems to be written in C# though ? but I will research the shared memmory workflow. I am not sure the concurrent execution really works though, the experiences with Simscape Multibody and concurrent calculations are not the best to be honest.
Thank you very much for the reply.
Vasco Lenzi
Vasco Lenzi on 11 Nov 2020
Yes the project is in C# unfortunately, but I thought it could serves as an inspiration.
You can write and/or embed native C++ in Simulink:
You could create a custom way of communicating through some shared memory.

Sign in to comment.

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!