ros2-patterns
ROS 2 node templates and message types for robotics development. Use when creating ROS 2 nodes, understanding message types, or writing publisher/subscriber patterns.
When & Why to Use This Skill
This Claude skill streamlines ROS 2 robotics development by providing standardized node templates, message type references, and common communication patterns. It helps developers quickly scaffold publishers, subscribers, and service servers while ensuring adherence to ROS 2 Humble conventions, proper error handling, and structured documentation.
Use Cases
- Rapid Prototyping: Quickly generate boilerplate code for new ROS 2 nodes to focus on core robotics logic rather than infrastructure setup.
- Communication Implementation: Efficiently set up publisher and subscriber patterns for seamless data exchange between different robotic sensors and actuators.
- Standardization and Best Practices: Ensure all robotics code follows ROS 2 Humble conventions, including proper node lifecycle management and error handling routines.
- Learning and Reference: Use as a quick reference for ROS 2 message types and standard node structures for developers transitioning to robotics engineering.
| name | ros2-patterns |
|---|---|
| description | ROS 2 node templates and message types for robotics development. Use when creating ROS 2 nodes, understanding message types, or writing publisher/subscriber patterns. |
| allowed-tools | Read, Bash |
ROS 2 Patterns
Instructions
When creating ROS 2 code:
- Use the provided templates as starting points
- Follow ROS 2 Humble conventions
- Include proper error handling
- Add docstrings and comments
Common Patterns
| Pattern | Template | Use Case |
|---|---|---|
| Publisher | publisher.py | Sending data to topics |
| Subscriber | subscriber.py | Receiving data from topics |
| Service Server | (extend publisher) | Request/response pattern |
| Action Server | (advanced) | Long-running tasks |
Node Structure
import rclpy
from rclpy.node import Node
class MyNode(Node):
def __init__(self):
super().__init__('node_name')
# Initialize publishers, subscribers, timers
def callback(self, msg):
# Handle incoming messages
pass
def main(args=None):
rclpy.init(args=args)
node = MyNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
Reference
See messages.md for common message types. See templates/ for complete templates.