Atlas Robotics
Lesson 3/6 · about 60 min

Install ROS 2, Gazebo and build workspace

Do this once for the entire course. If you have taken the 2D course, your device already has ROS 2 Humble and Gazebo Fortress, you just need to add a few packages for SLAM 3D and then build a new repo.

After this lesson you will have

  • ROS 2 Humble, Gazebo Fortress and SLAM 3D libraries (GTSAM, PCL, Eigen)
  • Repo atlas_sim3D and code FAST-LIO2 have pinned the correct version and patch of the course
  • Workspace build completed: 12 packages, about 3–4 minutes on dev machine

1. Operating system

Ubuntu 22.04, install directly or dual-boot. All commands below run in Ubuntu's terminal.

2. ROS 2 Humble

Ignore if ls /opt/ros/humble already exists (e.g. the machine has learned a 2D course).

sudo apt update && sudo apt install -y locales software-properties-common curl
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
sudo add-apt-repository -y universe
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt install -y ros-humble-desktop ros-dev-tools

This is the standard installation process of ROS 2 at the time of writing. If ROS side changes the key or URL, search for "ROS 2 Humble install Ubuntu deb packages" on docs.ros.org to get the new version.

3. Gazebo Fortress and required course packages

One command for both simulation, control, navigation and SLAM 3D library. These are literally 18 packages that check_env.sh tested:

sudo apt install -y \
  ros-humble-ros-gz ros-humble-gz-ros2-control ros-humble-ros2-controllers \
  ros-humble-xacro ros-humble-joint-state-publisher-gui ros-humble-teleop-twist-keyboard \
  ros-humble-navigation2 \
  ros-humble-gtsam ros-humble-pcl-conversions ros-humble-message-filters \
  libpcl-dev libeigen3-dev libyaml-cpp-dev pcl-tools \
  python3-vcstool python3-colcon-common-extensions python3-numpy python3-yaml
GroupPurpose
ros-gz, gz-ros2-control, ros2-controllersGazebo Fortress, ROS bridge ↔ Gazebo, wheel control (like 2D course)
navigation2Navigate in Part D
gtsam, PCL, Eigen, yaml-cppBuild FAST-LIO2, PGO (pose graph optimization) and relocalization
pcl-toolspcl_viewer to open map file map.pcd
vcstoolDownload third-party source code according to pinned commits

ros-humble-ros-gz tow right Gazebo Fortress. Don't install ros-humble-gazebo-*: it's Gazebo Classic, old version, can't be used with this repo. Fortress' command is ign gazebo, not gz sim.

4. Get the repo and build

Repo atlas_sim3D is a private repo on GitHub, open to members. After accepting the invitation on GitHub, clone using your account (SSH key or token):

git clone https://github.com/atlasroboticsvn/atlas_sim3D.git ~/atlas_sim3D

Get third-party FAST-LIO2 code, apply course patch, build SLAM part:

cd ~/atlas_sim3D
source /opt/ros/humble/setup.bash
src/atlas3d_slam/tools/setup_third_party.sh

This script does three things: loads FASTLIO2_ROS2 and Sophus the correct commit recorded in slam.repos into src/third_party/; apply patch file src/atlas3d_slam/patches/fastlio2_ros2_vlp16.patch; build packages up to atlas3d_slam in Release mode.

Đã áp patch: .../src/atlas3d_slam/patches/fastlio2_ros2_vlp16.patch
...
Summary: ... packages finished
Xong. source /home/<bạn>/atlas_sim3D/install/setup.bash

Build the rest (bringup, navigation):

cd ~/atlas_sim3D
CMAKE_BUILD_PARALLEL_LEVEL=1 MAKEFLAGS=-j1 colcon build --executor sequential
source install/setup.bash
Summary: 12 packages finished [...]
  3 packages had stderr output: fastlio2 localizer pgo

Three packages reporting stderr output are normal: they are compilation warnings (unused variable, comparison of signed and unsigned numbers) in the original FAST-LIO2 code, not errors. The real error will have the word Failed and the line error:.

Full clean build on dev machine takes 3 minutes 22 seconds; The longest is fastlio2 (1 minute 11 seconds), pgo (44 seconds), localizer (34 seconds).

Check

ros2 pkg list | grep -E "atlas3d|fastlio2|pgo|localizer"
atlas3d_bringup
atlas3d_control
atlas3d_description
atlas3d_gazebo
atlas3d_navigation
atlas3d_perception
atlas3d_slam
fastlio2
localizer
pgo

Rerun bash tools/check_env.sh: item 4 should now report Đã build đủ 11 package.

5. Prepare terminal

Each new terminal must source two environments, ROS first, workspace second:

source /opt/ros/humble/setup.bash
source ~/atlas_sim3D/install/setup.bash

To avoid retyping, add those two lines at the end of ~/.bashrc. If in ~/.bashrc is the source workspace of the 2D course (~/atlas_sim/install/setup.bash), remove that line: two workspaces with the same source at the same time can easily confuse the package.

Convention for all the following lessons: command ros2 run in the source terminal as above, located in directory ~/atlas_sim3D. When you need multiple programs to run at the same time, the article clearly states Terminal 1, Terminal 2.

Why build 1 thread. FAST-LIO2, PGO and relocalization using Eigen, PCL and GTSAM, full library of many templates. Each compilation process can take up several GB of RAM; Running multiple processes in parallel on a 16GB machine is prone to crashes or the compiler being killed by the operating system midway. --executor sequential build each package one by one, -j1 compile each file one by one. Slower, but only takes about 3–4 minutes.

Why pin the commit and apply a patch. FAST-LIO2 does not have an apt installation for Humble so it must be built from source code. slam.repos pin the correct commit you tried, so that even if the third party's source code changes, your repo will still be built as on the day of writing. Patch additional parts needed for LiDAR VLP-16 in simulation and connection to Atlas3D robot. M08 will read each change in the patch.

Why Humble + Fortress. Same set as 2D course, so what you learned about ros_gz_bridge and gz_ros2_control can be reused intact. Humble ends support in May 2027; Appendix D will switch to Jazzy + Harmonic.

Common errors during installation

Cannot apply patch src/third_party/FASTLIO2_ROS2 that has been modified or different from the commit. Delete that folder and run setup_third_party.sh. again
Could not find GTSAMMissing ros-humble-gtsam, or not source /opt/ros/humble/setup.bash before build.
Machine crashes when buildingForgot two variables CMAKE_BUILD_PARALLEL_LEVEL=1 MAKEFLAGS=-j1. Restart and rebuild with the above command.
Package 'atlas3d_xxx' not foundTerminal not yet source install/setup.bash, or build not completed.
Permission denied when cloneHaven't accepted invitation to repo on GitHub, or haven't logged into git with the invited account.
Install ROS 2, Gazebo and build the workspace · Module 0: Install & run the simulation — Atlas Robotics