occupancy_grid_publisher.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_ROS_OCCUPANCY_GRID_PUBLISHER_H
2 #define SLAM_CTOR_ROS_OCCUPANCY_GRID_PUBLISHER_H
3 
4 #include <ros/ros.h>
5 #include <nav_msgs/OccupancyGrid.h>
6 
7 #include "../core/states/state_data.h"
8 #include "../core/maps/grid_map.h"
9 
10 template <typename GridMapType>
11 class OccupancyGridPublisher : public WorldMapObserver<GridMapType> {
12 public: // method
14  const std::string &tf_map_frame_id,
15  double publ_interval_secs = 5.0):
17  _publishing_interval{publ_interval_secs} {}
18 
19  void on_map_update(const GridMapType &map) override {
21  return;
22  }
23 
24  nav_msgs::OccupancyGrid map_msg;
25  map_msg.header.frame_id = _tf_map_frame_id;
26  map_msg.info.map_load_time = ros::Time::now();
27  map_msg.info.width = map.width();
28  map_msg.info.height = map.height();
29  map_msg.info.resolution = map.scale();
30  // move map to the middle
31  nav_msgs::MapMetaData &info = map_msg.info;
32  DiscretePoint2D origin = map.origin();
33  info.origin.position.x = -info.resolution * origin.x;
34  info.origin.position.y = -info.resolution * origin.y;
35  info.origin.position.z = 0;
36  map_msg.data.reserve(info.height * info.width);
37  DiscretePoint2D pnt;
38  DiscretePoint2D end_of_map = DiscretePoint2D(info.width,
39  info.height) - origin;
40  for (pnt.y = -origin.y; pnt.y < end_of_map.y; ++pnt.y) {
41  for (pnt.x = -origin.x; pnt.x < end_of_map.x; ++pnt.x) {
42  double value = (double)map[pnt];
43  int cell_value = value == -1 ? -1 : value * 100;
44  map_msg.data.push_back(cell_value);
45  }
46  }
47 
48  _map_pub.publish(map_msg);
50  }
51 
52 private: // fields
54  std::string _tf_map_frame_id;
57 };
58 
59 #endif
void publish(const boost::shared_ptr< M > &message) const
static Time now()
void on_map_update(const GridMapType &map) override
std::string tf_map_frame_id()
Definition: init_utils.h:33
OccupancyGridPublisher(ros::Publisher pub, const std::string &tf_map_frame_id, double publ_interval_secs=5.0)


slam_constructor
Author(s): JetBrains Research, OSLL team
autogenerated on Mon Jun 10 2019 15:08:25