ros2-service-pattern

Generate ROS 2 service server and async client code examples.

9|2|Updated Nov 28, 2025
One-click install
npx skills add https://github.com/mjunaidca/robolearn --skill ros2-service-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ros2-service-pattern
Source: https://github.com/mjunaidca/robolearn/tree/main/.claude/skills/authoring/ros2-service-pattern
Command: npx skills add https://github.com/mjunaidca/robolearn --skill ros2-service-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Teaching request/response in ROS 2 requires reliable server/client patterns. This Skill provides canonical service and client code examples.

Core Features & Use Cases

  • Service Server Pattern: Implement a simple service with a request and response.
  • Service Client Pattern: Async client usage with proper error handling.
  • Decision Guidance: When to use services vs topics in educational contexts.

Quick Start

Implement a basic AddTwoInts service and a client that calls it, then run in a ROS 2 workspace.

Frequently Asked Questions about ros2-service-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement a ROS 2 service server and client for request-response communication?

A ROS 2 service server handles incoming requests and returns responses synchronously, while a client sends requests and waits for replies. Use the service server pattern to define a .srv interface, implement a callback handler, and spin the node; create an asynchronous client that sends requests with proper error handling and awaits responses.

When should I use ROS 2 services instead of topics for robot commands?

Services enforce synchronous request-response semantics ideal for commands requiring confirmation, while topics enable asynchronous one-way messaging. Choose services for discrete tasks like AddTwoInts operations where the client must wait for completion; use topics for continuous sensor streams and event broadcasting.

What's the correct async client pattern for calling ROS 2 services in Humble?

Create an async client using create_client(), construct a request object matching your .srv definition, call the service with await, and handle exceptions for timeouts or failures. This pattern prevents blocking while waiting for the server response and follows ROS 2 Humble canonical templates.

How do I structure a ROS 2 service definition and implement both server and client code?

Define request and response fields in a .srv file, create a server node with a callback that processes requests and returns responses, then build a client node that instantiates the service, sends requests, and processes replies. Follow official ROS 2 Humble patterns for both Python and C++ implementations.

Can I validate my ROS 2 service patterns against current ROS 2 Humble documentation?

Yes, this Skill validates generated service server and client code against live ROS 2 Humble documentation to ensure patterns match official standards. This guarantees your templates remain compatible with the current ROS 2 release and best practices.