Announcing grepros: grep for ROS bag files and live topics

Hi all,

I’d like to announce grepros - a command-line tool that I wrote for grepping ROS bags and live topics.

It works equally in ROS1 and ROS2; version is detected from environment. Requires ROS Python packages: rospy family in ROS1, rclpy in ROS2. Installation:

pip install grepros

You can search through ROS messages and match any message field value, by plain text or regular expression, regardless of field type. Or match specific fields in messages, or specific message types, or topics.

By default, matches are printed to console, like a combination of rostopic echo and grep, with matching values highlighted.

grepros latitude=59. | more

Screenshot

Additionally, matches can be written to a bagfile, or published to live topics. They can also be exported to a multitude of output formats: CSV, HTML, Parquet, Postgres, SQLite; and SQL schemas.

With exporting, grepros doubles as a useful bag conversion tool.


A few examples of use:

  • Grep live topics to see if all lidars are publishing data:
    grepros --live --topic */lidar*/data --max-per-topic 1 --lines-per-message 10
  • Print and publish all nav messages in “antenna” frame, auto-indexing any unindexed bags:
    grepros frame_id=antenna --type nav_msgs/* --publish --reindex-if-unindexed
  • Find messages where GNSS has fixed position, print two messages before and one after for context:
    grepros status=-1 --invert-match --type *NavSatStatus -B 2 -A 1
  • Print all odometry messages while battery charge is below 50%:
    grepros --type *odometry --condition "<topic */battery*>.charge < 0.5"
  • Print all diagnostics message fields containing “warn”, at least 5 seconds apart:
    grepros warn --every-nth-interval 5 --matched-fields-only --type diagnostic*
  • Export data from all bags in directory and subdirectories to SQLite, show progress bar:
    grepros --path /my/bags -r --write my.sqlite --no-console-output --progress

Full documentation of all options on github.


Plugins

grepros supports loading additional features from plugins.

It is easy to add a new output type: derive a plugin class from grepros.outputs.SinkBase, and feed it to grepros as an argument. Here is a sample with a few dozen lines of code, for posting matched ROS messages to a URL endpoint as JSON:

    nano ./urlsink.py  # Paste from https://pastebin.com/raw/GsLCDu8P

    PYTHONPATH=$PYTHONPATH:. \
    grepros --plugin urlsink --write http://my.host/my/path

Hope this package proves as useful to others, as it already has to me and my colleagues.

8 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.