Skip to content

na24b064/lidar_2d_mapping

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simultaneous Mapping And Localization using 2D LiDAR in ROS2

This project demonstrates 2D mapping and robot localization using LiDAR with slam_toolbox in ROS 2. The package enables autonomous mapping of environments and subsequent robot localization within those maps using a differential drive robot in Gazebo simulation. Check out the 2d mapping and localization here.

System Requirements

  • Ubuntu: 24.04 LTS
  • ROS 2: Jazzy Jalapa
  • Gazebo: Harmonic

Usage

Prerequisites

Install required ROS 2 packages:

sudo apt install ros-jazzy-robot-state-publisher \
                 ros-jazzy-joint-state-publisher \
                 ros-jazzy-xacro \
                 ros-jazzy-teleop-twist-keyboard \
                 ros-jazzy-ros-gz-sim \
                 ros-jazzy-ros-gz-bridge \
                 ros-jazzy-slam-toolbox 

Installation & Setup

  1. Create Workspace and Clone Repository
mkdir -p my_ws/src && cd my_ws/src
git clone https://github.com/yashikasharma0301/lidar_2d_mapping.git
  1. Build the Workspace
cd ..
colcon build
  1. Source the Workspace
source install/setup.bash

Running the Simulation

Phase 1: 2D Mapping

  1. Launch Robot with LiDAR in Gazebo
ros2 launch lidar_2d_mapping gazebo_spawn.launch.py
  1. Start SLAM Mapping
  • In a new terminal:
cd my_ws
source install/setup.bash
ros2 launch lidar_2d_mapping slam_mapping.launch.py
  • Wait for a minute and let it load
  1. Create the Map
  • In Gazebo, open the teleop plugin to control the robot

    image
  • Move the robot around the environment to generate a comprehensive map

  • Monitor the mapping progress in RViz

    image
  1. Save the Map
  • In RViz's "SlamToolboxPlugin" panel, enter the location where you want to save the map infront of the Serialize Map button :

    /home/YOUR_USERNAME/my_ws/src/lidar_2d_mapping/maps/map_serialize
    

    Replace YOUR_USERNAME with your actual username

  • Click on Serialize Map to save the generated map

    image
  • Saving the map in Save Map allows you to use the map for external environments also whearas to use the map with slam_toolbox, you need to save the serialized map

  • Close the mapping terminal once mapping is complete

Phase 2: Robot Localization

  1. Configure Localization Parameters
gedit ~/my_ws/src/lidar_2d_mapping/params/mapper_params_localization.yaml
image
  • Update the map_file_name parameter with your saved map location
  • Optionally, set your preferred initial pose using the map_start_pose parameter
  • Save and close the file
  • Close all the terminals
  1. Launch Localization
  • In a new terminal rebuild the workspace and launch the gazebo world again:
cd my_ws
colcon build
source install/setup.bash
ros2 launch lidar_2d_mapping gazebo_spawn.launch.py
  • In another terminal:
cd my_ws
source install/setup.bash
ros2 launch lidar_2d_mapping slam_localization.launch.py
  1. Test Localization
  • Use the Gazebo teleop plugin to move the robot

  • Observe how the robot localizes itself within the previously created map

    image

Credits & References

Robot Model: This project uses a URDF model adapted from the TortoiseBot example in the OSRF ROS Book. The original model has been modified for ROS 2 Jazzy and Gazebo Harmonic integration with LiDAR sensor capabilities.

Original Authors: Open Source Robotics Foundation (OSRF)

About

ROS2 package to perform 2D mapping and robot localization using LiDAR with slam_toolbox

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 75.7%
  • CMake 24.3%