• ROS中的珊格地图——nav_msgs::OccupancyGrid


    @

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

    在这里插入图片描述黑色块为障碍物,颜色较深的灰色块为危险区,颜色再浅一点的是可行区域,最浅的是未知区域(最外围的区域);

    二、地图数据格式

    官方数据类型解释如下:

    nav_msgs/OccupancyGrid MessageFile: nav_msgs/OccupancyGrid.msgRaw Message Definition

    # 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);
    }
    
  • 相关阅读:
    Expanding Rods(二分)
    Monthly Expense(二分)
    sdut1269 走迷宫(dfs)
    走迷宫(dfs)
    C Looooops(扩展欧几里得+模线性方程)
    41. First Missing Positive
    40. Combination Sum II
    39. Combination Sum
    37. Sudoku Solver
    36. Valid Sudoku
  • 原文地址:https://www.cnblogs.com/long5683/p/13217716.html
Copyright © 2020-2023  润新知