ROS2 Messaging Patterns

Implements ROS2 publisher, subscriber, and synchronization patterns with Clean Architecture in Python and C++.

Updated Aug 16, 2026
One-click install
npx skills add https://github.com/three1324/yeonjinautomotive --skill ros2-messaging-patterns-three1324
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ROS2 Messaging Patterns
Source: https://github.com/three1324/yeonjinautomotive/tree/main/.claude/skills/ros2_messaging
Command: npx skills add https://github.com/three1324/yeonjinautomotive --skill ros2-messaging-patterns-three1324

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires rclcpp, message_filters, sensor_msgs, std_msgs, nlohmann_json.

What problem does it solve? Mixing ROS2 message types directly into domain logic couples your core business rules to the middleware, making code hard to test and port. This Skill provides messaging patterns that keep the domain layer free of ROS2 dependencies. ## Core Features & Use Cases - Domain-Driven Publishers: Template-based C++ publisher classes that convert domain entities to ROS2 messages inside the infrastructure layer. - Generic Subscriber Handlers: Reusable base subscriber that converts incoming messages to entities before invoking callbacks. - Message Synchronization: ApproximateTime synchronization of camera image and camera_info topics using message_filters. - Event Bus: JSON-over-String event bus pattern for decoupled intra-system events. - Use Case: When building a robot application with Clean Architecture, use these patterns to publish robot state and subscribe to sensor topics without leaking rclcpp types into your domain entities. ## Quick Start Ask the AI to create a ROS2 publisher and subscriber for a robot state topic following Clean Architecture so the domain layer stays independent of ROS2 message types.

Frequently Asked Questions about ROS2 Messaging Patterns

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

FAQPage Schema
How do I keep ROS2 message types out of my domain layer?

Define pure domain entities and perform message-to-entity conversion only in the infrastructure layer. Publishers accept domain entities and map them to ROS2 messages internally, so domain code never imports rclcpp or message headers.

How to synchronize image and camera_info topics in ROS2 C++?

Use message_filters with the ApproximateTime sync policy. Create message_filters::Subscriber instances for each topic, then register a Synchronizer callback that fires when messages with close timestamps arrive.

What QoS profile should I use for ROS2 publishers and subscribers?

Choose Reliable QoS when every message matters, such as commands or state updates, and Best Effort for high-rate sensor data where occasional drops are acceptable. The QoS is passed to create_publisher and create_subscription.

Can I build an event bus over ROS2 topics?

Yes, publish JSON-serialized payloads on a shared std_msgs/String topic such as /events/all. Each event carries a type field and payload, letting subscribers filter by event type without defining custom messages.

How do I make ROS2 subscriber callbacks thread-safe in C++?

Protect shared resources accessed inside callbacks with std::mutex. Callbacks may run on executor threads concurrently, so any shared state mutation must be guarded to avoid data races.