建立ROS工作空间

mkdir -p  catkin/src
cd catkin

创建工作后,将雷达的ros功能包放在src路径下

Snipaste_2023-03-16_15-02-05

//编译
catkin_make

下载ROS相关功能包

sudo apt-get install ros-kinetic-hector-slam

修改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="laser_frame" />
<param name="odom_frame" value="laser_frame" />


<!-- 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 /laser_frame /laser 100"/>


  <node pkg="rviz" type="rviz" name="rviz"
    args="-d $(find hector_slam_launch)/rviz_cfg/mapping_demo.rviz"/>


</launch>

代码含义

//建图坐标系
<param name="map_frame" value="map" />
//base_frame是基座标系,使用雷达的基座标系
<param name="base_frame" value="laser_frame" />
//odom_frame是里程计坐标系,由于无里程计所以用雷达基座标系代替
<param name="odom_frame" value="laser_frame" />
//发布机器人坐标变换关系
<node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 /laser_frame /laser 100"/>

编译运行

建立hector文件

Snipaste_2023-03-16_15-23-30

连接雷达

//连接雷达
sudo chmod 777 /dev/ttyUSB0

启动雷达节点

cd catkin
//更新环境变量
 source ./devel/setup.bash
//启动雷达
roslaunch rplidar_ros rplidar_s2.launch 

启动hector

cd catkin
//更新环境变量
source ./devel/setup.bash
//启动hecotr
roslaunch rplidar_ros hector_slam.launch

最终效果

Snipaste_2023-03-07_15-25-47

1e00

最后修改:2023 年 11 月 10 日
如果觉得我的文章对你有用,请随意赞赏