C. rospy.spin() should be called before service creation
D. The handler must return a response object, not just a sum
Solution
Step 1: Check the handler function return type
The handler must return a response object of the service type, not just a raw sum value.
Step 2: Understand ROS service response structure
Returning only req.a + req.b causes an error; the correct return is AddTwoIntsResponse(req.a + req.b).
Final Answer:
The handler must return a response object, not just a sum -> Option D
Quick Check:
Handler returns response object [OK]
Hint: Handler returns response object, not raw value [OK]
Common Mistakes:
Returning raw values instead of response objects
Calling rospy.spin() too early
Incorrect service name format
5. You want to design a ROS system where a robot arm must receive a command and confirm completion immediately. Why is using a service better than a topic for this interaction?
hard
A. Because services provide a direct request-response, ensuring the command was received and processed
B. Because topics automatically guarantee message delivery and response
C. Because topics are faster for one-time commands
D. Because services can send continuous sensor data streams
Solution
Step 1: Analyze the communication needs for command and confirmation
The robot arm needs to know immediately if the command was received and completed, requiring a synchronous interaction.
Step 2: Compare services and topics for this use case
Services provide a request-response pattern, confirming completion, while topics are asynchronous and do not guarantee immediate feedback.
Final Answer:
Because services provide a direct request-response, ensuring the command was received and processed -> Option A
Quick Check:
Request-response ensures confirmation [OK]
Hint: Use services for commands needing immediate confirmation [OK]
Common Mistakes:
Thinking topics guarantee immediate response
Using services for continuous data streaming
Confusing speed with communication pattern
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.