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 #ifdef _WIN32
31 int setenv(const char *name, const char *value, int overwrite)
32 {
33  int errcode = 0;
34  if(!overwrite) {
35  size_t envsize = 0;
36  errcode = ::getenv_s(&envsize, NULL, 0, name);
37  if(errcode || envsize) return errcode;
38  }
39  return ::_putenv_s(name, value);
40 }
41 #endif
42 
43 namespace gazebo
44 {
45 
46 typedef std::vector<std::string> V_string;
47 typedef std::map<std::string, std::string> M_string;
48 
49 class GazeboRosPathsPlugin : public SystemPlugin
50 {
51 public:
53  {
54  this->LoadPaths();
55  }
56 
58  {
59  };
60 
61  void Init()
62  {
63  }
64 
65  void Load(int argc, char** argv)
66  {
67  }
68 
73  void LoadPaths()
74  {
75  // set gazebo media paths by adding all packages that exports "gazebo_media_path" for gazebo
76  gazebo::common::SystemPaths::Instance()->gazeboPathsFromEnv = false;
77  std::vector<std::string> gazebo_media_paths;
78  ros::package::getPlugins("gazebo_ros","gazebo_media_path",gazebo_media_paths);
79  for (std::vector<std::string>::iterator iter=gazebo_media_paths.begin(); iter != gazebo_media_paths.end(); iter++)
80  {
81  ROS_DEBUG_NAMED("paths_plugin", "Media path %s",iter->c_str());
82  gazebo::common::SystemPaths::Instance()->AddGazeboPaths(iter->c_str());
83  }
84 
85  // set gazebo plugins paths by adding all packages that exports "plugin_path" for gazebo
86  gazebo::common::SystemPaths::Instance()->pluginPathsFromEnv = false;
87  std::vector<std::string> plugin_paths;
88  ros::package::getPlugins("gazebo_ros","plugin_path",plugin_paths);
89  for (std::vector<std::string>::iterator iter=plugin_paths.begin(); iter != plugin_paths.end(); iter++)
90  {
91  ROS_DEBUG_NAMED("paths_plugin", "plugin path %s",(*iter).c_str());
92  gazebo::common::SystemPaths::Instance()->AddPluginPaths(iter->c_str());
93  }
94 
95  // set model paths by adding all packages that exports "gazebo_model_path" for gazebo
96  gazebo::common::SystemPaths::Instance()->modelPathsFromEnv = false;
97  std::vector<std::string> model_paths;
98  ros::package::getPlugins("gazebo_ros","gazebo_model_path",model_paths);
99  for (std::vector<std::string>::iterator iter=model_paths.begin(); iter != model_paths.end(); iter++)
100  {
101  ROS_DEBUG_NAMED("paths_plugin", "Model path %s",(*iter).c_str());
102  gazebo::common::SystemPaths::Instance()->AddModelPaths(iter->c_str());
103  }
104 
105  // set .gazeborc path to something else, so we don't pick up default ~/.gazeborc
106  std::string gazeborc = ros::package::getPath("gazebo_ros")+"/.do_not_use_gazeborc";
107  setenv("GAZEBORC",gazeborc.c_str(),1);
108  }
109 
110 };
111 
112 // Register this plugin with the simulator
113 GZ_REGISTER_SYSTEM_PLUGIN(GazeboRosPathsPlugin)
114 
115 }
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 Wed Aug 24 2022 02:47:50