world.c
Go to the documentation of this file.
1 #include "world.h"
2 #include "defines.h"
3 #include "error.h"
4 #include "varnames.h"
5 #include "random.h"
6 #include "list.h"
7 #include "shtransform.h"
8 
9 #include <math.h>
10 #include <string.h>
11 #include <ctype.h>
12 #include <xlocale.h>
13 #include <time.h>
14 #include <unistd.h>
15 #ifdef _OPENMP
16  #include <omp.h>
17 #endif
18 
35 void CreateBranch(Tbranch *b);
36 
45 void CopyBranch(Tbranch *b_dst,Tbranch *b_src);
46 
57 void AddStepToBranch(double s,Tjoint *joint,Tbranch *b);
58 
68 unsigned int nStepsBranch(Tbranch *b);
69 
83 void GetBranchStep(unsigned int i,double *s,Tjoint **joint,Tbranch *b);
84 
94 unsigned int GetBranchOrigin(Tbranch *b);
95 
105 unsigned int GetBranchDestination(Tbranch *b);
106 
107 
121 void MergeBranches(Tbranch *b1,Tbranch *b2,Tbranch *b);
122 
135 
143 void DeleteBranch(Tbranch *b);
144 
145 /*********************************************************************/
146 
148 {
150 }
151 
152 void CopyBranch(Tbranch *b_dst,Tbranch *b_src)
153 {
154  unsigned int i,n;
155  double s;
156  Tjoint *jo;
157 
158  CreateBranch(b_dst);
159  n=nStepsBranch(b_src);
160  for(i=0;i<n;i++)
161  {
162  GetBranchStep(i,&s,&jo,b_src);
163  AddStepToBranch(s,jo,b_dst);
164  }
165 }
166 
167 void AddStepToBranch(double s,Tjoint *joint,Tbranch *b)
168 {
169  TBranchStep *st;
170 
171  NEW(st,1,TBranchStep);
172 
173  st->joint=joint;
174  st->sign=s;
175 
176  NewVectorElement(&st,&(b->steps));
177 }
178 
179 unsigned int nStepsBranch(Tbranch *b)
180 {
181  return(VectorSize(&(b->steps)));
182 }
183 
184 void GetBranchStep(unsigned int i,double *s,Tjoint **joint,Tbranch *b)
185 {
186  TBranchStep **st;
187 
188  st=(TBranchStep **)GetVectorElement(i,&(b->steps));
189  if (st==NULL)
190  Error("Wrong index in GetBranchStep");
191  else
192  {
193  *s=(*st)->sign;
194  *joint=(*st)->joint;
195  }
196 }
197 
198 unsigned int GetBranchOrigin(Tbranch *b)
199 {
200  Tjoint *jo;
201  double s;
202  unsigned int k;
203 
204  GetBranchStep(0,&s,&jo,b);
205  if (s>0)
206  k=JointFromID(jo);
207  else
208  k=JointToID(jo);
209 
210  return(k);
211 }
212 
214 {
215  Tjoint *jo;
216  double s;
217  unsigned int k;
218 
219  GetBranchStep(nStepsBranch(b)-1,&s,&jo,b);
220  if (s>0)
221  k=JointToID(jo);
222  else
223  k=JointFromID(jo);
224 
225  return(k);
226 }
227 
229 {
230  /* We get two branches (b1,b2) representing two paths from
231  the groundLink to the same link.
232  The output 'b' will be the closed branch resulting from
233  eliminating from 'b1' and 'b2' the initial common path
234  from the groudnLink to where the paths differ */
235 
236  signed int k,n1,n2,i,nm;
237  Tjoint *jo1,*jo2;
238  boolean equal;
239  double s;
240 
241  n1=(signed int)nStepsBranch(b1);
242  n2=(signed int)nStepsBranch(b2);
243  nm=(n1<n2?n1:n2);
244  k=0;
245  equal=((n1>0)&&(n2>0));
246  while ((k<nm)&&(equal))
247  {
248  GetBranchStep((unsigned int)k,&s,&jo1,b1);
249  GetBranchStep((unsigned int)k,&s,&jo2,b2);
250  if (jo1==jo2)
251  k++;
252  else
253  equal=FALSE;
254  }
255 
256  CreateBranch(b);
257 
258  for(i=k;i<n1;i++)
259  {
260  GetBranchStep(i,&s,&jo1,b1);
261  AddStepToBranch(s,jo1,b);
262  }
263 
264  for(i=n2-1;i>=k;i--)
265  {
266  GetBranchStep(i,&s,&jo2,b2);
267  AddStepToBranch(-s,jo2,b);
268  }
269 }
270 
272 {
273  unsigned int i,n;
274  TBranchStep *st;
275  THTransform ti;
276 
278  n=nStepsBranch(b);
279  for(i=0;i<n;i++)
280  {
281  st=*(TBranchStep **)GetVectorElement(i,&(b->steps));
282  if (st->sign>0)
283  HTransformProduct(t,&(tj[GetJointID(st->joint)]),t);
284  else
285  {
286  HTransformInverse(&(tj[GetJointID(st->joint)]),&ti);
287  HTransformProduct(t,&ti,t);
288  }
289  }
290 }
291 
293 {
294  unsigned int i,n;
295  TBranchStep *st;
296 
297  n=nStepsBranch(b);
298  for(i=0;i<n;i++)
299  {
300  st=*(TBranchStep **)GetVectorElement(i,&(b->steps));
301  free(st);
302  }
303  DeleteVector(&(b->steps));
304 }
305 
306 
307 /*********************************************************************/
308 
337 unsigned int Branches2Links(unsigned int from,unsigned int *links,unsigned int *jointTo,
338  boolean *isLeaf,Tbranch *b,Tworld *w);
339 
363 void GenerateKinTree(Tvector *bOut,Tworld *w);
364 
377 
397 void GenerateTransEquationsFromBranch(Tparameters *p,unsigned int eq_type,
398  Tequation *eqs,Tbranch *b,Tworld *w);
399 
425 boolean GenerateEquationsFromBranch(Tparameters *p,unsigned int eq_type,
426  TCuikSystem *cs,Tbranch *b,Tworld *w);
427 
428 
438 
447 void WorldInitDOFInfo(Tworld *w);
448 
456 void WorldDeleteDOFInfo(Tworld *w);
457 
469 void GetLinkTransformsFromDOF(double *dof,THTransform **tl,Tworld *w);
470 
491 void GetLinkTransformsFromSolution(Tparameters *p,double *sol,
492  THTransform **tl,Tworld *w);
493 
514 boolean IsRevoluteBinaryLink(unsigned int nl,double ***p,Tworld *w);
515 
525 void InitWorldKinCS(Tparameters *p,Tworld *w);
526 
537 void InitWorldCS(Tworld *w);
538 
546 void DeleteWorldCS(Tworld *w);
547 
555 void DeleteWorldCD(Tworld *w);
556 
557 /************************************************************************/
558 unsigned int Branches2Links(unsigned int from,unsigned int *links,unsigned int *jointTo,
559  boolean *isLeaf,Tbranch *b,Tworld *w)
560 {
561  boolean *visited; /* visited links */
562  unsigned int c; /* current link in expansion (index in 'links' array) */
563  unsigned int i,j,t,f,nte,o,d;
564  Tjoint *jo;
565  double s;
566  boolean found;
567 
568  NEW(visited,w->nl,boolean);
569  for(i=0;i<w->nl;i++)
570  visited[i]=FALSE;
571 
572  c=0; /* current position in 'links' */
573  links[c]=from; /* we start expanding form node 'from' */
574  visited[from]=TRUE;
575  nte=1; /* number of elements in 'links' */
576  jointTo[from]=NO_UINT; /* node 'from' is the root (no joint lead to it). */
577  isLeaf[from]=TRUE; /* initially 'from' is a leaf link */
578 
579  /* Initialize the branches to the links */
580  for(i=0;i<w->nl;i++)
581  CreateBranch(&(b[i]));
582 
583  while(c<nte)
584  {
585  /* look all the joints that end/start at current links[c] */
586  found=FALSE;
587  for(j=0;((!found)&&(j<w->nj));j++)
588  {
589  jo=GetMechanismJoint(j,&(w->m));
590  t=JointToID(jo);
591  f=JointFromID(jo);
592  /* It is probably a good idea to try to avoid "inverse" joints
593  as much as possible */
594  if ((t==links[c])||(f==links[c]))
595  {
596  if (t==links[c])
597  {o=t;d=f;s=-1.0;}
598  else
599  {o=f;d=t;s=+1.0;}
600 
601  if (!visited[d])
602  {
603  /* Depth-first search produces longer equations */
604  /*found=TRUE;*/ /* comment this to get a Breadth-first search */
605 
606  isLeaf[o]=FALSE; /* Now link 'o' has a child */
607  links[nte++]=d; /* Add link 'd' to the list of nodes to expand */
608  visited[d]=TRUE; /* link 'd' is already reached */
609  jointTo[d]=j;
610  isLeaf[d]=TRUE; /* initially link 'd' is a leaf */
611  CopyBranch(&(b[d]),&(b[o]));
612  AddStepToBranch(s,jo,&(b[d]));
613  }
614  }
615  }
616  c++;
617  }
618 
619  free(visited);
620 
621  return(nte);
622 }
623 
625 {
626  boolean *usedJoint;
627  Tbranch *b,*b1;
628  unsigned int i,n,j,lfID,ltID;
629  Tjoint newJoint,*jo;
630  Tlink *ground;
631 
632  /*First we ensure that the mechanism is fully connected*/
633  ground=GetMechanismLink(0,&(w->m));
634 
635  NEW(w->branch2Link,w->nl,Tbranch);
636  NEW(w->sortedLinks,w->nl,unsigned int);
637  NEW(w->jointTo,w->nl,unsigned int);
638  NEW(w->openLink,w->nl,boolean);
640  if (n!=w->nl)
641  {
642  /* we need to reach all links (link 0 is root!) */
643  for(i=1;i<w->nl;i++)
644  {
645  if (nStepsBranch(&(w->branch2Link[i]))==0)
646  {
647  NewFreeJoint(w->nj,
648  0,ground,
649  i,GetMechanismLink(i,&(w->m)),&newJoint);
650  j=AddJoint2Mechanism(&newJoint,&(w->m));
651  DeleteJoint(&newJoint);
652 
653  /* define the tree info for this link */
654  AddStepToBranch(1.0,GetMechanismJoint(j,&(w->m)),&(w->branch2Link[i]));
655  w->sortedLinks[n++]=i;
656  w->jointTo[i]=j;
657  w->openLink[0]=FALSE; /* just in case :) */
658  w->openLink[i]=TRUE;
659 
660 
661  /*The number of joints is larger now*/
662  w->nj++;
663  }
664  }
665  }
666 
667  NEW(usedJoint,w->nj,boolean);
668  for(i=0;i<w->nj;i++)
669  usedJoint[i]=FALSE;
670  for(i=1;i<w->nl;i++) /* no joint takes to link 0! */
671  usedJoint[w->jointTo[i]]=TRUE;
672 
673  /* Initialize the vector with the pointers to the loop (or not loop) equations. */
674  InitVector(sizeof(void *),CopyVoidPtr,DeleteVoidPtr,w->nl,bOut);
675 
676  /* Here, the non-used joints form a basis of cycles */
677  for(i=0;i<w->nj;i++)
678  {
679  if (!usedJoint[i])
680  {
681  jo=GetMechanismJoint(i,&(w->m));
682  lfID=JointFromID(jo);
683  ltID=JointToID(jo);
684 
685  /* Add the non-used joint to one of the branches to close the loop */
686  NEW(b1,1,Tbranch);
687  CopyBranch(b1,&(w->branch2Link[lfID]));
688  AddStepToBranch(1,jo,b1);
689 
690  NEW(b,1,Tbranch);
691  MergeBranches(b1,&(w->branch2Link[ltID]),b);
692  NewVectorElement(&b,bOut);
693 
694  DeleteBranch(b1);
695  free(b1);
696 
697  /* Just in case, the two links are not open any more */
698  w->openLink[lfID]=FALSE;
699  w->openLink[ltID]=FALSE;
700  }
701  }
702 
703  /* Open links define open branches */
704  for(i=0;i<w->nl;i++)
705  {
706  if (w->openLink[i])
707  {
708  NEW(b,1,Tbranch);
709  CopyBranch(b,&(w->branch2Link[i]));
710  NewVectorElement(&b,bOut);
711  }
712  }
713 
714  /* Release memory */
715  free(usedJoint);
716 }
717 
719 {
720  unsigned int i,n;
721  double s;
722  Tjoint *jo;
723  TTransSeq ts;
724 
725  /* Id = Id */
726  InitMEquation(meq);
727 
728  /* Now add the variable terms, if any */
729  n=nStepsBranch(b);
730  for(i=0;i<n;i++)
731  {
732  GetBranchStep(i,&s,&jo,b);
733  GetJointTransSeq(p,&(w->kinCS),&ts,jo);
734  AddTransSeq2MEquation(s,&ts,meq);
735  DeleteTransSeq(&ts);
736  }
737  SimplifyMEquation(meq);
738 }
739 
740 void GenerateTransEquationsFromBranch(Tparameters *p,unsigned int eq_type,
741  Tequation *eq,Tbranch *b,Tworld *w)
742 {
743  unsigned int r;
744 
745  r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
746 
747  if (r==REP_JOINTS)
748  Error("GenerateTransEquationsFromBranch should not be used in JOINT-based representations");
749  else
750  {
751  /*A Loop is a closed branch: a path from one link to itself
752  going through other links*/
753  unsigned int n,i;
754  double s;
755  Tjoint *jo;
756 
757  for(i=0;i<3;i++)
758  {
759  InitEquation(&(eq[i]));
760  SetEquationType(eq_type,&(eq[i]));
761  SetEquationCmp(EQU,&(eq[i]));
762  }
763 
764  n=nStepsBranch(b);
765  for(i=0;i<n;i++)
766  {
767  /*Get current joint destination link (by treating the
768  destitation we deal with all links since the first link
769  is the ground link and does not require to be
770  processed)*/
771  GetBranchStep(i,&s,&jo,b);
772 
773  GenerateJointEquationsInBranch(p,s,&(w->kinCS),eq,jo);
774  }
775  }
776 }
777 
778 boolean GenerateEquationsFromBranch(Tparameters *p,unsigned int eq_type,
779  TCuikSystem *cs,Tbranch *b,Tworld *w)
780 {
781  unsigned int origin,destination,i;
782  boolean closedBranch;
783  Tequation eq[3];
784  Tmonomial f;
785  char *vname,*l1name;
786  Tlink *l1;
787  Tvariable var;
788  Tinterval rangeInf;
789  unsigned int vID;
790  unsigned int r;
791 
792  if (nStepsBranch(b)==0)
793  {
794  /* An empty branch is a branch from ground link to ground link and it
795  ony appears when trying to give coordinates to the ground link ??*/
796  origin=0;
797  destination=0;
798  closedBranch=FALSE;
799  }
800  else
801  {
802  origin=GetBranchOrigin(b);
803  destination=GetBranchDestination(b);
804  closedBranch=(origin==destination);
805  }
806 
807  r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
808 
809  if (r==REP_JOINTS)
810  {
811  if (closedBranch)
812  {
813  TMequation meq;
814 
815  GenerateMEquationFromBranch(p,b,&meq,w);
816  AddMatrixEquation2CS(p,&meq,cs);
817  DeleteMEquation(&meq);
818  }
819  }
820  else
821  {
822  GenerateTransEquationsFromBranch(p,eq_type,eq,b,w);
823 
824  InitMonomial(&f);
825  NewInterval(-w->maxCoord,w->maxCoord,&rangeInf);
826  for(i=0;i<3;i++)
827  {
828  if (!closedBranch)
829  {
830  l1=GetMechanismLink(destination,&(w->m));
831  l1name=GetLinkName(l1);
832 
833  NEW(vname,strlen(l1name)+100,char);
834  LINK_TRANS(vname,l1name,i);
835 
836  NewVariable(SYSTEM_VAR,vname,&var);
837  free(vname);
838  SetVariableInterval(&rangeInf,&var);
839 
840  vID=AddVariable2CS(&var,cs);
841 
842  DeleteVariable(&var);
843 
844  AddCt2Monomial(-1.0,&f);
845  AddVariable2Monomial(NFUN,vID,1,&f);
846  AddMonomial(&f,&(eq[i]));
847  ResetMonomial(&f);
848 
849  /* For open loops, the equations only give the coordinates of the
850  end of the loop -> they are coordinating equations.*/
851  SetEquationType(COORD_EQ,&(eq[i]));
852  }
853 
854  AddEquation2CS(p,&(eq[i]),cs);
855  DeleteEquation(&(eq[i]));
856  }
857  DeleteInterval(&rangeInf);
858  DeleteMonomial(&f);
859 
860  }
861  return(!closedBranch);
862 }
863 
864 
865 boolean IsRevoluteBinaryLink(unsigned int nl,double ***p,Tworld *w)
866 {
867  unsigned int i,j,nr,f,t,nnr;
868  Tjoint *jo;
869 
870  i=0;
871  nr=0;
872  nnr=0;
873  while ((i<w->nj)&&(nnr==0)&&(nr<3))
874  {
875  jo=GetMechanismJoint(i,&(w->m));
876  f=JointFromID(jo);
877  t=JointToID(jo);
878 
879  if ((f==nl)||(t==nl))
880  {
881  if (GetJointType(jo)==REV_JOINT)
882  {
883  if (nr<2)
884  {
885  for(j=0;j<2;j++)
886  GetJointPoint(((f==nl)?0:1),j,p[nr][j],jo);
887  }
888  nr++; /*a new revolute joint on the link*/
889  }
890  else
891  nnr++; /*a new non-revolute joint on the link*/
892  }
893 
894  i++;
895  }
896 
897  return((nnr==0)&&(nr==2));
898 }
899 
901 {
902  unsigned int i,j;
903  Tvector branches;
904  unsigned int nBranches;
905  Tbranch *b;
906  Tjoint *jo;
907  double ***points;
908  unsigned int r;
909 
910  if (w->nl==0)
911  Error("Empty mechanism");
912 
913  if (w->nl==1)
914  Error("A world with just one link makes no sense");
915  else
916  {
917  r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
918 
919  /*In some cases it is advisable to re-define the reference frame for the
920  links to get simpler equations*/
921  if ((r!=REP_JOINTS)&&(AllRevolute(&(w->m))))
922  {
923  NEW(points,2,double **);
924  for(i=0;i<2;i++)
925  {
926  NEW(points[i],2,double *);
927  for(j=0;j<2;j++)
928  NEW(points[i][j],3,double);
929  }
930 
931  for(i=0;i<w->nl;i++)
932  {
933  if (IsRevoluteBinaryLink(i,points,w))
934  ChangeLinkReferenceFrame(r,points[0],points[1],
935  GetMechanismLink(i,&(w->m)));
936  }
937 
938  for(i=0;i<2;i++)
939  {
940  for(j=0;j<2;j++)
941  free(points[i][j]);
942  free(points[i]);
943  }
944  free(points);
945  }
946 
947  /* All links appear in the kinCS: we add the variables and equations
948  defining the rotation matrix for each link*/
949  for(i=0;i<w->nl;i++)
950  GenerateLinkRot(p,i,&(w->kinCS),GetMechanismLink(i,&(w->m)));
951 
952  /* Compute the paths from ground link to all other links (this ensures
953  that links are fully connected adding as many free joints as
954  necessary. */
955  GenerateKinTree(&branches,w);
956  nBranches=VectorSize(&branches);
957 
958  /* All joints appear in the kinCS: we add variables and equations
959  for the joint and joint limits. IMPORTANT: the GenerateKinTree
960  function can geneterate new joints !!! */
961  for(i=0;i<w->nj;i++)
962  {
963  jo=GetMechanismJoint(i,&(w->m));
964  GenerateJointEquations(p,w->maxCoord,&(w->kinCS),jo);
966  }
967 
968  /* Generate the equations for the loops (and branches to terminal links)
969  involved in the mechanism */
970  for(i=0;i<nBranches;i++)
971  {
972  b=*(Tbranch **)GetVectorElement(i,&branches);
974  DeleteBranch(b);
975  free(b);
976  }
977  DeleteVector(&branches);
978  }
979 }
980 
982 {
983  InitCuikSystem(&(w->kinCS));
984 }
985 
987 {
988  unsigned int i;
989 
990  for(i=0;i<w->nl;i++)
991  DeleteBranch(&(w->branch2Link[i]));
992  free(w->branch2Link);
993 
994  DeleteEquations(&(w->refEqs));
995  DeleteJacobian(&(w->refEqsJ));
996 
997  free(w->openLink);
998  free(w->sortedLinks);
999  free(w->jointTo);
1000 
1001  DeleteCuikSystem(&(w->kinCS));
1002 
1003  free(w->systemVars);
1004 
1005  WorldDeleteDOFInfo(w);
1006 }
1007 
1008 
1009 /*********************************************************************/
1010 /*********************************************************************/
1011 
1012 
1013 void InitWorldCD(Tparameters *pr,unsigned int mt,Tworld *w)
1014 {
1015  if (w->stage!=WORLD_DEFINED)
1016  Error("Complete the workd definition before using the InitWorldCD function");
1017 
1018  if (w->wcd!=NULL)
1019  {
1020  DeleteCD(w->wcd);
1021  free(w->wcd);
1022  w->wcd=NULL;
1023  }
1024 
1025  /* The collision detection engine is only initialized if there is any
1026  collision to detect. */
1027  if (AnyCollision(w))
1028  {
1029  unsigned int e,i;
1030 
1031  e=(unsigned int)(GetParameter(CT_CD_ENGINE,pr));
1032 
1033  if (mt==0)
1034  Error("Wrong maximum number of threads in InitWorldCD");
1035 
1036  w->nwcd=mt;
1037  NEW(w->wcd,w->nwcd,TworldCD);
1038 
1039  /* when mt>0 is because OpenMP is available and will be used -> initialize in parallel */
1040  #pragma omp parallel for private(i) if (mt>1)
1041  for(i=0;i<mt;i++)
1042  InitCD(e,(mt>1),&(w->m),&(w->e),w->checkCollisionsLL,w->checkCollisionsLO,&(w->wcd[i]));
1043  }
1044 }
1045 
1047 {
1048  return(w->wcd!=NULL);
1049 }
1050 
1052 {
1053  if (w->wcd==NULL)
1054  return(FALSE);
1055  else
1056  /* we query the first collision detecion structure, even if we have many. */
1057  return(GetCDEngine(w->wcd)==C_FCL);
1058 }
1059 
1060 boolean MoveAndCheckCDFromTransforms(boolean all,unsigned int tID,
1061  THTransform *tl,THTransform *tlPrev,Tworld *w)
1062 {
1063  if (w->wcd!=NULL)
1064  {
1065  /* If sequential force it, even if tID is different from 0. */
1066  if (w->nwcd==0)
1067  return(CheckCollision(all,tl,tlPrev,&(w->wcd[0])));
1068  else
1069  return(CheckCollision(all,tl,tlPrev,&(w->wcd[tID])));
1070  }
1071  else
1072  return(FALSE); /* no collison to detect */
1073 }
1074 
1075 
1076 boolean MoveAndCheckCD(Tparameters *p,boolean all,unsigned int tID,
1077  double *sol,double *solPrev,Tworld *w)
1078 {
1079  if (w->wcd!=NULL)
1080  {
1081  THTransform *tl,*tlPrev=NULL;
1082  boolean c;
1083 
1084  GetLinkTransformsFromSolution(p,sol,&tl,w);
1085  if ((solPrev!=NULL)&&(GetCDEngine(w->wcd)==C_FCL))
1086  GetLinkTransformsFromSolution(p,sol,&tlPrev,w);
1087 
1088  c=MoveAndCheckCDFromTransforms(all,tID,tl,tlPrev,w);
1089 
1090  DeleteLinkTransforms(tl,w);
1091  if (tlPrev!=NULL)
1092  DeleteLinkTransforms(tlPrev,w);
1093 
1094  return(c);
1095  }
1096  else
1097  return(FALSE); /* no collison to detect */
1098 }
1099 
1101 {
1102  if (w->wcd!=NULL)
1103  {
1104  unsigned int i;
1105 
1106  for(i=0;i<w->nwcd;i++)
1107  DeleteCD(&(w->wcd[i]));
1108 
1109  free(w->wcd);
1110  w->wcd=NULL;
1111  }
1112 }
1113 
1114 
1115 /*********************************************************************/
1116 /*********************************************************************/
1117 
1119 {
1120  unsigned int i,l,parent,jID;
1121  THTransform *tj,t;
1122  Tjoint *j;
1123 
1124  NEW(tj,w->nj,THTransform);
1125  for(i=0;i<w->nj;i++)
1126  {
1127  j=GetMechanismJoint(i,&(w->m));
1128  GetJointTransform(&(dof[w->joint2dof[i]]),&(tj[i]),j);
1129  }
1130 
1131  NEW(*tl,w->nl,THTransform);
1132 #if (0)
1133  /* The old, slower way to obtain the transform for each link. */
1134  for(i=0;i<w->nl;i++)
1135  GetTransformFromBranch(tj,&((*tl)[i]),&(w->branch2Link[i]));
1136 #else
1137  /* The new way takes advantage of the kinematic tree structure
1138  to reduce the number of matrix products (does not repeate
1139  compuations). */
1140  HTransformIdentity(&((*tl)[0]));
1141  for(i=1;i<w->nl;i++)
1142  {
1143  l=w->sortedLinks[i]; /* next link whose pose can be easily computed */
1144  jID=w->jointTo[l]; /* joint to use to compute such pose */
1145  j=GetMechanismJoint(jID,&(w->m));
1146  if (l==JointToID(j))
1147  {
1148  parent=JointFromID(j);
1149  HTransformProduct(&((*tl)[parent]),&(tj[jID]),&((*tl)[l]));
1150  }
1151  else
1152  {
1153  parent=JointToID(j);
1154  HTransformInverse(&(tj[jID]),&t);
1155  HTransformProduct(&((*tl)[parent]),&t,&((*tl)[l]));
1156  }
1157  }
1158 #endif
1159 
1160  for(i=0;i<w->nj;i++)
1161  HTransformDelete(&(tj[i]));
1162  free(tj);
1163 }
1164 
1165 void GetLinkTransformsFromSolutionPoint(Tparameters *p,boolean simp,double *sol,
1166  THTransform **tl,Tworld *w)
1167 {
1168  unsigned int r;
1169 
1170  if (w->stage!=WORLD_DEFINED)
1171  Error("The equations and variables are not yet defined");
1172 
1173  r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
1174  if (r==REP_JOINTS)
1175  {
1176  /* In the JOINT-based representation all variables are system variables */
1177  /* and the simplified point is the same as the original */
1178  GetLinkTransformsFromDOF(sol,tl,w);
1179  }
1180  else
1181  {
1182  double *v;
1183 
1184  if (simp)
1185  RegenerateOriginalPoint(p,sol,&v,&(w->kinCS));
1186  else
1187  {
1188  unsigned int n,i,k;
1189 
1190  /* The input only has values for the input variables. Get the values for the
1191  non-system variables first. */
1192 
1193  n=GetCSNumVariables(&(w->kinCS));
1194  k=0;
1195  NEW(v,n,double);
1196  for(i=0;i<n;i++)
1197  {
1198  if (w->systemVars[i])
1199  {
1200  v[i]=sol[k];
1201  k++;
1202  }
1203  else
1204  v[i]=0.0; /*Non system variables are set to 0. See below! */
1205  }
1206  }
1207  RegenerateMechanismSolution(p,&(w->kinCS),v,&(w->m));
1208 
1210 
1211  free(v);
1212  }
1213 }
1214 
1216 {
1217  unsigned int rep,n;
1218 
1219  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
1220 
1221  n=GetCSNumSystemVariables(&(w->kinCS));
1222  NEW(*sol,n,double);
1223 
1224  if (rep==REP_JOINTS)
1225  GetMechanismDOFsFromTransforms(p,tl,*sol,&(w->m));
1226  else
1227  {
1228  unsigned int i,nv,k;
1229  double *dof,*sample;
1230  Tbox b;
1231 
1232  /* Get the dof from the transforms */
1233  NEW(dof,w->ndof,double);
1234  GetMechanismDOFsFromTransforms(p,tl,dof,&(w->m));
1235 
1236  /* Get the sample from the dof */
1237  nv=WorldDOF2Sol(p,dof,&sample,&b,w);
1238 
1239  /* and keep only the system variables */
1240  k=0;
1241  for(i=0;i<nv;i++)
1242  {
1243  if (w->systemVars[i])
1244  {
1245  (*sol)[k]=sample[i];
1246  k++;
1247  }
1248  }
1249 
1250  /* Release used memory */
1251  DeleteBox(&b);
1252  free(sample);
1253  free(dof);
1254  }
1255 
1256  return(GetCSNumSystemVariables(&(w->kinCS)));
1257 }
1258 
1259 
1261  THTransform **tl,Tworld *w)
1262 {
1263  unsigned int rep;
1264 
1265  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
1266 
1267  if (rep==REP_JOINTS)
1268  GetLinkTransformsFromDOF(sol,tl,w);
1269  else
1270  {
1271  unsigned int i;
1272  Tlink *l;
1273  double *r;
1274 
1275  NEW(*tl,w->nl,THTransform);
1276 
1277  NEW(r,3*w->nl,double);
1278  EvaluateEqualityEquations(FALSE,sol,r,&(w->refEqs));
1279 
1280  for(i=0;i<w->nl;i++)
1281  {
1282  l=GetMechanismLink(i,&(w->m));
1283  GetTransform2Link(p,&(w->kinCS),sol,IsGroundLink(i),
1284  &(r[3*i]),&((*tl)[i]),l);
1285  }
1286  free(r);
1287  }
1288 }
1289 
1291 {
1292  unsigned int i;
1293 
1294  for(i=0;i<w->nl;i++)
1295  HTransformDelete(&(tl[i]));
1296 
1297  free(tl);
1298 }
1299 
1300 
1301 
1302 /*********************************************************************/
1303 /*********************************************************************/
1304 /*********************************************************************/
1305 /*********************************************************************/
1306 /*********************************************************************/
1307 
1309 {
1310  InitEnvironment(&(w->e));
1311  InitMechanism(&(w->m));
1312 
1313  w->nl=0;
1314  w->nj=0;
1315  w->no=0;
1316  w->nb=0;
1317  w->np=0;
1318  w->nvars=0;
1319  w->nsvars=0;
1320  w->systemVars=NULL;
1321  w->checkCollisionsLL=NULL;
1322  w->checkCollisionsLO=NULL;
1323 
1324  w->endEffector=NO_UINT;
1325 
1326  w->branch2Link=NULL;
1327 
1329 
1330  w->wcd=NULL;
1331 }
1332 
1333 unsigned int AddLink2World(Tlink *l,boolean endEffector,Tworld *w)
1334 {
1335  unsigned int j,k;
1336 
1337  if (w->stage!=WORLD_IN_DEFINITION)
1338  Error("Links can only be added during the world definition");
1339 
1340  if (endEffector)
1341  w->endEffector=w->nl;
1342 
1343  w->nl++;
1344  k=LinkNBodies(l);
1345  w->nb+=k;
1346  w->np+=k;
1347 
1348  /* define a new row and column in he LL table */
1349 
1350  /* expand the previous rows, if any */
1351  for(j=0;j<w->nl-1;j++)
1352  {
1353  MEM_EXPAND(w->checkCollisionsLL[j],w->nl,boolean); /* enlarge */
1354  w->checkCollisionsLL[j][w->nl-1]=FALSE;
1355  }
1356 
1357  /* create a new row */
1358  if (w->checkCollisionsLL==NULL)
1359  { NEW(w->checkCollisionsLL,w->nl,boolean*); } /* create */
1360  else
1361  { MEM_EXPAND(w->checkCollisionsLL,w->nl,boolean*); } /* enlarge */
1362 
1363  /* allocate and initialize the new row */
1364  NEW(w->checkCollisionsLL[w->nl-1],w->nl,boolean);
1365  for(j=0;j<w->nl;j++)
1366  w->checkCollisionsLL[w->nl-1][j]=FALSE;
1367 
1368  if (w->no>0)
1369  {
1370  /* define a new row in he LO table */
1371  if (w->checkCollisionsLO==NULL)
1372  { NEW(w->checkCollisionsLO,w->nl,boolean*); } /* create */
1373  else
1374  { MEM_EXPAND(w->checkCollisionsLO,w->nl,boolean*); } /* enlarge */
1375  NEW(w->checkCollisionsLO[w->nl-1],w->no,boolean);
1376  for(j=0;j<w->no;j++)
1377  w->checkCollisionsLO[w->nl-1][j]=FALSE;
1378  }
1379 
1380  return(AddLink2Mechanism(l,&(w->m)));
1381 }
1382 
1383 unsigned int AddJoint2World(Tjoint *j,Tworld *w)
1384 {
1385  if (w->stage!=WORLD_IN_DEFINITION)
1386  Error("Joints can only be added during the world definition");
1387 
1388  w->nj++;
1389 
1390  return(AddJoint2Mechanism(j,&(w->m)));
1391 }
1392 
1393 void AddObstacle2World(char *name,Tpolyhedron *o,Tworld *w)
1394 {
1395  unsigned int j;
1396 
1397  if (w->stage!=WORLD_IN_DEFINITION)
1398  Error("Obstacles can only be added during the world definition");
1399 
1400  w->no++;
1401  w->np++;
1402 
1403  if (w->nl>0)
1404  {
1405  /* the first obstacle, we create the LO table */
1406  if (w->no==1)
1407  NEW(w->checkCollisionsLO,w->nl,boolean*);
1408 
1409  /* Add a column to the LO table */
1410  for(j=0;j<w->nl;j++)
1411  {
1412  if (w->no==1)
1413  { NEW(w->checkCollisionsLO[j],w->no,boolean); /*create*/}
1414  else
1415  { MEM_EXPAND(w->checkCollisionsLO[j],w->no,boolean); /* enlarge */}
1416  w->checkCollisionsLO[j][w->no-1]=FALSE;
1417  }
1418 
1419  /* initialize the new row */
1420  for(j=0;j<w->no;j++)
1421  w->checkCollisionsLO[w->nl-1][j]=FALSE;
1422  }
1423 
1424  AddShape2Environment(name,o,&(w->e));
1425 }
1426 
1427 unsigned int GetWorldMobility(Tworld *w)
1428 {
1429  return(GetMechanismMobility(&(w->m)));
1430 }
1431 
1433 {
1434  return(IsMechanismAllSpheres(&(w->m)));
1435 }
1436 
1437 unsigned int GetWorldLinkID(char *linkName,Tworld *w)
1438 {
1439  return(GetLinkID(linkName,&(w->m)));
1440 }
1441 
1442 unsigned int GetWorldObstacleID(char *obsName,Tworld *w)
1443 {
1444  return(GetObstacleID(obsName,&(w->e)));
1445 }
1446 
1447 Tlink *GetWorldLink(unsigned int linkID,Tworld *w)
1448 {
1449  return(GetMechanismLink(linkID,&(w->m)));
1450 }
1451 
1452 Tjoint *GetWorldJoint(unsigned int jointID,Tworld *w)
1453 {
1454  return(GetMechanismJoint(jointID,&(w->m)));
1455 }
1456 
1457 unsigned int GetWorldNLinks(Tworld *w)
1458 {
1459  return(w->nl);
1460 }
1461 
1462 unsigned int GetWorldNJoints(Tworld *w)
1463 {
1464  return(w->nj);
1465 }
1466 
1467 unsigned int GetWorldNObstacles(Tworld *w)
1468 {
1469  return(w->no);
1470 }
1471 
1473 {
1474  return(w->nb);
1475 }
1476 
1478 {
1479  return(w->np);
1480 }
1481 
1483 {
1484  unsigned int i;
1485 
1486  if (w->checkCollisionsLL!=NULL)
1487  {
1488  for(i=0;i<w->nl;i++)
1489  free(w->checkCollisionsLL[i]);
1490  free(w->checkCollisionsLL);
1491  }
1492 
1493  if (w->checkCollisionsLO!=NULL)
1494  {
1495  for(i=0;i<w->nl;i++)
1496  free(w->checkCollisionsLO[i]);
1497  free(w->checkCollisionsLO);
1498  }
1499 }
1500 
1502 {
1503  unsigned int i,k,l,n,p;
1504  Tjoint *j;
1505 
1506  if (w->stage!=WORLD_DEFINED)
1507  Error("The DOF info is to be defined at the end of the world definition");
1508 
1509  w->ndof=0;
1510  for(i=0;i<w->nj;i++)
1511  {
1512  j=GetMechanismJoint(i,&(w->m));
1513  w->ndof+=GetJointDOF(j);
1514  }
1515 
1516  NEW(w->joint2dof,w->nj,unsigned int);
1517  NEW(w->dof2joint,w->ndof,unsigned int);
1518  NEW(w->dof2range,w->ndof,unsigned int);
1519 
1520  n=0;
1521  for(i=0;i<w->nj;i++)
1522  {
1523  j=GetMechanismJoint(i,&(w->m));
1524  p=CoupledWith(j);
1525  if (p==NO_UINT)
1526  {
1527  /* Note that if Num_DOF==0 (FIX_JOINT) nothing is done
1528  and the dof2joint and joint2dof mappings are not
1529  actually used. */
1530 
1531  w->joint2dof[i]=n;
1532 
1533  k=GetJointDOF(j);
1534  for(l=0;l<k;l++)
1535  {
1536  w->dof2joint[n]=i;
1537  w->dof2range[n]=l;
1538  n++;
1539  }
1540  }
1541  else
1542  {
1543  if (p>=i)
1544  Error("Joints can only be coupled with preceeding joints");
1545  /* We will re-use the values from the original joint. */
1546  w->joint2dof[i]=w->joint2dof[p];
1547  }
1548  }
1549 }
1550 
1551 
1553 {
1554  free(w->joint2dof);
1555  free(w->dof2joint);
1556  free(w->dof2range);
1557 }
1558 
1559 unsigned int GetWorldNDOF(Tworld *w)
1560 {
1561  return(w->ndof);
1562 }
1563 
1564 void GetWorldRangeDOF(unsigned int ndof,Tinterval *r,Tworld *w)
1565 {
1566  Tjoint *j;
1567 
1568  if (ndof>=w->ndof)
1569  Error("DOF out of range in GetWorldRangeDOF");
1570 
1571  j=GetMechanismJoint(w->dof2joint[ndof],&(w->m));
1572  GetJointRangeN(w->dof2range[ndof],w->maxCoord,r,j);
1573 }
1574 
1575 void GetWorldJointLabel(unsigned int ndof,char **string,Tworld *w)
1576 {
1577  if (w->dof2joint==NULL)
1578  Error("Uninitialized dof info in GetWorkdJointLabel");
1579  if (w->dof2range[ndof]==0)
1580  GetJointName(string,GetMechanismJoint(w->dof2joint[ndof],&(w->m)));
1581  else
1582  *string=NULL;
1583 }
1584 
1585 void GetWorldDOFLabel(unsigned int ndof,char **string,Tworld *w)
1586 {
1587  Tjoint *j;
1588 
1589  if (w->dof2joint==NULL)
1590  Error("Uninitialized dof info in GetWorkdDOFLabel");
1591 
1592  j=GetMechanismJoint(w->dof2joint[ndof],&(w->m));
1593  if (GetJointDOF(j)==1)
1594  GetJointName(string,j);
1595  else
1596  {
1597  char *jointName;
1598 
1599  GetJointName(&jointName,GetMechanismJoint(w->dof2joint[ndof],&(w->m)));
1600  NEW(*string,strlen(jointName)+10,char);
1601 
1602  sprintf(*string,"%s %u",jointName,w->dof2range[ndof]+1);
1603  free(jointName);
1604  }
1605 }
1606 
1607 inline boolean IsWorldPolynomial(Tworld *w)
1608 {
1609  if (w->stage!=WORLD_DEFINED)
1610  Error("The equations and variables are not yet defined");
1611 
1612  return(IsCSPolynomial(&(w->kinCS)));
1613 }
1614 
1615 void CheckAllCollisions(unsigned int fl,unsigned int fo,Tworld *w)
1616 {
1617  unsigned int i,j;
1618 
1619  if (w->stage!=WORLD_IN_DEFINITION)
1620  Error("The geometry information must be added while defining the world");
1621 
1622  CheckSelfCollisions(fl,w);
1623 
1624  if (w->no>fo)
1625  {
1626  /* All link-obstacles are checked for collision except
1627  the ground link with any obstacle */
1628  for(i=fl;i<w->nl;i++)
1629  {
1630  for(j=fo;j<w->no;j++)
1631  w->checkCollisionsLO[i][j]=((!IsGroundLink(i))&&
1632  (GetObstacleShapeStatus(j,&(w->e))!=DECOR_SHAPE));
1633  }
1634  }
1635 }
1636 
1637 void NoCheckAllCollisions(unsigned int fl,unsigned int fo,Tworld *w)
1638 {
1639  unsigned int i,j;
1640 
1641  if (w->stage!=WORLD_IN_DEFINITION)
1642  Error("The geometry information must be added while defining the world");
1643 
1644  NoCheckSelfCollisions(fl,w);
1645 
1646  if (w->no>fo)
1647  {
1648  for(i=fl;i<w->nl;i++)
1649  {
1650  for(j=fo;j<w->no;j++)
1651  w->checkCollisionsLO[i][j]=FALSE;
1652  }
1653  }
1654 }
1655 
1656 void CheckSelfCollisions(unsigned int fl,Tworld *w)
1657 {
1658  unsigned int i,j;
1659 
1660  if (w->stage!=WORLD_IN_DEFINITION)
1661  Error("The geometry information must be added while defining the world");
1662 
1663  /* Collisions of a link with itself are not checked */
1664  for(i=fl;i<w->nl;i++)
1665  {
1666  for(j=fl;j<w->nl;j++)
1667  w->checkCollisionsLL[i][j]=(i!=j);
1668  }
1669 }
1670 
1671 void NoCheckSelfCollisions(unsigned int fl,Tworld *w)
1672 {
1673  unsigned int i,j;
1674 
1675  if (w->stage!=WORLD_IN_DEFINITION)
1676  Error("The geometry information must be added while defining the world");
1677 
1678  for(i=fl;i<w->nl;i++)
1679  {
1680  for(j=fl;j<w->nl;j++)
1681  w->checkCollisionsLL[i][j]=FALSE;
1682  }
1683 }
1684 
1685 void CheckLinkLinkCollision(unsigned int a,unsigned int b,Tworld *w)
1686 {
1687  if (w->stage!=WORLD_IN_DEFINITION)
1688  Error("The geometry information must be added while defining the world");
1689 
1690  if ((a<w->nl)&&(b<w->nl)&&(a!=b))
1691  w->checkCollisionsLL[a][b]=w->checkCollisionsLL[b][a]=TRUE;
1692 }
1693 
1694 void NoCheckLinkLinkCollision(unsigned int a,unsigned int b,Tworld *w)
1695 {
1696  if (w->stage!=WORLD_IN_DEFINITION)
1697  Error("The geometry information must be added while defining the world");
1698 
1699  if ((a<w->nl)&&(b<w->nl))
1700  w->checkCollisionsLL[a][b]=w->checkCollisionsLL[b][a]=FALSE;
1701 }
1702 
1703 void CheckLinkObstacleCollision(unsigned int a,unsigned int b,Tworld *w)
1704 {
1705  if (w->stage!=WORLD_IN_DEFINITION)
1706  Error("The geometry information must be added while defining the world");
1707 
1708  if ((a<w->nl)&&(!IsGroundLink(a))&&(b<w->no))
1709  w->checkCollisionsLO[a][b]=TRUE;
1710 }
1711 
1712 void NoCheckLinkObstacleCollision(unsigned int a,unsigned int b,Tworld *w)
1713 {
1714  if (w->stage!=WORLD_IN_DEFINITION)
1715  Error("The geometry information must be added while defining the world");
1716 
1717  if ((a<w->nl)&&(b<w->no))
1718  w->checkCollisionsLO[a][b]=FALSE;
1719 }
1720 
1722 {
1723  unsigned int i;
1724  boolean any;
1725 
1726  any=FALSE;
1727  for(i=0;((i<w->nl)&&(!any));i++)
1729 
1730  return(any);
1731 }
1732 
1733 void PrintCollisions(FILE *f,Tworld *w)
1734 {
1735  if (AnyCollision(w))
1736  {
1737  unsigned int i,j;
1738  char *l;
1739 
1740  fprintf(f,"[COLLISIONS]\n\n");
1741  fprintf(f," do not check: all\n");
1742  for(i=0;i<w->nl;i++)
1743  {
1744  l=GetLinkName(GetMechanismLink(i,&(w->m)));
1745  for(j=i+1;j<w->nl;j++)
1746  {
1747  if ((w->checkCollisionsLL[i][j])||(w->checkCollisionsLL[j][i]))
1748  fprintf(f," check: %s,%s\n",l,GetLinkName(GetMechanismLink(j,&(w->m))));
1749  }
1750  }
1751  for(i=0;i<w->nl;i++)
1752  {
1753  l=GetLinkName(GetMechanismLink(i,&(w->m)));
1754  for(j=0;j<w->no;j++)
1755  if (w->checkCollisionsLO[i][j])
1756  fprintf(f," check: %s,%s\n",l,GetObstacleName(j,&(w->e)));
1757  }
1758  fprintf(f,"\n");
1759  }
1760 }
1761 
1762 boolean NewtonInWorld(Tparameters *p,double *v,Tbox *b_sol,Tworld *w)
1763 {
1764  double *vA;
1765  Tbox b_solA;
1766  boolean converged;
1767  unsigned int i,k,nv,nvs;
1768  boolean *systemVarsKin;
1769 
1770  if (w->stage!=WORLD_DEFINED)
1771  Error("The equations and variables are not yet defined");
1772 
1773  nv=GetCSSystemVars(&systemVarsKin,&(w->kinCS));
1774  NEW(vA,nv,double);
1775 
1776  converged=CuikNewton(p,vA,&b_solA,&(w->kinCS));
1777 
1778  nvs=0;
1779  for(i=0;i<nv;i++)
1780  {
1781  if (systemVarsKin[i])
1782  nvs++;
1783  }
1784 
1785  InitBox(nvs,NULL,b_sol);
1786 
1787  k=0;
1788  for(i=0;i<nv;i++)
1789  {
1790  if (systemVarsKin[i])
1791  {
1792  v[k]=vA[i];
1793  SetBoxInterval(k,GetBoxInterval(i,&b_solA),b_sol);
1794  k++;
1795  }
1796  }
1797  DeleteBox(&b_solA);
1798  free(vA);
1799  free(systemVarsKin);
1800 
1801  #if (_DEBUG>2)
1802  printf("Newton generated box:");
1803  PrintBox(stdout,b_sol);
1804  fflush(stdout);
1805  #endif
1806 
1807  return(converged);
1808 }
1809 
1810 inline unsigned int GetWorldSystemVars(boolean **sv,Tworld *w)
1811 {
1812  if (w->stage!=WORLD_DEFINED)
1813  Error("The equations and variables are not yet defined");
1814 
1815  return(GetCSSystemVars(sv,&(w->kinCS)));
1816 }
1817 
1818 inline unsigned int GetWorldVarTopology(unsigned int vID,Tworld *w)
1819 {
1820  return(GetCSVarTopology(vID,&(w->kinCS)));
1821 }
1822 
1823 unsigned int GetWorldSimpVariableMask(Tparameters *p,boolean **sv,Tworld *w)
1824 {
1825  unsigned int i,n;
1826 
1827  if (w->stage!=WORLD_DEFINED)
1828  Error("The equations and variables are not yet defined");
1829 
1830  n=GetCSNumVariables(&(w->kinCS));
1831 
1832  NEW((*sv),n,boolean);
1833  for(i=0;i<n;i++)
1834  (*sv)[i]=FALSE;
1835 
1836  for(i=0;i<w->nl;i++)
1837  GetLinkPoseSimpVars(p,*sv,&(w->kinCS),GetMechanismLink(i,&(w->m)));
1838 
1839  return(n);
1840 }
1841 
1842 inline void GetWorldVarNames(char **vn,Tworld *w)
1843 {
1844  if (w->stage!=WORLD_DEFINED)
1845  Error("The equations and variables are not yet defined");
1846 
1847  return(GetCSVariableNames(vn,&(w->kinCS)));
1848 }
1849 
1851 {
1852  unsigned int i,rep;
1853  Tvariables vs;
1854 
1855  if (w->stage!=WORLD_IN_DEFINITION)
1856  Error("The equations are alrady defined");
1857 
1858  w->stage=WORLD_DEFINED;
1859 
1860  InitWorldCS(w);
1861 
1862  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
1863 
1866 
1867  /*Generate the kinematic equations: this includes link reference variables
1868  and equations, joint variables and equations, joint limit variables and
1869  equations and loop equations. Note that all links and joints are used in the kinCS
1870  and thus, after generating it, we can assume that the variables associated
1871  to links and joints are all already defined.
1872  This already initializes the branch2link, the sortedLinks and the jointTo
1873  arrays.
1874  */
1875  InitWorldKinCS(p,w);
1876 
1877 
1878  /* We generate the equations defining the translation
1879  from the ground link to all other links. These equations are the
1880  same as those generated by \ref GenerateEquationsFromBranch but for
1881  open branches we do not add the variables defining the X-Y-Z
1882  of the link reference.
1883  */
1884 
1885  InitEquations(&(w->refEqs));
1886  if (rep==REP_JOINTS)
1887  {
1888  TMequation ref;
1889 
1890  for(i=0;i<w->nl;i++)
1891  {
1892  GenerateMEquationFromBranch(p,&(w->branch2Link[i]),&ref,w);
1893  AddMatrixEquation(&ref,&(w->refEqs));
1894  DeleteMEquation(&ref);
1895  }
1896  }
1897  else
1898  {
1899  Tequation ref[3];
1900  unsigned int j;
1901 
1902  for(i=0;i<w->nl;i++)
1903  {
1905  for(j=0;j<3;j++)
1906  {
1907  AddEquationNoSimp(&(ref[j]),&(w->refEqs));
1908  DeleteEquation(&(ref[j]));
1909  }
1910  }
1911  }
1912  GetCSVariables(&vs,&(w->kinCS));
1913  InitJacobian(&vs,&(w->refEqs),&(w->refEqsJ));
1914  DeleteVariables(&vs);
1915 
1916  /*copy of the system variables to use later on*/
1917  w->nvars=GetCSSystemVars(&(w->systemVars),&(w->kinCS));
1918  w->nsvars=0;
1919  for(i=0;i<w->nvars;i++)
1920  {
1921  if (w->systemVars[i])
1922  w->nsvars++;
1923  }
1924 
1925  /* Define the dof information */
1926  WorldInitDOFInfo(w);
1927 }
1928 
1930 {
1931  unsigned int i,rep;
1932 
1933  if (w->stage!=WORLD_DEFINED)
1934  GenerateWorldEquations(p,w); /* Generate kin equations only */
1935 
1936  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
1937  if (rep==REP_JOINTS)
1938  Error("GenerateWorldSingularityEquations is not defined for DOF-based representations");
1939 
1940  CopyCuikSystem(cs,&(w->kinCS));
1941 
1942  for(i=0;i<w->nj;i++)
1944 
1945  if (ln!=NULL)
1946  {
1947  unsigned int lk;
1948 
1949  lk=GetMechanismLinkID(ln,&(w->m));
1950  if (lk!=NO_UINT)
1951  {
1952  Tequation eq;
1953  char *vname;
1954  Tlink *l;
1955  char *lname;
1956  Tinterval rangeInf;
1957  Tvariable var;
1958  Tmonomial f;
1959  unsigned int vID;
1960 
1961  l=GetMechanismLink(lk,&(w->m));
1962  lname=GetLinkName(l);
1963  NEW(vname,strlen(lname)+100,char);
1964  NewInterval(-w->maxCoord,w->maxCoord,&rangeInf);
1965  InitMonomial(&f);
1966 
1967  for(i=0;i<3;i++)
1968  {
1969  CopyEquation(&eq,GetEquation(lk*3+i,&(w->refEqs)));
1970 
1971  LINK_TRANS(vname,lname,i);
1972 
1973  NewVariable(CARTESIAN_VAR,vname,&var);
1974  SetVariableInterval(&rangeInf,&var);
1975  vID=AddVariable2CS(&var,cs);
1976  DeleteVariable(&var);
1977 
1978  AddCt2Monomial(-1.0,&f);
1979  AddVariable2Monomial(NFUN,vID,1,&f);
1980  AddMonomial(&f,&eq);
1981  ResetMonomial(&f);
1982 
1984 
1985  AddEquation2CS(p,&eq,cs);
1986 
1987  DeleteEquation(&eq);
1988  }
1989  free(vname);
1990  DeleteMonomial(&f);
1991  }
1992  }
1993 }
1995 {
1996  unsigned int i,nv,vID;
1997  boolean *selectedVars;
1998  char *vname;
1999 
2001 
2002  nv=GetCSNumVariables(cs);
2003  NEW(selectedVars,nv,boolean);
2004 
2005  /*in principle all variables are to be used in the Jacobian*/
2006  for(i=0;i<nv;i++)
2007  selectedVars[i]=TRUE;
2008 
2009  /*but we exclude those for translation*/
2010  NEW(vname,strlen(ln)+100,char);
2011  for(i=0;i<3;i++)
2012  {
2013  LINK_TRANS(vname,ln,i);
2014 
2015  vID=GetCSVariableID(vname,cs);
2016  if (vID==NO_UINT)
2017  Error("Translation variable is not included in the cuiksystem (in GenerateWorldTWSEquations)");
2018  selectedVars[vID]=FALSE;
2019  }
2020 
2021  AddSimplifiedJacobianEquations(p,selectedVars,cs);
2022 
2023  free(selectedVars);
2024  free(vname);
2025 }
2026 
2028 {
2029  if (w->stage!=WORLD_DEFINED)
2030  Error("World without equations in GetWorldKinJacobian");
2031 
2032  GetCSJacobian(J,&(w->kinCS));
2033 }
2034 
2036 {
2037  if (w->stage!=WORLD_DEFINED)
2038  Error("World without equations in GetWorldKinJacobian");
2039 
2040  GetSimpCSJacobian(p,J,&(w->kinCS));
2041 }
2042 
2043 inline unsigned int GetWorldSimpTopology(Tparameters *p,
2044  unsigned int **t,Tworld *w)
2045 {
2046  if (w->stage!=WORLD_DEFINED)
2047  Error("World without equations in GetWorldSimpTopology");
2048 
2049  return(GetSimpCSTopology(p,t,&(w->kinCS)));
2050 }
2051 
2052 inline unsigned int WorldSimpCuikNewton(Tparameters *p,double *pt,Tworld *w)
2053 {
2054  return(CuikNewtonSimp(p,pt,&(w->kinCS)));
2055 }
2056 
2057 inline void EvaluateWorldJacobian(double *pt,double ***J,Tworld *w)
2058 {
2059  if (w->stage!=WORLD_DEFINED)
2060  Error("World without equations in EvaluateWorldKinJacobian");
2061 
2062  EvaluateCSJacobian(pt,J,&(w->kinCS));
2063 }
2064 
2065 inline void WorldEvaluateEquations(double *pt,double *r,Tworld *w)
2066 {
2067  if (w->stage!=WORLD_DEFINED)
2068  Error("World without equations in EvaluateWorldKinJacobian");
2069 
2070  EvaluateCSEquations(pt,r,&(w->kinCS));
2071 }
2072 
2073 inline boolean WorldInequalitiesHold(double *pt,Tworld *w)
2074 {
2075  if (w->stage!=WORLD_DEFINED)
2076  Error("World without equations in WorldInequalitiesHold");
2077 
2078  return(InequalitiesHoldOnPoint(pt,&(w->kinCS)));
2079 }
2080 
2081 inline boolean WorldSimpInequalitiesHold(Tparameters *p,double *pt,Tworld *w)
2082 {
2083  if (w->stage!=WORLD_DEFINED)
2084  Error("World without equations in WorldInequalitiesHold");
2085 
2086  return(SimpInequalitiesHoldOnPoint(p,pt,&(w->kinCS)));
2087 }
2088 
2089 inline double WorldErrorInSimpInequalities(Tparameters *p,double *pt,Tworld *w)
2090 {
2091  if (w->stage!=WORLD_DEFINED)
2092  Error("World without equations in WorldErrorInSimpInequalities");
2093 
2094  return(ErrorInSimpInequalitiesOnPoint(p,pt,&(w->kinCS)));
2095 }
2096 
2097 inline void WorldEvaluateSimpEquations(Tparameters *p,double *pt,double *r,Tworld *w)
2098 {
2099  if (w->stage!=WORLD_DEFINED)
2100  Error("World without equations in WorldEvaluateSimpEquations");
2101 
2102  EvaluateSimpCSEquations(p,pt,r,&(w->kinCS));
2103 }
2104 
2105 inline void WorldEvaluateSubSetSimpEquations(Tparameters *p,boolean *se,double *pt,double *r,Tworld *w)
2106 {
2107  if (w->stage!=WORLD_DEFINED)
2108  Error("World without equations in WorldEvaluateSubSetSimpEquations");
2109 
2110  EvaluateSubSetSimpCSEquations(p,se,pt,r,&(w->kinCS));
2111 }
2112 
2113 double WorldErrorInEquations(double *pt,Tworld *w)
2114 {
2115  if (w->stage!=WORLD_DEFINED)
2116  Error("World without equations in WorldErrorInEquations");
2117 
2118  return(ErrorInCSEquations(pt,&(w->kinCS)));
2119 }
2120 
2121 inline double WorldErrorInSimpEquations(Tparameters *p,double *pt,Tworld *w)
2122 {
2123  if (w->stage!=WORLD_DEFINED)
2124  Error("World without equations in WorldErrorInSimpEquations");
2125 
2126  return(ErrorInSimpCSEquations(p,pt,&(w->kinCS)));
2127 }
2128 
2129 double WorldErrorFromDOFs(Tparameters *p,double *dof,Tworld *w)
2130 {
2131  double e,*v;
2132  Tbox b;
2133 
2134  WorldDOF2Sol(p,dof,&v,&b,w);
2135  DeleteBox(&b);
2136  e=WorldErrorInEquations(v,w);
2137  free(v);
2138 
2139  return(e);
2140 }
2141 
2142 inline double EvaluateWorldCost(Tparameters *p,boolean simp,double *pt,void *w)
2143 {
2144  if (((Tworld *)w)->stage!=WORLD_DEFINED)
2145  Error("World without equations in EvaluateWorldCost");
2146 
2147  return(EvaluateCSCost(p,simp,pt,(void *)&(((Tworld *)w)->kinCS)));
2148 }
2149 
2151 {
2152  if (w->stage!=WORLD_DEFINED)
2153  Error("World without equations in EvaluateWorldKinJacobian");
2154 
2155  return(GetCSNumVariables(&(w->kinCS)));
2156 }
2157 
2158 inline unsigned int GetWorldNumSystemVariables(Tworld *w)
2159 {
2160  if (w->stage!=WORLD_DEFINED)
2161  Error("World without equations in EvaluateWorldKinJacobian");
2162 
2163  return(GetCSNumSystemVariables(&(w->kinCS)));
2164 }
2165 
2166 inline unsigned int RegenerateWorldOriginalPoint(Tparameters *p,double *s,double **o,Tworld *w)
2167 {
2168  unsigned int nv,r;
2169 
2170  if (w->stage!=WORLD_DEFINED)
2171  Error("World without equations in EvaluateWorldKinJacobian");
2172 
2173  r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
2174 
2175  /* for JOINTS representations -> no simplification -> nothing to reconstruct */
2176  if (r==REP_JOINTS)
2177  {
2178  nv=GetCSNumVariables(&(w->kinCS));
2179  NEW(*o,nv,double);
2180  memcpy(*o,s,nv*sizeof(double));
2181  }
2182  else
2183  {
2184  /* Revover the original system variables and some of the dummies */
2185  nv=RegenerateOriginalPoint(p,s,o,&(w->kinCS));
2186 
2187  /* Some dummy variables that only appear in dummy equations are
2188  not present in the simplified system and their value can not be
2189  determined using 'RegenerateOriginalPoint'. We have to use the
2190  semantic of the variables to recover their value. */
2191  RegenerateMechanismSolution(p,&(w->kinCS),*o,&(w->m));
2192  }
2193  return(nv);
2194 }
2195 
2196 inline unsigned int WorldGenerateSimplifiedPoint(Tparameters *p,double *o,double **s,Tworld *w)
2197 {
2198  if (w->stage!=WORLD_DEFINED)
2199  Error("World without equations in EvaluateWorldKinJacobian");
2200 
2201  return(GenerateSimplifiedPoint(p,o,s,&(w->kinCS)));
2202 }
2203 
2204 inline void GetWorldInitialBox(Tbox *b,Tworld *w)
2205 {
2206  if (w->stage!=WORLD_DEFINED)
2207  Error("The equations and variables are not yet defined");
2208 
2209  GenerateInitialBox(b,&(w->kinCS));
2210 }
2211 
2213 {
2214  if (w->stage!=WORLD_DEFINED)
2215  Error("The equations and variables are not yet defined");
2216 
2217  GenerateSimpInitialBox(p,b,&(w->kinCS));
2218 }
2219 
2220 unsigned int MaxWorldReduction(Tparameters *p,Tbox *b,double *reduction,Tworld *w)
2221 {
2222  unsigned int s;
2223 
2224  if (w->stage!=WORLD_DEFINED)
2225  Error("The equations and variables are not yet defined");
2226 
2227  #if ((!_USE_MPI)&&(_DEBUG==1))
2228  {
2229  double sizeIn;
2230 
2231  sizeIn=GetBoxSize(w->systemVars,b);
2232  printf(" Kin <s:%g,l:%u>-> ",sizeIn,GetBoxLevel(b));
2233  }
2234  #endif
2235 
2236  s=MaxReduction(p,SYSTEM_VAR,reduction,b,&(w->kinCS));
2237  /*
2238  s can be EMPTY_BOX
2239  REDUCED_BOX
2240  REDUCED_BOX_WITH_SOLUTION
2241  ERROR_IN_PROCESS
2242  */
2243 
2244  #if ((!_USE_MPI)&&(_DEBUG==1))
2245  if (s==EMPTY_BOX)
2246  printf("e\n");
2247  else
2248  {
2249  double sizeOut;
2250 
2251  sizeOut=GetBoxSize(w->systemVars,b);
2252  printf("%g (s:%g)\n",*reduction,sizeOut);
2253  }
2254  fflush(stdout);
2255  #endif
2256 
2257  return(s);
2258 }
2259 
2260 void PlotWorld(Tparameters *pr,Tplot3d *pt,double axesLength,Tworld *w)
2261 {
2262  if (w->stage!=WORLD_DEFINED)
2263  Error("The equations and variables are not yet defined");
2264 
2265  /* We init the collision detection to be able to print
2266  collision information when moving the world */
2267  if (w->wcd==NULL)
2268  InitWorldCD(pr,1,w);
2269 
2270  Start3dBlock(pt);
2271  PlotEnvironment(pt,&(w->e));
2272  PlotMechanism(pt,axesLength,&(w->m));
2273  Close3dBlock(pt);
2274 }
2275 
2276 unsigned int RegenerateWorldSolutionPoint(Tparameters*pr,double *p,double **v,Tworld *w)
2277 {
2278  unsigned int i,n,k;
2279 
2280  if (w->stage!=WORLD_DEFINED)
2281  Error("The equations and variables are not yet defined");
2282 
2283  n=GetCSNumVariables(&(w->kinCS));
2284  NEW(*v,n,double);
2285 
2286  k=0;
2287  for(i=0;i<n;i++)
2288  {
2289  /*The input box only has values for the input variables*/
2290  if (w->systemVars[i])
2291  {
2292  (*v)[i]=p[k];
2293  k++;
2294  }
2295  else
2296  (*v)[i]=0.0; /*Non system variables are set to 0. See below! */
2297  }
2298 
2299  RegenerateMechanismSolution(pr,&(w->kinCS),*v,&(w->m));
2300 
2301  return(n);
2302 }
2303 
2304 void WorldPrintAtoms(Tparameters *pr,FILE *f,double *pt,Tworld *w)
2305 {
2306  THTransform *tl;
2307 
2308  if (GetEnvironmentNObstacles(&(w->e)))
2309  Warning("The bodies in the environment would not be considered");
2310 
2312 
2313  MechanismPrintAtoms(f,tl,&(w->m));
2314 
2315  DeleteLinkTransforms(tl,w);
2316 }
2317 
2318 void WorldStoreRigidGroups(Tparameters *pr,FILE *f,double *pt,Tworld *w)
2319 {
2320  THTransform *tl;
2321 
2322  if (GetEnvironmentNObstacles(&(w->e)))
2323  Warning("The bodies in the environment would not be considered");
2324 
2326 
2327  MechanismStoreRigidAtoms(f,tl,&(w->m));
2328 
2329  DeleteLinkTransforms(tl,w);
2330 }
2331 
2332 void WorldAtomJacobian(Tparameters *pr,double *sol,unsigned int *nr,unsigned int *nc,double ***J,Tworld *w)
2333 {
2334  double *a;
2335  unsigned int ta,*na,nb;
2336  unsigned int i,j,k,r;
2337  Tlink *l;
2338  Tpolyhedron *b;
2339 
2340  if (!IsMechanismAllSpheres(&(w->m)))
2341  Error("The world is not sphere-only (WorldAtomJacobian)");
2342 
2343  r=(unsigned int)(GetParameter(CT_REPRESENTATION,pr));
2344  if (r!=REP_JOINTS)
2345  Error("WorldAtomJacobian is only defined for JOINT-based representations");
2346 
2347  /* Count the number of atoms (total and per link) */
2348  NEW(na,w->nl,unsigned int); /* number of atoms per link */
2349  ta=0;
2350  for(i=0;i<w->nl;i++)
2351  {
2352  l=GetMechanismLink(i,&(w->m));
2353  nb=LinkNBodies(l);
2354  na[i]=0;
2355  for(j=0;j<nb;j++)
2356  {
2357  b=GetLinkBody(j,l);
2358  if (GetPolyhedronType(b)==SPHERE)
2359  na[i]++;
2360  }
2361  ta+=na[i];
2362  }
2363 
2364  /* Get the coordinates for each atom */
2365  NEW(a,3*ta,double); /* coordinates for each atom */
2366  k=0;
2367  for(i=0;i<w->nl;i++)
2368  {
2369  l=GetMechanismLink(i,&(w->m));
2370  nb=LinkNBodies(l);
2371  for(j=0;j<nb;j++)
2372  {
2373  b=GetLinkBody(j,l);
2374  if (GetPolyhedronType(b)==SPHERE)
2375  {
2376  GetPolyhedronCenter(&(a[k]),b);
2377  k+=3;
2378  }
2379  }
2380  }
2381 
2382  EvaluateJacobianXVectors(sol,ta,w->nl,na,a,nr,nc,J,&(w->refEqsJ));
2383 
2384  free(a);
2385 }
2386 
2388 {
2389  unsigned int n,r;
2390  double *v;
2391 
2392  if (w->stage!=WORLD_DEFINED)
2393  Error("The equations and variables are not yet defined");
2394 
2396  Warning("System-solution dimension missmatch in MoveWorld (using only the first value in the solution)");
2397 
2399  Error("Not enough values in the solution (using a different REPRESENTATION parameter?)");
2400 
2401  n=GetCSNumVariables(&(w->kinCS));
2402  NEW(v,n,double);
2403 
2404  r=(unsigned int)(GetParameter(CT_REPRESENTATION,pr));
2405  if (r==REP_JOINTS)
2406  {
2407  /* In dof repre. all variables are system variables */
2408  GetBoxCenter(NULL,v,b);
2409 
2410  MoveWorldDOF(pr,pt,v,w);
2411  }
2412  else
2413  {
2414  unsigned int i,k;
2415  THTransform *tl;
2416 
2417  k=0;
2418  for(i=0;i<n;i++)
2419  {
2420  /*The input box only has values for the input variables*/
2421  if (w->systemVars[i])
2422  {
2423  v[i]=IntervalCenter(GetBoxInterval(k,b));
2424  k++;
2425  }
2426  else
2427  v[i]=0.0; /*Non system variables are set to 0. See below! */
2428  }
2429 
2430  /* The input box only has values for the system variables.
2431  The dummies variables generated for each link when formulating
2432  the problem need to have values (they are used when moving links).
2433  Those dummy variables appear in the refEqs and, therefore, we have
2434  to re-generate the solution BEFORE evaluating the refEqs equations.
2435  */
2436  RegenerateMechanismSolution(pr,&(w->kinCS),v,&(w->m));
2437 
2438  GetLinkTransformsFromSolution(pr,v,&tl,w);
2439 
2440  if (MoveAndCheckCDFromTransforms(TRUE,0,tl,NULL,w))
2441  fprintf(stderr," Configuration is in collision\n");
2442  else
2443  fprintf(stderr," Configuration is NOT in collision\n");
2444 
2445  fprintf(stderr," Configuration error: %g\n",WorldErrorInEquations(v,w));
2446 
2447  MoveMechanismFromTransforms(pr,pt,tl,&(w->m));
2448 
2449  DeleteLinkTransforms(tl,w);
2450  }
2451  free(v);
2452 
2453 }
2454 
2455 void PrintWorldAxes(Tparameters *pr,FILE *f,Tbox *b,Tworld *w)
2456 {
2457  unsigned int i,k,n;
2458  double *r;
2459  double *v;
2460  Tjoint *j;
2461  unsigned int rep;
2462 
2463  if (w->stage!=WORLD_DEFINED)
2464  Error("The equations and variables are not yet defined");
2465 
2466  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,pr));
2467  if (rep==REP_JOINTS)
2468  Error("PrintWorldAxes is not defined for JOINT-based representations");
2469 
2470  n=GetCSNumVariables(&(w->kinCS));
2471  k=0;
2472  NEW(v,n,double);
2473  for(i=0;i<n;i++)
2474  {
2475  /*The input box only has values for the input variables*/
2476  if (w->systemVars[i])
2477  {
2478  v[i]=IntervalCenter(GetBoxInterval(k,b));
2479  k++;
2480  }
2481  else
2482  v[i]=0.0; /*Non system variables are set to 0. See below! */
2483  }
2484 
2485  /* The input box only has values for the system variables. The dummies variables
2486  generated for each link when formulating the problem need to have values (they
2487  are used when moving links).
2488  Those dummy variables appear in the refEqs and, therefore, we have to re-generate the
2489  solution BEFORE evaluating the refEqs equations.
2490  */
2491  RegenerateMechanismSolution(pr,&(w->kinCS),v,&(w->m));
2492 
2493  NEW(r,w->nl*3,double);
2495 
2496  for(i=0;i<w->nj;i++)
2497  {
2498  j=GetMechanismJoint(i,&(w->m));
2499  PrintJointAxes(pr,f,&(w->kinCS),v,r,j);
2500  }
2501  fprintf(f,"\n");
2502 
2503  free(r);
2504 
2505  free(v);
2506 }
2507 
2508 void PrintWorldCollisionInfo(FILE *f,char *fname,Tworld *w)
2509 {
2510  if (w->wcd!=NULL)
2511  StoreCollisionInfo(f,fname,w->endEffector,&(w->m),w->wcd);
2512 }
2513 
2514 void MoveWorldDOF(Tparameters *pr,Tplot3d *pt,double *dof,Tworld *w)
2515 {
2516  THTransform *tl;
2517  double *sample;
2518  Tbox bsample;
2519 
2520  if (w->stage!=WORLD_DEFINED)
2521  Error("The equations and variables are not yet defined");
2522 
2523  GetLinkTransformsFromDOF(dof,&tl,w);
2524 
2525  if (MoveAndCheckCDFromTransforms(TRUE,0,tl,NULL,w))
2526  {
2527  fprintf(stderr," Configuration is in collision\n");
2528  PrintCollisionInfo(tl,&(w->m),w->wcd);
2529  }
2530  else
2531  fprintf(stderr," Configuration is NOT in collision\n");
2532 
2533  WorldDOF2Sol(pr,dof,&sample,&bsample,w);
2534  fprintf(stderr," Configuration error: %g\n",WorldErrorInEquations(sample,w));
2535  free(sample);
2536  DeleteBox(&bsample);
2537 
2538  MoveMechanismFromTransforms(pr,pt,tl,&(w->m));
2539 
2540  DeleteLinkTransforms(tl,w);
2541 }
2542 
2543 unsigned int WorldDOF2Sol(Tparameters *p,double *dof,double **sol,Tbox *b,Tworld *w)
2544 {
2545  unsigned int r,i,n;
2546  Tjoint *j;
2547 
2548  if (w->stage!=WORLD_DEFINED)
2549  Error("The equations and variables are not yet defined");
2550 
2551  /* Ensure that the input dofs are in correct range */
2552  for(i=0;i<w->ndof;i++)
2553  {
2554  j=GetMechanismJoint(w->dof2joint[i],&(w->m));
2556  PI2PI(dof[i]);
2557  }
2558 
2559  n=GetCSNumVariables(&(w->kinCS));
2560  NEW(*sol,n,double);
2561  for(i=0;i<n;i++)
2562  (*sol)[i]=INF;
2563 
2564  r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
2565 
2566  if (r==REP_JOINTS)
2567  /* in dof all variables are system variables */
2568  memcpy(*sol,dof,n*sizeof(double));
2569  else
2570  {
2571  unsigned int k,l1,l2;
2572  THTransform *tl;
2573  Tjoint *j;
2574  Tlink *l;
2575 
2576  GetLinkTransformsFromDOF(dof,&tl,w);
2577  for(i=0;i<w->nl;i++)
2578  {
2579  l=GetMechanismLink(i,&(w->m));
2580  GenerateLinkSolution(p,&(tl[i]),&(w->kinCS),*sol,IsGroundLink(i),l);
2581  if (w->openLink[i])
2582  {
2583  /* Some links are at the end of an open chain of links (i.e., the
2584  mechanism is not fully composed by closed chains). In this case
2585  the system includes variables to represent the end position (x,y,z)
2586  of those links. Here we define the value for these variables from
2587  the translation part of the corresponding link transform. */
2588  char *vname,*ln;
2589  unsigned int vID;
2590 
2591  ln=GetLinkName(l);
2592  NEW(vname,strlen(ln)+100,char);
2593 
2594  for(k=0;k<3;k++)
2595  {
2596  LINK_TRANS(vname,ln,k);
2597 
2598  vID=GetCSVariableID(vname,&(w->kinCS));
2599  if (vID==NO_UINT)
2600  Error("Undefined reference variable in WorldDOF2Sol");
2601 
2602  (*sol)[vID]=HTransformGetElement(k,AXIS_H,&(tl[i]));
2603  }
2604  free(vname);
2605  }
2606  }
2607 
2608  for(i=0;i<w->nj;i++)
2609  {
2610  j=GetMechanismJoint(i,&(w->m));
2611  l1=JointFromID(j);
2612  l2=JointToID(j);
2613  GenerateJointSolution(p,&(dof[w->joint2dof[i]]),
2614  &(tl[l1]),&(tl[l2]),&(w->kinCS),*sol,j);
2615  }
2616 
2617  DeleteLinkTransforms(tl,w);
2618  }
2619 
2620  InitBoxFromPoint(n,*sol,b);
2621 
2622  return(n);
2623 }
2624 
2625 void WorldSample2DOF(Tparameters *p,double *sample,double *dof,Tworld *w)
2626 {
2627  unsigned int r ;
2628 
2629  if (w->stage!=WORLD_DEFINED)
2630  Error("The equations and variables are not yet defined");
2631 
2632  r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
2633 
2634  if (r==REP_JOINTS)
2635  {
2636  /* The samples are already in JOINTS form */
2637  memcpy(dof,sample,sizeof(double)*w->ndof);
2638  }
2639  else
2640  {
2641  unsigned int i,n,k;
2642  THTransform *tl;
2643  double *v;
2644 
2645  /* Fully reconstruct the solution point (obtain non-system variables from
2646  system ones) */
2647  n=GetCSNumVariables(&(w->kinCS));
2648  k=0;
2649  NEW(v,n,double);
2650  for(i=0;i<n;i++)
2651  {
2652  /*The input box only has values for the input variables*/
2653  if (w->systemVars[i])
2654  {
2655  v[i]=sample[k];
2656  k++;
2657  }
2658  else
2659  v[i]=0.0; /*Non system variables are set to 0. See below! */
2660  }
2661 
2662  RegenerateMechanismSolution(p,&(w->kinCS),v,&(w->m));
2663 
2664  /* Get a transform giving the absolute pose for each link using
2665  the full solution point. */
2666  GetLinkTransformsFromSolution(p,v,&tl,w);
2667 
2668  free(v);
2669 
2670  /* Obtain the joint variables from the link absolute poses */
2671  GetMechanismDOFsFromTransforms(p,tl,dof,&(w->m));
2672 
2673  DeleteLinkTransforms(tl,w);
2674  }
2675 }
2676 
2677 void AnimateWorld(Tparameters *pr,char *pname,double axesLength,
2678  double frameDelay,Tlist *p,Tworld *w)
2679 {
2680  Tplot3d p3d;
2681  boolean start;
2682  Titerator it;
2683 
2684  if (w->stage!=WORLD_DEFINED)
2685  Error("The equations and variables are not yet defined");
2686 
2687  if (axesLength<0) axesLength=0;
2688 
2689  if (frameDelay<0) frameDelay=0;
2690 
2691  InitPlot3d(pname,FALSE,0,NULL,&p3d);
2692 
2693  Start3dBlock(&p3d);
2695 
2696  PlotWorld(pr,&p3d,axesLength,w);
2697 
2698  InitIterator(&it,p);
2699  First(&it);
2700 
2702  Error("The input boxes does not have enough number of variables");
2703 
2704  start=TRUE;
2705  while(!EndOfList(&it))
2706  {
2707  MoveWorld(pr,&p3d,(Tbox *)GetCurrent(&it),w);
2708  if (start)
2709  {
2710  Close3dBlock(&p3d);
2711  start=FALSE;
2712  }
2713  Delay3dObject(FRAME_RATE+frameDelay,&p3d);
2714 
2715  Advance(&it);
2716  }
2718  ClosePlot3d(TRUE,0,0,0,&p3d); /*TRUE -> quit geomview after the animation*/
2719 }
2720 
2722 {
2723  Tfilename fout;
2724  FILE *f;
2725 
2726  if (w->stage!=WORLD_DEFINED)
2727  Error("The equations and variables are not yet defined");
2728 
2729  CreateFileName(GetFilePath(fname),GetFileName(fname),NULL,CUIK_EXT,&fout);
2730  f=fopen(GetFileFullName(&fout),"w");
2731  if (!f) Error("Could not open file in PrintWorldCS");
2732  #if (_DEBUG>0)
2733  printf("Generating cuik file : %s\n",GetFileFullName(&fout));
2734  #endif
2735 
2736  fprintf(f,"%% Kinematic equations\n");
2737  PrintCuikSystem(p,f,&(w->kinCS));
2738  fclose(f);
2739  DeleteFileName(&fout);
2740 }
2741 
2742 void PrintWorld(char *fname,int argc,char **arg,Tworld *w)
2743 {
2744  Tfilename fworld;
2745  FILE *f;
2746  time_t t;
2747  char hostname[50];
2748 
2749  CreateFileName(NULL,fname,NULL,WORLD_EXT,&fworld);
2750  fprintf(stderr,"Writing world to : %s\n",GetFileFullName(&fworld));
2751 
2752  f=fopen(GetFileFullName(&fworld),"w");
2753  if (!f)
2754  Error("Could not open the file to store the world");
2755 
2756  /* Do not document the link/joint/obstacle definitions. */
2757  fprintf(f,"/** \\cond */\n\n");
2758 
2759  PrintMechanism(f,GetFilePath(&fworld),GetFileName(&fworld),&(w->m));
2760 
2761  PrintEnvironment(f,GetFilePath(&fworld),&(w->e));
2762 
2763  /* Print the collision information */
2764  PrintCollisions(f,w);
2765 
2766  /* Autognerated documentation to avoid errors when generating the documentation. */
2767  fprintf(f,"/** \\endcond */\n");
2768  fprintf(f,"/**\n");
2769  fprintf(f," \\file %s.%s\n\n",GetFileName(&fworld),GetFileExtension(&fworld));
2770  fprintf(f," \\brief Automatically generated world file.\n\n");
2771  if ((argc>0)&&(arg!=NULL))
2772  {
2773  unsigned int i;
2774 
2775  fprintf(f," Automatically generated world file with the command:\n\n - ");
2776  for(i=0;i<(unsigned int)argc;i++)
2777  fprintf(f,"%s ",arg[i]);
2778  fprintf(f,"\n .\n\n");
2779  }
2780  else
2781  fprintf(f," Automatically generated world file.\n");
2782  t=time(NULL);
2783  gethostname(hostname,50);
2784  fprintf(f," Created on: %s Executed at: %s\n",ctime(&t),hostname);
2785  fprintf(f,"*/\n");
2786 
2787  fclose(f);
2788 
2789  DeleteFileName(&fworld);
2790 }
2791 
2793 {
2794  DeleteEnvironment(&(w->e));
2795  DeleteMechanism(&(w->m));
2797  DeleteWorldCD(w);
2798 
2799  /* if GenerateWorldEquationSystems was called */
2800  if (w->stage==WORLD_DEFINED)
2801  DeleteWorldCS(w);
2802 }
boolean NewtonInWorld(Tparameters *p, double *v, Tbox *b_sol, Tworld *w)
Generates a sample from a the kinematic cuiksystem in the world using the Newton algorithm.
Definition: world.c:1762
void First(Titerator *i)
Moves an iterator to the first position of its associated list.
Definition: list.c:356
void GetWorldDOFLabel(unsigned int ndof, char **string, Tworld *w)
Returns a label identifying each degree of freedom.
Definition: world.c:1585
void GetJointTransform(double *dof, THTransform *t, Tjoint *j)
Computes the transform induced by the joint.
Definition: joint.c:2527
unsigned int GetWorldObstacleID(char *obsName, Tworld *w)
Gets the identifier of an obstacle from its name.
Definition: world.c:1442
Set of variables of a cuiksystem.
Definition: variables.h:38
void RegenerateMechanismSolution(Tparameters *p, TCuikSystem *cs, double *sol, Tmechanism *m)
Computes the values for the non-system variables used to represent the rotation matrices for all link...
Definition: mechanism.c:242
void DeleteVector(void *vector)
Destructor.
Definition: vector.c:388
#define INITIAL_FRAME_DELAY
When generating 3d animations, delay before starting the animation.
Definition: world.h:39
unsigned int WorldGenerateSimplifiedPoint(Tparameters *p, double *o, double **s, Tworld *w)
Reconstruct a point in simplified kinematic system from an original point.
Definition: world.c:2196
void CheckLinkLinkCollision(unsigned int a, unsigned int b, Tworld *w)
Activates the possible collision between a particular pair of links.
Definition: world.c:1685
#define CARTESIAN_VAR
One of the possible type of variables.
Definition: variable.h:62
Tinterval * GetBoxInterval(unsigned int n, Tbox *b)
Returns a pointer to one of the intervals defining the box.
Definition: box.c:270
signed int GetMechanismMobility(Tmechanism *m)
Computes the mobility of a given mechanism.
Definition: mechanism.c:73
void GetJointPoint(unsigned int link, unsigned int point, double *p, Tjoint *j)
Gets one of the points defining the rotation/sliding axis for the joint.
Definition: joint.c:1012
signed int GetJointDOF(Tjoint *j)
Computes the degrees of freedom allowed by a given joint.
Definition: joint.c:1224
void EvaluateSubSetSimpCSEquations(Tparameters *pr, boolean *se, double *p, double *r, TCuikSystem *cs)
Evaluates a subset of the simplified equation set on a point.
Definition: cuiksystem.c:4806
char * GetFileName(Tfilename *fn)
Gets the file name.
Definition: filename.c:161
#define SYSTEM_EQ
One of the possible type of equations.
Definition: equation.h:146
void WorldInitDOFInfo(Tworld *w)
Collects information about the DOF of the mechanism.
Definition: world.c:1501
unsigned int nl
Definition: world.h:133
Tequation * GetEquation(unsigned int n, Tequations *eqs)
Gets an equation from the set.
Definition: equations.c:1697
#define REP_JOINTS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:60
void NoCheckLinkObstacleCollision(unsigned int a, unsigned int b, Tworld *w)
Desactivates the possible collision between a particular link and an object in the environment...
Definition: world.c:1712
boolean IsCSPolynomial(TCuikSystem *cs)
Identifies polynomial cuiksystems.
Definition: cuiksystem.c:2651
void InitJacobian(Tvariables *vs, Tequations *eqs, TJacobian *j)
Constructor.
Definition: jacobian.c:16
unsigned int VectorSize(Tvector *vector)
Gets the number of elements in a vector.
Definition: vector.c:169
boolean LinkCanCollide(unsigned int l, unsigned int nl, unsigned int no, boolean **checkCollisionsLL, boolean **checkCollisionsLO)
Identifies links than can collide.
Definition: cd.c:2209
void AddObstacle2World(char *name, Tpolyhedron *o, Tworld *w)
Adds an obstacle to the environment in the world.
Definition: world.c:1393
#define FALSE
FALSE.
Definition: boolean.h:30
void GenerateMEquationFromBranch(Tparameters *p, Tbranch *b, TMequation *meq, Tworld *w)
Generates a matrix equation from a branch.
Definition: world.c:718
unsigned int AddLink2World(Tlink *l, boolean endEffector, Tworld *w)
Adds a link to the mechanism in the world.
Definition: world.c:1333
void DeleteBranch(Tbranch *b)
Destructor.
Definition: world.c:292
void DeleteLinkTransforms(THTransform *tl, Tworld *w)
Deletes transforms for each link.
Definition: world.c:1290
Tvector steps
Definition: world.h:109
void InitWorldCD(Tparameters *pr, unsigned int mt, Tworld *w)
Initializes the collision detector.
Definition: world.c:1013
Relation between two links.
Definition: joint.h:177
void PlotMechanism(Tplot3d *pt, double axesLength, Tmechanism *m)
Adds a mechanism to a 3d scene.
Definition: mechanism.c:209
boolean WorldSimpInequalitiesHold(Tparameters *p, double *pt, Tworld *w)
Check if the inequalities hold for the simplified system.
Definition: world.c:2081
void GetPolyhedronCenter(double *c, Tpolyhedron *p)
Gets the center of the spheres.
Definition: polyhedron.c:1145
void SetEquationType(unsigned int type, Tequation *eq)
Changes the type of the equation (SYSTEM_EQ, CARTESIAN_EQ, DUMMY_EQ, DERIVED_EQ). ...
Definition: equation.c:1013
boolean ** checkCollisionsLL
Definition: world.h:145
void DeleteWorldCS(Tworld *w)
Deletes the world cuik system.
Definition: world.c:986
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
void GetWorldInitialBox(Tbox *b, Tworld *w)
Gets the kinematic search space for a given problem.
Definition: world.c:2204
void GetLinkTransformsFromSolutionPoint(Tparameters *p, boolean simp, double *sol, THTransform **tl, Tworld *w)
Define transforms for the links from the a solution point.
Definition: world.c:1165
double GetBoxSize(boolean *used, Tbox *b)
Computes the size of the box.
Definition: box.c:607
TCuikSystem kinCS
Definition: world.h:165
Data structure to hold the information about the name of a file.
Definition: filename.h:248
Auxiliary data for the collision detection.
Definition: cd.h:257
void GetMechanismDOFsFromTransforms(Tparameters *p, THTransform *tl, double *dof, Tmechanism *m)
Extract the joint DOF values form the poses of all links.
Definition: mechanism.c:298
void PlotWorld(Tparameters *pr, Tplot3d *pt, double axesLength, Tworld *w)
Adds a world (environment plus mechanism) in a 3D scene.
Definition: world.c:2260
void InitMEquation(TMequation *me)
Construtor.
Definition: mequation.c:99
void GetWorldJointLabel(unsigned int ndof, char **string, Tworld *w)
Returns a label identifying each joint.
Definition: world.c:1575
double GetMechanismMaxCoordinate(Tmechanism *m)
Returns the sum of the maximum coordinate value for all the links and joints in the mechanism...
Definition: mechanism.c:45
boolean * systemVars
Definition: world.h:169
void DeleteEquation(Tequation *eq)
Destructor.
Definition: equation.c:1748
A step in a kinematic branch.
Definition: world.h:80
void GetWorldSimpInitialBox(Tparameters *p, Tbox *b, Tworld *w)
Gets the kinematic simplified search space for a given problem.
Definition: world.c:2212
void GenerateInitialBox(Tbox *box, TCuikSystem *cs)
Gives the search space in the form of a box.
Definition: cuiksystem.c:4583
boolean GenerateEquationsFromBranch(Tparameters *p, unsigned int eq_type, TCuikSystem *cs, Tbranch *b, Tworld *w)
Generate equations from a branch.
Definition: world.c:778
unsigned int MaxWorldReduction(Tparameters *p, Tbox *b, double *reduction, Tworld *w)
Reduces the system variables as much as possible using the kinematic constraints. ...
Definition: world.c:2220
void * GetVectorElement(unsigned int i, Tvector *vector)
Returns a pointer to a vector element.
Definition: vector.c:269
A homgeneous transform in R^3.
void AddMatrixEquation(TMequation *equation, Tequations *eqs)
Adds a matrix equation to the set.
Definition: equations.c:1665
void SetBoxInterval(unsigned int n, Tinterval *is, Tbox *b)
Replaces a particular interval in a box.
Definition: box.c:259
double EvaluateWorldCost(Tparameters *p, boolean simp, double *pt, void *w)
Evaluates the functions cost defined in a world.
Definition: world.c:2142
Tmechanism m
Definition: world.h:131
void GenerateTransEquationsFromBranch(Tparameters *p, unsigned int eq_type, Tequation *eqs, Tbranch *b, Tworld *w)
Generate equations from a branch.
Definition: world.c:740
#define FINAL_FRAME_DELAY
When generating 3d animations, delay between the end of the animation and the exit of the animation b...
Definition: world.h:53
#define SYSTEM_VAR
One of the possible type of variables.
Definition: variable.h:24
void AddShape2Environment(char *name, Tpolyhedron *o, Tenvironment *e)
Adds an obstacle (i.e., a convex polyhedron) to the environment.
Definition: environment.c:20
unsigned int AddVariable2CS(Tvariable *v, TCuikSystem *cs)
Adds a variable to the system.
Definition: cuiksystem.c:2511
Definition of variable names.
void CopyEquation(Tequation *eq_dst, Tequation *eq_orig)
Copy constructor.
Definition: equation.c:216
void GetBranchStep(unsigned int i, double *s, Tjoint **joint, Tbranch *b)
Retrives a particular step form a kinematic chain.
Definition: world.c:184
#define PI2PI(a)
Forces an angle go be in [-pi,pi].
Definition: defines.h:205
void DeleteJacobian(TJacobian *j)
Destructor.
Definition: jacobian.c:249
double ErrorInSimpCSEquations(Tparameters *pr, double *p, TCuikSystem *cs)
Evaluates the norm of the error in a point for the simplified equations.
Definition: cuiksystem.c:4845
#define EQU
In a Tequation, the equation relational operator is equal.
Definition: equation.h:201
unsigned int GetWorldSimpVariableMask(Tparameters *p, boolean **sv, Tworld *w)
Identifies pose related variable that survied in the simplified system.
Definition: world.c:1823
void InitCD(unsigned int engine, boolean parallel, Tmechanism *m, Tenvironment *e, boolean **checkCollisionsLL, boolean **checkCollisionsLO, TworldCD *cd)
Initializes the collision detector.
Definition: cd.c:2126
void AddSimplifiedJacobianEquations(Tparameters *p, boolean *selectedVars, TCuikSystem *cs)
Adds linear a linear combination of the Jacobian to the system.
Definition: cuiksystem.c:2788
void DeleteCuikSystem(TCuikSystem *cs)
Destructor.
Definition: cuiksystem.c:5113
unsigned int GetCSSystemVars(boolean **sv, TCuikSystem *cs)
Identifies the system variables.
Definition: cuiksystem.c:2614
void DeleteMechanism(Tmechanism *m)
Destructor.
Definition: mechanism.c:441
Tenvironment e
Definition: world.h:130
#define EMPTY_BOX
One of the possible results of reducing a box.
Definition: box.h:25
void CreateBranch(Tbranch *b)
Constructor.
Definition: world.c:147
#define COORD_EQ
One of the possible type of equations.
Definition: equation.h:155
unsigned int CoupledWith(Tjoint *j)
Returns the identifier of the joint coupled with the query joint.
Definition: joint.c:1216
void InitPlot3d(char *name, boolean axes, int argc, char **arg, Tplot3d *p)
Constructor.
Definition: plot3d.c:41
#define WORLD_IN_DEFINITION
One of the stages of the Tworld structure definition.
Definition: world.h:61
boolean ** checkCollisionsLO
Definition: world.h:154
boolean AllRevolute(Tmechanism *m)
TRUE if all joints are revolute joints.
Definition: mechanism.c:193
void SetVariableInterval(Tinterval *i, Tvariable *v)
Sets the new range for the variable.
Definition: variable.c:70
#define TRUE
TRUE.
Definition: boolean.h:21
double WorldErrorInEquations(double *pt, Tworld *w)
Evalates the norm of the error in the kinematic equations for a given point.
Definition: world.c:2113
void InitBox(unsigned int dim, Tinterval *is, Tbox *b)
Initializes a box.
Definition: box.c:23
void Close3dBlock(Tplot3d *p)
Ends a block of commands.
Definition: plot3d.c:146
unsigned int np
Definition: world.h:137
void DeleteWorldCollisionInfo(Tworld *w)
Removes the collision information stored in a Tworld.
Definition: world.c:1482
void InitEquation(Tequation *eq)
Constructor.
Definition: equation.c:86
unsigned int GetWorldLinkID(char *linkName, Tworld *w)
Gets the identifier of a link from its name.
Definition: world.c:1437
char * GetFilePath(Tfilename *fn)
Gets the file path.
Definition: filename.c:156
void Error(const char *s)
General error function.
Definition: error.c:80
void MoveWorldDOF(Tparameters *pr, Tplot3d *pt, double *dof, Tworld *w)
Moves a mechanisms to a configuration given by the degrees of freedom.
Definition: world.c:2514
void AddMatrixEquation2CS(Tparameters *p, TMequation *eq, TCuikSystem *cs)
Adds a matrix equation to the system.
Definition: cuiksystem.c:2490
boolean WorldCanCollide(Tworld *w)
Determines if any collision is potentially possible.
Definition: world.c:1046
#define NFUN
No trigonometric function for the variable.
Definition: variable_set.h:36
void InitMechanism(Tmechanism *m)
Constructor.
Definition: mechanism.c:16
All the necessary information to generate equations for mechanisms.
Definition: world.h:124
#define CUIK_EXT
File extension for equation files.
Definition: filename.h:70
void SimplifyMEquation(TMequation *me)
Tries to reduce the complexity of the matrix equation.
Definition: mequation.c:299
void EvaluateCSEquations(double *p, double *r, TCuikSystem *cs)
Evaluates the equation set on a point.
Definition: cuiksystem.c:4793
#define AXIS_H
The homogeneous dimension in R^3.
Definition: htransform.h:108
void PrintWorld(char *fname, int argc, char **arg, Tworld *w)
Prints the world.
Definition: world.c:2742
unsigned int * dof2range
Definition: world.h:219
CBLAS_INLINE void HTransformProduct(THTransform *t1, THTransform *t2, THTransform *t3)
Product of two homogeneous transforms.
Definition: htransform.c:404
void InitWorldKinCS(Tparameters *p, Tworld *w)
Initializes the kinematic sub-problem of a Tworld structure.
Definition: world.c:900
unsigned int GetWorldSimpTopology(Tparameters *p, unsigned int **t, Tworld *w)
Gets the topology of the variables.
Definition: world.c:2043
unsigned int nStepsBranch(Tbranch *b)
Gets the number of steps in a kinematic chain.
Definition: world.c:179
Matrix equation.
Definition: mequation.h:38
Tlink * GetWorldLink(unsigned int linkID, Tworld *w)
Gets a link from its identifier.
Definition: world.c:1447
Tjoint * GetWorldJoint(unsigned int jointID, Tworld *w)
Gets a joint from its identifier.
Definition: world.c:1452
unsigned int Branches2Links(unsigned int from, unsigned int *links, unsigned int *jointTo, boolean *isLeaf, Tbranch *b, Tworld *w)
Determines kinematic branch from a link to all other links.
Definition: world.c:558
void CopyVoidPtr(void *a, void *b)
Copy constructor for void pointers.
Definition: vector.c:87
unsigned int GetSimpCSTopology(Tparameters *p, unsigned int **t, TCuikSystem *cs)
Topology of the variables in the simplified system.
Definition: cuiksystem.c:2674
void AddMonomial(Tmonomial *f, Tequation *eq)
Adds a new monomial to the equation.
Definition: equation.c:1356
unsigned int GetObstacleShapeStatus(unsigned int i, Tenvironment *e)
Gets the status (NORMAL, HIDDEN, DECOR) of an obstacle given its identifier.
Definition: environment.c:93
boolean AnyCollision(Tworld *w)
Determines if we want to avoid any collision.
Definition: world.c:1721
Definition of the Tworld type and the associated functions.
unsigned int no
Definition: world.h:136
unsigned int GetBoxNIntervals(Tbox *b)
Box dimensionality.
Definition: box.c:992
void CopyCuikSystem(TCuikSystem *cs_dst, TCuikSystem *cs_src)
Copy constructor.
Definition: cuiksystem.c:2204
void WorldEvaluateSimpEquations(Tparameters *p, double *pt, double *r, Tworld *w)
Evaluates the simplified kinematic equations.
Definition: world.c:2097
void PrintEnvironment(FILE *f, char *path, Tenvironment *e)
Stores the environment information into a file.
Definition: environment.c:120
void WorldEvaluateEquations(double *pt, double *r, Tworld *w)
Evaluates the kinematic equations.
Definition: world.c:2065
A polyhedron.
Definition: polyhedron.h:124
unsigned int * joint2dof
Definition: world.h:217
unsigned int GetBoxLevel(Tbox *b)
Returns the box level.
Definition: box.c:676
void GenerateJointEquationsInBranch(Tparameters *p, double s, TCuikSystem *cs, Tequation *eq, Tjoint *j)
Generate the constraints of a joint in a sequence.
Definition: joint.c:1755
void GetJointName(char **name, Tjoint *j)
Returns a string identifying the joint.
Definition: joint.c:961
Error and warning functions.
void EvaluateJacobianXVectors(double *p, unsigned int n, unsigned int ng, unsigned int *g, double *v, unsigned int *nr, unsigned int *nc, double ***m, TJacobian *j)
Evaluates the Jacobian multiplied by some given vectors.
Definition: jacobian.c:206
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
unsigned int GetJointID(Tjoint *j)
Gets the joint identifier.
Definition: joint.c:936
A 3D plot.
Definition: plot3d.h:54
boolean MoveAndCheckCD(Tparameters *p, boolean all, unsigned int tID, double *sol, double *solPrev, Tworld *w)
Checks a point for collision.
Definition: world.c:1076
unsigned int MaxReduction(Tparameters *p, unsigned int varMask, double *reduction, Tbox *b, TCuikSystem *cs)
Reduces a box as much as possible.
Definition: cuiksystem.c:2908
double ErrorInCSEquations(double *p, TCuikSystem *cs)
Evalates the norm of the error in a point.
Definition: cuiksystem.c:4826
unsigned int GetBranchDestination(Tbranch *b)
Returns the identifier of the link where the kinematic chain ends.
Definition: world.c:213
Tjoint * joint
Definition: world.h:81
boolean WorldInequalitiesHold(double *pt, Tworld *w)
Check if the inequalities hold.
Definition: world.c:2073
double HTransformGetElement(unsigned int i, unsigned int j, THTransform *t)
Gets an element in a homogeneous transform.
Definition: htransform.c:323
void AddStepToBranch(double s, Tjoint *joint, Tbranch *b)
Adds a step to a kinematic chain.
Definition: world.c:167
void MergeBranches(Tbranch *b1, Tbranch *b2, Tbranch *b)
Merge two kinematic branches.
Definition: world.c:228
#define INIT_NUM_JOINTS
Initial room for joints in a mechanism.
Definition: mechanism.h:36
void NewFreeJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, Tjoint *j)
Constructor.
Definition: joint.c:101
void DeleteTransSeq(TTransSeq *ts)
Destructor.
Definition: trans_seq.c:1109
void Delay3dObject(double t, Tplot3d *p)
Introduces a delay in the generation of the geometry.
Definition: plot3d.c:211
void SetEquationCmp(unsigned int cmp, Tequation *eq)
Changes the relational operator (LEQ, GEQ, EQU) of the equation.
Definition: equation.c:1018
void WorldDeleteDOFInfo(Tworld *w)
Deletes the information collected at WorldInitDOFInfo.
Definition: world.c:1552
boolean IsWorldPolynomial(Tworld *w)
Checks if the system of equations is polynomial.
Definition: world.c:1607
void ResetMonomial(Tmonomial *f)
Reset the monomial information.
Definition: monomial.c:24
unsigned int nj
Definition: world.h:135
void HTransformInverse(THTransform *t, THTransform *ti)
Inverse of a homogeneous transform.
Definition: htransform.c:468
void GetWorldVarNames(char **vn, Tworld *w)
Return the variable names.
Definition: world.c:1842
unsigned int GetWorldNDOF(Tworld *w)
Gets the number of degrees of freedom in the world.
Definition: world.c:1559
void GetTransformFromBranch(THTransform *tj, THTransform *t, Tbranch *b)
Defines the transform taking to the end of the branch.
Definition: world.c:271
void WorldPrintAtoms(Tparameters *pr, FILE *f, double *pt, Tworld *w)
Generates a file with the atom centers in global coordiantes.
Definition: world.c:2304
boolean EndOfList(Titerator *i)
Checks if an iterator is pointing at the end of the list.
Definition: list.c:445
unsigned int GetBranchOrigin(Tbranch *b)
Returns the identifier of the link where the kinematic chain starts.
Definition: world.c:198
An equation.
Definition: equation.h:236
void DeleteVariable(Tvariable *v)
Destructor.
Definition: variable.c:95
unsigned int GetWorldNConvexBodiesInLinks(Tworld *w)
Gets the number of convex polyhedrons that define the mechanism included in the world.
Definition: world.c:1472
Definitions of constants and macros used in several parts of the cuik library.
A generic list.
Definition: list.h:46
TworldCD * wcd
Definition: world.h:214
void MechanismStoreRigidAtoms(FILE *f, THTransform *tl, Tmechanism *m)
Auxiliary function for WorldStoreRigidGroups.
Definition: mechanism.c:335
void InitVector(unsigned int ele_size, void(*Copy)(void *, void *), void(*Delete)(void *), unsigned int max_ele, Tvector *vector)
Constructor.
Definition: vector.c:100
void GetWorldRangeDOF(unsigned int ndof, Tinterval *r, Tworld *w)
Gets the range for a given degree of freedom.
Definition: world.c:1564
void InitIterator(Titerator *i, Tlist *list)
Constructor.
Definition: list.c:284
unsigned int nsvars
Definition: world.h:168
unsigned int GetWorldSystemVars(boolean **sv, Tworld *w)
Gets the system vars of the kinematic cuiksystem.
Definition: world.c:1810
void InitEnvironment(Tenvironment *e)
Constructor.
Definition: environment.c:13
void GetCSJacobian(TJacobian *J, TCuikSystem *cs)
Defines the Jacobian of a CuikSystem.
Definition: cuiksystem.c:2669
Definition of the Tlist type and the associated functions.
unsigned int GetWorldMobility(Tworld *w)
Returns the number of degrees of freedom of the mechanism in the world.
Definition: world.c:1427
unsigned int GetJointRangeTopology(unsigned int nr, Tjoint *j)
Returns the topology of one of the ranges of the joint.
Definition: joint.c:1137
void CheckLinkObstacleCollision(unsigned int a, unsigned int b, Tworld *w)
Activates the possible collision between a particular link and an object in the environment.
Definition: world.c:1703
double WorldErrorInSimpEquations(Tparameters *p, double *pt, Tworld *w)
Evalates the norm of the error in the kinematic equations for a given point.
Definition: world.c:2121
void GenerateKinTree(Tvector *bOut, Tworld *w)
Builds a kinematic tree departing from the ground link.
Definition: world.c:624
void PrintWorldCollisionInfo(FILE *f, char *fname, Tworld *w)
Prints information collected durint last collision check.
Definition: world.c:2508
void NewVariable(unsigned int type, char *name, Tvariable *v)
Constructor.
Definition: variable.c:21
void EvaluateEqualityEquations(boolean systemOnly, double *v, double *r, Tequations *eqs)
Evaluates all equality equations in the set.
Definition: equations.c:2477
void InitEquations(Tequations *eqs)
Constructor.
Definition: equations.c:733
void PrintJointAxes(Tparameters *p, FILE *f, TCuikSystem *cs, double *sol, double *r, Tjoint *j)
Prints the joint axis in world coordinates.
Definition: joint.c:3271
unsigned int * dof2joint
Definition: world.h:218
unsigned int nvars
Definition: world.h:167
void DeleteEnvironment(Tenvironment *e)
Destructor.
Definition: environment.c:166
#define C_FCL
One of the possible collison detection engines.
Definition: parameters.h:105
#define CT_CD_ENGINE
Collision detection engine.
Definition: parameters.h:542
void DeleteInterval(Tinterval *i)
Destructor.
Definition: interval.c:1016
void InitWorld(Tworld *w)
Constructor.
Definition: world.c:1308
void NoCheckAllCollisions(unsigned int fl, unsigned int fo, Tworld *w)
Desactivates all the possible collision between links and links and obstacles.
Definition: world.c:1637
void NoCheckSelfCollisions(unsigned int fl, Tworld *w)
Desactivates all the possible collision between links.
Definition: world.c:1671
void InitCuikSystem(TCuikSystem *cs)
Constructor.
Definition: cuiksystem.c:2155
boolean CuikNewton(Tparameters *p, double *sol, Tbox *b_sol, TCuikSystem *cs)
Applies Newton-Rhapson to a set of equations.
Definition: cuiksystem.c:3905
unsigned int GetJointType(Tjoint *j)
Gets the joint type.
Definition: joint.c:931
void AddEquation2CS(Tparameters *p, Tequation *eq, TCuikSystem *cs)
Adds an equation to the system.
Definition: cuiksystem.c:2481
unsigned int WorldDOF2Sol(Tparameters *p, double *dof, double **sol, Tbox *b, Tworld *w)
Transforms from degrees of freedom to cuik variables.
Definition: world.c:2543
unsigned int nb
Definition: world.h:134
A scaled product of powers of variables.
Definition: monomial.h:32
void Warning(const char *s)
General warning function.
Definition: error.c:116
void MoveMechanismFromTransforms(Tparameters *pr, Tplot3d *pt, THTransform *tl, Tmechanism *m)
Displaces a mechanism in a 3d scene.
Definition: mechanism.c:372
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
unsigned int CuikNewtonSimp(Tparameters *p, double *x, TCuikSystem *cs)
CuikNewton on the simplified system.
Definition: cuiksystem.c:3571
boolean * openLink
Definition: world.h:203
void GetWorldSimpJacobian(Tparameters *p, TJacobian *J, Tworld *w)
Gets the simplified kinematic Jacobian.
Definition: world.c:2035
Tequations refEqs
Definition: world.h:186
boolean InequalitiesHoldOnPoint(double *p, TCuikSystem *cs)
Tests if all inqualities hold for a given point.
Definition: cuiksystem.c:4953
A sequence of transforms.
Definition: trans_seq.h:296
Tjoint * GetMechanismJoint(unsigned int i, Tmechanism *m)
Gets a joint given its identifier.
Definition: mechanism.c:182
unsigned int GetCSNumSystemVariables(TCuikSystem *cs)
Gets the number of system variables already in the cuiksystem.
Definition: cuiksystem.c:2549
A generic vector.
Definition: vector.h:227
void GetJointTransSeq(Tparameters *p, TCuikSystem *cs, TTransSeq *ts, Tjoint *j)
Build the sequence of transforms passing through the joint.
Definition: joint.c:2895
void GetLinkTransformsFromDOF(double *dof, THTransform **tl, Tworld *w)
Define transforms for the links from the DOF.
Definition: world.c:1118
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
A kinematic branch.
Definition: world.h:108
TJacobian refEqsJ
Definition: world.h:196
boolean IsMechanismAllSpheres(Tmechanism *m)
TRUE if the mechanism is composed by spheres only.
Definition: mechanism.c:40
void GetWorldJacobian(TJacobian *J, Tworld *w)
Gets the kinematic Jacobian.
Definition: world.c:2027
#define CT_REPRESENTATION
Representation.
Definition: parameters.h:215
double WorldErrorInSimpInequalities(Tparameters *p, double *pt, Tworld *w)
Determines the maximum error in the inequalites for the simplified system.
Definition: world.c:2089
void DeleteCD(TworldCD *cd)
Collision information destructor.
Definition: cd.c:2391
#define REV_JOINT
One of the possible type of joints.
Definition: joint.h:59
void GetCSVariables(Tvariables *vs, TCuikSystem *cs)
Gets the cuiksystem variables.
Definition: cuiksystem.c:2529
void EvaluateCSJacobian(double *p, double ***J, TCuikSystem *cs)
Evaluates the Jacobian of the system in a given point.
Definition: cuiksystem.c:4814
void StoreCollisionInfo(FILE *f, char *fname, unsigned int objectID, Tmechanism *m, TworldCD *cd)
Stores the information collected during last collision check into a file.
Definition: cd.c:2334
boolean CheckCollision(boolean all, THTransform *tl, THTransform *tlPrev, TworldCD *cd)
Determines if there is a collision.
Definition: cd.c:2251
unsigned int stage
Definition: world.h:125
void PrintCollisions(FILE *f, Tworld *w)
Stores the collision information into a file.
Definition: world.c:1733
#define SPHERE
One of the possible type of polyhedrons.
Definition: polyhedron.h:70
A box.
Definition: box.h:83
double WorldErrorFromDOFs(Tparameters *p, double *dof, Tworld *w)
Error in equations from DOFs.
Definition: world.c:2129
Data associated with each variable in the problem.
Definition: variable.h:84
void PrintMechanism(FILE *f, char *path, char *prefix, Tmechanism *m)
Stores the mechanisms information into a file.
Definition: mechanism.c:414
unsigned int GetWorldNumVariables(Tworld *w)
Number of variables in the kinematic subsystem.
Definition: world.c:2150
#define WORLD_EXT
File extension for problem files.
Definition: filename.h:161
void GetLinkTransformsFromSolution(Tparameters *p, double *sol, THTransform **tl, Tworld *w)
Define transforms for the links from the a solution point.
Definition: world.c:1260
A cuiksystem, i.e., a set of variables and equations defining a position analysis problem...
Definition: cuiksystem.h:181
void WorldEvaluateSubSetSimpEquations(Tparameters *p, boolean *se, double *pt, double *r, Tworld *w)
Evaluates a subset of the simplified kinematic equations.
Definition: world.c:2105
void WorldStoreRigidGroups(Tparameters *pr, FILE *f, double *pt, Tworld *w)
Generates a file with the atoms grouped in rigid clusters.
Definition: world.c:2318
void * GetCurrent(Titerator *i)
Gets the element pointed by the iterator.
Definition: list.c:299
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
void InitBoxFromPoint(unsigned int dim, double *p, Tbox *b)
Initializes a box from a point.
Definition: box.c:43
void CopyBranch(Tbranch *b_dst, Tbranch *b_src)
Copy constructor.
Definition: world.c:152
boolean IsRevoluteBinaryLink(unsigned int nl, double ***p, Tworld *w)
Identifies links articulated with only two revolute joints.
Definition: world.c:865
unsigned int WorldSimpCuikNewton(Tparameters *p, double *pt, Tworld *w)
Tries to reach the kinematic manifold.
Definition: world.c:2052
void PrintWorldAxes(Tparameters *pr, FILE *f, Tbox *b, Tworld *w)
Prints the axes of the mechanism.
Definition: world.c:2455
void AddVariable2Monomial(unsigned int fn, unsigned int varid, unsigned int p, Tmonomial *f)
Adds a power variable to the monomial.
Definition: monomial.c:171
unsigned int JointFromID(Tjoint *j)
Gets the identifier of the first link involved in the joint.
Definition: joint.c:941
double IntervalCenter(Tinterval *i)
Gets the interval center.
Definition: interval.c:129
void CheckSelfCollisions(unsigned int fl, Tworld *w)
Activates all the possible collision between links.
Definition: world.c:1656
Definition of the TSHTransform type and the associated functions.
unsigned int AddLink2Mechanism(Tlink *l, Tmechanism *m)
Adds a link to a mechanism.
Definition: mechanism.c:94
unsigned int GetCDEngine(TworldCD *cd)
Determines the collision engine.
Definition: cd.c:2246
void PrintCuikSystem(Tparameters *p, FILE *f, TCuikSystem *cs)
Prints a cuiksystem.
Definition: cuiksystem.c:5022
unsigned int GetWorldNObstacles(Tworld *w)
Gets the number of obstacles in the environment included in the world.
Definition: world.c:1467
unsigned int GetMechanismLinkID(char *ln, Tmechanism *m)
Gets a link identifier given its name.
Definition: mechanism.c:157
void GenerateJointSolution(Tparameters *p, double *dof, THTransform *t1, THTransform *t2, TCuikSystem *cs, double *sol, Tjoint *j)
Generates a solution point from degrees of freedom.
Definition: joint.c:2330
char * GetObstacleName(unsigned int i, Tenvironment *e)
Gets the name of an obstacle given its identifier.
Definition: environment.c:71
void GetCSVariableNames(char **varNames, TCuikSystem *cs)
Gets points to the variable names.
Definition: cuiksystem.c:2534
void DeleteBox(void *b)
Destructor.
Definition: box.c:1259
unsigned int GetSolutionPointFromLinkTransforms(Tparameters *p, THTransform *tl, double **sol, Tworld *w)
Determines the mechanisms configuration from the pose of all links.
Definition: world.c:1215
boolean SimpInequalitiesHoldOnPoint(Tparameters *pr, double *p, TCuikSystem *cs)
Tests if all simplified inqualities hold for a given point.
Definition: cuiksystem.c:4973
void GenerateWorldSingularityEquations(Tparameters *p, char *ln, TCuikSystem *cs, Tworld *w)
Adds variables/equations to detect singularities.
Definition: world.c:1929
void DeleteVariables(Tvariables *vs)
Destructor.
Definition: variables.c:354
The Jacobian of a set of equations.
Definition: jacobian.h:23
unsigned int ndof
Definition: world.h:216
Tbranch * branch2Link
Definition: world.h:178
void DeleteVoidPtr(void *a)
Destructor for void pointers.
Definition: vector.c:92
void HTransformDelete(THTransform *t)
Destructor.
Definition: htransform.c:833
void DeleteWorld(Tworld *w)
Destructor.
Definition: world.c:2792
boolean WorldContinuousCD(Tworld *w)
Determines the type of collision library used.
Definition: world.c:1051
unsigned int GetWorldVarTopology(unsigned int vID, Tworld *w)
Get the topology of a given variable.
Definition: world.c:1818
#define MEM_EXPAND(_var, _n, _type)
Expands a previously allocated memory space.
Definition: defines.h:404
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
unsigned int RegenerateWorldSolutionPoint(Tparameters *pr, double *p, double **v, Tworld *w)
Computes the missing values in a kinematic solution.
Definition: world.c:2276
unsigned int GetWorldNLinks(Tworld *w)
Gets the number of links in the mechanism included in the world.
Definition: world.c:1457
void EvaluateWorldJacobian(double *pt, double ***J, Tworld *w)
Evaluates the kinematic Jacobian.
Definition: world.c:2057
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
unsigned int AddJoint2World(Tjoint *j, Tworld *w)
Adds a joint to the mechanism in the world.
Definition: world.c:1383
Tlink * GetMechanismLink(unsigned int i, Tmechanism *m)
Gets a link given its identifier.
Definition: mechanism.c:146
void EvaluateSimpCSEquations(Tparameters *pr, double *p, double *r, TCuikSystem *cs)
Evaluates the simplified equation set on a point.
Definition: cuiksystem.c:4798
boolean IsMechanismInWorldAllSpheres(Tworld *w)
TRUE if the mechanisms in the world is based on spheres.
Definition: world.c:1432
#define INF
Infinite.
Definition: defines.h:70
unsigned int * sortedLinks
Definition: world.h:174
unsigned int endEffector
Definition: world.h:140
void AddCt2Monomial(double k, Tmonomial *f)
Scales a monomial.
Definition: monomial.c:158
List iterator.
Definition: list.h:61
void MoveWorld(Tparameters *pr, Tplot3d *pt, Tbox *b, Tworld *w)
Moves the mechanisms defined in a world information to a given configuration.
Definition: world.c:2387
void GetBoxCenter(boolean *used, double *c, Tbox *b)
Returns the box center along the selected dimensions.
Definition: box.c:697
double EvaluateCSCost(Tparameters *p, boolean simp, double *s, void *cs)
Evalutes the equation to minimize in a given point.
Definition: cuiksystem.c:4867
unsigned int GetWorldNConvexBodies(Tworld *w)
Gets the number of convex polyhedrons that define the mechanism and the environment included in the w...
Definition: world.c:1477
double GetEnvironmentMaxCoordinate(Tenvironment *e)
Returns the sum of the maximum coordinate value for all the convex polyhedrons in the environment...
Definition: environment.c:115
void DeleteEquations(Tequations *eqs)
Destructor.
Definition: equations.c:2750
unsigned int GetCSVariableID(char *name, TCuikSystem *cs)
Gets the numerical identifier of a variable given its name.
Definition: cuiksystem.c:2586
Definition of basic randomization functions.
void PrintBox(FILE *f, Tbox *b)
Prints a box.
Definition: box.c:1118
unsigned int GetCSNumNonDummyVariables(TCuikSystem *cs)
Gets the number of non-dummy variables already in the cuiksystem.
Definition: cuiksystem.c:2558
void GenerateWorldEquations(Tparameters *p, Tworld *w)
Generates all the cuiksystems derived from the world information.
Definition: world.c:1850
void GenerateJointRangeSingularityEquations(Tparameters *p, TCuikSystem *cs, Tjoint *j)
Modifies the cuik system to detect end range singularities.
Definition: joint.c:1276
unsigned int GetCSVarTopology(unsigned int vID, TCuikSystem *cs)
Determines the topology of a given variable.
Definition: cuiksystem.c:2627
unsigned int GetObstacleID(char *name, Tenvironment *e)
Gets the idetifier of an obstacles given its name.
Definition: environment.c:45
char * GetFileExtension(Tfilename *fn)
Gets the file extension.
Definition: filename.c:171
void AnimateWorld(Tparameters *pr, char *pname, double axesLength, double frameDelay, Tlist *p, Tworld *w)
Produces an animation along a path.
Definition: world.c:2677
unsigned int GetWorldNumSystemVariables(Tworld *w)
Number of system variables in the kinematic subsystem.
Definition: world.c:2158
Defines a interval.
Definition: interval.h:33
void GenerateWorldTWSEquations(Tparameters *p, char *ln, TCuikSystem *cs, Tworld *w)
Adds variables/equations to detect translational workspace boundaries.
Definition: world.c:1994
unsigned int RegenerateOriginalPoint(Tparameters *p, double *s, double **o, TCuikSystem *cs)
Generates an original point from a simplified point.
Definition: cuiksystem.c:4712
void HTransformIdentity(THTransform *t)
Constructor.
Definition: htransform.c:69
double sign
Definition: world.h:82
void InitMonomial(Tmonomial *f)
Constructor.
Definition: monomial.c:17
void WorldAtomJacobian(Tparameters *pr, double *sol, unsigned int *nr, unsigned int *nc, double ***J, Tworld *w)
Jacobian of the atom position w.r.t. the variables.
Definition: world.c:2332
void AddTransSeq2MEquation(int s, TTransSeq *ts, TMequation *me)
Concatenates a transform sequence to the matrix equation.
Definition: mequation.c:250
void GetSimpCSJacobian(Tparameters *p, TJacobian *J, TCuikSystem *cs)
Defines the Jacobian of a simplified CuikSystem.
Definition: cuiksystem.c:2683
unsigned int GetCSNumVariables(TCuikSystem *cs)
Gets the number of variables already in the cuiksystem.
Definition: cuiksystem.c:2544
unsigned int nwcd
Definition: world.h:210
double ErrorInSimpInequalitiesOnPoint(Tparameters *pr, double *p, TCuikSystem *cs)
Computes the maximum error in all the simplified inqualities for a given point.
Definition: cuiksystem.c:4996
unsigned int RegenerateWorldOriginalPoint(Tparameters *p, double *s, double **o, Tworld *w)
Reconstruct a point in original kinematic system from a simplified point.
Definition: world.c:2166
void DeleteJoint(Tjoint *j)
Destructor.
Definition: joint.c:3461
void PrintWorldCS(Tparameters *p, Tfilename *fname, Tworld *w)
Prints the cuiksystems derived from a world.
Definition: world.c:2721
void GenerateJointRangeEquations(Tparameters *p, TCuikSystem *cs, Tjoint *j)
Generate the constraints related with the joint limits.
Definition: joint.c:1463
boolean Advance(Titerator *i)
Moves an iterator to the next position of its associated list.
Definition: list.c:373
unsigned int GetLinkID(char *name, Tmechanism *m)
Gets the identifier of a link given its name.
Definition: mechanism.c:50
#define LINK_TRANS(vname, linkName, cn)
Translation part of the homogeneous transform defining the position of a link in global coordinates...
Definition: varnames.h:136
unsigned int * jointTo
Definition: world.h:176
void PrintCollisionInfo(THTransform *tl, Tmechanism *m, TworldCD *cd)
Prints some information collected during last collision check.
Definition: cd.c:2362
unsigned int AddJoint2Mechanism(Tjoint *j, Tmechanism *m)
Adds a joint to a mechanism.
Definition: mechanism.c:111
void MechanismPrintAtoms(FILE *f, THTransform *tl, Tmechanism *m)
Prints the center of the atoms in a mechanism.
Definition: mechanism.c:320
double maxCoord
Definition: world.h:142
unsigned int GenerateSimplifiedPoint(Tparameters *p, double *o, double **s, TCuikSystem *cs)
Generates a simplified point.
Definition: cuiksystem.c:4725
void GenerateJointEquations(Tparameters *p, double maxCoord, TCuikSystem *cs, Tjoint *j)
Generate the constraints related with the joint.
Definition: joint.c:1920
void DeleteMEquation(TMequation *me)
Destructor.
Definition: mequation.c:432
void GetJointRangeN(unsigned int nr, double mt, Tinterval *r, Tjoint *j)
Returns one of the ranges of the joint.
Definition: joint.c:1037
void PlotEnvironment(Tplot3d *pt, Tenvironment *e)
Displays the obstacles in the environment in a 3D geometry.
Definition: environment.c:143
void Start3dBlock(Tplot3d *p)
Starts a block of commands.
Definition: plot3d.c:141
void DeleteMonomial(Tmonomial *f)
Destructor.
Definition: monomial.c:289
unsigned int GetPolyhedronType(Tpolyhedron *p)
Retrives the type of a polyhedron.
Definition: polyhedron.c:1155
boolean MoveAndCheckCDFromTransforms(boolean all, unsigned int tID, THTransform *tl, THTransform *tlPrev, Tworld *w)
Checks a point for collision.
Definition: world.c:1060
void ClosePlot3d(boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
Destructor.
Definition: plot3d.c:473
void NoCheckLinkLinkCollision(unsigned int a, unsigned int b, Tworld *w)
Desactivates the possible collision between a particular pair of links.
Definition: world.c:1694
void GenerateSimpInitialBox(Tparameters *p, Tbox *box, TCuikSystem *cs)
Gives the search space in the form of a box for the simplified system.
Definition: cuiksystem.c:4588
unsigned int NewVectorElement(void *e, Tvector *vector)
Adds an element to the vector.
Definition: vector.c:212
#define TOPOLOGY_S
One of the possible topologies.
Definition: defines.h:139
unsigned int GetWorldNJoints(Tworld *w)
Gets the number of joints in the mechanism included in the world.
Definition: world.c:1462
#define DECOR_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:46
unsigned int GetEnvironmentNObstacles(Tenvironment *e)
Gets the number of obstacles in the environment.
Definition: environment.c:40
void AddEquationNoSimp(Tequation *equation, Tequations *eqs)
Adds an equation to the set.
Definition: equations.c:1656
unsigned int JointToID(Tjoint *j)
Gets the identifier of the second link involved in the joint.
Definition: joint.c:951
#define WORLD_DEFINED
One of the stages of the Tworld structure definition.
Definition: world.h:67
void WorldSample2DOF(Tparameters *p, double *sample, double *dof, Tworld *w)
Transforms a sample degrees of freedom.
Definition: world.c:2625
void CheckAllCollisions(unsigned int fl, unsigned int fo, Tworld *w)
Activates all the possible collision between links and links and obstacles.
Definition: world.c:1615
void InitWorldCS(Tworld *w)
Initializes the cuiksystems in a Tworld structure.
Definition: world.c:981
void DeleteWorldCD(Tworld *w)
Deletes the collision information stored in the world.
Definition: world.c:1100
#define FRAME_RATE
When generating 3d animations, frame rate.
Definition: world.h:45