Skip to content

5_Nav2_Tips

Arseni1919 edited this page Jul 31, 2025 · 7 revisions

🏠 Home

Nav2 Tips

This document provides a collection of useful tips, commands, and concepts for working with the ROS 2 Navigation Stack (Nav2).

Tutorials and Documentation

Core Concepts

Screenshot from 2025-07-26 21-29-04.png

Required TF Transformations

Nav2 requires the following transform tree to be published:

map → odom → base_link → <sensor_frame>
  • map → odom: Usually published by a localization system like AMCL or SLAM.
  • odom → base_link: Published by an odometry source (e.g., wheel encoders, IMU).
  • base_link → <sensor_frame>: Published by a robot_state_publisher based on your URDF.

Costmap Layers

The costmap consists of multiple layers that contribute to a cell's overall cost. The package is plugin-based, allowing for custom layers.

  • Static Layer: Represents the static map, usually from a SLAM-generated map published to the /map topic.
  • Obstacle Layer: Includes objects detected by sensors publishing LaserScan or PointCloud2 messages.
  • Voxel Layer: Similar to the obstacle layer but handles 3D data from LaserScan or PointCloud2.
  • Range Layer: Incorporates information from sonar and infrared sensors.
  • Inflation Layer: Adds a cost buffer around lethal obstacles to account for the robot's geometry and prevent collisions.

Robot Footprint

The robot's footprint can be defined in two ways:

  • robot_radius: A simple circular approximation.
  • footprint: A more accurate polygon representing the robot's actual shape.

If both are defined, the footprint polygon is used. The footprint can be dynamically updated via the ~/footprint topic to reflect changes in the robot's shape (e.g., moving a manipulator).

Launching and Running

Launching SLAM

To bring up slam_toolbox for mapping:

ros2 launch slam_toolbox online_async_launch.py use_sim_time:=true

Launching Nav2 Stack

To launch the full Nav2 stack, run these commands in order, waiting for each to initialize:

  1. Launch Robot Description, RViz, and Gazebo:

    ros2 launch ros_gz_example_bringup diff_drive.launch.py
  2. Launch SLAM Toolbox (wait for "Registering sensor" in the logs):

    ros2 launch slam_toolbox online_async_launch.py use_sim_time:=true
  3. Launch Nav2 (wait for "Creating bond timer" in the logs):

    ros2 launch nav2_bringup navigation_launch.py use_sim_time:=true

Visualization

Visualizing Costmap Voxels

To visualize the voxel representation of detected objects in RViz, run:

ros2 run nav2_costmap_2d nav2_costmap_2d_markers voxel_grid:=/local_costmap/voxel_grid visualization_marker:=/my_marker

Nav2 Nodes

Round Robin

Nav2 Docs | Control: RoundRobin

Profiling

  • Run:
valgrind --tool=callgrind ros2 run <package> <executable>
  • Run your ROS2 scenario (publish topics, call services, etc.)
  • Stop profiling with callgrind_control -d or Ctrl+C
  • Run:
kcachegrind callgrind.out.<pid> to analyze results

Essential Nav2 Documentation

General Tutorials

Core Documentation


🏠 Home

Clone this wiki locally