sm0.c
Go to the documentation of this file.
1 #include <time.h>
2 
3 #include "../csm/csm_all.h"
4 
5 
6 extern int distance_counter;
7 int main(int argc, const char*argv[]) {
8  FILE * file;
9  if(argc==1) {
10  file = stdin;
11  } else {
12  const char * filename = argv[1];
13  file = fopen(filename,"r");
14  if(file==NULL) {
15  fprintf(stderr, "Could not open '%s'.\n", filename);
16  return -1;
17  }
18  }
19 
20  struct sm_params params;
21  struct sm_result result;
22 
23  params.max_angular_correction_deg = 5;
24  params.max_linear_correction = 0.2;
25  params.max_iterations = 30;
26  params.epsilon_xy = 0.001;
27  params.epsilon_theta = 0.001;
28  params.max_correspondence_dist = 2;
29  params.sigma = 0.01;
30  params.restart = 1;
31  params.restart_threshold_mean_error = 3.0 / 300.0;
32  params.restart_dt= 0.1;
33  params.restart_dtheta= 1.5 * 3.14 /180;
34 
35  params.clustering_threshold = 0.05;
36  params.orientation_neighbourhood = 3;
37  params.use_corr_tricks = 1;
38 
39  params.do_alpha_test = 0;
40  params.outliers_maxPerc = 0.85;
41 
42  params.outliers_adaptive_order =0.7;
43  params.outliers_adaptive_mult=2;
44  params.do_visibility_test = 1;
45  params.do_compute_covariance = 0;
46 
47  int num_matchings = 0;
48  int num_iterations = 0;
49  clock_t start = clock();
50 
51  if(!(params.laser_ref = ld_read_smart(file)) ) {
52  printf("Could not read first scan.\n");
53  return -1;
54  }
55 
56  gsl_vector *u = gsl_vector_alloc(3);
57  gsl_vector *x_old = gsl_vector_alloc(3);
58  gsl_vector *x_new = gsl_vector_alloc(3);
59  while(! (params.laser_sens = ld_read_smart(file)) ) {
60  copy_from_array(x_old, params.laser_ref->odometry);
61  copy_from_array(x_new, params.laser_sens->odometry);
62  pose_diff(x_new,x_old,u);
63  vector_to_array(u, params.first_guess);
64 
65  sm_gpm(&params,&result);
66  /* sm_icp(&params,&result); */
67 
68  num_matchings++;
69  num_iterations += result.iterations;
70 
71  ld_free(params.laser_ref);
72  params.laser_ref = params.laser_sens;
73  }
74 
75  clock_t end = clock();
76  float seconds = (end-start)/((float)CLOCKS_PER_SEC);
77 
78  sm_debug("sm0: CPU time = %f (seconds) (start=%d end=%d)\n", seconds,(int)start,(int)end);
79  sm_debug("sm0: Total number of matchings = %d\n", num_matchings);
80  sm_debug("sm0: Total number of iterations = %d\n", num_iterations);
81  sm_debug("sm0: Avg. iterations per matching = %f\n", num_iterations/((float)num_matchings));
82  sm_debug("sm0: Avg. seconds per matching = %f\n", seconds/num_matchings);
83  sm_debug("sm0: that is, %d matchings per second\n", (int)floor(num_matchings/seconds));
84  sm_debug("sm0: Avg. seconds per iteration = %f (note: very imprecise)\n", seconds/num_iterations);
85  sm_debug("sm0: Number of comparisons = %d \n", distance_counter);
86  sm_debug("sm0: Avg. comparisons per ray = %f \n",
87  (distance_counter/((float)num_iterations*params.laser_ref->nrays)));
88 
89  ld_free(params.laser_ref);
90 
91  gsl_vector_free(u);
92  gsl_vector_free(x_old);
93  gsl_vector_free(x_new);
94  return 0;
95 }
sm_debug
void sm_debug(const char *msg,...)
Definition: logging.c:88
pose_diff
void pose_diff(const gsl_vector *pose2, const gsl_vector *pose1, gsl_vector *res)
Definition: math_utils_gsl.c:58
sm_params
Definition: algos.h:12
ld_free
void ld_free(LDP ld)
Definition: laser_data.c:87
sm_result::iterations
int iterations
Definition: algos.h:146
vector_to_array
void vector_to_array(const gsl_vector *v, double *x)
Definition: math_utils_gsl.c:36
sm_gpm
void sm_gpm(struct sm_params *input, struct sm_result *output)
Definition: gpm.c:11
distance_counter
int distance_counter
Definition: math_utils.c:46
sm_result
Definition: algos.h:138
ld_read_smart
LDP ld_read_smart(FILE *)
Definition: laser_data_load.c:130
copy_from_array
void copy_from_array(gsl_vector *v, double *x)
Definition: math_utils_gsl.c:30
main
int main(int argc, const char *argv[])
Definition: sm0.c:7
params
Definition: carmen2pdf.c:20


csm
Author(s): Andrea Censi
autogenerated on Wed Aug 17 2022 02:50:34