35 #include <boost/filesystem.hpp> 38 #include <nav_msgs/MapMetaData.h> 39 #include <nav_msgs/GetMap.h> 42 #include <yaml-cpp/yaml.h> 52 std::string image_filename;
55 std::string frame_id =
"map";
56 double resolution = 0.05;
59 double free_th = 0.196;
60 std::string mode =
"trinary";
61 double origin_x = 0.0;
62 double origin_y = 0.0;
63 std::string occupancy_grid_topic =
"map";
64 std::string nav_grid_topic =
"static_map";
66 private_nh.
param(
"frame_id", frame_id, frame_id);
68 if (filename.find(
"yaml") != std::string::npos)
70 YAML::Node config = YAML::LoadFile(filename.c_str());
71 image_filename = config[
"image"].as<std::string>();
72 if (image_filename[0] !=
'/')
74 boost::filesystem::path yaml_path(filename);
75 boost::filesystem::path image_path = yaml_path.parent_path() / image_filename;
76 image_filename = image_path.string();
79 if (config[
"resolution"]) resolution = config[
"resolution"].as<
double>();
81 if (config[
"negate"]) negate = config[
"negate"].as<bool,
int>(0);
82 if (config[
"occupied_thresh"]) occ_th = config[
"occupied_thresh"].as<
double>();
83 if (config[
"free_thresh"]) free_th = config[
"free_thresh"].as<
double>();
84 if (config[
"mode"]) mode = config[
"mode"].as<std::string>();
87 origin_x = config[
"origin"][0].as<
double>();
88 origin_y = config[
"origin"][1].as<
double>();
93 image_filename = filename;
97 private_nh.
param(
"resolution", resolution, resolution);
98 private_nh.
param(
"negate", negate, negate);
99 private_nh.
param(
"occupied_thresh", occ_th, occ_th);
100 private_nh.
param(
"free_thresh", free_th, free_th);
101 private_nh.
param(
"mode", mode, mode);
102 private_nh.
param(
"origin_x", origin_x, origin_x);
103 private_nh.
param(
"origin_y", origin_y, origin_y);
104 private_nh.
param(
"occupancy_grid_topic", occupancy_grid_topic, occupancy_grid_topic);
105 private_nh.
param(
"nav_grid_topic", nav_grid_topic, nav_grid_topic);
120 pub_.
init(global_nh, nav_grid_topic, occupancy_grid_topic,
"",
false);
141 bool mapCallback(nav_msgs::GetMap::Request &req, nav_msgs::GetMap::Response &res)
151 int main(
int argc,
char **argv)
167 catch(std::runtime_error& e)
nav_grid::VectorNavGrid< unsigned char > classicLoadMapFromFile(const std::string &filepath, const double resolution, const bool negate_param, const double occ_th, const double free_th, const std::string &mode)
Load an image from a file, mimicking map_server's loading style Resulting values are [0...
#define ROS_INFO_NAMED(name,...)
void setCostInterpretation(const std::vector< unsigned char > &cost_interpretation_table)
void publish(const boost::shared_ptr< M > &message) const
MapServer(const std::string &filename)
int main(int argc, char **argv)
nav_msgs::OccupancyGrid grid_version_
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
nav_grid::VectorNavGrid< unsigned char > the_map_
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
void init(ros::NodeHandle &nh, const std::string &nav_grid_topic="grid", const std::string &occupancy_grid_topic="costmap", const std::string &update_area_topic="update_area", bool publish_updates=true, ros::Duration full_publish_cycle=ros::Duration(0), ros::Duration update_publish_cycle=ros::Duration(0))
ROSCPP_DECL void spin(Spinner &spinner)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
void setInfo(const NavGridInfo &new_info) override
unsigned int getHeight() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
double getResolution() const
unsigned int getWidth() const
NavGridInfo getInfo() const
nav_grid_pub_sub::NavGridPublisher pub_
static std::vector< unsigned char > RAW(0)
#define ROS_ERROR_NAMED(name,...)
bool mapCallback(nav_msgs::GetMap::Request &req, nav_msgs::GetMap::Response &res)
ros::Publisher metadata_pub_
static bool waitForValid()
ros::ServiceServer service_
nav_msgs::OccupancyGrid toOccupancyGrid(const nav_grid::NavGrid< unsigned char > &grid, const ros::Time &stamp=ros::Time(0), const std::vector< unsigned char > cost_interpretation_table=std::vector< unsigned char >())