Navigation2 Tutorials

repository·rolling·Indexed 18 days ago

https://github.com/ros-navigation/navigation2_tutorials

Tutorial 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.

Tokens
1.5K
Snippets
3
Records
10
Agent score
62%

What's inside navigation2_tutorials

  1. How the Pure Pursuit algorithm works

    rolling

    The controller tracks a global path using the following process:

    1. Path Pruning: The global path is continuously pruned to find the point closest to the robot's current position.
    2. Coordinate Transformation: The pruned path is transformed into the robot's local frame.
    3. Lookahead Determination: A lookahead point is identified along the transformed path.
    4. Velocity Calculation: The pure pursuit algorithm uses this lookahead point to calculate the required command velocity to steer the robot toward the target.
  2. Use the Nav2 Lidar Ground Segmentation Demo

    rolling

    This 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

  3. Launch individual simulation components

    rolling

    If 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 the headless argument 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:=false
  4. Use the Sam Bot URDF for Differential Drive Robot Tutorials

    rolling

    This 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.
  5. Train and Integrate a Custom Semantic Segmentation Model

    rolling

    You can use your own trained model by following these steps:

    1. Data Collection: Capture training images from a real robot or Gazebo, ensuring varying lighting and environmental conditions.
    2. Training: Use the Simple Segmentation Toolkit to label and train your model.
    3. Conversion: Convert the trained model to ONNX format using the provided script:
      python3 convert_to_onnx.py
    4. Deployment: Copy the resulting model.onnx to the models/ directory of this package.
    5. Configuration: Ensure the ontology configuration in config/ontology.yaml matches the classes used during your training process.
  6. Launch the Semantic Segmentation Simulation

    rolling

    The semantic_segmentation_sim package provides several launch files to start different components of the simulation environment. Use segmentation_simulation_launch.py to 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:=false
  7. Configure Semantic Segmentation in Nav2

    rolling

    The simulation integrates semantic segmentation into the Nav2 costmap via the semantic_segmentation_layer. This layer works by:

    1. Subscribing to segmentation masks, confidence scores, and point clouds.
    2. Projecting the segmentation data onto the costmap.
    3. Assigning costs based on terrain class (e.g., sidewalk is marked as traversable, while grass is 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.
  8. Semantic Segmentation Node Topics and Interfaces

    rolling

    The semantic_segmentation_node communicates 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).