Discover how to keep your robot in control even during long jobs!
Why actions for long-running tasks in ROS - The Real Reasons
Imagine you have a robot that needs to move to a far location. You send a command and wait without knowing if it is still moving or stuck.
Manually tracking progress is hard. You might not know if the robot is still working, paused, or failed. This causes delays and confusion.
ROS actions let you send a goal and get updates while the robot works. You can see progress, cancel tasks, and get results when done.
send_goal(); wait_for_result(); // no feedback or cancelsend_goal(); on_feedback(update); on_result(done); cancel_goal();
It enables smooth control and monitoring of tasks that take time, making robots smarter and more responsive.
A delivery robot navigating a building can report its location continuously and stop if obstacles appear.
Manual waiting hides progress and errors.
Actions provide feedback, results, and cancel options.
This improves control over long tasks in robotics.
Practice
Solution
Step 1: Understand the difference between service calls and actions
Service calls in ROS are blocking and do not provide feedback during execution, making them unsuitable for long tasks.Step 2: Identify the benefits of actions for long tasks
Actions allow sending a goal, receiving continuous feedback, and can be preempted or canceled, which is essential for long-running tasks.Final Answer:
Because actions provide feedback and allow preemption during the task -> Option DQuick Check:
Actions give feedback and control = C [OK]
- Thinking actions are faster than services
- Believing actions don't need goals
- Assuming actions run only once without control
Solution
Step 1: Recall the components of a ROS action
A ROS action consists of three parts: Goal (what to do), Feedback (progress updates), and Result (final outcome).Step 2: Compare with other ROS communication types
Request/Response is for services, Publisher/Subscriber is for topics, and Service/Client is a pair for services, not actions.Final Answer:
Goal, Feedback, Result -> Option AQuick Check:
Action message parts = Goal, Feedback, Result = A [OK]
- Confusing actions with services
- Mixing up topics and actions
- Ignoring the feedback part
client.send_goal(goal_msg)
while not client.wait_for_result(timeout=1.0):
print('Working...')
result = client.get_result()
print(result)What will this code do during the long-running task?
Solution
Step 1: Analyze the wait_for_result call with timeout
The method waits up to 1 second for the result; if not ready, it returns False, so the loop continues printing 'Working...'.Step 2: Understand the loop behavior
The loop keeps printing 'Working...' every second until the action finishes, then it exits and prints the final result.Final Answer:
Print 'Working...' repeatedly until the task finishes, then print the result -> Option CQuick Check:
wait_for_result with timeout loops = D [OK]
- Assuming wait_for_result blocks fully without timeout
- Expecting only one 'Working...' print
- Thinking wait_for_result with timeout causes error
client.send_goal(goal_msg)
client.wait_for_result()
print('Result:', client.get_result())What is a likely reason for this behavior?
Solution
Step 1: Understand wait_for_result behavior
wait_for_result() blocks until the server sends a result or the server is unavailable.Step 2: Identify why it never prints
If the action server is not running or not responding, wait_for_result() blocks forever, so print never executes.Final Answer:
The action server is not running or not responding -> Option BQuick Check:
Server missing causes wait block = B [OK]
- Thinking send_goal needs repeating
- Believing wait_for_result needs timeout
- Calling get_result too early
Solution
Step 1: Identify requirements for the cleaning task
The task is long-running, needs progress updates, and must support pause/stop (preemption).Step 2: Match ROS communication types to requirements
Actions support goals, feedback, and preemption, making them ideal for this use case. Services block and lack feedback, topics alone don't handle goals or preemption well.Final Answer:
Define an action with a goal to start cleaning, send periodic feedback with percent done, and allow preemption to pause or stop -> Option AQuick Check:
Actions fit long tasks with feedback and control = A [OK]
- Using services for long tasks needing feedback
- Ignoring feedback and control with topics
- Not supporting preemption in design
Ready to prove it?
Pass the test and this pattern moves unknown
