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.

__UPDATE May 7, 2020: We no longer need use Portainer for the web-bash terminal since we now use the bash terminal functionality within our web-browser based VSCode environment. Additional clarifications presented below in the appropriate section.

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

Kick off a web based bash terminal to run ROS2. Use our web-bash terminal to run a simple ROS2 example. 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.

Install Docker for your OS. 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

__UPDATE May 7, 2020: We no longer need use Portainer for the web-bash terminal since we now use the bash terminal functionality within our web-browser based VSCode environment. Follow the new instructions below on launching a web-bash terminal from VSCode.

Open web browser tab (Firefox or Chrome preferred) to launch VSCode to run inside your browser. In the browser-based VSCode, click on the upper left 3-bar menu icon -> Terminal -> New Terminal.

A bash terminal panel should now appear in the lower right part of VSCode.

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:

Using a browser makes UI/UX OS agnostic which helps avoid potential confusions that arise from different OS widgets and terminal commands. Docker containers sandbox the ROS2 system code from your host system making upgrades and setup less intrusive. 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!

__UPDATE May 7, 2020: We did find an easier web-bash solution. We no longer need use Portainer for the web-bash terminal since we now use the bash terminal functionality within our web-browser based VSCode environment.

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:

Ran a bash ROS2 example in a web browser using Docker containers with the help of a guided Hadabot script. Explained what the ROS2 example showcased. 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"