odometry_msg.h
Go to the documentation of this file.
1 #ifndef ODOMETRY_MSG_H
2 #define ODOMETRY_MSG_H
3 
4 
5 #include <nav_msgs/Odometry.h>
6 #include "ros_parser_base.h"
7 
9 {
10 public:
11 
13  {
14  _data.emplace_back( "/header/seq" ); //0
15  _data.emplace_back( "/header/stamp" ); //1
16 
17  _data.emplace_back( "/pose/position/x" ); //2
18  _data.emplace_back( "/pose/position/y" ); //3
19  _data.emplace_back( "/pose/position/z" ); //4
20 
21  _data.emplace_back( "/pose/orientation/quat_x" ); // 5
22  _data.emplace_back( "/pose/orientation/quat_y" ); // 6
23  _data.emplace_back( "/pose/orientation/quat_z" ); // 7
24  _data.emplace_back( "/pose/orientation/quat_w" ); // 8
25  _data.emplace_back( "/pose/orientation/yaw_degrees" ); // 9
26 
27  _data.emplace_back( "/twist/linear/x" );// 10
28  _data.emplace_back( "/twist/linear/y" );// 11
29  _data.emplace_back( "/twist/linear/z" );// 12
30 
31  _data.emplace_back( "/twist/angular/x" );// 13
32  _data.emplace_back( "/twist/angular/y" );// 14
33  _data.emplace_back( "/twist/angular/z" );// 15
34  }
35 
36  static const std::string& getCompatibleKey()
37  {
39  return str;
40  }
41 
42  const std::unordered_set<std::string>& getCompatibleKeys() const override
43  {
44  static std::unordered_set<std::string> temp = { getCompatibleKey() };
45  return temp;
46  }
47 
48  virtual void pushMessageRef(const std::string& ,
49  const MessageRef& msg,
50  double timestamp) override
51  {
52  nav_msgs::Odometry odom;
53  ros::serialization::IStream is( const_cast<uint8_t*>(msg.data()), msg.size() );
55 
56  if( _use_header_stamp )
57  {
58  timestamp = odom.header.stamp.toSec();
59  }
60 
61 
62  _data[0].pushBack( {timestamp, static_cast<double>(odom.header.seq)} );
63  _data[1].pushBack( {timestamp, odom.header.stamp.toSec()} );
64 
65  _data[2].pushBack( {timestamp, odom.pose.pose.position.x} );
66  _data[3].pushBack( {timestamp, odom.pose.pose.position.y} );
67  _data[4].pushBack( {timestamp, odom.pose.pose.position.z} );
68 
69 
70  const auto& q = odom.pose.pose.orientation;
71  _data[5].pushBack( {timestamp, q.x} );
72  _data[6].pushBack( {timestamp, q.y} );
73  _data[7].pushBack( {timestamp, q.z} );
74  _data[8].pushBack( {timestamp, q.w} );
75 
76  // yaw (z-axis rotation)
77  double siny_cosp = +2.0 * (q.w * q.z + q.x * q.y);
78  double cosy_cosp = +1.0 - 2.0 * (q.y * q.y + q.z * q.z);
79  double yaw = atan2(siny_cosp, cosy_cosp) * 180 / M_PI;
80 
81  if( _data[9].size() == 0 )
82  {
83  _yaw_warp = 0;
84  }
85  else{
86  double prev_yaw = _data[9].back().y - _yaw_warp;
87  if( prev_yaw - yaw > 355 )
88  _yaw_warp += 360;
89  else if( yaw - prev_yaw > 355)
90  _yaw_warp -= 360;
91  }
92 
93  _data[9].pushBack( {timestamp, yaw + _yaw_warp} );
94 
95  _data[10].pushBack( {timestamp, odom.twist.twist.linear.x} );
96  _data[11].pushBack( {timestamp, odom.twist.twist.linear.y} );
97  _data[12].pushBack( {timestamp, odom.twist.twist.linear.z} );
98 
99  _data[13].pushBack( {timestamp, odom.twist.twist.angular.x} );
100  _data[14].pushBack( {timestamp, odom.twist.twist.angular.y} );
101  _data[15].pushBack( {timestamp, odom.twist.twist.angular.z} );
102 
103  }
104 
105  void extractData(PlotDataMapRef& plot_map, const std::string& prefix) override
106  {
107  for (auto& it: _data)
108  {
109  appendData(plot_map, prefix + it.name(), it);
110  }
111  }
112 
113 private:
114  std::vector<PlotData> _data;
115  double _yaw_warp;
116 };
117 
118 #endif // ODOMETRY_MSG_H
std::vector< PlotData > _data
Definition: odometry_msg.h:114
static const std::string & getCompatibleKey()
Definition: odometry_msg.h:36
size_t size() const
void extractData(PlotDataMapRef &plot_map, const std::string &prefix) override
Definition: odometry_msg.h:105
const std::unordered_set< std::string > & getCompatibleKeys() const override
Definition: odometry_msg.h:42
const uint8_t * data() const
static const char * value()
uintptr_t size
virtual void pushMessageRef(const std::string &, const MessageRef &msg, double timestamp) override
Definition: odometry_msg.h:48
static void appendData(PlotDataMapRef &destination_plot_map, const std::string &field_name, PlotData &in_data)
void deserialize(Stream &stream, T &t)


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17