00001 /* 00002 * Copyright (C) 2015-2016 Open Source Robotics Foundation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 */ 00017 /* 00018 Desc: GazeboVacuumGripper plugin for manipulating objects in Gazebo 00019 * Author: Kentaro Wada 00020 * Date: 7 Dec 2015 00021 */ 00022 00023 #ifndef GAZEBO_ROS_VACUUM_GRIPPER_HH 00024 #define GAZEBO_ROS_VACUUM_GRIPPER_HH 00025 00026 #include <string> 00027 00028 // Custom Callback Queue 00029 #include <ros/callback_queue.h> 00030 #include <ros/advertise_options.h> 00031 #include <ros/advertise_service_options.h> 00032 #include <std_srvs/Empty.h> 00033 00034 #include <ros/ros.h> 00035 #include <boost/thread.hpp> 00036 #include <boost/thread/mutex.hpp> 00037 00038 #include <gazebo/physics/physics.hh> 00039 #include <gazebo/transport/TransportTypes.hh> 00040 #include <gazebo/common/Plugin.hh> 00041 #include <gazebo/common/Events.hh> 00042 00043 00044 namespace gazebo 00045 { 00048 00095 class GazeboRosVacuumGripper : public ModelPlugin 00096 { 00098 public: GazeboRosVacuumGripper(); 00099 00101 public: virtual ~GazeboRosVacuumGripper(); 00102 00103 // Documentation inherited 00104 protected: void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf); 00105 00106 // Documentation inherited 00107 protected: virtual void UpdateChild(); 00108 00110 private: void QueueThread(); 00111 00112 private: bool OnServiceCallback(std_srvs::Empty::Request &req, 00113 std_srvs::Empty::Response &res); 00114 private: bool OffServiceCallback(std_srvs::Empty::Request &req, 00115 std_srvs::Empty::Response &res); 00116 00117 private: bool status_; 00118 00119 private: physics::ModelPtr parent_; 00120 00122 private: physics::WorldPtr world_; 00123 00125 private: physics::LinkPtr link_; 00126 00128 private: ros::NodeHandle* rosnode_; 00129 00131 private: boost::mutex lock_; 00132 private: ros::Publisher pub_; 00133 private: ros::ServiceServer srv1_; 00134 private: ros::ServiceServer srv2_; 00135 00137 private: std::string topic_name_; 00138 private: std::string service_name_; 00140 private: std::string link_name_; 00141 00143 private: std::string robot_namespace_; 00144 00145 // Custom Callback Queue 00146 private: ros::CallbackQueue queue_; 00148 private: boost::thread callback_queue_thread_; 00149 00150 // Pointer to the update event connection 00151 private: event::ConnectionPtr update_connection_; 00152 00154 private: int connect_count_; 00155 private: void Connect(); 00156 private: void Disconnect(); 00157 }; 00159 00160 } 00161 #endif