ROS中的珊格地图——nav

    技术2022-07-10  147

    文章目录

    一、Rviz中的地图效果如下:二、地图数据格式三、实例代码打赏

    一、Rviz中的地图效果如下:

    黑色块为障碍物,颜色较深的灰色块为危险区,颜色再浅一点的是可行区域,最浅的是未知区域(最外围的区域);

    二、地图数据格式

    官方数据类型解释如下:

    # This represents a 2-D grid map, in which each cell represents the probability of # occupancy. Header header #MetaData for the map MapMetaData info # The map data, in row-major order, starting with (0,0). Occupancy # probabilities are in the range [0,100]. Unknown is -1. int8[] data

    # This hold basic information about the characterists of the OccupancyGrid # The time at which the map was loaded time map_load_time # The map resolution [m/cell] float32 resolution # Map width [cells] uint32 width # Map height [cells] uint32 height # The origin of the map [m, m, rad]. This is the real-world pose of the # cell (0,0) in the map. geometry_msgs/Pose origin

    栅格地图中坐标是一维数组的形式,比如实际地图中某点坐标为(x,y),对应栅格地图中坐标为[x*map.info.width+y]。

    三、实例代码

    ros::Publisher mapPub = nodeHandler.advertise<nav_msgs::OccupancyGrid>("laser_map", 1, true); //发布地图. void PublishMap(ros::Publisher &map_pub) { nav_msgs::OccupancyGrid rosMap; rosMap.info.resolution = mapParams.resolution; rosMap.info.origin.position.x = 0.0; rosMap.info.origin.position.y = 0.0; rosMap.info.origin.position.z = 0.0; rosMap.info.origin.orientation.x = 0.0; rosMap.info.origin.orientation.y = 0.0; rosMap.info.origin.orientation.z = 0.0; rosMap.info.origin.orientation.w = 1.0; rosMap.info.origin.position.x = mapParams.origin_x; rosMap.info.origin.position.y = mapParams.origin_y; rosMap.info.width = mapParams.width; rosMap.info.height = mapParams.height; rosMap.data.resize(rosMap.info.width * rosMap.info.height); //0~100 int cnt0, cnt1, cnt2; cnt0 = cnt1 = cnt2 = 100; for (int i = 0; i < mapParams.width * mapParams.height; i++) { if (pMap[i] == 50) { rosMap.data[i] = -1.0; } else { rosMap.data[i] = pMap[i]; } } rosMap.header.stamp = ros::Time::now(); rosMap.header.frame_id = "map"; map_pub.publish(rosMap); }

    打赏

    码字不易,如果对您有帮助,就打赏一下吧O(∩_∩)O

    Processed: 0.008, SQL: 9