ROS2 using JupyterLab via Robostack
In one of the previous articles I described my experience on how to install any version of ROS2 using Robostack. One of the benefits of Robostack is the ease of use with JupyterLab [newer version of Jupyter Notebook]. My goal was to get ROS2 working from JupyterLab on a Robostack installation and in this article I describe the steps to get it working.
As a background and some disclaimers, it was not as simple to get it all working because the support for ROS2 in Jupyterlab is still in pre-release stages. However, the community on Robostack Gitter was extremely helpful in figuring out the issue and get it working.
Here are the additional steps I followed to get the ROS2 working in Jupyterlab using Robostack.
Pre-requisite:
Install Robostack as per the steps in article — https://robofoundry.medium.com/using-robostack-for-ros2-9bb52ca89c12
Installing Jupyter ROS extension
Installing jupyter-ros exetension with support for ROS2 in the mamba env we created for ROS2 humble environment was the tricky part. It will not work if you directly install available version of jupyros from Pypi using pip install as the package that is released is v0.3.0. However, there is a pre-release version v0.6.0a0 of jupyter-ros package that you need to install from source in order to get support for ROS2 [in future you may need to get a fully released tag or install a later release version using pip install but this is what works at the time of writing this article]. The basic instructions are given here — https://jupyter-ros.readthedocs.io/en/latest/dev_installation.html.
### switch to home directory and clone the repo and checkout branch
$ cd ~$ git clone https://github.com/RoboStack/jupyter-ros.git && cd jupyter-ros && git checkout v0.6.0a0
Create a new mamba env with all necessary channels and install ROS2 humble with single command and then activate the env
### create env with channels added$ mamba create -n ros_humble python=3.9 jupyterlab jupyter-packaging bqplot pyyaml ipywidgets ipycanvas ros-humble-desktop-full -c conda-forge -c robostack -c robostack-humble -c robostack-experimental### activate the env
$ mamba activate ros_humble
Install the jupyter-ros extension from source code with v.0.6.0a0 tag
# From the jupyter-ros root directory which for us is ~/jupyter-ros$ cd ~/jupyter-ros$ pip install -e .
Run jupter-lab
jupyter-lab
open ROS2 example notebook and run it step by step and see the ROS messages being logged to data topic. You can see how it works in following screencast video.
One of the important gotchas to remember and something I ran into was the fact that I had ROS2 foxy installed in the main computer outside of the mamba environments and I also had a .bashrc file that was sourcing the foxy installation which results in environment variable ROS_DISTRO=foxy. This was causing a lot of problems for me. So once I cleaned up that sourcing statement from .bashrc and re-sourced, everything started working correctly. I logged and closed an issue here that explains how I resolved it — https://github.com/RoboStack/jupyter-ros/issues/125
Hope this helps someone running the ROS2 in JupyterLab and allows them to tinker with various versions of ROS2 side-by-side. I’ll also create a github repo with few more ROS2 exercise notebooks in future that will allow folks to familiarize with various ROS concepts.
Enjoy!!