readworld.y
Go to the documentation of this file.
1 %{
3 #include "world.h"
4 
5 #include "boolean.h"
6 #include "error.h"
7 #include "error_world.h"
8 #include "constants.h"
9 #include "defines.h"
10 #include "color.h"
11 #include "htransform.h"
12 #include "vector.h"
13 
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <string.h>
17 #include <math.h>
18 
19 /*
20 * Definition of the function that initilizes a kinematic equations from a file.
21 * This is a method of the equations object.
22 */
23 
24  /*Lex and Yacc variables*/
25  extern FILE *ReadWorldin;
26 
27  /* first link/object in the file currently bein parsed */
28  extern unsigned int firstLink; /* first link in the current object */
29  extern unsigned int firstObject; /* first object in the current file */
30 
31  /*Lex and Yacc functions*/
32  int ReadWorldlex(void);
33  void Switch2File(char *ln,unsigned int nl,unsigned int no,char *path,char *file);
34 
35  /*Our own variables*/
36  extern unsigned int RWline; /* line number currently processed
37  (incremented by the LEX processor)*/
38 
39  /*Auxiliary variables used along readwordl*/
40  unsigned int rw_lID,rw_lID1,rw_lID2; /*link identifier*/
41  Tlink rw_link;
42  Tjoint rw_joint;
43  boolean rw_visible;
44 
45  /* Global pointer to allow the different parts of the parser to acces the
46  equations being initialized*/
47  Tworld *rw_world;
48 
49  THTransform rw_transform;
50 
51  unsigned int rw_r;
52 
53  double **rw_point;
54  unsigned int rw_i,rw_max;
55  double *rw_X,*rw_Y,*rw_Z;
56  double rw_angle;
57  Tinterval rw_range,rw_range0;
58  boolean rw_has_limits;
59  double **rw_range_point;
60  double **rw_in_patch_point;
61  Tcolor rw_color_default,rw_color_body;
62  Tfilename *rw_filename;
63  Tpolyhedron rw_cbody;
64  boolean rw_endEffector;
65 
66  Tconstants rw_constants;
67 
68  boolean rw_avoidLimits;
69  double rw_avoidLimitsWeight;
70 
71  boolean rw_prevolute;
72 %}
73 
74 %union
75 {
76  char *id;
77  char *string;
78  int int_number;
79  double real_number;
80  double color[3];
81 }
82 
83 %start world
84 
85 %token _CONSTANTS _ASSIGN _PI _COS _SIN _SQRT _LINKS _JOINTS _OBSTACLES _COLLISIONS _CHECK _NO _ALL _BODY _GRANULARITY _FIX _ID _TX _TY _TZ _TXYZ _RX _RY _RZ _PRISMATIC _REVOLUTE _CREVOLUTE _SPHERICAL _UNIVERSAL _SPH_SPH _SPH_PRS_SPH _IN_PATCH _BOX _SPHERE _CYLINDER _LINE _SEGMENTS _LENGTH _RADIUS _SELFCOLLISIONS _RANGE _COLOR _RED _GREEN _BLUE _PURPLE _CYAN _YELLOW _WHITE _BLACK _GREY _DECORATION _HIDDEN _AVOID _LIMITS _INCLUDE
86 
87 %token <id> _IDENTIFIER
88 %token <id> _EXT_IDENTIFIER
89 %token <int_number> _INTEGER
90 %token <real_number> _REAL
91 %token <string> _STRING
92 
93 %type <int_number> granularity
94 %type <int_number> shape_status
95 %type <real_number> expr
96 %type <color> color
97 %type <id> any_id
98 
99 %left '+' '-'
100 %left '*' '/'
101 %left '^'
102 %right _MAX_PRECEDENCE
103 %%
104 
105 world : world def_block
106  |
107  ;
108 
109 def_block : constant_defs
110  | link_defs
111  | joint_defs
112  | obstacle_defs
113  | collision_defs
114  | included_defs
115  ;
116 
117 constant_defs: _CONSTANTS constant_list
118  ;
119 
120 constant_list : constant_definition constant_list
121  |
122  ;
123 
124 constant_definition : _IDENTIFIER _ASSIGN expr
125  {
126  if (GetConstantWithName($1,&rw_constants)!=NO_UINT)
127  {
128  char s[200];
129 
130  sprintf(s,"Duplicated constant %s",$1);
131  ReadWorlderror(s);
132  }
133 
134  AddConstant($1,$3,&rw_constants);
135  free($1);
136  }
137  ;
138 
139 any_id : _IDENTIFIER
140  {
141  $$=$1; /* do not free $1, we will free $$ */
142  }
143  | _EXT_IDENTIFIER
144  {
145  $$=$1; /* do not free $1, we will free $$ */
146  }
147  ;
148 
149 expr : '+' expr %prec _MAX_PRECEDENCE
150  {
151  $$=$2;
152  }
153  | '-' expr %prec _MAX_PRECEDENCE
154  {
155  $$=-$2;
156  }
157  | expr '+' expr
158  {
159  $$=$1+$3;
160  }
161  | expr '-' expr
162  {
163  $$=$1-$3;
164  }
165  | expr '*' expr
166  {
167  $$=$1*$3;
168  }
169  | expr '^' expr
170  {
171  $$=pow($1,$3);
172  }
173  | expr '/' expr
174  {
175  if ($3==0.0)
176  ReadWorlderror("Division by zero");
177 
178  $$=$1/$3;
179  }
180  | '(' expr ')'
181  {
182  $$=$2;
183  }
184  | _PI
185  {
186  $$=M_PI;
187  }
188  | _SIN '(' expr ')'
189  {
190  $$=sin($3);
191  }
192  | _COS '(' expr ')'
193  {
194  $$=cos($3);
195  }
196  | _SQRT '(' expr ')'
197  {
198  $$=sqrt($3);
199  }
200  | any_id
201  {
202  unsigned int nc;
203 
204  nc=GetConstantWithName($1,&rw_constants);
205 
206  if (nc!=NO_UINT)
207  $$=GetConstantValue(nc,&rw_constants);
208  else
209  {
210  char ms[200];
211  sprintf(ms,"Undefined constant: %s",$1);
212  ReadWorlderror(ms);
213  }
214  free($1);
215  }
216  | _INTEGER
217  {
218  $$=(double)$1;
219  }
220  | _REAL
221  {
222  $$=$1;
223  }
224  ;
225 
226 link_defs : _LINKS link_list
227  ;
228 
229 link_list : link_definition link_list
230  |
231  ;
232 
233 link_definition: _IDENTIFIER
234  {
235  if (GetConstantWithName($1,&rw_constants)!=NO_UINT)
236  ReadWorlderror("Link with the name of a constant");
237 
238  if (GetWorldLinkID($1,rw_world)!=NO_UINT)
239  ReadWorlderror("Duplicated link");
240 
241  /*adds an empty link to the world*/
242  InitLink($1,&rw_link);
243 
244  free($1);
245  }
246  opt_link_definition
247  {
248  AddLink2World(&rw_link,rw_endEffector,rw_world);
249  DeleteLink(&rw_link);
250  }
251  ;
252 
253 
254 opt_link_definition : link_separator link_color link_shapes
255  |
256  ;
257 
258 link_separator : ':'
259  {
260  rw_endEffector=FALSE;
261  }
262  | '>'
263  {
264  rw_endEffector=TRUE;
265  }
266  ;
267 
268 link_shapes : shape
269  {
270  AddBody2Link(&rw_cbody,&rw_link);
271  DeletePolyhedron(&rw_cbody);
272  }
273  link_shapes
274  | shape
275  {
276  AddBody2Link(&rw_cbody,&rw_link);
277  DeletePolyhedron(&rw_cbody);
278  }
279  ;
280 
281 shape: _BODY _STRING body_color granularity shape_status
282  {
283  Tfilename fb;
284 
285  CreateFileName(GetFilePath(rw_filename),$2,NULL,NULL,&fb);
286 
287  InitPolyhedronFromFile(&fb,&rw_color_body,
288  $4,$5,&rw_cbody);
289 
290  DeleteFileName(&fb);
291  free($2);
292  }
293  | _BOX
294  {
295  rw_i=0;
296  rw_lID=NO_UINT;
297  }
298  point pointp body_color shape_status
299  {
300  NewBox(rw_point[0][0],rw_point[0][1],rw_point[0][2],
301  rw_point[1][0],rw_point[1][1],rw_point[1][2],
302  &rw_color_body,$6,&rw_cbody);
303  }
304  | _SPHERE expr
305  {
306  rw_i=0;
307  rw_lID=NO_UINT;
308  }
309  point body_color granularity shape_status
310  {
311  NewSphere($2,rw_point[0],&rw_color_body,$6,$7,&rw_cbody);
312  }
313  | _CYLINDER expr
314  {
315  rw_i=0;
316  rw_lID=NO_UINT;
317  }
318  point pointp body_color granularity shape_status
319  {
320  NewCylinder($2,rw_point[0],rw_point[1],&rw_color_body,2*$7,$8,&rw_cbody);
321  }
322  | _LINE
323  {
324  rw_i=0;
325  rw_lID=NO_UINT;
326  }
327  point pointp body_color shape_status
328  {
329  NewLine(rw_point[0],rw_point[1],&rw_color_body,$6,&rw_cbody);
330  }
331  | _SEGMENTS
332  {
333  rw_i=0;
334  rw_max=100;
335  NEW(rw_X,rw_max,double);
336  NEW(rw_Y,rw_max,double);
337  NEW(rw_Z,rw_max,double);
338  rw_lID=NO_UINT;
339  }
340  point_list body_color
341  {
342  NewSegments(rw_i,rw_X,rw_Y,rw_Z,&rw_color_body,&rw_cbody);
343  free(rw_X);
344  free(rw_Y);
345  free(rw_Z);
346  }
347  ;
348 
349 granularity : _GRANULARITY ':' _INTEGER
350  {
351  $$=$3;
352  }
353  |
354  {
355  $$=5;
356  }
357 
358  ;
359 
360 shape_status : _HIDDEN
361  {
362  $$=HIDDEN_SHAPE;
363  }
364  | _DECORATION
365  {
366  $$=DECOR_SHAPE;
367  }
368  |
369  {
370  $$=NORMAL_SHAPE;
371  }
372  ;
373 
374 color : _COLOR '(' expr ',' expr ',' expr ')'
375  {
376  $$[0]=$3;
377  $$[1]=$5;
378  $$[2]=$7;
379  }
380  | _RED
381  {
382  $$[0]=1;
383  $$[1]=0;
384  $$[2]=0;
385  }
386  | _GREEN
387  {
388  $$[0]=0;
389  $$[1]=1;
390  $$[2]=0;
391  }
392  | _BLUE
393  {
394  $$[0]=0;
395  $$[1]=0;
396  $$[2]=1;
397  }
398  | _BLACK
399  {
400  $$[0]=0;
401  $$[1]=0;
402  $$[2]=0;
403  }
404  | _GREY
405  {
406  $$[0]=0.7;
407  $$[1]=0.7;
408  $$[2]=0.7;
409  }
410  | _WHITE
411  {
412  $$[0]=1;
413  $$[1]=1;
414  $$[2]=1;
415  }
416  | _YELLOW
417  {
418  $$[0]=1;
419  $$[1]=1;
420  $$[2]=0;
421  }
422  | _PURPLE
423  {
424  $$[0]=1;
425  $$[1]=0;
426  $$[2]=1;
427  }
428  | _CYAN
429  {
430  $$[0]=0;
431  $$[1]=1;
432  $$[2]=1;
433  }
434  | _INTEGER '*' color
435  {
436  unsigned int i;
437 
438  for(i=0;i<3;i++)
439  $$[i]=(double)$1*$3[i];
440  }
441  | _REAL '*' color
442  {
443  unsigned int i;
444 
445  for(i=0;i<3;i++)
446  $$[i]=$1*$3[i];
447  }
448  | color '+' color
449  {
450  unsigned int i;
451 
452  for(i=0;i<3;i++)
453  $$[i]=$1[i]+$3[i];
454  }
455  ;
456 
457 link_color: color
458  {
459  NewColor($1[0],$1[1],$1[2],&rw_color_default);
460  }
461  |
462  {
463  NewColor(DLC_R,DLC_G,DLC_B,&rw_color_default);
464  }
465  ;
466 
467 body_color: color
468  {
469  NewColor($1[0],$1[1],$1[2],&rw_color_body);
470  }
471  |
472  {
473  CopyColor(&rw_color_body,&rw_color_default);
474  }
475  ;
476 
477 joint_defs : _JOINTS joint_list
478  ;
479 
480 joint_list : joint_definition joint_list
481  |
482  ;
483 
484 joint_definition: fix_joint
485  | prismatic_joint
486  | revolute_joint
487  | crevolute_joint
488  | spherical_joint
489  | universal_joint
490  | sph_sph_joint
491  | sph_prs_sph_joint
492  | in_patch_joint
493  ;
494 
495 fix_joint : _FIX ':' any_id any_id
496  {
497  HTransformIdentity(&rw_transform);
498  }
499  transforms
500  {
501  unsigned int id1,id2;
502 
503  id1=GetWorldLinkID($3,rw_world);
504  if (id1==NO_UINT)
505  ReadWorlderror("Unkown link (1st id) when defining a fix joint");
506 
507  id2=GetWorldLinkID($4,rw_world);
508  if (id2==NO_UINT)
509  ReadWorlderror("Unkown link (2st id) when allowing a fix joint");
510 
511  NewFixJoint(GetWorldNJoints(rw_world),
512  id1,GetWorldLink(id1,rw_world),
513  id2,GetWorldLink(id2,rw_world),
514  &rw_transform,&rw_joint);
515 
516  AddJoint2World(&rw_joint,rw_world);
517 
518  DeleteJoint(&rw_joint);
519  free($3);
520  free($4);
521 
522  HTransformDelete(&rw_transform);
523 
524  rw_prevolute=FALSE;
525  }
526  ;
527 
528 transforms: transform '*' transforms
529  | transform
530  ;
531 
532 transform : _ID
533  {
534  /* Nothing need to be done */
535  }
536  |
537  _TX '(' expr ')'
538  {
539  THTransform t;
540 
541  HTransformTx($3,&t);
542 
543  HTransformProduct(&rw_transform,&t,&rw_transform);
544  }
545  | _TY '(' expr ')'
546  {
547  THTransform t;
548 
549  HTransformTy($3,&t);
550 
551  HTransformProduct(&rw_transform,&t,&rw_transform);
552  }
553  | _TZ '(' expr ')'
554  {
555  THTransform t;
556 
557  HTransformTz($3,&t);
558 
559  HTransformProduct(&rw_transform,&t,&rw_transform);
560  }
561  | _TXYZ '(' expr ',' expr ',' expr')'
562  {
563  THTransform t;
564 
565  HTransformTxyz($3,$5,$7,&t);
566 
567  HTransformProduct(&rw_transform,&t,&rw_transform);
568  }
569  | _RX '(' expr ')'
570  {
571  THTransform t;
572 
573  HTransformRx($3,&t);
574 
575  HTransformProduct(&rw_transform,&t,&rw_transform);
576  }
577  | _RY '(' expr ')'
578  {
579  THTransform t;
580 
581  HTransformRy($3,&t);
582 
583  HTransformProduct(&rw_transform,&t,&rw_transform);
584  }
585  | _RZ '(' expr ')'
586  {
587  THTransform t;
588 
589  HTransformRz($3,&t);
590 
591  HTransformProduct(&rw_transform,&t,&rw_transform);
592  }
593  ;
594 
595 prismatic_joint: _PRISMATIC ':'
596  any_id
597  {
598  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
599  if (rw_lID1==NO_UINT)
600  ReadWorlderror("Unkown link (1st id) when defining a prismatic joint");
601 
602  rw_i=0;
603  }
604  point pointp
605  any_id
606  {
607  rw_lID2=rw_lID=GetWorldLinkID($7,rw_world);
608  if (rw_lID2==NO_UINT)
609  ReadWorlderror("Unkown link (2st id) when allowing a prismatic joint");
610  }
611  point pointp
612  _RANGE range
613  avoid_limits
614  {
616  rw_lID1,GetWorldLink(rw_lID1,rw_world),
617  rw_lID2,GetWorldLink(rw_lID2,rw_world),
618  rw_point,&rw_range,
619  rw_avoidLimits,rw_avoidLimitsWeight,
620  &rw_joint);
621 
622  AddJoint2World(&rw_joint,rw_world);
623 
624  DeleteJoint(&rw_joint);
625  free($3);
626  free($7);
627 
628  rw_prevolute=FALSE;
629  }
630  ;
631 
632 point : '(' expr ',' expr ',' expr ')'
633  {
634  rw_point[rw_i][0]=$2;
635  rw_point[rw_i][1]=$4;
636  rw_point[rw_i][2]=$6;
637  rw_i++;
638  }
639  | _INTEGER
640  {
641  Tpolyhedron *b;
642 
643  if (rw_lID==NO_UINT)
644  ReadWorlderror("Reference to body points can only be used inside joint definition");
645  b=GetLinkBody(0,GetWorldLink(rw_lID,rw_world));
646  GetPolyhedronDefiningPoint($1,rw_point[rw_i],b);
647  rw_i++;
648  }
649  | _INTEGER ':' _INTEGER
650  {
651  Tpolyhedron *b;
652 
653  if (rw_lID==NO_UINT)
654  ReadWorlderror("Reference to body points can only be used inside joint definition");
655  b=GetLinkBody($1,GetWorldLink(rw_lID,rw_world));
656  GetPolyhedronDefiningPoint($3,rw_point[rw_i],b);
657  rw_i++;
658  }
659  ;
660 
661 pointp : point
662  | '+''(' expr ',' expr ',' expr ')'
663  {
664  if (rw_i==0)
665  Error("Incremental vector in a wrong position??");
666 
667  rw_point[rw_i][0]=rw_point[rw_i-1][0]+$3;
668  rw_point[rw_i][1]=rw_point[rw_i-1][1]+$5;
669  rw_point[rw_i][2]=rw_point[rw_i-1][2]+$7;
670  rw_i++;
671  }
672  ;
673 
674 point_list : '(' coordinates3D ')'
675  ;
676 
677 coordinates3D : xyz ';' coordinates3D
678  | xyz
679  ;
680 
681 xyz : expr ',' expr ',' expr
682  {
683  if (rw_i==rw_max)
684  {
685  MEM_DUP(rw_X,rw_max,double);
686  MEM_EXPAND(rw_Y,rw_max,double);
687  MEM_EXPAND(rw_Z,rw_max,double);
688  }
689  rw_X[rw_i]=$1;
690  rw_Y[rw_i]=$3;
691  rw_Z[rw_i]=$5;
692  rw_i++;
693  }
694 
695 
696 range : '[' expr ',' expr ']'
697  {
698  NewInterval($2,$4,&rw_range);
699  if (EmptyInterval(&rw_range))
700  ReadWorlderror("Empty range");
701  }
702  ;
703 
704 revolute_joint: _REVOLUTE ':'
705  any_id
706  {
707  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
708  if (rw_lID1==NO_UINT)
709  ReadWorlderror("Unkown link (1st id) when defining a revolute joint");
710 
711  rw_i=0;
712  }
713  point pointp
714  any_id
715  {
716  rw_lID2=rw_lID=GetWorldLinkID($7,rw_world);
717  if (rw_lID2==NO_UINT)
718  ReadWorlderror("Unkown link (2st id) when allowing a revolute joint");
719  }
720  point pointp
721  opt_revolute_range
722  {
723  NewRevoluteJoint(GetWorldNJoints(rw_world),rw_r,
724  rw_lID1,GetWorldLink(rw_lID1,rw_world),
725  rw_lID2,GetWorldLink(rw_lID2,rw_world),
726  rw_point,
727  rw_has_limits,&rw_range,rw_range_point,
728  rw_avoidLimits,rw_avoidLimitsWeight,NULL,
729  &rw_joint);
730 
731  AddJoint2World(&rw_joint,rw_world);
732 
733  DeleteJoint(&rw_joint);
734  free($3);
735  free($7);
736 
737  rw_prevolute=TRUE;
738  }
739  ;
740 
741 crevolute_joint: _CREVOLUTE ':'
742  any_id
743  {
744  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
745  if (rw_lID1==NO_UINT)
746  ReadWorlderror("Unkown link (1st id) when defining a revolute joint");
747 
748  rw_i=0;
749  }
750  point pointp
751  any_id
752  {
753  rw_lID2=rw_lID=GetWorldLinkID($7,rw_world);
754  if (rw_lID2==NO_UINT)
755  ReadWorlderror("Unkown link (2st id) when allowing a revolute joint");
756  }
757  point pointp
758  opt_revolute_range
759  {
760  unsigned int id,k;
761  Tjoint *jp;
762 
763  id=GetWorldNJoints(rw_world);
764 
765  if ((!rw_prevolute)||(id<1))
766  ReadWorlderror("Coupled revolute joints need a previous revolute joint");
767 
768  id=GetWorldNJoints(rw_world);
769  k=id;
770  /* take into account that we can have a chain of coupled joints: determine the
771  original non-coupled joints (only revolute joints can be coupled) */
772  do {
773  k--;
774  jp=GetWorldJoint(k,rw_world);
775  } while ((k>0)&&(GetJointType(jp)==REV_JOINT)&&(CoupledWith(jp)!=NO_UINT));
776  if ((GetJointType(jp)!=REV_JOINT)||(CoupledWith(jp)!=NO_UINT))
777  Error("Error defining a chain of coupled revolute joints");
778 
779  NewRevoluteJoint(id,rw_r,
780  rw_lID1,GetWorldLink(rw_lID1,rw_world),
781  rw_lID2,GetWorldLink(rw_lID2,rw_world),
782  rw_point,
783  rw_has_limits,&rw_range,rw_range_point,
784  rw_avoidLimits,rw_avoidLimitsWeight,jp,
785  &rw_joint);
786 
787  AddJoint2World(&rw_joint,rw_world);
788 
789  DeleteJoint(&rw_joint);
790  free($3);
791  free($7);
792 
793  rw_prevolute=TRUE;
794  }
795  ;
796 
797 spherical_joint : _SPHERICAL ':'
798  any_id
799  {
800  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
801  if (rw_lID1==NO_UINT)
802  ReadWorlderror("Unkown link (1st id) when defining a spherical joint");
803 
804  rw_i=0;
805  }
806  point
807  any_id
808  {
809  rw_lID2=rw_lID=GetWorldLinkID($6,rw_world);
810  if (rw_lID2==NO_UINT)
811  ReadWorlderror("Unkown link (2st id) when allowing a spherical joint");
812 
813  /*We skip points[1] since the (incremental) range definition
814  assumes the displacement is given w.r.t. points[2] */
815  rw_i++;
816  }
817  point
818  opt_spherical_range
819  {
821  rw_lID1,GetWorldLink(rw_lID1,rw_world),
822  rw_lID2,GetWorldLink(rw_lID2,rw_world),
823  rw_point,
824  rw_has_limits,rw_angle,rw_range_point,
825  rw_avoidLimits,rw_avoidLimitsWeight,
826  &rw_joint);
827 
828  AddJoint2World(&rw_joint,rw_world);
829 
830  DeleteJoint(&rw_joint);
831  free($3);
832  free($6);
833 
834  rw_prevolute=FALSE;
835  }
836  ;
837 
838 universal_joint : _UNIVERSAL ':'
839  any_id
840  {
841  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
842  if (rw_lID1==NO_UINT)
843  ReadWorlderror("Unkown link (1st id) when defining a universal joint");
844 
845  rw_i=0;
846  }
847  point pointp
848  any_id
849  {
850  rw_lID2=rw_lID=GetWorldLinkID($7,rw_world);
851 
852  if (rw_lID2==NO_UINT)
853  ReadWorlderror("Unkown link (2nd id) when defining a universal joint");
854  }
855  point pointp
856  opt_universal_range
857  {
858  NewUniversalJoint(GetWorldNJoints(rw_world),rw_r,
859  rw_lID1,GetWorldLink(rw_lID1,rw_world),
860  rw_lID2,GetWorldLink(rw_lID2,rw_world),
861  rw_point,
862  rw_has_limits,&rw_range0,&rw_range,rw_range_point,
863  rw_avoidLimits,rw_avoidLimitsWeight,
864  &rw_joint);
865 
866  AddJoint2World(&rw_joint,rw_world);
867 
868  DeleteJoint(&rw_joint);
869  free($3);
870  free($7);
871 
872  rw_prevolute=FALSE;
873  }
874  ;
875 
876 sph_sph_joint: _SPH_SPH ':'
877  any_id
878  {
879  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
880  if (rw_lID1==NO_UINT)
881  ReadWorlderror("Unkown link (1st id) when defining a spherical-spherical joint");
882 
883  rw_i=0;
884  }
885  point
886  any_id
887  {
888  rw_lID2=rw_lID=GetWorldLinkID($6,rw_world);
889  if (rw_lID2==NO_UINT)
890  ReadWorlderror("Unkown link (2st id) when defining a spherical-spherical joint");
891  }
892  point
893  _LENGTH expr
894  _RADIUS expr
895  link_color
896  {
898  rw_lID1,GetWorldLink(rw_lID1,rw_world),
899  rw_lID2,GetWorldLink(rw_lID2,rw_world),
900  rw_point,$10,$12,&rw_color_default,
901  &rw_joint);
902 
903  AddJoint2World(&rw_joint,rw_world);
904 
905  DeleteJoint(&rw_joint);
906  free($3);
907  free($6);
908 
909  rw_prevolute=FALSE;
910  }
911  ;
912 
913 sph_prs_sph_joint: _SPH_PRS_SPH ':'
914  any_id
915  {
916  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
917  if (rw_lID1==NO_UINT)
918  ReadWorlderror("Unkown link (1st id) when defining a spherical-spherical joint");
919 
920  rw_i=0;
921  }
922  point
923  any_id
924  {
925  rw_lID2=rw_lID=GetWorldLinkID($6,rw_world);
926  if (rw_lID2==NO_UINT)
927  ReadWorlderror("Unkown link (2st id) when defining a spherical-spherical joint");
928  }
929  point
930  _RANGE range
931  _RADIUS expr
932  link_color
933  {
935  rw_lID1,GetWorldLink(rw_lID1,rw_world),
936  rw_lID2,GetWorldLink(rw_lID2,rw_world),
937  rw_point,&rw_range,$12,&rw_color_default,
938  &rw_joint);
939 
940  AddJoint2World(&rw_joint,rw_world);
941 
942  DeleteJoint(&rw_joint);
943  free($3);
944  free($6);
945 
946  rw_prevolute=FALSE;
947  }
948  ;
949 
950 in_patch_joint : _IN_PATCH ':'
951  any_id
952  {
953  rw_lID1=rw_lID=GetWorldLinkID($3,rw_world);
954  if (rw_lID1==NO_UINT)
955  ReadWorlderror("Unkown link (1st id) when defining a in_patch joint");
956 
957  rw_i=0;
958  }
959  point pointp
960  {
961  /*save the points in a different location*/
962  unsigned int i,j;
963 
964  for(i=0;i<2;i++)
965  {
966  for(j=0;j<3;j++)
967  rw_in_patch_point[i][j]=rw_point[i][j];
968  }
969 
970  rw_i=0;
971  }
972  any_id
973  {
974  rw_lID2=rw_lID=GetWorldLinkID($8,rw_world);
975  if (rw_lID2==NO_UINT)
976  ReadWorlderror("Unkown link (2st id) when defining a in_patch joint");
977  }
978  point point point point
979  avoid_limits
980  {
982  rw_lID1,GetWorldLink(rw_lID1,rw_world),
983  rw_lID2,GetWorldLink(rw_lID2,rw_world),
984  rw_in_patch_point,rw_point,
985  rw_avoidLimits,rw_avoidLimitsWeight,
986  &rw_joint);
987 
988  AddJoint2World(&rw_joint,rw_world);
989 
990  DeleteJoint(&rw_joint);
991  free($3);
992  free($8);
993 
994  rw_prevolute=FALSE;
995  }
996  ;
997 
998 rpointp : '(' expr ',' expr ',' expr ')'
999  {
1000  rw_range_point[rw_i][0]=$2;
1001  rw_range_point[rw_i][1]=$4;
1002  rw_range_point[rw_i][2]=$6;
1003  rw_i++;
1004  }
1005  | '+' '(' expr ',' expr ',' expr ')'
1006  {
1007  rw_range_point[rw_i][0]=rw_point[2*rw_i][0]+$3;
1008  rw_range_point[rw_i][1]=rw_point[2*rw_i][1]+$5;
1009  rw_range_point[rw_i][2]=rw_point[2*rw_i][2]+$7;
1010  rw_i++;
1011  }
1012  ;
1013 
1014 opt_revolute_range: _RANGE
1015  {
1016  rw_i=0;
1017  rw_has_limits=TRUE;
1018  }
1019  range
1020  rpointp rpointp
1021  avoid_limits
1022  |
1023  {
1024  rw_has_limits=FALSE;
1025  }
1026  ;
1027 
1028 opt_spherical_range : _RANGE
1029  {
1030  rw_i=0;
1031  rw_has_limits=TRUE;
1032  }
1033  '[' expr ']'
1034  {
1035  rw_angle=$4;
1036  }
1037  rpointp rpointp
1038  avoid_limits
1039  |
1040  {
1041  rw_has_limits=FALSE;
1042  }
1043  ;
1044 
1045 opt_universal_range : _RANGE
1046  {
1047  rw_i=0;
1048  rw_has_limits=TRUE;
1049  }
1050  range
1051  {
1052  CopyInterval(&rw_range0,&rw_range);
1053  }
1054  rpointp
1055  range rpointp
1056  avoid_limits
1057  |
1058  {
1059  rw_has_limits=FALSE;
1060  }
1061  ;
1062 
1063 obstacle_defs : _OBSTACLES obstacle_list
1064  ;
1065 
1066 obstacle_list : obstacle_definition obstacle_list
1067  |
1068  ;
1069 
1070 obstacle_definition: _IDENTIFIER ':' shape
1071  {
1072  if (GetConstantWithName($1,&rw_constants)!=NO_UINT)
1073  ReadWorlderror("Obstacle with the name of a constant");
1074 
1075  if (GetWorldLinkID($1,rw_world)!=NO_UINT)
1076  ReadWorlderror("Obstacle with the name of a link");
1077 
1078  if (GetWorldObstacleID($1,rw_world)!=NO_UINT)
1079  ReadWorlderror("Duplicated obstacle");
1080 
1081  AddObstacle2World($1,&rw_cbody,rw_world);
1082 
1083  DeletePolyhedron(&rw_cbody);
1084 
1085  free($1);
1086  }
1087 
1088 collision_defs : _COLLISIONS collision_list
1089  ;
1090 
1091 collision_list : collision_definition collision_list
1092  |
1093  ;
1094 
1095 collision_definition: _CHECK ':' _ALL
1096  {
1097  CheckAllCollisions(firstLink,firstObject,rw_world);
1098  }
1099  | _NO _CHECK ':' _ALL
1100  {
1101  NoCheckAllCollisions(firstLink,firstObject,rw_world);
1102  }
1103  | _CHECK ':' _SELFCOLLISIONS
1104  {
1105  CheckSelfCollisions(firstLink,rw_world);
1106  }
1107  | _NO _CHECK ':' _SELFCOLLISIONS
1108  {
1109  NoCheckSelfCollisions(firstLink,rw_world);
1110  }
1111  | _CHECK ':' any_id ',' any_id
1112  {
1113  unsigned int id1,id2;
1114 
1115  id1=GetWorldLinkID($3,rw_world);
1116  if (id1==NO_UINT)
1117  ReadWorlderror("Unkown link (1st id) when activating a collision check");
1118 
1119  id2=GetWorldLinkID($5,rw_world);
1120  if (id2==NO_UINT)
1121  {
1122  id2=GetWorldObstacleID($5,rw_world);
1123  if (id2==NO_UINT)
1124  ReadWorlderror("Unkown link/obstacle (2st id) when activating a collision check");
1125 
1126  CheckLinkObstacleCollision(id1,id2,rw_world);
1127  }
1128  else
1129  CheckLinkLinkCollision(id1,id2,rw_world);
1130 
1131  free($3);
1132  free($5);
1133  }
1134  | _NO _CHECK ':' any_id ',' any_id
1135  {
1136  unsigned int id1,id2;
1137 
1138  id1=GetWorldLinkID($4,rw_world);
1139  if (id1==NO_UINT)
1140  ReadWorlderror("Unkown link (1st id) when disabling a collision check");
1141 
1142  id2=GetWorldLinkID($6,rw_world);
1143  if (id2==NO_UINT)
1144  {
1145  id2=GetWorldObstacleID($6,rw_world);
1146  if (id2==NO_UINT)
1147  ReadWorlderror("Unkown link/obstacle (2st id) when disabling a collision check");
1148 
1149  NoCheckLinkObstacleCollision(id1,id2,rw_world);
1150  }
1151  else
1152  NoCheckLinkLinkCollision(id1,id2,rw_world);
1153 
1154  free($4);
1155  free($6);
1156  }
1157  ;
1158 
1159 avoid_limits : _AVOID _LIMITS opt_weight
1160  {
1161  rw_avoidLimits=TRUE;
1162 
1163  }
1164  |
1165  {
1166  rw_avoidLimits=FALSE;
1167  }
1168  ;
1169 
1170 opt_weight : expr
1171  {
1172  rw_avoidLimitsWeight=$1;
1173  }
1174  |
1175  {
1176  rw_avoidLimitsWeight=1.0;
1177  }
1178  ;
1179 
1180 
1181 included_defs : _INCLUDE include_list
1182  ;
1183 
1184 include_list : include_file include_list
1185  |
1186  ;
1187 
1188 include_file : _IDENTIFIER ':' _STRING
1189  {
1190  Switch2File($1,rw_world->nl,rw_world->no,GetFilePath(rw_filename),$3);
1191  free($1);
1192  free($3);
1193  }
1194  ;
1195 
1196 %%
1199 /*
1200  *
1201  */
1202 void InitWorldFromFile(Tparameters *p,Tfilename *filename,Tworld *w)
1203 {
1204  unsigned int i;
1205 
1206  NEW(rw_point,4,double*);
1207  for(i=0;i<4;i++)
1208  NEW(rw_point[i],3,double);
1209 
1210  NEW(rw_range_point,4,double*);
1211  for(i=0;i<4;i++)
1212  NEW(rw_range_point[i],3,double);
1213 
1214  NEW(rw_in_patch_point,2,double*);
1215  for(i=0;i<2;i++)
1216  NEW(rw_in_patch_point[i],3,double);
1217 
1218  rw_r=(unsigned int)(GetParameter(CT_REPRESENTATION,p));
1219 
1220  InitWorld(w); /*Generate an empty world*/
1221 
1222  InitConstants(&rw_constants); /*An empty set of constants*/
1223 
1224  ReadWorldin=fopen(GetFileFullName(filename),"r");
1225  if (!ReadWorldin)
1226  {
1227  char ErrorText[500];
1228 
1229  sprintf(ErrorText,"File %s does not exists",GetFileFullName(filename));
1230  Error(ErrorText);
1231  }
1232 
1233  /* Indicates whether the previous joint was revolute */
1234  rw_prevolute=FALSE;
1235 
1236  /*Reset the lines numbering*/
1237  RWline=1;
1238  firstLink=0;
1239  firstObject=0;
1240 
1241  /*we initalize the global pointer to make the parameters accesibles to any one inside the YACC module*/
1242  rw_world=w;
1243  rw_filename=filename;
1244 
1245  /*and process the file*/
1246  ReadWorldparse();
1247 
1248  DeleteConstants(&rw_constants);
1249 
1251 
1252  for(i=0;i<4;i++)
1253  free(rw_point[i]);
1254  free(rw_point);
1255 
1256  for(i=0;i<4;i++)
1257  free(rw_range_point[i]);
1258  free(rw_range_point);
1259 
1260  for(i=0;i<2;i++)
1261  free(rw_in_patch_point[i]);
1262  free(rw_in_patch_point);
1263 
1264  fclose(ReadWorldin);
1265 }
1266 
Definition of the boolean type.
unsigned int RWline
Number of the line currently parsed when reading a .world file.
Definition: error_world.c:45
void InitConstants(Tconstants *cts)
Initializes a constant set.
Definition: constants.c:21
void NewSegments(unsigned int n, double *x, double *y, double *z, Tcolor *c, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:1004
#define FALSE
FALSE.
Definition: boolean.h:30
void HTransformTxyz(double tx, double ty, double tz, THTransform *t)
Constructor.
Definition: htransform.c:140
double GetConstantValue(unsigned int n, Tconstants *cts)
Retrives a the value of a constant.
Definition: constants.c:113
void HTransformRx(double rx, THTransform *t)
Constructor.
Definition: htransform.c:155
Relation between two links.
Definition: joint.h:177
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:248
void HTransformTz(double tz, THTransform *t)
Constructor.
Definition: htransform.c:128
A homgeneous transform in R^3.
void InitWorldFromFile(Tparameters *p, Tfilename *f, Tworld *w)
Constructor.
Definition of a table of Tconstants.
#define NORMAL_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:28
unsigned int CoupledWith(Tjoint *j)
Returns the identifier of the joint coupled with the query joint.
Definition: joint.c:1216
#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:926
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:1712
All the necessary information to generate equations for mechanisms.
Definition: world.h:124
void CopyColor(Tcolor *c_dst, Tcolor *c_src)
Copy constructor.
Definition: color.c:21
A color.
Definition: color.h:23
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:857
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
CBLAS_INLINE void HTransformProduct(THTransform *t1, THTransform *t2, THTransform *t3)
Product of two homogeneous transforms.
Definition: htransform.c:404
void CopyInterval(Tinterval *i_dst, Tinterval *i_org)
Copy constructor.
Definition: interval.c:59
Definition of the Tworld type and the associated functions.
A polyhedron.
Definition: polyhedron.h:124
Error and warning functions.
void DeleteFileName(Tfilename *fn)
Destructor.
Definition: filename.c:205
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 HTransformRz(double rz, THTransform *t)
Constructor.
Definition: htransform.c:189
unsigned int GetWorldObstacleID(char *obsName, Tworld *w)
Gets the identifier of an obstacle from its name.
Definition: world.c:1442
void GenerateWorldEquations(Tparameters *p, Tworld *w)
Generates all the cuiksystems derived from the world information.
Definition: world.c:1850
void CheckSelfCollisions(unsigned int fl, Tworld *w)
Activates all the possible collision between links.
Definition: world.c:1656
void AddObstacle2World(char *name, Tpolyhedron *o, Tworld *w)
Adds an obstacle to the environment in the world.
Definition: world.c:1393
unsigned int AddLink2World(Tlink *l, boolean object, Tworld *w)
Adds a link to the mechanism in the world.
Definition: world.c:1333
Definitions of constants and macros used in several parts of the cuik library.
void NewRevoluteJoint(unsigned int id, unsigned int r, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, double **points, boolean hasLimits, Tinterval *range, double **rPoints, boolean avoidLimits, double avoidLimitsWeight, Tjoint *coupled, Tjoint *j)
Constructor.
Definition: joint.c:132
void NewUniversalJoint(unsigned int id, unsigned int r, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, double **points, boolean hasLimits, Tinterval *range1, Tinterval *range2, double **rPoints, boolean avoidLimits, double avoidLimitsWeight, Tjoint *j)
Constructor.
Definition: joint.c:288
void NewInPatchJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, double **points, double **patch, boolean avoidLimits, double avoidLimitsWeight, Tjoint *j)
Constructor.
Definition: joint.c:709
unsigned int GetJointType(Tjoint *j)
Gets the joint type.
Definition: joint.c:931
A table of parameters.
void CreateFileName(char *path, char *name, char *suffix, char *ext, Tfilename *fn)
Constructor.
Definition: filename.c:22
void NewCylinder(double r, double *p1, double *p2, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:950
Definition of the THTransform type and the associated functions.
unsigned int AddJoint2World(Tjoint *j, Tworld *w)
Adds a joint to the mechanism in the world.
Definition: world.c:1383
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
void NewFixJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, THTransform *t, Tjoint *j)
Constructor.
Definition: joint.c:110
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:1685
#define REV_JOINT
One of the possible type of joints.
Definition: joint.h:59
#define MEM_DUP(_var, _n, _type)
Duplicates a previously allocated memory space.
Definition: defines.h:414
Definition of the Tcolor 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:1437
void HTransformTx(double tx, THTransform *t)
Constructor.
Definition: htransform.c:106
Definition of the Tvector type and the associated functions.
void NewSphPrsSphJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, double **points, Tinterval *range, double r, Tcolor *color, Tjoint *j)
Constructor.
Definition: joint.c:652
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:1447
void NoCheckLinkLinkCollision(unsigned int a, unsigned int b, Tworld *w)
Desactivates the possible collision between a particular pair of links.
Definition: world.c:1694
Tjoint * GetWorldJoint(unsigned int jointID, Tworld *w)
Gets a joint from its identifier.
Definition: world.c:1452
unsigned int GetWorldNJoints(Tworld *w)
Gets the number of joints in the mechanism included in the world.
Definition: world.c:1462
void HTransformDelete(THTransform *t)
Destructor.
Definition: htransform.c:833
unsigned int GetConstantWithName(char *name, Tconstants *cts)
Retrives a constant from the set.
Definition: constants.c:88
#define MEM_EXPAND(_var, _n, _type)
Expands a previously allocated memory space.
Definition: defines.h:404
void GetPolyhedronDefiningPoint(unsigned int i, double *point, Tpolyhedron *p)
Gets a point defining a a object.
Definition: polyhedron.c:1190
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:1308
void NoCheckSelfCollisions(unsigned int fl, Tworld *w)
Desactivates all the possible collision between links.
Definition: world.c:1671
void DeletePolyhedron(Tpolyhedron *p)
Destructor.
Definition: polyhedron.c:1484
void NewSphericalJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, double **points, boolean hasLimits, double range, double **rPoints, boolean avoidLimits, double avoidLimitsWeight, Tjoint *j)
Constructor.
Definition: joint.c:452
void NewInterval(double lower, double upper, Tinterval *i)
Constructor.
Definition: interval.c:47
int ReadWorlderror(const char *s)
Syntax errors in .world files.
Definition: error_world.c:47
void HTransformTy(double ty, THTransform *t)
Constructor.
Definition: htransform.c:117
void DeleteConstants(Tconstants *cts)
Destructor.
Definition: constants.c:137
void NewColor(double r, double g, double b, Tcolor *c)
Constructor.
Definition: color.c:14
Defines a interval.
Definition: interval.h:33
void HTransformRy(double ry, THTransform *t)
Constructor.
Definition: htransform.c:172
void HTransformIdentity(THTransform *t)
Constructor.
Definition: htransform.c:69
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
void DeleteJoint(Tjoint *j)
Destructor.
Definition: joint.c:3461
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:541
#define DECOR_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:46
Error function specific of world.
void NewSphSphJoint(unsigned int id, unsigned int linkID1, Tlink *link1, unsigned int linkID2, Tlink *link2, double **points, double l, double r, Tcolor *color, Tjoint *j)
Constructor.
Definition: joint.c:609
#define HIDDEN_SHAPE
One of the possible type of shapes.
Definition: polyhedron.h:37
void NewLine(double *p1, double *p2, Tcolor *c, unsigned int bs, Tpolyhedron *p)
Constructor.
Definition: polyhedron.c:977