utilities.cpp
Go to the documentation of this file.
1 
4 /*****************************************************************************
5 ** Includes
6 *****************************************************************************/
7 
8 #include <iostream>
9 #include <ros/package.h>
10 #include <string>
11 #include "../../include/cost_map_ros/utilities.hpp"
12 
13 /*****************************************************************************
14 ** Namespaces
15 *****************************************************************************/
16 
17 namespace cost_map {
18 
19 /*****************************************************************************
20 ** Implementation
21 *****************************************************************************/
22 
23 std::string resolveResourceName(const std::string& resource_name) {
24 
25  /********************
26  ** Resource Name
27  ********************/
28  std::string delimiter = "/";
29  int index = resource_name.find(delimiter);
30  if ( index == std::string::npos ) {
31  throw std::invalid_argument(std::string("'") + resource_name + std::string("' is not a valid resource name."));
32  }
33  std::string package = resource_name.substr(0, index);
34  std::string name = resource_name.substr(index + delimiter.length());
35 
36  /********************
37  ** Lookup
38  ********************/
39  std::string plugin_package = "cost_map_ros"; // nav_core, cost_map
40  std::string attribute = "image_resource"; // plugin, yaml
41 
42  // pending release of https://github.com/ros/ros/pull/103
43  // std::vector<std::string> packages, costmaps;
44  // ros::package::getPlugins(plugin_package, attribute, packages, costmaps);
45  // for (unsigned int i = 0; i < packages.size(); ++i ) {
46  // std::cout << packages[i] << " " << costmaps[i] << std::endl;
47  // }
48 
49  // grunt workaround for now - its not 100% robust
50  std::vector<std::string> costmaps;
51  ros::package::getPlugins(plugin_package, attribute, costmaps);
52  for (const auto& filename : costmaps) {
53  if ( (filename.find(package) != std::string::npos) && (filename.find(name) != std::string::npos) ) {
54  return filename;
55  }
56  }
57  // not found
58  throw std::runtime_error(std::string("resource name '") + resource_name + std::string("' is not available (try 'rospack plugins --attrib=image_resource cost_map_ros')."));
59 }
60 
61 /*****************************************************************************
62  ** Trailers
63  *****************************************************************************/
64 
65 } // namespace cost_map
filename
string package
ROSLIB_DECL void getPlugins(const std::string &package, const std::string &attribute, V_string &plugins, bool force_recrawl=false)
std::string resolveResourceName(const std::string &resource_name)
Use rospack to resolve a costmap given a ros package resource name.
Definition: utilities.cpp:23


cost_map_ros
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:03:48