Go to the documentation of this file.00001 #ifdef DOXYGEN_SHOULD_SKIP_THIS
00002
00021 #endif // DOXYGEN_SHOULD_SKIP_THIS
00022
00023 #include <string>
00024 #include <set>
00025 #include <stdio.h>
00026 #include <execinfo.h>
00027 #include <signal.h>
00028 #include <stdlib.h>
00029 #include <unistd.h>
00030
00031 #include <ros/ros.h>
00032 #include <geometry_msgs/Pose.h>
00033
00034 #include <grasp_planning_graspit_ros/LogBindingROS.h>
00035 #include <grasp_planning_graspit_msgs/LoadDatabaseModel.h>
00036
00037 #include <grasp_planning_graspit/GraspItTypes.h>
00038
00039 #include <eigen_conversions/eigen_msg.h>
00040
00041
00045 void print_trace(void)
00046 {
00047 void *array[10];
00048 size_t size;
00049 char **strings;
00050 size_t i;
00051
00052 size = backtrace(array, 10);
00053 strings = backtrace_symbols(array, size);
00054
00055 printf("Obtained %zd stack frames.\n", size);
00056
00057 for (i = 0; i < size; i++)
00058 printf("%s\n", strings[i]);
00059
00060 free(strings);
00061 }
00062
00063
00064 void handler(int sig)
00065 {
00066 print_trace();
00067 ros::shutdown();
00068 exit(1);
00069 }
00070
00071 void printHelp(const char * progName)
00072 {
00073 PRINTMSG("Usage: " << progName << " <database model id> <clear other models: 'true' or 'false'> [<x> <y> <z>] [<qw> <qx> <qy> <qz>]");
00074 }
00075
00076 int run(int argc, char **argv)
00077 {
00078 if (argc < 3)
00079 {
00080 printHelp(argv[0]);
00081 return 0;
00082 }
00083
00084 const std::string falseStr("false");
00085 const std::string trueStr("true");
00086
00087 const std::string modelIDArg(argv[1]);
00088 const std::string clearOthersArg(argv[2]);
00089
00090 PRINTMSG("Loading model " << modelIDArg << " to graspit world. Clear others: " << clearOthersArg);
00091
00092 bool clearOthersOpt = false;
00093 if (clearOthersArg == trueStr)
00094 {
00095 clearOthersOpt = true;
00096 }
00097 else if (clearOthersArg != falseStr)
00098 {
00099 PRINTERROR("Must specify whether to clear other bodies " << trueStr << " or " << falseStr);
00100 printHelp(argv[0]);
00101 return 1;
00102 }
00103
00104 GraspIt::EigenTransform transform;
00105 transform.setIdentity();
00106
00107 if (argc > 3)
00108 {
00109 if ((argc != 6) && (argc != 10))
00110 {
00111 PRINTERROR("If you specify more than 2 arguments, you must specify either a) a translation or b) a complete transform");
00112 printHelp(argv[0]);
00113 return 1;
00114 }
00115
00116
00117 if (argc >= 6)
00118 {
00119
00120
00121 float x = atof(argv[3]);
00122 float y = atof(argv[4]);
00123 float z = atof(argv[5]);
00124
00125 transform = transform.translate(Eigen::Vector3d(x, y, z));
00126 }
00127 if (argc == 10)
00128 {
00129
00130
00131 float qw = atof(argv[6]);
00132 float qx = atof(argv[7]);
00133 float qy = atof(argv[8]);
00134 float qz = atof(argv[9]);
00135
00136 transform = transform.rotate(Eigen::Quaterniond(qw, qx, qy, qz));
00137 }
00138 }
00139
00140
00141 geometry_msgs::Pose modelPose;
00142 tf::poseEigenToMsg(transform, modelPose);
00143
00144
00145 std::string loadModelTopic = "graspit_load_model";
00146
00147 ros::NodeHandle n;
00148 ros::ServiceClient client = n.serviceClient<grasp_planning_graspit_msgs::LoadDatabaseModel>(loadModelTopic);
00149
00150
00151 int modelID = atof(modelIDArg.c_str());
00152
00153 grasp_planning_graspit_msgs::LoadDatabaseModel srv;
00154 srv.request.model_id = modelID;
00155 srv.request.model_pose = modelPose;
00156 srv.request.clear_other_models = clearOthersOpt;
00157
00158 if (!client.call(srv))
00159 {
00160 PRINTERROR("Failed to call service");
00161 return 1;
00162 }
00163
00164 if (srv.response.result != grasp_planning_graspit_msgs::LoadDatabaseModel::Response::LOAD_SUCCESS)
00165 {
00166 PRINTERROR("Could load model ID=" << modelIDArg);
00167 return 1;
00168 }
00169
00170 PRINTMSG("Successfully loaded model ID=" << modelID);
00171 return 0;
00172 }
00173
00174
00175 int main(int argc, char **argv)
00176 {
00177 signal(SIGSEGV, handler);
00178 signal(SIGABRT, handler);
00179
00180 ros::init(argc, argv, "database_test", ros::init_options::AnonymousName);
00181
00182 bool useRosLogging = true;
00183 if (useRosLogging)
00184 {
00185 PRINT_INIT_ROS();
00186 }
00187 else
00188 {
00189 PRINT_INIT_STD();
00190 }
00191
00192 int ret = run(argc, argv);
00193
00194 return ret;
00195 }