Skip to content

Commit 17768c9

Browse files
committed
1 parent 6fe14f7 commit 17768c9

File tree

3 files changed

+167
-0
lines changed

3 files changed

+167
-0
lines changed

sm/csm/algos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ struct sm_result {
159159

160160

161161
void sm_icp(struct sm_params*input, struct sm_result*output);
162+
void sm_icp_xy(struct sm_params*input, struct sm_result*output);
162163
void sm_gpm(struct sm_params*input, struct sm_result*output);
163164
void sm_hsm(struct sm_params*input, struct sm_result*output);
164165

sm/csm/icp/icp.c

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,167 @@ void sm_icp(struct sm_params*params, struct sm_result*res) {
185185

186186
if(JJ) jj_context_exit();
187187
}
188+
189+
void sm_icp_xy(struct sm_params*params, struct sm_result*res)
190+
{
191+
res->valid = 0;
192+
193+
LDP laser_ref = params->laser_ref;
194+
LDP laser_sens = params->laser_sens;
195+
196+
if(!ld_valid_fields(laser_ref) ||
197+
!ld_valid_fields(laser_sens)) {
198+
return;
199+
}
200+
201+
/*
202+
sm_debug("sm_icp: laser_sens has %d/%d; laser_ref has %d/%d rays valid\n",
203+
count_equal(laser_sens->valid, laser_sens->nrays, 1), laser_sens->nrays,
204+
count_equal(laser_ref->valid, laser_ref->nrays, 1), laser_ref->nrays);
205+
*/
206+
207+
/** Mark as invalid the rays outside of (min_reading, max_reading] */
208+
ld_invalid_if_outside(laser_ref, params->min_reading, params->max_reading);
209+
ld_invalid_if_outside(laser_sens, params->min_reading, params->max_reading);
210+
211+
/*
212+
sm_debug("sm_icp: laser_sens has %d/%d; laser_ref has %d/%d rays valid (after removing outside interval [%f, %f])\n",
213+
count_equal(laser_sens->valid, laser_sens->nrays, 1), laser_sens->nrays,
214+
count_equal(laser_ref->valid, laser_ref->nrays, 1), laser_ref->nrays,
215+
params->min_reading, params->max_reading);
216+
217+
if(JJ) jj_context_enter("sm_icp");
218+
219+
egsl_push_named("sm_icp");
220+
*/
221+
222+
if(params->use_corr_tricks || params->debug_verify_tricks)
223+
ld_create_jump_tables(laser_ref);
224+
/*
225+
ld_compute_cartesian(laser_ref);
226+
ld_compute_cartesian(laser_sens);
227+
*/
228+
229+
if(params->do_alpha_test) {
230+
ld_simple_clustering(laser_ref, params->clustering_threshold);
231+
ld_compute_orientation(laser_ref, params->orientation_neighbourhood, params->sigma);
232+
ld_simple_clustering(laser_sens, params->clustering_threshold);
233+
ld_compute_orientation(laser_sens, params->orientation_neighbourhood, params->sigma);
234+
}
235+
236+
if(JJ) jj_add("laser_ref", ld_to_json(laser_ref));
237+
if(JJ) jj_add("laser_sens", ld_to_json(laser_sens));
238+
239+
gsl_vector * x_new = gsl_vector_alloc(3);
240+
gsl_vector * x_old = vector_from_array(3, params->first_guess);
241+
242+
if(params->do_visibility_test) {
243+
sm_debug("laser_ref:\n");
244+
visibilityTest(laser_ref, x_old);
245+
246+
sm_debug("laser_sens:\n");
247+
gsl_vector * minus_x_old = gsl_vector_alloc(3);
248+
ominus(x_old,minus_x_old);
249+
visibilityTest(laser_sens, minus_x_old);
250+
gsl_vector_free(minus_x_old);
251+
}
252+
253+
double error;
254+
int iterations;
255+
int nvalid;
256+
if(!icp_loop(params, x_old->data, x_new->data, &error, &nvalid, &iterations)) {
257+
sm_error("icp: ICP failed for some reason. \n");
258+
res->valid = 0;
259+
res->iterations = iterations;
260+
res->nvalid = 0;
261+
262+
} else {
263+
/* It was succesfull */
264+
265+
double best_error = error;
266+
gsl_vector * best_x = gsl_vector_alloc(3);
267+
gsl_vector_memcpy(best_x, x_new);
268+
269+
if(params->restart &&
270+
(error/nvalid)>(params->restart_threshold_mean_error) ) {
271+
sm_debug("Restarting: %f > %f \n",(error/nvalid),(params->restart_threshold_mean_error));
272+
double dt = params->restart_dt;
273+
double dth = params->restart_dtheta;
274+
sm_debug("icp_loop: dt = %f dtheta= %f deg\n",dt,rad2deg(dth));
275+
276+
double perturb[6][3] = {
277+
{dt,0,0}, {-dt,0,0},
278+
{0,dt,0}, {0,-dt,0},
279+
{0,0,dth}, {0,0,-dth}
280+
};
281+
282+
int a; for(a=0;a<6;a++){
283+
sm_debug("-- Restarting with perturbation #%d\n", a);
284+
struct sm_params my_params = *params;
285+
gsl_vector * start = gsl_vector_alloc(3);
286+
gvs(start, 0, gvg(x_new,0)+perturb[a][0]);
287+
gvs(start, 1, gvg(x_new,1)+perturb[a][1]);
288+
gvs(start, 2, gvg(x_new,2)+perturb[a][2]);
289+
gsl_vector * x_a = gsl_vector_alloc(3);
290+
double my_error; int my_valid; int my_iterations;
291+
if(!icp_loop(&my_params, start->data, x_a->data, &my_error, &my_valid, &my_iterations)){
292+
sm_error("Error during restart #%d/%d. \n", a, 6);
293+
break;
294+
}
295+
iterations+=my_iterations;
296+
297+
if(my_error < best_error) {
298+
sm_debug("--Perturbation #%d resulted in error %f < %f\n", a,my_error,best_error);
299+
gsl_vector_memcpy(best_x, x_a);
300+
best_error = my_error;
301+
}
302+
gsl_vector_free(x_a); gsl_vector_free(start);
303+
}
304+
}
305+
306+
307+
/* At last, we did it. */
308+
res->valid = 1;
309+
vector_to_array(best_x, res->x);
310+
sm_debug("icp: final x = %s \n", gsl_friendly_pose(best_x));
311+
312+
313+
if(params->do_compute_covariance) {
314+
315+
val cov0_x, dx_dy1, dx_dy2;
316+
compute_covariance_exact(
317+
laser_ref, laser_sens, best_x,
318+
&cov0_x, &dx_dy1, &dx_dy2);
319+
320+
val cov_x = sc(square(params->sigma), cov0_x);
321+
// egsl_v2da(cov_x, res->cov_x);
322+
323+
res->cov_x_m = egsl_v2gslm(cov_x);
324+
res->dx_dy1_m = egsl_v2gslm(dx_dy1);
325+
res->dx_dy2_m = egsl_v2gslm(dx_dy2);
326+
327+
if(0) {
328+
egsl_print("cov0_x", cov0_x);
329+
egsl_print_spectrum("cov0_x", cov0_x);
330+
331+
val fim = ld_fisher0(laser_ref);
332+
val ifim = inv(fim);
333+
egsl_print("fim", fim);
334+
egsl_print_spectrum("ifim", ifim);
335+
}
336+
}
337+
338+
res->error = best_error;
339+
res->iterations = iterations;
340+
res->nvalid = nvalid;
341+
342+
gsl_vector_free(x_new);
343+
gsl_vector_free(x_old);
344+
gsl_vector_free(best_x);
345+
}
346+
/*
347+
egsl_pop_named("sm_icp");
348+
349+
if(JJ) jj_context_exit();
350+
*/
351+
}

sm/csm/icp/icp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
/** This sets the stage. */
99
void sm_icp(struct sm_params*params, struct sm_result*res);
1010

11+
void sm_icp_xy(struct sm_params*params, struct sm_result*res);
12+
1113
/** This is the meat */
1214
int icp_loop(struct sm_params*params, const double*q0, double*x_new,
1315
double*total_error, int*nvalid, int*iterations);

0 commit comments

Comments
 (0)