PrintModel.cpp
Go to the documentation of this file.
00001 
00032 #include <ros/ros.h>
00033 #include <urdf_traverser/UrdfTraverser.h>
00034 #include <urdf_traverser/PrintModel.h>
00035 #include <urdf_traverser/Functions.h>
00036 #include <cmath>
00037 
00038 using urdf_traverser::UrdfTraverser;
00039 using urdf_traverser::RecursionParams;
00040 using urdf_traverser::FlagRecursionParams;
00041 
00042 int printLink(urdf_traverser::RecursionParamsPtr& p)
00043 {
00044     if (!p->getLink())
00045     {
00046         ROS_ERROR("printLink: NULL link in parameters!");
00047         return -1;
00048     }
00049     urdf_traverser::LinkPtr link = p->getLink();
00050     urdf_traverser::LinkPtr parent = link->getParent();
00051     unsigned int level = p->getLevel();
00052 
00053     bool verbose = true;
00054     // if the flag in the paramter is true, print verbose.
00055     urdf_traverser::FlagRecursionParamsPtr flagParam = baselib_binding_ns::dynamic_pointer_cast<FlagRecursionParams>(p);
00056     if (flagParam) verbose = flagParam->flag;
00057 
00058     std::stringstream _indent;
00059     for (unsigned int i = 0; i < level; ++i) _indent << "   ";
00060     std::string indent = _indent.str();
00061 
00062     std::string pjoint("NULL");
00063     if (link->parent_joint) pjoint = link->parent_joint->name;
00064     ROS_INFO("%s**%s: parent joint %s", indent.c_str(), link->name.c_str(), pjoint.c_str());
00065 
00066     if (!verbose) return 1;
00067 
00068     // can only print more information if the parent joint is not NULL
00069     if (!link->parent_joint) return 1;
00070 
00071     Eigen::Vector3d rotAx = urdf_traverser::getRotationAxis(link->parent_joint);
00072     ROS_INFO("%s  - Parent joint axis: %f %f %f", indent.c_str(), rotAx.x(), rotAx.y(), rotAx.z());
00073 
00074     // get translation
00075     double x = link->parent_joint->parent_to_joint_origin_transform.position.x;
00076     double y = link->parent_joint->parent_to_joint_origin_transform.position.y;
00077     double z = link->parent_joint->parent_to_joint_origin_transform.position.z;
00078     ROS_INFO("%s  - Translation: %f %f %f", indent.c_str(), x, y, z);
00079 
00080     double qx = link->parent_joint->parent_to_joint_origin_transform.rotation.x;
00081     double qy = link->parent_joint->parent_to_joint_origin_transform.rotation.y;
00082     double qz = link->parent_joint->parent_to_joint_origin_transform.rotation.z;
00083     double qw = link->parent_joint->parent_to_joint_origin_transform.rotation.w;
00084     ROS_INFO("%s  - Quaternion: %f %f %f %f", indent.c_str(), qx, qy, qz, qw);
00085 
00086     // get rpy
00087     double roll, pitch, yaw;
00088     link->parent_joint->parent_to_joint_origin_transform.rotation.getRPY(roll, pitch, yaw);
00089 
00090     if (std::isnan(roll) || std::isnan(pitch) || std::isnan(yaw))
00091     {
00092         ROS_ERROR("getRPY() returned nan!");
00093         return -1;
00094     }
00095 
00096     ROS_INFO("%s     (=RPY: %f %f %f)", indent.c_str(), roll, pitch, yaw);
00097     return 1;
00098 }
00099 
00100 bool urdf_traverser::printModel(UrdfTraverser& traverser, const std::string& fromLink, bool verbose)
00101 {
00102     ROS_INFO("Printing model down from link: %s", fromLink.c_str());
00103 
00104     // go through entire tree
00105     urdf_traverser::RecursionParamsPtr p(new FlagRecursionParams(verbose));
00106     return traverser.traverseTreeTopDown(fromLink, boost::bind(&printLink, _1), p, true) >= 0;
00107 }
00108 
00109 bool urdf_traverser::printModel(UrdfTraverser& traverser, bool verbose)
00110 {
00111     std::string root_link = traverser.getRootLinkName();
00112     return printModel(traverser, root_link, verbose);
00113 }


urdf_traverser
Author(s): Jennifer Buehler
autogenerated on Fri Mar 1 2019 03:38:07