ros1_parsers/tf_msg.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <tf/tfMessage.h>
4 #include <tf2_msgs/TFMessage.h>
5 #include "fmt/format.h"
6 #include "ros1_parser.h"
7 #include "header_msg.h"
8 
9 template <typename TfMsgType>
10 class TfMsgParserImpl : public BuiltinMessageParser<TfMsgType>
11 {
12 
13 public:
15  using MessageParser::getSeries;
16  using MessageParser::getStringSeries;
17 
18  TfMsgParserImpl(const std::string& topic_name, PJ::PlotDataMapRef& plot_data)
19  : BaseParser(topic_name, plot_data)
20  {
21  }
22 
23  void parseMessageImpl(const TfMsgType& msg, double& timestamp) override
24  {
25  for (const auto& trans : msg.transforms)
26  {
27  double header_stamp = trans.header.stamp.toSec();
28  timestamp = (BaseParser::getConfig().use_header_stamp && header_stamp > 0) ? header_stamp : timestamp;
29 
30  std::string prefix;
31  if (trans.header.frame_id.empty())
32  {
33  prefix = fmt::format("{}/{}", BaseParser::_topic_name, trans.child_frame_id);
34  }
35  else
36  {
37  prefix = fmt::format("{}/{}/{}",
39  trans.header.frame_id,
40  trans.child_frame_id);
41  }
42 
43  PlotData* series;
44 
45  series = &getSeries(prefix + "/header/stamp");
46  series->pushBack({ timestamp, header_stamp });
47 
48  series = &getSeries(prefix + "/header/seq");
49  series->pushBack({ timestamp, double(trans.header.seq) });
50 
51  series = &getSeries(prefix + "/translation/x");
52  series->pushBack({ timestamp, trans.transform.translation.x });
53 
54  series = &getSeries(prefix + "/translation/y");
55  series->pushBack({ timestamp, trans.transform.translation.y });
56 
57  series = &getSeries(prefix + "/translation/z");
58  series->pushBack({ timestamp, trans.transform.translation.z });
59 
60  series = &getSeries(prefix + "/rotation/x");
61  series->pushBack({ timestamp, trans.transform.rotation.x });
62 
63  series = &getSeries(prefix + "/rotation/y");
64  series->pushBack({ timestamp, trans.transform.rotation.y });
65 
66  series = &getSeries(prefix + "/rotation/z");
67  series->pushBack({ timestamp, trans.transform.rotation.z });
68 
69  series = &getSeries(prefix + "/rotation/w");
70  series->pushBack({ timestamp, trans.transform.rotation.w });
71  }
72  }
73 };
74 
void parseMessageImpl(const TfMsgType &msg, double &timestamp) override
PJ::PlotData & getSeries(const std::string &key)
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
Definition: core.h:2081
void pushBack(const Point &p) override
TfMsgParserImpl(const std::string &topic_name, PJ::PlotDataMapRef &plot_data)
std::string _topic_name
const RosParserConfig & getConfig() const


plotjuggler_ros
Author(s): Davide Faconti
autogenerated on Fri Jun 23 2023 02:28:04