Publish /cmd_vel at 10 Hz with a timer
PythonThe starter drives the robot from a while loop with time.sleep(0.1). That blocks the node, so rclpy can never run its callbacks, and the period drifts by however long each publish takes. Rewrite it the ROS 2 way: a 0.1 s timer that publishes the Twist (0.2 m/s forward, 0.5 rad/s turn) and logs what it sent, then rclpy.spin().
Checks
- Not run yetUses a 0.1 s timer and rclpy.spin, with no sleep loop
- Not run yetPublishes 0.20 m/s and 0.50 rad/s ten times a second
- Not run yetRuns for 2 seconds without an error
Hints
- self.create_timer(0.1, self.tick) calls tick every 0.1 s once the node spins.
- Log each message with self.get_logger().info(f'linear.x={msg.linear.x:.2f} angular.z={msg.angular.z:.2f}').
- Replace Drive().run() with node = Drive() and rclpy.spin(node).