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 <vector>
00025 #include <stdio.h>
00026 #include <execinfo.h>
00027 #include <signal.h>
00028 #include <stdlib.h>
00029 #include <unistd.h>
00030 #include <ros/ros.h>
00031
00032 #include <grasp_planning_graspit_ros/WriteToFile.h>
00033 #include <grasp_planning_graspit_ros/LogBindingROS.h>
00034 #include <moveit_msgs/GraspPlanning.h>
00035
00036 #include <eigen_conversions/eigen_msg.h>
00037
00041 void print_trace(void)
00042 {
00043 void *array[10];
00044 size_t size;
00045 char **strings;
00046 size_t i;
00047
00048 size = backtrace(array, 10);
00049 strings = backtrace_symbols(array, size);
00050
00051 printf("Obtained %zd stack frames.\n", size);
00052
00053 for (i = 0; i < size; i++)
00054 printf("%s\n", strings[i]);
00055
00056 free(strings);
00057 }
00058
00059
00060 void handler(int sig)
00061 {
00062 print_trace();
00063 ros::shutdown();
00064 exit(1);
00065 }
00066
00067 void printHelp(const char * progName)
00068 {
00069 PRINTMSG("Usage: " << progName << " <robot name> <object id> [<output-path>]");
00070 PRINTMSG("Where <robot name> is a string, <object id> is and id and <output-path> is the path where resulting Grasp.msg are written");
00071 PRINTMSG("Only robots/objects added to the database and loaded into the graspit world can be referenced.");
00072 }
00073
00074 int run(int argc, char **argv)
00075 {
00076 if (argc < 3)
00077 {
00078 printHelp(argv[0]);
00079 return 0;
00080 }
00081
00082 std::string output_path;
00083 if (argc >= 4)
00084 {
00085 output_path=std::string(argv[3]);
00086 if (!grasp_planning_graspit_ros::makeDirectoryIfNeeded(output_path))
00087 {
00088 PRINTERROR("Could not create directory "<<output_path);
00089 return 0;
00090 }
00091 }
00092
00093 if (output_path.empty())
00094 {
00095 PRINTWARN("No output path configured, will print results on screen only.");
00096 printHelp(argv[0]);
00097 }
00098
00099 const std::string robotArg(argv[1]);
00100 const std::string objectArg(argv[2]);
00101
00102 PRINTMSG("Planning for robot ID=" << robotArg << " to grasp object ID=" << objectArg);
00103
00104
00105 std::string egPlanningTopic = "graspit_eg_planning";
00106
00107 ros::NodeHandle n;
00108 ros::ServiceClient client = n.serviceClient<moveit_msgs::GraspPlanning>(egPlanningTopic);
00109
00110
00111
00112
00113 object_recognition_msgs::ObjectType collModelType;
00114 collModelType.key = "NotAvailabeYet";
00115 collModelType.db = "SimpleGraspItDatabase";
00116
00117
00118
00119
00120
00121 geometry_msgs::PoseStamped modelPose;
00122 modelPose.header.frame_id = "0";
00123
00124
00125
00126
00127
00128
00129 moveit_msgs::CollisionObject collModel;
00130 collModel.header = modelPose.header;
00131 collModel.id = objectArg;
00132 collModel.type = collModelType;
00133 collModel.primitive_poses.push_back(modelPose.pose);
00134 PRINTWARN("Temporary hack: model pose for GraspPlanning service is "
00135 << "passed in first primitive pose. This should be handled by /tf "
00136 << "in future. See also issue #40.");
00137
00138 moveit_msgs::GraspPlanning srv;
00139 srv.request.group_name = robotArg;
00140 srv.request.target = collModel;
00141
00142 if (!client.call(srv))
00143 {
00144 PRINTERROR("Failed to call service");
00145 return 1;
00146 }
00147
00148 if (srv.response.error_code.val != moveit_msgs::MoveItErrorCodes::SUCCESS)
00149 {
00150 PRINTERROR("Could do the grasp planning. Error code " << srv.response.error_code.val);
00151 return 1;
00152 }
00153
00154 PRINTMSG("Successfully finished grasp planning. Have " << srv.response.grasps.size() << " resulting grasps.");
00155 std::vector<moveit_msgs::Grasp>::iterator it;
00156 int i=1;
00157 for (it = srv.response.grasps.begin(); it != srv.response.grasps.end(); ++it)
00158 {
00159 if (!output_path.empty())
00160 {
00161 std::stringstream filenamePrefix;
00162 filenamePrefix << "Grasp_"<<i;
00163 ++i;
00164 if (!grasp_planning_graspit_ros::writeGraspMessage(*it, output_path, filenamePrefix.str()))
00165 {
00166 PRINTERROR("Could not save to file "<<filenamePrefix.str());
00167 continue;
00168 }
00169 }
00170 else
00171 {
00172 PRINTMSG(*it);
00173 }
00174 }
00175 return 0;
00176 }
00177
00178
00179 int main(int argc, char **argv)
00180 {
00181 signal(SIGSEGV, handler);
00182 signal(SIGABRT, handler);
00183
00184 ros::init(argc, argv, "database_test", ros::init_options::AnonymousName);
00185
00186 bool useRosLogging = true;
00187 if (useRosLogging)
00188 {
00189 PRINT_INIT_ROS();
00190 }
00191 else
00192 {
00193 PRINT_INIT_STD();
00194 }
00195
00196 int ret = run(argc, argv);
00197 return ret;
00198 }