table_object_cluster_action_client_old.cpp
Go to the documentation of this file.
00001 
00059 /*
00060  * plane_extraction_action_client.cpp
00061  *
00062  *  Created on: 26.08.2011
00063  *      Author: goa
00064  */
00065 
00066 
00067 #include <ros/ros.h>
00068 #include <actionlib/client/simple_action_client.h>
00069 #include <actionlib/client/terminal_state.h>
00070 #include <cob_3d_mapping_msgs/TableObjectClusterAction.h>
00071 #include <cob_3d_mapping_msgs/GetObjectsOfClass.h>
00072 #include <pcl/io/pcd_io.h>
00073 #include <pcl/point_types.h>
00074 
00075 int main (int argc, char **argv)
00076 {
00077   ros::init(argc, argv, "test_table_object_cluster");
00078   ros::NodeHandle nh;
00079 
00080   ros::ServiceClient get_tables_client_;
00081   get_tables_client_ = nh.serviceClient<cob_3d_mapping_msgs::GetObjectsOfClass> ("get_objects_of_class");
00082   ROS_INFO("waiting for server to start");
00083   ros::service::waitForService ("get_objects_of_class");
00084   //build message
00085   cob_3d_mapping_msgs::GetObjectsOfClassRequest req;
00086   cob_3d_mapping_msgs::GetObjectsOfClassResponse res;
00087   get_tables_client_.call (req, res);
00088   ROS_INFO("Service call finished, found %d tables", res.objects.shapes.size());
00089 
00090   for(unsigned int i=0; i<res.objects.shapes.size(); i++)
00091   {
00092     // create the action client
00093     // true causes the client to spin its own thread
00094     actionlib::SimpleActionClient<cob_3d_mapping_msgs::TableObjectClusterAction> ac("table_object_cluster", true);
00095 
00096     ROS_INFO("Waiting for action server to start.");
00097     // wait for the action server to start
00098     ac.waitForServer(); //will wait for infinite time
00099 
00100     ROS_INFO("Action server started, sending goal.");
00101     // send a goal to the action
00102     cob_3d_mapping_msgs::TableObjectClusterGoal goal;
00103     goal.table_hull = res.objects.shapes[i].points[0];
00104     ac.sendGoal(goal);
00105 
00106     //wait for the action to return
00107     bool finished_before_timeout = ac.waitForResult(ros::Duration(30.0));
00108 
00109     if (finished_before_timeout)
00110     {
00111       actionlib::SimpleClientGoalState state = ac.getState();
00112       ROS_INFO("Action finished: %s",state.toString().c_str());
00113     }
00114     else
00115     {
00116       ROS_INFO("Action did not finish before the time out.");
00117       return 0;
00118     }
00119     cob_3d_mapping_msgs::TableObjectClusterResultConstPtr res = ac.getResult();
00120     for( unsigned int j=0; j < res->bounding_boxes.size(); j++)
00121     {
00122       pcl::PointCloud<pcl::PointXYZ> pc;
00123       pcl::fromROSMsg(res->bounding_boxes[j], pc);
00124       std::stringstream ss;
00125       ss << "/tmp/cluster_" << i << "_" << j << ".pcd";
00126       pcl::io::savePCDFile(ss.str(),pc, false);
00127     }
00128   }
00129   //exit
00130   return 0;
00131 }
00132 


cob_table_object_cluster
Author(s): Georg Arbeiter
autogenerated on Wed Aug 26 2015 11:05:13