Introduction to ROS Part 5: Services, Requests, and Responses with Python | DigiKey
In this ROS 2 tutorial, we take a closer look at services, one of the fundamental communication mechanisms in the Robot Operating System. Unlike topics, which broadcast data asynchronously to multiple nodes, services follow a request/response model ideal for tasks like sending commands or retrieving one-time information. This hands-on episode walks you through building both a service server and a service client in Python using the rclpy library. The written guide for this episode can be found here: https://www.digikey.com/en/maker/tutorials/2025/intro-to-ros-part-5-services-requests-and-responses-with-python 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 begin by exploring the differences between topics and services in ROS 2, explaining when and why you might choose one over the other. You’ll learn how services work under the hood, using well-defined interfaces that specify both the request and response formats. The tutorial uses the AddTwoInts example interface from example_interfaces to keep things simple and focused on the communication flow. From there, we guide you through the process of creating a minimal service server node that listens for integer addition requests and responds with the result. You’ll see how to structure the server class, handle callbacks, and log request data for debugging. We also demonstrate how to build and run the node using Docker and the ROS 2 CLI. Next, we build a service client node that randomly generates integers and sends them to the server for processing. You’ll gain a deeper understanding of asynchronous programming with ROS 2, learning how to use call_async() along with add_done_callback() and Future objects to handle responses efficiently. We also show how to use command-line tools and the rqt GUI to introspect and test services. Whether you're new to ROS 2 or expanding your skillset beyond topics, this tutorial provides a practical introduction to using services in Python. By the end of the video, you'll know how to structure synchronous communication between nodes and understand when to use services in your own robotic applications.

