Synchronizing 2 Simulink Models on 2 different machines via UDP
Show older comments
Hi, I'm trying to sinchronize 2 simulink models in 2 different machines to divide the work load of each. So far this is a test and my model is a simple mass, damper, spring moving only on the x-asis connected to a PID controller. I change the reference point with a joystick and visualize via VR Sink. Everything works fine if ran in one machine.
So what I did was divide the model so I put the PID controller in one machine, and the Plant with the physics in another machine and connected the models via UDP. If I start the models at the same time (by clicking the run button on both machines at the same time) the model works excellent with what appears to be zero delay.
The problem arises when I start the model in one machine first, and then, few seconds later I start the other. If I do this, the mass behaves like it's on crack and flyes everywhere. I believe this is because there is old data stored in some type of buffer somewhere and the model that starts late gets old data feed to it and it never schincronizes again; however I am not sure of this because in theory UDP is a best effort protocol and old data should be disregarded, right?
Anyways, some more useful information:
Ran on Matlab 2012a.
The model is compiled as a "Real-time windows target" and I use the Analog Input to get data from the joystick and Package output/Input to send/receive UDP data between machines.
From one machine I send the output from the PID controller and the other sends position data from the Physics Plant, so both computers send data to the other.
I did the experiment using a simple wireless router, and also tried Wireless Ad-Hoc connection to make sure the router wasn't causing the problem.
I appreciate any help given. Thanks!
3 Comments
Jan Houska
on 16 Jul 2012
This is not necessarily UDP packet sequence problem. The PID controller is not stateless (has internal states), and if it is started before the plant, it attempts to control the not-yet-running plant. This may set its internal states to values that are not acceptable when the plant is finally connected.
Please see Integral windup for explanation - except that in your case it may be the invalid input value from the not-yet-running plant what is causing the overshooting in the integral term.
venkadesan
on 1 Aug 2014
Accepted Answer
More Answers (2)
Walter Roberson
on 14 Jul 2012
0 votes
Data that manages to make its way between systems, and is matched to an open socket, is not discarded in UDP, not unless the receiving system requests discarding.
UDP packets that are received at a system that has no socket for them should be discarded by that system. But since there is no particular length of time defined for delivery, the packets could in theory be "in transit" for an undetermined amount of time. Your application needs to be able to detect and disregard "old" packets... even in cases where "old" turns out just to be "out of order" (a newer packet was received before an older one.)
7 Comments
Xenoepist
on 14 Jul 2012
Walter Roberson
on 14 Jul 2012
The socket is created by the application, but if you are using fixed source and destination ports then you need to have a way of determining that packets are not from a previous run of the program.
It doesn't really matter where the old packets get queued: you have a problem no matter where the queuing is occurring.
You need to solve some problems:
- ensuring that you ignore packets from "old" conversations
- a mechanism to allow a "new" conversation to be started no matter which program state you are in (because the other end might get reset for example). This mechanism must not rely on single packets in either direction, as those single packets might get lost
- a mechanism to detect that packets have been received out of order so you can ignore the extra ones
- position information transfered must not be relative, as relative positioning depends upon every packet getting through
- udp does not have an inherent timeout, so you need to implement your own mechanism to re-request data or acknowledgment. When you do that, keep in mind that the other end might be sending the information (and re-sending as needed) but the packets might not be getting received (there can be failures that affect only one direction of a link)
Unfortunately as you try to solve these things, you will find that you are nearly re-inventing TCP.
Xenoepist
on 15 Jul 2012
Walter Roberson
on 15 Jul 2012
When you are using "udp", the receiving computer has no way of knowing which packets are "old" and which packets are "new". udp does not reorder packets in the receive buffer. If packets get out of order somehow, they likely will stay out of order.
Note: a timestamp should be considered to be just a variety of packet sequence number unless the clocks of the two devices are synchronized. Also, watch out for the resolution of the timestamp mechanism: depending exactly which mechanism you use to timestamp, you might get the same timestamp for several packets in quick succession (the computer often runs faster than the timestamp updates.)
Xenoepist
on 16 Jul 2012
Xenoepist
on 18 Jul 2012
Walter Roberson
on 7 Aug 2019
https://en.wikipedia.org/wiki/Precision_Time_Protocol PTP is a possible option for synchronizing local computers.
K E
on 16 Jul 2012
0 votes
A workaround to your original problem might be to run your Simulink model with the Parallel Computing toolbox one just one machine so that Simulink runs faster, but you do not need both machines. Here are some tips on faster Simulink execution. If I have misunderstood your problem, sorry.
3 Comments
Xenoepist
on 17 Jul 2012
saiful azrie
on 6 Aug 2019
i did the same project, but i cannot find the problem like u before. can i know how to perform the problem?
Sree
on 12 Apr 2021
@Xenoepist, Could you please let me know how you have solved the problem?
Categories
Find more on Target Computer Setup in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!