Navigation2 Tutorials
repository·rolling·Indexed 18 days ago
https://github.com/ros-navigation/navigation2_tutorialsTutorial code and practical examples for the Navigation2 (Nav2) stack. Includes implementations for a Lidar ground segmentation demo, a Pure Pursuit controller plugin, a semantic segmentation node using ONNX Runtime with costmap integration, and the Sam Bot URDF for differential drive robot tutorials.
What's inside navigation2_tutorials
- The Nav2 Pure Pursuit Controller is a plugin implementation of the pure pursuit algorithm designed to track a global path. It is intended as a tutorial reference for writing new Nav2 controller plugins, following the patterns described in the official Nav2 documentation.
How the Pure Pursuit algorithm works
rollingThe controller tracks a global path using the following process:
- Path Pruning: The global path is continuously pruned to find the point closest to the robot's current position.
- Coordinate Transformation: The pruned path is transformed into the robot's local frame.
- Lookahead Determination: A lookahead point is identified along the transformed path.
- Velocity Calculation: The pure pursuit algorithm uses this lookahead point to calculate the required command velocity to steer the robot toward the target.
Use the Nav2 Lidar Ground Segmentation Demo
rollingThis demo provides tutorial code for implementing a ground consistency layer in Nav2. It is designed to work in conjunction with the official Nav2 documentation regarding ground consistency.
Refer to the official Nav2 tutorial for the full context and implementation details: https://docs.nav2.org/tutorials/docs/navigation2_with_ground_consistency_layer.html
Launch individual simulation components
rollingIf you need to run components separately, use the following launch files:
nav2_segmentation_launch.py: Starts the Nav2 navigation stack (including the semantic segmentation costmap layer), the ONNX-based semantic segmentation inference node, and optionally RViz.simulation_launch.py: Starts the Gazebo simulation environment with the Baylands world and spawns the TurtleBot 4 robot. Use theheadlessargument to control the GUI.
# Start Nav2 and segmentation inference ros2 launch semantic_segmentation_sim nav2_segmentation_launch.py rviz:=true # Start Gazebo simulation ros2 launch semantic_segmentation_sim simulation_launch.py headless:=falseUse the Sam Bot URDF for Differential Drive Robot Tutorials
rollingThis package provides a complete implementation of a URDF description for a simple differential drive robot. It is designed to replicate the official Nav2 URDF setup tutorial. It includes all necessary components to get a robot model running in simulation or real hardware for Nav2 testing, including:
- URDF files: The robot's physical description.
- Launch files: To spawn the robot and load configurations.
- Build files: For ROS 2 workspace integration.
- RViz configuration: Pre-configured visualization settings to view the robot model and its state.
Train and Integrate a Custom Semantic Segmentation Model
rollingYou can use your own trained model by following these steps:
- Data Collection: Capture training images from a real robot or Gazebo, ensuring varying lighting and environmental conditions.
- Training: Use the Simple Segmentation Toolkit to label and train your model.
- Conversion: Convert the trained model to ONNX format using the provided script:
python3 convert_to_onnx.py - Deployment: Copy the resulting
model.onnxto themodels/directory of this package. - Configuration: Ensure the ontology configuration in
config/ontology.yamlmatches the classes used during your training process.
Run the Semantic Segmentation Node
rollingTo perform real-time semantic segmentation inference using ONNX Runtime, run the
segmentation_nodeexecutable. The node subscribes to RGB camera images and publishes segmentation masks, confidence maps, and colored overlays.ros2 run semantic_segmentation_node segmentation_nodeLaunch the Semantic Segmentation Simulation
rollingThe
semantic_segmentation_simpackage provides several launch files to start different components of the simulation environment. Usesegmentation_simulation_launch.pyto start the complete stack including Gazebo, the TurtleBot 4 robot, Nav2 with the semantic segmentation costmap layer, and the inference node.Arguments:
use_sim_gui(bool): Launch Gazebo with GUI (default:true).use_rviz(bool): Launch RViz visualization (default:true).
# Launch the complete simulation with GUI and RViz ros2 launch semantic_segmentation_sim segmentation_simulation_launch.py # Launch without GUI and without RViz ros2 launch semantic_segmentation_sim segmentation_simulation_launch.py use_sim_gui:=false use_rviz:=falseConfigure Semantic Segmentation in Nav2
rollingThe simulation integrates semantic segmentation into the Nav2 costmap via the
semantic_segmentation_layer. This layer works by:- Subscribing to segmentation masks, confidence scores, and point clouds.
- Projecting the segmentation data onto the costmap.
- Assigning costs based on terrain class (e.g.,
sidewalkis marked as traversable, whilegrassis marked as danger).
Configuration Files:
config/nav2_params.yaml: Contains Nav2 parameters and the specific configuration for the semantic segmentation layer.config/segmentation_rviz_config.rviz: RViz configuration for visualizing the segmentation results.worlds/baylands.sdf: The Gazebo world file defining the environment.
Semantic Segmentation Node Topics and Interfaces
rollingThe
semantic_segmentation_nodecommunicates via the following ROS2 topics:Subscribed Topics:
/rgbd_camera/image(sensor_msgs/Image): Input RGB camera images.
Published Topics:
/segmentation/mask(sensor_msgs/Image): Segmentation mask containing class IDs (format:mono8)./segmentation/confidence(sensor_msgs/Image): Per-pixel confidence values (format:mono8, range 0-255)./segmentation/overlay(sensor_msgs/Image): Colored overlay visualization (format:bgr8)./segmentation/label_info(vision_msgs/LabelInfo): Class mappings (latched).