Parse String Data ROS topic in Simulink
显示 更早的评论
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!

回答(1 个)
Sebastian Castro
2018-8-14
If you pass in the signal "Msg", it will appear in the MATLAB Function block as a structure. For example, you should be able to do:
function readMyData(msg)
numElements = msg.Data_SL_Info.ReceivedLength;
for idx = 1:numElements
some_value = msg.Data(idx);
% ... and then you do something with these values
end
end
类别
在 帮助中心 和 File Exchange 中查找有关 String 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!