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
41extern "C" {
42#endif
43
44/// @cond EXTERNAL
45
46// Forward declarations
47struct _rtk_fig_t;
48
49// Limits
50#define MAP_WIFI_MAX_LEVELS 8
51
52// Description for a single map cell.
53typedef struct
54{
55 // Occupancy state (-1 = free, 0 = unknown, +1 = occ)
56 int occ_state;
57
58 // Distance to the nearest occupied cell
59 double occ_dist;
60
61 // Wifi levels
62 //int wifi_levels[MAP_WIFI_MAX_LEVELS];
63
64} map_cell_t;
65
66// Description for a map
67typedef struct
68{
69 // Map origin; the map is a viewport onto a conceptual larger map.
70 double origin_x, origin_y;
71
72 // Map scale (m/cell)
73 double scale;
74
75 // Map dimensions (number of cells)
76 int size_x, size_y;
77
78 // The map data, stored as a grid
79 map_cell_t *cells;
80
81 // Max distance at which we care about obstacles, for constructing
82 // likelihood field
83 double max_occ_dist;
84
85} map_t;
86
87/**************************************************************************
88 * Basic map functions
89 **************************************************************************/
90
91// Create a new (empty) map
92map_t *map_alloc(void);
93
94// Destroy a map
95void map_free(map_t *map);
96
97// Get the cell at the given point
98map_cell_t *map_get_cell(map_t *map, double ox, double oy, double oa);
99
100// Load an occupancy map
101int map_load_occ(map_t *map, const char *filename, double scale, int negate);
102
103// Load a wifi signal strength map
104//int map_load_wifi(map_t *map, const char *filename, int index);
105
106// Update the cspace distances
107void map_update_cspace(map_t *map, double max_occ_dist);
108
109/**************************************************************************
110 * Range functions
111 **************************************************************************/
112
113// Extract a single range reading from the map
114double map_calc_range(map_t *map, double ox, double oy, double oa, double max_range);
115
116/**************************************************************************
117 * GUI/diagnostic functions
118 **************************************************************************/
119
120// Draw the occupancy grid
121void map_draw_occ(map_t *map, struct _rtk_fig_t *fig);
122
123// Draw the cspace map
124void map_draw_cspace(map_t *map, struct _rtk_fig_t *fig);
125
126// Draw a wifi map
127void map_draw_wifi(map_t *map, struct _rtk_fig_t *fig, int index);
128
129/**************************************************************************
130 * Map manipulation macros
131 **************************************************************************/
132
133// Convert from map index to world coords
134#define MAP_WXGX(map, i) (map->origin_x + ((i)-map->size_x / 2) * map->scale)
135#define MAP_WYGY(map, j) (map->origin_y + ((j)-map->size_y / 2) * map->scale)
136
137// Convert from world coords to map coords
138#define MAP_GXWX(map, x) (floor((x - map->origin_x) / map->scale + 0.5) + map->size_x / 2)
139#define MAP_GYWY(map, y) (floor((y - map->origin_y) / map->scale + 0.5) + map->size_y / 2)
140
141// Test to see if the given map coords lie within the absolute map bounds.
142#define MAP_VALID(map, i, j) ((i >= 0) && (i < map->size_x) && (j >= 0) && (j < map->size_y))
143
144// Compute the cell index for the given map coords.
145#define MAP_INDEX(map, i, j) ((i) + (j)*map->size_x)
146
147/// @endcond
148
149#ifdef __cplusplus
150}
151#endif
152
153#endif