Skip to content

Navigation ​

This tutorial explains how to use Navigation2 (Nav2) for 2D autonomous navigation.

You will learn:

  • How Navigation2 works
  • How to use Navigation2 in practice

What is Navigation2? ​

Navigation2 (Nav2) is a collection of packages in ROS 2 that enables autonomous navigation for mobile robots. It integrates localization, path planning, obstacle avoidance, and path following to move a robot automatically to a given destination.

Main applications:

  • Indoor mobile robots (delivery robots, cleaning robots, etc.)
  • Autonomous navigation for research robots
  • Autonomous driving in competitions and projects
  • Automated control of a Minecraft player

How Navigation2 Works ​

Nav2 consists of several main layers:

Costmap ​

Represents the environment using maps and sensors (e.g., LiDAR). The costmap indicates distances to obstacles, which is essential for planning and safe navigation.

Planner ​

Generates a global path from the start to the goal based on the costmap and robot footprint.

Controller ​

Follows the path generated by the planner. It computes velocity commands from the path and localization data to drive the robot.

Behavior Tree ​

Controls the overall flow of tasks (e.g., navigating to a goal). Tasks are described in an XML tree structure, enabling flexible behaviors beyond just driving.

Requirements ​

  • ROS 2 Humble (Ubuntu 22.04 recommended)
  • Development tools: git, vcstool, colcon, rosdep
  • Repository: minecraft_ros2_example
  • Packages: minecraft_ros2 family (retrieved via .repos file)
  • Minecraft client launched via runClient.sh

Setup Instructions ​

0. Install Development Tools (if not already installed) ​

bash
sudo apt update
sudo apt install -y git python3-vcstool python3-colcon-common-extensions python3-rosdep
# Initialize rosdep (only once)
sudo rosdep init || true
rosdep update

1. Source ROS 2 Environment ​

bash
source /opt/ros/humble/setup.bash

(Ensures ROS_DISTRO=humble is active)

2. Create Workspace & Get Samples ​

Follow the Sample Setup Guide to prepare the sample code.

Run Instructions ​

Terminal 1: Launch Nav2 ​

bash
source ~/ros2_java_ws/install/setup.bash
source ~/minecraft_ros2_example_ws/install/setup.bash
ros2 launch minecraft_ros2_example nav2_bringup.launch.xml
  • Starts Nav2-related nodes
  • Uses the world -> player TF for autonomous navigation

Terminal 2: Launch Minecraft Client ​

bash
cd ~/minecraft_ros2
./runClient.sh
  • Start Minecraft in a superflat world
  • Build walls and equip LiDAR
  • If the costmap shows correctly, setup is successful
  • Use Rviz2 → 2D Goal Pose to send a target position and start autonomous navigation