-
Notifications
You must be signed in to change notification settings - Fork 0
5_Nav2_Tips
This document provides a collection of useful tips, commands, and concepts for working with the ROS 2 Navigation Stack (Nav2).
- Behavior Tree (BT) Tutorials: Getting Started with Behavior Trees
- Configuring EKF (robot_localization): EKF Configuration Guide
- Sample EKF Configuration: ekf.yaml on GitHub
- Preparing Sensor Data for robot_localization: Sensor Data Preparation Guide

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 arobot_state_publisherbased on your URDF.
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
/maptopic. -
Obstacle Layer: Includes objects detected by sensors publishing
LaserScanorPointCloud2messages. -
Voxel Layer: Similar to the obstacle layer but handles 3D data from
LaserScanorPointCloud2. - 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.
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).
To bring up slam_toolbox for mapping:
ros2 launch slam_toolbox online_async_launch.py use_sim_time:=trueTo launch the full Nav2 stack, run these commands in order, waiting for each to initialize:
-
Launch Robot Description, RViz, and Gazebo:
ros2 launch ros_gz_example_bringup diff_drive.launch.py
-
Launch SLAM Toolbox (wait for "Registering sensor" in the logs):
ros2 launch slam_toolbox online_async_launch.py use_sim_time:=true
-
Launch Nav2 (wait for "Creating bond timer" in the logs):
ros2 launch nav2_bringup navigation_launch.py use_sim_time:=true
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_markerNav2 Docs | Control: RoundRobin
- 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- Rotation Shim Controller: Rotate in place before movement
- Dynamic Object Following: A simple BT structure to follow somebody
- Keepout Zones Filter: Filter for costmaps to define no-go areas
- Speed Limits Filter: Filter for costmaps to enforce speed restrictions
- Docking Server: Automated docking capabilities
- Adding a Smoother to BT: Adding a smoother right after Path Planner completes
- Collision Monitor: Real-time collision detection and response
- Denoise Layer: Filtering noise-induced obstacles (Config Guide)
- Camera Calibration: Camera setup and calibration procedures
- Profiling: Performance analysis and optimization
- Docker in ROS: Development environment setup with Docker
- Configuration Guide: Comprehensive configuration reference for all Nav2 components
- Behavior Trees: Complete guide to Nav2's behavior tree system
- Navigation Plugins: Available plugins and how to create custom ones
- Simple Commander API: Python API for programmatic navigation control
Cassini Robotics