--- name: bt-action-nodes-nav2 description: 'Use Nav2 BT action nodes. Use when adding NavigateToPose, ComputePathToPose, FollowPath, Spin, BackUp, Wait, or ClearCostmap actions.' --- # Nav2 Built-in Action BT Nodes ## Core Navigation Actions ### NavigateToPose The primary single-goal navigation action. Calls the `/navigate_to_pose` action server, which internally runs its own BT for planning, controlling, and recovery. ```xml ``` | Port | Direction | Type | Description | |------------------|-----------|---------------------------|--------------------------------| | goal | input | PoseStamped | Target pose | | behavior_tree | input | string | Override BT XML path (optional)| | server_name | input | string | Action server name | | server_timeout | input | int (ms) | Server connection timeout | | error_code_id | output | uint16 | Error code on failure | ### NavigateThroughPoses Multi-goal variant. Sends all goals at once to the planner for a single optimized path: ```xml ``` | Port | Direction | Type | Description | |------------------|-----------|----------------------------|--------------------------------| | goals | input | vector\ | Ordered list of poses | | error_code_id | output | uint16 | Error code on failure | ### ComputePathToPose Calls the planner server to compute a path without executing it. This is the planning-only action: ```xml ``` | Port | Direction | Type | Description | |------------------|-----------|---------------|------------------------------------| | goal | input | PoseStamped | Target pose | | start | input | PoseStamped | Start pose (default: current pose) | | planner_id | input | string | Which planner plugin to use | | path | output | Path | Computed path | | error_code_id | output | uint16 | Planning error code | ### ComputePathThroughPoses Multi-goal planning variant: ```xml ``` ### FollowPath Sends a precomputed path to the controller server for execution: ```xml ``` | Port | Direction | Type | Description | |------------------|-----------|--------|-------------------------------------| | path | input | Path | Path to follow | | controller_id | input | string | Which controller plugin to use | | goal_checker_id | input | string | Which goal checker to use | | progress_checker_id | input | string | Which progress checker to use | | error_code_id | output | uint16 | Controller error code | ## The Compute → Follow Pipeline The fundamental Nav2 BT pattern connects planner output to controller input via the blackboard: ```xml ``` The `{path}` blackboard variable is the bridge: `ComputePathToPose` writes it (output port), `FollowPath` reads it (input port). This decoupling allows inserting path smoothing between them: ```xml ``` ## Recovery and Behavior Actions ### Spin Rotates the robot in place. Useful for clearing costmap artifacts or looking around: ```xml ``` | Port | Direction | Type | Description | |------------|-----------|--------|----------------------------------| | spin_dist | input | double | Rotation angle in radians | | time_allowance | input | int (ms) | Max time for the behavior | ### Wait Pauses for a duration. Does not halt other branches in a Parallel node: ```xml ``` ### BackUp Drives the robot backward: ```xml ``` | Port | Direction | Type | Description | |--------------|-----------|--------|--------------------------| | backup_dist | input | double | Distance in meters | | backup_speed | input | double | Speed in m/s | | time_allowance | input | int | Max time in seconds | ### DriveOnHeading Drives in a straight line on the current heading: ```xml ``` ### AssistedTeleop Blends teleoperation commands with obstacle avoidance: ```xml ``` ## Costmap Actions ### ClearEntireCostmap Resets a costmap layer completely. Use for global or local costmaps: ```xml ``` ### ClearCostmapExceptRegion Clears the costmap except within a radius around the robot: ```xml ``` ### ClearCostmapAroundRobot Clears the costmap within a radius around the robot: ```xml ``` ## Localization Actions ### ReinitializeGlobalLocalization Scatters AMCL particles uniformly for global relocalization: ```xml ``` Use as a last-resort recovery—the robot loses its localization confidence and must re-converge. ## Path Smoothing ### SmoothPath Applies a smoother plugin to a path: ```xml ``` Note: you can write the smoothed output back to the same blackboard variable (`smoothed_path="{path}"`) to replace the original path in-place. ## Error Code Propagation Every Nav2 action node has an `error_code_id` output port. Error codes are defined in `nav2_msgs/action/` for each action type. Common codes: | Code | Meaning | |------|--------------------------------------------------| | 0 | No error (success) | | 100 | Unknown / unspecified | | 101 | TF error | | 102 | Start/goal occupied | | 103 | Start/goal outside map | | 104 | Timeout | | 105 | No valid path found | | 106 | Patience exceeded (progress checker) | You can use the error code in downstream logic: ```xml