Skip to content

Instantly share code, notes, and snippets.

@rahulbhadani
Last active October 8, 2020 23:04
Show Gist options
  • Save rahulbhadani/3ca0ca732af9a804afae9c796f85bc87 to your computer and use it in GitHub Desktop.
Save rahulbhadani/3ca0ca732af9a804afae9c796f85bc87 to your computer and use it in GitHub Desktop.
Requisite for reading rosbag files in Python

Requisite for reading rosbag files in Python

If you are interested in reading bag files in python, you will need to install bagpy package. I recommend using virtual environment for installation.

Prerequisite

  1. Ubuntu
  2. Python 3.6 or higher preferred, might work with other versions of python but not tested on them.

Creating virtual environment

There are two ways you can create python virtual environment: (i) Using Anaconda (ii) Using python virtualenv package

Virtual Environment Using Anaconda

Donwload and Install Anaconda

  1. wget https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
  2. chmod +x https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh
  3. ./Anaconda3-2020.07-Linux-x86_64.sh

Create a virtual environment

Following command will create a virtual environment named rosread.

conda create -n rosread python=3.6 anaconda

It will take a few minutes to several depending on availability of CPU and RAM in your system.

Activate virtual environment

source activate rosread

Virtual Environment using virtualenv

Install virtualenv package

sudo apt install virtualenv

Now, create a virtual environment:

virtualenv --python=python3.6 rosread

Once you create virtual environment, activate as follows:

source rosread/bin/activate

Now, every time you open a terminal and want to use virtual environment, you will have to activate using one of the two methods methods mentioned above.

Installing packages

We will install packages in virtual environment. First activate the virtual environment and then install following bagpy package for reading bagfiles:

pip install bagpy

Now you are ready to use bagpy. Look for examples at https://github.com/jmscslgroup/bagpy/tree/master/notebook and documentation at https://jmscslgroup.github.io/bagpy/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment