How to get an array from a Rosbag

조회 수: 2 (최근 30일)
Paolino De Risi
Paolino De Risi 2021년 9월 16일
댓글: Cam Salzberger 2021년 9월 17일
Hi, I'm trying to plot a data from a rosbag, here what i did until now:
bag=rosbag('/home/paolino/bagfiles/subset.bag');
wh_gaz=select(bag,'Topic','/joint_states');
wh_gazStruct=readMessages(wh_gaz,'DataFormat','struct');
This struct is a 19153x1 cell and each element is a 1x1 struct with a velocity record, a 2x1 array.
Now, what i need is to create 1 column array with each wh_gazStruct.Velocity first element, but I can't find a solution. Until now I tryed:
wh_gaz_mat=cellfun(@(m) double(m.Velocity),wh_gazStruct);
but since the .Velocity record has two elements it doesn't work. How may I solve my problem?

답변 (1개)

Cam Salzberger
Cam Salzberger 2021년 9월 16일
I provided some guidance and sample code to a similar question here. That should help get you moving in the right direction!
-Cam
  댓글 수: 2
Paolino De Risi
Paolino De Risi 2021년 9월 17일
편집: Paolino De Risi 2021년 9월 17일
It doesn't work for me, in my case the record .Velocity has two elements inside since it is a float64 array with two elements. they are not indexed as subrecords as in the following image:
This seems not work:
function [wh1, wh2] = getwheelsvelocities(msg)
% Extract internal message first for efficiency
% (matters more for more nested messages)
wh_vect = msg.Velocity(1);
wh_vect1=msg.Velocity(2);
wh1 = wh_vect;
wh2 = wh_vect1;
end
Cam Salzberger
Cam Salzberger 2021년 9월 17일
Well, I don't know exactly what your messages look like. But if I set up my messages like this (to simulate using readMessages with DataFormat='struct'):
msg = rosmessage('sensor_msgs/JointState', 'DataFormat', 'struct');
n = 4;
msgs = cell(n, 1);
for k = 1:n
msgs{k} = msg;
msgs{k}.Velocity = [k ; -k];
end
Then I can do this:
[wh1, wh2] = cellfun(@getwheelsvelocities, msgs);
with your code as-provided, and it works just fine.
If you have any messages that do not have two entries in the Velocity field, then this code will fail.
-Cam

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 ROS Log Files and Transformations에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by