ROS2 Development
Node Pattern (rclpy)
class MyNode(Node):
def __init__(self):
super().__init__('my_node')
self.pub = self.create_publisher(Twist, 'cmd_vel', 10)
self.sub = self.create_subscription(LaserScan, 'scan', self.scan_cb,
QoSProfile(reliability=ReliabilityPolicy.BEST_EFFORT, depth=5))
self.timer = self.create_timer(0.1, self.timer_cb)
QoS Cheat Sheet
- Sensors:
BEST_EFFORT, VOLATILE, depth=5
- Commands:
RELIABLE, VOLATILE, depth=10
- Map data:
RELIABLE, TRANSIENT_LOCAL, depth=1
Standards
- REP-103: SI units (meters, radians, seconds)
- REP-105: frame names (base_link, odom, map)
- Use
sim_time in simulation, wall_time on real hardware
- Lifecycle nodes for managed startup/shutdown
Key Libraries
rclpy, rclcpp, launch_ros, tf2_ros, robot_state_publisher
1---2name: ros2-development3version: 1.0.04description: Idiomatic ROS2 development. Lifecycle nodes, QoS, launch files, TF2, custom messages.5---67# ROS2 Development89## Node Pattern (rclpy)10```python11class MyNode(Node):12 def __init__(self):13 super().__init__('my_node')14 self.pub = self.create_publisher(Twist, 'cmd_vel', 10)15 self.sub = self.create_subscription(LaserScan, 'scan', self.scan_cb,16 QoSProfile(reliability=ReliabilityPolicy.BEST_EFFORT, depth=5))17 self.timer = self.create_timer(0.1, self.timer_cb)18```1920## QoS Cheat Sheet21- Sensors: `BEST_EFFORT`, `VOLATILE`, depth=522- Commands: `RELIABLE`, `VOLATILE`, depth=1023- Map data: `RELIABLE`, `TRANSIENT_LOCAL`, depth=12425## Standards26- REP-103: SI units (meters, radians, seconds)27- REP-105: frame names (base_link, odom, map)28- Use `sim_time` in simulation, `wall_time` on real hardware29- Lifecycle nodes for managed startup/shutdown3031## Key Libraries32rclpy, rclcpp, launch_ros, tf2_ros, robot_state_publisher