icr_client.cpp
Go to the documentation of this file.
00001 
00007 #include "ros/ros.h"
00008 //#include "std_msgs/builtin_uint8.h"
00009 #include "icr/set_finger_number.h"
00010 #include "icr/load_object.h"
00011 #include "icr/compute_icr.h"
00012 #include <cstdlib>
00013 #include <string>
00014 
00015 
00016 using std::cout;
00017 using std::endl;
00018 using std::string;
00019 
00020 bool processOutput(icr::compute_icr::Response &res);
00021 
00022 int main(int argc, char **argv)
00023 {
00024   ros::init(argc, argv, "icr_client");
00025   if (argc != 3)
00026   {
00027     ROS_INFO("usage: $ icr_client <no_fingers> <path_obj> ");
00028     return 1;
00029   }
00030 
00031   ros::NodeHandle n;
00032   std::string prefix;
00033   n.searchParam("icr_prefix", prefix);
00034   string tmp_name;
00036   tmp_name = prefix + "/icr_server/set_finger_number";
00037   cout << tmp_name << endl;
00038   ros::ServiceClient clientFingerNoSet = 
00039     n.serviceClient<icr::set_finger_number>(tmp_name);
00041   tmp_name = prefix + "/icr_server/load_wfront_obj";
00042   ros::ServiceClient clientLoadObject = 
00043     n.serviceClient<icr::load_object>(tmp_name);
00045   tmp_name = prefix + "/icr_server/compute_icr";
00046   ros::ServiceClient clientComputeICR = 
00047     n.serviceClient<icr::compute_icr>(tmp_name);
00048 
00049   icr::set_finger_number set_finger_number_srv;
00050   icr::load_object load_object_srv;
00051   icr::compute_icr compute_icr_srv;
00052 
00053   string tmpName("example_object");
00054   uint16_t myints[] =  {1838, 4526, 4362, 1083, 793};
00055   //uint16_t myints[] =  {1, 2, 3, 4, 5};
00056 
00057   std::vector<uint16_t> 
00058     tmpPts(myints, myints + sizeof(myints) / sizeof(uint16_t) );
00059 
00060   //defining srvs
00061   cout <<"patrzcie niedowiarki "
00062        << sizeof(myints) << " " 
00063        << sizeof(uint16_t) << " " << tmpPts.size() <<  endl;
00064   set_finger_number_srv.request.number = atoll(argv[1]);
00065   load_object_srv.request.path = (std::string)argv[2];
00066   load_object_srv.request.name = tmpName;
00067 
00068   compute_icr_srv.request.centerpoint_ids = tmpPts;
00069   std::vector<uint8_t> tmp_used(5,1);
00070   compute_icr_srv.request.used = tmp_used;
00071 
00072   ROS_INFO("Path where the *.obj is located:"); 
00073   ROS_INFO("%s", load_object_srv.request.path.c_str());
00074   ROS_INFO("Object will have default name: %s",load_object_srv.request.name.c_str());
00075   ROS_INFO("Nuber of loaded center-points: %d",compute_icr_srv.request.centerpoint_ids.size());
00076 
00077   // call all servers and get responses
00078   //
00079   // if (clientFingerNoSet.call(set_finger_number_srv)) {
00080   //   ROS_INFO("Response: %ld", (long int)set_finger_number_srv.response.success);
00081   // } else {
00082   //   ROS_ERROR("Failed to call service /icr_server/set_finger_number");
00083   // }
00084   //
00085   if (clientLoadObject.call(load_object_srv)) {
00086     ROS_INFO("Response: %ld", (long int)load_object_srv.response.success);
00087   } else {
00088     ROS_ERROR("Failed to call service /icr_server/load_object");
00089   }
00090  
00091   //  if (set_finger_number_srv.response.success && load_object_srv.response.success) {
00092   // if (load_object_srv.response.success) {
00093   //   if (clientComputeICR.call(compute_icr_srv)) {
00094   //     ROS_INFO("Response: %ld", (long int)compute_icr_srv.response.success);
00095   //     ROS_INFO("ICR server responded somehow. Be happy.");
00096   //     processOutput(compute_icr_srv.response);
00097   //   } else {
00098   //     ROS_ERROR("Failed to call service /icr_server/compute_icr");
00099   //   }
00100   // } else {
00101   //   ROS_ERROR("ICR_Server don't know about the loaded object and/or added fingers ");
00102   // }
00103   
00104   return 0;
00105 }
00106 
00107 
00108 bool processOutput(icr::compute_icr::Response &res) 
00109 {
00110   ROS_INFO("Processing data");
00111 
00112   cout << "KURWA "<<  res.stx.size() << endl;
00113   cout << "KURWA "<<  res.len.size() << endl;
00114 
00115   for (uint j=0; j<res.stx.size();++j) {    
00116     cout << "icr " << j << " " << res.stx[j] << " " << res.len[j] << endl;
00117     for(uint i=res.stx[j]; i<res.stx[j]+res.len[j] ;i++) {
00118       cout << res.all_icrs.at(i) << " ";
00119     }
00120     cout << endl;
00121   }
00122   return true;
00123 }


icr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:36:10