ld_correct.c
Go to the documentation of this file.
1 #include <math.h>
2 #include <gsl/gsl_math.h>
3 
4 #include <options/options.h>
5 
6 #include "../csm/csm_all.h"
7 
8 int main(int argc, const char * argv[]) {
9  sm_set_program_name(argv[0]);
10 
11 
12  const char*input_filename;
13  const char*output_filename;
14  double diff[3] = {0, 0, 0};
15 
16  double laser[3] ={0,0,0};
17 
18  double omega[2] ={0,0};
19  double omega_vel = 0;
20  double vel[2] ={0,0};
21  double vel_omega = 0;
22 
23 
24  struct option* ops = options_allocate(15);
25  options_string(ops, "in", &input_filename, "stdin", "input file");
26  options_string(ops, "out", &output_filename, "stdout", "output file");
27  options_double(ops, "l_x", &(laser[0]), 0.0, "laser x (m)");
28  options_double(ops, "l_y", &(laser[1]), 0.0, "laser y (m)");
29  options_double(ops, "l_theta", &(laser[2]), 0.0, "laser theta (rad)");
30 
31  options_double(ops, "omega0", &(omega[0]), 0.0, "omega (rad)");
32  options_double(ops, "omega1", &(omega[1]), 0.0, "omega (linear)");
33  options_double(ops, "omega_vel", &(omega_vel), 0.0, "omega x vel");
34  options_double(ops, "vel0", &(vel[0]), 0.0, "vel (m)");
35  options_double(ops, "vel1", &(vel[1]), 0.0, "vel (linear)");
36  options_double(ops, "vel_omega", &(vel_omega), 0.0, "vel x omega");
37 
38 
39  if(!options_parse_args(ops, argc, argv)) {
40  fprintf(stderr, " Corrects bias in odometry.\n");
41  options_print_help(ops, stderr);
42  return -1;
43  }
44 
45  FILE * input_stream = open_file_for_reading(input_filename);
46  FILE *output_stream = open_file_for_writing(output_filename);
47 
48  if(!input_stream || !output_stream) return -1;
49 
50  LDP laser_ref = ld_read_smart(input_stream);
51  if(!laser_ref) {
52  sm_error("Cannot read first scan.\n");
53  return -2;
54  }
55 
56  copy_d(laser_ref->odometry, 3, laser_ref->estimate);
57 
58  double old_odometry[3];
59  copy_d(laser_ref->odometry, 3, old_odometry);
60 
61  LDP laser_sens;
62  ld_write_as_json(laser_ref, output_stream);
63 
64  while((laser_sens = ld_read_smart(input_stream))) {
65  double guess[3], old_guess[3];
66  pose_diff_d(laser_sens->odometry, old_odometry, guess);
67  pose_diff_d(laser_sens->odometry, old_odometry, old_guess);
68  copy_d(laser_sens->odometry, 3, old_odometry);
69 
70  if(fabs(guess[2]) > 1e-7)
71  guess[2] = old_guess[2] * omega[1] + omega_vel * guess[0] + omega[0];
72 
73  if(fabs(guess[0]) > 1e-7)
74  guess[0] = old_guess[0] * vel[1] + vel_omega * guess[2] + vel[0];
75 
76  fprintf(stderr, "odo: %f %f %f Corr: %f rad \t%f m \n", guess[0], guess[1], guess[2], guess[2]-old_guess[2], guess[0]-old_guess[0]);
77 
78  oplus_d(laser_ref->odometry, guess, laser_sens->odometry);
79  oplus_d(laser_sens->odometry, laser, laser_sens->estimate);
80 
81  fprintf(stderr, "ref odo: %s ref est: %s \n",
82  friendly_pose(laser_ref->odometry),
83  friendly_pose(laser_ref->estimate));
84  fprintf(stderr, "sens odo: %s sens est: %s \n",
85  friendly_pose(laser_sens->odometry),
86  friendly_pose(laser_sens->estimate));
87 
88 
89 
90  ld_write_as_json(laser_sens, output_stream);
91 
92  ld_free(laser_ref);
93  laser_ref = laser_sens;
94  }
95 
96  return 0;
97 }
void sm_set_program_name(const char *name)
Definition: logging.c:21
void ld_write_as_json(LDP ld, FILE *stream)
double odometry[3]
Definition: laser_data.h:39
void copy_d(const double *from, int n, double *to)
Definition: math_utils.c:83
const char * friendly_pose(const double *pose)
Definition: math_utils.c:266
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
struct option * ops
Definition: rb_sm.c:31
FILE * open_file_for_writing(const char *filename)
Definition: utils.c:25
LDP ld_read_smart(FILE *)
Definition: options.h:49
void ld_free(LDP ld)
Definition: laser_data.c:87
struct option * options_allocate(int n)
FILE * open_file_for_reading(const char *filename)
Definition: utils.c:19
void oplus_d(const double x1[3], const double x2[3], double res[3])
Definition: math_utils.c:96
void options_print_help(struct option *options, FILE *f)
Definition: options.c:398
double estimate[3]
Definition: laser_data.h:40
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
void pose_diff_d(const double pose2[3], const double pose1[3], double res[3])
Definition: math_utils.c:115
void sm_error(const char *msg,...)
Definition: logging.c:49
int main(int argc, const char *argv[])
Definition: ld_correct.c:8
int options_parse_args(struct option *ops, int argc, const char *argv[])
Definition: options.c:66


csm
Author(s): Andrea Censi
autogenerated on Tue May 11 2021 02:18:23