wg_pr2_bag_adapter.cpp
Go to the documentation of this file.
1 #include <utility>
2 
3 #include <boost/shared_ptr.hpp>
4 
5 #include <ros/ros.h>
6 #include <nav_msgs/OccupancyGrid.h>
7 #include <tf/tfMessage.h>
9 
11 #include "init_utils.h"
12 
13 using OccGridMsg = nav_msgs::OccupancyGrid;
15 
16 geometry_msgs::TransformStamped gt2map_transform;
17 bool gt2map_is_initialized = false;
18 
20  provided_grid = std::move(*msg);
21  provided_grid.header.frame_id = "provided_map";
22 }
23 
25  auto props = LaunchPropertiesProvider{};
26  static tf::TransformBroadcaster br;
27  static std::string map_frame_id = "/" + tf_map_frame_id();
28  static std::string odom_frame_id = "/" + tf_odom_frame_id(props);
29 
30  for (auto &t : msg->transforms) {
31  if (t.header.frame_id != map_frame_id ||
32  t.child_frame_id != odom_frame_id) {
33  br.sendTransform(t);
34  continue;
35  }
36  // handle pose correction provided by bag:
37  // - the correction is ignored, initial map->odom is sent instead
38  if (!gt2map_is_initialized) {
39  gt2map_transform = std::move(t);
40  gt2map_transform.header.frame_id = "/provided_map";
41  gt2map_transform.child_frame_id = "/map";
42  gt2map_is_initialized = true;
43  }
45  }
46 }
47 
48 int main(int argc, char **argv) {
49  ros::init(argc, argv, "WG-PR2-bag-adapter");
50 
51  ros::NodeHandle nh;
52 
53  auto provided_grid_pub = nh.advertise<OccGridMsg>("provided_grid", 10);
54  auto provided_grid_sub = nh.subscribe("provided_grid_orig", 10, on_gt_grid);
55 
56  auto tf_sub = nh.subscribe("tf_in", 10, on_tf_msg);
57 
58  ros::Rate rate{7};
59  while (ros::ok()) {
60  provided_grid_pub.publish(provided_grid);
61  ros::spinOnce();
62  rate.sleep();
63  }
64 }
nav_msgs::OccupancyGrid OccGridMsg
geometry_msgs::TransformStamped gt2map_transform
void on_tf_msg(boost::shared_ptr< tf::tfMessage > msg)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::string tf_odom_frame_id(const PropertiesProvider &props)
Definition: init_utils.h:29
ROSCPP_DECL bool ok()
void sendTransform(const StampedTransform &transform)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
int main(int argc, char **argv)
OccGridMsg provided_grid
bool gt2map_is_initialized
void on_gt_grid(boost::shared_ptr< nav_msgs::OccupancyGrid > msg)
std::string tf_map_frame_id()
Definition: init_utils.h:33
ROSCPP_DECL void spinOnce()


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