kvh_geo_fog_3d_status_panel.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (Apache 2.0)
3  *
4  * Copyright (c) 2019, The MITRE Corporation.
5  * All rights reserved.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * https://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * Sections of this project contains content developed by The MITRE Corporation.
20  * If this code is used in a deployment or embedded within another project,
21  * it is requested that you send an email to opensource@mitre.org in order to
22  * let us know where this software is being used.
23  *********************************************************************/
24 
35 
36 #include <QLineEdit>
37 #include <QHBoxLayout>
38 #include <QVBoxLayout>
39 #include <QLabel>
40 #include <QPainter>
41 #include <QFont>
42 
43 #include "diagnostic_msgs/DiagnosticArray.h"
44 #include <functional>
45 
46 
47 namespace kvh
48 {
57  StatusPanel::StatusPanel(QWidget* parent)
58  : rviz::Panel(parent)
59  {
60  QFont h1_font("Times", 18);
61  QFont h2_font("Times", 14);
62 
64  // System Status
66  QHBoxLayout* system_status_header = new QHBoxLayout;
67  QLabel* sys_stat_title = new QLabel("System Status");
68  sys_stat_title->setAlignment(Qt::AlignCenter);
69  sys_stat_title->setFont(h1_font);
70  system_status_header->addWidget(sys_stat_title);
71 
72  QHBoxLayout* system_status = new QHBoxLayout;
73  QVBoxLayout* failures = new QVBoxLayout;
74  QLabel* failure_label = new QLabel("Failures");
75  failure_label->setAlignment(Qt::AlignCenter);
76  failure_label->setFont(h2_font);
77  failures->addWidget(failure_label);
78  failures->addLayout(StatusIndicatorFactory(false, "System", "system"));
79  failures->addLayout(StatusIndicatorFactory(false, "Accelerometers", "accelerometers_failure"));
80  failures->addLayout(StatusIndicatorFactory(false, "Gyroscopes", "gyroscopes_failure"));
81  failures->addLayout(StatusIndicatorFactory(false, "Magnetometers", "magnetometers_failure"));
82  failures->addLayout(StatusIndicatorFactory(false, "Pressure", "pressure_failure"));
83  failures->addLayout(StatusIndicatorFactory(false, "GNSS", "gnss"));
84  system_status->addLayout(failures);
85 
86  QVBoxLayout* overrange = new QVBoxLayout;
87  QLabel* overrange_label = new QLabel("Overrange");
88  overrange_label->setAlignment(Qt::AlignCenter);
89  overrange_label->setFont(h2_font);
90  overrange->addWidget(overrange_label);
91  overrange->addLayout(StatusIndicatorFactory(false, "Accelerometers", "accelerometers_overrange"));
92  overrange->addLayout(StatusIndicatorFactory(false, "Gyroscopes", "gyroscopes_overrange"));
93  overrange->addLayout(StatusIndicatorFactory(false, "Magnetometers", "magnetometers_overrange"));
94  overrange->addLayout(StatusIndicatorFactory(false, "Pressure", "pressure_overrange"));
95  overrange->addWidget(new QLabel());
96  overrange->addWidget(new QLabel());
97  system_status->addLayout(overrange);
98 
99  QHBoxLayout* system_status_2 = new QHBoxLayout;
100  QVBoxLayout* alarms = new QVBoxLayout;
101  QLabel* alarms_label = new QLabel("Alarms");
102  alarms_label->setAlignment(Qt::AlignCenter);
103  alarms_label->setFont(h2_font);
104  alarms->addWidget(alarms_label);
105  alarms->addLayout(StatusIndicatorFactory(false, "Minimum Temperature", "minimum_temp"));
106  alarms->addLayout(StatusIndicatorFactory(false, "Maximum Temperature", "maximum_temp"));
107  alarms->addLayout(StatusIndicatorFactory(false, "Low Voltage", "low_volt"));
108  alarms->addLayout(StatusIndicatorFactory(false, "High Voltage", "high_volt"));
109  alarms->addLayout(StatusIndicatorFactory(false, "GNSS Antenna", "gps_antenna"));
110  alarms->addLayout(StatusIndicatorFactory(false, "Serial Port Overflow", "serial_port_over"));
111  system_status_2->addLayout(alarms);
112 
114  // Filter Status
116  QHBoxLayout* filter_status_header = new QHBoxLayout;
117  QLabel* filter_stat_title = new QLabel("Filter Status");
118  filter_stat_title->setAlignment(Qt::AlignCenter);
119  filter_stat_title->setFont(h1_font);
120  filter_status_header->addWidget(filter_stat_title);
121 
122  QHBoxLayout* filter_status = new QHBoxLayout;
123  QVBoxLayout* initialization = new QVBoxLayout;
124  QLabel* initialization_label = new QLabel("Initialization");
125  initialization_label->setAlignment(Qt::AlignCenter);
126  initialization_label->setFont(h2_font);
127  initialization->addWidget(initialization_label);
128  initialization->addLayout(StatusIndicatorFactory(false, "Orientation", "orientation_init"));
129  initialization->addLayout(StatusIndicatorFactory(false, "Navigation", "nav_init"));
130  initialization->addLayout(StatusIndicatorFactory(false, "Heading", "heading_init"));
131  initialization->addLayout(StatusIndicatorFactory(false, "Time", "time_init"));
132  initialization->addWidget(new QLabel(""));
133  initialization->addWidget(new QLabel(""));
134  initialization->addWidget(new QLabel(""));
135  filter_status->addLayout(initialization);
136 
137  QVBoxLayout* gnss_fix = new QVBoxLayout;
138  QLabel* gnss_label = new QLabel("GNSS");
139  gnss_label->setAlignment(Qt::AlignCenter);
140  gnss_label->setFont(h2_font);
141  gnss_fix->addWidget(gnss_label);
142  gnss_fix->addLayout(StatusIndicatorFactory(false, "2D", "gnss_2D"));
143  gnss_fix->addLayout(StatusIndicatorFactory(false, "3D", "gnss_3D"));
144  gnss_fix->addLayout(StatusIndicatorFactory(false, "SBAS", "gnss_sbas"));
145  gnss_fix->addLayout(StatusIndicatorFactory(false, "Differential", "gnss_diff"));
146  gnss_fix->addLayout(StatusIndicatorFactory(false, "Omnistar", "gnss_omni"));
147  gnss_fix->addLayout(StatusIndicatorFactory(false, "RTK Float", "gnss_rtk_float"));
148  gnss_fix->addLayout(StatusIndicatorFactory(false, "RTK", "gnss_rtk"));
149  filter_status->addLayout(gnss_fix);
150 
151  QHBoxLayout* filter_status_2 = new QHBoxLayout;
152  QVBoxLayout* filter_sources = new QVBoxLayout;
153  QLabel* filter_sources_label = new QLabel("Filter Sources");
154  filter_sources_label->setAlignment(Qt::AlignCenter);
155  filter_sources_label->setFont(h2_font);
156  filter_sources->addWidget(filter_sources_label);
157  filter_sources->addLayout(StatusIndicatorFactory(false, "Internal GNSS", "internal_gnss"));
158  filter_sources->addLayout(StatusIndicatorFactory(false, "Dual Antenna Heading", "dual_antenna_head"));
159  filter_sources->addLayout(StatusIndicatorFactory(false, "Velocity Heading", "vel_heading"));
160  filter_sources->addLayout(StatusIndicatorFactory(false, "Atmospheric Altitude", "atm_alt"));
161  filter_sources->addLayout(StatusIndicatorFactory(false, "External Position", "ext_pos"));
162  filter_sources->addLayout(StatusIndicatorFactory(false, "External Velocity", "ext_vel"));
163  filter_sources->addLayout(StatusIndicatorFactory(false, "External Heading", "ext_heading"));
164  filter_status_2->addLayout(filter_sources);
165 
166  QVBoxLayout* layout = new QVBoxLayout;
167  layout->addLayout(system_status_header);
168  layout->addLayout(system_status);
169  layout->addLayout(system_status_2);
170  layout->addLayout(filter_status_header);
171  layout->addLayout(filter_status);
172  layout->addLayout(filter_status_2);
173 
174  diag_sub_ = nh_.subscribe("diagnostics", 1, &StatusPanel::DiagnosticsCallback, this);
175 
176  setLayout(layout);
177  }
178 
187  QHBoxLayout* StatusPanel::StatusIndicatorFactory(bool _enabled, std::string _label, std::string _map_key)
188  {
189  QHBoxLayout* layout = new QHBoxLayout;
190  StatusPainter* painter = new StatusPainter;
191  painter->setEnabled(_enabled);
192 
193  painter_map_[_map_key] = painter;
194 
195  layout->addWidget(new QLabel(_label.c_str()));
196  layout->addWidget(painter);
197 
198  return layout;
199  }
200 
209  void StatusPanel::DiagnosticsCallback(const diagnostic_msgs::DiagnosticArray::ConstPtr& _diagArray)
210  {
211  ROS_DEBUG("Recieved diagnostic message.");
212  int kvh_filters_index{0};
213  bool kvh_filters_found{false};
214 
215  int kvh_system_index{0};
216  bool kvh_system_found{false};
217 
218  int loopCount{0};
219  for(diagnostic_msgs::DiagnosticStatus status : _diagArray->status)
220  {
221  if(status.name == "kvh_geo_fog_3d_driver_node: KVH Filters" && status.hardware_id == "KVH GEO FOG 3D")
222  {
223  kvh_filters_found = true;
224  kvh_filters_index = loopCount;
225  }
226  else if(status.name == "kvh_geo_fog_3d_driver_node: KVH System" && status.hardware_id == "KVH GEO FOG 3D")
227  {
228  kvh_system_found = true;
229  kvh_system_index = loopCount;
230  }
231  loopCount++;
232  }
233 
234  if (kvh_filters_found)
235  {
236  diagnostic_msgs::DiagnosticStatus kvh_status = _diagArray->status[kvh_filters_index];
237 
238  for (diagnostic_msgs::KeyValue pair : kvh_status.values)
239  {
240  ROS_DEBUG("%s, %s", pair.key.c_str(), pair.value.c_str());
241  if(pair.key == "Orient INIT")
242  {
243  painter_map_["orientation_init"]->setEnabled(pair.value == "True");
244  }
245  else if(pair.key == "Nav INIT")
246  {
247  painter_map_["nav_init"]->setEnabled(pair.value == "True");
248  }
249  else if(pair.key == "Heading INIT")
250  {
251  painter_map_["heading_init"]->setEnabled(pair.value == "True");
252  }
253  else if(pair.key == "Time INIT")
254  {
255  painter_map_["time_init"]->setEnabled(pair.value == "True");
256  }
257  else if(pair.key == "Internal GNSS Enabled")
258  {
259  painter_map_["internal_gnss"]->setEnabled(pair.value == "True");
260  }
261  else if(pair.key == "Dual ANT Heading Active")
262  {
263  painter_map_["dual_antenna_head"]->setEnabled(pair.value == "True");
264  }
265  else if(pair.key == "Vel Heading Enabled")
266  {
267  painter_map_["vel_heading"]->setEnabled(pair.value == "True");
268  }
269  else if(pair.key == "Atm Alt Enabled")
270  {
271  painter_map_["atm_alt"]->setEnabled(pair.value == "True");
272  }
273  else if(pair.key == "EXT Pos Active")
274  {
275  painter_map_["ext_pos"]->setEnabled(pair.value == "True");
276  }
277  else if(pair.key == "EXT Vel Active")
278  {
279  painter_map_["ext_vel"]->setEnabled(pair.value == "True");
280  }
281  else if(pair.key == "EXT Heading Active")
282  {
283  painter_map_["ext_heading"]->setEnabled(pair.value == "True");
284  }
285  else if(pair.key == "Fix Status")
286  {
287  painter_map_["gnss_2D"]->setEnabled(pair.value == "2D Fix");
288  painter_map_["gnss_3D"]->setEnabled(pair.value == "3D Fix");
289  painter_map_["gnss_sbas"]->setEnabled(pair.value == "SBAS");
290  painter_map_["gnss_diff"]->setEnabled(pair.value == "Diff");
291  painter_map_["gnss_omni"]->setEnabled(pair.value == "Omni/Star");
292  painter_map_["gnss_rtk_float"]->setEnabled(pair.value == "RTK Float");
293  painter_map_["gnss_rtk"]->setEnabled(pair.value == "RTK Fixed");
294  }
295  else if(pair.key == "Event1")
296  {
297  // Ignore for now
298  }
299  else if(pair.key == "Event2")
300  {
301  // Ignore for now
302  }
303  else
304  {
305  ROS_ERROR("CODING ERROR! You shouldn't be able to get here.");
306  }
307  }
308  }
309 
310  if (kvh_system_found)
311  {
312  diagnostic_msgs::DiagnosticStatus kvh_system_status = _diagArray->status[kvh_system_index];
313 
314  for (diagnostic_msgs::KeyValue pair : kvh_system_status.values)
315  {
316  if (pair.key == "System")
317  {
318  painter_map_["system"]->setEnabled(pair.value == "False");
319  }
320  else if (pair.key == "Accel")
321  {
322  painter_map_["accelerometers_failure"]->setEnabled(pair.value == "False");
323  }
324  else if (pair.key == "Gyro")
325  {
326  painter_map_["gyroscopes_failure"]->setEnabled(pair.value == "False");
327  }
328  else if (pair.key == "Mag")
329  {
330  painter_map_["magnetometers_failure"]->setEnabled(pair.value == "False");
331  }
332  else if (pair.key == "Pressure")
333  {
334  painter_map_["pressure_failure"]->setEnabled(pair.value == "False");
335  }
336  else if (pair.key == "GNSS")
337  {
338  painter_map_["gnss"]->setEnabled(pair.value == "False");
339  }
340  else if (pair.key == "Acc OOR")
341  {
342  painter_map_["accelerometers_overrange"]->setEnabled(pair.value == "False");
343  }
344  else if (pair.key == "Gyro OOR")
345  {
346  painter_map_["gyroscopes_overrange"]->setEnabled(pair.value == "False");
347  }
348  else if (pair.key == "Mag OOR")
349  {
350  painter_map_["magnetometers_overrange"]->setEnabled(pair.value == "False");
351  }
352  else if (pair.key == "Pressure OOR")
353  {
354  painter_map_["pressure_overrange"]->setEnabled(pair.value == "False");
355  }
356  else if (pair.key == "Min Temp")
357  {
358  painter_map_["minimum_temp"]->setEnabled(pair.value == "False");
359  }
360  else if (pair.key == "Max Temp")
361  {
362  painter_map_["maximum_temp"]->setEnabled(pair.value == "False");
363  }
364  else if (pair.key == "Low V")
365  {
366  painter_map_["low_volt"]->setEnabled(pair.value == "False");
367  }
368  else if (pair.key == "High V")
369  {
370  painter_map_["high_volt"]->setEnabled(pair.value == "False");
371  }
372  else if (pair.key == "GNSS ANT DC")
373  {
374  painter_map_["gps_antenna"]->setEnabled(pair.value == "False");
375  }
376  else if (pair.key == "Data Overflow")
377  {
378  painter_map_["serial_port_over"]->setEnabled(pair.value == "False");
379  }
380  }
381  }
382 
383  }
384 
385 
386 }
387 
388 // Exporting the plugin
void DiagnosticsCallback(const diagnostic_msgs::DiagnosticArray::ConstPtr &)
Function to receive diagnostics information and calculate statuses.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::Subscriber diag_sub_
ROS subscriber for diagnostics information.
RVIZ panel for displaying KVH sensor status.
PLUGINLIB_EXPORT_CLASS(kvh::StatusPanel, rviz::Panel)
KVH Geo Fog 3D RVIZ plugin status panel.
StatusPainter which lets us draw red/green circles for device status.
ros::NodeHandle nh_
Our ROS nodehandle object.
QHBoxLayout * StatusIndicatorFactory(bool, std::string, std::string)
Create mappings from our diagnostics strings to painters.
StatusPanel(QWidget *parent=0)
Constructor for our RVIZ panel.
std::unordered_map< std::string, StatusPainter * > painter_map_
Holds our key/value set of diagnostics message strings to painter objects.
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


kvh_geo_fog_3d_rviz
Author(s): Zach LaCelle
autogenerated on Fri Jan 24 2020 03:18:20