matlabtime-seriesrosbag

Loading a set of messages from rosbag into Matlab


I am curious if there's a better way to load information from ROS bag files into Matlab.

My current work flow is:

bag = rosbag(FILE_LOCATION)
bagSel = select(bag,'Topic','/mavros/imu/data')
X_imu_raw = timeseries(bagSel)
t_imu_angvel = X_imu_raw.Time - bag.StartTime
X_imu_angvel = X_immu_raw.Data(:,8:10) % indices of X,Y, and Z

When having to load a lot of different message sets this becomes very cumbersome. I'm not sure how to pull sets of messages from the timerseries, for example I can pull the angular velocity of just one axis by writing:

timeseries(bagSel,'AngularVelocity.X')

I would ideally like to write something like:

timeseries(bagSel,'AngularVelocity')

and pull all of the angular velocity messages from the topic (x,y, and z) but I'm not sure if it is possible nor how to do it?


Solution

  • I am assuming you are trying to get ROSBAG data into Matlab. In our experience with IMU messages we found the matlab toolbox very slow, so forked some existing code to develop something that works efficiently for us. It is a bit cumbersome, but once you add your own definitions, this code works super fast. We could process bags in 10secs which might have taken 10 mins with Matlab toolbox. Basically it is written in C++ with hard coded message definations and uses Matlab's mex module to convert directly to a .mat file. Hope you find it useful - https://github.com/neufieldrobotics/bag2mat