Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 19

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 20

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 21

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 22

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/wwwroot/phxin.top/usr/themes/Joe/public/config.php on line 23
导航实现02--地图服务 - Hello World

导航实现02--地图服务

清歌
2023-02-08 / 0 评论 / 0 阅读 / 正在检测是否收录...

简介

map_server功能包中提供了两个节点: map_saver 和 map_server,前者用于将栅格地图保存到磁盘,后者读取磁盘的栅格地图并以服务的方式提供出去。map_server安装前面也有介绍,命令如下:

sudo apt install ros-<ROS版本>-map-server

map_saver节点说明

订阅的topic
map(nav_msgs/OccupancyGrid)

订阅此话题用于生成地图文件。

地图保存

大致流程
  • 依次启动仿真环境,键盘控制节点与SLAM节点
  • 通过键盘控制机器人运动并绘图;
  • 通过上述地图保存方式保存地图。
  • 最后会在指定路径下会生成两个文件,xxx.pgm 与 xxx.yaml
launch文件编写
    <arg name="filename" value="$(find 功能包)/map/nav" />
    <node name="map_save" pkg="map_server" type="map_saver" args="-f $(arg filename)" />
</launch>
最终现象

请输入图片描述

保存结果解释

xxx.pgm 本质是一张图片,直接使用图片查看程序即可打开。

xxx.yaml 保存的是地图的元数据信息,用于描述图片,内容格式如下:

image: /home/rosmelodic/ws02_nav/src/mycar_nav/map/nav.pgm
resolution: 0.050000
origin: [-50.000000, -50.000000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196
解释

image:被描述的图片资源路径,可以是绝对路径也可以是相对路径。

resolution: 图片分片率(单位: m/像素)。

origin: 地图中左下像素的二维姿势,为(x,y,偏航),偏航为逆时针旋转(偏航= 0表示无旋转)。

occupied_thresh: 占用概率大于此阈值的像素被视为完全占用。

free_thresh: 占用率小于此阈值的像素被视为完全空闲。

negate: 是否应该颠倒白色/黑色自由/占用的语义。

map_server 中障碍物计算规则:

地图中的每一个像素取值在 [0,255] 之间,白色为 255,黑色为 0,该值设为 x;
map_server 会将像素值作为判断是否是障碍物的依据,首先计算比例: p = (255 - x) / 255.0,白色为0,黑色为1(negate为true,则p = x / 255.0);
根据步骤2计算的比例判断是否是障碍物,如果 p > occupied_thresh 那么视为障碍物,如果 p < free_thresh 那么视为无物。

备注:图片也可以根据需求编辑。

map_server使用之地图服务(map_server)

发布的话题
 map_metadata(nav_msgs / MapMetaData)

发布地图元数据。

map(nav_msgs / OccupancyGrid)

地图数据

服务
static_map(nav_msgs / GetMap)

通过此服务获取地图。

参数
〜frame_id(字符串,默认值:“map”)

地图坐标系

地图读取

launch文件编写
<launch> 
           <arg name="map"  default="nav.yaml"  />
            <node pkg="map_server"  type="map_server" name="map_server" args="$(find nav_demo)/map/$(arg map)" />
  
</launch>

地图显示

启动launch节点
启动rviz
0

评论 (0)

取消