CodeTheRobot

Track 03 · Advanced · Free

C++ Advanced

Node-style C++17 design, then real ROS 2 C++ from nodes to lifecycle nodes.

Phase 6 trains your C++ for ROS 2's architecture without ROS installed: node-like classes, callbacks, event loops, thread-safe queues and timers. Phase 7 is the actual ROS 2 C++ course: nodes, publishers, subscribers, services, actions, parameters, launch files, TF2, URDF, Gazebo, Nav2, packages, executors and lifecycle nodes.

Prerequisite: C++ Intermediate, or working experience with smart pointers, lambdas, templates and CMake.

Pixel-art C++ robotics programming workbench
COMPILER READY
Track 03 · Advanced TRACK

You will be able to

  • Structure code as node-like classes with callbacks, queues and timers
  • Write ROS 2 nodes, publishers, subscribers, services and actions in C++17
  • Describe a robot with URDF, transform it with TF2 and simulate it in Gazebo
  • Package, launch and manage ROS 2 systems with executors and lifecycle nodes

Lesson outline

01

Class-based node-like structures

A class that owns its state, publishers and timers, the shape every ROS 2 node has.

60–90 minOpen lesson
02

Callbacks and lambdas

Passing behaviour into objects, binding member functions, and callback lifetimes.

60–90 minOpen lesson
03

Event-driven programming

An event loop, dispatching events to handlers, and never blocking inside a handler.

60–90 minOpen lesson
04

Asynchronous patterns

Futures, worker threads and posting results back to the main loop safely.

60–90 minOpen lesson
05

Clean API design

Small interfaces, strong types, const-correctness and hard-to-misuse functions.

45–75 minOpen lesson
06

Logging patterns

Log levels, structured messages, throttling and keeping logging out of hot loops.

45–75 minOpen lesson
07

Configuration structs

Grouping settings in a struct, defaults, validation and loading from a file or map.

45–75 minOpen lesson
08

Thread-safe queues

A blocking queue with a mutex and condition variable for passing work between threads.

60–90 minOpen lesson
09

Timers and periodic tasks

Fixed-rate loops with steady_clock and sleep_until, without drift.

45–75 minOpen lesson
10

ROS 2 nodes in C++

rclcpp::init, rclcpp::Node, spin and shutdown.

60–90 minOpen lesson
11

Publishers

create_publisher, message types, QoS depth and wall timers.

60–90 minOpen lesson
12

Subscribers

create_subscription, callback signatures, shared-pointer messages and QoS matching.

60–90 minOpen lesson
13

Services

Request and response calls with create_service and create_client.

60–90 minOpen lesson
14

Actions

Goals with feedback, results and cancellation using rclcpp_action.

90–120 minOpen lesson
15

Parameters

declare_parameter, get_parameter, defaults, and reacting to changes.

60–90 minOpen lesson
16

Launch files

Starting several nodes with parameters and remappings from one Python launch file.

45–75 minOpen lesson
17

TF2 transforms

Coordinate frames, broadcasting transforms and looking them up in C++.

90–120 minOpen lesson
18

URDF and robot_state_publisher

Describing links and joints, and publishing the robot's transforms from joint states.

90–120 minOpen lesson
19

Gazebo simulation

Spawning a URDF in Gazebo, bridging topics and controlling a simulated robot.

90–120 minOpen lesson
20

Navigation stack basics (Nav2)

Maps, localization, planners and controllers, and sending a NavigateToPose goal.

90–120 minOpen lesson
21

Writing your own ROS 2 packages

package.xml, CMakeLists.txt with ament_cmake, installing targets and testing.

90–120 minOpen lesson
22

Multi-threaded executors and callback groups

SingleThreadedExecutor vs MultiThreadedExecutor and avoiding blocked callbacks.

90–120 minOpen lesson
23

Lifecycle nodes

Managed states: unconfigured, inactive, active, and the transition callbacks.

90–120 minOpen lesson

Project examples

PRJ-07

Event loop and thread-safe queue

A small event dispatcher with a blocking thread-safe queue, a worker thread and a fixed-rate timer, built without ROS so the ideas are clear.

queue.push(Event{"temperature", 42.0});
auto e = queue.pop();  // blocks until an event arrives
handlers.at(e.type)(e);
PRJ-08

Temperature node pair

A publisher and subscriber package with parameters, a launch file and a gtest, built with colcon and inspected with the ros2 CLI.

pub_ = create_publisher<std_msgs::msg::Float64>("temperature", 10);
timer_ = create_wall_timer(500ms, [this] { publish_sample(); });
PRJ-09

Simulated mobile robot

A URDF robot spawned in Gazebo, driven by a C++ node, with TF2 frames and a Nav2 goal sent through the NavigateToPose action.

auto client = rclcpp_action::create_client<Nav>(node, "navigate_to_pose");
client->async_send_goal(goal);

Free course

Begin when you are ready.

23 lessons · 2 phases · self-paced. Curriculum aligned with the ISO C++ reference material and verified September 2026.

ISO C++ resources