00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <IKOR/general.h>
00018 #include <stdio.h>
00019 #include <math.h>
00020
00021 void simp1(a,mm,ll,nll,iabf,kp,bmax)
00022 float **a,*bmax;
00023 int *kp,iabf,ll[],mm,nll;
00024 {
00025 int k;
00026 float test;
00027
00028 *kp=ll[1];
00029 *bmax=a[mm+1][*kp+1];
00030 for (k=2;k<=nll;k++) {
00031 if (iabf == 0)
00032 test=a[mm+1][ll[k]+1]-(*bmax);
00033 else
00034 test=fabs(a[mm+1][ll[k]+1])-fabs(*bmax);
00035 if (test > 0.0) {
00036 *bmax=a[mm+1][ll[k]+1];
00037 *kp=ll[k];
00038 }
00039 }
00040 }
00041
00042
00043 #define EPS 1.0e-6
00044 void simp2(a,n,l2,nl2,ip,kp,q1)
00045 float **a,*q1;
00046 int *ip,kp,l2[],n,nl2;
00047 {
00048 int k,ii,i;
00049 float qp,q0,q;
00050
00051 *ip=0;
00052 for (i=1;i<=nl2;i++) {
00053 if (a[l2[i]+1][kp+1] < -EPS) {
00054 *q1 = -a[l2[i]+1][1]/a[l2[i]+1][kp+1];
00055 *ip=l2[i];
00056 for (i=i+1;i<=nl2;i++) {
00057 ii=l2[i];
00058 if (a[ii+1][kp+1] < -EPS) {
00059 q = -a[ii+1][1]/a[ii+1][kp+1];
00060 if (q < *q1) {
00061 *ip=ii;
00062 *q1=q;
00063 } else if (q == *q1) {
00064 for (k=1;k<=n;k++) {
00065 qp = -a[*ip+1][k+1]/a[*ip+1][kp+1];
00066 q0 = -a[ii+1][k+1]/a[ii+1][kp+1];
00067 if (q0 != qp) break;
00068 }
00069 if (q0 < qp) *ip=ii;
00070 }
00071 }
00072 }
00073 }
00074 }
00075 }
00076
00077
00078 void simp3(a,i1,k1,ip,kp)
00079 float **a;
00080 int i1,ip,k1,kp;
00081 {
00082 int kk,ii;
00083 float piv;
00084
00085 piv=1.0/a[ip+1][kp+1];
00086 for (ii=1;ii<=i1+1;ii++)
00087 if (ii-1 != ip) {
00088 a[ii][kp+1] *= piv;
00089 for (kk=1;kk<=k1+1;kk++)
00090 if (kk-1 != kp)
00091 a[ii][kk] -= a[ip+1][kk]*a[ii][kp+1];
00092 }
00093 for (kk=1;kk<=k1+1;kk++)
00094 if (kk-1 != kp) a[ip+1][kk] *= -piv;
00095 a[ip+1][kp+1]=piv;
00096 }
00097
00098
00099 #define FREEALL free_ivector(l3,1,m);free_ivector(l2,1,m);\
00100 free_ivector(l1,1,n+1);
00101
00102 void simplx(a,m,n,m1,m2,m3,icase,izrov,iposv)
00103 float **a;
00104 int *icase,iposv[],izrov[],m,m1,m2,m3,n;
00105 {
00106 void simp1(),simp2(),simp3();
00107 int i,ip,ir,is,k,kh,kp,m12,nl1,nl2;
00108 int *l1,*l2,*l3;
00109 float q1,bmax;
00110
00111 if (m != (m1+m2+m3)) nrerror("Bad input constraint counts in simplx");
00112 l1=ivector(1,n+1);
00113 l2=ivector(1,m);
00114 l3=ivector(1,m);
00115 nl1=n;
00116 for (k=1;k<=n;k++) l1[k]=izrov[k]=k;
00117 nl2=m;
00118 for (i=1;i<=m;i++) {
00119 if (a[i+1][1] < 0.0) nrerror("Bad input tableau in simplx");
00120 l2[i]=i;
00121 iposv[i]=n+i;
00122 }
00123 for (i=1;i<=m2;i++) l3[i]=1;
00124 ir=0;
00125 if (m2+m3) {
00126 ir=1;
00127 for (k=1;k<=(n+1);k++) {
00128 q1=0.0;
00129 for (i=m1+1;i<=m;i++) q1 += a[i+1][k];
00130 a[m+2][k] = -q1;
00131 }
00132 do {
00133 simp1(a,m+1,l1,nl1,0,&kp,&bmax);
00134 if (bmax <= EPS && a[m+2][1] < -EPS) {
00135 *icase = -1;
00136 FREEALL return;
00137 } else if (bmax <= EPS && a[m+2][1] <= EPS) {
00138 m12=m1+m2+1;
00139 if (m12 <= m) {
00140 for (ip=m12;ip<=m;ip++) {
00141 if (iposv[ip] == (ip+n)) {
00142 simp1(a,ip,l1,
00143 nl1,1,&kp,&bmax);
00144 if (bmax > 0.0)
00145 goto one;
00146 }
00147 }
00148 }
00149 ir=0;
00150 --m12;
00151 if (m1+1 <= m12)
00152 for (i=m1+1;i<=m12;i++)
00153 if (l3[i-m1] == 1)
00154 for (k=1;k<=n+1;k++)
00155 a[i+1][k] = -a[i+1][k];
00156 break;
00157 }
00158 simp2(a,n,l2,nl2,&ip,kp,&q1);
00159 if (ip == 0) {
00160 *icase = -1;
00161 FREEALL return;
00162 }
00163 one: simp3(a,m+1,n,ip,kp);
00164 if (iposv[ip] >= (n+m1+m2+1)) {
00165 for (k=1;k<=nl1;k++)
00166 if (l1[k] == kp) break;
00167 --nl1;
00168 for (is=k;is<=nl1;is++) l1[is]=l1[is+1];
00169 ++a[m+2][kp+1];
00170 for (i=1;i<=m+2;i++) a[i][kp+1] = -a[i][kp+1];
00171 } else {
00172 if (iposv[ip] >= (n+m1+1)) {
00173 kh=iposv[ip]-m1-n;
00174 if (l3[kh]) {
00175 l3[kh]=0;
00176 ++a[m+2][kp+1];
00177 for (i=1;i<=m+2;i++)
00178 a[i][kp+1] = -a[i][kp+1];
00179 }
00180 }
00181 }
00182 is=izrov[kp];
00183 izrov[kp]=iposv[ip];
00184 iposv[ip]=is;
00185 } while (ir);
00186 }
00187 for (;;) {
00188 simp1(a,0,l1,nl1,0,&kp,&bmax);
00189 if (bmax <= 0.0) {
00190 *icase=0;
00191 FREEALL return;
00192 }
00193 simp2(a,n,l2,nl2,&ip,kp,&q1);
00194 if (ip == 0) {
00195 *icase=1;
00196 FREEALL return;
00197 }
00198 simp3(a,m,n,ip,kp);
00199 is=izrov[kp];
00200 izrov[kp]=iposv[ip];
00201 iposv[ip]=is;
00202 }
00203 }
00204 #undef FREEALL
00205
00206
00207
00208 #define NM1M2 (sN+sM1+sM2)
00209
00210 mysimplx( c, sM, sN, sM1, sM2, sM3, NP, MP )
00211 float **c;
00212 int sM, sN, sM1, sM2, sM3;
00213 {
00214 int i,icase,j,*izrov,*iposv;
00215 float **a;
00216 static char *txt[9]=
00217 {" ","x1","x2","x3","x4","y1","y2","y3"};
00218
00219
00220 printf("\n\n N: %d, M: %d, M1: %d, M2: %d, M3: %d, NP: %d, MP: %d",
00221 sN, sM, sM1, sM2, sM3, NP, MP);
00222 for (i = 0; i<MP; i++) { printf( "\nA[%d] = ", i );
00223 for (j=0; j<NP; j++) printf( " %9.6f ", c[i][j] ); }
00224 printf("\n");
00225
00226
00227 izrov=ivector(1,sN);
00228 iposv=ivector(1,sM);
00229 a=convert_matrix(&c[0][0],1,MP,1,NP);
00230 simplx(a,sM,sN,sM1,sM2,sM3,&icase,izrov,iposv);
00231 if (icase == 1)
00232 printf("\nunbounded objective function\n");
00233 else if (icase == -1)
00234 printf("\nno solutions satisfy constraints given\n");
00235 else {
00236 printf("\n%11s"," ");
00237 for (i=1;i<=sN;i++)
00238 if (izrov[i] <= NM1M2) printf("%10s",txt[izrov[i]]);
00239 printf("\n");
00240 for (i=1;i<=M+1;i++) {
00241 if (i == 1 || iposv[i-1] <= NM1M2) {
00242 if (i > 1)
00243 printf("%s",txt[iposv[i-1]]);
00244 else
00245 printf(" ");
00246 printf("%10.2f",a[i][1]);
00247 for (j=2;j<=N+1;j++)
00248 if (izrov[j-1] <= NM1M2)
00249 printf("%10.2f",a[i][j]);
00250 printf("\n");
00251 }
00252 }
00253 }
00254 free_convert_matrix(a,1,MP,1,NP);
00255 free_ivector(iposv,1,sM);
00256 free_ivector(izrov,1,sN);
00257
00258 exit (1);
00259 return 0;
00260 }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275 MATRIX *findt_without_Betas_SIMPLX(FSP_data, B, H, datafp)
00276 FILE *datafp;
00277 MATRIX *B,
00278 *H;
00279 Solutions *FSP_data;
00280 {
00281 int t_ind,
00282 col_ind,
00283 sN, sM, i, j;
00284 float **coeff;
00285 MATRIX *dq;
00286
00287 if (DEBUG) {
00288 fprintf(datafp, "\n Executing SIMPLX Optimization \n");
00289 fprintf(datafp, "\n SPAN = %d Bcols = %d gcols = %d\n",
00290 SPAN, B->cols, FSP_data->g->cols);
00291 fmat_pr(datafp, " Solution Vectors ", FSP_data->g);
00292 }
00293
00294 dq = mat_malloc( FSP_data->M, 1 );
00295 coeff= (float **) malloc ( 3 * sizeof( float * ) );
00296
00297 for (t_ind=0;t_ind<3;t_ind++)
00298 coeff[t_ind]= (float *) malloc ( (SPAN + 1) * sizeof( float ) );
00299 coeff[0][0] = coeff[2][0] = 0.0; coeff[1][0] = 1.0;
00300
00301
00302 if ((STEP == ONE) && (!FSP_data->Null_Space))
00303 {
00304 for (t_ind = 1; t_ind < SPAN+1; t_ind++)
00305 {
00306 coeff[0][t_ind] = coeff[2][t_ind] = 0.0; coeff[1][t_ind] = -1.0;
00307 for (col_ind=0; col_ind<B->cols; col_ind++) coeff[0][t_ind] +=
00308 B->p[col_ind][col_ind] * FSP_data->g->p[t_ind-1][col_ind];
00309 }
00310
00311 if (DEBUG) ;
00312
00313 sN = SPAN;
00314 sM = 1;
00315 printf("\n N: %d, M: %d, M1: %d, M2: %d, M3: %d, NP: %d, MP: %d",
00316 sN, sM, 0, 0, 1, sN+1, sM+2);
00317 for (i = 0; i<3; i++) { printf( "\nA[%d] = ", i );
00318 for (j=0; j<SPAN+1; j++) printf( " %9.6f ", coeff[i][j] ); }
00319 printf("\n");
00320
00321
00322 mysimplx( coeff, sM, sN, 0, 0, 1, sN+1, sM+2 );
00323
00324 }
00325 else if ((STEP == TWO) || (FSP_data->Null_Space)) {
00326 IKerror(31, OK, " SIMPLX has no Null_Space Motions ");
00327 for (col_ind=0; col_ind<B->cols; col_ind++)
00328 dq->p[col_ind][0] = ZERO;
00329 }
00330 else IKerror(29,FATAL,"findt_without_Betas_SIMPLX");
00331
00332
00333 return (dq);
00334 }
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 MATRIX *Build_Grammian2 (FSP_data, B, datafp)
00365 FILE *datafp;
00366 MATRIX *B;
00367 Solutions *FSP_data;
00368 {
00369 int i,j,k;
00370 MATRIX *Grammian,
00371 *gtemp,
00372 *Btemp,
00373 *gBtrans;
00374
00375 Grammian = mat_malloc(SPAN, SPAN);
00376 Btemp = mat_malloc(FSP_data->g->cols, FSP_data->g->cols);
00377
00378
00379 if (B->rows == Btemp->rows)
00380 mat_cp(B, Btemp);
00381 else
00382 for (i=0; i<Btemp->rows; i++)
00383 for (j=0; j<Btemp->rows; j++)
00384 Btemp->p[i][j] = B->p[i][j];
00385 gtemp = mat_mul2(FSP_data->g, Robot->Weights);
00386 gBtrans = mat_mul2(gtemp, Btemp);
00387
00388
00389 for (i = 0; i < gBtrans->rows; i++)
00390 for (j = 0; j < gBtrans->rows; j++)
00391 {
00392 Grammian-> p[i][j] = 0;
00393 for (k = 0; k < gBtrans->cols; k++)
00394 {
00395 Grammian -> p[i][j] += gBtrans -> p[i][k] * gBtrans -> p[j][k];
00396 }
00397 }
00398
00399 if (DEBUG) {
00400 fprintf(datafp,"\n ______________________________ \n");
00401 fprintf(datafp,"\n Building Grammian \n");
00402 fprintf(datafp, " ______________________________ \n\n");
00403 fmat_pr(datafp,"g",FSP_data->g);
00404 fmat_pr(datafp,"Angle Weights", Robot->Weights);
00405 fmat_pr(datafp,"B Vector", B);
00406 fmat_pr(datafp,"g*Weights*B",gtemp);
00407 fmat_pr(datafp,"Grammian",Grammian);
00408 }
00409
00410 mat_free(gtemp);
00411 mat_free(gBtrans);
00412 mat_free(Btemp);
00413
00414 return (Grammian);
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 void find_jl_beta(FSP_data, chk, distance, datafp)
00439 FILE *datafp;
00440 int chk;
00441 double distance;
00442 Solutions *FSP_data;
00443 {
00444 int i;
00445
00446 if (chk > (FSP_data->g->cols -1));
00447 else
00448 for( i=0; i < FSP_data->g->rows; i++ )
00449 FSP_data->betall->p[i][FSP_data->cn] =
00450 FSP_data->g->p[i][chk]/(distance);
00451
00452 FSP_data->cn++;
00453 }
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 void find_obs_beta(FSP_data, chk, newl, delta, normal, datafp)
00478 FILE *datafp;
00479 int chk;
00480 double *newl,
00481 delta,
00482 normal[3];
00483 Solutions *FSP_data;
00484 {
00485 int i, j, p, k;
00486 MATRIX *alpha,
00487 *Jacob;
00488
00489 alpha = mat_malloc( 3, SPAN );
00490 Jacob = mat_malloc( N, M );
00491
00492
00493
00494
00495
00496
00497 for (i=0; i<Robot->NL; i++) LL[i] = Robot->LINKS[i];
00498
00499 LL[chk] = *newl;
00500 for (i=chk+1; i<Robot->NL; i++ ) LL[i] = 0.0;
00501
00502 GET_JACOBIAN_ALTERED(Jacob, FSP_data->Qarray);
00503
00504
00505
00506
00507
00508 for (i = 0;i<3;i++) for (p = 0;p<SPAN;p++) alpha -> p[i][p] = 0.0;
00509
00510
00511 for (i = 0; i < 3; i++)
00512 for (j = 0; j < SPAN; j++)
00513 for (k = 0; k < M; k++)
00514 alpha->p[i][j] += Jacob->p[i][k] * FSP_data->g->p[j][k];
00515
00516 if (DEBUG) {
00517 fmat_pr(datafp,"*** Jacobian @ Xj ***", Jacob);
00518 fmat_pr(datafp,"*** Alpha ***", alpha);
00519 }
00520
00521
00522 for (i = 0; i < SPAN; i++)
00523 {
00524 FSP_data->betall->p[i][FSP_data->cn] = 0;
00525 for (j = 0; j < 3; j++)
00526 FSP_data->betall->p[i][FSP_data->cn] +=
00527 alpha->p[j][i] * normal[j];
00528 FSP_data->betall->p[i][FSP_data->cn] /= fabs(delta);
00529 if (DEBUG) fprintf(datafp,"b[%d]: %f ", i,
00530 FSP_data->betall->p[i][FSP_data->cn]);
00531 }
00532 FSP_data->cn++;
00533
00534 mat_free(alpha);
00535 mat_free(Jacob);
00536 }
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550 MATRIX *findt_without_Betas_BANGBANG(FSP_data, B, H, old, datafp)
00551 FILE *datafp;
00552 MATRIX *B,
00553 *H,
00554 *old;
00555 Solutions *FSP_data;
00556 {
00557 int t_ind,
00558 col_ind,
00559 least_ind = -1,
00560 MISMATCH = FALSE;
00561 float least_flow,
00562 total_flow;
00563 MATRIX *dq, *dq1;
00564
00565 if (DEBUG) {
00566 fprintf(datafp, "\n Executing BIGBANG Optimization \n");
00567 fprintf(datafp, "\n SPAN = %d Bcols = %d gcols = %d\n",
00568 SPAN, B->cols, FSP_data->g->cols);
00569 fmat_pr(datafp, " Solution Vectors ", FSP_data->g);
00570 }
00571
00572 dq = mat_malloc( FSP_data->M, 1 );
00573
00574
00575 if ((STEP == ONE) && (!FSP_data->Null_Space))
00576 {
00577 for (t_ind = 0; t_ind < SPAN; t_ind++)
00578 {
00579 total_flow=0.0;
00580 for (col_ind=0; col_ind<B->cols; col_ind++)
00581 total_flow += (old->p[col_ind][0]>0)?1.0:-1.0 *
00582 ( B->p[col_ind][col_ind] * FSP_data->g->p[t_ind][col_ind] );
00583
00584 if (DEBUG);{ fprintf(stderr, " %9.6f ", total_flow ); }
00585
00586 if ((total_flow < least_flow) || (least_ind<0))
00587 { least_ind = t_ind; least_flow = total_flow; }
00588 }
00589
00590 for (col_ind=0; col_ind<B->cols; col_ind++) {
00591 dq->p[col_ind][0] = FSP_data->g->p[least_ind][col_ind];
00592 if ((dq->p[col_ind][0]>=0)&&(old->p[col_ind][0]>=0));
00593 else if ((dq->p[col_ind][0]<=0)&&(old->p[col_ind][0]<=0));
00594 else {
00595 MISMATCH = TRUE;
00596 fprintf(stderr, "MISMATCH: dq[%d] = %9.6f, old[%d] = %9.6f \n",
00597 col_ind, dq->p[col_ind][0], col_ind, old->p[col_ind][0]);
00598 break;
00599 }
00600 }
00601
00602 if (MISMATCH) {
00603 dq1 = findt_without_Betas_BANGBANG(FSP_data, B, H, dq, datafp);
00604 for (col_ind=0; col_ind<B->cols; col_ind++)
00605 dq->p[col_ind][0] = dq1->p[col_ind][0];
00606 mat_free(dq1);
00607 MISMATCH = FALSE;
00608 }
00609 else fprintf(stderr, "OK");
00610
00611
00612 if (DEBUG) {
00613 fprintf(datafp, "\nLeast Flow: %f, Least Index: %d \n\n\n",
00614 least_flow, least_ind );
00615 }
00616 }
00617 else if ((STEP == TWO) || (FSP_data->Null_Space)) {
00618 IKerror(31, OK, " BANGBANG has no Null_Space Motions ");
00619 for (col_ind=0; col_ind<B->cols; col_ind++)
00620 dq->p[col_ind][0] = ZERO;
00621 }
00622 else IKerror(29,FATAL,"findt_without_Betas_BANGBANG");
00623
00624 fprintf(stderr,"\n");
00625
00626 return (dq);
00627 }
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653 MATRIX *findt_with_Betas_Holonomic(FSP_data, B, H, datafp)
00654 FILE *datafp;
00655 MATRIX *B,
00656 *H;
00657 Solutions *FSP_data;
00658 {
00659 int i, j, k, a, b;
00660 double sum1 = 0, sum2 = 0,
00661 afinal;
00662 MATRIX *bfinal,
00663 *cfinal,
00664 *dfinal,
00665 *A, *Ainv,
00666 *nu, *mu,
00667 *e, *eT,
00668 *t, *temp, *temp2, *temp3,
00669 *G, *Ginv, *iden,
00670 *dq;
00671 float ctemp;
00672
00673 dq = mat_malloc(M , 1);
00674 e = mat_malloc(SPAN, 1);
00675 eT = mat_malloc( 1, SPAN);
00676
00677 if (DEBUG) fprintf(datafp, "\n\n# of constraints %d \n", FSP_data->cn);
00678
00679
00680 for (i = 0; i < SPAN; i++)
00681 { e -> p[i][0] = eT -> p[0][i] = 1.0e0;}
00682
00683
00684 G = Build_Grammian2(FSP_data, B, datafp);
00685
00686 Ginv = mat_cp2(G);
00687 mat_LU_inv(Ginv);
00688 iden = mat_mul2(Ginv, G);
00689
00690 if (DEBUG) {
00691 fmat_pr(datafp,"*** Identity Matrix Check (G * Ginv) ***", iden);
00692 fmat_pr(datafp,"*** betas ***", FSP_data->betall);
00693 }
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704 afinal = 0;
00705 for (i = 0; i < SPAN; i++)
00706 for (j = 0; j < SPAN; j++)
00707 afinal += Ginv -> p[i][j];
00708
00709
00710
00711 temp = mat_malloc (SPAN,1);
00712 bfinal = mat_malloc (1, FSP_data->cn);
00713 for (k = 0; k < FSP_data->cn; k++)
00714 {
00715 for (i = 0; i < SPAN; i++)
00716 {
00717 temp->p[i][0] = 0.0;
00718 for (j = 0; j < SPAN; j++)
00719 temp->p[i][0] += Ginv->p[i][j] * FSP_data->betall->p[j][k];
00720 }
00721 bfinal->p[0][k] = 0.0;
00722 for (i = 0; i < SPAN; i++)
00723 bfinal->p[0][k] += temp->p[i][0];
00724 }
00725 mat_free(temp);
00726
00727
00728
00729 temp = mat_malloc (SPAN, 1);
00730 cfinal = mat_malloc (FSP_data->cn , 1);
00731 for (a = 0; a < FSP_data->cn; a++)
00732 {
00733 for (i = 0; i < SPAN; i++)
00734 {
00735 temp->p[i][0] = 0.0;
00736 for (j = 0; j < SPAN; j++)
00737 temp->p[i][0] += Ginv->p[i][j];
00738 }
00739 cfinal ->p[a][0] = 0.0;
00740 for (j = 0; j < SPAN; j++)
00741 cfinal->p[a][0] += FSP_data->betall->p[j][a] * temp->p[j][0];
00742 }
00743 mat_free(temp);
00744
00745
00746 temp = mat_malloc(SPAN, 1);
00747 dfinal = mat_malloc(FSP_data->cn,FSP_data->cn);
00748 for (k = 0; k < FSP_data->cn; k++)
00749 for (b = 0; b < FSP_data->cn; b++)
00750 {
00751 dfinal->p[k][b] = 0.0;
00752 for (i = 0; i < SPAN; i++)
00753 {
00754 temp->p[i][0] = 0.0;
00755 for (j = 0; j < SPAN; j++)
00756 temp->p[i][0] += Ginv->p[i][j] * FSP_data->betall->p[j][k];
00757 }
00758 for (j = 0; j < SPAN; j++)
00759 dfinal->p[k][b] += FSP_data->betall->p[j][b] * temp->p[j][0];
00760 }
00761 mat_free(temp);
00762
00763
00764
00765 temp = mat_malloc(FSP_data->cn,FSP_data->cn);
00766 for(a=0;a<FSP_data->cn;a++)
00767 for(b=0;b<FSP_data->cn;b++)
00768 temp ->p[a][b]=dfinal->p[a][b]*afinal;
00769
00770 temp2= mat_malloc(FSP_data->cn,FSP_data->cn);
00771 for (i = 0; i < FSP_data->cn; i++)
00772 for (j = 0; j < FSP_data->cn; j++)
00773 temp2->p[i][j]=cfinal->p[i][0]*bfinal->p[0][j];
00774
00775 A = mat_malloc(FSP_data->cn, FSP_data->cn);
00776 Ainv = mat_malloc(FSP_data->cn, FSP_data->cn);
00777
00778 for (i = 0; i < FSP_data->cn; i++)
00779 for (j = 0; j < FSP_data->cn; j++)
00780 A ->p[i][j]=temp2->p[i][j]-temp->p[i][j];
00781
00782 mat_free(temp);
00783 mat_free(temp2);
00784 mat_cp(A, Ainv);
00785
00786 if (DEBUG) {
00787 fprintf(datafp, " a= %9.9f\n", afinal);
00788 fmat_prf(datafp, "b= ", bfinal);
00789 fmat_prf(datafp, "c= ", cfinal);
00790 fmat_prf(datafp, "d= ", dfinal);
00791 fmat_prf(datafp, "A = ", A);
00792 }
00793 if ((A->p[0][0]==0.0)&&(A->rows=1)&&(A->cols=1))
00794 IKerror(30,FATAL,"");
00795 else mat_LU_inv(Ainv);
00796
00797
00798
00799
00800
00801
00802
00803 if ((STEP == ONE)
00804 && (!FSP_data->Null_Space))
00805 {
00806
00807 temp = mat_malloc (FSP_data->cn, 1);
00808 for(i=0;i<FSP_data->cn;i++)
00809 temp->p[i][0]=afinal - cfinal->p[i][0];
00810 nu=mat_mul2(Ainv,temp);
00811 mat_free(temp);
00812
00813
00814 mu = mat_mul2(bfinal, nu);
00815 mu->p[0][0] = -1 * (mu->p[0][0] + 1 )/ afinal;
00816 }
00817 else if ((STEP == TWO) || (FSP_data->Null_Space))
00818 {
00819
00820 temp = mat_malloc (FSP_data->cn, 1);
00821 for(i=0;i<FSP_data->cn;i++)
00822 temp->p[i][0]=afinal;
00823 nu=mat_mul2(Ainv,temp);
00824 mat_free(temp);
00825
00826
00827 mu = mat_mul2(bfinal, nu);
00828 mu->p[0][0] /= -afinal;
00829 }
00830 else IKerror(29,FATAL,"findt_with_Betas_Holonomic");
00831
00832
00833
00834
00835
00836
00837 temp2 = mat_malloc(SPAN, 1);
00838 for(i=0;i<SPAN;i++)
00839 {
00840 temp2->p[i][0] = 0.0;
00841 for(j=0;j<SPAN;j++)
00842 temp2->p[i][0]+=Ginv->p[i][j];
00843 }
00844
00845 temp3 = mat_malloc(SPAN, 1);
00846 for(i=0;i<SPAN;i++)
00847 temp3->p[i][0]= -(mu->p[0][0])*temp2->p[i][0];
00848 mat_free(temp2);
00849
00850 temp = mat_malloc (SPAN, 1);
00851 for(i=0;i<SPAN;i++)
00852 {
00853 temp->p[i][0] = 0.0;
00854 for(a=0;a<FSP_data->cn;a++)
00855 temp->p[i][0]+=FSP_data->betall->p[i][a]*nu->p[a][0];
00856 }
00857
00858 temp2= mat_malloc (SPAN, 1);
00859 for(i=0;i<SPAN;i++)
00860 {
00861 temp2->p[i][0] = 0.0;
00862 for(j=0;j<SPAN;j++)
00863 temp2->p[i][0]+=Ginv->p[i][j]*temp->p[j][0];
00864 }
00865
00866 t = mat_malloc (SPAN, 1);
00867 for(i=0;i<SPAN;i++)
00868 t->p[i][0] = temp3->p[i][0] - temp2->p[i][0];
00869
00870
00871 mat_free(temp );
00872 mat_free(temp2);
00873 mat_free(temp3);
00874
00875 sum1 = 0;
00876 for (i = 0; i < SPAN; i++)
00877 sum1 += t -> p[i][0];
00878 if (!FSP_data->Null_Space) {
00879 if ((sum1< .99)||(sum1>1.01)) IKerror (21, FATAL,
00880 "findt_with_Betas_Holonomic");
00881 }
00882 else if ((sum1<-.01)||(sum1> .01)) IKerror (21, FATAL,
00883 "findt_with_Betas_Holonomic");
00884
00885
00886 if (DEBUG) {
00887 fmat_prf(datafp, "Nu =", nu);
00888 fprintf(datafp, " Mu = %9.9f \n", mu->p[0][0]);
00889 fmat_prf(datafp, "Ginv * -mu", temp3);
00890 fmat_prf(datafp, "Ginv * B * nu", temp2);
00891 fmat_prf(datafp, "*** t's for Collision ***", t);
00892
00893 sum1 = 0;
00894 for (i = 0; i < SPAN; i++)
00895 sum1 += t -> p[i][0];
00896 fprintf(datafp, "\nsum ti: %7.4f\n", sum1);
00897
00898 for (j=0; j<FSP_data->cn; j++)
00899 {
00900 sum1 = 0;
00901 for (i = 0; i < SPAN; i++)
00902 sum1 += FSP_data->betall -> p[i][j] * t -> p[i][0];
00903 fprintf(datafp, "\nsum betai*ti: %7.4f \n", sum1);
00904 }
00905 }
00906
00907 for (i = 0; i < FSP_data->M; i++)
00908 {
00909 dq->p[i][0]=0.0;
00910 for (j = 0; j < SPAN; j++)
00911 dq->p[i][0] += (t -> p[j][0]) * (FSP_data->g->p[j][i]);
00912 }
00913
00914
00915
00916 mat_free(t);
00917 mat_free(nu);
00918 mat_free(mu);
00919
00920 mat_free(iden);
00921 mat_free(Ginv);
00922 mat_free(bfinal);
00923 mat_free(cfinal);
00924 mat_free(dfinal);
00925 mat_free(A);
00926 mat_free(Ainv);
00927 mat_free(G);
00928 mat_free(e);
00929 mat_free(eT);
00930 return (dq);
00931 }
00932
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953 MATRIX *findt_without_Betas_Holonomic(FSP_data, B, H, datafp)
00954 FILE *datafp;
00955 MATRIX *B,
00956 *H;
00957 Solutions *FSP_data;
00958 {
00959 int i, j, k;
00960 float sum=0.0;
00961 double a, b;
00962 MATRIX *dq,
00963 *G,*Gtemp,
00964 *t,
00965 *x,*y,*z,*iden,
00966 *e,
00967 *eT;
00968
00969
00970 dq = mat_malloc (M , 1);
00971 e = mat_malloc (SPAN, 1);
00972 eT = mat_malloc ( 1, SPAN);
00973 z = mat_malloc (H->rows, H->cols);
00974
00975
00976 for (i = 0; i < (SPAN); i++)
00977 { e -> p[i][0] = eT -> p[0][i] = 1.0e0; }
00978
00979 Gtemp = Build_Grammian2 (FSP_data, B, datafp);
00980
00981 G = mat_cp2(Gtemp);
00982 mat_LU_inv(G);
00983
00984 if (DEBUG) {
00985 fprintf(datafp,"\n ______________________________ \n");
00986 fprintf(datafp,"\n LEAST NORM MOTION \n");
00987 fprintf(datafp, " ______________________________ \n\n");
00988
00989 iden = mat_mul2(G,Gtemp);
00990 fmat_pr(datafp,"*** G ***",Gtemp);
00991 fmat_pr(datafp,"*** Ginv ***", G);
00992 fmat_pr(datafp,"*** iden ***", iden);
00993 mat_free(iden);
00994 }
00995
00996 x = mat_mul2(eT, G);
00997 y = mat_mul2(x, e);
00998
00999 a = y->p[0][0]; mat_free(y);
01000
01001 y = mat_mul2(x, H);
01002
01003 if (!FSP_data->Null_Space)
01004 b = -(1 + y->p[0][0])/a;
01005 else
01006 b = -y->p[0][0]/a;
01007
01008 mat_sca(e, b);
01009
01010 mat_add(H, e, z);
01011 mat_sca(G, -1.0);
01012
01013 t = mat_mul2(G, z);
01014
01015 for (i = 0; i < M; i++)
01016 {
01017 dq->p[i][0] = 0.0e0;
01018 for (j = 0; j < SPAN; j++)
01019 dq->p[i][0] += (t -> p[j][0]) * (FSP_data->g -> p[j][i]);
01020 }
01021
01022 for (i = 0, sum = 0; i < SPAN; i++) sum += t -> p[i][0];
01023 if (!FSP_data->Null_Space) {
01024 if ((sum< .99)||(sum>1.01))
01025 IKerror (21, FATAL, "findt_without_Betas_Holonomic");
01026 }
01027 else if ((sum<-.01)||(sum> .01)) IKerror (21, FATAL,
01028 "findt_without_Betas_Holonomic");
01029
01030
01031 if (DEBUG) {
01032 fmat_pr(datafp, "*** t's ***", t);
01033 fprintf(datafp, "\nsum (no betas): %7.4f \n", sum);
01034 for (i = 0, sum = 0; i < M; i++)
01035 sum += dq->p[i][0];
01036 fprintf(datafp, "\nsum t*g: %7.4f\n", sum);
01037 }
01038
01039 mat_free(Gtemp);
01040 mat_free(G);
01041 mat_free(eT);
01042 mat_free(e);
01043 mat_free(t);
01044 mat_free(x);
01045 mat_free(y);
01046
01047 return (dq);
01048 }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072 #include"general.h"
01073
01074 MATRIX *findt_with_Betas_Nonholonomic(FSP_data, B, H, datafp)
01075 FILE *datafp;
01076 MATRIX *B,
01077 *H;
01078 Solutions *FSP_data;
01079
01080 {
01081
01082 MATRIX *temp,
01083 *temp1,
01084 *temp2,
01085 *temp3,
01086 *temp4,
01087 *temp5,
01088 *temp6,
01089 *e, *eT,
01090 *G, *Ginv,
01091 *cfinal,
01092 *sfinal,
01093 *tfinal,
01094 *mfinal,
01095 *rfinal,
01096 *zfinal,
01097 *wfinal,
01098 *delta,
01099 *lambda, *lambda_inv,
01100 *Afinal,
01101 *alpha, *alphaT,
01102 *xfinal,
01103 *nu,
01104 *iden,
01105 *dq,
01106 *betas;
01107 float ctemp,
01108 ctemp1,
01109 ctemp2,
01110 ctemp3,
01111 bfinal,
01112 dfinal,
01113 lfinal,
01114 kfinal,
01115 pfinal,
01116 eta,
01117 mu;
01118 double sum1 = 0, sum2 = 0;
01119
01120 int i,j,k,
01121 b;
01122
01123 if (DEBUG) fprintf(datafp, "\n\n# of constraints %d \n", FSP_data->cn);
01124
01125
01126 e = mat_malloc(SPAN,1);
01127 eT= mat_malloc(1,SPAN);
01128 for (i = 0; i < SPAN; i++)
01129 { e -> p[i][0] = eT -> p[0][i] = 1.0e0;}
01130
01131
01132 G = Build_Grammian2(FSP_data, B, datafp);
01133
01134 Ginv = mat_cp2(G);
01135 mat_LU_inv(Ginv);
01136
01137
01138
01139 betas = mat_malloc(M, FSP_data->cn);
01140 for (i = 0; i < M; i++)
01141 for (j = 0; j < FSP_data->cn; j++)
01142 betas->p[i][j] = FSP_data->betall->p[i][j];
01143 if (DEBUG)
01144 {
01145 fmat_pr(datafp,"betas (betall)", betas);
01146 iden = mat_mul2(Ginv, G);
01147 fmat_pr(datafp,"*** Identity Matrix Check (G * Ginv) ***", iden);
01148 fmat_pr(datafp,"*** betas ***", FSP_data->betall);
01149 mat_free(iden);
01150 }
01151
01152
01153
01154
01155
01156
01157
01158
01159 Afinal = mat_malloc(M,1);
01160 for (i = 0; i < M; i++) Afinal->p[i][0] = 0.0;
01161 Afinal->p[M - 3][0] = -sin(FSP_data->Qarray->p[M-1][0] + (PI/2));
01162 Afinal->p[M - 2][0] = cos(FSP_data->Qarray->p[M-1][0] + (PI/2));
01163 Afinal->p[M - 1][0] = -(Robot->PLAT.Length)/2;
01164
01165 alpha = mat_malloc(SPAN,1);
01166 for (i = 0; i < SPAN; i++)
01167 alpha->p[i][0] = 0.0;
01168 for (i = 0; i < SPAN; i++)
01169 for (j = M - 3; j < M; j++)
01170 alpha->p[i][0] += Afinal->p[j][0] * FSP_data->g->p[i][j];
01171 alphaT=mat_malloc(1,SPAN);
01172 for (i = 0; i < SPAN; i++)
01173 alphaT->p[0][i] = alpha->p[i][0];
01174
01175
01176 temp = mat_malloc(1,SPAN);
01177 bfinal = 0.0;
01178 for (i = 0; i < SPAN; i++)
01179 {
01180 temp->p[0][i] = 0.0;
01181 for (j = 0; j < SPAN; j++)
01182 temp->p[0][i] += alphaT->p[0][j] * Ginv->p[j][i];
01183 }
01184 for (i = 0; i < SPAN; i++)
01185 bfinal += temp->p[0][i];
01186 mat_free(temp);
01187
01188
01189 temp = mat_malloc(1,SPAN);
01190 dfinal = 0.0;
01191 for (i = 0; i < SPAN; i++)
01192 {
01193 temp->p[0][i] = 0.0;
01194 for (j = 0; j < SPAN; j++)
01195 temp->p[0][i] += alphaT->p[0][j] * Ginv->p[j][i];
01196 }
01197 for (i = 0; i < SPAN; i++)
01198 dfinal += temp->p[0][i] * alpha->p[i][0];
01199 mat_free(temp);
01200
01201
01202 kfinal = 0.0;
01203 for (i = 0; i < SPAN; i++)
01204 for (j = 0; j < SPAN; j++)
01205 kfinal += Ginv->p[i][j];
01206
01207
01208 temp = mat_malloc(1,SPAN);
01209 lfinal = 0.0;
01210 for (i = 0; i < SPAN; i++)
01211 {
01212 temp->p[0][i] = 0.0;
01213 for (j = 0; j < SPAN; j++)
01214 temp->p[0][i] += Ginv->p[j][i];
01215 }
01216 for (i = 0; i < SPAN; i++)
01217 lfinal += temp->p[0][i] * alpha->p[i][0];
01218 mat_free(temp);
01219
01220
01221
01222 pfinal = (bfinal * lfinal) - (dfinal * kfinal);
01223
01224
01225 cfinal = mat_malloc(FSP_data->cn, 1);
01226 temp = mat_malloc(1, SPAN);
01227 mat_mul(alphaT, Ginv, temp);
01228 for (j = 0; j < FSP_data->cn; j++)
01229 {
01230 cfinal->p[j][0] = 0.0;
01231 for (i = 0; i < SPAN; i++)
01232 cfinal->p[j][0] += temp->p[0][i] * betas->p[i][j];
01233 }
01234 mat_free(temp);
01235
01236
01237 sfinal = mat_malloc(FSP_data->cn, 1);
01238 temp = mat_malloc(SPAN, 1);
01239 mat_mul(Ginv, alpha, temp);
01240 mat_tra(betas);
01241 for (j = 0; j < FSP_data->cn; j++)
01242 {
01243 sfinal->p[j][0] = 0.0;
01244 for (i = 0; i < SPAN; i++)
01245 sfinal->p[j][0] += betas->p[j][i] * temp->p[i][0];
01246 }
01247 mat_tra(betas);
01248 mat_free(temp);
01249
01250
01251 mfinal = mat_malloc(FSP_data->cn,1);
01252 temp = mat_malloc(1,SPAN);
01253 mat_mul(eT, Ginv, temp);
01254 for (i = 0; i < FSP_data->cn; i++)
01255 {
01256 mfinal->p[i][0] = 0;
01257 for (j = 0; j < SPAN; j++)
01258 mfinal->p[i][0] += temp->p[0][j] * betas->p[j][i];
01259 }
01260 mat_free(temp);
01261
01262
01263 rfinal = mat_malloc(FSP_data->cn, 1);
01264 temp = mat_malloc(SPAN,1);
01265 mat_mul(Ginv, e, temp);
01266 mat_tra(betas);
01267 for (i = 0; i < FSP_data->cn; i++)
01268 {
01269 rfinal->p[i][0] = 0;
01270 for (j = 0; j < SPAN; j++)
01271 rfinal->p[i][0] += betas->p[i][j] * temp->p[j][0];
01272 }
01273 mat_tra(betas);
01274 mat_free(temp);
01275
01276
01277 zfinal = mat_malloc(FSP_data->cn, 1);
01278 mat_sca(sfinal, bfinal);
01279 mat_sca(rfinal, dfinal);
01280 mat_sub(sfinal, rfinal, zfinal);
01281 ctemp1 = 1 / bfinal;
01282 ctemp2 = 1 / dfinal;
01283 mat_sca(sfinal, ctemp1);
01284 mat_sca(rfinal, ctemp2);
01285
01286
01287 wfinal = mat_malloc(FSP_data->cn, 1);
01288 mat_sca(cfinal, kfinal);
01289 mat_sca(mfinal, bfinal);
01290 mat_sub(cfinal, mfinal, wfinal);
01291 ctemp1 = 1 / kfinal;
01292 ctemp2 = 1 / bfinal;
01293 mat_sca(cfinal, ctemp1);
01294 mat_sca(mfinal, ctemp2);
01295
01296
01297
01298
01299 temp = mat_malloc(SPAN, 1);
01300 delta = mat_malloc(FSP_data->cn, FSP_data->cn);
01301 for (k = 0; k < FSP_data->cn; k++)
01302 for (b = 0; b < FSP_data->cn; b++)
01303 {
01304 delta->p[k][b] = 0.0;
01305 for (i = 0; i < SPAN; i++)
01306 {
01307 temp->p[i][0] = 0.0;
01308 for (j = 0; j < SPAN; j++)
01309 temp->p[i][0] += Ginv->p[i][j] * betas->p[j][k];
01310 }
01311 for (j = 0; j < SPAN; j++)
01312 delta->p[k][b] += betas->p[j][b] * temp->p[j][0];
01313 }
01314 mat_free(temp);
01315
01316
01317 lambda = mat_malloc(FSP_data->cn,FSP_data->cn);
01318 for (j = 0; j < FSP_data->cn; j++)
01319 for (i = 0; i < FSP_data->cn; i++)
01320 {
01321 ctemp1 = bfinal * delta->p[j][i];
01322 ctemp2 = rfinal->p[j][0] * cfinal->p[i][0];
01323 lambda->p[j][i] = pfinal * (ctemp1 - ctemp2);
01324 lambda->p[j][i] += zfinal->p[j][0] * wfinal->p[i][0];
01325 }
01326
01327
01328
01329
01330
01331
01332
01333
01334 if ((STEP == ONE) && (!FSP_data->Null_Space))
01335 {
01336
01337 xfinal = mat_malloc(FSP_data->cn,1);
01338 mat_sca(zfinal, bfinal);
01339 for (i = 0; i < FSP_data->cn; i++)
01340 xfinal->p[i][0] = zfinal->p[i][0] - (bfinal * pfinal);
01341 ctemp1 = 1/bfinal;
01342 mat_sca(zfinal,ctemp1);
01343
01344
01345 nu = mat_malloc(FSP_data->cn,1);
01346 lambda_inv = mat_malloc(FSP_data->cn,FSP_data->cn);
01347 for (i = 0; i < FSP_data->cn;i++)
01348 for (j = 0; j < FSP_data->cn; j++)
01349 lambda_inv->p[i][j] = lambda->p[i][j];
01350 mat_LU_inv(lambda_inv);
01351 mat_mul(lambda_inv, xfinal, nu);
01352
01353
01354 temp1 = mat_malloc(1,1);
01355 temp2 = mat_malloc(1,1);
01356 mat_tra(nu);
01357 mat_mul(nu,cfinal,temp1);
01358 mat_sca(temp1,kfinal);
01359 mat_mul(nu,mfinal,temp2);
01360 mat_sca(temp2,bfinal);
01361 eta = -(bfinal - temp1->p[0][0] + temp2->p[0][0])/pfinal;
01362 mat_tra(nu);
01363 mat_free(temp1);
01364 mat_free(temp2);
01365
01366
01367 temp1 = mat_malloc(1,1);
01368 mat_tra(nu);
01369 mat_mul(nu,cfinal,temp1);
01370 mu = -(temp1->p[0][0] + (eta * dfinal))/bfinal;
01371 mat_tra(nu);
01372 mat_free(temp1);
01373 }
01374 else if ((STEP == TWO) || (FSP_data->Null_Space))
01375 {
01376
01377 xfinal = mat_malloc(FSP_data->cn,1);
01378 for (i = 0; i < FSP_data->cn; i++)
01379 xfinal->p[i][0] = -bfinal * pfinal;
01380
01381
01382 nu = mat_malloc(FSP_data->cn, 1);
01383 lambda_inv = mat_malloc(FSP_data->cn,FSP_data->cn);
01384 for (i = 0; i < FSP_data->cn;i++)
01385 for (j = 0; j < FSP_data->cn; j++)
01386 lambda_inv->p[i][j] = lambda->p[i][j];
01387 mat_LU_inv(lambda_inv);
01388 mat_mul(lambda_inv, xfinal, nu);
01389
01390
01391 temp1 = mat_malloc(1,1);
01392 temp2 = mat_malloc(1,1);
01393 mat_tra(nu);
01394 mat_mul(nu,cfinal,temp1);
01395 mat_sca(temp1,kfinal);
01396 mat_mul(nu,mfinal,temp2);
01397 mat_sca(temp2,bfinal);
01398 eta = -temp2->p[0][0] + temp1->p[0][0];
01399 eta /= pfinal;
01400 mat_tra(nu);
01401 mat_free(temp1);
01402 mat_free(temp2);
01403
01404
01405 temp1 = mat_malloc(1,1);
01406 mat_tra(nu);
01407 mat_mul(nu,cfinal,temp1);
01408 mu = -(temp1->p[0][0] + (eta * dfinal));
01409 mu /= bfinal;
01410 mat_tra(nu);
01411 mat_free(temp1);
01412
01413 }
01414 else IKerror(29,FATAL,"findt_with_Betas_Nonholonomic");
01415
01416
01417
01418
01419
01420
01421
01422 tfinal = mat_malloc(SPAN,1);
01423 temp1 = mat_malloc(SPAN,1);
01424 temp2 = mat_malloc(SPAN,FSP_data->cn);
01425 temp3 = mat_malloc(SPAN,1);
01426 temp4 = mat_malloc(SPAN,1);
01427 temp5 = mat_malloc(SPAN,1);
01428 temp6 = mat_malloc(SPAN,1);
01429 mat_mul(Ginv,e,temp1);
01430 mat_sca(temp1,mu);
01431 mat_mul(Ginv,betas,temp2);
01432 mat_mul(temp2,nu,temp3);
01433 mat_mul(Ginv,alpha,temp4);
01434 mat_sca(temp4,eta);
01435 mat_add(temp1,temp3,temp5);
01436 mat_add(temp5,temp4,temp6);
01437 for (i = 0; i < SPAN; i++) tfinal->p[i][0] = -(temp6->p[i][0]);
01438 mat_free(temp1);
01439 mat_free(temp2);
01440 mat_free(temp3);
01441 mat_free(temp4);
01442 mat_free(temp5);
01443 mat_free(temp6);
01444
01445 for (i = 0, sum1 = 0; i < SPAN; i++)
01446 sum1 += tfinal -> p[i][0];
01447 if (!FSP_data->Null_Space) {
01448 if ((sum1< .99)||(sum1>1.01)) IKerror (21, FATAL,
01449 "findt_with_Betas_Nonholonomic");
01450 }
01451 else if ((sum1<-.01)||(sum1> .01)) IKerror (21, FATAL,
01452 "findt_with_Betas_Nonholonomic");
01453
01454 if (DEBUG) {
01455 fprintf(datafp, " b= %9.4f\n", bfinal);
01456 fprintf(datafp, " d= %9.4f\n", dfinal);
01457 fprintf(datafp, " k= %9.4f\n", kfinal);
01458 fprintf(datafp, " l= %9.4f\n", lfinal);
01459 fprintf(datafp, " p= %9.4f\n", pfinal);
01460 fmat_pr(datafp, "c= ", cfinal);
01461 fmat_pr(datafp, "m= ", mfinal);
01462 fmat_pr(datafp, "r= ", rfinal);
01463 fmat_pr(datafp, "s= ", sfinal);
01464 fmat_pr(datafp, "z= ", zfinal);
01465 fmat_pr(datafp, "w= ", wfinal);
01466 fmat_pr(datafp,"delta = ", delta);
01467 fmat_pr (datafp, "Nu =", nu);
01468 fprintf (datafp, "Mu = %9.4f \n", mu);
01469 fprintf (datafp, "Eta = %9.4f \n", eta);
01470 fmat_pr(datafp,"Term1", temp3);
01471 fmat_pr(datafp,"Term2", temp2);
01472 fmat_pr (datafp, "*** t's for Collision ***", tfinal);
01473
01474 fprintf(datafp, "\nsum ti: %7.4f\n", sum1);
01475 for (j=0; j<FSP_data->cn; j++)
01476 {
01477 sum1 = 0;
01478 for (i = 0; i < SPAN; i++)
01479 sum1 += betas -> p[i][j] * tfinal -> p[i][0];
01480 fprintf(datafp, "\nsum betai*ti: %7.4f \n", sum1);
01481 }
01482 }
01483 dq = mat_malloc(M, 1);
01484 for (i = 0; i < FSP_data->M; i++)
01485 {
01486 dq->p[i][0]=0.0;
01487 for (j = 0; j < SPAN; j++)
01488 dq->p[i][0] += (tfinal -> p[j][0]) * (FSP_data->g->p[j][i]);
01489 }
01490 if (DEBUG) fmat_pr(datafp, "New dq reflecting constraints (t * g)", dq);
01491
01492 for (i=sum1=0;i<SPAN;i++) { sum1 = tfinal->p[i][0] * eta; }
01493
01494
01495
01496
01497
01498 mat_free(Afinal);
01499 mat_free(tfinal);
01500 mat_free(nu);
01501 mat_free(Ginv);
01502 mat_free(cfinal);
01503 mat_free(sfinal);
01504 mat_free(mfinal);
01505 mat_free(rfinal);
01506 mat_free(zfinal);
01507 mat_free(wfinal);
01508 mat_free(xfinal);
01509 mat_free(delta);
01510 mat_free(lambda);
01511 mat_free(lambda_inv);
01512 mat_free(alphaT);
01513 mat_free(G);
01514 mat_free(e);
01515 mat_free(eT);
01516 mat_free(betas);
01517
01518 return (dq);
01519 }
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538 MATRIX *findt_without_Betas_Nonholonomic(FSP_data, B, H, datafp)
01539 FILE *datafp;
01540 MATRIX *B,
01541 *H;
01542 Solutions *FSP_data;
01543
01544 {
01545 MATRIX *temp,
01546 *temp1,
01547 *temp2,
01548 *tfinal,
01549 *alphaT,
01550 *e, *eT,
01551 *G, *Ginv,
01552 *iden,
01553 *dq,
01554 *alpha,
01555 *Afinal;
01556 float ctemp,
01557 bfinal,
01558 dfinal,
01559 lfinal,
01560 kfinal,
01561 pfinal,
01562 eta,
01563 mu;
01564 int i,j;
01565 double sum1 = 0, sum2 = 0;
01566
01567 if (DEBUG) fprintf(datafp, "\n\n# of constraints %d \n", FSP_data->cn);
01568
01569
01570 e = mat_malloc(SPAN,1);
01571 eT= mat_malloc(1,SPAN);
01572 for (i = 0; i < SPAN; i++)
01573 { e -> p[i][0] = eT -> p[0][i] = 1.0e0;}
01574
01575
01576 G = Build_Grammian2(FSP_data, B, datafp);
01577
01578 Ginv = mat_cp2(G);
01579 mat_LU_inv(Ginv);
01580 if (DEBUG)
01581 {
01582 iden = mat_mul2(Ginv, G);
01583 fmat_pr(datafp,"*** Identity Matrix Check (G * Ginv) ***", iden);
01584 mat_free(iden);
01585 }
01586
01587
01588
01589
01590
01591
01592
01593
01594 Afinal = mat_malloc(M,1);
01595 for (i = 0; i < M; i++) Afinal->p[i][0] = 0.0;
01596 Afinal->p[M - 3][0] = -sin(FSP_data->Qarray->p[M-1][0] + (PI/2));
01597 Afinal->p[M - 2][0] = cos(FSP_data->Qarray->p[M-1][0] + (PI/2));
01598 Afinal->p[M - 1][0] = -(Robot->PLAT.Length)/2.25;
01599
01600 alpha = mat_malloc(SPAN,1);
01601 for (i = 0; i < SPAN; i++)
01602 alpha->p[i][0] = 0.0;
01603 for (i = 0; i < SPAN; i++)
01604 for (j = M - 3; j < M; j++)
01605 alpha->p[i][0] += Afinal->p[j][0] * FSP_data->g->p[i][j];
01606 alphaT=mat_malloc(1,SPAN);
01607 for (i = 0; i < SPAN; i++)
01608 alphaT->p[0][i] = alpha->p[i][0];
01609
01610
01611 temp = mat_malloc(1,SPAN);
01612 bfinal = 0.0;
01613 for (i = 0; i < SPAN; i++)
01614 {
01615 temp->p[0][i] = 0.0;
01616 for (j = 0; j < SPAN; j++)
01617 temp->p[0][i] += alphaT->p[0][j] * Ginv->p[j][i];
01618 }
01619 for (i = 0; i < SPAN; i++)
01620 bfinal += temp->p[0][i];
01621 mat_free(temp);
01622
01623
01624 temp = mat_malloc(1,SPAN);
01625 dfinal = 0.0;
01626 for (i = 0; i < SPAN; i++)
01627 {
01628 temp->p[0][i] = 0.0;
01629 for (j = 0; j < SPAN; j++)
01630 temp->p[0][i] += alphaT->p[0][j] * Ginv->p[j][i];
01631 }
01632 for (i = 0; i < SPAN; i++)
01633 dfinal += temp->p[0][i] * alpha->p[i][0];
01634 mat_free(temp);
01635
01636
01637 kfinal = 0.0;
01638 for (i = 0; i < SPAN; i++)
01639 for (j = 0; j < SPAN; j++)
01640 kfinal += Ginv->p[i][j];
01641
01642
01643 temp = mat_malloc(1,SPAN);
01644 lfinal = 0.0;
01645 for (i = 0; i < SPAN; i++)
01646 {
01647 temp->p[0][i] = 0.0;
01648 for (j = 0; j < SPAN; j++)
01649 temp->p[0][i] += Ginv->p[j][i];
01650 }
01651 for (i = 0; i < SPAN; i++)
01652 lfinal += temp->p[0][i] * alpha->p[i][0];
01653 mat_free(temp);
01654
01655
01656
01657 pfinal = (bfinal * lfinal) - (dfinal * kfinal);
01658
01659
01660
01661
01662
01663
01664
01665
01666
01667
01668
01669 {
01670
01671 eta = - (bfinal / pfinal );
01672
01673
01674 mu = ( -( eta ) * dfinal ) / bfinal;
01675 }
01676
01677
01678
01679
01680
01681
01682
01683 tfinal = mat_malloc(SPAN,1);
01684 temp1 = mat_malloc(SPAN,1);
01685 temp2 = mat_malloc(SPAN,1);
01686 mat_mul(Ginv,e,temp1);
01687 mat_mul(Ginv,alpha,temp2);
01688 mat_sca(temp1,mu);
01689 mat_sca(temp2,eta);
01690 mat_add(temp1,temp2,tfinal);
01691 ctemp = -1;
01692 mat_sca(tfinal,ctemp);
01693 mat_free(temp1);
01694 mat_free(temp2);
01695
01696 for (i = 0, sum1 = 0; i < SPAN; i++) sum1 += tfinal -> p[i][0];
01697 if (!FSP_data->Null_Space) {
01698 if ((sum1< .99)||(sum1>1.01)) IKerror (21, OK,
01699 "findt_without_Betas_Nonholonomic");
01700 }
01701
01702 if (DEBUG) {
01703 fprintf(datafp, " b= %9.4f\n", bfinal);
01704 fprintf(datafp, " d= %9.4f\n", dfinal);
01705 fprintf(datafp, " k= %9.4f\n", kfinal);
01706 fprintf(datafp, " l= %9.4f\n", lfinal);
01707 fprintf(datafp, " p= %9.4f\n", pfinal);
01708 fprintf (datafp, "Mu = %9.4f \n", mu);
01709 fprintf (datafp, "Eta = %9.4f \n", eta);
01710 fmat_pr (datafp, "*** t's for Collision ***", tfinal);
01711 fprintf(datafp, "\nsum ti: %7.4f\n", sum1);
01712 }
01713
01714 dq = mat_malloc(M, 1);
01715 for (i = 0; i < FSP_data->M; i++)
01716 {
01717 dq->p[i][0]=0.0;
01718 for (j = 0; j < SPAN; j++)
01719 dq->p[i][0] += (tfinal -> p[j][0]) * (FSP_data->g->p[j][i]);
01720 }
01721
01722 for (i=sum1=0;i<SPAN;i++) { sum1 = tfinal->p[i][0] * eta; }
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732 if (DEBUG) fmat_pr(datafp, "New dq reflecting constraints (t * g)", dq);
01733
01734 if (FSP_data->Null_Space) for(i=0;i<FSP_data->M; dq->p[i++][0] = 0.0);
01735
01736 mat_free(Afinal);
01737 mat_free(tfinal);
01738 mat_free(Ginv);
01739 mat_free(alphaT);
01740 mat_free(G);
01741 mat_free(e);
01742 mat_free(eT);
01743
01744 return (dq);
01745 }