Actions: how ROS2 handles long tasks without blocking the system
Atlasbot · 16/8/2026 · 11 min read
The article "What is Action in ROS2?" introduced the goal → feedback → result model. What's interesting is that Action is not a completely new protocol — it is built by reassembling the same learned mechanisms: Service and Topic.
Key concepts
Looking under the hood, an Action actually creates:
- 2 Service —
send_goal(client sends goal, server returns acceptance or rejection) andget_result(client asks for final result, server returns when completed) - 1 Topic feedback — server continuously publishes progress here, client subscribes to receive
- 1 Topic status — server publishes current status of goal (waiting, running, canceled...)
Pre-packaging these 4 communication channels into a unified API (ActionClient/ActionServer) saves users from having to manually assemble it themselves — just define a single .action file.
Status machine of a goal
Each goal sent to the action server goes through clear states, managed by the action server:
Goal sent to the server
↓
Server accepted? ──No──► REJECTED
│ Has
▼
EXECUTING ──────────────► CANCELING (if client calls cancel)
│ │
▼ ▼
SUCCEEDED / ABORTED CANCELED
In short: Action is not "new technology" — it is ROS2's way of packaging a common design pattern — a long, scheduled, cancelable task — from the exact same Topic and Service bricks that are already there, plus a state machine to neatly manage the goal lifecycle.
How it works
File .action defines all three goal/result/feedback parts in one file, separated by ---:
# NavigateToPose.action
geometry_msgs/PoseStamped pose # Goal
---
std_msgs/Empty result # Result
---
geometry_msgs/PoseStamped current_pose # Feedback
float32 distance_remaining
Send goal and cancel midway using Python code:
goal_handle = await action_client.send_goal_async(goal_msg, feedback_callback=on_feedback)
# ... after a while, I wanted to cancel halfway through
if muon_huy:
await goal_handle.cancel_goal_async() # Move goal to CANCELING status
In reality, NavigateToPose is the action that Nav2 provides to receive the command "move the robot to a point" - every time a goal is set on RViz, behind it is the correct flow to send the goal → receive continuous current position feedback → receive the result when the robot reaches the destination.
Technical details
Parameters
Some popular standard actions available in the ROS2/Nav2 ecosystem — knowing the name and type in advance helps avoid having to redefine an existing action yourself:
| Action | Package | Used for |
|---|---|---|
NavigateToPose | nav2_msgs | Move the robot to a destination point |
FollowWaypoints | nav2_msgs | Moves through multiple points in order |
ComputePathToPose | nav2_msgs | Only calculates the path, does not actually move |
FollowJointTrajectory | control_msgs | Controls the manipulator/arm according to |
Protocol
The goal published status on topic status uses the correct set of standardized integer codes in action_msgs/msg/GoalStatus: STATUS_ACCEPTED=1, STATUS_EXECUTING=2, STATUS_CANCELING=3, STATUS_SUCCEEDED=4, STATUS_CANCELED=5, STATUS_ABORTED=6 — all actions in the ROS2 ecosystem (no matter which package is written) use the same code set, helping tools like ros2 action info or RViz displays a consistent state regardless of the specific action.
Practical applications
preemption mechanism (replace running goal with new goal) is a common behavior when operating real AMR — if the operator sets a new destination on RViz while the robot is moving to the old one, Nav2 automatically cancels the old goal (switches to CANCELED) and starts the new goal immediately, without waiting for the robot to complete the old journey first. How to design an action server with preemption or not (only accept 1 goal at a time, reject a new goal if busy, or self-destruct the old goal to receive a new goal) is an important architectural decision depending on the task — with AMR robots, preemption is often the desired behavior to quickly respond to plan changes.
Practical example
$ ros2 action info /navigate_to_pose -t
Output:
Action: /navigate_to_pose
Action clients: 1
/rviz_navigation_dialog
Action servers: 1
/bt_navigator
Action type: nav2_msgs/action/NavigateToPose
ros2 action info -t shows the exact type of action, along with a list of connected clients/servers - the first diagnostic tool when a goal sent from RViz does not see any reaction from the robot, helping to immediately determine whether it is due to a lack of server (Nav2 has not been started) or due to other problems in the goal processing logic.
Common mistakes
- Assume the server always accepts goal — does not check whether the
send_goal_asyncresult isREJECTEDbefore continuing to wait for feedback/result — if the server refuses (eg: goal is outside the known map), the code still waits in vain for a result that will never arrive in the expected flow. - Only looking at feedback on good progress but forgetting to check the final result — feedback reporting 95% progress does not guarantee the goal will be
SUCCEEDED— the robot can absolutelyABORTEDright before reaching the destination (eg: an obstacle suddenly appears) — always checkstatusin the result, do not infer from the feedback. - Action server does not periodically check the cancel flag in the execution loop — if the server-side code does not call the
goal_handle.is_cancel_requestedcheck regularly while processing a long goal, the cancel request from the client will not take effect immediately, may be significantly delayed, or be completely ignored. - Not properly releasing/tracking old
goal_handlewhen sending new goal — keeping a reference to a completed/destroyed goal handle and still operating on it (e.g. callingcancel_goal_asyncon an alreadySUCCEEDEDgoal) can cause errors or undefined behavior.
Conclusion
Action is an intentional combination of Service (goal, get_result) and Topic (feedback, status), packaged into a unified API for the "long, scheduled, cancelable" task pattern very popular in robotics — most notably Nav2. Understanding the goal state machine properly and always checking the final result (not just relying on feedback) is an essential skill when integrating with any action server. The next article in this section is about QoS — the policy that determines the reliability of both Topic, Service, and Action.
Get new articles and lessons by email
When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.
Unsubscribe any time with the link in each email. See our Privacy policy.