7 #include <movehelper.h>
14 #include "actuators.h"
17 #include "match-timing.h"
20 #include "common-states.h"
22 void robot_calibrate_odometry()
24 robot.odo_distance_a = 0;
25 robot.odo_distance_b = 0;
27 file = fopen ("odometry_cal_data", "r");
32 fprintf(stderr, "ODO calibration file not found! \n\n");
39 while (fgets (line, 15 , file)) {
40 a += atof(strtok(line," "));
41 fgets (line, 15 , file);
42 b += atof(strtok(NULL," "));
44 printf("a: %i, b: %i, num: %i\n", a, b, num);
47 if(a == 0 || b == 0) {
52 robot.odo_cal_a = a / num;
53 robot.odo_cal_b = b / num;
54 printf("ODO calibrated value A: %f\n",robot.odo_cal_a);
55 printf("ODO calibrated value B: %f\n",robot.odo_cal_b);
58 UL_LOG_CUST(ulogd_strategy_odo_calibration); /* Log domain name = ulogd + name of the file */
67 ul_logmsg("waiting for start\n");
73 robot.use_back_bumpers = false;
76 FSM_TRANSITION(go_back_for_cal);
85 case EV_SWITCH_STRATEGY:
86 FSM_TRANSITION(central_buillon_wait_for_start);
92 /* State for odometry calibration */
94 FSM_STATE(go_back_for_cal)
96 double x1 = 0, y1 = 0;
100 robot_set_est_pos_trans(ROBOT_AXIS_TO_BACK_M + 1.0,
101 PLAYGROUND_HEIGHT_M - (ROBOT_WIDTH_M/2.0),
103 robot_move_by(-1.1, NO_TURN(), &tcVerySlow);
107 ROBOT_LOCK(est_pos_odo);
108 robot.odo_cal_a = -1.0/robot.odo_distance_a;
109 robot.odo_cal_b = -1.0/robot.odo_distance_b;
110 x1 = robot.odo_distance_a;
111 y1 = robot.odo_distance_b;
112 ROBOT_UNLOCK(est_pos_odo);
113 if(x1 != 0 || y1 != 0) {
114 printf("Distance for calibration: \n");
115 printf("Left%f\n", x1);
116 printf("Right%f\n", y1);
118 file = fopen ("odometry_cal_data","w");
119 sprintf(buffer, "%4.4f", -1/x1);
122 sprintf(buffer, "%4.4f", -1/y1);
127 FSM_TRANSITION(central_buillon_wait_for_start);
130 ROBOT_LOCK(est_pos_odo);
131 if(x1 == robot.odo_distance_a){
132 x1 = robot.odo_distance_a;
133 y1 = robot.odo_distance_b;
135 FSM_SIGNAL(MOTION,EV_MOVE_STOP, NULL);
136 FSM_SIGNAL(MAIN, EV_MOTION_DONE, NULL);
140 ROBOT_UNLOCK(est_pos_odo);