ARTICLE AD BOX
I am developing a custom Python controller for a TurtleBot3 (Burger) using ROS 2. My node publishes geometry_msgs/msg/Twist messages to the /cmd_vel topic.
The Problem: When I run my Python script, the robot does not move. However, when I check the topic using ros2 topic echo /cmd_vel, I can clearly see my messages being published. Furthermore, ros2 topic info --verbose confirms that my publisher and the robot's subscriber are connected (matched QoS).
Strangely, if I manually publish a command via the terminal, the robot moves perfectly: ros2 topic pub /cmd_vel geometry_msgs/msg/Twist "{linear: {x: 0.10}}" -r 10
The Setup & Code Flutter Client (robot_connection_page.dart) Sends a JSON command via WebSocket.
Future<void> _testConnection() async { // ... connection logic ... debugPrint('Connected! Sending forward for 3 seconds...'); // Send forward commands for (int i = 0; i < 30; i++) { channel.sink.add(jsonEncode({'movement': 'forward'})); await Future.delayed(const Duration(milliseconds: 100)); } // ... }Here is my Python code snippet:
class TurtleBotController(Node): def __init__(self): super().__init__('turtlebot_controller') # QoS is set to RELIABLE to match TurtleBot3 default qos = QoSProfile( reliability=ReliabilityPolicy.RELIABLE, history=HistoryPolicy.KEEP_LAST, depth=10 ) self.publisher_ = self.create_publisher(Twist, '/cmd_vel', qos) def move_forward(self): msg = Twist() msg.linear.x = 0.25 # <--- THIS IS THE VALUE SENT msg.angular.z = 0.0 self.current_cmd = msg self.publisher_.publish(msg) self.get_logger().info("CMD: FORWARD")Debug Info:
Topic Echo: Shows linear.x: 0.25 (Data is flowing). Connection: Publisher count 1, Subscriber count 1 (Both RELIABLE). Domain ID: Verified correct (Nodes see each other).ros2 topic echo /cmd_vel shows the data is definitely on the network:
linear: x: 0.25 y: 0.0 z: 0.0Why does the robot ignore my Python script but obey the terminal command?
