首先创建工作空间rplidar_test文件夹。
一、 新建一个文件夹并clone
mkdir -p ~/rplidar_test/src
cd ~/rplidar_test/src
git clone https://gitee.com/h_yun/rplidar_ros.git
二、编译
cd ..
catkin_make
*******当创建工作空间编译时,出现该错误***********
1、 Unable to find either executable 'empy' or Python module 'em'... try installing the package 'python3-empy'
解决办法:catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3(调整python版本)
2、配置环境变量,使用以下命令行:
source devel/setup.bash
配置环境变量
source devel/setup.bash
三、建图基本步骤:
1、运行roscore
2、新开一个终端 运行
cd ~/rplidar_test
. devel/setup.bash
注:第一次运行还需打开串口权限,
1 ls -l /dev |grep ttyUSB
2 ls -l /dev |grep ttyUSB(看是否显示设备,如果用的是虚拟机的话,需要把雷达接口设备映射到虚拟机上)
3 sudo chmod 666 /dev/ttyUSB0(打开设备接口权限)
运行
roslaunch rplidar_ros view_rplidar.launch
此时出现点云图
3、建图安装hector_mapping包
sudo apt-get install ros-noetic-hector-slam
4、新建一个slam.launch文件(建图用的包)
内容如下
<launch>
<include file="$(find rplidar_ros)/launch/rplidar.launch" />
<node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">
<!-- Frame names -->
<param name="pub_map_odom_transform" value="true"/>
<param name="map_frame" value="map" />
<param name="base_frame" value="base_link" />
<param name="odom_frame" value="base_link" />
<!-- Tf use -->
<param name="use_tf_scan_transformation" value="true"/>
<param name="use_tf_pose_start_estimate" value="false"/>
<!-- Map size / start point -->
<param name="map_resolution" value="0.05"/>
<param name="map_size" value="512"/>
<param name="map_start_x" value="0.5"/>
<param name="map_start_y" value="0.5" />
<param name="laser_z_min_value" value = "-1.0" />
<param name="laser_z_max_value" value = "1.0" />
<param name="map_multi_res_levels" value="2" />
<param name="map_pub_period" value="2" />
<param name="laser_min_dist" value="0.4" />
<param name="laser_max_dist" value="5.5" />
<param name="output_timing" value="false" />
<param name="pub_map_scanmatch_transform" value="true" />
<!--<param name="tf_map_scanmatch_transform_frame_name" value="scanmatcher_frame" />-->
<!-- Map update parameters -->
<param name="update_factor_free" value="0.4"/>
<param name="update_factor_occupied" value="0.7" />
<param name="map_update_distance_thresh" value="0.2"/>
<param name="map_update_angle_thresh" value="0.06" />
<!-- Advertising config -->
<param name="advertise_map_service" value="true"/>
<param name="scan_subscriber_queue_size" value="5"/>
<param name="scan_topic" value="scan"/>
</node>
<node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 /base_link /laser 100"/>
<node pkg="rviz" type="rviz" name="rviz"
args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/>
</launch>
5、打开slam
roslaunch rplidar_ros slam.launch
6、出现建图图片
7、保存地图
sudo apt-get install ros-noetic-map-server(安装对应的软件包)
rosrun map_server map_saver -f ~/my_map(保存到主目录下,可以改动)
若出现以下错误:
RLException: [slam.launch] is neither a launch file in package [rplidar_ros] nor is [rplidar_ros] a launch file name The traceback for the exception was written to the log file
解决方案:
https://blog.csdn.net/weixin_44436677/article/details/106442240
参考具体文档:
https://blog.csdn.net/m0_56895840/article/details/127612897
https://blog.csdn.net/weixin_44046400/article/details/85008724
https://blog.csdn.net/weixin_41459903/article/details/102795148
https://blog.csdn.net/hangtianxia/article/details/117529049