How to parse String in Simulink/MATLAB and ROS
Hi to all,
I would like to be able to read my /mobile_robot/io topic which has this output:
data: 1517480481.375425333,0,0,0,0,1514,3307,0,0,0,0,0,0,0,0,0,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,6629
---
data: 1517480481.476979162,0,0,0,0,1032,3571,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,6630
---
data: 1517480481.574876785,0,0,0,0,288,3308,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,0,0,0,0,0,0,0,0,6631
---
data: 1517480481.674732409,0,0,0,0,4914,3268,0,0,0,0,0,0,0,0,0,1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,6632
I would like to read the first value which is the timestamp and the values placed at *positions 6 and 7.* The message type is String and I'm not able to correctly parse the output of this node.
I created the subscription block in Simulink and then I added the BUS Selector with three outputs:
Data
Data_SL_Info.CurrentLength
Data_SL_Info.ReceivedLength
What kind of block or function do I need to use in order to be able to read the timestamp and values at 6 and 7 columns?
I hope you can help me!
This is not an answer, but a question: why are you using a string for this, and not a properly structured message with properly typed fields?
Unfortunately, this node is old and when I developed it I didn't considered to use a structured message. I recorded several bags and now I can't run the tests again so I need to find a way to parse these strings in simulink.
I would say this is purely a Simulink question/issue then. Simulink should provide you with the blocks needed to cut-up string 'signals'.
I would suggest to try the Mathworks fora.
I know in Matlab, you can use textscan (if I am understanding correctly, what you want to do). For Simulink, I am not sure about its equivalent
Unfortunately, it gives me this error:
Function 'textscan' is not supported for code generation. Consider adding coder.extrinsic('textscan') at the top of the function to bypass code generation.
It seems the function is not supported by SimulinkYou'll have to use the correct function blocks to split the string. Or at least, that will probably be the most straightforward way to do it.
An alternative could be to post-process your bag to split your msg up, but that may be to involved.
Thank you for your support! Is there any tutorial I can read to understand how to split the string in Simulink?
This is not a Mathworks support forum, but a ROS one. I would refer you to the Mathworks Matlab / Simulink documentation and / or their support fora.