A Foundational Roadmap for Mastering ROS 2
If you’ve decided to dive into ROS 2 (Robot Operating System 2), the learning curve might hit you like a brick wall. You’re expected to understand C++, a new build system (ament), and a messaging architecture—all at once. On top of that, most tutorials assume you already know how to work with terminals and Linux systems. That’s why it’s important to follow a clear plan on how to start with ROS2—one that builds your foundation step by step instead of overwhelming you from the start.
Instead of randomly jumping from tutorial to tutorial, what you need is a structured roadmap. A plan that separates the core skills you need and helps you master them in the right sequence. This blog will walk you through the exact steps to start learning ROS2 the right way.
Phase 1: C++ Foundation — Before ROS2
Why Start with C++?
ROS2 is built primarily in C++. That means if you don’t understand C++, your ability to read, write, or debug ROS2 nodes will be limited. By first mastering the language outside of the ROS ecosystem, you isolate your variables: when your code fails, it’s not because of ROS—it’s just the C++.
Step 1: Write Single-File C++ Programs
Start with classic programs like:
cpp
#include <iostream>
using namespace std;
int main() {
cout << "Hello, ROS2!" << endl;
return 0;
}
Compile with:
bash
g++ hello.cpp -o hello
./hello
This helps you build a mental model of how code turns into an executable. No build system. No packages. Just logic.
Step 2: Move to Multi-File Projects
Split your code into:
- main.cpp
- MotorController.cpp
- MotorController.hpp
Compile like this:
bash
g++ main.cpp MotorController.cpp -o robot_program
Learning this prepares you for the modular programming structure used in ROS 2 packages, which follow a similar convention.
Phase 2: Software Engineering with CMake
Step 1: Learn Modern CMake
CMake is the underlying build system of ROS2 (ament_cmake). Here’s a minimal CMakeLists.txt to compile your multi-file project:
cmake
cmake_minimum_required(VERSION 3.10)
project(my_robot)
add_executable(robot_node main.cpp MotorController.cpp)
Use this to generate your build:
bash
mkdir build && cd build
cmake ..
make
Understanding this prepares you for more advanced ament_cmake-based ROS2 projects.
Step 2: Create and Link Libraries
Structure your code into libraries such as:
- libMotorDriver
- libSensorFusion
- libPowerManagement
Then, link them to your executable:
cmake
add_library(motor_driver MotorDriver.cpp)
target_link_libraries(robot_node motor_driver)
This modular approach mirrors how ROS 2 breaks complex systems into nodes and packages.
Step 3: Add Unit Tests
Integrate GoogleTest:
cmake
enable_testing()
add_executable(test_motor test_motor.cpp)
target_link_libraries(test_motor motor_driver gtest_main)
add_test(NAME MotorTest COMMAND test_motor)
By learning how to test your logic before touching ROS2, you eliminate guesswork later when debugging robotic behaviors.
Phase 3: Command Line + ROS 2 Concepts
Become Fluent with the Terminal
If you’re not comfortable using commands like cd, mkdir, source, or export, you’ll struggle in ROS2. These are essential for setting up and managing workspaces, launching nodes, and inspecting running systems.
Linux Journey offers a beginner-friendly CLI learning path.
Phase 4: First Steps Inside the ROS2 Ecosystem
Understanding ROS 2 Communication: Topics, Nodes, and Messages
Create two workspaces:
- colcon_ws_A → with a talker node
- colcon_ws_B → with a listener node
In your talker node:
cpp
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
publisher_ = this->create_publisher<std_msgs::msg::String>("chatter", 10);
In the listener node, subscribe to chatter.
Use the CLI to monitor:
bash
ros2 topic echo /chatter
rqt_graph
This phase teaches how nodes publish and subscribe to topics, which forms the backbone of ROS2 communication.
Phase 5: C++ + ROS2 Integration
Step 1: Use Gazebo Simulation
Launch TurtleBot3 simulation:
bash
export TURTLEBOT3_MODEL=burger
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
Publish a command:
bash
ros2 topic pub /cmd_vel geometry_msgs/Twist "{linear: {x: 0.1}, angular: {z: 0.1}}"
By interacting with /scan, /odom, and /cmd_vel, you see how simulation and ROS2 are integrated.
Explore simulation-ready TurtleBot3 packages for practical applications.
Step 2: Embed Your C++ Library Inside a ROS 2 Node
Let’s say you built a libSensorFusion in Phase 2. Now:
- Create a ROS 2 package:
bash
ros2 pkg create --build-type ament_cmake sensor_node
- Copy your .cpp and .hpp into the src directory.
- Update CMakeLists.txt:
cmake
add_library(sensor_fusion src/SensorFusion.cpp)
add_executable(sensor_node src/sensor_node.cpp)
target_link_libraries(sensor_node sensor_fusion)
- Use your class inside the node:
cpp
#include "SensorFusion.hpp"
auto filtered = sensor_fusion.process(raw_imu_data);
This structure separates your core logic from ROS-specific code. It’s easier to debug, extend, and test.
Learning Path Chart
Here’s how your progression should look:
Phase | Skills Gained | Tools Used |
C++ Basics | Syntax, classes, files | g++, terminal |
Build Systems | Modular code, CMake | CMake, GoogleTest |
ROS 2 Intro | Topics, CLI, multi-node architecture | ros2 CLI, colcon, rqt |
Simulation | Real-time robot interaction | Gazebo, TurtleBot3 |
Integration | Package creation, abstraction | ROS 2 packages, libraries |
ROS 2 the Right Way
By following this roadmap, you’re not just learning commands—you’re learning software development for robotics. You’ll no longer get stuck wondering, “Is the issue in my C++ code, or is ROS 2 acting weird?” You’ll know where to look.
This learning sequence reflects how real mobile robotics engineers at Robotisim train beginners—from C++ to deployment on real robots. Their structured Mobile Robotics Engineering course is built around how to start with ROS2 the right way, turning this roadmap into a practical, hands-on experience that builds real skills.
Final Thoughts
If you start with tutorials without foundational skills, every error feels like magic. But if you follow the step-by-step roadmap above—starting with C++, mastering CMake, and finally entering ROS2 with clarity—you’ll build working robots, not frustration. This is how to start with ROS2 in a way that actually works—by focusing on fundamentals before diving into complexity.
The ROS 2 documentation, ROS Answers, and Robotisim’s Learning Path will make a lot more sense once you have this grounding.
So take a step back, breathe, and build each layer properly.
You’re not late to ROS2. You just needed a better map.