Hadabot is a robot kit to learn ROS2 and robotics. With Hadabot, you'll be able to build and program a physical ROS2 robot with minimal frustration and intimidation.

In my last post about the renewed Hadabot effort, I mentioned that we'll be primarily interacting with ROS2 and the Hadabot software stack through a web browser.

In this write-up, I'll start documenting my efforts at materializing the new Hadabot software stack. Specifically, we'll be doing the following:

  1. Kick off a web based bash terminal to run ROS2.

  2. Use our web-bash terminal to run a simple ROS2 example.

  3. Explain how using a web-bash terminal ties into the new Hadabot kit (the current work-in-progress).

The exercises below should take no more than 15 minutes.


1. Starting a ROS2 web-bash terminal in your browser

1a. Set up Docker

We'll be leaning heavily on Docker containers to sandbox our ROS2 environment. So let's first install the docker tools we need.

  1. Install Docker for your OS.

  2. If you are not using a Mac, install Docker Compose (ie docker-compose).

I promise you, we are trying to keep the installation steps as minimal as possible! =)

1b. Get the Hadabot code

Clone the Hadabot repo for the scripts to start the Docker containers and to guide you on running the ROS2 example.

Type the following into your host OS terminal.

$ git clone https://github.com/hadabot/hadabot_main.git

$ cd hadabot_main/docker

$ docker-compose up -d

1c. Kick off a bash terminal in a web browser
  1. Open a web browser tab (Firefox or Chrome preferred), go to http://localhost:9000.

  2. Create a local Portainer admin account - we'll explain about Portainer later.

    1. If you see a bunch of failure tooltips, Ctrl-Shift-R to refresh the page with a flushed cache.
    2. NOTE: this admin account is created locally within the container you launched. It is not created in the cloud so you don't have to fret about security.

  3. Upon seeing a Connect Portainer to the Docker environment you want to manage panel:

    1. NOTE: if you don't see this panel and you get directly sent to your dashboard, logging out and then logging back in should fix the problem... argh... Portainer woes.
    2. Select the Local - manage the local Docker environment box.
    3. Click Connect.

  4. From the left-menu bar, click Home.

  5. In the Endpoints panel, select the local sub-panel box.

  6. Click Containers, then click ros2_console from the list of containers.

  7. At the bottom of the Container status panel box, click >_ Console, then click Connect.

A bash terminal for the ros2_console container should start.

Congrats! You successfully launched a ROS2 web-bash terminal. Woot!


2. Run Hadabot's guided script for a simple ROS2 example

From the web-bash terminal, run our guided python3 script:

root@id:/# python3 /content/pt1/rd_1.py

NOTE: this is a Python 3 script so don't forget to use python3.

Follow the instructions described in the output to run the ROS2 example (ie guide you on how to start another web-bash terminal, etc).


3. Significance of the ROS2 example

ROS, and by extension ROS2, uses a publisher-subscriber architecture to encourage modularity. Each "module" is called a ROS node and ROS nodes communicate to each other by publishing and subscribing to topics of interest.

For example, one ROS node may be responsible for monitoring encoder ticks from a wheel on the robot. It publishes an integer total number of clicks it has seen to an /encoder_wheel topic.

Another ROS node may be responsible for estimating the robot's pose so it would subscribe to /encoder_wheel.

In the ROS2 example you ran, you created two ROS nodes. In one web-bash terminal, when you typed ros2 topic pub..., you created a ROS node to publish a string message (specifically the std_msgs/msg/String type - more on that later) to a /chatter topic.

In the other terminal, you created the second ROS node via ros2 topic echo... to subscribe to and echo back the data from the /chatter topic.

As for the std_msgs/msg/String type - the ROS2 system comes pre-installed with a couple of message definitions - std_msgs/msg/String is one of them.

Extra credit ROS2 exercises

Want to see what nodes are running? With a 3rd web-bash terminal in another browser tab, you can type:

root@id:/# ros2 node list -a

... to see the 2 nodes you created under the name /_ros2cli_xxx and /_ros2cli_yyy.

Want to learn more about the built in ROS2 message types. You can find out how the std_msgs/msg/String message is defined:

root@id:/# ros2 interface show std_msgs/msg/String

You can list out all message types that ROS2 knows about via:

root@id:/# ros2 interface list

For another exercise - although using the original ROS (not ROS2) so you will have to be a bit scrappy in mapping the calls to ROS2 - refer to an older post we wrote for Silicon Valley Robotics.


4. Significance of running ROS2 in the browser using containers

The Hadabot UX will be predominantly web-based and the web services and apps will be running off containers. This offers a number of benefits:

  1. Using a browser makes UI/UX OS agnostic which helps avoid potential confusions that arise from different OS widgets and terminal commands.

  2. Docker containers sandbox the ROS2 system code from your host system making upgrades and setup less intrusive.

  3. Containers also allows us to separate the Hadabot user code from ROS2 system code while still easily allowing you to access the Hadabot user code from your host system.

What is Portainer?

Portainer is a web-based container management tool. Portainer itself runs as a container so the entire web application runs locally and is sandboxed within Docker - privacy intact! The web-based console tool is part of a suite of other tools that comes with Portainer.

Perhaps we'll have cycles to implement a simpler Hadabot-centric web-bash console in the future (too many "clicks" within Portainer to get to the console), obviating the need for Portainer. But for now, we will continue to leverage Portainer's web-based bash console. If anyone has a better suggestion, let me know!


5. Conclusion

To stop and clean up the running Docker containers, from hadabot_main/docker:

$ docker-compose down -v

Congrats on completing the first guided example of running ROS2 on Hadabot's (work-in-progress) software stack. To conclude, in this post we:

  1. Ran a bash ROS2 example in a web browser using Docker containers with the help of a guided Hadabot script.

  2. Explained what the ROS2 example showcased.

  3. Explained how web-bash and containers will be integral to the Hadabot developments.

If you have suggestions, comments, or just want to say hi, don't hesitate to reach out - hello AT hadabot DOT com.

If you haven't already done so, sign up to stay in touch with the latest updates to my Hadabot developments using the link above or below.

Thanks and happy building!
Jack "the Hadabot Maker"