Welcome to SLAM LiDAR repository
2.Handheld lidar mapping
2.Handheld lidar mapping
This function needs to start the program in the slam_gmapping function package. The source code is located in the [rplidar_ws] source code file.
Here we use the supporting virtual machine to explain how to start the program. If you want to put it on your own motherboard, you need to put [slam_gmapping] and [openslam_gmapping] in the src directory of the workspace to compile.
2.1 Start gmapping mapping
Input following command:
ros2 launch rplidar_ros test_gmapping.launch.py

rviz displays as follows:

2.2 View node communication
Input following command:
xxxxxxxxxxros2 run rqt_graph rqt_graph
2.3 View TF tree
Input following command:
xxxxxxxxxxros2 run tf2_tools view_frames.py

In the directory where the command terminal is started, the system will generate a frames.pdf file, which is the generated TF tree.

2.4 launch file analysis
File path (combined with virtual machine):
xxxxxxxxxx/home/yahboom/rplidar_ws/src/rplidar_ros-dev-ros2/launch/test_gmapping.launch.pytest_gmapping.launch.py
xfrom launch import LaunchDescriptionfrom launch_ros.actions import Node import osfrom launch.actions import IncludeLaunchDescriptionfrom launch.conditions import LaunchConfigurationEquals,LaunchConfigurationNotEqualsfrom launch.launch_description_sources import PythonLaunchDescriptionSource,AnyLaunchDescriptionSourcefrom ament_index_python.packages import get_package_share_directoryfrom launch.actions import DeclareLaunchArgumentimport os
def generate_launch_description(): LIDAR_TYPE = os.getenv('LIDAR_TYPE') lidar_type_arg = DeclareLaunchArgument(name='lidar_type', default_value=LIDAR_TYPE, description='The type of lidar') lidar_launch = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(get_package_share_directory('rplidar_ros'), 'launch'),'/lidar.launch.py'])) s2_gmapping_launch = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(get_package_share_directory('slam_gmapping'), 'launch'),'/s2_gmapping_launch.py']),condition=LaunchConfigurationEquals('lidar_type', 's2')) gmapping_launch = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(get_package_share_directory('slam_gmapping'), 'launch'),'/gmapping_launch.py']),condition=LaunchConfigurationNotEquals('lidar_type', 's2')) s2_slam_gmapping_launch = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(get_package_share_directory('slam_gmapping'), 'launch'),'/s2_slam_gmapping.launch.py']),condition=LaunchConfigurationEquals('lidar_type', 's2')) slam_gmapping_launch = IncludeLaunchDescription(PythonLaunchDescriptionSource([os.path.join(get_package_share_directory('slam_gmapping'), 'launch'),'/slam_gmapping.launch.py']),condition=LaunchConfigurationNotEquals('lidar_type', 's2')) return LaunchDescription([ lidar_type_arg, lidar_launch, s2_gmapping_launch, s2_slam_gmapping_launch, gmapping_launch, slam_gmapping_launch ]) [lidar_type_arg] Gets the value of [LIDAR_TYPE] set in the environment variable, and starts the corresponding lidar and corresponding mapping instructions based on this value.
[lidar_launch] launch lidar launch file, the file is located at /home/yahboom/rplidar_ws/src/rplidar_ros-dev-ros2/launch/lidar.launch.py
[s2_gmapping_launch] Start S2/S2L lidar gmapping mapping. Here you need to remap the lidar topic into a filtered lidar topic. The file is located
/home/yahboom/rplidar_ws/src/slam_gmapping/launch/s2_gmapping_launch.py
[s2_slam_gmapping_launch] Release some necessary static TF transformations and startup rviz for S2/S2L mapping lidar. The file is located at /home/yahboom/rplidar_ws/src/slam_gmapping/launch/s2_slam_gmapping.launch.py
[gmapping_launch] Other lidar gmapping mapping, the file is located in /home/yahboom/rplidar_ws/src/slam_gmapping/launch/gmapping_launch.py
[slam_gmapping_launch] Release some necessary static TF transformations and launch rviz for other lidar mapping. The file is located at /home/yahboom/rplidar_ws/src/slam_gmapping/launch/slam_gmapping.launch.py