$search
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 "pr2_interactive_manipulation/interactive_marker_node.h" 00031 00032 #include <visualization_msgs/InteractiveMarker.h> 00033 #include <visualization_msgs/InteractiveMarkerFeedback.h> 00034 00035 using namespace visualization_msgs; 00036 using namespace interactive_markers; 00037 00038 namespace pr2_interactive_manipulation 00039 { 00040 00041 typedef actionlib::SimpleActionClient<pr2_object_manipulation_msgs::IMGUIAction> IMGUIActionClient; 00042 00043 InteractiveMarkerNode::InteractiveMarkerNode() : 00044 root_nh_(""), 00045 priv_nh_("~"), 00046 im_gui_action_client_("imgui_action", true), 00047 marker_server_("interactive_manipulation") 00048 { 00049 graspable_objects_sub_ = root_nh_.subscribe("interactive_object_recognition_result", 10, 00050 &InteractiveMarkerNode::processGraspableObjects, this); 00051 00052 options_.collision_checked = true; 00053 options_.grasp_selection = 1; 00054 00055 options_.adv_options.lift_steps = 10; 00056 options_.adv_options.retreat_steps = 10; 00057 options_.adv_options.reactive_force = false; 00058 options_.adv_options.reactive_grasping = false; 00059 options_.adv_options.reactive_place = false; 00060 options_.adv_options.lift_direction_choice = 0; 00061 00062 dyn_conf_srv_.setCallback( boost::bind(&InteractiveMarkerNode::processConfig, this, _1, _2) ); 00063 collision_map_interface_.resetCollisionId(1000); 00064 00065 } 00066 00067 InteractiveMarkerNode::~InteractiveMarkerNode() 00068 { 00069 } 00070 00071 void InteractiveMarkerNode::processConfig(PickupConfig &config, uint32_t level) 00072 { 00073 options_.adv_options.reactive_grasping = config.reactive_grasping; 00074 options_.adv_options.lift_steps = config.lift_steps; 00075 if (config.lift_vertically) options_.adv_options.lift_direction_choice = 0; 00076 else options_.adv_options.lift_direction_choice = 1; 00077 } 00078 00079 void InteractiveMarkerNode::processGraspableObjects( 00080 const pr2_interactive_object_detection::GraspableObjectListConstPtr &objects) 00081 { 00082 object_handlers_.clear(); 00083 00084 if ( objects->meshes.size() != objects->graspable_objects.size() ) 00085 { 00086 ROS_ERROR( "Number of meshes an graspable objects is not identical!" ); 00087 return; 00088 } 00089 00090 for ( unsigned o=0; o<objects->meshes.size() && o<objects->graspable_objects.size(); o++ ) 00091 { 00092 char name[255]; 00093 sprintf( name, "object_%d", o ); 00094 00095 object_handlers_.push_back( boost::shared_ptr<GraspableObjectHandler>( new GraspableObjectHandler( name, this, objects->graspable_objects[o], objects->meshes[o], marker_server_, options_, &collision_map_interface_ ) ) ); 00096 } 00097 marker_server_.applyChanges(); 00098 } 00099 00100 std::vector<object_manipulation_msgs::GraspableObject> InteractiveMarkerNode::getMovableObstacles() 00101 { 00102 std::vector<object_manipulation_msgs::GraspableObject> movable_obstacles; 00103 for (size_t i=0; i<object_handlers_.size(); i++) 00104 { 00105 if (!object_handlers_[i]->getCollisionName().empty()) 00106 { 00107 movable_obstacles.push_back(object_handlers_[i]->getGraspableObject()); 00108 } 00109 } 00110 return movable_obstacles; 00111 } 00112 00113 } 00114 00115 00116 int main(int argc, char **argv) 00117 { 00118 ros::init(argc, argv, "interactive_manipulation_marker_node"); 00119 pr2_interactive_manipulation::InteractiveMarkerNode node; 00120 ros::spin(); 00121 return 0; 00122 } 00123