urdf2graspit_node.cpp
Go to the documentation of this file.
00001 
00019 #include <ros/ros.h>
00020 
00021 #include <urdf2inventor/Helpers.h>
00022 #include <urdf2graspit/Urdf2Graspit.h>
00023 #include <urdf2graspit/FileIO.h>
00024 #include <string>
00025 #include <vector>
00026 
00027 int main(int argc, char** argv)
00028 {
00029     ros::init(argc, argv, "urdf2graspit", ros::init_options::AnonymousName);
00030     ros::NodeHandle priv("~");
00031     ros::NodeHandle pub("");
00032 
00033     if (argc < 5)
00034     {
00035         ROS_ERROR("Not enough arguments!");
00036         ROS_INFO_STREAM("Usage: " << argv[0] <<
00037                         " <urdf-file> <output-directory> <palm link name>" <<
00038                         " <finger joint name 0> ... <finger joint name n>");
00039         return 0;
00040     }
00041 
00042     // set parameters
00043 
00044     std::string urdf_filename = std::string(argv[1]);
00045     ROS_INFO("URDF file: %s", urdf_filename.c_str());
00046 
00047     std::string outputDir = std::string(argv[2]);
00048     ROS_INFO("Output dir: %s", outputDir.c_str());
00049 
00050     std::string palmLinkName = std::string(argv[3]);
00051     ROS_INFO("Hand root: %s", palmLinkName.c_str());
00052 
00053     std::vector<std::string> roots;
00054     for (unsigned int i = 4; i < argc; ++i)
00055     {
00056         std::string fingerJoint = std::string(argv[i]);
00057         ROS_INFO("Joint: %s", fingerJoint.c_str());
00058         roots.push_back(fingerJoint);
00059     }
00060 
00061     std::string outputMaterial = "plastic";
00062     priv.param<std::string>("output_material", outputMaterial, outputMaterial);
00063     ROS_INFO("output_material: <%s>", outputMaterial.c_str());
00064 
00065     double scaleFactor = 1000;
00066     priv.param<double>("scale_factor", scaleFactor, scaleFactor);
00067     ROS_INFO("scale_factor: <%f>", scaleFactor);
00068     
00069     bool negateJointMoves = false;
00070     priv.param<bool>("negate_joint_movement", negateJointMoves, negateJointMoves);
00071     ROS_INFO("negate_joint_movement: <%d>", negateJointMoves);
00072 
00073 
00074     // An axis and angle (degrees) can be specified which will transform *all*
00075     // visuals (not links, but their visuals!) within their local coordinate system.
00076     // This can be used to correct transformation errors which may have been 
00077     // introduced in converting meshes from one format to the other, losing orientation information
00078     // For example, .dae has an "up vector" definition which may have been ignored.
00079     float visCorrAxX=0;
00080     priv.param<float>("visual_corr_axis_x", visCorrAxX, visCorrAxX);
00081     float visCorrAxY=0;
00082     priv.param<float>("visual_corr_axis_y", visCorrAxY, visCorrAxY);
00083     float visCorrAxZ=0;
00084     priv.param<float>("visual_corr_axis_z", visCorrAxZ, visCorrAxZ);
00085     float visCorrAxAngle=0;
00086     priv.param<float>("visual_corr_axis_angle", visCorrAxAngle, visCorrAxAngle);
00087     urdf2graspit::Urdf2GraspIt::EigenTransform addVisualTrans(Eigen::AngleAxisd(visCorrAxAngle*M_PI/180, Eigen::Vector3d(visCorrAxX,visCorrAxY,visCorrAxZ)));
00088 
00089     urdf2inventor::Urdf2Inventor::UrdfTraverserPtr traverser(new urdf_traverser::UrdfTraverser());
00090     urdf2graspit::Urdf2GraspIt converter(traverser, scaleFactor, negateJointMoves);
00091 
00092     ROS_INFO("Starting model conversion...");
00093 
00094     urdf2graspit::Urdf2GraspIt::ConversionResultPtr cResult =
00095         converter.processAll(urdf_filename,
00096                              palmLinkName,
00097                              roots, outputMaterial, addVisualTrans);
00098     if (!cResult || !cResult->success)
00099     {
00100         ROS_ERROR("Failed to process.");
00101         return 0;
00102     }
00103 
00104     ROS_INFO("Conversion done.");
00105 
00106     urdf2graspit::FileIO fileIO(outputDir, converter.getOutStructure());
00107 
00108     if (!fileIO.write(cResult))
00109     {
00110         ROS_ERROR("Could not write files");
00111         return 0;
00112     }
00113     
00114     ROS_INFO("Cleaning up...");
00115     converter.cleanup();
00116 
00117     ROS_INFO("Done.");
00118     return 0;
00119 }


urdf2graspit
Author(s): Jennifer Buehler
autogenerated on Wed May 8 2019 02:53:45