1 #include <gsl/gsl_histogram.h> 2 #include <gsl/gsl_matrix.h> 5 #include "../csm_all.h" 34 double hist_min = -
M_PI-theta_bin_size;
35 double hist_max = +
M_PI+theta_bin_size;
36 size_t nbins = (size_t) ceil( (hist_max-hist_min) / theta_bin_size);
37 gsl_histogram*hist = gsl_histogram_alloc(nbins);
38 gsl_histogram_set_ranges_uniform(hist, hist_min, hist_max);
46 int num_correspondences_theta=-1;
53 if(num_correspondences_theta < laser_ref->nrays) {
54 sm_error(
"sm_gpm(): I found only %d correspondences in the first pass of GPM. I consider it a failure.\n",
55 num_correspondences_theta);
60 size_t max_bin = gsl_histogram_max_bin(hist);
63 double min_range, max_range;
64 gsl_histogram_get_range(hist,max_bin,&min_range,&max_range);
68 min_range += -extend_range;
69 max_range += +extend_range;
80 u[2] = 0.5 * (max_range + min_range);
81 double new_range_deg =
rad2deg( 0.5*(max_range - min_range) );
84 int num_correspondences=-1;
87 new_range_deg, interval, x_new, &num_correspondences) ;
89 if(num_correspondences < laser_ref->nrays) {
90 sm_error(
"sm_gpm(): I found only %d correspondences in the second pass of GPM. I consider it a failure.\n",
99 sm_debug(
"gpm : acceptable range for theta: [%f, %f]\n", min_range,max_range);
100 sm_debug(
"gpm : 1) Num correspondences for theta: %d\n", num_correspondences_theta);
117 gsl_histogram_free(hist);
121 const double*x0,
double max_linear_correction,
122 double max_angular_correction_deg,
int interval, gsl_histogram*hist,
int*num_correspondences)
129 for(i=0;i<laser_sens->
nrays;i++) {
131 if(i % interval)
continue;
133 const double * p_i = laser_sens->
points[i].
p;
135 const double * p_i_w = laser_sens->
points_w[i].
p;
136 int from;
int to;
int start_cell;
138 max_linear_correction, &from, &to, &start_cell);
142 for(j=from;j<=to;j++) {
144 if(j % interval)
continue;
147 double theta_diff =
angleDiff(theta,x0[2]);
148 if( fabs(theta_diff) >
deg2rad(max_angular_correction_deg) )
150 theta = x0[2] + theta_diff;
152 const double * p_j = laser_ref->
points[j].
p;
154 double c = cos(theta);
double s = sin(theta);
155 double t_x = p_j[0] - (c*p_i[0]-s*p_i[1]);
156 double t_y = p_j[1] - (s*p_i[0]+c*p_i[1]);
157 double t_dist = sqrt(
square(t_x-x0[0]) +
square(t_y-x0[1]) );
159 if(t_dist > max_linear_correction)
164 gsl_histogram_accumulate(hist, theta, weight);
165 gsl_histogram_accumulate(hist, theta+2*
M_PI, weight);
166 gsl_histogram_accumulate(hist, theta-2*
M_PI, weight);
170 *num_correspondences = count;
171 sm_debug(
" correspondences = %d\n",count);
175 const double*x0,
double max_linear_correction,
176 double max_angular_correction_deg,
int interval,
double*x,
int*num_correspondences)
181 double L[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
182 double z[3] = {0,0,0};
186 for(i=0;i<laser_sens->
nrays;i++) {
188 if(i % interval)
continue;
191 const double * p_i = laser_sens->
points_w[i].
p;
193 const double * p_i_w = laser_sens->
points_w[i].
p;
194 int from;
int to;
int start_cell;
196 max_linear_correction, &from, &to, &start_cell);
201 for(j=from;j<=to;j++) {
202 if(j % interval)
continue;
206 double theta_diff =
angleDiff(theta,x0[2]);
207 if( fabs(theta_diff) >
deg2rad(max_angular_correction_deg) )
209 theta = x0[2] + theta_diff;
211 const double * p_j = laser_ref->
points[j].
p;
213 double c = cos(theta);
double s = sin(theta);
214 double t_x = p_j[0] - (c*p_i[0]-s*p_i[1]);
215 double t_y = p_j[1] - (s*p_i[0]+c*p_i[1]);
216 double t_dist = sqrt(
square(t_x-x0[0]) +
square(t_y-x0[1]) );
218 if(t_dist > max_linear_correction)
226 double alpha = laser_ref->
alpha[j];
227 double ca = cos(alpha);
double sa=sin(alpha);
234 z[0] += weight*(ca*ca*t_x + sa*ca*t_y);
235 z[1] += weight*(sa*ca*t_x + sa*sa*t_y);
236 z[2] += weight*theta;
237 L[0][0] += weight* ca * ca;
238 L[0][1] += weight* sa * ca;
239 L[1][0] += weight* sa * ca;
240 L[1][1] += weight* sa * sa;
247 *num_correspondences = count;
251 double weight = 0.5 * count;
252 z[0] += x0[0] * weight;
253 z[1] += x0[1] * weight;
283 sm_debug(
"gpm: second step: found %d correspondences\n",count);
void sm_gpm(struct sm_params *params, struct sm_result *res)
void copy_d(const double *from, int n, double *to)
double angleDiff(double a, double b)
double max_angular_correction_deg
const char * friendly_pose(const double *pose)
int orientation_neighbourhood
void ld_compute_orientation(LDP ld, int size_neighbourhood, double sigma)
double clustering_threshold
int ld_valid_fields(LDP ld)
double max_linear_correction
void ght_find_theta_range(LDP laser_ref, LDP laser_sens, const double *x0, double max_linear_correction, double max_angular_correction_deg, int interval, gsl_histogram *hist, int *num_correspondences)
void possible_interval(const double *p_i_w, LDP laser_sens, double max_angular_correction_deg, double max_linear_correction, int *from, int *to, int *start_cell)
val egsl_alloc(size_t rows, size_t columns)
void ght_one_shot(LDP laser_ref, LDP laser_sens, const double *x0, double max_linear_correction, double max_angular_correction_deg, int interval, double *x, int *num_correspondences)
int *restrict alpha_valid
point2d *restrict points_w
val egsl_vFa(size_t rows, const double *)
void ld_simple_clustering(LDP ld, double threshold)
void ld_compute_world_coords(LDP ld, const double *pose)
double * egsl_atmp(val v, size_t i, size_t j)
double gpm_theta_bin_size_deg
void sm_debug(const char *msg,...)
double gpm_extend_range_deg
void ld_compute_cartesian(LDP ld)
void sm_error(const char *msg,...)
double rad2deg(double rad)
void egsl_v2a(val, double *)