cuikaddjacobian.c
Go to the documentation of this file.
1 #include "parameters.h"
2 #include "defines.h"
3 #include "world.h"
4 #include "error.h"
5 #include "filename.h"
6 
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 
102 int main(int argc, char **arg)
103 {
104  Tparameters parameters; /* Parameters */
105  TCuikSystem cuik; /* The cuiksystem to enrich with the Jacobian equations*/
106 
107  Tfilename fparam;
108  Tfilename fcuik;
109  Tfilename fcuikOut;
110 
111  FILE *f;
112  boolean *selectedVars;
113  unsigned int i,nv,vID;
114 
115  if (argc>1)
116  {
117  /*Init parameters*/
118  CreateFileName(NULL,arg[1],NULL,PARAM_EXT,&fparam);
119  #if (_DEBUG>0)
120  printf("Reading parameter file : %s\n",GetFileFullName(&fparam));
121  #endif
122  InitParametersFromFile(GetFileFullName(&fparam),&parameters);
123 
124  /*Init cuik*/
125  CreateFileName(NULL,arg[1],NULL,CUIK_EXT,&fcuik);
126  #if (_DEBUG>0)
127  printf("Reading .cuik file : %s\n",GetFileFullName(&fcuik));
128  #endif
129  /*Read the cuik file*/
130  InitCuikSystemFromFile(&parameters,GetFileFullName(&fcuik),&cuik);
131 
132  /*determine the variables*/
133  nv=GetCSNumVariables(&cuik);
134 
135  if (argc>2)
136  {
137  NEW(selectedVars,nv,boolean);
138  /*in principle all variables are to be used in the Jacobian*/
139  for(i=0;i<nv;i++)
140  selectedVars[i]=TRUE;
141  /*but we exclude those given by the user*/
142  for(i=2;i<argc;i++)
143  {
144  vID=GetCSVariableID(arg[i],&cuik);
145  if (vID==NO_UINT)
146  fprintf(stderr,"ERROR: Variable %s is not included in the cuiksystem\n",arg[i]);
147  else
148  {
149  fprintf(stderr," Focusing on variable : %s (%u)\n",arg[i],vID);
150  selectedVars[vID]=FALSE;
151  }
152  }
153  }
154  else
155  selectedVars=NULL;
156 
157  /*Add singularity equations*/
158  AddJacobianEquations(&parameters,selectedVars,&cuik);
159 
160  /*Print resulting extended cuiksystem*/
161  CreateFileName(NULL,arg[1],"_J",CUIK_EXT,&fcuikOut);
162 
163  f=fopen(GetFileFullName(&fcuikOut),"w");
164  if (!f)
165  Error("Could not open output file in cuikaddjacobian");
166  #if (_DEBUG>0)
167  printf("Generating the _J.cuik file: %s\n",GetFileFullName(&fcuikOut));
168  #endif
169  PrintCuikSystem(&parameters,f,&cuik);
170  fclose(f);
171 
172  /* link the parameter/joints/links files */
173  LinkFileNmeWithExtension(&fcuik,PARAM_EXT ,&fcuikOut);
174  LinkFileNmeWithExtension(&fcuik,JOINTS_EXT,&fcuikOut);
175  LinkFileNmeWithExtension(&fcuik,LINKS_EXT ,&fcuikOut);
176 
177  /* Delete the data structures */
178  if (selectedVars!=NULL)
179  free(selectedVars);
180  DeleteCuikSystem(&cuik);
181  DeleteParameters(&parameters);
182 
183  /* Delete the file names */
184  DeleteFileName(&fparam);
185  DeleteFileName(&fcuik);
186  DeleteFileName(&fcuikOut);
187  }
188  else
189  {
190  fprintf(stderr," Wrong number of parameters.\n");
191  fprintf(stderr," Use:\n");
192  fprintf(stderr," cuikaddjacobian <problem name> <varname1> <varname2> ...\n");
193  fprintf(stderr," where \n");
194  fprintf(stderr," <problem name> is the cuik file resulting from cuiksingequations\n");
195  fprintf(stderr," <varnames> is the list of variables of interest\n");
196  }
197 
198  return(EXIT_SUCCESS);
199 }
200 
#define FALSE
FALSE.
Definition: boolean.h:30
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:248
void DeleteCuikSystem(TCuikSystem *cs)
Destructor.
Definition: cuiksystem.c:5113
Definition of the Tfilename type and the associated functions.
#define TRUE
TRUE.
Definition: boolean.h:21
void Error(const char *s)
General error function.
Definition: error.c:80
#define PARAM_EXT
File extension for parameter files.
Definition: filename.h:131
#define CUIK_EXT
File extension for equation files.
Definition: filename.h:70
Definition of the Tworld type and the associated functions.
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
Definitions of constants and macros used in several parts of the cuik library.
void InitCuikSystemFromFile(Tparameters *p, char *filename, TCuikSystem *cs)
Constructor from a file.
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void InitParametersFromFile(char *file, Tparameters *p)
Constructor from a file.
Definition: parameters.c:51
void AddJacobianEquations(Tparameters *p, boolean *selectedVars, TCuikSystem *cs)
Adds linear a linear combination of the Jacobian to the system.
Definition: cuiksystem.c:2758
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define JOINTS_EXT
File extension for files with samples represented by the joint values.
Definition: filename.h:187
A cuiksystem, i.e., a set of variables and equations defining a position analysis problem...
Definition: cuiksystem.h:181
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
void DeleteParameters(Tparameters *p)
Destructor.
Definition: parameters.c:295
void PrintCuikSystem(Tparameters *p, FILE *f, TCuikSystem *cs)
Prints a cuiksystem.
Definition: cuiksystem.c:5022
int main(int argc, char **arg)
Main body of the cuikaddjacobian application.
void LinkFileNmeWithExtension(Tfilename *fn1, char *ext, Tfilename *fn2)
Creates a link to a given filename.
Definition: filename.c:177
unsigned int GetCSVariableID(char *name, TCuikSystem *cs)
Gets the numerical identifier of a variable given its name.
Definition: cuiksystem.c:2586
Definition of the Tparameters type and the associated functions.
unsigned int GetCSNumVariables(TCuikSystem *cs)
Gets the number of variables already in the cuiksystem.
Definition: cuiksystem.c:2544
#define LINKS_EXT
File extension for files with samples represented by the link poses.
Definition: filename.h:180