occupancy_grid.cpp
Go to the documentation of this file.
00001 
00004 /*****************************************************************************
00005 ** Includes
00006 *****************************************************************************/
00007 
00008 #include <cost_map_core/cost_map.hpp>
00009 #include <cost_map_ros/converter.hpp>
00010 #include <nav_msgs/OccupancyGrid.h>
00011 #include "../../include/cost_map_visualisations/occupancy_grid.hpp"
00012 
00013 /*****************************************************************************
00014 ** Namespaces
00015 *****************************************************************************/
00016 
00017 namespace cost_map {
00018 
00019 /*****************************************************************************
00020 ** Implementation
00021 *****************************************************************************/
00022 
00023 OccupancyGrid::OccupancyGrid()
00024 {
00025   ros::NodeHandle nodehandle("~");
00026 
00027   subscriber_ = nodehandle.subscribe("cost_map", 10, &OccupancyGrid::_costMapCallback, this);
00028 }
00029 
00030 void OccupancyGrid::_costMapCallback(const cost_map_msgs::CostMap::ConstPtr& msg) {
00031   for (const auto& layer : msg->layers) {
00032     if ( publishers_.count(layer) == 0 ) {
00033       ros::NodeHandle nodehandle("~");
00034       auto result = publishers_.insert(std::pair<std::string, ros::Publisher>(layer, ros::Publisher(nodehandle.advertise<nav_msgs::OccupancyGrid>(layer, 1, true))));
00035     }
00036     // TODO check if layers disappeared and remove the publishers
00037     ros::Publisher& publisher = publishers_[layer];
00038     if (publisher.getNumSubscribers() >= 0) {
00039       cost_map::CostMap cost_map;
00040       cost_map::fromMessage(*msg, cost_map);
00041       nav_msgs::OccupancyGrid occupancy_grid_msg;
00042       cost_map::toOccupancyGrid(cost_map, layer, occupancy_grid_msg);
00043       publisher.publish(occupancy_grid_msg);
00044     }
00045   }
00046 }
00047 
00048 /*****************************************************************************
00049  ** Trailers
00050  *****************************************************************************/
00051 
00052 } // namespace cost_map


cost_map_visualisations
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 20:27:59