Parse String Data ROS topic in Simulink

3 visualizzazioni (ultimi 30 giorni)
marcusbarnet il 21 Mar 2018
Risposto: Sebastian Castro il 14 Ago 2018
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:
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 Commento
marcusbarnet il 22 Mar 2018
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);
External Current Sensor %%%
curr_sensors_time = io_data(:,1) - io_data(1,1);
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;
cuurent_sensor_data = [curr_sensors_time, curr_sensors(:,1), curr_sensors(:,2)];
I can't use it inside Simulink, unfortunately.

Accedi per commentare.

Risposte (1)

Sebastian Castro
Sebastian Castro il 14 Ago 2018
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

Community Treasure Hunt

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

Start Hunting!

Translated by