《Ubuntu20.04环境下的ROS进阶学习5》

一、Hector_Mapping构建二维地图

在前面我们已经介绍了如何使用激光雷达来扫描地图,如何用激光雷达来建造地图,本节我们将两者结合起来,通过Hector_Mapping功能包实现SLAM。

二、在仿真环境中进行2D SLAM

1、下载Hector_Mapping

sudo apt install ros-noetic-hector-mapping

这里是去ROS官方应用商店下载,您可以参考之前的博客了解相关内容( 《Ubuntu20.04环境下的ROS进阶学习0》-CSDN博客

2、运行gazebo仿真环境

roslaunch wpr_simulation wpb_stage_slam.launch

如果您没有此功能包,您可以去看这篇博客( 《Ubuntu20.04环境下的ROS进阶学习0》-CSDN博客

3、运行Hector_Mapping

rosrun hector_mapping hector_mapping

4、运行rviz三维图形化工具

rosrun rviz rviz

a、添加机器人模型

add RobotModel

b、添加激光雷达扫描测距

add LaserScan

这里将话题改为 /scan 同时将size改为0.03

通过鼠标左键和鼠标中键来调整视角,如果您想了解详细内容可以看我之前的一篇博客 ( 《Ubuntu20.04环境下的ROS进阶学习2》-CSDN博客

c、添加地图

add Map

将地图的话题改为 /Map

d、保存rviz配置

5、运行机器人运动工具

rosrun rqt_robot_steering rqt_robot_steering

控制机器人运动将整个地图建造出来。

三、使用launch文件并修改Hector_Mapping相关参数设置

1、创建新的功能包

cd ~/catkin_ws/src

catkin_creat_pkg learning_launch

cd learning_launch

mkdir launch

如果您之前按照《Ubuntu20.04环境下的ROS学习笔记13》-CSDN博客 来干的话您也有这样的功能包。

2、编写launch文件的代码

cd ~/catkin_ws/src/learning_launch/launch

touch hector_slam.launch

XML 复制代码
<launch>

	<include file = "$(find wpr_simulation)/launch/wpb_stage_slam.launch"/>
	
	<node pkg = "hector_mapping" type = "hector_mapping" name = "hector_mapping"/>
	
	<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find learning_launch)/rviz/hector_slam.rviz"/>
	
	<node pkg = "rqt_robot_steering" type = "rqt_robot_steering" name = "rqt_robot_steering"/>

</launch>

3、运行launch文件

launch文件大部分都不用编译,里面的可执行文件都是现成了,除非您修改过代码。

这里出于保险您可以编译下

cd ~/catkin_ws

catkin_make

source devel/setup.bash 值得一提的是,这一步如果您按照了之前的文章来做,可以省略。(《Ubuntu20.04环境下的ROS学习笔记4》-CSDN博客

到这里编译完成。

roslaunch learning_launch hector_slam.launch

4、对Hector_Mapping进行参数配置

a、了解Hector_Mapping参数

首先登录 index.ros.org 网站搜索一下Hector_Mapping功能包。您也可以直接搜这个网址 hector_mapping - ROS Wiki ,翻到Parameters列表,~后表示参数名,括号里的是(参数的类型 , default:参数的默认值) 再下面就是参数的类型说明。

b、介绍几个简单的参数

1、map_update_distance_thresh

map_update_distance_thresh这个参数是一个双精度浮点数,默认是0.4m。

每次地图更新后,机器人必须位移超过这个阈值,并产生超过map_update_angle_thresh阈值的角度,才会再次更新地图。

2、map_update_angle_thresh

map_update_angle_thresh这个参数是一个双精度浮点数,默认是0.9rad。

每次地图更新后,机器人必须转动超过这个阈值,并产生超过map_update_distance_thresh阈值的位移,才会再次更新地图。

3、map_pub_period

map_pub_period这个参数是一个双精度浮点数,默认是2s

这是地图更新的周期。

您可以修改您的hector_slam.launch文件,实现快速建图,当然也会更消耗资源。

XML 复制代码
<launch>

	<include file = "$(find wpr_simulation)/launch/wpb_stage_slam.launch"/>
	
	<node pkg = "hector_mapping" type = "hector_mapping" name = "hector_mapping">
	
		<param name = "map_update_distance_thresh" value = "0.1"/>
		<param name = "map_update_angle_thresh" value = "0.1"/>
		<param name = "map_pub_period" value = "0.2"/>
	
	</node>
	
	<node pkg = "rviz" type = "rviz" name = "rviz" args = "-d $(find learning_launch)/rviz/hector_slam.rviz"/>
	
	<node pkg = "rqt_robot_steering" type = "rqt_robot_steering" name = "rqt_robot_steering"/>

</launch>

四、参考

Hector_Mapping 年轻人的第一次SLAM建图_哔哩哔哩_bilibili

43.通过launch文件启动Hector_Mapping的建图功能_哔哩哔哩_bilibili

44.Hector_Mapping建图的参数设置_哔哩哔哩_bilibili

相关推荐
水境传感 张园园1 分钟前
土壤蒸渗仪:土壤水分动态的“记录仪”
人工智能
啵啵鱼爱吃小猫咪2 分钟前
一个机械臂抓取项目的复现
人工智能·机器人
LaughingZhu2 分钟前
Product Hunt 每日热榜 | 2025-12-25
人工智能·经验分享·深度学习·神经网络·产品运营
数字化脑洞实验室2 分钟前
智能决策时代的核心引擎——决策优化的力量
人工智能·求解器·决策优化
南山nash2 分钟前
Linux 系统如何释放内存
linux·运维·服务器
2501_940277802 分钟前
如何通过ModelEngine的工程化思维搭建企业级数字资产智能问答助手
人工智能
思成不止于此3 分钟前
【MySQL 零基础入门】事务精讲(三):隔离级别与实战总结
数据库·笔记·学习·mysql
小智RE0-走在路上7 分钟前
Python学习笔记(12) --对象,类的成员方法,构造方法,其他内置方法,封装,继承,多态,类型注解
笔记·python·学习
漫天黄叶远飞14 分钟前
🎄2025年圣诞节,单身的我只能用 Gemini 3 “嘴遁”出了一棵赛博圣诞树
前端·人工智能·gemini
腾飞开源14 分钟前
53_Spring AI 干货笔记之转录API
人工智能·语音转文字·spring ai·azure openai·转录api·openai whisper·统一接口