urdf_viewer_node.cpp
Go to the documentation of this file.
00001 
00031 #include <ros/ros.h>
00032 #include <urdf2inventor/Urdf2Inventor.h>
00033 #include <urdf_viewer/InventorViewer.h>
00034 #include <string>
00035 
00036 using urdf_viewer::InventorViewer;
00037 using urdf2inventor::Urdf2Inventor;
00038 
00039 int main(int argc, char *argv[])
00040 {
00041     ros::init(argc, argv, "urdf_viewer", ros::init_options::AnonymousName);
00042     ros::NodeHandle priv("~");
00043 
00044     if (argc < 2)
00045     {
00046         ROS_INFO_STREAM("Usage: " << argv[0] << " <input-file> [--iv | <from-link>]");
00047         ROS_INFO_STREAM(" If --iv is specified, the file is assumed to be an inventor file, otherwise a URDF file.");
00048         ROS_INFO_STREAM(" if <from-link> is specified (only supported if not using --iv), the URDF is displayed from this link down.");
00049         return 0;
00050     }
00051 
00052     bool isURDF = true;
00053 
00054     std::string inputFile = argv[1];
00055     std::string fromLink;
00056 
00057     if (argc > 2)
00058     {
00059         std::string arg(argv[2]);
00060         if (arg == "--iv") isURDF = false;
00061         else if (arg != "root") fromLink = arg;
00062     }
00063 
00064 
00065     // join fixed links before displaying
00066     bool joinFixedLinks = false;
00067     priv.param<bool>("join_fixed_links", joinFixedLinks, joinFixedLinks);
00068 
00069     // rotate all axes to z
00070     bool rotateAxesZ = false;
00071     priv.param<bool>("rotate_axes_z", rotateAxesZ, rotateAxesZ);
00072 
00073     // true to display axes of local joint coordinate systems
00074     bool displayAxes = true;
00075     priv.param<bool>("display_axes", displayAxes, displayAxes);
00076 
00077     float axRad = 0.001;
00078     priv.param<float>("axes_radius", axRad, axRad);
00079 
00080     float axLen = 0.015;
00081     priv.param<float>("axes_length", axLen, axLen);
00082 
00083     // An axis and angle (degrees) can be specified which will transform *all*
00084     // visuals (not links, but their visuals!) within their local coordinate system.
00085     // This can be used to correct transformation errors which may have been
00086     // introduced in converting meshes from one format to the other, losing orientation information
00087     // For example, .dae has an "up vector" definition which may have been ignored.
00088     float visCorrAxX = 0;
00089     priv.param<float>("visual_corr_axis_x", visCorrAxX, visCorrAxX);
00090     float visCorrAxY = 0;
00091     priv.param<float>("visual_corr_axis_y", visCorrAxY, visCorrAxY);
00092     float visCorrAxZ = 0;
00093     priv.param<float>("visual_corr_axis_z", visCorrAxZ, visCorrAxZ);
00094     float visCorrAxAngle = 0;
00095     priv.param<float>("visual_corr_axis_angle", visCorrAxAngle, visCorrAxAngle);
00096     Urdf2Inventor::EigenTransform addVisualTrans(Eigen::AngleAxisd(visCorrAxAngle * M_PI / 180, Eigen::Vector3d(visCorrAxX, visCorrAxY, visCorrAxZ)));
00097 
00098     bool success = true;
00099     urdf2inventor::Urdf2Inventor::UrdfTraverserPtr traverser(new urdf_traverser::UrdfTraverser());
00100     Urdf2Inventor converter(traverser, 1);
00101     InventorViewer view;
00102     view.init("WindowName");
00103     if (isURDF)
00104     {
00105         ROS_INFO_STREAM("Converting model from file " << inputFile << "...");
00106         if (!fromLink.empty()) ROS_INFO_STREAM("Starting from link " << fromLink);
00107 
00108         ROS_INFO("Loading file...");
00109         if (!converter.loadModelFromFile(inputFile))
00110         {
00111             ROS_ERROR_STREAM("Could not load file " << inputFile);
00112             return 0;
00113         }
00114         converter.printJointNames(fromLink);
00115 
00116         ROS_INFO("Check to join fixed links...");
00117         if (joinFixedLinks && !converter.joinFixedLinks(fromLink))
00118         {
00119             ROS_ERROR_STREAM("Could not join fixed links");
00120             return 0;
00121         }
00122 
00123         ROS_INFO("Check to align rotation axis...");
00124         Eigen::Vector3d axis(0, 0, 1);
00125         if (rotateAxesZ && !converter.allRotationsToAxis(fromLink, axis))
00126         {
00127             ROS_ERROR_STREAM("Could not rotate axes");
00128             return 0;
00129         }
00130 
00131         ROS_INFO("Getting inventor node...");
00132         SoNode * node = converter.getAsInventor(fromLink, false, displayAxes, axRad, axLen, addVisualTrans, NULL);
00133         if (!node)
00134         {
00135             ROS_INFO_STREAM("ERROR: Could not get inventor node");
00136             success = false;
00137         }
00138         else
00139         {
00140             ROS_INFO_STREAM("Model converted, now loading into viewer...");
00141             view.loadModel(node);
00142         }
00143     }
00144     else
00145     {
00146         view.loadModel(inputFile);
00147     }
00148     if (success)  view.runViewer();
00149 
00150     converter.cleanup();
00151     return 0;
00152 }
00153 
00154 


urdf_viewer
Author(s): Jennifer Buehler
autogenerated on Fri Mar 1 2019 03:38:13