X-Git-Url: http://rtime.felk.cvut.cz/gitweb/eurobot/public.git/blobdiff_plain/e3c466600b579d6e9c892b5cb41dee6cfd8f4b86..bfbd61a139592e6564fc79035e7d72e5668a002b:/src/robofsm/robot.c diff --git a/src/robofsm/robot.c b/src/robofsm/robot.c index bf3120e2..5aeb5dd4 100644 --- a/src/robofsm/robot.c +++ b/src/robofsm/robot.c @@ -31,6 +31,7 @@ UL_LOG_CUST(ulogd_robot); /* Log domain name = ulogd + name of the file */ #define MOTION_CONTROL_INIT_ONLY #include "motion-control.h" +#include "robot.h" /* Global definition of robot structure */ struct robot robot; @@ -58,36 +59,25 @@ static void int_handler(int sig) void fill_in_known_areas_in_map() { - /* Do not plan path close to edges */ - //ShmapSetRectangleFlag(0.0, 0.0, 0.26, 2.1, MAP_FLAG_WALL, 0); /* left */ - //ShmapSetRectangleFlag(0.0, 0.0, 3.0, 0.26, MAP_FLAG_WALL, 0); /* bottom */ - //ShmapSetRectangleFlag(0.0, 1.84, 3.0, 2.1, MAP_FLAG_WALL, 0); /* top */ - //ShmapSetRectangleFlag(2.74, 0.0, 3.0, 2.1, MAP_FLAG_WALL, 0); /* right */ - -// /* Container surroundings */ -// ShmapSetRectangleFlag(0.0, 0.0, 0.4, 0.2, 0, MAP_FLAG_WALL); /* left container */ -// ShmapSetRectangleFlag(3.0, 0.0, 2.6, 0.2, 0, MAP_FLAG_WALL); /* right container */ - -// /* Ignore other obstacles at edges */ -// ShmapSetRectangleFlag(0.0, 0.0, 0.09, 2.1, MAP_FLAG_IGNORE_OBST, 0); /* left */ -// ShmapSetRectangleFlag(0.0, 0.0, 3.0, 0.09, MAP_FLAG_IGNORE_OBST, 0); /* bottom */ -// ShmapSetRectangleFlag(0.0, 2.01, 3.0, 2.1, MAP_FLAG_IGNORE_OBST, 0); /* top */ -// ShmapSetRectangleFlag(2.91, 0.0, 3.0, 2.1, MAP_FLAG_IGNORE_OBST, 0); /* right */ -// ShmapSetRectangleFlag(1.0, 1.5, 1.95, 2.1, MAP_FLAG_IGNORE_OBST, 0); /* rised area */ - - /* start blocs */ - ShmapSetRectangleFlag(0, 1.7, 0.4, 1.678, MAP_FLAG_WALL, 0); - ShmapSetRectangleFlag(2.55, 1.7, 3, 1.678, MAP_FLAG_WALL, 0); - - /* protected bloc left */ - ShmapSetRectangleFlag(0.45, 0, 1.15, 0.12, MAP_FLAG_WALL, 0); - ShmapSetRectangleFlag(0.45, 0.12, 0.472, 0.25, MAP_FLAG_WALL, 0); - ShmapSetRectangleFlag(1.128, 0.12, 1.15, 0.25, MAP_FLAG_WALL, 0); - - /* protected bloc right */ - ShmapSetRectangleFlag(1.85, 0, 2.55, 0.12, MAP_FLAG_WALL, 0); - ShmapSetRectangleFlag(1.85, 0.12, 1.872, 0.25, MAP_FLAG_WALL, 0); - ShmapSetRectangleFlag(2.528, 0.12, 2.55, 0.25, MAP_FLAG_WALL, 0); + /*----- playground width 3.0 m and playground height 2.0 m -----*/ + /* Ignore other obstacles at edges */ + ShmapSetRectangleFlag(0.0, 0.0, 0.09, 2.0, MAP_FLAG_IGNORE_OBST, 0); /* left */ + ShmapSetRectangleFlag(0.0, 0.0, 3.0, 0.09, MAP_FLAG_IGNORE_OBST, 0); /* bottom */ + ShmapSetRectangleFlag(0.0, 1.91, 3.0, 2.0, MAP_FLAG_IGNORE_OBST, 0); /* top */ + ShmapSetRectangleFlag(2.91, 0.0, 3.0, 2.0, MAP_FLAG_IGNORE_OBST, 0); /* right */ + + /* Small walls that cannot be detected by hokuyo */ + ShmapSetRectangleFlag(0.0, 1.49, 0.39, 1.432, MAP_FLAG_WALL, 0); + ShmapSetRectangleFlag(3.0, 1.49, 2.61, 1.432, MAP_FLAG_WALL, 0); + ShmapSetRectangleFlag(0.325, 0.0, 0.38, 0.74, MAP_FLAG_WALL, 0); + ShmapSetRectangleFlag(2.675, 0.0, 2.62, 0.74, MAP_FLAG_WALL, 0); + + /* Palm tree */ + //ShmapSetCircleFlag(1.5, 1.0, 0.075, MAP_FLAG_WALL, 0); + + /* Totems and palm tree */ + ShmapSetRectangleFlag(0.975, 0.875, 2.025, 1.125, MAP_FLAG_WALL, 0); + //ShmapSetRectangleFlag(1.775, 0.875, 2.025, 1.125, MAP_FLAG_WALL, 0); } static void trans_callback(struct robo_fsm *fsm) @@ -115,7 +105,7 @@ int robot_init() { int rv; pthread_mutexattr_t mattr; - + robot_calibrate_odometry(); rv = pthread_mutexattr_init(&mattr); #ifdef HAVE_PRIO_INHERIT rv = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT); @@ -146,7 +136,7 @@ int robot_init() ul_loginf("We are BLUE!\n"); } - robot_set_est_pos_trans(1, 1, DEG2RAD(0)); + robot_set_est_pos_trans(ROBOT_START_X_M, ROBOT_START_Y_M, DEG2RAD(ROBOT_START_ANGLE_DEG)); robot.ignore_hokuyo = false; robot.map = ShmapInit(1); @@ -176,9 +166,9 @@ int robot_init() */ robot.obstacle_avoidance_enabled = true; - robot.use_back_switch = true; - robot.use_left_switch = true; - robot.use_right_switch = true; + robot.use_back_bumpers = true; + robot.use_left_bumper = true; + robot.use_right_bumper = true; robot.start_state = POWER_ON; robot.check_turn_safety = true; @@ -296,3 +286,38 @@ void robot_get_est_pos(double *x, double *y, double *phi) ROBOT_UNLOCK(ref_pos); } } + +void robot_calibrate_odometry() +{ + robot.odo_distance_a = 0; + robot.odo_distance_b = 0; + FILE *file; + file = fopen ("odometry_cal_data", "r"); + if (file == NULL) + { + robot.odo_cal_a = 1; + robot.odo_cal_b = 1; + fprintf(stderr, "File not found. \n\n"); + return; + } + char line [10]; + float a = 0; + float b = 0; + int num = 0; + while (fgets (line, 10 , file)) { + a = atof(line); + fgets (line, 10 , file); + b = atof(line); + num ++; + } + fclose (file); + if(a == 0 || b == 0) { + robot.odo_cal_a = 1; + robot.odo_cal_b = 1; + return; + } + robot.odo_cal_a = a / num; + robot.odo_cal_b = b / num; + printf("calibrated value left: %f\n",robot.odo_cal_a); + printf("calibrated value right: %f\n",robot.odo_cal_b); +}