diff --git a/urdf/src/model.cpp b/urdf/src/model.cpp index 648c33c..65e8a14 100644 --- a/urdf/src/model.cpp +++ b/urdf/src/model.cpp @@ -232,12 +232,6 @@ bool Model::initXml(TiXmlElement *robot_xml) return false; } - // make sure tree is not empty - if (parent_link_tree.empty()){ - ROS_ERROR("The robot xml does not contain any valid links. Are you parsing an empty file, or an un-processed xacro file?"); - return false; - } - // find the root link if (!this->initRoot(parent_link_tree)) { @@ -323,21 +317,23 @@ bool Model::initRoot(std::map &parent_link_tree) this->root_link_.reset(); - for (std::map::iterator p=parent_link_tree.begin(); p!=parent_link_tree.end(); p++) + // for (std::map::iterator p=parent_link_tree.begin(); p!=parent_link_tree.end(); p++) + // find the links that have no parent in the tree + for (std::map >::iterator l=this->links_.begin(); l!=this->links_.end(); l++) { - if (parent_link_tree.find(p->second) == parent_link_tree.end()) + std::map::iterator parent = parent_link_tree.find(l->first); + if (parent == parent_link_tree.end()) { - if (this->root_link_) + // store root link + if (!this->root_link_) { - ROS_DEBUG("child '%s', parent '%s', root '%s'", p->first.c_str(), p->second.c_str(), this->root_link_->name.c_str()); - if (this->root_link_->name != p->second) - { - ROS_ERROR("Two root links found: '%s' and '%s'", this->root_link_->name.c_str(), p->second.c_str()); - return false; - } + getLink(l->first, this->root_link_); + } + // we already found a root link + else{ + ROS_ERROR("Two root links found: '%s' and '%s'", this->root_link_->name.c_str(), l->first.c_str()); + return false; } - else - getLink(p->second,this->root_link_); } } if (!this->root_link_) diff --git a/urdf/test/pr2_desc_bracket.xml b/urdf/test/fail_pr2_desc_bracket.urdf similarity index 100% rename from urdf/test/pr2_desc_bracket.xml rename to urdf/test/fail_pr2_desc_bracket.urdf diff --git a/urdf/test/pr2_desc_double.xml b/urdf/test/fail_pr2_desc_double.urdf similarity index 100% rename from urdf/test/pr2_desc_double.xml rename to urdf/test/fail_pr2_desc_double.urdf diff --git a/urdf/test/pr2_desc_double_joint.xml b/urdf/test/fail_pr2_desc_double_joint.urdf similarity index 100% rename from urdf/test/pr2_desc_double_joint.xml rename to urdf/test/fail_pr2_desc_double_joint.urdf diff --git a/urdf/test/pr2_desc_loop.xml b/urdf/test/fail_pr2_desc_loop.urdf similarity index 100% rename from urdf/test/pr2_desc_loop.xml rename to urdf/test/fail_pr2_desc_loop.urdf diff --git a/urdf/test/pr2_desc_no_filename_in_mesh.xml b/urdf/test/fail_pr2_desc_no_filename_in_mesh.urdf similarity index 100% rename from urdf/test/pr2_desc_no_filename_in_mesh.xml rename to urdf/test/fail_pr2_desc_no_filename_in_mesh.urdf diff --git a/urdf/test/pr2_desc_no_joint2.xml b/urdf/test/fail_pr2_desc_no_joint2.urdf similarity index 99% rename from urdf/test/pr2_desc_no_joint2.xml rename to urdf/test/fail_pr2_desc_no_joint2.urdf index 7b37fbe..be1fdbc 100644 --- a/urdf/test/pr2_desc_no_joint2.xml +++ b/urdf/test/fail_pr2_desc_no_joint2.urdf @@ -10,6 +10,7 @@ + diff --git a/urdf/test/pr2_desc_parent_itself.xml b/urdf/test/fail_pr2_desc_parent_itself.urdf similarity index 100% rename from urdf/test/pr2_desc_parent_itself.xml rename to urdf/test/fail_pr2_desc_parent_itself.urdf diff --git a/urdf/test/pr2_desc_two_trees.xml b/urdf/test/fail_pr2_desc_two_trees.urdf similarity index 100% rename from urdf/test/pr2_desc_two_trees.xml rename to urdf/test/fail_pr2_desc_two_trees.urdf diff --git a/urdf/test/fail_three_links_one_joint.urdf b/urdf/test/fail_three_links_one_joint.urdf new file mode 100644 index 0000000..a6766a9 --- /dev/null +++ b/urdf/test/fail_three_links_one_joint.urdf @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/urdf/test/pr2_desc.xml b/urdf/test/pr2_desc.urdf similarity index 100% rename from urdf/test/pr2_desc.xml rename to urdf/test/pr2_desc.urdf diff --git a/urdf/test/pr2_desc_explicit_world.xml b/urdf/test/pr2_desc_explicit_world.urdf similarity index 100% rename from urdf/test/pr2_desc_explicit_world.xml rename to urdf/test/pr2_desc_explicit_world.urdf diff --git a/urdf/test/pr2_desc_no_joint.xml b/urdf/test/pr2_desc_no_joint.urdf similarity index 84% rename from urdf/test/pr2_desc_no_joint.xml rename to urdf/test/pr2_desc_no_joint.urdf index 0f17fe0..04839d2 100644 --- a/urdf/test/pr2_desc_no_joint.xml +++ b/urdf/test/pr2_desc_no_joint.urdf @@ -1,7 +1,7 @@ - + diff --git a/urdf/test/test_robot_model_parser.cpp b/urdf/test/test_robot_model_parser.cpp index ef46eb1..13236f6 100644 --- a/urdf/test/test_robot_model_parser.cpp +++ b/urdf/test/test_robot_model_parser.cpp @@ -70,16 +70,16 @@ protected: TEST_F(TestParser, test) { - for (int i=1; i= g_argc-2) - ASSERT_TRUE(robot.initXml(robot_xml)); + std::string folder = std::string(g_argv[1]) + "/test/"; + printf("Folder %s",folder.c_str()); + for (int i=2; i - +