$search
00001 /* 00002 * Copyright (c) 2008, 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 #ifndef GAZEBO_CONTROLLER_MANAGER_H 00031 #define GAZEBO_CONTROLLER_MANAGER_H 00032 00033 #include <vector> 00034 #include <map> 00035 #include <gazebo/Controller.hh> 00036 #include <gazebo/Entity.hh> 00037 #include <gazebo/Model.hh> 00038 #include "pr2_hardware_interface/hardware_interface.h" 00039 #include "pr2_controller_manager/controller_manager.h" 00040 #include "pr2_gazebo_plugins/SetModelsJointsStates.h" 00041 #include "pr2_mechanism_model/robot.h" 00042 #include <tinyxml.h> 00043 #include <gazebo/Param.hh> 00044 #include <ros/ros.h> 00045 #undef USE_CBQ 00046 #ifdef USE_CBQ 00047 #include <ros/callback_queue.h> 00048 #endif 00049 00050 #include "boost/thread/mutex.hpp" 00051 00052 namespace gazebo 00053 { 00054 class XMLConfigNode; 00055 00058 00104 class GazeboRosControllerManager : public gazebo::Controller 00105 { 00106 public: 00107 GazeboRosControllerManager(Entity *parent); 00108 virtual ~GazeboRosControllerManager(); 00109 00110 protected: 00111 // Inherited from gazebo::Controller 00112 virtual void LoadChild(XMLConfigNode *node); 00113 virtual void InitChild(); 00114 virtual void UpdateChild(); 00115 virtual void FiniChild(); 00116 00117 private: 00118 00119 Model *parent_model_; 00120 pr2_hardware_interface::HardwareInterface hw_; 00121 pr2_controller_manager::ControllerManager *cm_; 00122 00126 pr2_mechanism_model::RobotState *fake_state_; 00127 std::vector<gazebo::Joint*> joints_; 00128 00130 private: ParamT<std::string> *setModelsJointsStatesServiceNameP; 00131 private: std::string setModelsJointsStatesServiceName; 00132 00133 /* 00134 * \brief read pr2.xml for actuators, and pass tinyxml node to mechanism control node's initXml. 00135 */ 00136 void ReadPr2Xml(XMLConfigNode *node); 00137 00138 /* 00139 * \brief pointer to ros node 00140 */ 00141 ros::NodeHandle* rosnode_; 00142 00144 private: ros::ServiceServer setModelsJointsStatesService; 00145 00147 private: bool setModelsJointsStates(pr2_gazebo_plugins::SetModelsJointsStates::Request &req, 00148 pr2_gazebo_plugins::SetModelsJointsStates::Response &res); 00149 00151 /* 00152 * \brief tmp vars for performance checking 00153 */ 00154 double wall_start_, sim_start_; 00155 00157 ParamT<std::string> *robotParamP; 00158 ParamT<std::string> *robotNamespaceP; 00159 std::string robotParam; 00160 std::string robotNamespace; 00161 00162 bool fake_calibration_; 00163 00164 #ifdef USE_CBQ 00165 private: ros::CallbackQueue controller_manager_queue_; 00166 private: void ControllerManagerQueueThread(); 00167 private: boost::thread controller_manager_callback_queue_thread_; 00168 #endif 00169 private: void ControllerManagerROSThread(); 00170 private: boost::thread ros_spinner_thread_; 00171 00172 }; 00173 00175 00176 00177 } 00178 00179 #endif 00180