Robotics StackExchange | Archived questions

What is the best way to use a text file listing topics to filter a rosbag

I want to play a rosbag with hundreds of recorded topics

This ros bag is intended to test a node I am working on but the person who recorded it also included topics such as the ones my node is supposed to publish. I want to filter-out a list of specific topics.

I would like to avoid techniques involving creating another ros bag from my existing bag and removing the topics in this way. The reason is I am planning on using this in a build engine (Bazel) and it will be more convenient to have only rosbag and filter the playback as I please.

I would like to use a list of topics as a text file (it could be plain text or something like yaml).

I would like the playback to be started from a launch file.

I am looking for something like this:

<launch>
   <node 
     pkg="rosbag" 
     name="play" 
     type="play" 
     args= --bags $(find test_package)/mybag.bag --topics=$(read-from-file file.yaml) />
</launch>

Asked by epapillon on 2020-11-24 17:45:11 UTC

Comments

Answers

Afaik this is not supported by rosbag.

If you don't want to extend rosbag's functionality (ie: contribute reading a list of topics from a file), then I believe you can achieve what you are asking for by combining roslaunch's support for args and current rosbag functionality.

args can be set from the command line, so if you have a plain text file (no need for YAML I believe) with the list of topics on a single line, we can pass its contents as the value for a roslaunch arg, which finally gets passed on to rosbag play.

You could perhaps do something like this:

<launch>
   <arg name="list_of_topics" doc="A space-separated list of topics to play, single line" />
   <node 
     pkg="rosbag" 
     name="play" 
     type="play" 
     args="--bags $(find test_package)/mybag.bag --topics=$(arg list_of_topics)" />
</launch>

You would then invoke roslaunch as follows:

roslaunch your_pkg rosbag_wrapper.launch list_of_topics:="$(cat /path/to/topic_list.txt)"

Alternatively write a small Python script (or whichever language you prefer), which takes in a .yaml and spits out a single line of space separated topic names. You would then do something like:

roslaunch your_pkg rosbag_wrapper.launch list_of_topics:="$(your_utility.py /path/to/topic_list.yaml)"

that should result again in list_of_topics to be set to the list of topics, which is then passed to rosbag.

Note: I've not checked whether there are extra quotes needed around the value passed to --topics. That would be something to verify.

Asked by gvdhoorn on 2020-11-25 04:34:09 UTC

Comments

A related issue on ros_comm's tracker would be ros/ros_comm#81. It asks for being able to specify the list of topics to record by using a file, but that seems very similar to what you describe.

No one has picked that up though (and the issue is from 2013 (and actually older, probably around 2010, as it comes from the old Trac issue tracker)).

Asked by gvdhoorn on 2020-11-25 04:35:56 UTC