VideoLibrary

Introduction to ROS Part 7: Custom Interfaces | DigiKey

In this video, we take your ROS 2 development to the next level by introducing custom interfaces for both messages and services. While ROS 2 includes a wide range of built-in types, real-world robotics applications often need bespoke data formats. Custom interfaces allow you to structure your messages based exactly on your needs, including sensor data, navigation paths, or control parameters. The written guide for this episode can be found here: https://www.digikey.com/en/maker/tutorials/2025/intro-to-ros-part-7-custom-interfaces The GitHub repository containing the Docker image and example code for this series can be found here: https://github.com/ShawnHymel/introduction-to-ros We’ll start by creating a dedicated interface package using ament_cmake, the standard ROS 2 build tool. You’ll learn how to define a .msg file to represent a 3-axis accelerometer reading and a .srv file that allows a client to request a list of random 3D points from a server. We'll walk through how to properly update package.xml and CMakeLists.txt to include the necessary build and runtime dependencies, ensuring your interfaces are available to both Python and C++ nodes. Once the interfaces are built, we demonstrate how to use them in real ROS 2 nodes. In Python, we create a publisher node that broadcasts fake accelerometer data using the custom message. Then we write a C++ subscriber node that listens to this data and logs the output. This cross-language compatibility highlights how ROS 2’s middleware can unify components written in different languages. Next, we show how to build a request/response architecture using a custom service. A Python server node accepts a number and returns a list of random geometry points. Meanwhile, a C++ client node periodically sends requests and displays the resulting points. You’ll learn how to use asynchronous callbacks and proper message typing to make this interaction seamless and responsive. By the end of this tutorial, you’ll know how to create and use custom ROS 2 interfaces to give your robotics software the structure and flexibility it needs. This foundational skill is essential for any serious ROS 2 developer working on scalable or production-grade systems.

11/3/2025 9:03:27 PM