Challenge - 5 Problems
ROS Robotics Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateWhy does ROS use a publish-subscribe model?
ROS uses a publish-subscribe communication model. What is the main advantage of this model in robotics?
Attempts:
2 left
💡 Hint
Think about how robots need flexible communication between many parts.
✗ Incorrect
The publish-subscribe model lets different parts of a robot send and receive messages independently, making the system flexible and scalable.
❓ component_behavior
intermediateWhat happens when a ROS node crashes?
In ROS, if a node crashes unexpectedly, what is the typical behavior of the system?
Attempts:
2 left
💡 Hint
Consider how ROS nodes are designed to be independent.
✗ Incorrect
ROS nodes run independently, so if one crashes, others keep running but lose communication with it until it restarts.
📝 Syntax
advancedIdentify the correct ROS Python node initialization
Which of the following code snippets correctly initializes a ROS node in Python?
Attempts:
2 left
💡 Hint
Check the official ROS Python API for node initialization.
✗ Incorrect
The correct way is to import rospy, call rospy.init_node with the node name, then call rospy.spin to keep the node alive.
🔧 Debug
advancedWhy does this ROS subscriber not receive messages?
Given this ROS Python subscriber code, why does it not receive any messages?
import rospy
from std_msgs.msg import String
def callback(data):
rospy.loginfo(data.data)
rospy.init_node('listener')
rospy.Subscriber('chatter', String, callback)
# Missing line here
ROS
import rospy from std_msgs.msg import String def callback(data): rospy.loginfo(data.data) rospy.init_node('listener') rospy.Subscriber('chatter', String, callback) # Missing line here
Attempts:
2 left
💡 Hint
Think about what keeps a ROS node running to receive messages.
✗ Incorrect
Without rospy.spin(), the node exits immediately after subscribing, so it never processes incoming messages.
❓ state_output
expertWhat is the output of this ROS Python publisher code?
Consider this ROS Python publisher code snippet:
import rospy
from std_msgs.msg import String
rospy.init_node('talker')
pub = rospy.Publisher('chatter', String, queue_size=10)
rate = rospy.Rate(1) # 1 Hz
count = 0
while count < 3:
msg = String()
msg.data = f'hello {count}'
pub.publish(msg)
rate.sleep()
count += 1
print('Done publishing')
What will be printed to the console?
ROS
import rospy from std_msgs.msg import String rospy.init_node('talker') pub = rospy.Publisher('chatter', String, queue_size=10) rate = rospy.Rate(1) # 1 Hz count = 0 while count < 3: msg = String() msg.data = f'hello {count}' pub.publish(msg) rate.sleep() count += 1 print('Done publishing')
Attempts:
2 left
💡 Hint
Consider what the print statement outputs and what publishing does internally.
✗ Incorrect
The code prints 'Done publishing' after sending messages; publishing does not print messages itself.
