Kristin's Blog

← Back to blog

Published on Sat Jan 18 2025 00:00:00 GMT+0000 (Coordinated Universal Time) by Kristin Wei

Personally I have heard ROS since 2015 (wow TEN YEARS from now), but at that time the linux system is not very stable (I believe the popular version was Ubuntu14 or Ubuntu16) and I was struggling with other courses in Uni. So I did not have the chance to learn until now, but it’s never too late to learn anything.

What is ROS?

ROS is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms.

Installation

We will use ROS2 here, since ROS2 is the latest version of ROS and it is more stable and more powerful than ROS1.

I tried both humble and jazzy, and found out that the new Gazebo is not easy to use intuitively, and there are less tutorials about that. So for Gazebo part, I use classic Gazebo and ros2 humble.

To be honest, the official website is way much better, so you may want to follow this for jazzy and this for humble

Docker

I wouldn’t recommend using docker with Gazebo and rviz, from my experience so far, it’s not stable enough or hard to make it correct.

There are some docker tutorials for humble and jazzy already:

I also attach my personal code for docker using docker-compose.yaml(Docker) and devcontainer.json (VSCode extension).

Humble Docker Set Up
// devcontainer.json
{
  "name": "ROS 2 Development Container",
  "privileged": true,
  "remoteUser": "kristin",
  "dockerComposeFile": "docker-compose.yaml",
  "service": "devcontainer",
  "workspaceFolder": "/home/kristin/ros2_ws", // you should change to your own workspace
  "customizations": {
      "vscode": {
          "extensions": [
              "ms-vscode.cpptools-extension-pack",
              "twxs.cmake",
              "donjayamanne.python-extension-pack",
              "eamodio.gitlens",
              "ms-iot.vscode-ros",
              "ms-azuretools.vscode-docker",
              "ms-python.black-formatter",
              "smilerobotics.urdf",
              "redhat.vscode-xml"
          ]
      }
  },
  "postCreateCommand": "sudo rosdep update && sudo rosdep install --from-paths src --ignore-src -y && sudo chown -R $(whoami) /home/kristin/ros2_ws/" // you should change to your own workspace
}
# ./devcontainer/docker-compose.yaml
services:
  devcontainer:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - USERNAME=kristin # you should change to your own username
    image: vac611/ros2_humble_gazebo:latest # you should change to your own image name
    container_name: vac611_ros2_humble_gazebo # you should change to your own container name
    volumes:
      - /home/kristin/ros2_ws:/home/kristin/ros2_ws:rw # you should change to your own workspace path
      - type: bind
        source: /tmp/.X11-unix
        target: /tmp/.X11-unix
        consistency: cached
      - type: bind
        source: /dev/dri
        target: /dev/dri
        consistency: cached
    command: sleep infinity
    network_mode: host
    pid: host
    ipc: host
    environment:
      - DISPLAY=unix:0
      - ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
      - ROS_DOMAIN_ID=42
    privileged: true
Jazzy Docker Set Up
// .devcontainer/devcontainer.json
{
    "name": "ROS 2 Development Container",
    "privileged": true,
    "remoteUser": "kristin",
    "dockerComposeFile": "docker-compose.yaml",
    "service": "devcontainer",
    "workspaceFolder": "/home/kristin/ros2_ws", // you should change to your own workspace path
    "customizations": {
        "vscode": {
            "extensions": [
                "ms-vscode.cpptools-extension-pack",
                "twxs.cmake",
                "donjayamanne.python-extension-pack",
                "eamodio.gitlens",
                "ms-iot.vscode-ros",
                "ms-azuretools.vscode-docker",
                "ms-python.black-formatter",
                "smilerobotics.urdf",
                "redhat.vscode-xml"
            ]
        }
    },
    "postCreateCommand": "sudo rosdep update && sudo rosdep install --from-paths src --ignore-src -y && sudo chown -R $(whoami) /home/kristin/ros2_ws/" // you should change to your own workspace path
}
# .devcontainer/docker-compose.yaml
services:
  devcontainer:
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - USERNAME=kristin # you should change to your own username
    image: vac611/ros2_jazzy_gazebo:latest # you should change to your own image name
    container_name: vac611_ros2_jazzy_gazebo # you should change to your own container name
    volumes:
      - /home/kristin/ros2_ws:/home/kristin/ros2_ws:rw # you should change to your own workspace path
      - type: bind
        source: /tmp/.X11-unix
        target: /tmp/.X11-unix
        consistency: cached
      - type: bind
        source: /dev/dri
        target: /dev/dri
        consistency: cached
    command: sleep infinity
    network_mode: host
    pid: host
    ipc: host
    environment:
      - DISPLAY=unix:0
      - ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
      - ROS_DOMAIN_ID=42
    privileged: true

Bashrc file set up

After installation, you need to set up the bashrc file to source the ros2 environment for autocompletion and other features.

# ~/.bashrc

# ros2
source /opt/ros/humble/setup.bash

# colcon
source /usr/share/colcon_cd/function/colcon_cd-argcomplete.bash

# ros2 workspace 
source ~/ros2_ws/install/setup.bash # you should change to your own workspace path

# gazebo
source /usr/share/gazebo/setup.bash

# nav2
export TURTLEBOT3_MODEL=waffle
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp # a fix

ROS2 Basic Concepts

ROS2 Basic Concepts

You can find the official explanation as a reference

Nodes

Topics

Services

Actions

Parameters

ROS Launch

Launch files in ROS are used to start multiple nodes and set parameters in a single command. It supports python and xml.

Nav2

The official website is here.

It provides navigation tools in Gazebo and rviz. You can play with it from here, and navigate the turtlebot3 in Gazebo world environment.

Moveit (TBC)

ROS Demos

I made a few demos to learn ROS. You can find them in My Github ROS Demo repo.

Turtlesim Chase Game

in branch ros_beginner

This demo only uses basic ROS concepts (node, topic, message, service, launch). The src code in c++ and python is in package src/turtle_control.

Turtlebot3 Navigation

in branch nav2

In this demo, I created a map using Gazebo. It has online models that we can easily drag inside Gazebo.

Written by Kristin Wei

← Back to blog