pj_statistics_msg.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_map>
4 
5 #include "plotjuggler_msgs/msg/statistics_names.hpp"
6 #include "plotjuggler_msgs/msg/statistics_values.hpp"
7 
8 #include "ros2_parser.h"
9 #include "fmt/format.h"
10 #include "header_msg.h"
11 
12 
13 static std::unordered_map<uint32_t, std::vector<std::string>> _stored_pj_statistics_names;
14 
15 class PJ_StatisticsNamesParser : public BuiltinMessageParser<plotjuggler_msgs::msg::StatisticsNames>
16 {
17 public:
18  PJ_StatisticsNamesParser(const std::string& topic_name, PJ::PlotDataMapRef& plot_data)
19  : BuiltinMessageParser<plotjuggler_msgs::msg::StatisticsNames>(topic_name, plot_data)
20  {
21  }
22 
23  void parseMessageImpl(const plotjuggler_msgs::msg::StatisticsNames& msg, double& timestamp) override
24  {
25  _stored_pj_statistics_names.insert({ msg.names_version, msg.names });
26  }
27 };
28 
29 //-----------------------------------------------------
30 class PJ_StatisticsValuesParser : public BuiltinMessageParser<plotjuggler_msgs::msg::StatisticsValues>
31 {
32 public:
33  PJ_StatisticsValuesParser(const std::string& topic_name, PJ::PlotDataMapRef& plot_data)
34  : BuiltinMessageParser<plotjuggler_msgs::msg::StatisticsValues>(topic_name, plot_data)
35  , _header_parser(topic_name + "/header", plot_data)
36  {
37  }
38 
39  void parseMessageImpl(const plotjuggler_msgs::msg::StatisticsValues& msg, double& timestamp) override
40  {
41  auto& values = _data[msg.names_version];
42 
43  _header_parser.parse(msg.header, timestamp, _config.use_header_stamp);
44 
45  auto names_it = _stored_pj_statistics_names.find(msg.names_version);
46  if (names_it == _stored_pj_statistics_names.end())
47  {
48  return; // missing vocabulary
49  }
50  const auto& names = names_it->second;
51 
52  if (msg.values.size() != names.size())
53  {
54  return; // weird... skip
55  }
56 
57  for (size_t index = 0; index < msg.values.size(); index++)
58  {
59  const auto& name = names[index];
60  if (index >= values.size())
61  {
62  values.emplace_back(&getSeries(fmt::format("{}/{}",_topic_name, name)));
63  }
64  values[index]->pushBack({ timestamp, msg.values[index] });
65  }
66  }
67 
68 private:
69  std::unordered_map<uint32_t, std::vector<PJ::PlotData*>> _data;
71 };
72 
std::vector< double > values
PJ::PlotData & getSeries(const std::string &key)
void parseMessageImpl(const plotjuggler_msgs::msg::StatisticsValues &msg, double &timestamp) override
PJ_StatisticsValuesParser(const std::string &topic_name, PJ::PlotDataMapRef &plot_data)
PJ_StatisticsNamesParser(const std::string &topic_name, PJ::PlotDataMapRef &plot_data)
HeaderMsgParser _header_parser
std::size_t index
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&... args)
Definition: core.h:2081
static std::unordered_map< uint32_t, std::vector< std::string > > _stored_pj_statistics_names
void parseMessageImpl(const plotjuggler_msgs::msg::StatisticsNames &msg, double &timestamp) override
std::unordered_map< uint32_t, std::vector< PJ::PlotData * > > _data
std::string _topic_name
msg


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