26 #define M_PI 3.14159265358979323846 30 #define BIG_INITIAL_ERROR 1000000.0F 123 float L,
int laserStep,
126 int ProjectionFilter,
128 int MaxIter,
float error_ratio,
129 float error_x,
float error_y,
float error_t,
int IterSmoothConv){
132 printf(
"-- Init EM params . . ");
163 Tsc *sensorMotion,
Tsc *solution){
172 while (numIteration<params.
MaxIter){
181 resMStep=
MStep(solution);
185 else if (resMStep==-1)
212 static Tscan ptosNewRef;
217 float cp_ass_ptX,cp_ass_ptY,cp_ass_ptD;
220 float q1x, q1y, q2x,q2y,p2x,p2y, dqx, dqy, dqpx, dqpy, qx, qy,dx,dy;
297 cp_associations[cnt].
index=indexPtosNewRef[i];
305 cp_associations[cnt].
L=L;
306 cp_associations[cnt].
R=R;
314 dx=p2x-qx; dy=p2y-qy;
315 dist=dx*dx+dy*dy-(dx*qy-dy*qx)*(dx*qy-dy*qx)/(qx*qx+qy*qy+LMET2);
318 cp_associations[cnt].
nx=ptosNewRef.
laserC[i].
x;
319 cp_associations[cnt].
ny=ptosNewRef.
laserC[i].
y;
320 cp_associations[cnt].
rx=ptosRef.
laserC[R].
x;
321 cp_associations[cnt].
ry=ptosRef.
laserC[R].
y;
322 cp_associations[cnt].
dist=dist;
335 for (J=L+1;J<=R;J++){
343 dqpx=q1x-p2x; dqpy=q1y-p2y;
344 A=1/(p2x*p2x+p2y*p2y+LMET2);
353 else if (landaMin>1){
356 qx=(1-landaMin)*q1x+landaMin*q2x;
357 qy=(1-landaMin)*q1y+landaMin*q2y;
369 tmp_cp_indD=dx*dx+dy*dy-(dx*qy-dy*qx)*(dx*qy-dy*qx)/(qx*qx+qy*qy+LMET2);
372 if (tmp_cp_indD < cp_ass_ptD){
375 cp_ass_ptD=tmp_cp_indD;
380 if (cp_ass_ptD< params.
Br){
381 cp_associations[cnt].
nx=ptosNewRef.
laserC[i].
x;
382 cp_associations[cnt].
ny=ptosNewRef.
laserC[i].
y;
383 cp_associations[cnt].
rx=cp_ass_ptX;
384 cp_associations[cnt].
ry=cp_ass_ptY;
385 cp_associations[cnt].
dist=cp_ass_ptD;
391 cp_associations[cnt].
nx=ptosNewRef.
laserC[i].
x;
392 cp_associations[cnt].
ny=ptosNewRef.
laserC[i].
y;
393 cp_associations[cnt].
rx=0;
394 cp_associations[cnt].
ry=0;
395 cp_associations[cnt].
dist=params.
Br;
405 printf(
"Number of associations too low <%d out of %f>\n",
423 float error_ratio, error;
424 float cosw, sinw, dtx, dty, tmp1, tmp2;
434 cp_tmp[i+1]=cp_associations[i];
440 cnt=((int)(cntAssociationsT*100*params.
filter))/100;
443 cp_associationsTemp[i]=cp_tmp[i+1];
449 if (cp_associations[i].dist<params.
Br){
450 cp_associationsTemp[cnt]=cp_associations[i];
459 printf(
"All assoc: %d Filtered: %d Percentage: %f\n",
472 printf(
"estim_cp: <%f %f %f>\n",estim_cp.
x, estim_cp.
y,estim_cp.
tita);
473 printf(
"New impl: <%f %f %f>\n",estim_cp.
x, estim_cp.
y,estim_cp.
tita);
476 cosw=(float)cos(estim_cp.
tita); sinw=(float)sin(estim_cp.
tita);
477 dtx=estim_cp.
x; dty=estim_cp.
y;
484 for (i = 0; i<cnt;i++){
485 tmp1=cp_associationsTemp[i].
nx * cosw - cp_associationsTemp[i].
ny * sinw + dtx - cp_associationsTemp[i].
rx;tmp1*=tmp1;
486 tmp2=cp_associationsTemp[i].
nx * sinw + cp_associationsTemp[i].
ny * cosw + dty - cp_associationsTemp[i].
ry;tmp2*=tmp2;
487 error = error+ tmp1+tmp2;
493 printf(
"<err,errk1,errRatio>=<%f,%f,%f>\n estim=<%f,%f,%f>\n",
494 error,
error_k1,error_ratio, estim_cp.
x,estim_cp.
y, estim_cp.
tita);
500 if (fabs(1.0-error_ratio)<=params.
error_th ||
538 float A1, A2, A3, B1, B2, B3, C1, C2, C3, D1, D2, D3;
542 A1=0;A2=0;A3=0;B1=0;B2=0;B3=0;
543 C1=0;C2=0;C3=0;D1=0;D2=0;D3=0;
548 for (i=0; i<cnt; i++){
549 X1[i]=cp_ass[i].
nx*cp_ass[i].
nx;
550 Y1[i]=cp_ass[i].
ny*cp_ass[i].
ny;
551 X2[i]=cp_ass[i].
rx*cp_ass[i].
rx;
552 Y2[i]=cp_ass[i].
ry*cp_ass[i].
ry;
553 X2Y2[i]=cp_ass[i].
rx*cp_ass[i].
ry;
555 X1X2[i]=cp_ass[i].
nx*cp_ass[i].
rx;
556 X1Y2[i]=cp_ass[i].
nx*cp_ass[i].
ry;
557 Y1X2[i]=cp_ass[i].
ny*cp_ass[i].
rx;
558 Y1Y2[i]=cp_ass[i].
ny*cp_ass[i].
ry;
560 K[i]=X2[i]+Y2[i] + LMETRICA2;
561 DS[i]=Y1Y2[i] + X1X2[i];
563 X2DsD[i]=cp_ass[i].
rx*DsD[i];
564 Y2DsD[i]=cp_ass[i].
ry*DsD[i];
566 Bs[i]=X1Y2[i]-Y1X2[i];
569 A1=A1 + (1-Y2[i]/K[i]);
570 B1=B1 + X2Y2[i]/K[i];
571 C1=C1 + (-cp_ass[i].
ny + Y2DsD[i]);
572 D1=D1 + (cp_ass[i].
nx - cp_ass[i].
rx -cp_ass[i].
ry*BsD[i]);
575 B2=B2 + (1-X2[i]/K[i]);
576 C2=C2 + (cp_ass[i].
nx-X2DsD[i]);
577 D2=D2 + (cp_ass[i].
ny -cp_ass[i].
ry +cp_ass[i].
rx*BsD[i]);
581 C3=C3 + (X1[i] + Y1[i] - DS[i]*DS[i]/K[i]);
582 D3=D3 + (Bs[i]*(-1+DsD[i]));
602 estimacion->
x=-
VDATA(vecSol,0);
603 estimacion->
y=-
VDATA(vecSol,1);
620 motion2=*initialMotion;
629 ptosNew.
laserC[ptosNew.
numPuntos].
x=(float)(laserK1[i].r * cos(laserK1[i].t));
630 ptosNew.
laserC[ptosNew.
numPuntos].
y=(float)(laserK1[i].r * sin(laserK1[i].t));
649 ptosRef.
laserC[ptosRef.
numPuntos].
x=(float)(laserK[i].r * cos(laserK1[i].t));
650 ptosRef.
laserC[ptosRef.
numPuntos].
y=(float)(laserK[i].r * sin(laserK1[i].t));
int MbICPmatcher(Tpfp *laserK, Tpfp *laserK1, Tsc *sensorMotion, Tsc *solution)
void initialize_matrix(MATRIX *m, int rows, int cols)
void print_matrix(char *message, MATRIX const *m)
void transfor_directa_p(float x, float y, Tsc *sistema, Tpf *sol)
static void preProcessingLib(Tpfp *laserK, Tpfp *laserK1, Tsc *initialMotion)
Tpfp laserP[MAXLASERPOINTS]
void Init_MbICP_ScanMatching(float max_laser_range, float Bw, float Br, float L, int laserStep, float MaxDistInter, float filter, int ProjectionFilter, float AsocError, int MaxIter, float error_ratio, float error_x, float error_y, float error_t, int IterSmoothConv)
TAsoc cp_associations[MAXLASERPOINTS]
void heapsort(TAsoc a[], int n)
void car2pol(Tpf *in, Tpfp *out)
Tpf laserC[MAXLASERPOINTS]
static int computeMatrixLMSOpt(TAsoc *cp_ass, int cnt, Tsc *estimacion)
int inverse_matrix(MATRIX const *m, MATRIX *n)
static float refdqy2[MAXLASERPOINTS]
#define BIG_INITIAL_ERROR
int multiply_matrix_vector(MATRIX const *m, VECTOR const *v, VECTOR *r)
void initialize_vector(VECTOR *v, int elements)
static float refdqxdqy[MAXLASERPOINTS]
static float refdqx2[MAXLASERPOINTS]
void composicion_sis(Tsc *sis1, Tsc *sis2, Tsc *sisOut)
static float distref[MAXLASERPOINTS]
static float refdqy[MAXLASERPOINTS]
TAsoc cp_associationsTemp[MAXLASERPOINTS]
static float refdqx[MAXLASERPOINTS]
static int MStep(Tsc *solucion)