Performance: Preempting actions
Preempting actions affects how quickly a robot can respond to new commands by interrupting ongoing tasks, impacting interaction responsiveness.
if action_client.is_active(): action_client.cancel_goal() action_client.send_goal(new_goal) # Use preempt to cancel current goal if new one arrives
action_client.send_goal(goal) # Waits for current action to finish before accepting new goals # No preemption logic implemented
| Pattern | CPU Usage | Response Delay | User Experience | Verdict |
|---|---|---|---|---|
| No preemption | Low during action | High (waits for completion) | Poor responsiveness | [X] Bad |
| Preempting actions | Moderate (due to cancelling overhead) | Low (immediate switch) | Good responsiveness | [OK] Good |
What does cancel_goal() do in ROS action clients?
cancel_goal()cancel_goal() specifically requests stopping the current goal.cancel_goal() stops current goal [OK]Which of the following is the correct sequence to preempt an action in ROS?
1. cancel_goal()
2. send_goal(new_goal)cancel_goal() first ensures the old task stops, then send_goal(new_goal) starts the new task.Given this ROS action client code snippet, what will be the output behavior?
client.send_goal(goal1)
client.cancel_goal()
client.send_goal(goal2)What happens to goal1 and goal2?
goal1, cancel_goal() requests to stop it immediately.goal2goal2 after canceling goal1 starts the new action goal.Identify the error in this ROS action client code snippet:
client.send_goal(goal1)
client.send_goal(goal2)
client.cancel_goal()What is wrong with this sequence?
cancel_goal() after both sends only cancels the currently active goal, not preempting properly between goals.You want to preempt a running action only if it has been active for more than 5 seconds. Which approach correctly implements this logic?
if client.get_state() == ACTIVE and client.get_time_active() > 5:
client.cancel_goal()
client.send_goal(new_goal)Pass the test and this pattern moves unknown