hsm_interface.c
Go to the documentation of this file.
1 #include <options/options.h>
2 #include <assert.h>
3 
4 #include "../csm_all.h"
5 
6 void hsm_add_options(struct option* ops, struct hsm_params*p) {
7  options_double(ops, "hsm_linear_cell_size", &p->linear_cell_size, 0.03, "HSM: Size of a rho cell");
8  options_double(ops, "hsm_angular_cell_size_deg", &p->angular_cell_size_deg, 1.0, "HSM: Size of angualar cell (deg)");
9  options_int(ops, "hsm_num_angular_hypotheses", &p->num_angular_hypotheses, 8, "HSM: Number of angular hypotheses.");
10  options_double(ops, "hsm_xc_directions_min_distance_deg", &p->xc_directions_min_distance_deg, 10.0, "HSM: Min distance between directions for cross corr (deg)");
11  options_int(ops, "hsm_xc_ndirections", &p->xc_ndirections, 3, "HSM: Number of directions for cross corr (deg)");
12  options_double(ops, "hsm_angular_hyp_min_distance_deg", &p->angular_hyp_min_distance_deg, 10.0, "HSM: Min distance between different angular hypotheses (deg)");
13 
14  options_int(ops, "hsm_linear_xc_max_npeaks", &p->linear_xc_max_npeaks, 5, "HSM: Number of peaks per direction for linear translation");
15  options_double(ops, "hsm_linear_xc_peaks_min_distance", &p->linear_xc_peaks_min_distance, 5.0, "HSM: Min distance between different peaks in linear correlation");
16 }
17 
18 int hsm_compute_ht_for_scan(LDP ld, struct hsm_params*p, const double base[3], hsm_buffer *b);
19 
20 int hsm_compute_ht_for_scan(LDP ld, struct hsm_params*p, const double base[3], hsm_buffer *b) {
21  *b = 0;
22 
24  double max_reading = max_in_array(ld->readings, ld->nrays);
25 
26  if(!(max_reading>0)) {
27  sm_error("No valid points.\n");
28  return 0;
29  }
30 
31  p->max_norm = norm_d(base) + max_reading;
32 
33  *b = hsm_buffer_alloc(p);
34  hsm_compute_ht_base(*b, base);
35 
37  int np = 0;
38  for(int i=0; i<ld->nrays; i++) {
39  if(!ld_valid_ray(ld, i)) continue;
40 
41  hsm_compute_ht_point(*b, ld->points[i].p[0], ld->points[i].p[1], 1.0);
42 
43  np++;
44  }
45 
46  sm_debug("Computed HT with %d points.\n", np);
47  if(np<5) {
48  hsm_buffer_free(*b);
49  *b = 0;
50  return 0;
51  } else {
52  return 1;
53  }
54 }
55 
56 void sm_hsm(struct sm_params* params, struct sm_result* res) {
57  res->valid = 0;
58 
59  params->first_guess[0]=0.2;
60  params->first_guess[1]=0;
61  params->first_guess[2]=0;
62 
63 
64  /* use true information if present */
65  int has_true1 = !any_nan(params->laser_ref->true_pose, 3);
66  int has_true2 = !any_nan(params->laser_sens->true_pose, 3);
67  if(has_true1 && has_true2) {
68  params->hsm.debug_true_x_valid = 1;
69 
70  double true_x[3];
71  pose_diff_d(params->laser_sens->true_pose, params->laser_ref->true_pose, true_x);
72 
73  /* This is the difference between results and true_x */
74  pose_diff_d(true_x, params->first_guess, params->hsm.debug_true_x);
75 
76  } else {
77  params->hsm.debug_true_x_valid = 0;
78  }
79 
80  double zero[3] = {0,0,0};
81  hsm_buffer b1, b2;
82  int ok1 = hsm_compute_ht_for_scan(params->laser_ref, &(params->hsm), zero, &b1);
83  int ok2 = hsm_compute_ht_for_scan(params->laser_sens,&(params->hsm), params->first_guess, &b2);
84 
85  if(!ok1 || !ok2) {
86  sm_error("Could not compute buffers (too few points?).\n");
87  if(b1) hsm_buffer_free(b1);
88  if(b2) hsm_buffer_free(b2);
89  return;
90  }
91 
94 
95  params->hsm.max_translation = max(b1->rho_max, b2->rho_max);
96 
97  hsm_match(&(params->hsm),b1,b2);
98 
99 
100  if(b1->num_valid_results) {
101  res->valid = 1;
102  double pl[3];
103  double d2[3];
104 
105  pose_diff_d(params->first_guess, b1->results[0], res->x);
106  pose_diff_d(b1->results[0], params->first_guess, d2);
107  oplus_d(params->first_guess, b1->results[0], pl);
108 
109  sm_info("hsm: odo = %s\n", friendly_pose(params->first_guess));
110  sm_info("hsm: res = %s\n", friendly_pose(b1->results[0]));
111  sm_info("hsm: plus = %s\n", friendly_pose(pl));
112  sm_info("hsm: d2 = %s\n", friendly_pose(d2));
113  sm_info("hsm: xmin = %s\n", friendly_pose(res->x));
114  res->error = 0;
115  res->iterations = 0;
116  res->nvalid = 0;
117  } else {
118  sm_error("HSM did not produce any result.\n");
119  res->valid = 0;
120  }
121 
122 
123  hsm_buffer_free(b1);
124  hsm_buffer_free(b2);
125 }
126 
any_nan
int any_nan(const double *d, int n)
Definition: math_utils.c:64
sm_debug
void sm_debug(const char *msg,...)
Definition: logging.c:88
hsm_compute_spectrum
void hsm_compute_spectrum(hsm_buffer b)
Definition: hsm.c:140
p
struct @0 p
max_in_array
double max_in_array(const double *v, int n)
Definition: math_utils.c:273
ld_valid_ray
INLINE int ld_valid_ray(LDP ld, int i)
Definition: laser_data_inline.h:13
sm_result::nvalid
int nvalid
Definition: algos.h:148
laser_data::readings
double *restrict readings
Definition: laser_data.h:24
options.h
sm_params
Definition: algos.h:12
laser_data::nrays
int nrays
Definition: laser_data.h:17
options_double
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
Definition: options_interface.c:62
sm_result::iterations
int iterations
Definition: algos.h:146
max
#define max(a, b)
Definition: bits.h:20
sm_result::error
double error
Definition: algos.h:150
friendly_pose
const char * friendly_pose(const double *pose)
Definition: math_utils.c:266
hsm_buffer_struct::num_valid_results
int num_valid_results
Definition: hsm.h:73
pose_diff_d
void pose_diff_d(const double pose2[3], const double pose1[3], double res[3])
Definition: math_utils.c:115
hsm_buffer_struct::results
double ** results
Definition: hsm.h:76
hsm_match
void hsm_match(struct hsm_params *p, hsm_buffer b1, hsm_buffer b2)
Definition: hsm.c:156
options_int
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
Definition: options_interface.c:39
hsm_buffer_struct
Definition: hsm.h:46
sm_result::valid
int valid
Definition: algos.h:140
hsm_buffer_alloc
hsm_buffer hsm_buffer_alloc(struct hsm_params *p)
Definition: hsm.c:10
ops
struct option * ops
Definition: rb_sm.c:31
hsm_compute_ht_for_scan
int hsm_compute_ht_for_scan(LDP ld, struct hsm_params *p, const double base[3], hsm_buffer *b)
Definition: hsm_interface.c:20
sm_info
void sm_info(const char *msg,...)
Definition: logging.c:71
norm_d
double norm_d(const double p[2])
Definition: math_utils.c:71
option
Definition: options.h:49
hsm_add_options
void hsm_add_options(struct option *ops, struct hsm_params *p)
Definition: hsm_interface.c:6
hsm_buffer_free
void hsm_buffer_free(hsm_buffer b)
Definition: hsm.c:62
sm_result
Definition: algos.h:138
hsm_buffer_struct::rho_max
double rho_max
Definition: hsm.h:59
sm_error
void sm_error(const char *msg,...)
Definition: logging.c:49
ld_compute_cartesian
void ld_compute_cartesian(LDP ld)
Definition: laser_data.c:118
laser_data::points
point2d *restrict points
Definition: laser_data.h:44
oplus_d
void oplus_d(const double x1[3], const double x2[3], double res[3])
Definition: math_utils.c:96
laser_data
Definition: laser_data.h:16
hsm_compute_ht_point
void hsm_compute_ht_point(hsm_buffer b, double x0, double y0, double weight)
Definition: hsm.c:90
sm_result::x
double x[3]
Definition: algos.h:143
point2d::p
double p[2]
Definition: laser_data.h:12
sm_hsm
void sm_hsm(struct sm_params *params, struct sm_result *res)
Definition: hsm_interface.c:56
hsm_params
Definition: hsm.h:7
params
Definition: carmen2pdf.c:20
hsm_compute_ht_base
void hsm_compute_ht_base(hsm_buffer b, const double base_pose[3])
Definition: hsm.c:82


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