00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <IKOR/general.h>
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 void IKerror(int error_vector, int fatal, char *mesg)
00039 {
00040 fprintf (stderr, "\nERROR %d: ", error_vector);
00041 switch (error_vector) {
00042 case 10: fprintf (stderr, "FSP didn't complete!\n"); break;
00043 case 11: fprintf (stderr, "Unable to Open '%s'\n", mesg); break;
00044 case 12: fprintf (stderr, "General File Error in '%s'", mesg); break;
00045 case 15: fprintf (stderr, "Too Many Points in Trajectory. '%s'\n",mesg);
00046 break;
00047 case 16: fprintf (stderr, "Request Joint Space %d is > %d in %s.\n",
00048 M, Robot->NA,mesg); break;
00049 case 17: fprintf (stderr, "Requested Task Space %d is > 6 in %s.\n",
00050 mesg); break;
00051 case 18: fprintf (stderr, "Memory allocation error in 's'\n",mesg);
00052 break;
00053 case 19: fprintf (stderr, "Manipulator File Integrity Lost \n Bad data",
00054 " file: ROBOT.dat in '%s'\n", mesg); break;
00055 case 21: fprintf (stderr, "SORRY!...more constraints %s %s\n",
00056 "than D.O.R. in procedure: ", mesg); break;
00057 case 23: fprintf (stderr, "Defaulting to using one-shot in %s.\n",
00058 mesg); break;
00059 case 24: fprintf (stderr, "Platform does not exist, see %s.\n", mesg);
00060 break;
00061 case 25: fprintf (stderr, "System did not complete.\n"); break;
00062 case 26: fprintf (stderr, "Requested dx[%s] too large.\n",mesg); break;
00063 case 29: fprintf (stderr, "%s%s%s\n", "System Error: Did not Execute One",
00064 " Step or Two Step in ",mesg); break;
00065 case 30: fprintf (stderr, "Division by zero in Analytical.c\n"); break;
00066 case 31: fprintf (stderr, "Option UnImplemented: %s\n",mesg); break;
00067 default: fprintf (stderr, "No such Error. error_vector doesn't exist.\n");
00068 }
00069
00070 if (fatal == FATAL)
00071 { fprintf(stderr, "FATAL Error. aborting... \n"); abort(); }
00072 else fprintf(stderr, "Error not Fatal. Continuing execution...\n");
00073 }
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 Solutions *Solutions_init(int M, int N)
00094 {
00095 int i, j;
00096 Solutions *Temp;
00097
00098 Temp = (Solutions *) malloc( sizeof( Solutions ) );
00099 Temp->g = mat_malloc( M, M);
00100 Temp->Qarray = mat_malloc( M, 1);
00101 Temp->Xelim = mat_malloc( M, 1);
00102 Temp->betall = mat_malloc( M - N + 15, M);
00103
00104 for (i=0; i< Temp->betall->rows; i++)
00105 for (j=0; j<Temp->betall->cols; j++)
00106 Temp->betall->p[i][j]=0.0;
00107
00108 if(!Temp) IKerror(18, FATAL, "Solutions_init");
00109
00110 Temp->M = Temp->Mred = M;
00111 Temp->N = Temp->Nred = N;
00112 Temp->cn = 0;
00113
00114 return (Temp);
00115 }
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 void Solutions_free( Solutions *Temp )
00132 {
00133 mat_free(Temp->betall);
00134 mat_free(Temp->Qarray);
00135 mat_free(Temp->Xelim);
00136 mat_free(Temp->g);
00137 free ( (char *) Temp);
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156 GetData ( MATRIX *A, MATRIX *b)
00157 {
00158 FILE *fpin;
00159 int i, j;
00160
00161 fpin = fopen("FSP_data", "r");
00162
00163 for (i=0; i<N; i++)
00164 for (j=0; j<M; j++)
00165 fscanf(fpin, "%f", &A->p[i][j]);
00166
00167 for (i=0; i<N; i++)
00168 fscanf(fpin, "%f", &b->p[i][0]);
00169
00170 fclose(fpin);
00171 }
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 int spheres(spheredata, datafp)
00190 FILE *datafp;
00191 double spheredata[4][4];
00192 {
00193 int ns, sphere_no, i;
00194 FILE *sphere_file;
00195 char question='n';
00196
00197 if (CHANGE_SPHERES)
00198 {
00199 fprintf(stdout, "\nDo you want to change the spheres? ");
00200 scanf(" %c", &question);
00201 }
00202
00203 if ((sphere_file = fopen("sphere_data", "r+")) == NULL)
00204 { IKerror(11, OK, "sphere_data"); return 0; }
00205
00206 if ((question != 'Y') && (question != 'y'))
00207 {
00208 fscanf(sphere_file, "%d", &ns);
00209 for (sphere_no = 0; sphere_no < ns; sphere_no++)
00210 for (i = 0; i < 4; i++)
00211 fscanf(sphere_file, "%lf", &spheredata[sphere_no][i]);
00212 }
00213 else
00214 {
00215 fprintf(stdout, "How many spheres? (4 max): ");
00216
00217
00218
00219
00220 scanf("%d", &ns);
00221 if (ns > 4) ns = 4;
00222
00223 for (i = 0; i < ns; i++)
00224 {
00225 fprintf(stdout, "xcenter of sphere[%d]: ", i);
00226 fscanf(stdin, "%f", &spheredata[i][0]);
00227 fprintf(stdout, "ycenter of sphere[%d]: ", i);
00228 fscanf(stdin, "%f", &spheredata[i][1]);
00229 fprintf(stdout, "zcenter of sphere[%d]: ", i);
00230 fscanf(stdin, "%f", &spheredata[i][2]);
00231 fprintf(stdout, " radius of sphere[%d]: ", i);
00232 fscanf(stdin, "%f", &spheredata[i][3]);
00233 }
00234
00235 fprintf(sphere_file, "%i\n", ns);
00236 for (sphere_no = 0; sphere_no < ns; sphere_no++)
00237 {
00238 for (i = 0; i < 4; i++)
00239 fprintf(sphere_file, "%f ", spheredata[sphere_no][i]);
00240 fprintf(sphere_file, "\n");
00241 }
00242 }
00243
00244 fprintf(datafp,"\n Spheres read into the system...");
00245 for (i=0; i< ns; i++)
00246 fprintf(datafp,"\n%i: <%f, %f, %f> %f",i,
00247 spheredata[i][0], spheredata[i][1], spheredata[i][2], spheredata[i][3]);
00248
00249 fclose(sphere_file);
00250 return (ns);
00251 }
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 void fmat_pr (FILE *checkfile, char *string, MATRIX *a)
00272 {
00273 int i, j;
00274
00275 fprintf(checkfile, "\n %s ROWS: %d, COLS: %d\n",
00276 string, a->rows, a->cols);
00277 for (i = 0; i < a->rows; i++)
00278 {
00279 for (j = 0; j < a->cols; j++)
00280 fprintf(checkfile, "%8.4f ", a->p[i][j]);
00281 fprintf(checkfile, "\n");
00282 }
00283 fprintf(checkfile, "\n");
00284 }
00285
00286 void fmat_prf(FILE *checkfile, char *string, MATRIX *a)
00287 {
00288 int i, j;
00289
00290 fprintf(checkfile, "\n %s Rows: %d, Cols: %d\n",
00291 string, a->rows, a->cols);
00292 for (i = 0; i < a->rows; i++)
00293 {
00294 for (j = 0; j < a->cols; j++)
00295 {
00296 fprintf(checkfile," %16.12f", a->p[i][j]);
00297 }
00298 fprintf(checkfile, "\n");
00299 }
00300 fprintf(checkfile, "\n");
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 void fprint_norm(outfile,dq,datafp)
00318 MATRIX *dq;
00319 FILE *outfile, *datafp;
00320 {
00321 int i;
00322 double temp, result;
00323
00324
00325
00326
00327
00328
00329
00330 for (i = 0, result = 0.0; i < dq->rows; i++)
00331 {
00332 temp = (dq->p[i][0]);
00333 temp *= temp;
00334 result += sqrt((temp * temp));
00335 }
00336
00337 if (DEBUG) fprintf(datafp, "\n NORM value: %lf", result);
00338
00339 fprintf (outfile, " %14.10f\n", result);
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 void fprint_hist(outfile, Old_DQs)
00354 FILE *outfile;
00355 History *Old_DQs;
00356 {
00357 int i, j;
00358
00359 fprintf(outfile, "index pointer at: %d\n", Old_DQs->whereami);
00360 fprintf(outfile, "times:\n");
00361 for (i=0; i<HIST_SIZE; i++)
00362 fprintf(outfile, " %5.6lf ", Old_DQs->dq[i].time);
00363 fprintf(outfile, "\n\n");
00364 for (i=0; i<HIST_SIZE; i++)
00365 {
00366 for (j=0; j<Old_DQs->dq[i].DQ->rows; j++)
00367 fprintf(outfile, "%8.6lf ", Old_DQs->dq[i].DQ->p[j][0]);
00368 fprintf(outfile, "\n");
00369 }
00370 fprintf(outfile, "\t==========================================\n\n");
00371
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 void fdq_pr (DQFile, Old_DQs)
00386 FILE *DQFile;
00387 History Old_DQs;
00388 {
00389 int now,
00390 i;
00391
00392 now = Old_DQs.whereami-1;
00393 if (now == -1) now = HIST_SIZE - 1;
00394 fprintf(DQFile, "%8.6lf ", Old_DQs.dq[now].time);
00395 for (i=0; i<M; i++)
00396 fprintf(DQFile, "%8.6lf ", Old_DQs.dq[now].DQ->p[i][0]);
00397 fprintf(DQFile, "\n");
00398 }
00399