MATLAB Answers

0

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.

  댓글 수: 0

로그인 to comment.

답변 수: 1

Cam Salzberger 님의 답변 3 Jun 2019
 채택된 답변

Hello Pavan,
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?
-Cam

  댓글 수: 5

표시 이전 댓글 수: 2
Thanks Cam, Actually the entire model is running in external mode.The ros publisher is a python script and the subscriber is in matlab model.I need to receive all CAN messages.I tried changing the simulation sample time in config parameters and also in block parameters of subscribe block, but it didn't worked. There is an option in code generation of subscribe block to change the length of callback message queue. I changed it the value, and didn't got expected result.
Yeah, then that workaround won't do it for you. And the message queue option only applies if it is taking too long to process each message (such that a queue is building up). For Simulink models, the processing time is minimal. The issue is that the underlying subscriber is handling all the messages, but your model isn't looping fast enough to pick them all up. You could try to optimize your model to reduce the processing time that any given timestep takes?
Again, though, it may be that you may not need all your messages. Are you able to answer my earlier questions about the message contents, or is it proprietary information or something like that?
I have created a custom message type which gets data from CAN device, extract it and publish the required contents of data i.e, uint8, uint8[ ] and time values. The model and python script is running on raspberry pi and checked the publishing rate with command 'rostopic hz /data', the rate is varying between 835.00 hz.The simulation rate in config parameters is set as 0.001 and in subscribe block as 0.002 and when comparing the ros publisher data and the subscriber data, the data missing rate is nealy 2 to 3. Now I'm moving to implement the model with parallel computing toolbox, as an idea to increase the simulation rate and reduce the load on cpu by executing tasks in parallel.
Also please give me some inputs on how parallel computing can be integrated with simulink model that too in externel mode operation.

로그인 to comment.



Translated by