ld_stats.c
Go to the documentation of this file.
1 #include <options/options.h>
2 
3 #include <csm/csm_all.h>
4 
5 int main(int argc, const char * argv[]) {
6  sm_set_program_name(argv[0]);
7 
8  const char*input_filename;
9  const char*output_filename;
10  double max_xy;
11  double max_theta_deg;
12 
13  struct option* ops = options_allocate(10);
14  options_string(ops, "in", &input_filename, "stdin", "input file (log)");
15  options_string(ops, "out", &output_filename, "stdout", "output file ");
16  options_double(ops, "max_xy", &max_xy, 100.0, "Max admissible xy displacement");
17  options_double(ops, "max_theta_deg", &max_theta_deg, 360.0,
18  "Max admissible theta displacement (deg)");
19 
20  if(!options_parse_args(ops, argc, argv)) {
21  sm_info("computes odometry statistics.\n\nOptions:\n");
22  options_print_help(ops, stderr);
23  return -1;
24  }
25 
26  FILE * input_stream = open_file_for_reading(input_filename);
27  FILE *output_stream = open_file_for_writing(output_filename);
28 
29  if(!input_stream || !output_stream) return -1;
30 
31  LDP laser_ref = ld_read_smart(input_stream);
32  if(!laser_ref) {
33  sm_error("Cannot read first scan.\n.");
34  return -2;
35  }
36 
37  int count = 0, valid = 0;
38  LDP laser_sens;
39 
40  double avg_correction[3] = {0,0,0};
41  double max_correction[3] = {0,0,0};
42  while((laser_sens = ld_read_smart(input_stream))) {
43  double diff_true_pose[3], diff_odometry[3], diff_estimate[3];
44  pose_diff_d(laser_sens->odometry, laser_ref->odometry, diff_odometry);
45  pose_diff_d(laser_sens->true_pose, laser_ref->true_pose, diff_true_pose);
46  pose_diff_d(laser_sens->estimate, laser_ref->estimate, diff_estimate);
47  double diff[3];
48  pose_diff_d(diff_estimate, diff_odometry, diff);
49 
50  JO jo = jo_new();
51  jo_add_double_array(jo, "diff_odometry", diff_odometry, 3);
52  jo_add_double_array(jo, "diff_true_pose", diff_true_pose, 3);
53  jo_add_double_array(jo, "diff_estimate", diff_estimate, 3);
54  jo_add_double_array(jo, "correction", diff, 3);
55 
56  fputs(jo_to_string(jo), output_stream);
57  fputs("\n", output_stream);
58  jo_free(jo);
59  ld_free(laser_ref);
60  laser_ref = laser_sens;
61 
62  int use_it = (fabs(diff[0]) < max_xy) && (fabs(diff[1]) < max_xy) &&
63  (fabs(diff[2]) < deg2rad(max_theta_deg));
64 
65  if(use_it) {
66  int i; for(i=0;i<3;i++) {
67  avg_correction[i] += diff[i];
68  max_correction[i] = GSL_MAX(max_correction[i], fabs(diff[i]));
69  }
70  valid ++;
71  }
72 
73  count ++;
74  }
75 
76  int i; for(i=0;i<3;i++)
77  avg_correction[i] /= valid;
78 
79  fprintf(stderr, "Used %d/%d rays (%.1f %%)\n", valid, count, (100.0 *valid)/count);
80 
81  fprintf(stderr, "Avg: %f %f %f = %fdeg \n",
82  avg_correction[0], avg_correction[1], avg_correction[2], rad2deg(avg_correction[2]));
83  fprintf(stderr, "Max: %f %f %f = %fdeg \n",
84  max_correction[0], max_correction[1], max_correction[2], rad2deg(max_correction[2]));
85 
86  return 0;
87 }
#define deg2rad(x)
Definition: gpc_test.c:22
double true_pose[3]
Definition: laser_data.h:38
void sm_set_program_name(const char *name)
Definition: logging.c:21
#define jo_to_string
double odometry[3]
Definition: laser_data.h:39
#define jo_new
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)
void jo_add_double_array(JO root, const char *name, const double *v, int n)
FILE * open_file_for_reading(const char *filename)
Definition: utils.c:19
void options_print_help(struct option *options, FILE *f)
Definition: options.c:398
double estimate[3]
Definition: laser_data.h:40
void sm_info(const char *msg,...)
Definition: logging.c:71
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
int main(int argc, const char *argv[])
Definition: ld_stats.c:5
void sm_error(const char *msg,...)
Definition: logging.c:49
int options_parse_args(struct option *ops, int argc, const char *argv[])
Definition: options.c:66
double rad2deg(double rad)
Definition: math_utils.c:79
#define jo_free


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