How do you use Juypter notebook with ROS 2?

I understand that using Juypter notebooks makes a lot of sense once you have some data and want to do some analysis or ML with that data, but I don’t really understand the workflow of developing a node, publisher, subscriber, client, server etc with Jupyter notebook.

I do not come from a Python background, but from my understanding of ROS 2 nodes are generally one or more classes with callback methods which does not seem to be particularly compatible with the REPL paradigm on which (I believe) Juypter notebook is based.

So I would like to know more about how you are using Juypter notebooks while developing ROS 2 applications.


I think you would want to subscribe to various data topics from your ROS2 nodes (robots), capture that data to disk, then run a notebook on that data. If you actually wanted to influence your node’s behavior based on the analysis then you would want to either rebuild your nodes based on the tuned parameters or publish that data to topics such that the node could use those parameter updates. Either way, this isn’t a feature of ROS2 as the purpose of the framework is to provide this message bus architecture and flexible set of plugins and launchers which is custom code and configuration that developers can leverage to extensively define the behavior of a robot. Essentially ROS2 provides an actor or more specifically an event sourced behavior architecture. This is fantastic because the messages themselves are eventually consistent snapshots of real events in a time series which is what makes the visualization tools so powerful. For example have a look at Foxglove studio to get an idea of just how far you can go with this. So that said, if you’re going to use ML to tune your robot’s behavior then ROS2 is how you want to define that behavior in your robot. Here’s an example implementation where the author defined custom message types and provides widgets in the notebook to interact with those messages

1 Like

So to summarise, we have the following use cases for Juypter notebooks:

  1. Capture data as a rosbag and analyse it (offline)
  2. Create some data/parameters in Jupyter notebook and inject that data into the ROS graph (online)
  3. Create some widgets in a notebook that when toggled/adjusted, inject data into the ROS graph (online)

Did I miss anything? As I understand, eventually juypter-ros2 will also be able to directly subscribe to topics and plot data, although my impression is that this isn’t implemented yet.

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