grasp_planning_save_world_client.cpp
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 
00033 #include <grasp_planning_graspit_ros/LogBindingROS.h>
00034 #include <grasp_planning_graspit_msgs/SaveWorld.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 << " <filename> <as inventor: 'true' or 'false'>");
00070     PRINTMSG("If file is not saved as inventor, it will be saved as graspit XML file.");
00071 }
00072 
00073 int run(int argc, char **argv)
00074 {
00075     if (argc < 3)
00076     {
00077         printHelp(argv[0]);
00078         return 0;
00079     }
00080 
00081     const std::string falseStr("false");
00082     const std::string trueStr("true");
00083 
00084     const std::string filenameArg(argv[1]);
00085     const std::string asInventorArg(argv[2]);
00086 
00087     PRINTMSG("Save world as file " << filenameArg << ", as inventor: " << asInventorArg);
00088 
00089     bool asInventorOpt = false;
00090     if (asInventorArg == trueStr)
00091     {
00092         asInventorOpt = true;
00093     }
00094     else if (asInventorArg != falseStr)
00095     {
00096         PRINTERROR("Must specify whether to save as inventor as '" << trueStr << "' or '" << falseStr << "'");
00097         printHelp(argv[0]);
00098         return 1;
00099     }
00100 
00101     // TODO parameterize this
00102     std::string saveWorldTopic = "graspit_save_world";
00103 
00104     ros::NodeHandle n;
00105     ros::ServiceClient client = n.serviceClient<grasp_planning_graspit_msgs::SaveWorld>(saveWorldTopic);
00106 
00107     grasp_planning_graspit_msgs::SaveWorld srv;
00108     srv.request.filename = filenameArg;
00109     srv.request.asInventor = asInventorOpt;
00110 
00111     if (!client.call(srv))
00112     {
00113         PRINTERROR("Failed to call service");
00114         return 1;
00115     }
00116 
00117     if (!srv.response.success)
00118     {
00119         PRINTERROR("Could load save the world into file " << filenameArg);
00120         return 1;
00121     }
00122 
00123     PRINTMSG("Successfully saved world in " << filenameArg);
00124     return 0;
00125 }
00126 
00127 
00128 int main(int argc, char **argv)
00129 {
00130     signal(SIGSEGV, handler);
00131     signal(SIGABRT, handler);
00132 
00133     ros::init(argc, argv, "database_test", ros::init_options::AnonymousName);
00134 
00135     bool useRosLogging = true;
00136     if (useRosLogging)
00137     {
00138         PRINT_INIT_ROS();
00139     }
00140     else
00141     {
00142         PRINT_INIT_STD();
00143     }
00144 
00145     int ret = run(argc, argv);
00146     return ret;
00147 }


grasp_planning_graspit_ros
Author(s): Jennifer Buehler
autogenerated on Wed May 8 2019 02:53:42