rviz_grid_viewer.h
Go to the documentation of this file.
1 #ifndef __RVIZ_GRID_VIEWER_H
2 #define __RVIZ_GRID_VIEWER_H
3 
4 #include <string>
5 #include <vector>
6 #include <ros/ros.h>
8 #include <nav_msgs/OccupancyGrid.h>
9 
10 #include "../core/state_data.h"
11 #include "../core/maps/grid_map.h"
12 
18 public: // method
19 
24  RvizGridViewer(ros::Publisher pub, const double show_map_rate,
25  std::string frame_odom, std::string frame_robot_pose) :
26  _map_pub(pub), map_publishing_rate(show_map_rate),
27  _frame_odom(frame_odom), _frame_robot_pose(frame_robot_pose) {}
28 
33  void show_robot_pose(const RobotState &r) {
34  tf::Transform t;
35  t.setOrigin(tf::Vector3(r.x, r.y, 0.0));
37  q.setRPY(0, 0, r.theta);
38  t.setRotation(q);
42  }
43 
48  void show_map(const GridMap &map) {
49  // TODO: move map publishing rate to parameter
51  return;
52  }
53 
54  nav_msgs::OccupancyGrid map_msg;
55  map_msg.info.map_load_time = ros::Time::now();
56  map_msg.info.width = map.width();
57  map_msg.info.height = map.height();
58  map_msg.info.resolution = map.scale();
59  // move map to the middle
60  nav_msgs::MapMetaData &info = map_msg.info;
61  info.origin.position.x = -info.resolution * map.map_center_x();
62  info.origin.position.y = -info.resolution * map.map_center_y();
63  info.origin.position.z = 0;
64 
65  for (const auto &row : map.cells()) {
66  for (const auto &cell : row) {
67  int cell_value = cell->value() == -1 ? -1 : cell->value() * 100;
68  map_msg.data.push_back(cell_value);
69  }
70  }
71 
72  _map_pub.publish(map_msg);
74  }
75 
76 private: // fields
80  const double map_publishing_rate;
81  std::string _frame_odom;
82  std::string _frame_robot_pose;
83 };
84 
85 #endif
The class publishes information about robot&#39;s map and location in ROS-compatible format so it can be ...
double x
Definition: state_data.h:38
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
void publish(const boost::shared_ptr< M > &message) const
tf::TransformBroadcaster _tf_brcst
int width() const
Returns the width of the map.
Definition: grid_map.h:54
ros::Publisher _map_pub
void show_robot_pose(const RobotState &r)
int height() const
Returns thr height of the map.
Definition: grid_map.h:57
const double map_publishing_rate
An occupancy grid implementation.
Definition: grid_map.h:22
double theta
The position of robot.
Definition: state_data.h:38
std::string _frame_odom
double y
Definition: state_data.h:38
void setRPY(const tfScalar &roll, const tfScalar &pitch, const tfScalar &yaw)
Defines a robot position in cartesian coordinates and an angle of rotation.
Definition: state_data.h:14
double scale() const
Returns the scale.
Definition: grid_map.h:60
void show_map(const GridMap &map)
void sendTransform(const StampedTransform &transform)
std::string _frame_robot_pose
RvizGridViewer(ros::Publisher pub, const double show_map_rate, std::string frame_odom, std::string frame_robot_pose)
ros::Time _last_pub_time
static Time now()
int map_center_y() const
Definition: grid_map.h:133
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
int map_center_x() const
Definition: grid_map.h:129
const std::vector< std::vector< Cell > > cells() const
Returns map&#39;s cells.
Definition: grid_map.h:63


tiny_slam
Author(s):
autogenerated on Mon Jun 10 2019 15:30:57