utilities.cpp
Go to the documentation of this file.
00001 
00004 /*****************************************************************************
00005 ** Includes
00006 *****************************************************************************/
00007 
00008 #include <iostream>
00009 #include <ros/package.h>
00010 #include <string>
00011 #include "../../include/cost_map_ros/utilities.hpp"
00012 
00013 /*****************************************************************************
00014 ** Namespaces
00015 *****************************************************************************/
00016 
00017 namespace cost_map {
00018 
00019 /*****************************************************************************
00020 ** Implementation
00021 *****************************************************************************/
00022 
00023 std::string resolveResourceName(const std::string& resource_name) {
00024 
00025   /********************
00026   ** Resource Name
00027   ********************/
00028   std::string delimiter = "/";
00029   int index = resource_name.find(delimiter);
00030   if ( index == std::string::npos ) {
00031     throw std::invalid_argument(std::string("'") + resource_name + std::string("' is not a valid resource name."));
00032   }
00033   std::string package = resource_name.substr(0, index);
00034   std::string name = resource_name.substr(index + delimiter.length());
00035 
00036   /********************
00037   ** Lookup
00038   ********************/
00039   std::string plugin_package = "cost_map_ros";  // nav_core, cost_map
00040   std::string attribute = "image_resource"; // plugin, yaml
00041 
00042   // pending release of https://github.com/ros/ros/pull/103
00043   // std::vector<std::string> packages, costmaps;
00044   // ros::package::getPlugins(plugin_package, attribute, packages, costmaps);
00045   // for (unsigned int i = 0; i < packages.size(); ++i ) {
00046   //   std::cout << packages[i] << " " << costmaps[i] << std::endl;
00047   // }
00048 
00049   // grunt workaround for now - its not 100% robust
00050   std::vector<std::string> costmaps;
00051   ros::package::getPlugins(plugin_package, attribute, costmaps);
00052   for (const auto& filename : costmaps) {
00053     if ( (filename.find(package) != std::string::npos) && (filename.find(name) != std::string::npos) ) {
00054       return filename;
00055     }
00056   }
00057   // not found
00058   throw std::runtime_error(std::string("resource name '") + resource_name + std::string("' is not available (try 'rospack plugins --attrib=image_resource cost_map_ros')."));
00059 }
00060 
00061 /*****************************************************************************
00062  ** Trailers
00063  *****************************************************************************/
00064 
00065 } // namespace cost_map


cost_map_ros
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 20:27:54