Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <ros/ros.h>
00037 #include "collada_parser/collada_parser.h"
00038 #include "urdf/model.h"
00039 #include "urdf_parser/urdf_parser.h"
00040 #include <iostream>
00041 #include <fstream>
00042
00043 using namespace urdf;
00044 using namespace std;
00045
00046 #define PRINT_ORIGIN(os, origin) \
00047 os << "xyz: " << origin.position.x << " " << origin.position.y << " " << origin.position.z << " "; \
00048 { double r,p,y; origin.rotation.getRPY(r, p, y); \
00049 os << "rpy: " << r << " " << p << " " << y; }
00050
00051 #define PRINT_ORIGIN_XML(os, origin) \
00052 os << "xyz=\"" << origin.position.x << " " << origin.position.y << " " << origin.position.z << "\""; \
00053 { double r,p,y; origin.rotation.getRPY(r, p, y); os << " rpy=\"" << r << " " << p << " " << y << "\""; }
00054
00055 #define PRINT_GEOM(os, geometry) \
00056 if ( geometry->type == urdf::Geometry::MESH ) { os << "geom: name: " << ((urdf::Mesh *)geometry.get())->filename; }
00057
00058 void addChildLinkNames(boost::shared_ptr<const Link> link, ofstream& os)
00059 {
00060 double r, p, y;
00061 os << "\"" << link->name << "\" [label=\"" << link->name;
00062 if ( link->inertial != NULL ) {
00063 os << "\\n inertial xyz: "
00064 << link->inertial->origin.position.x << " "
00065 << link->inertial->origin.position.y << " "
00066 << link->inertial->origin.position.z << " ";
00067 link->inertial->origin.rotation.getRPY(r, p, y);
00068 os << "rpy: " << r << " " << p << " " << y << "\\n";
00069 os << "mass: " << link->inertial->mass << " ";
00070 os << "matrix: "
00071 << link->inertial->ixx << " "
00072 << link->inertial->ixy << " "
00073 << link->inertial->ixz << " "
00074 << link->inertial->iyy << " "
00075 << link->inertial->iyz << " "
00076 << link->inertial->izz << "\\n";
00077
00078 } else {
00079
00080 }
00081
00082 if ( !!link->visual ) {
00083 os << "\\n";
00084 os << "visual: ";
00085 PRINT_ORIGIN ( os, link->visual->origin );
00086 os << "\\n";
00087 PRINT_GEOM ( os, link->visual->geometry );
00088
00089 }
00090
00091 if ( !!link->collision ) {
00092 os << "\\n";
00093 os << "collision: ";
00094 PRINT_ORIGIN ( os, link->collision->origin );
00095 os << "\\n";
00096 PRINT_GEOM ( os, link->collision->geometry );
00097
00098 }
00099
00100 os << "\"];" << endl;
00101 for (std::vector<boost::shared_ptr<Link> >::const_iterator child = link->child_links.begin(); child != link->child_links.end(); child++)
00102 addChildLinkNames(*child, os);
00103 }
00104
00105 void addChildJointNames(boost::shared_ptr<const Link> link, ofstream& os)
00106 {
00107 double r, p, y;
00108 for (std::vector<boost::shared_ptr<Link> >::const_iterator child = link->child_links.begin(); child != link->child_links.end(); child++){
00109 (*child)->parent_joint->parent_to_joint_origin_transform.rotation.getRPY(r,p,y);
00110 os << "\"" << link->name << "\" -> \"" << (*child)->parent_joint->name
00111 << "\" [label=\"xyz: "
00112 << (*child)->parent_joint->parent_to_joint_origin_transform.position.x << " "
00113 << (*child)->parent_joint->parent_to_joint_origin_transform.position.y << " "
00114 << (*child)->parent_joint->parent_to_joint_origin_transform.position.z << " "
00115 << "\\nrpy: " << r << " " << p << " " << y << "\"]" << endl;
00116 os << "\"" << (*child)->parent_joint->name << "\" -> \"" << (*child)->name << "\"" << endl;
00117
00118
00119 addChildJointNames(*child, os);
00120 }
00121 }
00122
00123 void printTree(boost::shared_ptr<const Link> link, string file)
00124 {
00125 std::ofstream os;
00126 os.open(file.c_str());
00127 os << "digraph G {" << endl;
00128
00129 os << "node [shape=box];" << endl;
00130 addChildLinkNames(link, os);
00131
00132 os << "node [shape=ellipse, color=blue, fontcolor=blue];" << endl;
00133 addChildJointNames(link, os);
00134
00135 os << "}" << endl;
00136 os.close();
00137 }
00138
00139 int main(int argc, char** argv)
00140 {
00141 if (argc != 2){
00142 std::cerr << "Usage: urdf_to_graphiz input.xml" << std::endl;
00143 return -1;
00144 }
00145
00146
00147 std::string xml_string;
00148 std::fstream xml_file(argv[1], std::fstream::in);
00149 while ( xml_file.good() )
00150 {
00151 std::string line;
00152 std::getline( xml_file, line);
00153 xml_string += (line + "\n");
00154 }
00155 xml_file.close();
00156
00157 boost::shared_ptr<ModelInterface> robot;
00158 if( xml_string.find("<COLLADA") != std::string::npos )
00159 {
00160 ROS_DEBUG("Parsing robot collada xml string");
00161 robot = parseCollada(xml_string);
00162 }
00163 else
00164 {
00165 ROS_DEBUG("Parsing robot urdf xml string");
00166 robot = parseURDF(xml_string);
00167 }
00168
00169 if (!robot){
00170 std::cerr << "ERROR: Model Parsing the xml failed" << std::endl;
00171 return -1;
00172 }
00173 string output = robot->getName();
00174
00175
00176 printTree(robot->getRoot(), output+".gv");
00177 cout << "Created file " << output << ".gv" << endl;
00178
00179 string command = "dot -Tpdf "+output+".gv -o "+output+".pdf";
00180 system(command.c_str());
00181 cout << "Created file " << output << ".pdf" << endl;
00182
00183 return 0;
00184 }