25 #include <SimoxUtility/algorithm/get_map_keys_values.h>
27 #include <qnamespace.h>
29 #include <qtablewidget.h>
34 #include <QPushButton>
45 for(std::size_t i = 0; i < l.size(); i++)
47 const auto& tag = l.at(i);
67 Qt::QueuedConnection);
72 Qt::QueuedConnection);
74 connect(widget.pushButtonUnrequireAll,
79 updateSummaryTimer =
new QTimer(
this);
80 updateSummaryTimer->setInterval(100);
109 armarx::core::time::dto::DateTime now;
111 robotHealthTopicPrx->heartbeat(
getName(), now);
117 std::stringstream ss;
118 ss << std::fixed << std::setprecision(3) <<
value;
124 Qt::AlignmentFlag horAlignment = Qt::AlignLeft)
126 auto* item =
new QTableWidgetItem(QString::fromStdString(text));
127 item->setTextAlignment(horAlignment | Qt::AlignVCenter);
136 if (robotHealthComponentPrx)
141 auto summary = robotHealthComponentPrx->getSummary();
143 const std::size_t nCols = 10;
145 auto& tableWidget = widget.tableHealthState;
146 tableWidget->setRowCount(summary.entries.size());
147 tableWidget->setColumnCount(nCols);
149 const auto summaryVals = simox::alg::get_values(summary.entries);
151 tableWidget->setHorizontalHeaderLabels({
152 "identifier",
"required",
"keeps frequency",
"tags",
"time since\nlast arrival [ms]",
"time to\nreference [ms]",
"time sync \n+ Ice [ms]",
"warning\nthreshold [ms]",
"error\nthreshold [ms]",
"hostname"
155 tableWidget->setColumnWidth(0, 250);
156 tableWidget->setColumnWidth(1, 80);
157 tableWidget->setColumnWidth(2, 120);
158 tableWidget->setColumnWidth(3, 180);
159 tableWidget->setColumnWidth(4, 120);
160 tableWidget->setColumnWidth(5, 120);
161 tableWidget->setColumnWidth(6, 120);
162 tableWidget->setColumnWidth(7, 120);
164 for(std::size_t i = 0; i < summary.entries.size(); i++)
166 const auto& entry = summaryVals.at(i);
168 std::string stateRepr;
174 stateColor.setRgb(0, 255, 0);
178 stateColor.setRgb(255, 165, 0);
182 stateColor.setRgb(255, 0, 0);
186 const std::string hostname = entry.lastReferenceTimestamp.hostname;
188 const std::string timeSinceLastArrivalRepr =
to_string_rounded(entry.timeSinceLastArrival.microSeconds / 1000.0);
189 const std::string timeToLastReferenceRepr =
to_string_rounded(entry.timeSinceLastUpdateReference.microSeconds / 1000.0);
192 const float syncErrorMilliSeconds =
std::abs(entry.timeSinceLastArrival.microSeconds - entry.timeSinceLastUpdateReference.microSeconds) / 1000.0;
194 tableWidget->setItem(i, 0,
new QTableWidgetItem(QString::fromStdString(entry.identifier)));
195 tableWidget->setItem(i, 1,
make_item(entry.required ?
"yes" :
"no", Qt::AlignHCenter));
198 auto* item =
make_item(stateRepr, Qt::AlignHCenter);
199 item->setBackgroundColor(stateColor);
200 tableWidget->setItem(i, 2, item);
203 tableWidget->setItem(i, 3,
new QTableWidgetItem(QString::fromStdString(tagsRepr)));
204 tableWidget->setItem(i, 4,
make_item(timeSinceLastArrivalRepr, Qt::AlignRight));
205 tableWidget->setItem(i, 5,
make_item(timeToLastReferenceRepr, Qt::AlignRight));
210 QColor timeSyncColor;
211 if (syncErrorMilliSeconds > 20.)
213 timeSyncColor.setRgb(255, 0, 0);
217 timeSyncColor.setRgb(0, 255, 0);
219 item->setBackgroundColor(timeSyncColor);
221 tableWidget->setItem(i, 6, item);
226 tableWidget->setItem(i, 9,
new QTableWidgetItem(QString::fromStdString(hostname)));
229 std::string tagsText =
"Active tags: [";
231 std::sort(summary.activeTags.begin(), summary.activeTags.end());
238 widget.labelTags->setText(QString::fromStdString(tagsText));
250 if (robotHealthComponentPrx)
254 robotHealthComponentPrx->resetRequiredTags();
264 robotHealthTopicPrx = getTopic<RobotHealthInterfacePrx>(
"RobotHealthTopic");
265 robotHealthComponentPrx = getProxy<RobotHealthComponentInterfacePrx>(
"RobotHealth");
274 updateSummaryTimer->start();
286 updateSummaryTimer->stop();