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 
double norm_d(const double p[2])
Definition: math_utils.c:71
void hsm_buffer_free(hsm_buffer b)
Definition: hsm.c:62
double true_pose[3]
Definition: laser_data.h:38
point2d *restrict points
Definition: laser_data.h:44
int nvalid
Definition: algos.h:148
double ** results
Definition: hsm.h:76
void hsm_compute_ht_base(hsm_buffer b, const double base_pose[3])
Definition: hsm.c:82
#define max(a, b)
Definition: bits.h:20
int hsm_compute_ht_for_scan(LDP ld, struct hsm_params *p, const double base[3], hsm_buffer *b)
Definition: hsm_interface.c:20
int iterations
Definition: algos.h:146
int num_angular_hypotheses
Definition: hsm.h:16
const char * friendly_pose(const double *pose)
Definition: math_utils.c:266
void hsm_compute_ht_point(hsm_buffer b, double x0, double y0, double weight)
Definition: hsm.c:90
INLINE int ld_valid_ray(LDP ld, int i)
void options_double(struct option *, const char *name, double *p, double def_value, const char *desc)
struct option * ops
Definition: rb_sm.c:31
void hsm_compute_spectrum(hsm_buffer b)
Definition: hsm.c:140
double angular_cell_size_deg
Definition: hsm.h:13
double error
Definition: algos.h:150
hsm_buffer hsm_buffer_alloc(struct hsm_params *p)
Definition: hsm.c:10
int num_valid_results
Definition: hsm.h:73
double rho_max
Definition: hsm.h:59
int valid
Definition: algos.h:140
double debug_true_x[3]
Definition: hsm.h:42
Definition: options.h:49
double linear_xc_peaks_min_distance
Definition: hsm.h:33
void sm_hsm(struct sm_params *params, struct sm_result *res)
Definition: hsm_interface.c:56
double *restrict readings
Definition: laser_data.h:24
int linear_xc_max_npeaks
Definition: hsm.h:30
void hsm_match(struct hsm_params *p, hsm_buffer b1, hsm_buffer b2)
Definition: hsm.c:156
struct @0 p
double max_in_array(const double *v, int n)
Definition: math_utils.c:273
void options_int(struct option *, const char *name, int *p, int def_value, const char *desc)
double xc_directions_min_distance_deg
Definition: hsm.h:26
int debug_true_x_valid
Definition: hsm.h:40
void hsm_add_options(struct option *ops, struct hsm_params *p)
Definition: hsm_interface.c:6
LDP laser_ref
Definition: algos.h:14
double linear_cell_size
Definition: hsm.h:11
LDP laser_sens
Definition: algos.h:16
struct hsm_params hsm
Definition: algos.h:134
Definition: hsm.h:7
double max_norm
Definition: hsm.h:9
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
int xc_ndirections
Definition: hsm.h:23
double max_translation
Definition: hsm.h:37
void sm_debug(const char *msg,...)
Definition: logging.c:88
double x[3]
Definition: algos.h:143
void sm_info(const char *msg,...)
Definition: logging.c:71
int any_nan(const double *d, int n)
Definition: math_utils.c:64
void pose_diff_d(const double pose2[3], const double pose1[3], double res[3])
Definition: math_utils.c:115
void ld_compute_cartesian(LDP ld)
Definition: laser_data.c:118
void sm_error(const char *msg,...)
Definition: logging.c:49
double angular_hyp_min_distance_deg
Definition: hsm.h:19
double p[2]
Definition: laser_data.h:12


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