00001 00032 #include <ros/ros.h> 00033 #include <urdf_traverser/Functions.h> 00034 #include <urdf_traverser/UrdfTraverser.h> 00035 #include <urdf_traverser/JointNames.h> 00036 00037 using urdf_traverser::UrdfTraverser; 00038 using urdf_traverser::RecursionParams; 00039 using urdf_traverser::StringVectorRecursionParams; 00040 00044 int getJointNamesCB(urdf_traverser::RecursionParamsPtr& p) 00045 { 00046 StringVectorRecursionParams::Ptr param = baselib_binding_ns::dynamic_pointer_cast<StringVectorRecursionParams>(p); 00047 if (!param) 00048 { 00049 ROS_ERROR("Wrong recursion parameter type"); 00050 return -1; 00051 } 00052 00053 urdf_traverser::LinkPtr link = p->getLink(); 00054 if (!link) 00055 { 00056 ROS_ERROR("printLink: NULL link in parameters!"); 00057 return -1; 00058 } 00059 00060 urdf_traverser::LinkPtr parent = link->getParent(); 00061 //unsigned int level = p->level; 00062 00063 // only return parent joints starting from first recursion level, 00064 // because we want only the joints in-between the starting linke 00065 // and the end of the chain. 00066 //if (level <=1 ) return 1; 00067 00068 std::string pjoint; 00069 if (link->parent_joint) 00070 { 00071 pjoint = link->parent_joint->name; 00072 if (!param->skipFixed || urdf_traverser::isActive(link->parent_joint)) 00073 param->names.push_back(pjoint); 00074 } 00075 //ROS_INFO("Information about %s: parent joint %s (recursion level %i)", link->name.c_str(), pjoint.c_str(), level); 00076 return 1; 00077 } 00078 00079 bool urdf_traverser::getJointNames(UrdfTraverser& traverser, const std::string& fromLink, 00080 const bool skipFixed, std::vector<std::string>& result) 00081 { 00082 ROS_INFO("Get joint names starting from link: %s", fromLink.c_str()); 00083 00084 // go through entire tree 00085 StringVectorRecursionParams * stringParams = new StringVectorRecursionParams(skipFixed); 00086 urdf_traverser::RecursionParamsPtr p(stringParams); 00087 bool success = (traverser.traverseTreeTopDown(fromLink, boost::bind(&getJointNamesCB, _1), p, false) >= 0); 00088 if (success) 00089 { 00090 result = stringParams->names; 00091 } 00092 return success; 00093 } 00094 00095 00096