ROS2 Command Line - Topic Echo

Easy CLI Tools 88% pass rate
#python#subscriber#cli#logging

Practice the ROS2 Command Line - Topic Echo coding problem in CLI Tools. Browser-based execution with automated grading — no local ROS install required. 88% of engineers pass this challenge.

🧠 Concept: Subscribers and Callbacks

A subscriber listens to a topic and calls your function every time a new message arrives. It's the receiving side of the publisher/subscriber pattern.

Key API:

self.sub = self.create_subscription(MessageType, '/topic', self.callback, queue_depth)

The callback receives the message automatically:

def callback(self, msg):
    self.get_logger().info(f'Received: {msg.data}')

Logging levels:

self.get_logger().info('normal message')
self.get_logger().warn('something unusual')
self.get_logger().error('something went wrong')

Problem Statement

Create a ROS2 Python node that listens to messages from a topic and processes them. This completes the communication loop started by the publisher.

Requirements

  • Create a node named simple_subscriber
  • Subscribe to topic /chatter
  • Message type: std_msgs/String
  • Log the received message to the console using self.get_logger().info()
  • Format: "I heard: [message data]"

Input/Output Format

Input:

  • /chatter (std_msgs/String) - Receives string messages

Output:

  • Console Logs - Prints "I heard: Hello ROS2!" (or whatever is published)

⚠️ Common Pitfalls

  • Forgetting to add self to the callback method definition.
  • Mismatched message types between publisher and subscriber.

📚 Helpful Resources

Frequently asked questions

What is the ROS2 Command Line - Topic Echo practice problem?

It is a hands-on CLI Tools challenge on SimuCode where you implement and run ROS2 code in the browser with runtime-verified tests.

How do I practice ROS2 Command Line - Topic Echo online?

Open this page, sign in, and solve the problem in the built-in IDE. Your solution is graded against real ROS2 execution checks.

What skills does ROS2 Command Line - Topic Echo test?

This Easy problem focuses on python, subscriber, cli skills used in robotics interviews and production systems.