sm3.c
Go to the documentation of this file.
1 #include <time.h>
2 #include <string.h>
3 
4 #include "../csm/csm_all.h"
5 
6 #include <options/options.h>
7 
8 struct sm3_params {
9  const char * input_filename;
10 
11 } p;
12 extern void sm_options(struct sm_params*p, struct option*ops);
13 
14 extern int distance_counter;
15 
16 
17 int main(int argc, const char*argv[]) {
18  sm_set_program_name(argv[0]);
19 
20  struct sm_params params;
21  struct sm_result result;
22 
23  struct option* ops = options_allocate(100);
24  options_string(ops, "in", &p.input_filename, "stdin",
25  "Log file");
26 
27  sm_options(&params, ops);
28  if(!options_parse_args(ops, argc, argv)) {
29  fprintf(stderr, "\n\nUsage:\n");
30  options_print_help(ops, stderr);
31  return -1;
32  }
33 
34  FILE * file = open_file_for_reading(p.input_filename);
35  if(!file) return -1;
36 
37  LDP *lds; int lds_size;
38  if(!ld_read_all(file, &lds, &lds_size)) {
39  sm_error("Cannot read all laser scans.\n");
40  return -1;
41  }
42 
43  sm_debug("Read %d scans.\n", lds_size);
44 
45 
46  int num_matchings = 0;
47  int num_iterations = 0;
48  clock_t start = clock();
49 
50  int i;
51  for(i=0;i<lds_size-1;i++) {
52  params.laser_ref = lds[i];
53  params.laser_sens = lds[i+1];
54 
55  double odometry[3];
56  pose_diff_d(params.laser_sens->odometry, params.laser_ref->odometry, odometry);
57  double ominus_laser[3], temp[3];
58  ominus_d(params.laser, ominus_laser);
59  oplus_d(ominus_laser, odometry, temp);
60  oplus_d(temp, params.laser, params.first_guess);
61 
62  sm_icp(&params,&result);
63 
64  num_matchings++;
65  num_iterations += result.iterations;
66 
67  fprintf(stderr, ".");
68  }
69 
70  clock_t end = clock();
71  float seconds = (end-start)/((float)CLOCKS_PER_SEC);
72 
73  if(num_matchings>0) {
74  printf("sm3: CPU time = %f (seconds) (start=%d end=%d)\n", seconds,(int)start,(int)end);
75  printf("sm3: Total number of matchings = %d\n", num_matchings);
76  printf("sm3: Total number of iterations = %d\n", num_iterations);
77  printf("sm3: Avg. iterations per matching = %f\n", num_iterations/((float)num_matchings));
78  printf("sm3: Avg. seconds per matching = %f\n", seconds/num_matchings);
79  printf("sm3: that is, %d matchings per second\n", (int)floor(num_matchings/seconds));
80  printf("sm3: Avg. seconds per iteration = %f (note: very imprecise)\n", seconds/num_iterations);
81  printf("sm3: Number of comparisons = %d \n", distance_counter);
82  printf("sm3: Avg. comparisons per ray per iteration = %f \n",
83  (distance_counter/((float)num_iterations*params.laser_ref->nrays)));
84  } else {
85  sm_error("Empty file?\n");
86  return 1;
87  }
88  return 0;
89 }
void sm_set_program_name(const char *name)
Definition: logging.c:21
void sm_icp(struct sm_params *input, struct sm_result *output)
Definition: icp.c:29
double odometry[3]
Definition: laser_data.h:39
int iterations
Definition: algos.h:146
int main(int argc, const char *argv[])
Definition: sm3.c:17
struct option * ops
Definition: rb_sm.c:31
Definition: options.h:49
int ld_read_all(FILE *file, LDP **array, int *num)
struct option * options_allocate(int n)
void sm_options(struct sm_params *p, struct option *ops)
Definition: sm_options.c:6
const char * input_filename
Definition: sm3.c:9
LDP laser_ref
Definition: algos.h:14
LDP laser_sens
Definition: algos.h:16
FILE * open_file_for_reading(const char *filename)
Definition: utils.c:19
double first_guess[3]
Definition: algos.h:19
void oplus_d(const double x1[3], const double x2[3], double res[3])
Definition: math_utils.c:96
struct sm3_params p
double laser[3]
Definition: algos.h:121
int distance_counter
Definition: math_utils.c:46
void options_print_help(struct option *options, FILE *f)
Definition: options.c:398
void ominus_d(const double x[3], double res[3])
Definition: math_utils.c:87
void sm_debug(const char *msg,...)
Definition: logging.c:88
void options_string(struct option *, const char *name, const char **p, const char *def_balue, const char *desc)
Definition: sm3.c:8
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 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