A. rospy.init_node should be called after rospy.spin
B. Wrong node name 'listener'
C. Missing import of std_msgs
D. Missing parentheses after rospy.spin
Solution
Step 1: Check usage of rospy.spin
rospy.spin is a function and must be called with parentheses to keep the node alive.
Step 2: Verify other parts
Node name 'listener' is valid, std_msgs import is not required here, and init_node must be called before spin.
Final Answer:
Missing parentheses after rospy.spin -> Option D
Quick Check:
Call rospy.spin() with parentheses [OK]
Hint: Always call rospy.spin() with parentheses [OK]
Common Mistakes:
Forgetting parentheses on rospy.spin
Thinking node name causes error
Misordering init_node and spin
5. You want to create two ROS nodes that communicate by sending messages. Which is the best way to organize your code?
hard
A. Write two separate node programs, each with its own init_node call
B. Write one program with two init_node calls for both nodes
C. Use one node and switch its name dynamically
D. Create one node and run it twice without changes
Solution
Step 1: Understand ROS node design
Each node is a separate program with its own init_node call to run independently.
Step 2: Evaluate other options
One program cannot have two init_node calls; switching names dynamically or running one node twice without changes won't create two communicating nodes properly.
Final Answer:
Write two separate node programs, each with its own init_node call -> Option A
Quick Check:
Separate programs = separate nodes [OK]
Hint: One node per program with init_node call [OK]
Common Mistakes:
Trying to call init_node twice in one program
Reusing one node for two roles
Not separating node logic into programs
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.