{
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);
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;
+}
/** is set to true in separate thread when there is short time left */
bool short_time_to_end;
bool check_turn_safety;
+
+ float odo_cal_b;
+ float odo_cal_a;
+ float odo_distance_a;
+ float odo_distance_b;
}; /* robot */
extern struct robot robot;
int robot_start() __attribute__ ((warn_unused_result));
void robot_exit();
void robot_destroy();
+void robot_calibrate_odometry();
void robot_get_est_pos_trans(double *x, double *y, double *phi);
void robot_get_est_pos(double *x, double *y, double *phi);
break;
}
- dleft = ((robot.odo_data.left - instance->left) >> 8) * c; // TODO >> 8 ?
- dright = ((instance->right - robot.odo_data.right) >> 8) * c;
+ dleft = ((robot.odo_data.left - instance->left) >> 8) * c * robot.odo_cal_a; // TODO >> 8 ?
+ dright = ((instance->right - robot.odo_data.right) >> 8) * c * robot.odo_cal_b;
dtang = (dleft + dright) / 2.0;
dphi = (dright - dleft) / (2.0*ODOMETRY_ROTATION_RADIUS_M);
ROBOT_LOCK(est_pos_indep_odo);
+ robot.odo_distance_a +=dleft;
+ robot.odo_distance_b +=dright;
double a = robot.est_pos_indep_odo.phi;
robot.est_pos_indep_odo.x += dtang*cos(a);
robot.est_pos_indep_odo.y += dtang*sin(a);
/* FIXME maybe it is not correct to do this nasty hack here (switch dleft and dright),
what is the right solution?
This was neccessary to view motor odometry correctly in robomon. */
- dright = ((robot.motion_irc.left - instance->left) >> 8) * c;
- dleft = ((instance->right - robot.motion_irc.right) >> 8) * c;
-
+ dright = ((robot.motion_irc.left - instance->left) >> 8) * c * robot.odo_cal_b;
+ dleft = ((instance->right - robot.motion_irc.right) >> 8) * c * robot.odo_cal_a;
+
dtang = (dleft + dright) / 2.0;
dphi = (dright - dleft) / (2.0*ROBOT_ROTATION_RADIUS_M);
ROBOT_LOCK(est_pos_odo);
+ robot.odo_distance_a +=dleft;
+ robot.odo_distance_b +=dright;
double a = robot.est_pos_odo.phi;
robot.est_pos_odo.x += dtang*cos(a);
robot.est_pos_odo.y += dtang*sin(a);