00001 /********************************************************************* 00002 * Software License Agreement (BSD License) 00003 * 00004 * Copyright (c) 2013, Open Source Robotics Foundation 00005 * Copyright (c) 2013, The Johns Hopkins University 00006 * All rights reserved. 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions 00010 * are met: 00011 * 00012 * * Redistributions of source code must retain the above copyright 00013 * notice, this list of conditions and the following disclaimer. 00014 * * Redistributions in binary form must reproduce the above 00015 * copyright notice, this list of conditions and the following 00016 * disclaimer in the documentation and/or other materials provided 00017 * with the distribution. 00018 * * Neither the name of the Open Source Robotics Foundation 00019 * nor the names of its contributors may be 00020 * used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00026 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00027 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00028 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00029 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00030 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00032 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 00033 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00034 * POSSIBILITY OF SUCH DAMAGE. 00035 *********************************************************************/ 00036 00037 /* Author: Dave Coleman, Jonathan Bohren 00038 Desc: Gazebo plugin for ros_control that allows 'hardware_interfaces' to be plugged in 00039 using pluginlib 00040 */ 00041 00042 // Boost 00043 #include <boost/shared_ptr.hpp> 00044 #include <boost/thread.hpp> 00045 00046 // ROS 00047 #include <ros/ros.h> 00048 #include <pluginlib/class_loader.h> 00049 #include <std_msgs/Bool.h> 00050 00051 // Gazebo 00052 #include <gazebo/gazebo.hh> 00053 #include <gazebo/physics/physics.hh> 00054 #include <gazebo/common/common.hh> 00055 00056 // ros_control 00057 #include <gazebo_ros_control/robot_hw_sim.h> 00058 #include <controller_manager/controller_manager.h> 00059 #include <transmission_interface/transmission_parser.h> 00060 00061 namespace gazebo_ros_control 00062 { 00063 00064 class GazeboRosControlPlugin : public gazebo::ModelPlugin 00065 { 00066 public: 00067 00068 virtual ~GazeboRosControlPlugin(); 00069 00070 // Overloaded Gazebo entry point 00071 virtual void Load(gazebo::physics::ModelPtr parent, sdf::ElementPtr sdf); 00072 00073 // Called by the world update start event 00074 void Update(); 00075 00076 // Called on world reset 00077 virtual void Reset(); 00078 00079 // Get the URDF XML from the parameter server 00080 std::string getURDF(std::string param_name) const; 00081 00082 // Get Transmissions from the URDF 00083 bool parseTransmissionsFromURDF(const std::string& urdf_string); 00084 00085 protected: 00086 void eStopCB(const std_msgs::BoolConstPtr& e_stop_active); 00087 00088 // Node Handles 00089 ros::NodeHandle model_nh_; // namespaces to robot name 00090 00091 // Pointer to the model 00092 gazebo::physics::ModelPtr parent_model_; 00093 sdf::ElementPtr sdf_; 00094 00095 // deferred load in case ros is blocking 00096 boost::thread deferred_load_thread_; 00097 00098 // Pointer to the update event connection 00099 gazebo::event::ConnectionPtr update_connection_; 00100 00101 // Interface loader 00102 boost::shared_ptr<pluginlib::ClassLoader<gazebo_ros_control::RobotHWSim> > robot_hw_sim_loader_; 00103 void load_robot_hw_sim_srv(); 00104 00105 // Strings 00106 std::string robot_namespace_; 00107 std::string robot_description_; 00108 00109 // Transmissions in this plugin's scope 00110 std::vector<transmission_interface::TransmissionInfo> transmissions_; 00111 00112 // Robot simulator interface 00113 std::string robot_hw_sim_type_str_; 00114 boost::shared_ptr<gazebo_ros_control::RobotHWSim> robot_hw_sim_; 00115 00116 // Controller manager 00117 boost::shared_ptr<controller_manager::ControllerManager> controller_manager_; 00118 00119 // Timing 00120 ros::Duration control_period_; 00121 ros::Time last_update_sim_time_ros_; 00122 ros::Time last_write_sim_time_ros_; 00123 00124 // e_stop_active_ is true if the emergency stop is active. 00125 bool e_stop_active_, last_e_stop_active_; 00126 ros::Subscriber e_stop_sub_; // Emergency stop subscriber 00127 00128 }; 00129 00130 00131 }