Parse String Data ROS topic in Simulink

2 次查看(过去 30 天)
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 个评论
marcusbarnet
marcusbarnet 2018-3-22
Is it possible to call a Matlab function to load the data?
In my Matlab, I use this code to obtain the same data:
bagselect_io = select(bag, 'Topic', '/robo/io');
readMsg_io = readMessages(bagselect_io);
io_data = zeros(size(readMsg_io,1),32);
for i = 1:size(readMsg_io,1)
C = strsplit(readMsg_io{i,1}.Data,',');
io_data(i,:) = str2double(C);
end
External Current Sensor %%%
curr_sensors_time = io_data(:,1) - io_data(1,1);
curr_sensors_time(elements:end,:,:)=[];
currTmp = io_data(:,6:7) - 2410; % current data from the external sensors
currTmp = [ currTmp(:,1), currTmp(:,2); ];
curr_sensors = -(currTmp)*(300/5000)*0.5*0.92;
curr_sensors(elements:end,:,:)=[];
cuurent_sensor_data = [curr_sensors_time, curr_sensors(:,1), curr_sensors(:,2)];
I can't use it inside Simulink, unfortunately.

请先登录,再进行评论。

回答(1 个)

Sebastian Castro
Sebastian Castro 2018-8-14
You can use a MATLAB Function block to read the message.
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

类别

Help CenterFile Exchange 中查找有关 String 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by