首先在思岚官网下载rplidar_s1的ROS功能包(官网的下载和支持里),新建工作空间catkin_ws/src
接下来安装配置思岚RPLIDAR S1,首先在github上下载它的ROS包。
在工作空间的src下面下载官网ROS包。
git clone https://github.com/Slamtec/rplidar_ros.git
检查rplidar的串行端口的权限:
ls -l / dev | grep ttyUSB
- 1
添加写权限:(例如/ dev / ttyUSB0)
chmod 666 / dev / ttyUSB0
启动一个rplidar节点并在rviz中查看扫描结果(点云显示)
#记得启动之前启动roscore
source devel/setup.bash
roslaunch rplidar_ros view_rplidar_s1.launch
在前面的章节我们在ROS上测试了思岚RPLIDAR S1的功能以及雷达点云图:
ROS学习08-NVIDIA JETSON TX2安装配置激光雷达-思岚RPLIDAR S1(在Rviz上显示点位图)
但是我们如果要把渲染出来的地图保存出来的话就需要借助gmapping等其他工具了,由于gmapping构建的话相对来说有点复杂,我们这节使用一个简单点的hector_mapping来构建地图。
hector_mapping包安装
sudo apt-get install ros-melodic-hector-slam
创建launch文件
在rplidar_ros/launch/目录下添加hector_mapping_demo.launch文件
vim hector_mapping_demo.launch
<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="2048"/>
<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="rplidar_ros" type="rplidarNode" name="rplidarNode" output="screen">
<param name="serial_port" type="string" value="/dev/ttyUSB0"/>
<param name="serial_baudrate" type="int" value="265000"/>
<param name="frame_id" type="string" value="laser"/>
<param name="inverted" type="bool" value="false"/>
<param name="angle_compensate" type="bool" value="true"/>
</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>
(注意:如果使用的激光雷达,不是rplidar_s1,而是rplidar_s2 ,要修改波特率,上文红色字体,修改为1000000)
catkin_make编译完成后记得source
source devel/setup.bash
启动launch文件
roslaunch rplidar_ros hector_mapping_demo.launch
如果没反应的话试试再开一个终端运行一下rplidar_s1.launch文件
roslaunch rplidar_ros rplidar_s1.launch
如果要保存地图的话
我们需要使用map_server软件包里的map_saver来保存当前的地图,首先需要保证已经安装了map_server软件包,安装命令如下:
sudo apt-get install ros-melodic-map-server
当安装好map_server后,接下来就可以使用如下命令来保存地图了,在stdr_gmapping的maps目录下执行命令如下:
rosrun map_server map_saver map:=/hector_map -f mymap
所遇问题及解决方法:
一.运行此命令:roslaunch rplidar_ros hector_mapping_demo.launch
报错如下:
Resource not found: hector_slam_launch
ROS path [0]=/opt/ros/melodic/share/ros
ROS path [1]=/home/ytzn/catkin_ws/src
ROS path [2]=/opt/ros/melodic/share
The traceback for the exception was written to the log file
原 因:没有安装hector_mapping 算法
解决方法:
hector_mapping包安装
sudo apt-get install ros-melodic-hector-slam
二.
报错如下:
ERROR: cannot launch node of type [rplidar_ros/rplidarNode]: Cannot locate node of type [rplidarNode] in package [rplidar_ros]. Make sure file exists in package path and permission is set to executable (chmod +x)
原 因:没有编译
方 法:回到工作空间目录下 catkin_make