00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2008, Willow Garage, Inc. 00005 * All rights reserved. 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * * Redistributions in binary form must reproduce the above 00014 * copyright notice, this list of conditions and the following 00015 * disclaimer in the documentation and/or other materials provided 00016 * with the distribution. 00017 * * Neither the name of Willow Garage nor the names of its 00018 * contributors may be used to endorse or promote products derived 00019 * from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00022 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00023 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00024 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00025 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00026 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00027 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00028 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00030 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00031 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00032 * POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 * $Id$ 00035 * 00036 *********************************************************************/ 00037 00038 /* Author: Wim Meeussen */ 00039 00040 #include "pr2_doors_actions/action_detect_door.h" 00041 #include <pr2_doors_common/door_functions.h> 00042 #include <actionlib/client/simple_action_client.h> 00043 #include <door_msgs/DoorAction.h> 00044 #include <ros/ros.h> 00045 00046 using namespace ros; 00047 using namespace std; 00048 using namespace door_handle_detector; 00049 using namespace pr2_doors_common; 00050 00051 // ----------------------------------- 00052 // MAIN 00053 // ----------------------------------- 00054 00055 int 00056 main (int argc, char **argv) 00057 { 00058 ros::init(argc, argv, "trigger_door_action"); 00059 00060 if (argc < 2){ 00061 ROS_ERROR("Name of action to trigger required"); 00062 return 0; 00063 } 00064 00065 // goal 00066 door_msgs::DoorGoal door_goal; 00067 door_goal.door.frame_p1.x = 1.0; 00068 door_goal.door.frame_p1.y = -0.5; 00069 door_goal.door.frame_p2.x = 1.0; 00070 door_goal.door.frame_p2.y = 0.5; 00071 door_goal.door.rot_dir = door_msgs::Door::ROT_DIR_COUNTERCLOCKWISE; 00072 door_goal.door.hinge = door_msgs::Door::HINGE_P2; 00073 door_goal.door.header.frame_id = "base_footprint"; 00074 00075 // create action client 00076 actionlib::SimpleActionClient<door_msgs::DoorAction> action_client(argv[1], true); 00077 cout << "waiting for action server to start..." << endl; 00078 boost::thread(boost::bind(&ros::spin)); 00079 action_client.waitForServer(); 00080 cout << "... started" << endl; 00081 00082 // call action server from action client 00083 action_client.sendGoalAndWait(door_goal); 00084 bool finished_before_timeout = action_client.waitForResult(ros::Duration(30.0)); 00085 00086 if (finished_before_timeout){ 00087 actionlib::SimpleClientGoalState state = action_client.getState(); 00088 cout << "Door detection finished with state " << state.toString() << endl; 00089 cout << " resulting door: " << action_client.getResult()->door << endl; 00090 } 00091 else{ 00092 cout << "Door detection timed out" << endl; 00093 } 00094 00095 return (0); 00096 }