DebugPlotterWidgetWidgetController.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * \package ArmarXGui::gui-plugins::DebugPlotterWidgetWidgetController
17  * \author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * \date 2021
19  * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 
25 #include <string>
26 #include <cstdint>
27 
28 //boilerplate config
29 namespace armarx
30 {
32  {
34  getDebugObserverComponentPlugin().setDebugObserverTopic(settings->value("dbgo", "DebugObserver").toString().toStdString());
35  }
36 
38  {
40  settings->setValue("dbgo", QString::fromStdString(getDebugObserverComponentPlugin().getDebugObserverTopic()));
41  }
42 
43  QPointer<QDialog> DebugPlotterWidgetWidgetController::getConfigDialog(QWidget* parent)
44  {
46  if (!_dialog)
47  {
48  _dialog = new SimpleConfigDialog(parent);
49  _dialog->addLineEdit("dbgo", "DebugObserver Topic", "DebugObserver");
50  }
51  return qobject_cast<SimpleConfigDialog*>(_dialog);
52  }
53 
55  {
58  }
59 }
60 
61 //boilerplate ctor/cycle
62 
63 namespace armarx
64 {
66  {
67  _widget.setupUi(getWidget());
68  connect(_widget.pushButtonSend, &QPushButton::clicked,
69  this, &DebugPlotterWidgetWidgetController::send);
70  startTimer(3);
71  }
72 }
73 
74 namespace armarx
75 {
76  void DebugPlotterWidgetWidgetController::send()
77  {
78  _last_send = clock_t::now();
79 
80  DebugObserverHelper oh{this, getDebugObserver()};
81  oh.setDebugObserverBatchModeEnabled(true);
83 
84  auto obs = getDebugObserver()->ice_batchOneway();
85  obs->setDebugDatafield("DebugPlotter_obs", "field", new Variant(1));
86  obs->setDebugChannel("DebugPlotter_obs_c2",
87  {
88  {"field_1", new Variant(1)},
89  {"field_2", new Variant(1)}
90  });
91  obs->setDebugDatafield("DebugPlotter_obs", "field_2", new Variant(1));
92  obs->removeDebugDatafield("DebugPlotter_obs", "field_2");
93 
94  const double val =
95  _widget.checkBoxSinValue->isChecked() ?
96  std::sin(std::chrono::steady_clock::now().time_since_epoch().count() / 1e9) :
97  _widget.doubleSpinBoxValue->value();
98 
99  const auto num_instances = _widget.spinBoxNumInstances->value();
100 
101  const auto s = [&](const std::string & name, auto value)
102  {
103  for (int i = 0; i < num_instances; ++i)
104  {
105  const auto n = name + "_" + std::to_string(i);
106  setDebugObserverDatafield("DebugPlotter", n, value);
107  oh.setDebugObserverDatafield("DebugPlotter_via_helper", n, value);
108  }
109  };
110 
111  const bool b = static_cast<std::uint64_t>(val) % 2;
112  s("float", static_cast<float>(val));
113  s("double", static_cast<double>(val));
114 
115  s("uint8", static_cast<unsigned char>(val));
116  s("uint16", static_cast<std::uint16_t>(val));
117  s("uint32", static_cast<std::uint32_t>(val));
118  s("uint64", static_cast<std::uint64_t>(val));
119 
120  s("int8", static_cast<char >(val));
121  s("int16", static_cast<std::int16_t>(val));
122  s("int32", static_cast<std::int32_t>(val));
123  s("int64", static_cast<std::int64_t>(val));
124 
125  s("string", std::to_string(val));
126 
127  s("bool", b);
128 
130  oh.sendDebugObserverBatch();
131  obs->ice_flushBatchRequests();
132  }
133 
135  {
136  _widget.doubleSpinBoxValue->setSingleStep(_widget.doubleSpinBoxValueStep->value());
137  if (!_widget.checkBoxAutoSend->isChecked())
138  {
139  return;
140  }
141  const auto dtMs = std::chrono::duration_cast<std::chrono::milliseconds>(
142  clock_t::now() - _last_send
143  ).count();
144  if (dtMs >= _widget.spinBoxAutoSendDelay->value())
145  {
146  send();
147  }
148  }
149 }
armarx::DebugObserverComponentPluginUser::getDebugObserverComponentPlugin
plugins::DebugObserverComponentPlugin & getDebugObserverComponentPlugin()
Definition: DebugObserverComponentPlugin.cpp:85
armarx::DebugObserverHelper::sendDebugObserverBatch
void sendDebugObserverBatch()
Definition: DebugObserverHelper.cpp:63
armarx::plugins::DebugObserverComponentPlugin::setDebugObserverTopic
void setDebugObserverTopic(const std::string &name)
Definition: DebugObserverComponentPlugin.cpp:30
armarx::DebugPlotterWidgetWidgetController::DebugPlotterWidgetWidgetController
DebugPlotterWidgetWidgetController()
Controller Constructor.
Definition: DebugPlotterWidgetWidgetController.cpp:65
armarx::DebugObserverComponentPluginUser::getDebugObserver
const DebugObserverInterfacePrx & getDebugObserver() const
Definition: DebugObserverComponentPlugin.cpp:113
armarx::DebugPlotterWidgetWidgetController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: DebugPlotterWidgetWidgetController.cpp:43
armarx::DebugObserverHelper::setDebugObserverBatchModeEnabled
void setDebugObserverBatchModeEnabled(bool enable)
Definition: DebugObserverHelper.cpp:58
armarx::DebugPlotterWidgetWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: DebugPlotterWidgetWidgetController.cpp:31
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:69
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::DebugPlotterWidgetWidgetController::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: DebugPlotterWidgetWidgetController.cpp:134
DebugPlotterWidgetWidgetController.h
armarx::DebugPlotterWidgetWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: DebugPlotterWidgetWidgetController.cpp:37
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::DebugPlotterWidgetWidgetController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: DebugPlotterWidgetWidgetController.cpp:54
armarx::DebugObserverComponentPluginUser::setDebugObserverDatafield
void setDebugObserverDatafield(Ts &&...ts) const
Definition: DebugObserverComponentPlugin.h:97
armarx::SimpleConfigDialog
A config-dialog containing one (or multiple) proxy finders.
Definition: SimpleConfigDialog.h:84