? RPLIDAR是低成本的二维雷达解决方案,由SLAMTec公司的RoboPeak团队开发,本次学习使用的是PRLIDAR A2型号的激光雷达,其具有16米测量半径,8000次/秒的测量频率,非常谁和用于构建地图、做SLAM或构建3D模型。
1、创建工作空间
mkdir -p ~/turtlebot_ws/src
cd ~/turtlebot_ws/src
git clone https://github.com/ncnynl/rplidar_ros.git
这一步克隆如果不成功可以多试几次,或者到github上找到包,自己克隆一下
cd ..
catkin_make
2、设置环境变量
`source /turtlebot_ws/devel/setup.bash`
玩过ros的应该都知道这一步
下面配置端口
ls -l /dev |grep ttyUSB
sudo chmod 666 /dev/ttyUSB0
3.运行测试
运行PRLIDAR和并打开rviz查看:
roslaunch rplidar_ros view_rplidar.launch
运行PRLIDAR和查看测试应用
roslaunch rplidar_ros rplidar.launch
新终端打开:
rosrun rplidar_ros rplidarNodeClient
4、构建地图
①hector_mapping包安装:
sudo apt-get install ros-melodic-hector-slam
②创建launch文件:
在rplidar_ros/launch/目录下添加hector_mapping_demo.launch文件
<launch>
? <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">
? <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" />
? <param name="use_tf_scan_transformation" value="true"/>
? <param name="use_tf_pose_start_estimate" value="false"/>
? <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="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" />
? <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>`
如果有错误,请先查看格式缩进是否对应,语言的结束符号/是否加注合格。
③运行测试
运行前查看端口号、给予端口权限:
lsusb
sudo chmod a+rw /dev/ttyUSB0
运行下面的代码:
roslaunch rplidar_ros hector_mapping_demo.launch
roslaunch rplidar_ros rplidar.launch
|