Creating an Environment Map with SLAM
SLAM (Simultaneous Localization and Mapping) refers to an algorithm that performs estimation of the current position and map generation simultaneously. Moby-RP has implemented SLAM using Cartographer.
Preparation
- For the operation of the SLAM algorithm, Moby's control node and LiDAR node must be running. Please run the Moby Control Node according to the instructions in the Moby Control Node Execution chapter.
How to run
1. Launch the SLAM node
-
You can run the Cartographer node for SLAM with the following command:
-
Now, the RViz window opens, and you can see the map being displayed. You can observe the LaserScan measurement points being recorded as black obstacle areas.
2. Drawing the map
- As you move the robot using the joystick, you can see the areas recognized by the robot's field of view are gradually updated on the RViz screen's map.
- For robot operation using the joystick, please refer to the Basic Operation.
3. Saving the map
-
You can save the map drawn so far using the command below. Open a new terminal and enter the desired file path in file_path and execute the following command.
-
Example:
-
Once the map generation is complete, return to the terminal where you ran the cartographer node and terminate the node.
-
Running the command in the example above will create the following two files at the specified path:
- ~/default_map.pgm : Map image file
- ~/default_map.yaml : Metadata file for the map and origin
4. Editing the map
- You can open and edit the generated *.pgm file using an image editing tool like GIMP.
- Black is the area confirmed as an obstacle ( #000000 ).
- Gray is the area not confirmed by LiDAR ( #CDCDCD ).
- White is the area confirmed to be free of obstacles ( #FFFFFF ).
- You can directly draw and add obstacles that the sensor cannot detect, such as glass or low steps, or erase wrongly recognized obstacles.
Configuration of cartographer.launch.py file
- The configuration information for Cartographer is defined in the Lua script located in the following path. For information about this file, refer to the Read the Docs of Cartographer ROS.
moby-ros2/moby_mapping/param/moby_lds_2d.lua
- When running cartographer.launch.py, you can specify the following options in the command line depending on the situation:
Name | Type | Description | Default Value |
---|---|---|---|
cartographer_config_dir | string | Path where the Cartographer config file is located | ~/ros2_ws/install/ moby_navigation/share/ moby_mapping/config |
configuration_basename | string | Cartographer config file name | moby_lds_2d.lua |
resolution | float | Size (m) of each pixel in the map image that will be occupied in the actual environment | 0.05 |
publish_period_sec | float | Frequency of map data publication | 1.0 |
launch_rviz | bool | Execution status of RViz screen | true |