00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <ros/ros.h>
00038
00039 #include <string>
00040 #include <vector>
00041
00042 #include "tabletop_object_detector/TabletopSegmentation.h"
00043 #include "tabletop_object_detector/TabletopObjectRecognition.h"
00044
00046 int main(int argc, char **argv)
00047 {
00048 ros::init(argc, argv, "ping_tabletop_node");
00049 ros::NodeHandle nh;
00050
00051 std::string service_name("/tabletop_segmentation");
00052 while ( !ros::service::waitForService(service_name, ros::Duration().fromSec(3.0)) && nh.ok() )
00053 {
00054 ROS_INFO("Waiting for service %s...", service_name.c_str());
00055 }
00056 if (!nh.ok()) exit(0);
00057
00058 tabletop_object_detector::TabletopSegmentation segmentation_srv;
00059 if (!ros::service::call(service_name, segmentation_srv))
00060 {
00061 ROS_ERROR("Call to segmentation service failed");
00062 exit(0);
00063 }
00064 if (segmentation_srv.response.result != segmentation_srv.response.SUCCESS)
00065 {
00066 ROS_ERROR("Segmentation service returned error %d", segmentation_srv.response.result);
00067 exit(0);
00068 }
00069 ROS_INFO("Segmentation service succeeded. Detected %d clusters", (int)segmentation_srv.response.clusters.size());
00070 if (segmentation_srv.response.clusters.empty()) exit(0);
00071
00072 service_name = "/tabletop_object_recognition";
00073 if ( !ros::service::waitForService(service_name, ros::Duration().fromSec(3.0)) )
00074 {
00075 ROS_INFO("Recognition service %s is not available", service_name.c_str());
00076 exit(0);
00077 }
00078
00079 tabletop_object_detector::TabletopObjectRecognition recognition_srv;
00080 recognition_srv.request.table = segmentation_srv.response.table;
00081 recognition_srv.request.clusters = segmentation_srv.response.clusters;
00082 recognition_srv.request.num_models = 5;
00083 if (!ros::service::call(service_name, recognition_srv))
00084 {
00085 ROS_ERROR("Call to recognition service failed");
00086 exit(0);
00087 }
00088
00089 ROS_INFO("Recognition results:");
00090 for (size_t i=0; i<recognition_srv.response.models.size(); i++)
00091 {
00092 if (recognition_srv.response.models[i].model_list.empty())
00093 {
00094 ROS_INFO(" Unidentifiable cluster");
00095 }
00096 else
00097 {
00098 ROS_INFO(" Model id %d",recognition_srv.response.models[i].model_list[0].model_id);
00099 }
00100 }
00101
00102 ROS_INFO("Clusters correspond to following recognition results:");
00103 for (size_t i=0; i<recognition_srv.response.cluster_model_indices.size(); i++)
00104 {
00105 ROS_INFO(" Cluster %u: recognition result %d", (unsigned int)i,
00106 recognition_srv.response.cluster_model_indices.at(i));
00107 }
00108 return true;
00109 }