Autonomous Navigation in ROS2 with Nav2 and Behavior Tree

In this tutorial, you will learn how to perform autonomous navigation in ROS2 using the Nav2 stack with integrated Behavior Trees (BT). The Nav2 framework provides a powerful modular system that allows robots to navigate in a known map using planning, localization, and behavior control components. 

 📝 Requirements 

  • – ROS2 installed (e.g., Humble or Foxy) 
    – A robot simulation (e.g., TurtleBot3 in Gazebo) 
    – `nav2_bringup` package and configured parameters 
    Pre-built map and localization (AMCL) 
    RViz for goal setting and diagnostics 

Step 1: Launch Nav2 stack 

Launch the full Nav2 stack including AMCL and map loading: 

ros2 launch nav2_bringup bringup_launch.py use_sim_time:=True map:=/path/to/map.yaml 

 

🖥️Step 2: Send a Navigation Goal

In RViz, click on the ‘Nav2 Goal’ tool and select a target pose. This will initiate the autonomous navigation behavior tree to begin planning and execution. 

b2fbd169-8fdd-4fb0-85d5-17e338610211

Step 3: Understand the Behavior Tree Execution 

Nav2 uses a Behavior Tree (BT) to structure the navigation task. This BT includes conditions and actions like path planning, obstacle checking, controller execution, and recovery behaviors. You can visualize the current tree being executed by launching the Behavior Tree visualizer: 

 

ros2 run nav2_bt_navigator bt_navigator_cli –print_tree 

🛠️Step 4: Reach the Goal and Confirm Success

If all goes well, the robot should reach the target location while avoiding obstacles. You can monitor the result in RViz or through logs. On success, the BT transitions to an idle state. 

🛠️Step 5: Troubleshooting 

– Robot doesn’t move:

ensure all Nav2 nodes are running (e.g., controller_server, planner_server). 
– Planning failed:

check the map and robot pose accuracy. 
– BT gets stuck:

verify the recovery behaviors are active and well defined in the XML tree. 
– Localization drift:

use AMCL parameters tuning or re-initialize robot pose in RViz.

Want to learn more?

You can find a detailed explaination of the autonomous navigation in the "Self Driving and ROS - Learn by Doing! Odometry and Control" course
DISCOUNT
en_US