robot_pose_observers.h
Go to the documentation of this file.
1 #ifndef SLAM_CTOR_ROS_ROBOT_POSE_OBSERVERS_H
2 #define SLAM_CTOR_ROS_ROBOT_POSE_OBSERVERS_H
3 
4 #include <fstream>
5 #include <ros/ros.h>
7 
8 #include "topic_with_transform.h"
9 #include "../core/states/world.h"
10 
12 public: //methods
14  const std::string &tf_robot_frame_id) :
15  _tf_map_frame_id{tf_map_frame_id},
16  _tf_robot_frame_id{tf_robot_frame_id} {}
17 
18  void on_pose_update(const RobotPose &pose) override {
19  auto map2robot = tf::Transform{
21  tf::Vector3(pose.x, pose.y, 0.0)};
22 
23  auto transform = tf::StampedTransform{map2robot, robot_pose_timestamp(),
25  _tf_brcst.sendTransform(transform);
26  }
27 
28 private:
29 
31  return ros::Time::now();
32  }
33 
34 
35 private: // fields
38 };
39 
40 template <typename ObsType>
42  , public TopicObserver<ObsType> {
43 public:
45  const std::string &tf_robot_frame_id)
46  : RobotPoseTfPublisher{tf_map_frame_id, tf_robot_frame_id} {}
47 
50  const tf::StampedTransform&) override {
51 
52  _observation_time = ros::message_traits::TimeStamp<ObsType>::value(*obs);
53  }
54 
55 private:
56 
58  return _observation_time;
59  }
60 
61 private:
63 };
64 
66 public:
67  RobotPoseTumTrajectoryDumper(const std::string &fname,
68  bool flush_every_entry = false)
69  : _fstream{fname, std::ios::out}
70  , _flush_every_entry{flush_every_entry} {}
71 
72  void on_pose_update(const RobotPose &pose) override {
73  log_robot_pose(ros::Time::now(), pose);
74  }
75 
76  void log_robot_pose(const ros::Time &time, const RobotPose &pose) {
77  auto q = tf::createQuaternionFromRPY(0, 0, pose.theta);
78  _fstream << time.sec << '.' << time.nsec
79  << ' ' << pose.x << ' ' << pose.y << ' ' << '0'
80  << ' ' << q.x() << ' ' << q.y() << ' ' << q.z() << ' ' << q.w()
81  << '\n';
82  if (_flush_every_entry) {
83  _fstream.flush();
84  }
85  }
86 
87 private:
88  std::ofstream _fstream;
90 };
91 
92 #endif
void log_robot_pose(const ros::Time &time, const RobotPose &pose)
static tf::Quaternion createQuaternionFromRPY(double roll, double pitch, double yaw)
double theta
Definition: robot_pose.h:131
void on_pose_update(const RobotPose &pose) override
ObservationStampedRoboPoseTfPublisher(const std::string &tf_map_frame_id, const std::string &tf_robot_frame_id)
RobotPoseTfPublisher(const std::string &tf_map_frame_id, const std::string &tf_robot_frame_id)
void handle_transformed_msg(const boost::shared_ptr< ObsType > obs, const tf::StampedTransform &) override
RobotPoseTumTrajectoryDumper(const std::string &fname, bool flush_every_entry=false)
void sendTransform(const StampedTransform &transform)
virtual ros::Time robot_pose_timestamp()
double y
Definition: robot_pose.h:131
static Time now()
tf::TransformBroadcaster _tf_brcst
std::string tf_map_frame_id()
Definition: init_utils.h:33
void on_pose_update(const RobotPose &pose) override
double x
Definition: robot_pose.h:131


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