MyRoboPathOpen Robotics Lab
ros214 min readUpdated 2026-03-05Intermediate

ROS 2 Custom Interfaces: Messages, Services & Actions

Create custom .msg, .srv, and .action definitions in a standalone CMake package, generate C++ and Python headers, and implement preemptible Action Servers.

MyRoboPath Engineering Lab
Peer-Reviewed Open-Source Hardware & Firmware Guide

Key Engineering Takeaways

  • •Topics = Continuous stream (unidirectional); Services = Fast request/response (synchronous blocking); Actions = Long-running tasks with feedback and preemption.
  • •Always keep interface definitions in a dedicated `<project>_msgs` package to prevent circular dependencies.
  • •Action goals allow clients to cancel mid-execution (e.g. aborting navigation when an obstacle appears).
Prerequisites
  • • Basic ROS 2 nodes

When to Use Topics vs Services vs Actions

Choosing the correct communication paradigm is critical for robust system design:

  • Topic: LiDAR scans at 10Hz, wheel odometry at 50Hz, camera images at 30Hz.
  • Service: Trigger camera calibration snapshot, reset odometry origin, enable/disable motors.
  • Action: Navigate to 3D waypoint coordinates, execute 5-second robotic arm pick-and-place trajectory.
Tags:#ROS 2#Interfaces#Actions#Services#CMake#colcon