Go to the documentation of this file.
21 #include <unordered_map>
23 using namespace tinyxml2;
127 if (fabs(b+ M_PI)<0.001)
131 if (fabs(b- M_PI)<0.001)
154 tp=( char *)element->Attribute( "xyz");
157 sscanf(tp, "%lf %lf %lf",&x,&y,&z);
163 Error( "Origin without xyz attribute");
169 tp=( char *)element->Attribute( "rpy");
172 sscanf(tp, "%lf %lf %lf",&a,&b,&c);
180 Error( "Origin without rpy attribute");
189 *child=node->FirstChild();
190 while((!found)&&(*child))
192 element=(*child)->ToElement();
193 found=((element)&&(strcasecmp(element->Value(),label)==0));
195 *child=(*child)->NextSibling();
208 *child=(*child)->NextSibling();
209 while((!found)&&(*child))
211 element=(*child)->ToElement();
212 found=((element)&&(strcasecmp(element->Value(),label)==0));
214 *child=(*child)->NextSibling();
252 unsigned int lPath,lName;
254 lPath=strlen(arg[1]);
255 if (arg[1][lPath]== '/')
256 {lPath--;arg[1][lPath]=0;}
257 lName=strlen(arg[2]);
259 NEW(fileName,lPath+lName+2, char);
260 sprintf(fileName, "%s/%s",arg[1],arg[2]);
261 fileName[lPath+lName+1]=0;
274 Error( "URDF without a robot definition?");
277 unsigned int i,l1,l2;
278 char *linkName,*jointName,*jointType,*jointParent,*jointChild;
279 XMLNode *linkNode,*jointNode,*partNode,*geomNode,*materialNode,*bodyNode,*colorNode,*parentNode,*childNode,*inertiaNode;
280 XMLElement *link,*joint,*part,*origin,*geom,*material,*body,*color,*parent,*child,*axis,*limit,*dynamicInfo,*mass,*inertia;
287 double *z,**point,**rangePoint,*a,*ap,**iMatrix;
293 double friction,damping,velocity,effort;
295 std::unordered_map<std::string,Tcolor> materials;
297 NEW(point,4, double*);
299 NEW(point[i],3, double);
301 NEW(rangePoint,4, double*);
303 NEW(rangePoint[i],3, double);
309 NEW(iMatrix,3, double*);
311 NEW(iMatrix[i],3, double);
313 z[0]=0;z[1]=0;z[2]=0;
319 printf( "\n Processing links\n");
323 linkName=( char *)link->Attribute( "name");
324 printf( " Processing link: %s\n",linkName);
337 mss=atof(mass->Attribute( "value"));
344 double ixx,ixy,ixz,iyy,iyz,izz;
346 ixx=atof(inertia->Attribute( "ixx"));
347 ixy=atof(inertia->Attribute( "ixy"));
348 ixz=atof(inertia->Attribute( "ixz"));
349 iyy=atof(inertia->Attribute( "iyy"));
350 iyz=atof(inertia->Attribute( "iyz"));
351 izz=atof(inertia->Attribute( "izz"));
353 iMatrix[0][0]=ixx;iMatrix[0][1]=ixy;iMatrix[0][2]=ixz;
354 iMatrix[1][0]=ixy;iMatrix[1][1]=iyy;iMatrix[1][2]=iyz;
355 iMatrix[2][0]=ixz;iMatrix[2][1]=iyz;iMatrix[2][2]=izz;
359 iMatrix[0][0]=0.0;iMatrix[0][1]=0.0;iMatrix[0][2]=0.0;
360 iMatrix[1][0]=0.0;iMatrix[1][1]=0.0;iMatrix[1][2]=0.0;
361 iMatrix[2][0]=0.0;iMatrix[2][1]=0.0;iMatrix[2][2]=0.0;
364 InitLink(linkName,mss,iMatrix,&iFrame,&l);
367 InitLink(linkName,0.0,NULL,NULL,&l);
390 std::string materialName;
392 materialName=material->Attribute( "name");
399 sc=( char *)color->Attribute( "rgba");
400 sscanf(sc, "%lf %lf %lf",&r,&g,&b);
402 materials[materialName]=c;
407 std::unordered_map<std::string,Tcolor>::const_iterator mat;
410 mat=materials.find(materialName);
411 if (mat==materials.end())
425 bodyNode=geomNode->FirstChild();
429 body=bodyNode->ToElement();
436 if (strcasecmp(body->Value(),( char*) "mesh")==0)
443 char *meshName,*fileMeshName;
446 meshName=( char *)body->Attribute( "filename");
449 s=( char *)body->Attribute( "scale");
452 sscanf(s, "%lf %lf %lf",&sx,&sy,&sz);
460 lName=strlen(meshName);
463 while ((i<lName)&&((meshName[k]!= ':')||(meshName[k+1]!= '/')||(meshName[k+2]!= '/')))
469 NEW(fileMeshName,lPath+lName+2, char);
470 sprintf(fileMeshName, "%s/%s",arg[1],&(meshName[k]));
471 fileMeshName[lPath+lName+1]=0;
481 if (strcasecmp(body->Value(),( char*) "sphere")==0)
484 double r,z[3]={0,0,0};
486 sr=( char *)body->Attribute( "radius");
493 if (strcasecmp(body->Value(),( char*) "cylinder")==0)
497 double p1[3]={0,0,0},p2[3]={0,0,0};
499 sr=( char *)body->Attribute( "radius");
501 sl=( char *)body->Attribute( "length");
513 if (strcasecmp(body->Value(),( char*) "box")==0)
518 ss=( char *)body->Attribute( "size");
519 sscanf(ss, "%lf %lf %lf",&x,&y,&z);
539 bodyNode=bodyNode->NextSibling();
552 printf( "\n Processing joints\n");
556 jointName=( char *)joint->Attribute( "name");
557 jointType=( char *)joint->Attribute( "type");
560 jointParent=( char *)parent->Attribute( "link");
563 jointChild=( char *)child->Attribute( "link");
567 Error( "Unkown parent link when defining a joint");
571 Error( "Unkown child when defining joint");
573 printf( " Processing joint: %s [%s] %s <-> %s\n",jointName,jointType,jointParent,jointChild);
588 ap=( char *)axis->Attribute( "xyz");
589 sscanf(ap, "%lf %lf %lf",&(a[0]),&(a[1]),&(a[2]));
592 { a[0]=1.0;a[1]=0.0;a[2]=0.0; }
596 point[2][0]=point[2][1]=point[2][2]=0.0;
597 point[3][0]=a[0];point[3][1]=a[1];point[3][2]=a[2];
601 rangePoint[1][0]=ap[0];rangePoint[1][1]=ap[1];rangePoint[1][2]=ap[2];
612 fr=( char *)dynamicInfo->Attribute( "friction");
616 da=( char *)dynamicInfo->Attribute( "damping");
630 ll=atof(( char *)limit->Attribute( "lower"));
631 ul=atof(( char *)limit->Attribute( "upper"));
634 ve=( char *)limit->Attribute( "velocity");
638 ef=( char *)limit->Attribute( "effort");
646 if (strcasecmp(jointType,( char *) "fixed")==0)
653 if (strcasecmp(jointType,( char *) "revolute")==0)
657 ( double **)point, TRUE, TRUE,&range,( double **)rangePoint,
659 velocity, INF,effort,1.0,friction,damping,&j);
662 if (strcasecmp(jointType,( char *) "continuous")==0)
666 ( double **)point, FALSE, TRUE,&range,( double **)rangePoint,
668 velocity, INF,effort,1.0,friction,damping,&j);
671 if (strcasecmp(jointType,( char *) "prismatic")==0)
675 ( double **)point,&range,
677 velocity, INF,effort,1.0,friction,damping,&j);
680 if (strcasecmp(jointType,( char *) "floating")==0)
684 velocity, INF,effort,1.0,friction,damping,&j);
686 Error( "Undefined joint type");
703 PrintWorld((argc>3?arg[3]:fileName),argc,arg,&w);
729 Error( "Unable to parse the XML in the URDF file");
735 fprintf(stderr, " Wrong number of parameters.\n");
736 fprintf(stderr, " Use:\n");
737 fprintf(stderr, " cuikurdf2world <package path> <problem filename>.urdf [<output>.world]\n");
738 fprintf(stderr, " where <package path> is folder with the ROS package files (relative to the current directory).\n");
739 fprintf(stderr, " <problem filename> is the URDF file to read (relative to the package)\n");
740 fprintf(stderr, " <ouput> is the optional name for the world file to create (relative to the current directory).\n");
741 fprintf(stderr, " (the '.urdf' extension is not required)\n");
743 return(EXIT_SUCCESS);
|
Follow us!