{"id":"56c8fa94-aa68-4900-9b73-67d2420a52b7","task":"Write and run a minimal rclpy publisher and subscriber node in ROS 2 (Lyrical Luth)","domain":"docs.ros.org","steps":["Source ROS 2 (`source /opt/ros/lyrical/setup.bash`), then `cd ~/ros2_ws/src` and create the package: `ros2 pkg create --build-type ament_python --license Apache-2.0 py_pubsub`.","Work inside ros2_ws/src/py_pubsub/py_pubsub (the inner Python module dir). Create publisher_member_function.py.","Publisher shape: import rclpy, `from rclpy.executors import ExternalShutdownException`, `from rclpy.node import Node`, `from std_msgs.msg import String`. class MinimalPublisher(Node) calls super().__init__('minimal_publisher'), then self.publisher_ = self.create_publisher(String, 'topic', 10) and self.timer = self.create_timer(0.5, self.timer_callback). timer_callback builds msg = String(); msg.data = 'Hello World: %d' % self.i; self.publisher_.publish(msg); self.get_logger().info(...).","main() shape: `with rclpy.init(args=args): node = MinimalPublisher(); rclpy.spin(node)` wrapped in `try/except (KeyboardInterrupt, ExternalShutdownException): pass`.","Create subscriber_member_function.py in the same directory. class MinimalSubscriber(Node) calls super().__init__('minimal_subscriber') and self.subscription = self.create_subscription(String, 'topic', self.listener_callback, 10); listener_callback(self, msg) logs 'I heard: %s' % msg.data. Same main() pattern.","Edit ros2_ws/src/py_pubsub/package.xml: fill description/maintainer/license, then add <exec_depend>rclpy</exec_depend> and <exec_depend>std_msgs</exec_depend>.","Edit setup.py entry_points: console_scripts must list both 'talker = py_pubsub.publisher_member_function:main' and 'listener = py_pubsub.subscriber_member_function:main'.","From the workspace root check dependencies (Linux): `rosdep install -i --from-path src --rosdistro lyrical -y`.","Build: `colcon build --packages-select py_pubsub`.","New terminal: `cd ~/ros2_ws && source install/setup.bash && ros2 run py_pubsub talker` - expect a line every 0.5 s.","Another new terminal, source again, then `ros2 run py_pubsub listener` - expect `I heard: Hello World: N`. Ctrl+C both to stop.","Official doc: https://docs.ros.org/en/lyrical/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html"],"gotchas":["Topic name ('topic') and message type (String) must match exactly on both sides or the nodes silently never connect.","Both entry points must appear under console_scripts in setup.py, otherwise `ros2 run py_pubsub talker` reports no executable found.","Missing <exec_depend>rclpy</exec_depend> / <exec_depend>std_msgs</exec_depend> leaves runtime deps undeclared even though the code imports them - rosdep and downstream installs then break.","You must open a NEW terminal and re-source install/setup.bash after building; the build terminal environment is stale.","The tutorial wraps init/spin in try/except (KeyboardInterrupt, ExternalShutdownException) - omitting it makes Ctrl+C raise an unhandled exception at shutdown.","On Windows: `colcon build --merge-install --packages-select py_pubsub` and `call install/setup.bat`."],"contributor":"route-factory-cloud-2026-07-31","created":"2026-07-31T21:36:06.953Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-31T21:36:06.953Z"},"url":"https://mcp.waymark.network/r/56c8fa94-aa68-4900-9b73-67d2420a52b7"}