amtec_acquire_data.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Dejan Pangercic <pangercic@cs.tum.edu>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <ros/ros.h>
00031 #include <actionlib/client/simple_action_client.h>
00032 #include <actionlib/client/terminal_state.h>
00033 
00034 //for GetClustersAction
00035 #include <pcl_cloud_tools/GetClustersAction.h>
00036 
00037 //for rotating amtec PTU
00038 #include <amtec/SetPosition.h>
00039 
00040 boost::shared_ptr<const pcl_cloud_tools::GetClustersResult> getClusters(int ec_goal)
00041 {
00042   //get the object from Kinect
00043   typedef actionlib::SimpleActionClient<pcl_cloud_tools::GetClustersAction> GetClustersClient;
00044   GetClustersClient gcc("/extract_clusters/get_clusters", true);
00045   while(!gcc.waitForServer())
00046     {
00047       ROS_INFO("Waiting for /extract_clusters/get_clusters server to come up");
00048     }
00049   
00050   pcl_cloud_tools::GetClustersGoal goal;
00051   goal.ec_goal = ec_goal;
00052   // Fill in goal here
00053   gcc.sendGoal(goal);
00054   gcc.waitForResult(ros::Duration(5.0));
00055   if (gcc.getState() == actionlib::SimpleClientGoalState::SUCCEEDED)
00056     ROS_INFO("/extract_clusters/get_clusters SUCCEEDED");
00057   boost::shared_ptr<const pcl_cloud_tools::GetClustersResult> result = gcc.getResult();
00058   return result;
00059 }
00060 
00061 
00062 int main (int argc, char **argv)
00063 {
00064     ros::init(argc, argv, "amtec_acquire_data");
00065     ros::NodeHandle nh;
00066     //get the cluster on the table
00067     boost::shared_ptr<const pcl_cloud_tools::GetClustersResult> result = getClusters(0);
00068     if (result->clusters.size () == 0)
00069     {
00070       ROS_ERROR("No clusters found, returning");
00071       return -1;
00072     }
00073     else
00074     {
00075       ROS_INFO("%ld clusters found", result->clusters.size ());
00076     }
00077 
00078     //rotate amtec unit
00079     ros::ServiceClient client = nh.serviceClient<amtec::SetPosition>("/amtec/set_position");
00080     amtec::SetPosition srv;
00081     srv.request.position_pan = 0.0;
00082     srv.request.position_pan = atof(argv[1]);
00083     if (client.call(srv))
00084     {
00085       ROS_INFO("Successful call to service /amtec/set_position");
00086     }
00087     else
00088     {
00089       ROS_ERROR("Failed to call service /amtec/set_position");
00090       return -1;
00091     }
00092     return 0;
00093 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends


pr2_data_acquisition_tools
Author(s): Dejan Pangercic
autogenerated on Thu May 23 2013 17:32:31