How to parse String in Simulink/MATLAB and ROS

asked 2018-03-21 15:17:45 -0500

Marcus Barnet gravatar image

updated 2018-03-21 15:17:58 -0500

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!

image description

edit retag flag offensive close merge delete

Comments

1

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?

gvdhoorn gravatar image gvdhoorn  ( 2018-03-21 15:41:09 -0500 )edit

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.

Marcus Barnet gravatar image Marcus Barnet  ( 2018-03-21 15:44:50 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-21 15:47:49 -0500 )edit
1

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

nazir-ust gravatar image nazir-ust  ( 2018-03-21 22:49:16 -0500 )edit

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 Simulink

Marcus Barnet gravatar image Marcus Barnet  ( 2018-03-22 05:16:03 -0500 )edit
1

You'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.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-22 06:05:37 -0500 )edit

Thank you for your support! Is there any tutorial I can read to understand how to split the string in Simulink?

Marcus Barnet gravatar image Marcus Barnet  ( 2018-03-22 06:07:33 -0500 )edit

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.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-22 06:09:16 -0500 )edit