ros2-publisher-subscriber

Generate ROS 2 Humble publisher and subscriber Python code examples for educational use.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Teaching ROS 2 pub/sub patterns requires clean, ready-to-run code examples that illustrate message exchange and lifecycle.

Core Features & Use Cases

  • Canonical Patterns: Publisher and subscriber code following ROS 2 Humble conventions.
  • Educational Integration: Examples linked to chapters about topics, QoS, and node lifecycle.
  • Tutorial-Ready: Ready to drop into lessons and practice exercises.

Quick Start

Copy the publisher and subscriber snippets into a ROS 2 workspace, run the nodes, and publish a few messages to verify communication.

Frequently Asked Questions about ros2-publisher-subscriber

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

FAQPage Schema
How do I create a ROS 2 publisher and subscriber to exchange messages on a topic?

ROS 2 publisher and subscriber code examples follow canonical patterns using rclpy nodes. Create a publisher node that sends messages to a topic and a subscriber node that listens and processes them. Both nodes require proper initialization, spinning to keep the node alive, and graceful shutdown—the Skill generates complete, ready-to-run Python examples for Humble.

What is ROS 2 pub/sub and when should I use topic-based communication?

ROS 2 pub/sub (publish/subscribe) is a topic-based messaging pattern where publishers send data and subscribers receive it asynchronously. Use it for decoupled, one-to-many communication—sensors broadcasting data, multiple nodes consuming the same stream, or any workflow where producers and consumers shouldn't know about each other directly.

How do I set up QoS (Quality of Service) settings for ROS 2 message delivery?

Quality of Service in ROS 2 controls message reliability and delivery guarantees. The Skill implements QoS depth of 10, storing recent messages so late-joining subscribers receive historical data. Configure QoS policies in your publisher and subscriber to match your application's needs—reliability levels, durability, and history depth determine message persistence.

Can I run ROS 2 publisher and subscriber code locally and in the cloud?

Yes. ROS 2 Humble code examples work across Tier 1 cloud and Tier 2 local environments. The Skill generates code compatible with both deployment contexts, allowing you to develop and test locally, then scale to cloud infrastructure without rewriting node logic or communication patterns.

What Python knowledge do I need to write ROS 2 nodes and run pub/sub examples?

ROS 2 nodes using rclpy require basic Python: class definitions, imports, and function calls. The Skill generates educational code samples that teach node lifecycle (initialization, spinning, shutdown) and message handling—suitable for learners new to ROS 2 who have introductory Python familiarity.

Do ROS 2 pub/sub examples work with the current Humble API documentation?

Yes. The Skill fetches current ROS 2 Humble API documentation before code generation to ensure examples conform to the latest conventions and APIs. Generated publisher and subscriber code follows Humble best practices and remains compatible as the framework updates.