ros1_parser.cpp
Go to the documentation of this file.
1 #include "ros1_parser.h"
2 #include "jointstates_msg.h"
3 #include "imu_msg.h"
4 #include "diagnostic_msg.h"
5 #include "odometry_msg.h"
6 #include "pal_statistics_msg.h"
7 #include "tf_msg.h"
9 #include "plotjuggler_msgs.h"
10 
11 
12 bool IntrospectionParser::parseMessage(MessageRef serialized_msg, double& timestamp)
13 {
14  RosIntrospection::Span<uint8_t> span( serialized_msg.data(), serialized_msg.size() );
16 
18  {
19  for (const auto& it : _flat_msg.value)
20  {
21  if (it.second.getTypeID() != RosIntrospection::TIME)
22  {
23  continue;
24  }
25  const RosIntrospection::StringTreeNode* leaf1 = it.first.node_ptr;
26  const RosIntrospection::StringTreeNode* leaf2 = leaf1->parent();
27  if (leaf2 && leaf2->value() == "header" && leaf1->value() == "stamp")
28  {
29  double header_stamp = it.second.convert<double>();
30 
31  if (header_stamp > 0)
32  {
33  timestamp = header_stamp;
34  }
35  break;
36  }
37  }
38  }
39 
41 
42  for (const auto& it : _renamed)
43  {
44  const auto& key = it.first;
45  double value = 0;
46 
47  if( it.second.getTypeID() == RosIntrospection::BuiltinType::UINT64 )
48  {
49  uint64_t raw_value = it.second.extract<uint64_t>();
50  // if( raw_value >= (1l<<53) ){
51  // TODO: warn the user?
52  // }
53  value = static_cast<double>(raw_value);
54  }
55  else if( it.second.getTypeID() == RosIntrospection::BuiltinType::INT64 )
56  {
57  int64_t raw_value = it.second.extract<int64_t>();
58  // if( raw_value >= (1l<<53) ){
59  // TODO: warn the user?
60  // }
61  value = static_cast<double>(raw_value);
62  }
63  else if( it.second.getTypeID() == RosIntrospection::BuiltinType::STRING )
64  {
65  // special case for strings
66  auto str = it.second.extract<std::string>();
67  bool parsed = PJ::ParseDouble(str, value,
70 
71  if( !parsed && _plot_data.numeric.count(key) == 0 )
72  {
73  auto& series = _plot_data.getOrCreateStringSeries( key );
74  series.pushBack({ timestamp, str});
75  }
76  continue;
77  }
78  else{
79  value = it.second.convert<double>();
80  }
81 
82  auto& series = getSeries(key);
83 
84  if (!std::isnan(static_cast<double>(value)) && !std::isinf(value))
85  {
86  series.pushBack({ timestamp, value });
87  }
88  }
89  return true;
90 }
91 
92 //-----------------------------------------
93 
94 void RosCompositeParser::registerMessageType(const std::string& topic_name,
95  const std::string& topic_type,
96  const std::string& definition)
97 {
98  std::shared_ptr<RosMessageParser> parser;
99  if (_parsers.count(topic_name) > 0)
100  {
101  return;
102  }
103 
104  const std::string& type = topic_type;
105 
106  if (type == "sensor_msgs/JointState")
107  {
108  parser.reset(new JointStateMsgParser(topic_name, _plot_data));
109  }
110  else if (type == "diagnostic_msgs/DiagnosticArray")
111  {
112  parser.reset(new DiagnosticMsgParser(topic_name, _plot_data));
113  }
114  else if (type == "tf/tfMessage")
115  {
116  parser.reset(new TfMsgParser(topic_name, _plot_data));
117  }
118  else if (type == "tf2_msgs/TFMessage")
119  {
120  parser.reset(new Tf2MsgParser(topic_name, _plot_data));
121  }
122  else if (type == "geometry_msgs/Quaternion")
123  {
124  parser.reset(new QuaternionMsgParser(topic_name, _plot_data));
125  }
126  else if (type == "sensor_msgs/Imu")
127  {
128  parser.reset(new ImuMsgParser(topic_name, _plot_data));
129  }
130  else if (type == "nav_msgs/Odometry")
131  {
132  parser.reset(new OdometryMsgParser(topic_name, _plot_data));
133  }
134  else if (type == "geometry_msgs/Pose")
135  {
136  parser.reset(new PoseMsgParser(topic_name, _plot_data));
137  }
138  else if (type == "geometry_msgs/PoseStamped")
139  {
140  parser.reset(new PoseStampedMsgParser(topic_name, _plot_data));
141  }
142  else if (type == "geometry_msgs/PoseWithCovariance")
143  {
144  parser.reset(new PoseCovarianceMsgParser(topic_name, _plot_data));
145  }
146  else if (type == "geometry_msgs/PoseWithCovarianceStamped")
147  {
148  parser.reset(new PoseCovarianceStampedMsgParser(topic_name, _plot_data));
149  }
150  else if (type == "geometry_msgs/Twist")
151  {
152  parser.reset(new TwistMsgParser(topic_name, _plot_data));
153  }
154  else if (type == "geometry_msgs/TwistStamped")
155  {
156  parser.reset(new TwistStampedMsgParser(topic_name, _plot_data));
157  }
158  else if (type == "geometry_msgs/TwistWithCovariance")
159  {
160  parser.reset(new TwistCovarianceMsgParser(topic_name, _plot_data));
161  }
162  else if (type == "pal_statistics_msgs/StatisticsNames")
163  {
164  parser.reset(new PalStatisticsNamesParser(topic_name, _plot_data));
165  }
166  else if (type == "pal_statistics_msgs/StatisticsValues")
167  {
168  parser.reset(new PalStatisticsValuesParser(topic_name, _plot_data));
169  }
170  else if (type == "plotjuggler_msgs/Dictionary")
171  {
172  parser.reset(new PlotJugglerDictionaryParser(topic_name, _plot_data));
173  }
174  else if (type == "plotjuggler_msgs/DataPoints")
175  {
176  parser.reset(new PlotJugglerDataPointsParser(topic_name, _plot_data));
177  }
178  else if (type == "fiveai_node_msgs/NodeDiagnostics")
179  {
180  parser.reset(new FiveAiDiagnosticMsg(topic_name, _plot_data));
181  }
182  else
183  {
184  parser.reset(new IntrospectionParser(topic_name, type, definition, _plot_data));
185  }
186 
187  parser->setConfig(_config);
188  _parsers.insert({ topic_name, parser });
189 }
190 
191 
192 
RosIntrospection::Parser _parser
Definition: ros1_parser.h:51
RosIntrospection::RenamedValues _renamed
Definition: ros1_parser.h:53
size_t size() const
type
PlotDataMapRef & _plot_data
Element of the tree. it has a single parent and N >= 0 children.
PJ::PlotData & getSeries(const std::string &key)
virtual bool parseMessage(MessageRef serialized_msg, double &timestamp) override
Definition: ros1_parser.cpp:12
void registerMessageType(const std::string &topic_name, const std::string &topic_type, const std::string &definition)
Definition: ros1_parser.cpp:94
TimeseriesMap numeric
IntrospectionParser(const std::string &topic_name, const std::string &topic_type, const std::string &definition, PJ::PlotDataMapRef &plot_data)
Definition: ros1_parser.h:38
StringSeries & getOrCreateStringSeries(const std::string &name, PlotGroup::Ptr group={})
TfMsgParserImpl< tf::tfMessage > TfMsgParser
std::vector< std::pair< StringTreeLeaf, Variant > > value
void applyNameTransform(const std::string &msg_identifier, const FlatMessage &container, RenamedValues *renamed_value, bool dont_add_topicname=false)
applyNameTransform is used to create a vector of type RenamedValues from the vector FlatMessage::valu...
iterator it
bool ParseDouble(const std::string &str, double &value, bool remover_suffix, bool parse_boolean)
RosIntrospection::FlatMessage _flat_msg
Definition: ros1_parser.h:52
void pushBack(const Point &p) override
std::string _topic_name
parser
TfMsgParserImpl< tf2_msgs::TFMessage > Tf2MsgParser
const uint8_t * data() const
bool deserializeIntoFlatContainer(const std::string &msg_identifier, Span< uint8_t > buffer, FlatMessage *flat_container_output, const uint32_t max_array_size) const
deserializeIntoFlatContainer takes a raw buffer of memory and extract information from it...


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