test_action_client.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, Willow Garage, Inc.
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 the 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 
00032 #include <actionlib/client/simple_action_client.h>
00033 #include <std_msgs/Empty.h>
00034 
00035 #include "pr2_gripper_click/GripperClickPickupAction.h"
00036 #include "pr2_gripper_click/GripperClickPlaceAction.h"
00037 
00038 class GraspPlanningGripperClick
00039 {
00040 private:
00041   ros::NodeHandle root_nh_;
00042 
00043   ros::NodeHandle priv_nh_;
00044 
00045   actionlib::SimpleActionClient<pr2_gripper_click::GripperClickPickupAction> *pickup_action_client_;
00046   actionlib::SimpleActionClient<pr2_gripper_click::GripperClickPlaceAction> *place_action_client_;
00047 
00048   std::string pickup_action_topic_;
00049   std::string place_action_topic_;
00050 
00051   ros::Subscriber sub_;
00052 
00053   void triggerCb(const std_msgs::EmptyConstPtr& msg)
00054   {
00055     while(!pickup_action_client_->waitForServer(ros::Duration(2.0)) && priv_nh_.ok())
00056     {
00057       ROS_INFO("Waiting for action client");
00058     }
00059     
00060     pr2_gripper_click::GripperClickPickupGoal click_goal;
00061     ROS_INFO("Sending goal");
00062     pickup_action_client_->sendGoal(click_goal);
00063     while (!pickup_action_client_->waitForResult(ros::Duration(0.5)) && priv_nh_.ok())
00064     {
00065     }
00066     if (!priv_nh_.ok()) 
00067     {
00068       pickup_action_client_->cancelGoal();
00069       return;
00070     }
00071     if (pickup_action_client_->getState() != actionlib::SimpleClientGoalState::SUCCEEDED)
00072     {
00073       ROS_INFO("The gripper click grasp action has not succeeded;");
00074     }
00075     else
00076     {    
00077       ROS_INFO("Gripper click grasp has succeeded;");
00078     }
00079   }
00080 
00081 public:
00082   GraspPlanningGripperClick() : 
00083     root_nh_(""), priv_nh_("~")
00084   {
00085     
00086     priv_nh_.param<std::string>("pickup_action_topic", pickup_action_topic_, "/gripper_click_pickup_ui");    
00087     pickup_action_client_ = new actionlib::SimpleActionClient<pr2_gripper_click::GripperClickPickupAction>
00088       (pickup_action_topic_, true);
00089     
00090     priv_nh_.param<std::string>("place_action_topic", place_action_topic_, "/gripper_click_place_ui");    
00091     place_action_client_ = new actionlib::SimpleActionClient<pr2_gripper_click::GripperClickPlaceAction>
00092       (place_action_topic_, true);
00093 
00094     //sub_ = root_nh_.subscribe("trigger", 1, boost::bind(&GraspPlanningGripperClick::triggerCb, this, _1));
00095     sub_ = root_nh_.subscribe("trigger", 1, &GraspPlanningGripperClick::triggerCb, this);
00096 
00097     ROS_INFO("Grasp planning gripper click node started");
00098   }
00099   ~GraspPlanningGripperClick()
00100   {
00101     delete pickup_action_client_;
00102     delete place_action_client_;
00103   }
00104 };
00105 
00106 int main(int argc, char **argv)
00107 {
00108   ros::init(argc, argv, "grasp_planning_gripper_click_node");
00109   GraspPlanningGripperClick node;
00110   ros::spin();
00111   return 0;
00112 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends


pr2_gripper_click
Author(s): Matei Ciocarlie
autogenerated on Tue Oct 30 2012 07:55:20