map.h
00001 /* 00002 * Player - One Hell of a Robot Server 00003 * Copyright (C) 2003 00004 * Andrew Howard 00005 * Brian Gerkey 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 * 00021 */ 00022 00023 00024 /************************************************************************** 00025 * Desc: Global map (grid-based) 00026 * Author: Andrew Howard 00027 * Date: 6 Feb 2003 00028 * CVS: $Id: map.h 8466 2009-12-16 00:51:26Z gbiggs $ 00029 **************************************************************************/ 00030 00031 #ifndef MAP_H 00032 #define MAP_H 00033 00034 #if !defined (WIN32) 00035 #include <stdint.h> 00036 #endif 00037 00038 #ifdef __cplusplus 00039 extern "C" { 00040 #endif 00041 00042 // Forward declarations 00043 struct _rtk_fig_t; 00044 00045 00046 // Limits 00047 #define MAP_WIFI_MAX_LEVELS 8 00048 00049 00050 // Description for a single map cell. 00051 typedef struct 00052 { 00053 // Occupancy state (-1 = free, 0 = unknown, +1 = occ) 00054 int occ_state; 00055 00056 // Distance to the nearest occupied cell 00057 double occ_dist; 00058 00059 // Wifi levels 00060 int wifi_levels[MAP_WIFI_MAX_LEVELS]; 00061 00062 } map_cell_t; 00063 00064 00065 // Description for a map 00066 typedef struct 00067 { 00068 // Map origin; the map is a viewport onto a conceptual larger map. 00069 double origin_x, origin_y; 00070 00071 // Map scale (m/cell) 00072 double scale; 00073 00074 // Max occupancy distance value 00075 double max_occ_dist; 00076 00077 // Map dimensions (number of cells) 00078 int size_x, size_y; 00079 00080 // The map data, stored as a grid 00081 map_cell_t *cells; 00082 00083 } map_t; 00084 00085 00086 00087 /************************************************************************** 00088 * Basic map functions 00089 **************************************************************************/ 00090 00091 // Create a new (empty) map 00092 map_t *map_alloc(void); 00093 00094 // Destroy a map 00095 void map_free(map_t *map); 00096 00097 // Get the cell at the given point 00098 map_cell_t *map_get_cell(map_t *map, double ox, double oy, double oa); 00099 00100 // Load an occupancy map 00101 int map_load_occ(map_t *map, const char *filename, double scale, int negate); 00102 00103 // Load a wifi signal strength map 00104 int map_load_wifi(map_t *map, const char *filename, int index); 00105 00106 // Update the cspace distances 00107 void map_update_cspace(map_t *map, double max_occ_dist); 00108 00109 00110 /************************************************************************** 00111 * Range functions 00112 **************************************************************************/ 00113 00114 // Extract a single range reading from the map 00115 double map_calc_range(map_t *map, double ox, double oy, double oa, double max_range); 00116 00117 00118 /************************************************************************** 00119 * GUI/diagnostic functions 00120 **************************************************************************/ 00121 00122 // Draw the occupancy grid 00123 void map_draw_occ(map_t *map, struct _rtk_fig_t *fig); 00124 00125 // Draw the cspace map 00126 void map_draw_cspace(map_t *map, struct _rtk_fig_t *fig); 00127 00128 // Draw a wifi map 00129 void map_draw_wifi(map_t *map, struct _rtk_fig_t *fig, int index); 00130 00131 00132 /************************************************************************** 00133 * Map manipulation macros 00134 **************************************************************************/ 00135 00136 // Convert from map index to world coords 00137 #define MAP_WXGX(map, i) (map->origin_x + ((i) - map->size_x / 2) * map->scale) 00138 #define MAP_WYGY(map, j) (map->origin_y + ((j) - map->size_y / 2) * map->scale) 00139 00140 // Convert from world coords to map coords 00141 #define MAP_GXWX(map, x) (floor((x - map->origin_x) / map->scale + 0.5) + map->size_x / 2) 00142 #define MAP_GYWY(map, y) (floor((y - map->origin_y) / map->scale + 0.5) + map->size_y / 2) 00143 00144 // Test to see if the given map coords lie within the absolute map bounds. 00145 #define MAP_VALID(map, i, j) ((i >= 0) && (i < map->size_x) && (j >= 0) && (j < map->size_y)) 00146 00147 // Compute the cell index for the given map coords. 00148 #define MAP_INDEX(map, i, j) ((i) + (j) * map->size_x) 00149 00150 #ifdef __cplusplus 00151 } 00152 #endif 00153 00154 #endif