Fawkes API  Fawkes Development Version
map.h
1 
2 /***************************************************************************
3  * map.h: Global map (grid-based)
4  *
5  * Created: Thu May 24 18:44:56 2012
6  * Copyright 2000 Brian Gerkey
7  * 2000 Kasper Stoy
8  * 2012 Tim Niemueller [www.niemueller.de]
9  ****************************************************************************/
10 
11 /* This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL file in the doc directory.
22  */
23 
24 /* From:
25  * Player - One Hell of a Robot Server (LGPL)
26  * Copyright (C) 2000 Brian Gerkey & Kasper Stoy
27  * gerkey@usc.edu kaspers@robotics.usc.edu
28  */
29 /**************************************************************************
30  * Desc: Global map (grid-based)
31  * Author: Andrew Howard
32  * Date: 6 Feb 2003
33  **************************************************************************/
34 
35 #ifndef MAP_H
36 #define MAP_H
37 
38 #include <stdint.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /// @cond EXTERNAL
45 
46 // Forward declarations
47 struct _rtk_fig_t;
48 
49 
50 // Limits
51 #define MAP_WIFI_MAX_LEVELS 8
52 
53 
54 // Description for a single map cell.
55 typedef struct
56 {
57  // Occupancy state (-1 = free, 0 = unknown, +1 = occ)
58  int occ_state;
59 
60  // Distance to the nearest occupied cell
61  double occ_dist;
62 
63  // Wifi levels
64  //int wifi_levels[MAP_WIFI_MAX_LEVELS];
65 
66 } map_cell_t;
67 
68 
69 // Description for a map
70 typedef struct
71 {
72  // Map origin; the map is a viewport onto a conceptual larger map.
73  double origin_x, origin_y;
74 
75  // Map scale (m/cell)
76  double scale;
77 
78  // Map dimensions (number of cells)
79  int size_x, size_y;
80 
81  // The map data, stored as a grid
82  map_cell_t *cells;
83 
84  // Max distance at which we care about obstacles, for constructing
85  // likelihood field
86  double max_occ_dist;
87 
88 } map_t;
89 
90 
91 
92 /**************************************************************************
93  * Basic map functions
94  **************************************************************************/
95 
96 // Create a new (empty) map
97 map_t *map_alloc(void);
98 
99 // Destroy a map
100 void map_free(map_t *map);
101 
102 // Get the cell at the given point
103 map_cell_t *map_get_cell(map_t *map, double ox, double oy, double oa);
104 
105 // Load an occupancy map
106 int map_load_occ(map_t *map, const char *filename, double scale, int negate);
107 
108 // Load a wifi signal strength map
109 //int map_load_wifi(map_t *map, const char *filename, int index);
110 
111 // Update the cspace distances
112 void map_update_cspace(map_t *map, double max_occ_dist);
113 
114 
115 /**************************************************************************
116  * Range functions
117  **************************************************************************/
118 
119 // Extract a single range reading from the map
120 double map_calc_range(map_t *map, double ox, double oy, double oa, double max_range);
121 
122 
123 /**************************************************************************
124  * GUI/diagnostic functions
125  **************************************************************************/
126 
127 // Draw the occupancy grid
128 void map_draw_occ(map_t *map, struct _rtk_fig_t *fig);
129 
130 // Draw the cspace map
131 void map_draw_cspace(map_t *map, struct _rtk_fig_t *fig);
132 
133 // Draw a wifi map
134 void map_draw_wifi(map_t *map, struct _rtk_fig_t *fig, int index);
135 
136 
137 /**************************************************************************
138  * Map manipulation macros
139  **************************************************************************/
140 
141 // Convert from map index to world coords
142 #define MAP_WXGX(map, i) (map->origin_x + ((i) - map->size_x / 2) * map->scale)
143 #define MAP_WYGY(map, j) (map->origin_y + ((j) - map->size_y / 2) * map->scale)
144 
145 // Convert from world coords to map coords
146 #define MAP_GXWX(map, x) (floor((x - map->origin_x) / map->scale + 0.5) + map->size_x / 2)
147 #define MAP_GYWY(map, y) (floor((y - map->origin_y) / map->scale + 0.5) + map->size_y / 2)
148 
149 // Test to see if the given map coords lie within the absolute map bounds.
150 #define MAP_VALID(map, i, j) ((i >= 0) && (i < map->size_x) && (j >= 0) && (j < map->size_y))
151 
152 // Compute the cell index for the given map coords.
153 #define MAP_INDEX(map, i, j) ((i) + (j) * map->size_x)
154 
155 /// @endcond
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif