int i, x, y;
int xcontig, ycontig, xstart, ystart, xgoal, ygoal;
struct map *map = ShmapIsMapInit();
+ bool valid;
if (!map) return -1;
// Transform real data in cell data
- ShmapPoint2Cell(xstart_real, ystart_real, &xstart, &ystart);
+ ShmapPoint2Cell(xstart_real, ystart_real, &xstart, &ystart, &valid);
+ if (!valid)
+ return -1;
start = &graph[ystart][xstart];
- ShmapPoint2Cell(xgoal_real, ygoal_real, &xgoal, &ygoal);
+ ShmapPoint2Cell(xgoal_real, ygoal_real, &xgoal, &ygoal, &valid);
+ if (!valid)
+ return -1;
goal = &graph[ygoal][xgoal];
/**@{*/
#include <sys/stat.h>
#include <math.h>
-
struct map* map = NULL;
int shmap_id;
/** @addtogroup maplib */
struct map_cell *ShmapCellAtPoint(double x_m, double y_m)
{
int i, j;
- ShmapPoint2Cell(x_m, y_m, &i, &j);
- return &(map->cells[j][i]);
+ bool valid;
+ ShmapPoint2Cell(x_m, y_m, &i, &j, &valid);
+ if (valid)
+ return &(map->cells[j][i]);
+ else
+ return NULL;
}
/**
int ShmapIsFreePoint(double x_m, double y_m)
{
int i,j;
- ShmapPoint2Cell(x_m, y_m, &i, &j);
+ bool valid;
+ ShmapPoint2Cell(x_m, y_m, &i, &j, &valid);
return ShmapIsFreeCell(i, j);
}
int ShmapSetRectangleFlag(double x1, double y1, double x2, double y2, map_cell_flag_t set_flags, map_cell_flag_t clear_flags)
{
int i,j, i1, i2, j1, j2;
- ShmapPoint2Cell(x1, y1, &i1, &j1);
- ShmapPoint2Cell(x2, y2, &i2, &j2);
+ bool valid;
+ ShmapPoint2Cell(x1, y1, &i1, &j1, &valid);
+ if (!valid)
+ return 0;
+ ShmapPoint2Cell(x2, y2, &i2, &j2, &valid);
+ if (!valid)
+ return 0;
if (i1 > i2) {
i = i2;
i2 = i1;
* @param x Coodonte of X
*/
-void ShmapPoint2Cell(double x, double y, int *ix, int *iy){
- if (ix) *ix = (int)floor(x/MAP_CELL_SIZE_M);
- if (iy) *iy = MAP_HEIGHT-1-(int)floor(y/MAP_CELL_SIZE_M);
+void ShmapPoint2Cell(double x, double y, int *ix, int *iy, bool *valid){
+ int xx, yy;
+ xx = (int)floor(x/MAP_CELL_SIZE_M);
+ yy = MAP_HEIGHT-1-(int)floor(y/MAP_CELL_SIZE_M);
+
+ if (valid != NULL) {
+ *valid = ShmapIsCellInMap(xx, yy);
+ }
+ if (ix) *ix = xx;
+ if (iy) *iy = yy;
}
/**
#ifndef __MAP_H
#define __MAP_H
+
+#include <stdbool.h>
+
/**
* @defgroup maplib Library to manage the map
* This libary implements a discrete map use wich can be use in robotics.
void ShmapDt(void);
struct map * ShmapIsMapInit(void);
-void ShmapPoint2Cell(double x, double y, int *cx, int *cy);
+void ShmapPoint2Cell(double x, double y, int *cx, int *cy, bool *valid);
int ShmapCell2Point(int ix, int iy, double *x, double *y);
*/
static inline int ShampIsPointInMap(double x_m, double y_m){
int x, y;
- ShmapPoint2Cell(x_m, y_m, &x, &y);
+ bool valid;
+ ShmapPoint2Cell(x_m, y_m, &x, &y, &valid);
return ShmapIsCellInMap(x, y);
}
* ROBOT DIMENSIONS
* S0
* S4 +--------------------------+ S2
- * ^ | | | |---|
+ * ^ | | | |--,
* ^ | | ------- ABE | |
* RR| | | :<--------------------->|
- * v | | : | |
- * W| | + Center (L) | |
- * | | AB : AF | |
+ * v | | : |--'
+ * W| | + Center (L) |
+ * | | AB : AF |--,
* | |<---->:<----------------->| |
* | | ------- | |
- * v | | | |---|
+ * v | | | |--'
* S5 +--------------------------+ S3
* <--> S1
* WR
#define ROBOT_AXIS_TO_BACK_M (ROBOT_AXIS_TO_BACK_MM/1000.0)
#define ROBOT_AXIS_TO_FRONT_MM 183 /* AF */
#define ROBOT_AXIS_TO_FRONT_M (ROBOT_AXIS_TO_FRONT_MM/1000.0)
-#define ROBOT_AXIS_TO_BELT_MM 280 /* ABE */ /* FIXME: no belt in the Eurobot 2008 */
-#define ROBOT_AXIS_TO_BELT_M (ROBOT_AXIS_TO_BELT_MM/1000.0)
+#define ROBOT_AXIS_TO_BRUSH_MM 280 /* ABE */
+#define ROBOT_AXIS_TO_BRUSH_M (ROBOT_AXIS_TO_BRUSH_MM/1000.0)
/**
Pos future_pos;
struct map *map = robot.map;
int xcell, ycell;
+ double x, y;
+ bool valid;
- traj->getRefPos(current_time+0.5, future_pos);
+ traj->getRefPos(current_time+1/*s*/, future_pos);
- ShmapPoint2Cell(future_pos.x, future_pos.y, &xcell, &ycell);
- printf("Checking cell %2d %2d", xcell, ycell);
+ /* Ignore obstacles when turning */
+ if (fabs(future_pos.v) < 0.01)
+ return;
+
+ x = future_pos.x + cos(future_pos.phi)*ROBOT_AXIS_TO_BRUSH_M;
+ y = future_pos.y + sin(future_pos.phi)*ROBOT_AXIS_TO_BRUSH_M;
+
+ ShmapPoint2Cell(x, y, &xcell, &ycell, &valid);
+ if (!valid)
+ return;
if (map->cells[ycell][xcell].detected_obstacle > 0) {
- printf(" obstacle");
if (sem_trywait(&recalculation_not_running) == 0) {
- printf(" - starting recalc");
sem_post(&start_recalculation);
}
}
- printf("\n");
}
static void do_control()
/* This recalculation must only be triggered from mvoement state. */
void *thread_trajectory_realculation(void *arg)
{
- printf("Recalculation thread ready");
while (1) {
sem_wait(&start_recalculation);
- printf("Recalculation started");
/* TODO: Different start for planning than esitmated position */
enum target_status ret = new_goal(¤t_target);
switch (ret) {
struct est_pos_type est_pos;
struct map *map = robot.map;
double xx, yy;
+ bool valid;
if (!map)
return;
- ShmapPoint2Cell(x, y, &xcell, &ycell);
- if (!ShmapIsCellInMap(xcell, ycell))
+ ShmapPoint2Cell(x, y, &xcell, &ycell, &valid);
+ if (!valid)
return;
/* The obstacle was detected here */