Jupyter ROS: embedding ROS Data Visualization on Jupyter notebooks

Written by Ruben Alves

14/03/2020

.

 

 

 

 

 

 

What we are going to learn

Learn how to embed ROS data visualization inside a Jupyter notebook.

List of resources used in this post

Opening the ROSject

In today’s post, we are going to learn how to see ROS Data inside a Jupyter Notebook using the Jupyter ROS package. Let’s start by clicking on the ROSject link (http://www.rosject.io/l/d4b0981/). You should now have a copy of the ROSject.

Now, let’s open the notebook by clicking the Open ROSject button.

Open ROSject - Juypter ROS Demo on ROSDS

Open ROSject – Juypter ROS Demo on ROSDS

When you open the ROSject, a default notebook will be automatically open with the instructions on how to show ROS Data in Jupyter.

The demos are possible thanks to the Jupyter-ROS project developed by Wolf Vollprecht from Quantstack. All credit goes to him and his team.

What follows is the list of ROS enabled notebook demos that work off-the-shelf by using the ROSDS integrated simulations. The original notebook demos were created by Wolf. In The Construct, we only have added the explanations required to understand the code and launch the simulations, so you can have a live demo without having to install and configure your computer.

The ROSject provides everything already installed and configured. Hence, you don’t need to install Jupyter ROS, you only need to learn how to use it… and then use it! (for instructions about how to install on your own computer, please check the author’s repo)

You can freely use all the material from the ROSject to create your own notebooks with ROS.

List of demos

When you open the notebook, the list of demos you have are:

  • ROS 3D Grid: about how to include an interactive 3D grid inside a notebook.
  • ROS Robot: about how to add the robot model inside the 3D grid
  • ROS Laser Scan: about how to show the robot laser on the 3D grid.
  • ROS TEB Demo: about how to add interactive markers to the 3D viewer

Where to find the notebooks inside the rosject

All the notebook files are contained in the ROSject.

In order to see the actual files, use the IDE (top menu, Tools->IDE). Then navigate through the folders up to notebook_ws->notebooks.

Jupyter ROS - List of files in ROSDS

Jupyter ROS – List of files in ROSDS

 

How to modify the provided notebooks directly in ROSDS

Use the Jupyter notebook tool to edit the notebooks included in this rosject (or to create new ones).In case you close the notebook, you can re-open it by going to the top menu and selecting Tools->Jupyter Notebook.
Once you have the notebook open, edit at your own will. Check the Jupyter documentation to understand all the possible options.

ROS Laser Scan demo

In the notebooks of the ROSject, we have four demos, but in this post, we are going to show only how to show Laser Scan in the notebook to make things simpler.

In order to get this working, we are going to use the simulation of a Turtlebot.

Remember that you have to have the ROS Bridge running in order for Jupyter ROS to work. If you haven’t started it yet, launch it now.

  1. Go to the ROSDS TAB in your browser
  2. On the top menu, select Tools->Shell
  3. On the opened shell type the following command:
roslaunch ~/notebook_ws/notebooks/launch/bridge.launch --screen

Launching the simulation

We’ll need someone to publish the URDF and the TF. For that, we are going to use a Gazebo simulation. Let’s start a Turtlebot2 simulation.
  1. Go to the ROSDS TAB and go to its top menu.
  2. Select Simulations.
  3. On the panel that appears, click on the label that says Select world.
  4. Then on the drop-down menu that appears, move down until you see the AR Drone world.
  5. On the panel that appears, click on the label that says Select robot.
  6. Then on the drop-down menu that appears, move down until you see the Turtlebot 2.
  7. Click on it and then press Start simulation
Turtlebot in a green area in ROSDS

Turtlebot in a green area in ROSDS

 

A new window should appear and load the simulation. Once loaded you should see something similar to this:

Turtlebot opened in a green area in ROSDS

Turtlebot opened in a green area in ROSDS

First, Start the demo

First, import the required classes from Jupyter ROS.

Click on the next cell and then press Shift+Enterto activate the Python code.IMPORTANT: the import of such a class can take some time!. You will know that the code is still running because the number on the left of the cell has changed to a * character. Do not move to the next step until the * is gone.

try:
    from sidecar import Sidecar
except:
    pass
    
from jupyros import ros3d

Second, create an instance of the viewer, connect to ROS and get the TF

Click on the next cell and then press Shift+Enterto activate the Python code.

v = ros3d.Viewer()
rc = ros3d.ROSConnection()
tf_client = ros3d.TFClient(ros=rc, fixed_frame='/base_footprint')

Connect to the topic of the laser

Click on the next cell and then press Shift+Enterto activate the Python code.
laser_view = ros3d.LaserScan(topic="/kobuki/laser/scan", ros=rc, tf_client=tf_client)

Fourth, get the 3D grid and the robot model

Click on the next cell and then press Shift+Enterto activate the Python code.

g = ros3d.GridModel()
import os
urdf = ros3d.URDFModel(ros=rc, tf_client=tf_client, path=os.environ.get('JUPYROS_ASSETS_URL', 'http://localhost:3000'))
v.objects = [g, laser_view, urdf]

Fifth, visualize everything

Click on the next cell and then press Shift+Enterto activate the Python code

try:
    sc = Sidecar(title='Sidecar Output')
    with sc:
        display(v)
except:
    display(v)

Sixth, change the visualization style (if required)

Click on the next cell and then press Shift+Enterto activate the Python code.

v.layout.height= '1000px'
g.color = '#CCC'
laser_view.point_size = 0.1
laser_view.static_color = "green"

Move the robot around and watch the laser change!

Open a new shell (Tools -> Shell) and type the following command to make the robot move around:

rostopic pub /cmd_vel geometry_msgs/Twist "linear:
  x: 0.2
  y: 0.0
  z: 0.0
angular:
  x: 0.0
  y: 0.0
  z: 0.3"

That is it. If you did everything ok, you should see the robot moving around in the jupyter notebook.

Learn more about Jupyter ROS

If you want to learn more about Jupyter ROS, here we have the interview we made to Wolf for the ROS Developers Podcast where he explains the ins and outs of Jupyter ROS.

Youtube video

So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.

Keep pushing your ROS Learning.

Topics:
Masterclass 2023 batch2 blog banner

Check Out These Related Posts

129. ros2ai

129. ros2ai

I would like to dedicate this episode to all the ROS Developers who believe that ChatGPT or...

read more

1 Comment

  1. Phil

    Hi there, the links for the ROSject at the top of the article are broken. Can you please advise how to access to ROS Jupyter notebook material?

    Reply

Submit a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest

Share This