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_transform/ScaleModel.h>
00036 #include <urdf_transform/JoinFixedLinks.h>
00037 #include <urdf_transform/AlignRotationAxis.h>
00038 #include <string>
00039
00040 using urdf_traverser::UrdfTraverser;
00041
00042 void printHelp(char * progName)
00043 {
00044 ROS_INFO_STREAM("Test tool for urdf transform.");
00045 ROS_INFO_STREAM("Usage: " << progName << " <OP> <input-file> [<from-link>]");
00046 ROS_INFO_STREAM("<OP>: The operation to perform. <print|scale|join|zaxis>");
00047 ROS_INFO_STREAM("If <from-link> is specified, the URDF is processed from this link down instead of the root link.");
00048 }
00049
00050 int main(int argc, char **argv)
00051 {
00052 ros::init(argc, argv, "urdf_traverser_scale_model", ros::init_options::AnonymousName);
00053
00054 if (argc < 3)
00055 {
00056 printHelp(argv[0]);
00057 return 0;
00058 }
00059
00060 enum Operation {PRINT, SCALE, JOIN, ZAXIS};
00061 Operation op;
00062 std::string opArg = argv[1];
00063 if (opArg == "print")
00064 {
00065 op = PRINT;
00066 }
00067 else if (opArg == "scale")
00068 {
00069 op = SCALE;
00070 }
00071 else if (opArg == "join")
00072 {
00073 op = JOIN;
00074 }
00075 else if (opArg == "zaxis")
00076 {
00077 op = ZAXIS;
00078 }
00079 else
00080 {
00081 printHelp(argv[0]);
00082 ROS_ERROR_STREAM("Unkown operation: " << opArg);
00083 return 1;
00084 }
00085
00086 std::string inputFile = argv[2];
00087 std::string fromLink;
00088
00089 if (argc > 3)
00090 {
00091 fromLink = argv[3];
00092 }
00093
00094 ROS_INFO_STREAM("Traversing model from file " << inputFile << "...");
00095 if (!fromLink.empty()) ROS_INFO_STREAM("Starting from link " << fromLink);
00096
00097 bool verbose = false;
00098
00099 ROS_INFO("Loading file...");
00100 UrdfTraverser traverser;
00101 if (!traverser.loadModelFromFile(inputFile))
00102 {
00103 ROS_ERROR_STREAM("Could not load file " << inputFile);
00104 return 0;
00105 }
00106
00107 switch (op)
00108 {
00109 case PRINT:
00110 {
00111 ROS_INFO("###### MODEL #####");
00112 verbose = true;
00113 traverser.printModel(verbose);
00114 ROS_INFO("###### JOINT NAMES #####");
00115 traverser.printJointNames(fromLink);
00116 break;
00117 }
00118 case SCALE:
00119 {
00120 ROS_INFO("###### MODEL BEFORE #####");
00121 verbose = true;
00122 traverser.printModel(verbose);
00123 urdf_transform::scaleModel(traverser, 2);
00124 break;
00125 }
00126 case JOIN:
00127 {
00128 ROS_INFO("Join fixed links...");
00129 if (!urdf_transform::joinFixedLinks(traverser, fromLink))
00130 {
00131 ROS_ERROR_STREAM("Could not join fixed links");
00132 return 0;
00133 }
00134
00135 ROS_INFO("$$$--- Joint names after fixed linked joining:");
00136 traverser.printJointNames(fromLink);
00137 break;
00138 }
00139 case ZAXIS:
00140 {
00141 verbose = true;
00142 ROS_INFO("Align rotation axis...");
00143 ROS_INFO("###### MODEL BEFORE #####");
00144 traverser.printModel(verbose);
00145 Eigen::Vector3d axis(0, 0, 1);
00146 if (!urdf_transform::allRotationsToAxis(traverser, fromLink, axis))
00147 {
00148 ROS_ERROR_STREAM("Could not rotate axes");
00149 return 0;
00150 }
00151 break;
00152 }
00153 default:
00154 {
00155 ROS_ERROR("Unknown operation.");
00156 return 1;
00157 }
00158 }
00159
00160 if (op != PRINT)
00161 {
00162 ROS_INFO("### Model after processing:");
00163 traverser.printModel(verbose);
00164 }
00165
00166 return 0;
00167 }
00168
00169