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
00037 #include "urdf_parser/urdf_parser.h"
00038 #include <iostream>
00039 #include <fstream>
00040
00041 using namespace urdf;
00042
00043 void printTree(boost::shared_ptr<const Link> link,int level = 0)
00044 {
00045 level+=2;
00046 int count = 0;
00047 for (std::vector<boost::shared_ptr<Link> >::const_iterator child = link->child_links.begin(); child != link->child_links.end(); child++)
00048 {
00049 if (*child)
00050 {
00051 for(int j=0;j<level;j++) std::cout << " ";
00052 std::cout << "child(" << (count++)+1 << "): " << (*child)->name << std::endl;
00053
00054 printTree(*child,level);
00055 }
00056 else
00057 {
00058 for(int j=0;j<level;j++) std::cout << " ";
00059 std::cout << "root link: " << link->name << " has a null child!" << *child << std::endl;
00060 }
00061 }
00062
00063 }
00064
00065
00066 int main(int argc, char** argv)
00067 {
00068 if (argc < 2){
00069 std::cerr << "Expect URDF xml file to parse" << std::endl;
00070 return -1;
00071 }
00072
00073 std::string xml_string;
00074 std::fstream xml_file(argv[1], std::fstream::in);
00075 while ( xml_file.good() )
00076 {
00077 std::string line;
00078 std::getline( xml_file, line);
00079 xml_string += (line + "\n");
00080 }
00081 xml_file.close();
00082
00083 boost::shared_ptr<ModelInterface> robot = parseURDF(xml_string);
00084 if (!robot){
00085 std::cerr << "ERROR: Model Parsing the xml failed" << std::endl;
00086 return -1;
00087 }
00088 std::cout << "robot name is: " << robot->getName() << std::endl;
00089
00090
00091 std::cout << "---------- Successfully Parsed XML ---------------" << std::endl;
00092
00093 boost::shared_ptr<const Link> root_link=robot->getRoot();
00094 if (!root_link) return -1;
00095
00096 std::cout << "root Link: " << root_link->name << " has " << root_link->child_links.size() << " child(ren)" << std::endl;
00097
00098
00099
00100 printTree(root_link);
00101 return 0;
00102 }
00103