readtensegrity.y
Go to the documentation of this file.
1 %{
3 #include "world.h"
4 
5 #include "boolean.h"
6 #include "error.h"
7 #include "vector.h"
8 #include "polyhedron.h"
9 #include "error_tensegrity.h"
10 
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <math.h>
15 
16 /*
17 * Definition of the function that initilizes a kinematic equations from a file.
18 * This is a method of the equations object.
19 */
20 
21  /*Lex and Yacc variables*/
22  extern FILE *ReadTensegrityin;
23 
24  /*Lex and Yacc functions*/
25  int ReadTensegritylex(void);
26 
27  /*Our own variables*/
28  extern unsigned int RTline; /* line number currently processed
29  (incremented by the LEX processor)*/
30 
31  /* different types of tensegrities */
32  #define NO_TYPE 0
33  #define PLANAR 1
34  #define SPATIAL 2
35 
36  typedef struct {
37  unsigned int type;
38  unsigned int l1;
39  unsigned int l2;
40  double scale;
41  THTransform t;
42  } Tcouple;
43 
44  /*
45  Auxiliary function to copy Tcouple structures.
46  */
47  void CopyCouple(void *l_dst,void *l_src);
48 
49  typedef struct {
50  unsigned int id;
51  unsigned int n[3];
52  double **p;
53  } Taddon;
54 
55  /*
56  Auxiliary function to copy Taddon structures.
57  */
58  void CopyAddon(void *l_dst,void *l_src);
59  /*
60  Auxiliary function to delete Taddon structures.
61  */
62  void DeleteAddon(void *l);
63 
64  /*Auxiliary variables used along readwordl*/
65  double **rt_point;
66  unsigned int rt_i;
67  unsigned int rt_type;
68  unsigned int rt_elementID;
69  Tpolyhedron rt_cbody;
70  Tconstants rt_constants;
71  Tfilename *rt_filename;
72  Tvector rt_couples;
73  Tvector rt_addons;
74  boolean rt_hasStiffness;
75  boolean rt_hasForce;
76  unsigned int rt_coupleLinkID;
77  Tlink *rt_coupleLink;
78  unsigned int rt_coupleType;
79  boolean rt_free_fly;
80  double rt_fly_range[3];
81  boolean rt_canFix;
82  unsigned int rt_base=NO_UINT;
83  Tlink rt_link;
84 
85  /* Global pointer to allow the different parts of the parser to acces the
86  equations being initialized*/
87  Tworld *rt_world;
88 
89  /* Global pointer to the parameter structure */
90  Tparameters *rt_parameters;
91 
92 %}
93 
94 %union
95 {
96  char *id;
97  char *string;
98  int int_number;
99  double real_number;
100  Tcolor color;
101  Tinterval range;
102  THTransform t;
103 }
104 
105 %start tensegrity
106 
107 %token _CONSTANTS _STRUCTURE _PLANAR _FREE _FLYING _ASSIGN _EQUAL _NOT_EQUAL _LESS_EQUAL _GREATER_EQUAL _LESS _GREATER _PI _EXP _PARAMETER _COS _SIN _TAN _COT _ACOS _ASIN _ATAN _ATAN2 _SQRT _ABS _PRINT _TX _TY _TZ _RX _RY _RZ _OBSTACLES _COLLISIONS _CHECK _DO _NOT _ALL _CONNECTED _BODY _GRANULARITY _STRUT _BAR _CABLE _SPRING _PRISMATIC _LOOPS _STIFFNESS _REST _FORCE _COUPLE _ORIENTATION _FORCES _ADDONS _NO _NULL _FIXED_POINTS _X _Y _Z _BOX _PRISM _SPHERE _CYLINDER _LENGTH _RADIUS _COLOR _RED _GREEN _BLUE _PURPLE _CYAN _YELLOW _WHITE _BLACK _GREY _DECORATION _HIDDEN
108 
109 %token <id> _IDENTIFIER
110 %token <int_number> _INTEGER
111 %token <real_number> _REAL
112 %token <string> _STRING
113 
114 %type <int_number> couple_element
115 %type <int_number> opt_granularity
116 %type <int_number> opt_body_status
117 %type <int_number> opt_loops
118 %type <int_number> dim
119 %type <real_number> expr
120 %type <real_number> opt_scale
121 %type <real_number> opt_rad
122 %type <range> opt_rest
123 %type <range> opt_force
124 %type <real_number> opt_stiffness
125 %type <range> range_or_ct
126 %type <color> color body_color opt_element_color
127 %type <t> opt_transform trans_seq trans
128 
129 %left _EQUAL _NOT_EQUAL _LESS_EQUAL _GREATER_EQUAL _LESS _GREATER
130 %left '+' '-'
131 %left '*' '/'
132 %right _MAX_PRECEDENCE
133 %left '^'
134 %%
135 
136 tensegrity : tensegrity def_block
137  |
138  ;
139 
140 def_block : constant_defs
141  | structure_defs
142  | couple_defs
143  | fix_point_defs
144  | addon_defs
145  | forces_defs
146  | obstacle_defs
147  | collision_defs
148  ;
149 
150 constant_defs: _CONSTANTS constant_list
151  ;
152 
153 constant_list : constant_definition constant_list
154  |
155  ;
156 
157 constant_definition : _IDENTIFIER _ASSIGN expr
158  {
159  if (GetConstantWithName($1,&rt_constants)!=NO_UINT)
160  {
161  char s[200];
162 
163  sprintf(s,"Duplicated constant %.100s",$1);
165  }
166 
167  AddConstant($1,$3,&rt_constants);
168  free($1);
169  }
170  | _PRINT _IDENTIFIER
171  {
172  unsigned int nc;
173 
174  nc=GetConstantWithName($2,&rt_constants);
175  if (nc==NO_UINT)
176  {
177  char ms[200];
178 
179  sprintf(ms,"Undefined constant: %.100s",$2);
181  }
182  fprintf(stderr," %s = %.12f\n",$2,GetConstantValue(nc,&rt_constants));
183  free($2);
184  }
185  ;
186 
187 expr : '+' expr %prec _MAX_PRECEDENCE
188  {
189  $$=$2;
190  }
191  | '-' expr %prec _MAX_PRECEDENCE
192  {
193  $$=-$2;
194  }
195  | expr '+' expr
196  {
197  $$=$1+$3;
198  }
199  | expr '-' expr
200  {
201  $$=$1-$3;
202  }
203  | expr '*' expr
204  {
205  $$=$1*$3;
206  }
207  | expr '^' expr
208  {
209  $$=pow($1,$3);
210  }
211  | expr '/' expr
212  {
213  $$=$1/$3;
214  }
215  | '(' expr ')'
216  {
217  $$=$2;
218  }
219  | '(' expr '?' expr ':' expr ')'
220  {
221  if ($2)
222  $$=$4;
223  else
224  $$=$6;
225  }
226  | expr _EQUAL expr
227  {
228  $$=($1==$3);
229  }
230  | expr _NOT_EQUAL expr
231  {
232  $$=($1!=$3);
233  }
234  | expr _LESS_EQUAL expr
235  {
236  $$=($1<=$3);
237  }
238  | expr _GREATER_EQUAL expr
239  {
240  $$=($1>=$3);
241  }
242  | expr _LESS expr
243  {
244  $$=($1<$3);
245  }
246  | expr _GREATER expr
247  {
248  $$=($1>$3);
249  }
250  | _PI
251  {
252  $$=M_PI;
253  }
254  | _SIN '(' expr ')'
255  {
256  $$=sin($3);
257  }
258  | _COS '(' expr ')'
259  {
260  $$=cos($3);
261  }
262  | _TAN '(' expr ')'
263  {
264  $$=tan($3);
265  }
266  | _COT '(' expr ')'
267  {
268  $$=tan(M_PI_2-$3);
269  }
270  | _ASIN '(' expr ')'
271  {
272  $$=asin($3);
273  }
274  | _ACOS '(' expr ')'
275  {
276  $$=acos($3);
277  }
278  | _ATAN '(' expr ')'
279  {
280  $$=atan($3);
281  }
282  | _ATAN2 '(' expr ',' expr ')'
283  {
284  $$=atan2($3,$5);
285  }
286  | _EXP '(' expr ')'
287  {
288  $$=exp($3);
289  }
290  | _SQRT '(' expr ')'
291  {
292  $$=sqrt($3);
293  }
294  | _ABS '(' expr ')'
295  {
296  $$=fabs($3);
297  }
298  | _PARAMETER '(' _IDENTIFIER ')'
299  {
300  unsigned int n;
301 
302  n=GetParameterID($3,rt_parameters);
303  if (n==NO_UINT)
304  {
305  char ms[200];
306 
307  sprintf(ms,"Undefined parameter: %.100s",$3);
309  }
310  $$=GetParameter(n,rt_parameters);
311 
312  free($3);
313  }
314  | _IDENTIFIER
315  {
316  unsigned int nc;
317 
318  nc=GetConstantWithName($1,&rt_constants);
319 
320  if (nc!=NO_UINT)
321  $$=GetConstantValue(nc,&rt_constants);
322  else
323  {
324  char ms[200];
325 
326  sprintf(ms,"Undefined constant: %.100s",$1);
328  }
329  free($1);
330  }
331  | _INTEGER
332  {
333  $$=(double)$1;
334  }
335  | _REAL
336  {
337  $$=$1;
338  }
339  ;
340 
341 structure_defs : structure_type structure_list
342  ;
343 
344 structure_type : '[' _STRUCTURE ']'
345  {
346  if (rt_type==NO_TYPE)
347  {
348  rt_type=SPATIAL;
349  rt_free_fly=FALSE;
350  rt_fly_range[0]=rt_fly_range[1]=rt_fly_range[2]==0.0;
351  rt_canFix=TRUE;
352  }
353  else
354  {
355  if (rt_type!=SPATIAL)
356  ReadTensegrityerror("Cannot mix spatial and planar structures");
357  }
358  }
359  | '[' _FREE _FLYING _STRUCTURE expr ',' expr ',' expr ']'
360  {
361  if (rt_type==NO_TYPE)
362  {
363  rt_type=SPATIAL;
364  rt_free_fly=TRUE;
365  rt_fly_range[0]=$5;
366  rt_fly_range[1]=$7;
367  rt_fly_range[2]=$9;
368  rt_canFix=FALSE;
369  if ((rt_fly_range[0]<0)||(rt_fly_range[1]<0)||(rt_fly_range[2]<0))
370  ReadTensegrityerror("The free flying range can not be negative");
371  }
372  else
373  {
374  if (rt_type!=SPATIAL)
375  ReadTensegrityerror("Cannot mix spatial and planar structures");
376  }
377  }
378  | '[' _PLANAR _STRUCTURE ']'
379  {
380  if (rt_type==NO_TYPE)
381  {
382  rt_type=PLANAR;
383  rt_free_fly=FALSE;
384  rt_fly_range[0]=rt_fly_range[1]=rt_fly_range[2]==0.0;
385  rt_canFix=TRUE;
386  }
387  else
388  {
389  if (rt_type!=PLANAR)
390  ReadTensegrityerror("Cannot mix spatial and planar structures");
391  }
392  }
393  | '[' _FREE _FLYING _PLANAR _STRUCTURE expr ',' expr ']'
394  {
395  if (rt_type==NO_TYPE)
396  {
397  rt_type=PLANAR;
398  rt_free_fly=TRUE;
399  rt_fly_range[0]=$6;
400  rt_fly_range[1]=$8;
401  rt_fly_range[2]=0.0;
402  rt_canFix=FALSE;
403  if ((rt_fly_range[0]<0)||(rt_fly_range[1]<0))
404  ReadTensegrityerror("The free flying range can not be negative");
405  }
406  else
407  {
408  if (rt_type!=PLANAR)
409  ReadTensegrityerror("Cannot mix spatial and planar structures");
410  }
411  }
412 
413 structure_list : basic_element structure_list
414  |
415  ;
416 
417 elementID : _STRUT
418  {
419  rt_elementID=STRUT; /* Fixed length. Tension/stiffness is negative */
420  }
421  | _BAR
422  {
423  rt_elementID=BAR; /* Fixed length. Tension/stiffnes is free */
424  }
425  | _CABLE
426  {
427  rt_elementID=CABLE; /* Fixed/variable length. Tension/stiffnes is possitive */
428  }
429  | _SPRING
430  {
431  rt_elementID=SPRING; /* Variable length. Tension/stiffnes is possitive */
432  }
433  | _PRISMATIC
434  {
435  rt_elementID=PRISMATIC_BAR; /* Variable length. Tension/stiffnes is free */
436  }
437  ;
438 
439 
440 basic_element : elementID _IDENTIFIER ':' _IDENTIFIER _IDENTIFIER
441  _LENGTH range_or_ct
442  opt_stiffness
443  opt_rest
444  opt_force
445  opt_rad
446  opt_loops
447  opt_granularity
448  opt_element_color
449  opt_body_status
450  {
451  unsigned int nf0,nf1,nf2,n1,n2;
452  Tlink l;
453  unsigned int k;
454  double **points;
455  double rad;
456 
457  if ((!rt_hasStiffness)&&(!rt_hasForce))
458  ReadTensegrityerror("Stiffness or force must be given");
459 
460  NEW(points,4,double*); /* last two points only used in case of free-flying */
461  for(k=0;k<4;k++)
462  {
463  NEW(points[k],3,double);
464  points[k][0]=points[k][1]=points[k][2]=0.0;
465  }
466 
467  if (rt_free_fly)
468  {
469  Tjoint j;
470  Tinterval range;
471 
472  InitNoRotLink("world0",&l);
473  nf0=AddLink2World(&l,FALSE,rt_world);
474  DeleteLink(&l);
475 
476  InitNoRotLink("world1",&l);
477  nf1=AddLink2World(&l,FALSE,rt_world);
478  DeleteLink(&l);
479 
480  if (rt_type!=PLANAR)
481  {
482  InitNoRotLink("world2",&l);
483  nf2=AddLink2World(&l,FALSE,rt_world);
484  DeleteLink(&l);
485  }
486 
487  NewInterval(-rt_fly_range[0],rt_fly_range[0],&range);
488  points[1][0]=points[3][0]=1; /* translation along X axis */
490  nf0,GetWorldLink(nf0,rt_world),
491  nf1,GetWorldLink(nf1,rt_world),
492  points,&range,
493  FALSE,0.0,&j);
494  AddJoint2World(&j,rt_world);
495  DeleteJoint(&j);
496  points[1][0]=points[3][0]=0; /* cancel translation along X axis */
497  DeleteInterval(&range);
498 
499  if (rt_type!=PLANAR)
500  {
501  NewInterval(-rt_fly_range[1],rt_fly_range[1],&range);
502  points[1][1]=points[3][1]=1; /* translation along Y axis */
504  nf1,GetWorldLink(nf1,rt_world),
505  nf2,GetWorldLink(nf2,rt_world),
506  points,&range,
507  FALSE,0.0,&j);
508  AddJoint2World(&j,rt_world);
509  DeleteJoint(&j);
510  points[1][1]=points[3][1]=0; /* cancel translation along Y axis */
511  DeleteInterval(&range);
512  }
513 
514  }
515 
516  n1=GetWorldLinkID($4,rt_world);
517  if (n1==NO_UINT)
518  {
519  InitNoRotLink($4,&l);
520  n1=AddLink2World(&l,FALSE,rt_world);
521  DeleteLink(&l);
522  }
523 
524  if (rt_free_fly)
525  {
526  Tjoint j;
527  Tinterval range;
528 
529  if (rt_type==PLANAR)
530  {
531  NewInterval(-rt_fly_range[1],rt_fly_range[1],&range);
532  points[1][1]=points[3][1]=1; /* translation along Y axis */
534  nf1,GetWorldLink(nf1,rt_world),
535  n1,GetWorldLink(n1,rt_world),
536  points,&range,
537  FALSE,0.0,&j);
538  AddJoint2World(&j,rt_world);
539  DeleteJoint(&j);
540  points[1][1]=points[3][1]=0; /* cancel translation along Y axis */
541  DeleteInterval(&range);
542  }
543  else
544  {
545  NewInterval(-rt_fly_range[2],rt_fly_range[2],&range);
546  points[1][2]=points[3][2]=1; /* translation along Z axis */
548  nf2,GetWorldLink(nf2,rt_world),
549  n1,GetWorldLink(n1,rt_world),
550  points,&range,
551  FALSE,0.0,&j);
552  AddJoint2World(&j,rt_world);
553  DeleteJoint(&j);
554  points[1][2]=points[3][2]=0; /* cancel translation along Z axis */
555  DeleteInterval(&range);
556  }
557 
558  /* the free-flying mechanism is already set */
559  rt_free_fly=FALSE;
560 
561  /* keepp the identifier of the first link in the tensegrity */
562  rt_base=n1;
563  }
564 
565  n2=GetWorldLinkID($5,rt_world);
566  if (n2==NO_UINT)
567  {
568  InitNoRotLink($5,&l);
569  n2=AddLink2World(&l,FALSE,rt_world);
570  DeleteLink(&l);
571  }
572 
573 
574  /* struts must have negative force */
575  if ((rt_elementID==STRUT)&&(UpperLimit(&($10))>0.0))
576  ReadTensegrityerror("Struts work in compression (i.e., negative forces)");
577 
578  /* cables must have positive stiffness */
579  if (((rt_elementID==CABLE)||(rt_elementID==SPRING))&&($8<0))
580  ReadTensegrityerror("Stiffness of cables must be positive");
581 
582  /* cables must have positive force */
583  if (((rt_elementID==CABLE)||(rt_elementID==SPRING))&&(LowerLimit(&($10))<0.0))
584  ReadTensegrityerror("Cables/springs work on tension (i.e., possitive forces)");
585 
586  /* struts and bars must have constant length */
587  if (((rt_elementID==STRUT)||(rt_elementID==BAR))&&(IntervalSize(&($7))>ZERO))
588  ReadTensegrityerror("Struts/bars must have constant length");
589 
590  /* can not have rest length without stiffness */
591  if ((fabs($8)<ZERO)&&(!ZeroInterval(&($9))))
592  ReadTensegrityerror("Wrong stiffness/rest length");
593 
594  /* contant length cables can not have linear force information */
595  if ((rt_elementID==CABLE)&&(IntervalSize(&($7))<ZERO)&&((fabs($8)>ZERO)||(!ZeroInterval(&($9)))))
596  ReadTensegrityerror("Constant length cables can not have stiffness nor rest length");
597 
598  /* springs can not be constant length */
599  if ((rt_elementID==SPRING)&&(IntervalSize(&($7))<ZERO))
600  ReadTensegrityerror("Springs can not have constant length");
601 
602  /* prismatic bars must be properly extensible (upper part must fit inside
603  the lower part) */
604  if ((rt_elementID==PRISMATIC_BAR)&&(IntervalSize(&($7))<ZERO))
605  ReadTensegrityerror("Springs can not have constant length");
606 
607  if ((rt_elementID==PRISMATIC_BAR)&&(LowerLimit(&($7))<IntervalSize(&($7))))
608  ReadTensegrityerror("Wrong length range in prismatic bar");
609 
610  if ($11==0)
611  {
612  /* default radius */
613  if (rt_elementID==SPRING)
614  rad=0.00625;
615  else
616  {
617  if (rt_elementID==CABLE)
618  rad=0.003125; /* very thin cylinder */
619  else
620  rad=0.025; /* struts, bar, prismatic */
621  }
622  }
623  else
624  rad=$11;
625 
626  AddLeg2World($2, /* link name */
627  (rt_type==PLANAR), /* planar */
628  rt_elementID, /* element type: strut, bar, ... */
629  n1,n2, /* connected links */
630  points, /* connection points on links */
631  &($7), /* length */
632  $8, /* stiffness */
633  &($9), /* rest */
634  &($10), /* force range */
635  rad, /* radius */
636  (rt_elementID==SPRING?$12:$13), /* granularity/loops */
637  &($14), /* color */
638  $15, /* shape_status */
639  rt_world);
640 
641  for(k=0;k<4;k++)
642  free(points[k]);
643  free(points);
644 
645  DeleteInterval(&($7));
646  DeleteInterval(&($9));
647  DeleteInterval(&($10));
648 
649  free($2);
650  free($4);
651  free($5);
652 
653  rt_hasStiffness=FALSE;
654  rt_hasForce=FALSE;
655  }
656  ;
657 
658 opt_stiffness : _STIFFNESS expr
659  {
660  if ((rt_elementID==STRUT)||(rt_elementID==BAR))
661  ReadTensegrityerror("Contant length elements (struts, bars) can not have stiffness (just a force range)");
662 
663  $$=$2;
664  rt_hasStiffness=TRUE;
665  }
666  |
667  {
668  $$=0.0;
669  rt_hasStiffness=FALSE;
670  }
671  ;
672 
673 opt_rest : _REST range_or_ct
674  {
675  if ((rt_elementID==STRUT)||(rt_elementID==BAR))
676  ReadTensegrityerror("Contant length elements (struts, bars) can not have rest lenght");
677 
678  CopyInterval(&($$),&($2));
679  }
680  |
681  {
682  NewInterval(0.0,0.0,&($$));
683  }
684  ;
685 
686 opt_force : _FORCE range_or_ct
687  {
688  CopyInterval(&($$),&($2));
689  rt_hasForce=TRUE;
690  }
691  |
692  {
693  if (rt_elementID==STRUT)
694  NewInterval(-INF,0.0,&($$));
695  else
696  {
697  if ((rt_elementID==CABLE)||(rt_elementID==SPRING))
698  NewInterval(0.0,INF,&($$));
699  else
700  NewInterval(-INF,INF,&($$));
701  }
702  }
703  ;
704 
705 
706 range_or_ct : '[' expr ',' expr ']'
707  {
708  NewInterval($2,$4,&($$));
709  if (EmptyInterval(&($$)))
710  ReadTensegrityerror("Empty interval");
711  }
712  | expr
713  {
714  NewInterval($1,$1,&($$));
715  }
716  ;
717 
718 opt_rad : _RADIUS expr
719  {
720  $$=$2;
721  }
722  |
723  {
724  $$=0.0;
725  }
726  ;
727 
728 opt_loops : _LOOPS expr
729  {
730  if (rt_elementID!=SPRING)
731  ReadTensegrityerror("Loops con only be given for springs. Do you mean granularity?");
732  if ($2<ZERO)
733  ReadTensegrityerror("The number of loops must be positive");
734  if ($2-floor($2)>ZERO)
735  ReadTensegrityerror("The number of loops must be a natural number");
736 
737  $$=(unsigned int)floor($2);
738  }
739  |
740  {
741  $$=80;
742  }
743  ;
744 
745 opt_granularity : _GRANULARITY _INTEGER
746  {
747  if (rt_elementID==SPRING)
748  ReadTensegrityerror("Can not give granularity for springs. Do you mean loops?");
749  if ($2<ZERO)
750  ReadTensegrityerror("The granularity must be positive");
751  if ($2-floor($2)>ZERO)
752  ReadTensegrityerror("The granularity must be a natural number");
753 
754  $$=$2;
755  }
756  |
757  {
758  $$=5;
759  }
760  ;
761 
762 opt_element_color : color
763  {
764  CopyColor(&($$),&($1));
765  }
766  |
767  {
768  if ((rt_elementID==CABLE)||(rt_elementID==SPRING))
769  NewColor(0,0,1,&($$)); // blue
770  else
771  NewColor(0,0,0,&($$)); // black
772  }
773  ;
774 
775 opt_body_status : _HIDDEN
776  {
777  $$=HIDDEN_SHAPE;
778  }
779  | _DECORATION
780  {
781  $$=DECOR_SHAPE;
782  }
783  |
784  {
785  $$=NORMAL_SHAPE;
786  }
787  ;
788 
789 couple_defs : _COUPLE couple_list
790  ;
791 
792 couple_list : couple couple_list
793  |
794  ;
795 
796 couple_element : _LENGTH
797  {
798  $$=COUPLE_LENGTH;
799  }
800  | _REST
801  {
802  $$=COUPLE_REST;
803  }
804  | _FORCE
805  {
806  $$=COUPLE_FORCE;
807  }
808  ;
809 
810 couple : couple_element ':' _IDENTIFIER
811  {
812  rt_coupleType=$1;
813 
814  rt_coupleLinkID=GetWorldLinkID($3,rt_world);
815  if (rt_coupleLinkID==NO_UINT)
816  ReadTensegrityerror("Undefined first link in couple");
817 
818  rt_coupleLink=GetWorldLink(rt_coupleLinkID,rt_world);
819 
820  if ((rt_coupleType==COUPLE_LENGTH)&&(!IsVariableLengthLink(rt_coupleLink)))
821  ReadTensegrityerror("Can not couple the length of fixed-length elements");
822 
823  free($3);
824  }
825  coupled_items
826  | _ORIENTATION ':' _IDENTIFIER
827  {
828  rt_coupleType=COUPLE_ORIENTATION;
829 
830  rt_coupleLinkID=GetWorldLinkID($3,rt_world);
831  if (rt_coupleLinkID==NO_UINT)
832  ReadTensegrityerror("Undefined first link in orientation couple");
833 
834  rt_coupleLink=GetWorldLink(rt_coupleLinkID,rt_world);
835 
836  free($3);
837  }
838  coupled_orientation_items
839  ;
840 
841 coupled_items : coupled_item coupled_items
842  | coupled_item
843  ;
844 
845 coupled_orientation_items : coupled_orientation_item coupled_orientation_items
846  | coupled_orientation_item
847  ;
848 
849 coupled_item : ',' opt_scale _IDENTIFIER
850  {
851  Tcouple couple;
852  unsigned int n2;
853  Tlink *l2;
854 
855  n2=GetWorldLinkID($3,rt_world);
856  if (n2==NO_UINT)
857  ReadTensegrityerror("Undefined coupled link");
858 
859  l2=GetWorldLink(n2,rt_world);
860 
861  if ((GetLinkType(rt_coupleLink)!=GetLinkType(l2))||
862  (GetLinkForceModel(rt_coupleLink)!=GetLinkForceModel(l2))||
863  (IsVariableLengthLink(rt_coupleLink)!=IsVariableLengthLink(l2)))
864  ReadTensegrityerror("The two links to couple must be of the same type");
865 
866  couple.type=rt_coupleType;
867  couple.l1=rt_coupleLinkID;
868  couple.l2=n2;
869  couple.scale=$2;
870  HTransformIdentity(&(couple.t));
871 
872  NewVectorElement((void *)&couple,&rt_couples);
873 
874  free($3);
875  }
876  ;
877 
878 coupled_orientation_item : ',' opt_transform _IDENTIFIER
879  {
880  Tcouple couple;
881  unsigned int n2;
882 
883  n2=GetWorldLinkID($3,rt_world);
884  if (n2==NO_UINT)
885  ReadTensegrityerror("Undefined coupled link");
886 
887  couple.type=COUPLE_ORIENTATION;
888  couple.l1=rt_coupleLinkID;
889  couple.l2=n2;
890  couple.scale=1.0;
891  HTransformCopy(&(couple.t),&($2));
892  HTransformDelete(&($2));
893 
894  NewVectorElement((void *)&couple,&rt_couples);
895 
896  free($3);
897  }
898  ;
899 
900 opt_scale : '[' expr ']'
901  {
902  $$=$2;
903  }
904  |
905  {
906  $$=1.0;
907  }
908  ;
909 
910 opt_transform : '[' trans_seq ']'
911  {
912  HTransformCopy(&($$),&($2));
913  HTransformDelete(&($2));
914  }
915  |
916  {
917  HTransformIdentity(&($$));
918  }
919  ;
920 
921 trans_seq : trans '*' trans_seq
922  {
923  HTransformProduct(&($1),&($3),&($$));
924  HTransformDelete(&($1));
925  HTransformDelete(&($3));
926  }
927  | trans
928  {
929  HTransformCopy(&($$),&($1));
930  HTransformDelete(&($1));
931  }
932  ;
933 
934 trans : _RX '(' expr ')'
935  {
936  HTransformRx($3,&($$));
937  }
938  | _RY '(' expr ')'
939  {
940  HTransformRy($3,&($$));
941  }
942  | _RZ '(' expr ')'
943  {
944  HTransformRz($3,&($$));
945  }
946  ;
947 
948 fix_point_defs : _FIXED_POINTS fix_point_list
949  ;
950 
951 fix_point_list : fix_point fix_point_list
952  |
953  ;
954 
955 fix_point : _IDENTIFIER '(' dim ')' '=' expr
956  {
957  unsigned int n1;
958  Tlink *l;
959 
960  if (!rt_canFix)
961  ReadTensegrityerror("Free-flying structures can not have fixed points");
962 
963  n1=GetWorldLinkID($1,rt_world);
964  if (n1==NO_UINT)
965  ReadTensegrityerror("Undefined link");
966 
967  l=GetWorldLink(n1,rt_world);
968 
969  if (GetLinkType(l)!=LINK_NoRot)
970  ReadTensegrityerror("Only nodes can be fixed");
971 
972  if ((IsGroundLink(n1))&&(fabs($6)>ZERO))
973  ReadTensegrityerror("The translation of the ground link can only be fixed to 0");
974 
975  SetLinkTrans($3,$6,l);
976 
977  free($1);
978  }
979  | _IDENTIFIER '=' '(' expr ',' expr ',' expr ')'
980  {
981  unsigned int n1;
982  Tlink *l;
983 
984  if (!rt_canFix)
985  ReadTensegrityerror("Free-flying structures can not have fixed points");
986 
987  n1=GetWorldLinkID($1,rt_world);
988  if (n1==NO_UINT)
989  ReadTensegrityerror("Undefined link");
990 
991  l=GetWorldLink(n1,rt_world);
992 
993  if (GetLinkType(l)!=LINK_NoRot)
994  ReadTensegrityerror("Only nodes can be fixed");
995 
996  if ((IsGroundLink(n1))&&((fabs($4)>ZERO)||(fabs($6)>ZERO)||(fabs($8)>ZERO)))
997  ReadTensegrityerror("The translation of the ground link can only be fixed to 0");
998 
999  SetLinkTrans(0,$4,l); /* X */
1000  SetLinkTrans(1,$6,l); /* Y */
1001  SetLinkTrans(2,$8,l); /* Z */
1002 
1003  free($1);
1004  }
1005  ;
1006 
1007 dim : _X
1008  {
1009  $$=0;
1010  }
1011  | _Y
1012  {
1013  $$=1;
1014  }
1015  | _Z
1016  {
1017  $$=2;
1018  }
1019  ;
1020 
1021 addon_defs : _ADDONS addon_list
1022  ;
1023 
1024 addon_list : addon addon_list
1025  |
1026  ;
1027 
1028 addon : _IDENTIFIER ':'
1029  {
1030  InitLink($1,&rt_link);
1031  free($1);
1032  }
1033  shape_list
1034  '(' expr ',' expr ',' expr ')' _IDENTIFIER
1035  '(' expr ',' expr ',' expr ')' _IDENTIFIER
1036  '(' expr ',' expr ',' expr ')' _IDENTIFIER
1037  {
1038  Taddon a;
1039  Tjoint j;
1040 
1041  /* Add the geometry as a link */
1042  a.id=AddLink2World(&rt_link,FALSE,rt_world);
1043  DeleteLink(&rt_link);
1044 
1045  /* and add a free joint from thw world to the addon */
1046  NewFreeJoint(GetWorldNJoints(rt_world),
1047  0,GetWorldLink(0,rt_world),
1048  a.id,GetWorldLink(a.id,rt_world),
1049  &j);
1050  AddJoint2World(&j,rt_world);
1051  DeleteJoint(&j);
1052 
1053  a.n[0]=GetWorldLinkID($12,rt_world);
1054 
1055  NEW(a.p,3,double*);
1056  if (a.n[0]==NO_UINT)
1057  ReadTensegrityerror("Undefined first anchor node");
1058  if (GetLinkType(GetWorldLink(a.n[0],rt_world))!=LINK_NoRot)
1059  ReadTensegrityerror("Only nodes can be used to fix addons");
1060  NEW(a.p[0],3,double);
1061  a.p[0][0]=$6;
1062  a.p[0][1]=$8;
1063  a.p[0][2]=$10;
1064 
1065  a.n[1]=GetWorldLinkID($20,rt_world);
1066  if (a.n[1]==NO_UINT)
1067  ReadTensegrityerror("Undefined second anchor node");
1068  if (GetLinkType(GetWorldLink(a.n[1],rt_world))!=LINK_NoRot)
1069  ReadTensegrityerror("Only nodes can be used to fix addons");
1070  NEW(a.p[1],3,double);
1071  a.p[1][0]=$14;
1072  a.p[1][1]=$16;
1073  a.p[1][2]=$18;
1074 
1075  a.n[2]=GetWorldLinkID($28,rt_world);
1076  if (a.n[2]==NO_UINT)
1077  ReadTensegrityerror("Undefined third anchor node");
1078  if (GetLinkType(GetWorldLink(a.n[2],rt_world))!=LINK_NoRot)
1079  ReadTensegrityerror("Only nodes can be used to fix addons");
1080  NEW(a.p[2],3,double);
1081  a.p[2][0]=$22;
1082  a.p[2][1]=$24;
1083  a.p[2][2]=$26;
1084 
1085  NewVectorElement((void *)&a,&rt_addons);
1086 
1087  free(a.p[0]);
1088  free(a.p[1]);
1089  free(a.p[2]);
1090  free(a.p);
1091 
1092  free($12);
1093  free($20);
1094  free($28);
1095  }
1096  ;
1097 
1098 shape_list : shape
1099  {
1100  AddBody2Link(&rt_cbody,&rt_link);
1101  DeletePolyhedron(&rt_cbody);
1102  }
1103  shape_list
1104  |
1105  ;
1106 
1107 forces_defs : _FORCES force_list
1108  ;
1109 
1110 force_list : force force_list
1111  |
1112  ;
1113 
1114 force : _IDENTIFIER '(' expr ',' expr ',' expr ')'
1115  {
1116  unsigned int n1;
1117  Tlink *l;
1118 
1119  n1=GetWorldLinkID($1,rt_world);
1120  if (n1==NO_UINT)
1121  ReadTensegrityerror("Undefined link");
1122  l=GetWorldLink(n1,rt_world);
1123  if (!IsForceEquilibriumLink(l))
1124  ReadTensegrityerror("Adding forces to a non-equilibrium node");
1125 
1126  AddForce2Link($3,$5,$7,l);
1127 
1128  free($1);
1129  }
1130  | _NO _NULL _FORCE ':' no_force_list
1131  ;
1132 
1133 no_force_list : no_force_id ',' no_force_list
1134  | no_force_id
1135  ;
1136 
1137 no_force_id : _IDENTIFIER
1138  {
1139  unsigned int n1;
1140  Tlink *l;
1141 
1142  n1=GetWorldLinkID($1,rt_world);
1143  if (n1==NO_UINT)
1144  ReadTensegrityerror("Undefined link");
1145 
1146  l=GetWorldLink(n1,rt_world);
1147  if (GetLinkType(l)!=LINK_NoRot)
1148  ReadTensegrityerror("Only nodes can be in equilibrium");
1149 
1151 
1152  free($1);
1153  }
1154  ;
1155 
1156 
1157 obstacle_defs : _OBSTACLES obstacle_list
1158  ;
1159 
1160 obstacle_list : obstacle_definition obstacle_list
1161  |
1162  ;
1163 
1164 obstacle_definition: _IDENTIFIER ':' shape
1165  {
1166  if (GetConstantWithName($1,&rt_constants)!=NO_UINT)
1167  ReadTensegrityerror("Obstacle with the name of a constant");
1168 
1169  if (GetWorldLinkID($1,rt_world)!=NO_UINT)
1170  ReadTensegrityerror("Obstacle with the name of a node");
1171 
1172  if (GetWorldObstacleID($1,rt_world)!=NO_UINT)
1173  ReadTensegrityerror("Duplicated obstacle");
1174 
1175  AddObstacle2World($1,&rt_cbody,rt_world);
1176 
1177  DeletePolyhedron(&rt_cbody);
1178 
1179  free($1);
1180  }
1181 
1182 
1183 shape: _BODY _STRING body_color opt_granularity opt_body_status
1184  {
1185  Tfilename fb;
1186 
1187  CreateFileName(GetFilePath(rt_filename),$2,NULL,NULL,&fb);
1188 
1189  InitPolyhedronFromFile(&fb,&($3),
1190  $4,$5,&rt_cbody);
1191 
1192  DeleteFileName(&fb);
1193  free($2);
1194  }
1195  | _BOX
1196  {
1197  rt_i=0;
1198  }
1199  point pointp body_color opt_body_status
1200  {
1201  NewBox(rt_point[0][0],rt_point[0][1],rt_point[0][2],
1202  rt_point[1][0],rt_point[1][1],rt_point[1][2],
1203  &($5),$6,&rt_cbody);
1204  }
1205  | _PRISM
1206  {
1207  rt_i=0;
1208  }
1209  point point point expr body_color opt_body_status
1210  {
1211 
1212  NewTriangularPrism(rt_point[0],rt_point[1],rt_point[2],
1213  $6,
1214  &($7),$8,&rt_cbody);
1215  }
1216  | _SPHERE expr
1217  {
1218  rt_i=0;
1219  }
1220  point body_color opt_granularity opt_body_status
1221  {
1222  NewSphere($2,rt_point[0],&($5),$6,$7,&rt_cbody);
1223  }
1224  | _CYLINDER expr
1225  {
1226  rt_i=0;
1227  }
1228  point pointp body_color opt_granularity opt_body_status
1229  {
1230  NewCylinder($2,rt_point[0],rt_point[1],&($6),2*$7,$8,&rt_cbody);
1231  }
1232  ;
1233 
1234 
1235 pointp : point
1236  | '+''(' expr ',' expr ',' expr ')'
1237  {
1238  if (rt_i==0)
1239  Error("Incremental vector in a wrong position??");
1240 
1241  rt_point[rt_i][0]=rt_point[rt_i-1][0]+$3;
1242  rt_point[rt_i][1]=rt_point[rt_i-1][1]+$5;
1243  rt_point[rt_i][2]=rt_point[rt_i-1][2]+$7;
1244  rt_i++;
1245  }
1246  ;
1247 
1248 point : '(' expr ',' expr ',' expr ')'
1249  {
1250  rt_point[rt_i][0]=$2;
1251  rt_point[rt_i][1]=$4;
1252  rt_point[rt_i][2]=$6;
1253  rt_i++;
1254  }
1255  ;
1256 
1257 color : _COLOR '(' expr ',' expr ',' expr ')'
1258  {
1259  NewColor($3,$5,$7,&($$));
1260  }
1261  | _RED
1262  {
1263  NewColorWithID(RED,&($$));
1264  }
1265  | _GREEN
1266  {
1267  NewColorWithID(GREEN,&($$));
1268  }
1269  | _BLUE
1270  {
1271  NewColorWithID(BLUE,&($$));
1272  }
1273  | _BLACK
1274  {
1275  NewColorWithID(BLACK,&($$));
1276  }
1277  | _GREY
1278  {
1279  NewColorWithID(GREY,&($$));
1280  }
1281  | _WHITE
1282  {
1283  NewColorWithID(WHITE,&($$));
1284  }
1285  | _YELLOW
1286  {
1287  NewColorWithID(YELLOW,&($$));
1288  }
1289  | _PURPLE
1290  {
1291  NewColorWithID(PURPLE,&($$));
1292  }
1293  | _CYAN
1294  {
1295  NewColorWithID(CYAN,&($$));
1296  }
1297  | _INTEGER '*' color
1298  {
1299  CopyColor(&($$),&($3));
1300  ScaleColor((double)$1,&($$));
1301  }
1302  | _REAL '*' color
1303  {
1304  CopyColor(&($$),&($3));
1305  ScaleColor($1,&($$));
1306  }
1307  | color '+' color
1308  {
1309  CopyColor(&($$),&($3));
1310  AccumulateColor(&($1),&($$));
1311  }
1312  ;
1313 
1314 
1315 
1316 body_color: color
1317  {
1318  CopyColor(&($$),&($1));
1319  }
1320  |
1321  {
1322  NewColor(DLC_R,DLC_G,DLC_B,&($$)); // default color defined in link.h
1323  }
1324  ;
1325 
1326 
1327 collision_defs : _COLLISIONS collision_list
1328  ;
1329 
1330 collision_list : collision_definition collision_list
1331  |
1332  ;
1333 
1334 collision_definition: _CHECK ':' _ALL
1335  {
1336  CheckAllCollisions(0,0,rt_world);
1337  }
1338  | _DO _NOT _CHECK ':' _ALL
1339  {
1340  NoCheckAllCollisions(0,0,rt_world);
1341  }
1342  | _DO _NOT _CHECK ':' _CONNECTED
1343  {
1344  NoCheckConnectedCollisions(0,rt_world);
1345  }
1346  | _CHECK ':' _IDENTIFIER
1347  {
1348  unsigned int id;
1349 
1350  id=GetWorldObstacleID($3,rt_world);
1351  if (id==NO_UINT)
1352  ReadTensegrityerror("Unkown obstacle when activating a collision check");
1353 
1354  CheckObstacleCollision(0,id,rt_world);
1355 
1356  free($3);
1357  }
1358  | _DO _NOT _CHECK ':' _IDENTIFIER
1359  {
1360  unsigned int id;
1361 
1362  id=GetWorldObstacleID($5,rt_world);
1363  if (id==NO_UINT)
1364  ReadTensegrityerror("Unkown obstacle when disabling a collision check");
1365 
1366  NoCheckObstacleCollision(0,id,rt_world);
1367 
1368  free($5);
1369  }
1370  | _DO _NOT _CHECK ':' _IDENTIFIER ',' _IDENTIFIER
1371  {
1372  unsigned int id1,id2;
1373 
1374  id1=GetWorldLinkID($5,rt_world);
1375  if (id1==NO_UINT)
1376  ReadTensegrityerror("Unkown link (1st id) when disabling a collision check");
1377 
1378  id2=GetWorldLinkID($7,rt_world);
1379  if (id2==NO_UINT)
1380  {
1381  id2=GetWorldObstacleID($7,rt_world);
1382  if (id2==NO_UINT)
1383  ReadTensegrityerror("Unkown link/obstacle (2st id) when disabling a collision check");
1384 
1385  NoCheckLinkObstacleCollision(id1,id2,rt_world);
1386  }
1387  else
1388  {
1389  if (id1==id2)
1390  ReadTensegrityerror("Repeated link when disabling a collision check");
1391  NoCheckLinkLinkCollision(id1,id2,rt_world);
1392  }
1393 
1394  free($5);
1395  free($7);
1396  }
1397  | _CHECK ':' _IDENTIFIER ',' _IDENTIFIER
1398  {
1399  unsigned int id1,id2;
1400 
1401  id1=GetWorldLinkID($3,rt_world);
1402  if (id1==NO_UINT)
1403  ReadTensegrityerror("Unkown link (1st id) when enabling a collision check");
1404 
1405  id2=GetWorldLinkID($5,rt_world);
1406  if (id2==NO_UINT)
1407  {
1408  id2=GetWorldObstacleID($5,rt_world);
1409  if (id2==NO_UINT)
1410  ReadTensegrityerror("Unkown link/obstacle (2st id) when enabling a collision check");
1411 
1412  CheckLinkObstacleCollision(id1,id2,rt_world);
1413  }
1414  else
1415  {
1416  if (id1==id2)
1417  ReadTensegrityerror("Repeated link when enabling a collision check");
1418  CheckLinkLinkCollision(id1,id2,rt_world);
1419  }
1420 
1421  free($3);
1422  free($5);
1423  }
1424  ;
1425 
1426 
1427 %%
1430 void CopyCouple(void *l_dst,void *l_src)
1431 {
1432  Tcouple *c_dst,*c_src;
1433 
1434  c_dst=(Tcouple*)l_dst;
1435  c_src=(Tcouple*)l_src;
1436 
1437  c_dst->type=c_src->type;
1438  c_dst->l1=c_src->l1;
1439  c_dst->l2=c_src->l2;
1440  c_dst->scale=c_src->scale;
1441  HTransformCopy(&(c_dst->t),&(c_src->t));
1442 }
1443 
1444 
1445 void CopyAddon(void *l_dst,void *l_src)
1446 {
1447  Taddon *a_dst,*a_src;
1448  unsigned int i,j;
1449 
1450  a_dst=(Taddon*)l_dst;
1451  a_src=(Taddon*)l_src;
1452 
1453  a_dst->id=a_src->id;
1454  for(i=0;i<3;i++)
1455  a_dst->n[i]=a_src->n[i];
1456 
1457  NEW(a_dst->p,3,double*);
1458  for(i=0;i<3;i++)
1459  {
1460  NEW(a_dst->p[i],3,double);
1461  for(j=0;j<3;j++)
1462  a_dst->p[i][j]=a_src->p[i][j];
1463  }
1464 }
1465 
1466 void DeleteAddon(void *l)
1467 {
1468  Taddon *a;
1469  unsigned int i;
1470 
1471  a=(Taddon*)l;
1472 
1473  for(i=0;i<3;i++)
1474  free(a->p[i]);
1475  free(a->p);
1476 }
1477 
1478 /*
1479  *
1480  */
1481 boolean InitTensegrityFromFile(Tparameters *p,char *fn,Tworld *w)
1482 {
1483  Tfilename ftensegrity;
1484  boolean ok;
1485 
1486  CreateFileName(NULL,fn,NULL,TENSEGRITY_EXT,&ftensegrity);
1487 
1488  ReadTensegrityin=fopen(GetFileFullName(&ftensegrity),"r");
1489  if (!ReadTensegrityin)
1490  ok=FALSE;
1491  else
1492  {
1493  unsigned int i;
1494  unsigned int rep;
1495  unsigned int col;
1496  unsigned int dummify;
1497  unsigned int ncouples;
1498  unsigned int naddons;
1499  Tcouple *couple;
1500  Taddon *addon;
1501 
1502  fprintf(stderr,"Reading tensegrity from : %s\n",GetFileFullName(&ftensegrity));
1503 
1504  rep=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
1505  if (rep!=REP_FLINKS)
1506  {
1507  Warning("Switching representation to FLINKS");
1509  }
1510 
1511  col=(unsigned int)(GetParameter(CT_CD_ENGINE,p));
1512  if (col!=SOLID)
1513  {
1514  Warning("Switching cd_engine to SOLID");
1516  }
1517 
1518  dummify=(unsigned int)(GetParameter(CT_DUMMIFY,p));
1519  if (dummify!=0)
1520  {
1521  Warning("Switching dummify to 0");
1523  }
1524 
1525  NEW(rt_point,4,double*);
1526  for(i=0;i<4;i++)
1527  NEW(rt_point[i],3,double);
1528 
1529  InitVector(sizeof(Tcouple),CopyCouple,NULL,100,&rt_couples);
1530  InitVector(sizeof(Taddon),CopyAddon,DeleteAddon,100,&rt_addons);
1531 
1532  InitWorld(w); /*Generate an empty tensegrity*/
1533 
1534  InitConstants(&rt_constants); /*An empty set of constants*/
1535 
1536  /*Reset the lines numbering*/
1537  RTline=1;
1538 
1539  /* No defined type */
1540  rt_type=NO_TYPE;
1541 
1542  /* flags used in element definition. At least one of them must be given */
1543  rt_hasStiffness=FALSE;
1544  rt_hasForce=FALSE;
1545 
1546  /*we initalize the global pointer to make the parameters accesibles to any one inside the YACC module*/
1547  rt_world=w;
1548  rt_filename=&ftensegrity;
1549  rt_parameters=p;
1550 
1551  /*and process the file*/
1552  ReadTensegrityparse();
1553 
1554  /* The constatns are not needed any more */
1555  DeleteConstants(&rt_constants);
1556 
1557  /* Verify that we have something */
1558  if (rt_type==NO_TYPE)
1559  ReadTensegrityerror("Tensegrity without structure?");
1560 
1561  /* Generate the kinematic equations */
1563 
1564  /* Planar structure are in the XY plane */
1565  if (rt_type==PLANAR)
1566  FixZToZero(p,w);
1567 
1568  /* Generate the force equilibrium equations */
1570 
1571  /* Fix some of the tensegrit nodes */
1572  FixLinks(p,w);
1573 
1574  /* Add an equation to the base of the tensegrity. In this way the
1575  translation variables are in the system (avoids problems with
1576  translation between original-simplified-dof systems) */
1577  ncouples=VectorSize(&rt_couples);
1578  for(i=0;i<ncouples;i++)
1579  {
1580  couple=(Tcouple*)GetVectorElement(i,&rt_couples);
1582  couple->type,couple->l1,couple->l2,
1583  couple->scale,&(couple->t),
1584  w);
1585  }
1586 
1587  /* Add the equations fixing the addons to the tensegrity structure */
1588  naddons=VectorSize(&rt_addons);
1589  for(i=0;i<naddons;i++)
1590  {
1591  addon=(Taddon*)GetVectorElement(i,&rt_addons);
1592  WorldFixTensegrityAddon(rt_parameters,addon->id,addon->p,addon->n,w);
1593  }
1594 
1595  /* Release memory */
1596  DeleteVector(&rt_addons);
1597  DeleteVector(&rt_couples);
1598  for(i=0;i<4;i++)
1599  free(rt_point[i]);
1600  free(rt_point);
1601 
1602  fclose(ReadTensegrityin);
1603 
1604  /* if we reached this point it means we correctly defined a
1605  tensegrity structure */
1606  ok=TRUE;
1607  }
1608 
1609  DeleteFileName(&ftensegrity);
1610 
1611  return(ok);
1612 }
1613 
Definition of the boolean type.
#define COUPLE_LENGTH
One of the possible variables to couple in tensegrities.
Definition: world.h:77
#define PURPLE
Purple.
Definition: color.h:72
void GenerateForceEquilibriumEquations(Tparameters *p, Tworld *w)
Adds force equilibrium equations.
Definition: world.c:2510
void DeleteVector(void *vector)
Destructor.
Definition: vector.c:389
void InitConstants(Tconstants *cts)
Initializes a constant set.
Definition: constants.c:21
#define TENSEGRITY_EXT
File extension for files describing tensegrities.
Definition: filename.h:251
void WorldCoupleTensegrityVariable(Tparameters *p, unsigned int t, unsigned int lID1, unsigned int lID2, double scale, THTransform *r, Tworld *w)
Couple variables from different elements of a tensegrity.
Definition: world.c:2889
unsigned int VectorSize(Tvector *vector)
Gets the number of elements in a vector.
Definition: vector.c:173
#define FALSE
FALSE.
Definition: boolean.h:30
double GetConstantValue(unsigned int n, Tconstants *cts)
Retrives a the value of a constant.
Definition: constants.c:113
#define REP_FLINKS
One of the possible values of the REPRESENTATION parameter.
Definition: parameters.h:37
void HTransformRx(double rx, THTransform *t)
Constructor.
Definition: htransform.c:161
Error function specific of the tensegrity parser.
Relation between two links.
Definition: joint.h:168
#define BLUE
Blue.
Definition: color.h:37
A table of constants.
Definition: constants.h:53
#define NEW(_var, _n, _type)
Allocates memory space.
Definition: defines.h:385
Data structure to hold the information about the name of a file.
Definition: filename.h:271
#define BAR
One of the possible types of legs.
Definition: world.h:142
unsigned int RTline
Number of the line currently parsed when reading a .tensegrity file.
void * GetVectorElement(unsigned int i, Tvector *vector)
Returns a pointer to a vector element.
Definition: vector.c:270
A homgeneous transform in R^3.
#define STRUT
One of the possible types of legs.
Definition: world.h:134
void FixLinks(Tparameters *p, Tworld *w)
Generate equations to fix some links.
Definition: world.c:2783
void NoCheckConnectedCollisions(unsigned int fl, Tworld *w)
Desactivates the collision detection between connected links.
Definition: world.c:2225
void NewTriangularPrism(double *p1, double *p2, double *p3, double h, Tcolor *c, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:861
#define NORMAL_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:28
#define TRUE
TRUE.
Definition: boolean.h:21
void NewSphere(double r, double *center, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:1020
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 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:2200
All the necessary information to generate equations for mechanisms.
Definition: world.h:229
void CopyColor(Tcolor *c_dst, Tcolor *c_src)
Copy constructor.
Definition: color.c:57
A color.
Definition: color.h:86
void NewBox(double xl, double yl, double zl, double xu, double yu, double zu, Tcolor *c, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:946
#define PRISMATIC_BAR
One of the possible types of legs.
Definition: world.h:171
void CheckObstacleCollision(unsigned int fl, unsigned int b, Tworld *w)
Activates the possible collision between a particular obstacle and all the links. ...
Definition: world.c:2209
void NoCheckAllCollisions(unsigned int fl, unsigned int fo, Tworld *w)
Desactivates all the possible collision between links and links and obstacles.
Definition: world.c:2119
CBLAS_INLINE void HTransformProduct(THTransform *t1, THTransform *t2, THTransform *t3)
Product of two homogeneous transforms.
Definition: htransform.c:410
#define ZERO
Floating point operations giving a value below this constant (in absolute value) are considered 0...
Definition: defines.h:37
void CopyInterval(Tinterval *i_dst, Tinterval *i_org)
Copy constructor.
Definition: interval.c:59
#define WHITE
White.
Definition: color.h:58
void NoCheckObstacleCollision(unsigned int fl, unsigned int b, Tworld *w)
Deactivates the possible collision between a particular obstacle and all the links.
Definition: world.c:2217
Definition of the Tworld type and the associated functions.
A polyhedron.
Definition: polyhedron.h:134
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
#define BLACK
Black.
Definition: color.h:44
void CheckAllCollisions(unsigned int fl, unsigned int fo, Tworld *w)
Activates all the possible collision between links and links and obstacles.
Definition: world.c:2097
void AddLeg2World(char *name, boolean planar, unsigned int type, unsigned int lID1, unsigned int lID2, double **points, Tinterval *length, double stiffness, Tinterval *rest, Tinterval *force, double radius, unsigned int gr, Tcolor *color, unsigned int bs, Tworld *w)
Adds a sph-sph joint to the world.
Definition: world.c:1446
void NewFreeJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, Tjoint *j)
Constructor.
Definition: joint.c:93
void HTransformRz(double rz, THTransform *t)
Constructor.
Definition: htransform.c:195
unsigned int GetWorldObstacleID(char *obsName, Tworld *w)
Gets the identifier of an obstacle from its name.
Definition: world.c:1837
double LowerLimit(Tinterval *i)
Gets the lower limit.
Definition: interval.c:79
unsigned int id
Definition: joint.h:172
void GenerateWorldEquations(Tparameters *p, Tworld *w)
Generates all the cuiksystems derived from the world information.
Definition: world.c:2431
void AddObstacle2World(char *name, Tpolyhedron *o, Tworld *w)
Adds an obstacle to the environment in the world.
Definition: world.c:1788
unsigned int AddLink2World(Tlink *l, boolean object, Tworld *w)
Adds a link to the mechanism in the world.
Definition: world.c:1383
void InitVector(unsigned int ele_size, void(*Copy)(void *, void *), void(*Delete)(void *), unsigned int max_ele, Tvector *vector)
Constructor.
Definition: vector.c:100
#define M_PI_2
Pi/2.
Definition: defines.h:92
int ReadTensegrityerror(const char *s)
Syntax errors in .tensegrity files.
void ScaleColor(double s, Tcolor *c)
Scales a color.
Definition: color.c:76
#define CT_CD_ENGINE
Collision detection engine.
Definition: parameters.h:542
void DeleteInterval(Tinterval *i)
Destructor.
Definition: interval.c:1021
#define YELLOW
Yellow.
Definition: color.h:65
#define GREEN
Green.
Definition: color.h:30
void Warning(const char *s)
General warning function.
Definition: error.c:116
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
#define GREY
Grey.
Definition: color.h:51
void NewCylinder(double r, double *p1, double *p2, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:1044
unsigned int AddJoint2World(Tjoint *j, Tworld *w)
Adds a joint to the mechanism in the world.
Definition: world.c:1436
void FixZToZero(Tparameters *p, Tworld *w)
Generate equations to fix the Z components of the links.
Definition: world.c:2867
double UpperLimit(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:87
unsigned int AddConstant(char *name, double v, Tconstants *cts)
Add a constant.
Definition: constants.c:65
void InitPolyhedronFromFile(Tfilename *fname, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:727
A generic vector.
Definition: vector.h:227
boolean InitTensegrityFromFile(Tparameters *p, char *fn, Tworld *w)
Constructor.
char * GetFileFullName(Tfilename *fn)
Gets the file full name (paht+name+extension).
Definition: filename.c:151
#define M_PI
Pi.
Definition: defines.h:83
#define CT_REPRESENTATION
Representation.
Definition: parameters.h:215
void CheckLinkLinkCollision(unsigned int a, unsigned int b, Tworld *w)
Activates the possible collision between a particular pair of links.
Definition: world.c:2167
#define CT_DUMMIFY
Dummification level.
Definition: parameters.h:339
boolean ZeroInterval(Tinterval *i)
Checks if a given interval is zero.
Definition: interval.c:340
Definition of the Tpolyhedron type and the associated functions.
#define NO_UINT
Used to denote an identifier that has not been initialized.
Definition: defines.h:435
unsigned int GetWorldLinkID(char *linkName, Tworld *w)
Gets the identifier of a link from its name.
Definition: world.c:1832
#define CYAN
Cyan.
Definition: color.h:79
Definition of the Tvector type and the associated functions.
boolean EmptyInterval(Tinterval *i)
Checks if a given interval is empty.
Definition: interval.c:335
Tlink * GetWorldLink(unsigned int linkID, Tworld *w)
Gets a link from its identifier.
Definition: world.c:1842
void NoCheckLinkLinkCollision(unsigned int a, unsigned int b, Tworld *w)
Desactivates the possible collision between a particular pair of links.
Definition: world.c:2179
unsigned int GetWorldNJoints(Tworld *w)
Gets the number of joints in the mechanism included in the world.
Definition: world.c:1857
void HTransformDelete(THTransform *t)
Destructor.
Definition: htransform.c:887
unsigned int GetConstantWithName(char *name, Tconstants *cts)
Retrives a constant from the set.
Definition: constants.c:88
#define CABLE
One of the possible types of legs.
Definition: world.h:150
double GetParameter(unsigned int n, Tparameters *p)
Gets the value for a particular parameter.
Definition: parameters.c:93
void InitWorld(Tworld *w)
Constructor.
Definition: world.c:1358
void DeletePolyhedron(Tpolyhedron *p)
Destructor.
Definition: polyhedron.c:1692
void AccumulateColor(Tcolor *c1, Tcolor *c)
Adds a color.
Definition: color.c:83
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
#define INF
Infinite.
Definition: defines.h:70
#define COUPLE_REST
One of the possible variables to couple in tensegrities.
Definition: world.h:85
#define RED
Red.
Definition: color.h:23
#define COUPLE_FORCE
One of the possible variables to couple in tensegrities.
Definition: world.h:93
void HTransformCopy(THTransform *t_dst, THTransform *t_src)
Copy constructor.
Definition: htransform.c:83
void DeleteConstants(Tconstants *cts)
Destructor.
Definition: constants.c:137
void NewColor(double r, double g, double b, Tcolor *c)
Constructor.
Definition: color.c:14
unsigned int GetParameterID(char *name, Tparameters *p)
Returns the parameter identifier given the paramete name.
Definition: parameters.c:110
Defines a interval.
Definition: interval.h:33
void HTransformRy(double ry, THTransform *t)
Constructor.
Definition: htransform.c:178
void ChangeParameter(unsigned int n, double v, Tparameters *p)
Sets the value for a particular parameter.
Definition: parameters.c:164
void HTransformIdentity(THTransform *t)
Constructor.
Definition: htransform.c:69
double IntervalSize(Tinterval *i)
Gets the uppser limit.
Definition: interval.c:96
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:2191
#define SPRING
One of the possible types of legs.
Definition: world.h:159
void DeleteJoint(Tjoint *j)
Destructor.
Definition: joint.c:3190
#define COUPLE_ORIENTATION
One of the possible variables to couple in tensegrities.
Definition: world.h:104
void NewColorWithID(unsigned int id, Tcolor *c)
Constructor.
Definition: color.c:21
void NewPrismaticJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, double **points, Tinterval *range, boolean avoidLimits, double avoidLimitsWeight, Tjoint *j)
Constructor.
Definition: joint.c:533
#define SOLID
One of the possible collison detection engines.
Definition: parameters.h:69
unsigned int NewVectorElement(void *e, Tvector *vector)
Adds an element to the vector.
Definition: vector.c:216
void WorldFixTensegrityAddon(Tparameters *p, unsigned int linkID, double **point, unsigned int *n, Tworld *w)
Fixes a tensegrity addon.
Definition: world.c:2819
#define DECOR_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:46
#define HIDDEN_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:37