Go to the documentation of this file.00001 #include <ros/ros.h>
00002 #include <tabletop_object_detector/TabletopDetection.h>
00003 #include <tabletop_collision_map_processing/TabletopCollisionMapProcessing.h>
00004
00005 int main(int argc, char **argv)
00006 {
00007
00008 ros::init(argc, argv, "tabletop_perception_test");
00009 ros::NodeHandle nh;
00010
00011
00012 const std::string OBJECT_DETECTION_SERVICE_NAME =
00013 "/object_detection";
00014 const std::string COLLISION_PROCESSING_SERVICE_NAME =
00015 "/tabletop_collision_map_processing/tabletop_collision_map_processing";
00016
00017
00018 ros::ServiceClient object_detection_srv;
00019 ros::ServiceClient collision_processing_srv;
00020
00021
00022 while (!ros::service::waitForService(OBJECT_DETECTION_SERVICE_NAME,
00023 ros::Duration(2.0)) && nh.ok() )
00024 {
00025 ROS_INFO("Waiting for object detection service to come up");
00026 }
00027 if (!nh.ok()) exit(0);
00028 object_detection_srv =
00029 nh.serviceClient<tabletop_object_detector::TabletopDetection>
00030 (OBJECT_DETECTION_SERVICE_NAME, true);
00031
00032
00033 while ( !ros::service::waitForService(COLLISION_PROCESSING_SERVICE_NAME,
00034 ros::Duration(2.0)) && nh.ok() )
00035 {
00036 ROS_INFO("Waiting for collision processing service to come up");
00037 }
00038 if (!nh.ok()) exit(0);
00039 collision_processing_srv =
00040 nh.serviceClient
00041 <tabletop_collision_map_processing::TabletopCollisionMapProcessing>
00042 (COLLISION_PROCESSING_SERVICE_NAME, true);
00043
00044
00045
00046 ROS_INFO("Calling tabletop detector");
00047 tabletop_object_detector::TabletopDetection detection_call;
00048
00049
00050 detection_call.request.return_clusters = false;
00051
00052 detection_call.request.return_models = false;
00053 if (!object_detection_srv.call(detection_call))
00054 {
00055 ROS_ERROR("Tabletop detection service failed");
00056 return -1;
00057 }
00058 if (detection_call.response.detection.result !=
00059 detection_call.response.detection.SUCCESS)
00060 {
00061 ROS_ERROR("Tabletop detection returned error code %d",
00062 detection_call.response.detection.result);
00063 return -1;
00064 }
00065 if (detection_call.response.detection.clusters.empty() &&
00066 detection_call.response.detection.models.empty() )
00067 {
00068 ROS_ERROR("The tabletop detector detected the table, "
00069 "but found no objects");
00070 return -1;
00071 }
00072 else
00073 {
00074 ROS_WARN("Tabletop suceeded and found %zu unknown clusters and %zu known objects, and the table", detection_call.response.detection.clusters.size(), detection_call.response.detection.models.size());
00075 }
00076
00077
00078 ROS_INFO("Calling collision map processing");
00079 tabletop_collision_map_processing::TabletopCollisionMapProcessing
00080 processing_call;
00081
00082 processing_call.request.detection_result =
00083 detection_call.response.detection;
00084
00085
00086 processing_call.request.reset_collision_models = true;
00087 processing_call.request.reset_attached_models = true;
00088
00089
00090
00091
00092 processing_call.request.desired_frame = "base_footprint";
00093 if (!collision_processing_srv.call(processing_call))
00094 {
00095 ROS_ERROR("Collision map processing service failed");
00096 return -1;
00097 }
00098
00099 if (processing_call.response.graspable_objects.empty())
00100 {
00101 ROS_ERROR("Collision map processing returned no graspable objects");
00102 return -1;
00103 }
00104 else
00105 {
00106 ROS_WARN("Collision map processing succeeded and returned %zu graspable objects", processing_call.response.graspable_objects.size() );
00107 }
00108
00109 }