ROS2 and Gazebo


As an author, I am supposed to say few words about how wonderful and interesting ROS2 is, how robotics takes over the world and so on...

ROS2 is around for many years yet it is still poorly documented. When you look at forums, you may notice that to find answers people sometimes have to go through ROS2 source code!
And I do realize that a single person can not change that. Or can I?

As I study ROS2, I am going to document my "discoveries" here, trying to make it as readable as possible. The complete code will always be provided, I am going to make sure it works before making it available, and so on.

That said, ROS2 keeps changing, so code that works on a current version (I use Foxy) might not work on the next version. This is beyond my control.

And yes, it is ROS2, and always ROS2. A huge problem with ROS(2) tutorials is that people write "ROS" instead, Google has no idea how to index it, and when you do search, you get mixed ROS/ROS2 results. Then you read half of a post just to discover that it was for a previous version, not for ROS2.
I know it is hard to type an extra character, but I am going to do my best. ROS2. Here. See?

The reason for choosing ROS2 is purely practical. At some point, ROS will be no longer supported, so to build your career, you have to learn ROS2. Yes, it is buggy, poorly documentsd and keeps changing. But learning it now in a slow way is better, than to have to switch to it in a hurry, five years from now.

Unrelated note: in sections below, I provide directory structures for packages I created. Additionally, all those packages refer to an outside folder src/worlds that contains "worlds" - as the models of the "worlds" are common, there is no need to duplicate them in each package.

                ├── worlds
                │   ├──
                │   ├── maze.sdf
                │   └── shapes.sdf

The archive for worlds files is available here.


ROS 2 packages for working with Gazebo are located in a meta package named gazebo_ros_pkgs. The packages support ROS 2 Crystal and later and Gazebo 9 and later; they can be installed from debian packages or from source.

It means that gazebo_ros_pkgs comes as part of Ubuntu repos, and we don't have to take extra steps to save it.
Additionally, we may need core tools (repos again).

Make sure you install packages below. Also keep in mind that this is one of the main sources of confusion: when something "just does not work" in ROS2, often it is because you don't have one of those packages (and I can not promise that I have provided a complete list!)
Once again. Imagine: something doesn't work. No meaningful error messages, mixed and confusing info on forums. And chances are, you simply haven't installed something.

                $ sudo apt install software-properties-common
                $ sudo add-apt-repository universe
                $ sudo apt update && sudo apt install curl
                $ sudo curl -sSL -o /usr/share/keyrings/ros-archive-keyring.gpg
                $ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
                $ sudo apt update
                $ sudo apt upgrade
                $ sudo apt install ros-galactic-desktop
                $ sudo apt install ros-galactic-ros-base
                $ sudo apt install ros-dev-tools

                $ sudo apt install ros-galactic-ros2-control ros-galactic-ros2-controllers ros-galactic-gazebo-ros2-control
                $ sudo apt install ros-galactic-gazebo-ros-pkgs
                $ sudo apt install ros-galactic-ros-core ros-galactic-geometry2
                $ sudo pip3 install setuptools
                $ sudo apt-get install ros-galactic-joint-state-publisher-gui ros-galactic-xacro

                $ sudo apt install ros-galactic-navigation2
                $ sudo apt install ros-galactic-nav2-bringup
                $ sudo apt install ros-galactic-slam-toolbox
                $ sudo apt install ros-galactic-robot-localization
                $ sudo apt install ros-galactic-robot-state-publisher
                $ sudo apt install ros-galactic-rviz2

                # sudo apt install ros-galactic-teleop-twist-keyboard

                $ sudo rosdep init
                $ rosdep update
                # src like ~/SnowCron/ros_projects/harsh
                $ rosdep install --from-paths src --ignore-src --rosdistro galactic -y
                $ sudo apt install python3-colcon-common-extensions
                # Note: changed API after this version
                $ pip install opencv-contrib-python== 
                $ sudo apt install ros-galactic-aruco

                # Robotic arm
                $ sudo apt install python3-vcstool
                $ sudo apt install ros-galactic-test-msgs
                $ sudo apt install ros-galactic-control-toolbox
                $ sudo apt install ros-galactic-gazebo-ros-pkgs
                $ sudo apt install ros-galactic-xacro
                $ sudo apt install ros-galactic-joint-state-publisher-gui

                $ pip install tinyik
                # With the visualization feature:
                $ pip install tinyik[viz]

                # Transformations tree tool
                $ sudo apt-get install -y ros-galactic-rqt-tf-tree

                rosdep install --from-paths ./ -i -y --rosdistro galactic --ignore-src
                sudo apt-get install ros-galactic-ros2-control ros-galactic-ros2-controllers

                sudo apt update && sudo apt install blender

                sudo apt install ros-galactic-gazebo-ros-pkgs

                $ source /opt/ros/galactic/setup.bash

                #pip install trimesh
                #pip install pymesh
                #pip install pydae
                #pip install pymeshfix
                pip install open3d
                #pip install vtk

                python -m pip install scipy
                sudo apt-get install python3-scipy

                # pip install filterpy

Uninstalling ROS2 and Gazebo:

                $ sudo apt-get remove gazebo-*
                $ sudo apt remove ~nros-galactic-* && sudo apt autoremove
                $ sudo rm /etc/apt/sources.list.d/ros2.list
                $ sudo apt update
                $ sudo apt autoremove
                # Consider upgrading for packages previously shadowed.
                $ sudo apt upgrade            

(C), all rights reserved

Please read the disclaimer