ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to filterout a type from a rosbag record?

asked 2021-04-22 13:52:09 -0600

Aleksander Bobiński gravatar image

I have on my hands a 18GiB rosbag that contains multiple topics of PointCloud2 type. From my experience those are the main contributors to the rosbags' size. After the bag is recorded I can use the following to throw away the PointCloud2 messages: rosbag filter big.bag small.bag "'PointCloud2' not in str(type(m))" but what flag to rosbag record should I use to not record them?

I know rosbag record -x but according to documentation that only works with regexes and my PointCloud2 topics have different names.

By default I use rosbag record -a since the PointCloud2 topics are only a fraction of what I want to record.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2021-04-23 18:17:12 -0600

Aleksander Bobiński gravatar image

Somewhat guided by gvdhoorn's answer I wrote the following shell wrapper around rosbag record.

unwanted_type=PointCloud2
unwanted_topics_as_regex_alternative=$(rostopic list --verbose | grep $unwanted_type | cut -d '[' -f 1 | cut -d '*' -f2- | sed -E 's/^ (.*) $/\1/g' | tr '\n' '|')
rosbag record -a -x "($unwanted_topics_as_regex_alternative)"
edit flag offensive delete link more

Comments

Nice idea to use rostopic in a shell script wrapper. Would rostopic list with rostopic type be less --verbose?

gvdhoorn gravatar image gvdhoorn  ( 2021-04-24 02:56:37 -0600 )edit

I think one would have to use a for loop since rostopic type does not accept multiple topic names as arguments. Maybe if rostopic type would accept topic names from stdin this could be done in one line without the cut tricks by piping from rostopic list to rostopic type to grep.

Aleksander Bobiński gravatar image Aleksander Bobiński  ( 2021-04-24 03:49:05 -0600 )edit

Maybe if rostopic type would accept topic names from stdin this could be done in one line without the cut tricks by piping from rostopic list to rostopic type to grep.

afaik, it does support that.

gvdhoorn gravatar image gvdhoorn  ( 2021-04-24 06:32:56 -0600 )edit

Are you sure? For me echo "/velodyne_points" | rostopic type results in: usage: rostopic type [-h] topic_or_field rostopic type: error: the following arguments are required: topic_or_field

Aleksander Bobiński gravatar image Aleksander Bobiński  ( 2021-04-24 07:51:29 -0600 )edit

You can do it with xargs: rostopic list | xargs -i rostopic type {}. But you don't really gain anything doing this I believe.

gvdhoorn gravatar image gvdhoorn  ( 2021-04-24 10:55:20 -0600 )edit
1

answered 2021-04-23 02:24:37 -0600

gvdhoorn gravatar image

I don't believe rosbag supports this directly. -x works with topic names, not types. -a will record everything.

You could take a look at the rosbag API, which would make this not too difficult (ie: retrieve a list of all recorded topics, prune those with a specific type), but that wouldn't prevent them from being recorded first. You'd be post-processing an already recorded .bag.

Another option (which would require some work): write a wrapper which uses the ROS Master API to get a list of all topics, filters them based on type, then spits out a list of topic names which don't carry msgs of that type and then you can pass those to rosbag record. This would prevent topics you're not interestd in from being recorded.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-04-22 13:52:09 -0600

Seen: 231 times

Last updated: Apr 23 '21