]> rtime.felk.cvut.cz Git - eurobot/public.git/blobdiff - src/robofsm/robot.c
robofsm: Do not calibrate odometery right after robot init.
[eurobot/public.git] / src / robofsm / robot.c
index ab43c837adb567f72692595c2c33bc73ccd4ae9f..7704096c42e8b6fce6c05603759a8b7efc4fd5d8 100644 (file)
@@ -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;
@@ -60,10 +61,10 @@ void fill_in_known_areas_in_map()
 {
        /*----- 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, 0.40, 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 */
+       ShmapSetRectangleFlag(2.6, 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);
@@ -72,11 +73,14 @@ void fill_in_known_areas_in_map()
        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);
+       //ShmapSetCircleFlag(1.5, 1.0, 0.075, MAP_FLAG_WALL, 0);
        
-       /* Totems */
-       ShmapSetRectangleFlag(1.01, 0.91, 1.19, 1.09, MAP_FLAG_WALL, 0);
-       ShmapSetRectangleFlag(1.81, 0.91, 1.99, 1.09, MAP_FLAG_WALL, 0);
+       /* Totems and palm tree */
+       ShmapSetRectangleFlag(0.975, 0.875, 2.025, 1.125, MAP_FLAG_WALL, 0);
+        ShmapSetCircleFlag(1.1, 1.0, 0.3, MAP_FLAG_WALL, 0);
+        ShmapSetCircleFlag(2.0, 1.0, 0.3, 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)
@@ -104,7 +108,6 @@ int robot_init()
 {
        int rv;
        pthread_mutexattr_t mattr;
-
        rv = pthread_mutexattr_init(&mattr);
 #ifdef HAVE_PRIO_INHERIT
        rv = pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
@@ -127,12 +130,12 @@ int robot_init()
        robot.fsm.act.transition_callback = trans_callback;
        robot.fsm.motion.transition_callback = trans_callback;
 
-       robot.team_color = RED;
+       robot.team_color = VIOLET;
 
-       if (robot.team_color == RED) {
-               ul_loginf("We are RED!\n");
+       if (robot.team_color == VIOLET) {
+               ul_loginf("We are VIOLET!\n");
        } else {
-               ul_loginf("We are BLUE!\n");
+               ul_loginf("We are RED!\n");
        }
 
        robot_set_est_pos_trans(ROBOT_START_X_M, ROBOT_START_Y_M, DEG2RAD(ROBOT_START_ANGLE_DEG));
@@ -285,3 +288,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, "ODO calibration file not found! \n\n");
+               return;
+       }
+       char line [15];
+       float a = 0;
+       float b = 0;
+       int num = 0;
+       while (fgets (line, 15 , file)) {
+               a += atof(strtok(line," "));
+               fgets (line, 15 , file);
+               b += atof(strtok(NULL," "));
+               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("ODO calibrated value A: %f\n",robot.odo_cal_a);
+       printf("ODO calibrated value B: %f\n",robot.odo_cal_b);
+}