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-development3description: Idiomatic ROS2 development. Lifecycle nodes, QoS, launch files, TF2, custom messages.4---56# ROS2 Development78## Node Pattern (rclpy)9```python10class MyNode(Node):11 def __init__(self):12 super().__init__('my_node')13 self.pub = self.create_publisher(Twist, 'cmd_vel', 10)14 self.sub = self.create_subscription(LaserScan, 'scan', self.scan_cb,15 QoSProfile(reliability=ReliabilityPolicy.BEST_EFFORT, depth=5))16 self.timer = self.create_timer(0.1, self.timer_cb)17```1819## QoS Cheat Sheet20- Sensors: `BEST_EFFORT`, `VOLATILE`, depth=521- Commands: `RELIABLE`, `VOLATILE`, depth=1022- Map data: `RELIABLE`, `TRANSIENT_LOCAL`, depth=12324## Standards25- REP-103: SI units (meters, radians, seconds)26- REP-105: frame names (base_link, odom, map)27- Use `sim_time` in simulation, `wall_time` on real hardware28- Lifecycle nodes for managed startup/shutdown2930## Key Libraries31rclpy, rclcpp, launch_ros, tf2_ros, robot_state_publisher