gazebo_ros_paths_plugin.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2012-2014 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  * Author: John Hsu, Nate Koenig, Dave Coleman
00019  * Desc: External interfaces for Gazebo
00020  */
00021 
00022 #include <gazebo/common/SystemPaths.hh>
00023 #include <gazebo/common/Plugin.hh>
00024 
00025 #include <ros/ros.h>
00026 #include <ros/package.h>
00027 
00028 #include <map>
00029 
00030 namespace gazebo
00031 {
00032 
00033 typedef std::vector<std::string> V_string;
00034 typedef std::map<std::string, std::string> M_string;
00035 
00036 class GazeboRosPathsPlugin : public SystemPlugin
00037 {
00038 public:
00039   GazeboRosPathsPlugin()
00040   {
00041     this->LoadPaths();
00042   }
00043 
00044   ~GazeboRosPathsPlugin()
00045   {
00046   };
00047 
00048   void Init()
00049   {
00050   }
00051 
00052   void Load(int argc, char** argv)
00053   {
00054   }
00055 
00060   void LoadPaths()
00061   {
00062     // set gazebo media paths by adding all packages that exports "gazebo_media_path" for gazebo
00063     gazebo::common::SystemPaths::Instance()->gazeboPathsFromEnv = false;
00064     std::vector<std::string> gazebo_media_paths;
00065     ros::package::getPlugins("gazebo_ros","gazebo_media_path",gazebo_media_paths);
00066     for (std::vector<std::string>::iterator iter=gazebo_media_paths.begin(); iter != gazebo_media_paths.end(); iter++)
00067     {
00068       ROS_DEBUG("med path %s",iter->c_str());
00069       gazebo::common::SystemPaths::Instance()->AddGazeboPaths(iter->c_str());
00070     }
00071 
00072     // set gazebo plugins paths by adding all packages that exports "plugin_path" for gazebo
00073     gazebo::common::SystemPaths::Instance()->pluginPathsFromEnv = false;
00074     std::vector<std::string> plugin_paths;
00075     ros::package::getPlugins("gazebo_ros","plugin_path",plugin_paths);
00076     for (std::vector<std::string>::iterator iter=plugin_paths.begin(); iter != plugin_paths.end(); iter++)
00077     {
00078       ROS_DEBUG("plugin path %s",(*iter).c_str());
00079       gazebo::common::SystemPaths::Instance()->AddPluginPaths(iter->c_str());
00080     }
00081 
00082     // set model paths by adding all packages that exports "gazebo_model_path" for gazebo
00083     gazebo::common::SystemPaths::Instance()->modelPathsFromEnv = false;
00084     std::vector<std::string> model_paths;
00085     ros::package::getPlugins("gazebo_ros","gazebo_model_path",model_paths);
00086     for (std::vector<std::string>::iterator iter=model_paths.begin(); iter != model_paths.end(); iter++)
00087     {
00088       ROS_DEBUG("model path %s",(*iter).c_str());
00089       gazebo::common::SystemPaths::Instance()->AddModelPaths(iter->c_str());
00090     }
00091 
00092     // set .gazeborc path to something else, so we don't pick up default ~/.gazeborc
00093     std::string gazeborc = ros::package::getPath("gazebo_ros")+"/.do_not_use_gazeborc";
00094     setenv("GAZEBORC",gazeborc.c_str(),1);
00095   }
00096 
00097 };
00098 
00099 // Register this plugin with the simulator
00100 GZ_REGISTER_SYSTEM_PLUGIN(GazeboRosPathsPlugin)
00101 
00102 }
00103 


gazebo_ros
Author(s): John Hsu, Nate Koenig, Dave Coleman
autogenerated on Thu Jun 6 2019 18:41:02