Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <ros/ros.h>
00029 #include <ros/package.h>
00030 #include <gazebo/gazebo_ros_api_plugin.h>
00031
00032 #include <map>
00033
00034 namespace gazebo
00035 {
00036
00037 typedef std::vector<std::string> V_string;
00038 typedef std::map<std::string, std::string> M_string;
00039
00040 class GazeboRosPathsPlugin : public SystemPlugin
00041 {
00042 public:
00043 GazeboRosPathsPlugin()
00044 {
00045 this->LoadPaths();
00046 }
00047
00048 ~GazeboRosPathsPlugin()
00049 {
00050 };
00051
00052 void Init()
00053 {
00054 }
00055
00056 void Load(int argc, char** argv)
00057 {
00058 }
00059
00060
00061
00062
00063
00064
00065 void rosPackageCommandDebug(const std::string& cmd, V_string& output)
00066 {
00067 std::string out_string = ros::package::command(cmd);
00068 V_string full_list;
00069 boost::split(full_list, out_string, boost::is_any_of("\r\n"));
00070
00071
00072 V_string::iterator it = full_list.begin();
00073 V_string::iterator end = full_list.end();
00074 for (; it != end; ++it)
00075 {
00076 if (!it->empty())
00077 {
00078 output.push_back(*it);
00079 }
00080 }
00081 }
00082
00083
00084
00085
00086
00087 void rosPackageGetPluginsDebug(const std::string& package, const std::string& attribute, V_string& plugins)
00088 {
00089 M_string plugins_map;
00090 rosPackageGetPluginsDebug(package, attribute, plugins_map);
00091 M_string::iterator it = plugins_map.begin();
00092 M_string::iterator end = plugins_map.end();
00093 for (; it != end; ++it)
00094 {
00095 plugins.push_back(it->second);
00096 }
00097 }
00098
00099
00100
00101
00102
00103 void rosPackageGetPluginsDebug(const std::string& package, const std::string& attribute, M_string& plugins)
00104 {
00105 V_string lines;
00106 rosPackageCommandDebug("plugins --attrib=" + attribute + " " + package, lines);
00107
00108 V_string::iterator it = lines.begin();
00109 V_string::iterator end = lines.end();
00110 for (; it != end; ++it)
00111 {
00112 V_string tokens;
00113 boost::split(tokens, *it, boost::is_any_of(" "));
00114
00115 if (tokens.size() >= 2)
00116 {
00117 std::string package = tokens[0];
00118 std::string rest = boost::join(V_string(tokens.begin() + 1, tokens.end()), " ");
00119 plugins[package] = rest;
00120 }
00121 }
00122 }
00123 void LoadPaths()
00124 {
00125
00126
00127
00128
00129
00130
00131
00132
00133 gazebo::common::SystemPaths::Instance()->ClearOgrePaths();
00134 gazebo::common::SystemPaths::Instance()->ogrePathsFromEnv = false;
00135 std::string ogre_package_name("ogre");
00136 std::string ogre_package_path = ros::package::getPath(ogre_package_name)+std::string("/ogre/lib/OGRE");
00137 if (ogre_package_path.empty())
00138 ROS_DEBUG("Package[%s] does not exist, assuming user must have set OGRE_RESOURCE_PATH already.",ogre_package_name.c_str());
00139 else
00140 {
00141 ROS_DEBUG("ogre path %s",ogre_package_path.c_str());
00142 gazebo::common::SystemPaths::Instance()->AddOgrePaths(ogre_package_path);
00143 }
00144
00145
00146 gazebo::common::SystemPaths::Instance()->ClearGazeboPaths();
00147 gazebo::common::SystemPaths::Instance()->gazeboPathsFromEnv = false;
00148 std::vector<std::string> gazebo_media_paths;
00149 rosPackageGetPluginsDebug("gazebo","gazebo_media_path",gazebo_media_paths);
00150 for (std::vector<std::string>::iterator iter=gazebo_media_paths.begin(); iter != gazebo_media_paths.end(); iter++)
00151 {
00152 ROS_DEBUG("med path %s",iter->c_str());
00153 gazebo::common::SystemPaths::Instance()->AddGazeboPaths(iter->c_str());
00154 }
00155
00156
00157 gazebo::common::SystemPaths::Instance()->ClearPluginPaths();
00158 gazebo::common::SystemPaths::Instance()->pluginPathsFromEnv = false;
00159 std::vector<std::string> plugin_paths;
00160 rosPackageGetPluginsDebug("gazebo","plugin_path",plugin_paths);
00161 for (std::vector<std::string>::iterator iter=plugin_paths.begin(); iter != plugin_paths.end(); iter++)
00162 {
00163 ROS_DEBUG("plugin path %s",(*iter).c_str());
00164 gazebo::common::SystemPaths::Instance()->AddPluginPaths(iter->c_str());
00165 }
00166
00167
00168 std::string gazeborc = ros::package::getPath("gazebo")+"/.do_not_use_gazeborc";
00169 setenv("GAZEBORC",gazeborc.c_str(),1);
00170
00171 }
00172 private:
00173
00174 };
00175
00176
00177 GZ_REGISTER_SYSTEM_PLUGIN(GazeboRosPathsPlugin)
00178
00179 }
00180