Issue with MATLAB rosbag, can't select topics

2 visualizaciones (últimos 30 días)
Marc Carmichael
Marc Carmichael el 15 de Jun. de 2018
Respondida: Antun Ivanovic el 4 de Abr. de 2020
I have a ROS bag that I can load into MATLAB with the rosbag function, and I can read the data using the ReadMessages function, however I cannot select specific topics using the select function. For example:
bag_topic = select(bag,'Topic','wrench');
I have traced this to an issue with the leading slash in the topic names. When I collected the bag using ROS I did not specify the slash at the beginning of the topic. This still recorded fine and I could play it back in ROS. The issue seems to be when I try to select the specific topic by name, the function always adds a leading slash to the search term. This happens on line 687 of BagSelection.m
% Add leading slashes to the topic names (if they don't exist)
select.Topic = cellfun(@(x) robotics.ros.internal.NetworkIntrospection.addLeadingSlash(x), ...
select.Topic, 'UniformOutput', false);
Does anyone know of workarounds? Ideally this will be fixed in the future.

Respuestas (1)

Antun Ivanovic
Antun Ivanovic el 4 de Abr. de 2020
I had the exact same problem as described. It turns out this sort of things happen when you record your data with rosbag command running in namespace. For some reason, the saved topics read by MATLAB are without slashes. There is a function at line 735 in NetworkInspection.m which adds leading slashes to every topic name and that is the reason it cannot find a topic without slash.
My workaround was to edit the NetworkInspection.m function called addLeadingSlash:
function slashedName = addLeadingSlash(name)
%addLeadingSlash Add a leading slash if the name does not have one
if ~strncmp(name, '/', 1)
%slashedName = ['/' name]; -> this one is original line that adds slashes
slashedName = name; % -> this is a replacement line
else
slashedName = name;
end
end
Path to this file on windows 10 and MATLAB R2018a was in my case ... MATLAB\R2018a\toolbox\robotics\ros\+robotics\+ros\+internal\NetworkInspection.m
To edit this file you might need to run MATLAB or a text editor as administrator on Windows.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by