#ifndefMAP_H#defineMAP_H#include<stdint.h>#ifdef__cplusplusextern"C"{#endif// Forward declarationsstruct_rtk_fig_t;// Limits#defineMAP_WIFI_MAX_LEVELS8// Description for a single map cell.typedefstruct{// Occupancy state (-1 = free, 0 = unknown, +1 = occ)int occ_state;// Distance to the nearest occupied celldouble occ_dist;// Wifi levels//int wifi_levels[MAP_WIFI_MAX_LEVELS];} map_cell_t;// Description for a maptypedefstruct{// Map origin; the map is a viewport onto a conceptual larger map.double origin_x, origin_y;// Map scale (m/cell)double scale;// Map dimensions (number of cells)int size_x, size_y;// The map data, stored as a grid
map_cell_t *cells;// Max distance at which we care about obstacles, for constructing// likelihood fielddouble max_occ_dist;} map_t;
2. 定义操作地图的方法
// Create a new (empty) map
map_t *map_alloc(void);// Destroy a mapvoidmap_free(map_t *map);// Get the cell at the given point
map_cell_t *map_get_cell(map_t *map,double ox,double oy,double oa);// Load an occupancy mapintmap_load_occ(map_t *map,constchar*filename,double scale,int negate);// Load a wifi signal strength map//int map_load_wifi(map_t *map, const char *filename, int index);// Update the cspace distancesvoidmap_update_cspace(map_t *map,double max_occ_dist);
3. 坐标与索引的相互转化,以及相关检测
// Convert from map index to world coords#defineMAP_WXGX(map, i)(map->origin_x +((i)- map->size_x /2)* map->scale)#defineMAP_WYGY(map, j)(map->origin_y +((j)- map->size_y /2)* map->scale)// Convert from world coords to map coords#defineMAP_GXWX(map, x)(floor((x - map->origin_x)/ map->scale +0.5)+ map->size_x /2)#defineMAP_GYWY(map, y)(floor((y - map->origin_y)/ map->scale +0.5)+ map->size_y /2)// Test to see if the given map coords lie within the absolute map bounds.#defineMAP_VALID(map, i, j)((i >=0)&&(i < map->size_x)&&(j >=0)&&(j < map->size_y))// Compute the cell index for the given map coords.#defineMAP_INDEX(map, i, j)((i)+(j)* map->size_x)