* Parameters of Obstacle detection
*******************************************************************************/
-const double OBS_SIZE_M = 0.2; /**< Expected size of detected obstacle */
-const double IGNORE_CLOSER_THAN_M = 0.2; /**< Do not mark any obstacle closer than this to center of the robot (avoid path planning deadlock) */
-const double IGNORE_FURTHER_THAN_M = 0.5; /**< Ignore data from sharp if further than this */
-const int OBS_FORGET_PERIOD = 100; /**< The period of thread_obstacle_forgeting [ms] */
-const int OBS_FORGET_SEC = 1; /**< Time to completely forget detected obstacle. */
-const double OBS_OFFSET = 0.6;
-
-void obstacle_detected_at(double x, double y, bool real_obstacle) {
+MapHandling map_handle;
+
+void MapHandling::obstacle_detected_at(double x, double y, bool real_obstacle) {
int i,j, xcell, ycell;
struct robot_pos_type est_pos;
- struct map *map = robot.map;
double xx, yy;
bool valid;
- if (!map)
+ if (!sh_map)
return;
ShmapPoint2Cell(x, y, &xcell, &ycell, &valid);
return;
/* Ignore obstacles at marked places */
- if (map->cells[ycell][xcell].flags & MAP_FLAG_IGNORE_OBST)
+ if (sh_map->cells[ycell][xcell].flags & MAP_FLAG_IGNORE_OBST)
return;
if (real_obstacle) {
/* The obstacle was detected here */
- map->cells[ycell][xcell].flags |= MAP_FLAG_DET_OBST;
+ sh_map->cells[ycell][xcell].flags |= MAP_FLAG_DET_OBST;
}
/** Then all the cells arround obstacle cell are set as
ShmapCell2Point(i, j, &xx, &yy);
if ((distance(xx, yy, est_pos.x, est_pos.y) > IGNORE_CLOSER_THAN_M) &&
(distance(xx, yy, x, y) < OBS_SIZE_M)) { // We expect cirtular area around obstacle
- map->cells[j][i].detected_obstacle = MAP_NEW_OBSTACLE;
+ sh_map->cells[j][i].detected_obstacle = MAP_NEW_OBSTACLE;
}
}
}
}
-void figure_detected_at(double x, double y, const bool state) {
+void MapHandling::figure_detected_at(double x, double y, const bool state) {
int i,j, xcell, ycell;
struct robot_pos_type est_pos;
- struct map *map = robot.map;
double xx, yy;
bool valid;
- if (!map)
+ if (!sh_map)
return;
ShmapPoint2Cell(x, y, &xcell, &ycell, &valid);
return;
/* Ignore obstacles at marked places */
- if (map->cells[ycell][xcell].flags & MAP_FLAG_IGNORE_OBST)
+ if (sh_map->cells[ycell][xcell].flags & MAP_FLAG_IGNORE_OBST)
return;
if (state) {
- map->cells[ycell][xcell].flags |= MAP_FLAG_DET_OBST;
+ sh_map->cells[ycell][xcell].flags |= MAP_FLAG_DET_OBST;
/* Mark "protected" area around the obstacle */
robot.get_est_pos(est_pos.x, est_pos.y, est_pos.phi);
ShmapCell2Point(i, j, &xx, &yy);
if ((distance(xx, yy, est_pos.x, est_pos.y) > IGNORE_CLOSER_THAN_M) &&
(distance(xx, yy, x, y) < OBS_SIZE_M)) { // We expect cirtular area around obstacle
- map->cells[j][i].detected_obstacle = MAP_NEW_OBSTACLE;
+ sh_map->cells[j][i].detected_obstacle = MAP_NEW_OBSTACLE;
}
}
}
*
* @return
*/
-void obst_coord(struct robot_pos_type *e, const sharp_pos *s, double v, double &x, double &y) {
+void MapHandling::obst_coord(struct robot_pos_type *e, const sharp_pos *s, double v, double &x, double &y) {
double sx, sy, sa;
sx = e->x + s->x*cos(e->phi) - s->y*sin(e->phi);
sy = e->y + s->x*sin(e->phi) + s->y*cos(e->phi);
y = sy+v*sin(sa);
}
-void get_checkerboard(std::vector<Shape_detect::Point> &team) {
+void MapHandling::get_checkerboard(std::vector<Shape_detect::Point> &team) {
Shape_detect::Point tmp, newPoint, start;
unsigned int i;
team.push_back(tmp);
}
-inline float point_distance(Shape_detect::Point a, Shape_detect::Point b) {
- return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
-}
-
-void update_map_hokuyo(struct hokuyo_scan_type *s) {
+void MapHandling::update_map_hokuyo(struct hokuyo_scan_type *s) {
double x, y;
struct robot_pos_type e;
unsigned int i;
*/
static void forget_obstacles(map_cell_detobst_t val) {
int i,j;
- struct map *map = robot.map;
+ struct map *map = map_handle.get_map();
for (j=0;j<MAP_HEIGHT;j++){
for(i=0;i<MAP_WIDTH;i++){
#ifndef _MAP_HANDLING_H
#define _MAP_HANDLING_H
+#include <cmath>
+#include <robot.h>
#include <robodim.h>
+#include <map.h>
+#include <robomath.h>
+#include <hokuyo.h>
-#ifdef __cplusplus
-extern "C" {
-#endif
+#include <shape_detect.h>
-void * thread_obstacle_forgeting(void * arg);
-/*void update_map(struct sharps_type *s);*/
-void update_map_hokuyo(struct hokuyo_scan_type *s);
+const double OBS_SIZE_M = 0.2; /**< Expected size of detected obstacle */
+const double IGNORE_CLOSER_THAN_M = 0.2; /**< Do not mark any obstacle closer than this to center of the robot (avoid path planning deadlock) */
+const double IGNORE_FURTHER_THAN_M = 0.5; /**< Ignore data from sharp if further than this */
+const int OBS_FORGET_PERIOD = 100; /**< The period of thread_obstacle_forgeting [ms] */
+const int OBS_FORGET_SEC = 1; /**< Time to completely forget detected obstacle. */
+const double OBS_OFFSET = 0.6;
-#ifdef __cplusplus
-}
-#endif
+class MapHandling{
+
+ map *sh_map;
+ void obstacle_detected_at(double x, double y, bool real_obstacle);
+ void figure_detected_at(double x, double y, const bool state);
+ void obst_coord(struct robot_pos_type *e, const sharp_pos *s, double v, double &x, double &y);
+ void get_checkerboard(std::vector<Shape_detect::Point> &team);
+ float point_distance(Shape_detect::Point a, Shape_detect::Point b) {
+ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
+ }
+
+ public:
+ void update_map_hokuyo(struct hokuyo_scan_type *s);
+ map* get_map() {
+ return sh_map;
+ }
+ void set_map(map *map_shared) {
+ sh_map = map_shared;
+ }
+};
+extern MapHandling map_handle;
+void * thread_obstacle_forgeting(void * arg);
#endif