gazebo_ros_paths_plugin.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /*
18  * Author: John Hsu, Nate Koenig, Dave Coleman
19  * Desc: External interfaces for Gazebo
20  */
21 
22 #include <gazebo/common/SystemPaths.hh>
23 #include <gazebo/common/Plugin.hh>
24 
25 #include <ros/ros.h>
26 #include <ros/package.h>
27 
28 #include <map>
29 
30 namespace gazebo
31 {
32 
33 typedef std::vector<std::string> V_string;
34 typedef std::map<std::string, std::string> M_string;
35 
36 class GazeboRosPathsPlugin : public SystemPlugin
37 {
38 public:
40  {
41  this->LoadPaths();
42  }
43 
45  {
46  };
47 
48  void Init()
49  {
50  }
51 
52  void Load(int argc, char** argv)
53  {
54  }
55 
60  void LoadPaths()
61  {
62  // set gazebo media paths by adding all packages that exports "gazebo_media_path" for gazebo
63  gazebo::common::SystemPaths::Instance()->gazeboPathsFromEnv = false;
64  std::vector<std::string> gazebo_media_paths;
65  ros::package::getPlugins("gazebo_ros","gazebo_media_path",gazebo_media_paths);
66  for (std::vector<std::string>::iterator iter=gazebo_media_paths.begin(); iter != gazebo_media_paths.end(); iter++)
67  {
68  ROS_DEBUG_NAMED("paths_plugin", "Media path %s",iter->c_str());
69  gazebo::common::SystemPaths::Instance()->AddGazeboPaths(iter->c_str());
70  }
71 
72  // set gazebo plugins paths by adding all packages that exports "plugin_path" for gazebo
73  gazebo::common::SystemPaths::Instance()->pluginPathsFromEnv = false;
74  std::vector<std::string> plugin_paths;
75  ros::package::getPlugins("gazebo_ros","plugin_path",plugin_paths);
76  for (std::vector<std::string>::iterator iter=plugin_paths.begin(); iter != plugin_paths.end(); iter++)
77  {
78  ROS_DEBUG_NAMED("paths_plugin", "plugin path %s",(*iter).c_str());
79  gazebo::common::SystemPaths::Instance()->AddPluginPaths(iter->c_str());
80  }
81 
82  // set model paths by adding all packages that exports "gazebo_model_path" for gazebo
83  gazebo::common::SystemPaths::Instance()->modelPathsFromEnv = false;
84  std::vector<std::string> model_paths;
85  ros::package::getPlugins("gazebo_ros","gazebo_model_path",model_paths);
86  for (std::vector<std::string>::iterator iter=model_paths.begin(); iter != model_paths.end(); iter++)
87  {
88  ROS_DEBUG_NAMED("paths_plugin", "Model path %s",(*iter).c_str());
89  gazebo::common::SystemPaths::Instance()->AddModelPaths(iter->c_str());
90  }
91 
92  // set .gazeborc path to something else, so we don't pick up default ~/.gazeborc
93  std::string gazeborc = ros::package::getPath("gazebo_ros")+"/.do_not_use_gazeborc";
94  setenv("GAZEBORC",gazeborc.c_str(),1);
95  }
96 
97 };
98 
99 // Register this plugin with the simulator
100 GZ_REGISTER_SYSTEM_PLUGIN(GazeboRosPathsPlugin)
101 
102 }
std::vector< std::string > V_string
#define ROS_DEBUG_NAMED(name,...)
ROSLIB_DECL std::string getPath(const std::string &package_name)
ROSLIB_DECL void getPlugins(const std::string &package, const std::string &attribute, V_string &plugins, bool force_recrawl=false)
void LoadPaths()
Set Gazebo Path/Resources Configurations GAZEBO_MODEL_PATH, PLUGIN_PATH and GAZEBO_MEDIA_PATH by addi...
std::map< std::string, std::string > M_string
void Load(int argc, char **argv)


gazebo_ros
Author(s): John Hsu, Nate Koenig, Dave Coleman
autogenerated on Tue Apr 6 2021 02:19:48