$search
00001 //================================================================================================= 00002 // Copyright (c) 2012, Johannes Meyer, TU Darmstadt 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 // * Redistributions of source code must retain the above copyright 00008 // notice, this list of conditions and the following disclaimer. 00009 // * Redistributions in binary form must reproduce the above copyright 00010 // notice, this list of conditions and the following disclaimer in the 00011 // documentation and/or other materials provided with the distribution. 00012 // * Neither the name of the Flight Systems and Automatic Control group, 00013 // TU Darmstadt, nor the names of its contributors may be used to 00014 // endorse or promote products derived from this software without 00015 // specific prior written permission. 00016 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 //================================================================================================= 00028 00029 #include <hector_gazebo_plugins/reset_plugin.h> 00030 00031 #include <gazebo/Global.hh> 00032 #include <gazebo/XMLConfig.hh> 00033 #include <gazebo/Simulator.hh> 00034 #include <gazebo/gazebo.h> 00035 #include <gazebo/World.hh> 00036 #include <gazebo/PhysicsEngine.hh> 00037 #include <gazebo/GazeboError.hh> 00038 #include <gazebo/ControllerFactory.hh> 00039 00040 using namespace gazebo; 00041 00042 GZ_REGISTER_DYNAMIC_CONTROLLER("reset_plugin", GazeboResetPlugin) 00043 00044 GazeboResetPlugin::GazeboResetPlugin(Entity *parent) 00045 : Controller(parent) 00046 { 00047 if (!ros::isInitialized()) 00048 { 00049 int argc = 0; 00050 char** argv = NULL; 00051 ros::init(argc,argv, "gazebo", ros::init_options::NoSigintHandler|ros::init_options::AnonymousName); 00052 } 00053 00054 Param::Begin(¶meters); 00055 namespace_param_ = new ParamT<std::string>("robotNamespace", "", false); 00056 topic_param_ = new ParamT<std::string>("topicName", "/syscommand", false); 00057 Param::End(); 00058 } 00059 00061 // Destructor 00062 GazeboResetPlugin::~GazeboResetPlugin() 00063 { 00064 delete namespace_param_; 00065 delete topic_param_; 00066 } 00067 00069 // Load the controller 00070 void GazeboResetPlugin::LoadChild(XMLConfigNode *node) 00071 { 00072 namespace_param_->Load(node); 00073 namespace_ = namespace_param_->GetValue(); 00074 topic_param_->Load(node); 00075 topic_ = topic_param_->GetValue(); 00076 } 00077 00079 // Initialize the controller 00080 void GazeboResetPlugin::InitChild() 00081 { 00082 node_handle_ = new ros::NodeHandle(namespace_); 00083 00084 ros::AdvertiseOptions aso = ros::AdvertiseOptions::create<std_msgs::String>( 00085 topic_, 1, 00086 ros::SubscriberStatusCallback(), ros::SubscriberStatusCallback(), 00087 ros::VoidPtr(), &this->callback_queue_); 00088 publisher_ = node_handle_->advertise(aso); 00089 00090 } 00091 00093 // Update the controller 00094 void GazeboResetPlugin::UpdateChild() 00095 { 00096 } 00097 00099 // Reset the controller 00100 void GazeboResetPlugin::ResetChild() 00101 { 00102 std_msgs::String command; 00103 command.data = "reset"; 00104 publisher_.publish(command); 00105 } 00106 00108 // Finalize the controller 00109 void GazeboResetPlugin::FiniChild() 00110 { 00111 node_handle_->shutdown(); 00112 delete node_handle_; 00113 }