rosbag filter using Python's any() in filter expression doesn't work?

asked 2018-09-20 02:37:38 -0500

moooeeeep gravatar image

updated 2018-09-20 02:46:24 -0500

I would like to include topics in my filtered bag that match any of the prefixes I provide in the filter expression. I'm trying to formulate this using Python's built-in any() function, like this:

rosbag filter old.bag new.bag "any(topic.startswith(x) for x in ('/tf', '/velodyne'))"

Apparantly this doesn't work, as I receive this error message:

Traceback (most recent call last):
  File "/opt/ros/kinetic/bin/rosbag", line 35, in <module>
    rosbag.rosbagmain()
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosbag/rosbag_main.py", line 896, in rosbagmain
    cmds[cmd](argv[2:])
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosbag/rosbag_main.py", line 350, in filter_cmd
    if filter_fn(topic, msg, t):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rosbag/rosbag_main.py", line 294, in eval_fn
    return eval(expr)
  File "<string>", line 1, in <module>
  File "<string>", line 1, in <genexpr>
NameError: global name 'topic' is not defined

Similar expression without the any() function work as expected, e.g.,

rosbag filter old.bag new.bag "topic.startswith('/tf') or topic.startswith('/velodyne')"

Can anyone reproduce this error? Is this filter expression too complicated?

edit retag flag offensive close merge delete