Go to the documentation of this file.00001
00031 #include <ros/ros.h>
00032
00033 #include <urdf_traverser/UrdfTraverser.h>
00034 #include <urdf2inventor/Helpers.h>
00035 #include <urdf2inventor/Urdf2Inventor.h>
00036 #include <urdf2inventor/FileIO.h>
00037 #include <string>
00038 #include <sstream>
00039 #include <vector>
00040
00041 int main(int argc, char** argv)
00042 {
00043 ros::init(argc, argv, "urdf2inventor", ros::init_options::AnonymousName);
00044 ros::NodeHandle priv("~");
00045 ros::NodeHandle pub("");
00046
00047 if (argc < 3)
00048 {
00049 ROS_ERROR("Not enough arguments!");
00050 ROS_INFO_STREAM("Usage: " << argv[0] <<
00051 " <urdf-file> <output-directory> [<root link name>]");
00052 return 0;
00053 }
00054
00055
00056
00057 std::string urdf_filename = std::string(argv[1]);
00058 ROS_INFO("URDF file: %s", urdf_filename.c_str());
00059
00060 std::string outputDir = std::string(argv[2]);
00061 ROS_INFO("Output dir: %s", outputDir.c_str());
00062
00063 std::string rootLinkName;
00064 if (argc > 3)
00065 {
00066 rootLinkName = std::string(argv[3]);
00067 ROS_INFO("Root %s", argv[3]);
00068 }
00069
00070 double scaleFactor = 1;
00071
00072 priv.param<double>("scale_factor", scaleFactor, scaleFactor);
00073 ROS_INFO("scale_factor: <%f>", scaleFactor);
00074
00075
00076
00077
00078
00079
00080 float visCorrAxX = 0;
00081 priv.param<float>("visual_corr_axis_x", visCorrAxX, visCorrAxX);
00082 float visCorrAxY = 0;
00083 priv.param<float>("visual_corr_axis_y", visCorrAxY, visCorrAxY);
00084 float visCorrAxZ = 0;
00085 priv.param<float>("visual_corr_axis_z", visCorrAxZ, visCorrAxZ);
00086 float visCorrAxAngle = 0;
00087 priv.param<float>("visual_corr_axis_angle", visCorrAxAngle, visCorrAxAngle);
00088 urdf2inventor::Urdf2Inventor::EigenTransform addTrans(Eigen::AngleAxisd(visCorrAxAngle * M_PI / 180, Eigen::Vector3d(visCorrAxX, visCorrAxY, visCorrAxZ)));
00089
00090 urdf2inventor::Urdf2Inventor::UrdfTraverserPtr traverser(new urdf_traverser::UrdfTraverser());
00091
00092 urdf2inventor::Urdf2Inventor converter(traverser, scaleFactor);
00093
00094 ROS_INFO("Starting model conversion...");
00095
00096 std::string outputMaterial = "plastic";
00097 urdf2inventor::Urdf2Inventor::ConversionParametersPtr params
00098 = converter.getBasicConversionParams(rootLinkName, outputMaterial, addTrans);
00099
00100 ROS_INFO("Loading and converting...");
00101
00102 urdf2inventor::Urdf2Inventor::ConversionResultPtr cResult =
00103 converter.loadAndConvert(urdf_filename, true, params);
00104 if (!cResult->success)
00105 {
00106 ROS_ERROR("Failed to process.");
00107 return 0;
00108 }
00109
00110 ROS_INFO("Conversion done. Now writing files.");
00111
00112 urdf2inventor::FileIO<urdf2inventor::Urdf2Inventor::MeshFormat> fileIO(outputDir);
00113 if (!fileIO.write(cResult))
00114 {
00115 ROS_ERROR("Could not write files");
00116 return 0;
00117 }
00118
00119 std::stringstream wholeFile;
00120 wholeFile << outputDir << "/robot/" << traverser->getModelName() << ".iv";
00121 ROS_INFO_STREAM("Now writing whole robot to " << wholeFile.str());
00122 if (!converter.writeAsInventor(wholeFile.str(), "", true, addTrans))
00123 {
00124 ROS_ERROR("Could not write whole robot file");
00125 return 0;
00126 }
00127
00128 ROS_INFO("Cleaning up...");
00129 converter.cleanup();
00130
00131 ROS_INFO("Done.");
00132 return 0;
00133 }