Data mismatch between ROS publisher and Simulink subscriber model

Illustration
Mason - 2021-04-05T11:26:23+00:00
Question: Data mismatch between ROS publisher and Simulink subscriber model

I'm publishing the data to ros subscriber in matlab and writng the published data and subscribed data to a file respectively. The problem is that the data is not accurate when comparing two files. I think the problem is in matlab to write the ros data to a file with as the ros publishes data in high speed.  

Expert Answer

Profile picture of John Williams John Williams answered . 2025-11-20

What is the difference between the two? What data is being stored (the whole ROS message, or an extracted data field from it)? Is it simply dropped messages that are published but apparently not seen by the subscriber?
 
If it is the latter, then I have a suspicion about what is happening. Simulink executes its simulation on a (typically) fixed timestep. Every timestep, the Subscriber block will output the most recently receive message, indicating if it is a new message or one that has been output before. If your publisher is sending data faster than Simulink is running its timesteps, it will not pick up every message. Even if MATLAB is running slower, if the network communication happens in such a way that two messages arrive during the same timestep in Simulink, only one will be output.
 
Commonly,  Simulink is used in feedback control systems or similar, where it needs the latest sensor or position data to determine the next action. From this point of view, always operating on the latest message received makes more sense than operating on all messages received in order. What are you planning on using the Subscriber in Simulink for though, that you require every message?


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!