亚博microros小车-原生ubuntu支持系列:17 gmapping

前置依赖

先看下亚博官网的介绍

Gmapping简介

  • gmapping只适用于单帧二维激光点数小于1440的点,如果单帧激光点数大于1440,那么就会出【[mapping-4] process has died】 这样的问题。

  • Gmapping是基于滤波SLAM框架的常用开源SLAM算法。

  • Gmapping基于RBpf粒子滤波算法,即时定位和建图过程分离,先进行定位再进行建图。

  • Gmapping在RBpf算法上做了两个主要的改进:改进提议分布和选择性重采样。

优点:Gmapping可以实时构建室内地图,在构建小场景地图所需的计算量较小且精度较高。

缺点:随着场景增大所需的粒子增加,因为每个粒子都携带一幅地图,因此在构建大地图时所需内存和计算量都会增加。因此不适合构建大场景地图。并且没有回环检测,因此在回环闭合时可能会造成地图错位,虽然增加粒子数目可以使地图闭合但是以增加计算量和内存为代价。

底层转换

ros2 launch yahboomcar_bringup yahboomcar_bringup_launch.py      #底层数据程序

参见:https://blog.csdn.net/bohu83/article/details/145394204

ros2 launch yahboomcar_nav map_gmapping_launch.py    #建图节点
from launch import LaunchDescription
from launch_ros.actions import Node
import os
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    slam_gmapping_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([os.path.join(
        get_package_share_directory('slam_gmapping'), 'launch'),
         '/slam_gmapping.launch.py'])
    )

    base_link_to_laser_tf_node = Node(
     package='tf2_ros',
     executable='static_transform_publisher',
     name='base_link_to_base_laser',
     arguments=['-0.0046412', '0' , '0.094079','0','0','0','base_link','laser_frame']
    )
    
    return LaunchDescription([slam_gmapping_launch,base_link_to_laser_tf_node])

这里启动了一个launch文件-slam_gmapping_launch和一个发布静态变换的节点-base_link_to_laser_tf_node。

从代码上看,依赖了slam_gmapping.

slam_gammping

 可以从网上找个资料大概了解下,也可以看官网文档:gmapping - ROS Wiki

从文档大概看就是订阅话题:/scan 激光雷达数据、tf 坐标变换;发布了话题:map_metadata、map\~entropy 服务:dynamic_map 获取地图数据

launch还是要引用代码,所以apt-install 办法不适合,需要找源码编译安装。

https://github.com/ros-perception/slam_gmapping

找了这个地址,试了下编译安装。

CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "Findcatkin.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "catkin", but
  CMake did not find one.

  Could not find a package configuration file provided by "catkin" with any
  of the following names:

    catkinConfig.cmake
    catkin-config.cmake

  Add the installation prefix of "catkin" to CMAKE_PREFIX_PATH or set
  "catkin_DIR" to a directory containing one of the above files.  If "catkin"
  provides a separate development package or SDK, be sure it has been
  installed.

我的测试环境是ubuntu 22+ ros2 humble.系统缺少 catkin 这个包.

因为在ros2 中catkin 已经被ament取代,如何用ros2 中colcon build 编译 ros中 catkin的功能包?

需要修改源码和cmakelists把catkin相关的更换成ament,我看了下比较麻烦,直接使用了亚博官方的代码。工程结构如下所示,就是指定了启动脚本:src/slam_gmapping/launch/slam_gmapping.launch.py跟slam_gmapping.yaml

slam_gmapping.launch.py,这里启动了slam_gmapping的节点,加载了slam_gmapping.yaml参数文件。

slam_gmapping.yaml

/slam_gmapping:
  ros__parameters:
    angularUpdate: 0.5
    astep: 0.05
    base_frame: base_footprint
    map_frame: map
    odom_frame: odom
    delta: 0.05
    iterations: 5
    kernelSize: 1
    lasamplerange: 0.005
    lasamplestep: 0.005
    linearUpdate: 1.0
    llsamplerange: 0.01
    llsamplestep: 0.01
    lsigma: 0.075
    lskip: 0
    lstep: 0.05
    map_update_interval: 5.0
    maxRange: 6.0
    maxUrange: 4.0
    minimum_score: 0.0
    occ_thresh: 0.25
    ogain: 3.0
    particles: 30
    qos_overrides:
      /parameter_events:
        publisher:
          depth: 1000
          durability: volatile
          history: keep_all
          reliability: reliable
      /tf:
        publisher:
          depth: 1000
          durability: volatile
          history: keep_last
          reliability: reliable
    resampleThreshold: 0.5
    sigma: 0.05
    srr: 0.1
    srt: 0.2
    str: 0.1
    stt: 0.2
    temporalUpdate: 1.0
    transform_publish_period: 0.05
    use_sim_time: false
    xmax: 10.0
    xmin: -10.0
    ymax: 10.0
    ymin: -10.0

运行

启动小车代理:

首先启动小车处理底层数据程序,

ros2 launch yahboomcar_bringup yahboomcar_bringup_launch.py
from ament_index_python.packages import get_package_share_path

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.conditions import IfCondition, UnlessCondition
from launch.substitutions import Command, LaunchConfiguration

from launch_ros.actions import Node
from launch_ros.parameter_descriptions import ParameterValue

def generate_launch_description():
    package_path = get_package_share_path('yahboomcar_nav')
    default_rviz_config_path = package_path / 'rviz/view.rviz'
    rviz_arg = DeclareLaunchArgument(name='rvizconfig', default_value=str(default_rviz_config_path),
                                     description='Absolute path to rviz config file')

    rviz_node = Node(
        package='rviz2',
        executable='rviz2',
        name='rviz2',
        output='screen',
        arguments=['-d', LaunchConfiguration('rvizconfig')],
    )

    return LaunchDescription([
        rviz_arg,
        rviz_node
    ])
bohu@bohu-TM1701:~/yahboomcar/yahboomcar_ws$ ros2 launch yahboomcar_bringup yahboomcar_bringup_launch.py
[INFO] [launch]: All log files can be found below /home/bohu/.ros/log/2025-01-30-14-52-59-130561-bohu-TM1701-316456
[INFO] [launch]: Default logging verbosity is set to INFO
---------------------robot_type = x3---------------------
[INFO] [complementary_filter_node-1]: process started with pid [316458]
[INFO] [ekf_node-2]: process started with pid [316460]
[INFO] [static_transform_publisher-3]: process started with pid [316462]
[INFO] [joint_state_publisher-4]: process started with pid [316464]
[INFO] [robot_state_publisher-5]: process started with pid [316466]
[INFO] [static_transform_publisher-6]: process started with pid [316468]
[static_transform_publisher-3] [WARN] [1738219979.422738190] []: Old-style arguments are deprecated; see --help for new-style arguments
[static_transform_publisher-6] [WARN] [1738219979.430808316] []: Old-style arguments are deprecated; see --help for new-style arguments
[static_transform_publisher-3] [INFO] [1738219979.474861598] [base_link_to_base_imu]: Spinning until stopped - publishing transform
[static_transform_publisher-3] translation: ('-0.002999', '-0.003000', '0.031701')
[static_transform_publisher-3] rotation: ('0.000000', '0.000000', '0.000000', '1.000000')
[static_transform_publisher-3] from 'base_link' to 'imu_frame'
[static_transform_publisher-6] [INFO] [1738219979.486498703] [static_transform_publisher_dyynkHgPuvMB4QSZ]: Spinning until stopped - publishing transform
[static_transform_publisher-6] translation: ('0.000000', '0.000000', '0.050000')
[static_transform_publisher-6] rotation: ('0.000000', '0.000000', '0.000000', '1.000000')
[static_transform_publisher-6] from 'base_footprint' to 'base_link'
[complementary_filter_node-1] [INFO] [1738219979.494221633] [complementary_filter_gain_node]: Starting ComplementaryFilterROS
[robot_state_publisher-5] [WARN] [1738219979.497129656] [kdl_parser]: The root link base_link has an inertia specified in the URDF, but KDL does not support a root link with an inertia.  As a workaround, you can add an extra dummy link to your URDF.
[robot_state_publisher-5] [INFO] [1738219979.497311822] [robot_state_publisher]: got segment base_link
[robot_state_publisher-5] [INFO] [1738219979.497405894] [robot_state_publisher]: got segment imu_Link
[robot_state_publisher-5] [INFO] [1738219979.497427256] [robot_state_publisher]: got segment jq1_Link
[robot_state_publisher-5] [INFO] [1738219979.497440404] [robot_state_publisher]: got segment jq2_Link
[robot_state_publisher-5] [INFO] [1738219979.497453384] [robot_state_publisher]: got segment radar_Link
[robot_state_publisher-5] [INFO] [1738219979.497465220] [robot_state_publisher]: got segment yh_Link
[robot_state_publisher-5] [INFO] [1738219979.497477294] [robot_state_publisher]: got segment yq_Link
[robot_state_publisher-5] [INFO] [1738219979.497489516] [robot_state_publisher]: got segment zh_Link
[robot_state_publisher-5] [INFO] [1738219979.497501480] [robot_state_publisher]: got segment zq_Link
[joint_state_publisher-4] [INFO] [1738219980.049008205] [joint_state_publisher]: Waiting for robot_description to be published on the robot_description topic...

然后,启动rviz,可视化建图,终端输入,

ros2 launch yahboomcar_nav display_launch.py

此时还没运行建图节点,所以没有数据。接下来运行建图节点,终端输入,

ros2 launch yahboomcar_nav map_gmapping_launch.py
from launch import LaunchDescription
from launch_ros.actions import Node
import os
from launch.actions import IncludeLaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from ament_index_python.packages import get_package_share_directory


def generate_launch_description():
    slam_gmapping_launch = IncludeLaunchDescription(
        PythonLaunchDescriptionSource([os.path.join(
        get_package_share_directory('slam_gmapping'), 'launch'),
         '/slam_gmapping.launch.py'])
    )

    base_link_to_laser_tf_node = Node(
     package='tf2_ros',
     executable='static_transform_publisher',
     name='base_link_to_base_laser',
     arguments=['-0.0046412', '0' , '0.094079','0','0','0','base_link','laser_frame']
    )
    
    return LaunchDescription([slam_gmapping_launch,base_link_to_laser_tf_node])

#启动键盘控制
ros2 run yahboomcar_ctrl yahboom_keyboard

控制小车慢慢转一圈。最终效果如下

生成的map

建图完毕后,输入以下指令保存地图,终端输入,

ros2 launch yahboomcar_nav save_map_launch.py
from ament_index_python.packages import get_package_share_path

from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration

from launch_ros.actions import Node
import os


def generate_launch_description():
    package_share_path = str(get_package_share_path('yahboomcar_nav'))
    package_path = os.path.abspath(os.path.join(
        package_share_path, "../../../../src/yahboomcar_nav"))
    map_name = "yahboom_map"
    default_map_path = os.path.join(package_path, 'maps', map_name)

    map_arg = DeclareLaunchArgument(name='map_path', default_value=str(default_map_path),
                                    description='The path of the map')

    map_saver_node = Node(
        package='nav2_map_server',
        executable='map_saver_cli',
        arguments=[
            '-f', LaunchConfiguration('map_path'), '--ros-args', '-p', 'save_map_timeout:=60000.00'],
    )

    return LaunchDescription([
        map_arg,
        map_saver_node
    ])

bohu@bohu-TM1701:~/yahboomcar/yahboomcar_ws$ ros2 launch yahboomcar_nav save_map_launch.py
[INFO] [launch]: All log files can be found below /home/bohu/.ros/log/2025-01-30-15-33-14-161314-bohu-TM1701-319017
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [map_saver_cli-1]: process started with pid [319018]
[map_saver_cli-1] [INFO] [1738222394.419546962] [map_saver]: 
[map_saver_cli-1] 	map_saver lifecycle node launched. 
[map_saver_cli-1] 	Waiting on external lifecycle transitions to activate
[map_saver_cli-1] 	See https://design.ros2.org/articles/node_lifecycle.html for more information.
[map_saver_cli-1] [INFO] [1738222394.419654445] [map_saver]: Creating
[map_saver_cli-1] [INFO] [1738222394.419713380] [map_saver]: Configuring
[map_saver_cli-1] [INFO] [1738222394.420777030] [map_saver]: Saving map from 'map' topic to '/home/bohu/yahboomcar/yahboomcar_ws/src/yahboomcar_nav/maps/yahboom_map' file
[map_saver_cli-1] [WARN] [1738222394.420801411] [map_saver]: Free threshold unspecified. Setting it to default value: 0.250000
[map_saver_cli-1] [WARN] [1738222394.420813330] [map_saver]: Occupied threshold unspecified. Setting it to default value: 0.650000
[map_saver_cli-1] [WARN] [1738222395.293844583] [map_io]: Image format unspecified. Setting it to: pgm
[map_saver_cli-1] [INFO] [1738222395.294086677] [map_io]: Received a 384 X 608 map @ 0.05 m/pix
[map_saver_cli-1] [INFO] [1738222395.473549155] [map_io]: Writing map occupancy data to /home/bohu/yahboomcar/yahboomcar_ws/src/yahboomcar_nav/maps/yahboom_map.pgm
[map_saver_cli-1] [INFO] [1738222395.474901659] [map_io]: Writing map metadata to /home/bohu/yahboomcar/yahboomcar_ws/src/yahboomcar_nav/maps/yahboom_map.yaml
[map_saver_cli-1] [INFO] [1738222395.475071124] [map_io]: Map saved
[map_saver_cli-1] [INFO] [1738222395.475082707] [map_saver]: Map saved successfully
[map_saver_cli-1] [INFO] [1738222395.737027994] [map_saver]: Destroying
[INFO] [map_saver_cli-1]: process has finished cleanly [pid 319018]

会有两个文件生成,一个是yahboom_map.pgm,一个是yahboom_map.yaml,看下yaml的内容, 

 image: yahboom_map.pgm

mode: trinary

resolution: 0.05

origin: [-10, -10, 0]

negate: 0

occupied_thresh: 0.65

free_thresh: 0.25

  • image:表示地图的图片,也就是yahboom_map.pgm

  • mode:该属性可以是trinary、scale或者raw之一,取决于所选择的mode,trinary模式是默认模式

  • resolution:地图的分辨率, 米/像素

  • origin:地图左下角的 2D 位姿(x,y,yaw), 这里的yaw是逆时针方向旋转的(yaw=0 表示没有旋转)。目前系统中的很多部分会忽略yaw值。

  • negate:是否颠倒 白/黑 、自由/占用 的意义(阈值的解释不受影响)

  • occupied_thresh:占用概率大于这个阈值的的像素,会被认为是完全占用。

  • free_thresh:占用概率小于这个阈值的的像素,会被认为是完全自由。

 其他的属性:

TFtree

节点通讯图

应该是小车第一次运行激光雷达进行建图。

以上

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/962382.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

FreeRTOS从入门到精通 第十六章(任务通知)

参考教程:【正点原子】手把手教你学FreeRTOS实时系统_哔哩哔哩_bilibili 一、任务通知简介 1、概述 (1)任务通知顾名思义是用来通知任务的,任务控制块中的结构体成员变量ulNotifiedValue就是这个通知值。 (2&#…

数据结构选讲 (更新中)

参考 smWCDay7 数据结构选讲2 by yyc 。 可能会补充的: AT_cf17_final_j TreeMST 的 F2 Boruvka算法 目录 AT_cf17_final_j Tree MSTP5280 [ZJOI2019] 线段树 AT_cf17_final_j Tree MST link 题意 给定一棵 n n n 个点的树,点有点权 w i w_i wi​&am…

【01】共识机制

BTF共识 拜占庭将军问题 拜占庭将军问题是一个共识问题 起源 Leslie Lamport在论文《The Byzantine Generals Problem》提出拜占庭将军问题。 核心描述 军中可能有叛徒,却要保证进攻一致,由此引申到计算领域,发展成了一种容错理论。随着…

春晚舞台上的人形机器人:科技与文化的奇妙融合

文章目录 人形机器人Unitree H1的“硬核”实力传统文化与现代科技的创新融合网友热议与文化共鸣未来展望:科技与文化的更多可能结语 2025 年央视春晚的舞台,无疑是全球华人目光聚焦的焦点。就在这个盛大的舞台上,一场名为《秧BOT》的创意融合…

.NET Core缓存

目录 缓存的概念 客户端响应缓存 cache-control 服务器端响应缓存 内存缓存(In-memory cache) 用法 GetOrCreateAsync 缓存过期时间策略 缓存的过期时间 解决方法: 两种过期时间策略: 绝对过期时间 滑动过期时间 两…

如何从客观角度批判性阅读分析博客

此文仅以个人博客为例,大量阅读朋友反馈给我的交流让我得知他们所理解我的博客所表达的意思并非我所想表达的,差异或大或小,因人而异。 观点与事实 只有从客观角度反复批判性阅读和分析,才能逐渐清晰观点和事实。 观点不等于事实…

【力扣】49.字母异位词分组

AC截图 题目 思路 由于互为字母异位词的两个字符串包含的字母相同,因此对两个字符串分别进行排序之后得到的字符串一定是相同的,故可以将排序之后的字符串作为哈希表的键。 可以遍历strs,将其中每一个str排序,然后用unodered_ma…

【4Day创客实践入门教程】Day4 迈向高手之路——进一步学习!

Day4 迈向高手之路——进一步学习! 目录 Day4 迈向高手之路——进一步学习!更多的开发板外壳制作 Day0 创想启程——课程与项目预览Day1 工具箱构建——开发环境的构建Day2 探秘微控制器——单片机与MicroPython初步Day3 实战演练——桌面迷你番茄钟Day4…

什么是线性化PDF?

线性化PDF是一种特殊的PDF文件组织方式。 总体而言,PDF是一种极为优雅且设计精良的格式。PDF由大量PDF对象构成,这些对象用于创建页面。相关信息存储在一棵二叉树中,该二叉树同时记录文件中每个对象的位置。因此,打开文件时只需加…

向下调整算法(详解)c++

算法流程: 与⽗结点的权值作⽐较,如果⽐它⼤,就与⽗亲交换; 交换完之后,重复 1 操作,直到⽐⽗亲⼩,或者换到根节点的位置 大家可能会有点疑惑,这个是大根堆,22是怎么跑到…

unity学习25:用 transform 进行旋转和移动,简单的太阳地球月亮模型,以及父子级关系

目录 备注内容 1游戏物体的父子级关系 1.1 父子物体 1.2 坐标关系 1.3 父子物体实际是用 每个gameobject的tranform来关联的 2 获取gameObject的静态数据 2.1 具体命令 2.2 具体代码 2.3 输出结果 3 获取gameObject 的方向 3.1 游戏里默认的3个方向 3.2 获取方向代…

C基础算法与实现

前言 通过业务侧输入需求,使用代码完成。 1.偶数立方和 编写函数求1~100中奇数的平方与偶数的立方的和 1.1代码实现结果 1.2源码示例 #include <stdio.h>// 计算1到100中奇数的平方与偶数的立方的和 int calculateSum() {int sum 0;// 遍历1到100之间的所有数字for (…

基于SSM实现的乡村振兴文化平台系统功能实现十八

一、前言介绍&#xff1a; 1.1 项目摘要 农耕文明是广大群众在几千年的农业生产生活中智慧的结晶&#xff0c;不仅是乡土文化的核心和精髓&#xff0c;还是中华文明的起源和基因。因此&#xff0c;传承和发扬优秀乡村文化&#xff0c;是传承农耕文明的必然要求。 文化振兴是乡…

如何让一个用户具备创建审批流程的权限

最近碰到一个问题&#xff0c;两个sandbox&#xff0c;照理用户的权限应该是一样的&#xff0c;结果开发环境里面我可以左右的做各种管理工作&#xff0c;但是使用change set上传后&#xff0c;另一个环境的同一个用户&#xff0c;没有相对于的权限&#xff0c;权限不足。 当时…

实现B-树

一、概述 1.历史 B树&#xff08;B-Tree&#xff09;结构是一种高效存储和查询数据的方法&#xff0c;它的历史可以追溯到1970年代早期。B树的发明人Rudolf Bayer和Edward M. McCreight分别发表了一篇论文介绍了B树。这篇论文是1972年发表于《ACM Transactions on Database S…

解锁维特比算法:探寻复杂系统的最优解密码

引言 在复杂的技术世界中&#xff0c;维特比算法以其独特的魅力和广泛的应用&#xff0c;成为通信、自然语言处理、生物信息学等领域的关键技术。今天&#xff0c;让我们一同深入探索维特比算法的奥秘。 一、维特比算法的诞生背景 维特比算法由安德鲁・维特比在 1967 年提出…

CPU 100% 出现系统中断 怎么解决

CPU 100% 出现系统中断 怎么解决 电脑开机时会掉帧&#xff0c;切换到桌面时就会卡顿&#xff0c;然后打开任务管理器就会看到系统中断的cpu占用率达到100%&#xff0c;过一段时间再打开还是会有显示100%的占用率&#xff0c;这个问题怎么解决&#xff1f; 文章目录 CPU 100% …

Python 梯度下降法(五):Adam Optimize

文章目录 Python 梯度下降法&#xff08;五&#xff09;&#xff1a;Adam Optimize一、数学原理1.1 介绍1.2 符号说明1.3 实现流程 二、代码实现2.1 函数代码2.2 总代码2.3 遇到的问题2.4 算法优化 三、优缺点3.1 优点3.2 缺点 Python 梯度下降法&#xff08;五&#xff09;&am…

labelme_json_to_dataset ValueError: path is on mount ‘D:‘,start on C

这是你的labelme运行时label照片的盘和保存目的地址的盘不同都值得报错 labelme_json_to_dataset ValueError: path is on mount D:,start on C 只需要放一个盘但可以不放一个目录

中间件安全

一.中间件概述 1.中间件定义 介绍&#xff1a;中间件&#xff08;Middleware&#xff09;作为一种软件组件&#xff0c;在不同系统、应用程序或服务间扮演着数据与消息传递的关键角色。它常处于应用程序和操作系统之间&#xff0c;就像一座桥梁&#xff0c;负责不同应用程序间…