Giter Club home page Giter Club logo

nml_bag's Introduction

A simple ROS2 bag file interface

This Python package wraps and documents functionality for reading data from bag files generated by ROS2. Bag files (or "bags") are the standard via which ROS2 stores data to disk. For an introduction to bag files, please see the ROS2 documentation that explains recording and playing back data.

The purpose of this package is to facilitate direct reading of data from bag files that have been recorded by ROS.1 The ROS 2 bag design document explains the motivation and approach to data storage, and the rosbag2 package provides an official implementation (C++ and Python). However, documentation of the rosbag2 API is currently both scattered and limited, as are recommended best practices for working with bags. This package is intended to aggregate documentation about existing ROS2 functionality and to illustrate its usage. This package is intended only to fill a temporary gap, and it is expected that later versions of ROS2 (Jazzy and beyond) will make it obsolete.

Installation

The rosbag2 package must be installed. This does not necessarily require that ROS2 must be installed.

With the rosbag2 package installed, no further steps are required, as long as the package is available on the Python path (e.g., via PYTHONPATH).

A setup.cfg file has been provided, to facilitate package installation via setuptools. Package installation can be accomplished via the command:

pip install path/to/nml_bag

Quickstart / Usage

Basic usage of the package follows this pattern:

  1. Initialize a ROS2 command prompt by sourcing the ROS2 environment.
  2. Import the package:
    import nml_bag
  3. Initialize a Reader object:
    reader = nml_bag.Reader('path/to/bag.mcap', topics=['topic_a', '/topic_b'])
  4. Iterate through message records:
    for message_record in reader: print(message_record)
    
  5. Alternatively, the records property will return all available message records:
    records = reader.records
    

Example

A usage example is included in this package as example.py. The example initializes a bag directory and a MCAP file bag_test_0.mcap. The bag file contains a single topic test, on which two string-type messages are recorded.

Roughly following the quickstart outline, the code for reading the bag is:

from pprint import pprint
import nml_bag
reader = nml_bag.Reader('path/to/bag_test_0.mcap')
pprint(reader.records)

And the output is similar to:

[{'data': 'Hello World!',
  'time_ns': 1654207659885697659,
  'topic': 'test',
  'type': 'example_interfaces/msg/String'},
 {'data': 'Goodybye World!',
  'time_ns': 1654207659885798001,
  'topic': 'test',
  'type': 'example_interfaces/msg/String'}]

A note about serialization and storage formats

By default, ROS2 messages are serialized using the Common Data Representation (CDR) standard and stored using MCAP (since Iron) -- "an open source container file format for multimodal log data". Formerly, data were stored using sqlite 3.

Note: Although the sqlite3 package is part of the standard distribution of Python 3 -- and it can be used to interpret bag files -- it is recommended that the ROS2 API be used for decoding bag files wherever possible.

Footnotes

  1. Note that reading data directly from bags is different from playing data back. The latter functionality is amply explained in the ROS2 documentation.

nml_bag's People

Contributors

mstoelzle avatar ricmua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nml_bag's Issues

Install: python setup.py develop did not run successfully.

Failed to install using pip.

Command: pip3 install --user --editable .

  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: requests in /usr/lib/python3/dist-packages (from nml-bag==1.0.0) (2.25.1)
Installing collected packages: nml-bag
  Running setup.py develop for nml-bag
    error: subprocess-exited-with-error
    
    × python setup.py develop did not run successfully.
    │ exit code: 1
    ╰─> [32 lines of output]
        ...
        EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
        ...
        error: can't create or remove files in install directory
        ...
        The installation directory you specified (via --install-dir, --prefix, or
        the distutils default setting) was:
        
            /usr/local/lib/python3.10/dist-packages/
        
        Perhaps your account does not have write access to this directory?  If the
        installation directory is a system-owned directory, you may need to sign in
        as the administrator or "root" account.  If you do not have administrative
        access to this machine, you may wish to choose a different installation
        directory, preferably one that is listed in your PYTHONPATH environment
        variable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.