Parse String Data ROS topic in Simulink

조회 수: 1 (최근 30일)
marcusbarnet
marcusbarnet 2018년 3월 21일
답변: Sebastian Castro 2018년 8월 14일
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