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 <cstdint>
26 #include <string>
27 
28 //boilerplate config
29 namespace armarx
30 {
31  void
33  {
36  settings->value("dbgo", "DebugObserver").toString().toStdString());
37  }
38 
39  void
41  {
43  settings->setValue(
44  "dbgo",
45  QString::fromStdString(getDebugObserverComponentPlugin().getDebugObserverTopic()));
46  }
47 
48  QPointer<QDialog>
50  {
52  if (!_dialog)
53  {
54  _dialog = new SimpleConfigDialog(parent);
55  _dialog->addLineEdit("dbgo", "DebugObserver Topic", "DebugObserver");
56  }
57  return qobject_cast<SimpleConfigDialog*>(_dialog);
58  }
59 
60  void
62  {
65  }
66 } // namespace armarx
67 
68 //boilerplate ctor/cycle
69 
70 namespace armarx
71 {
73  {
74  _widget.setupUi(getWidget());
75  connect(_widget.pushButtonSend,
76  &QPushButton::clicked,
77  this,
78  &DebugPlotterWidgetWidgetController::send);
79  startTimer(3);
80  }
81 } // namespace armarx
82 
83 namespace armarx
84 {
85  void
86  DebugPlotterWidgetWidgetController::send()
87  {
88  _last_send = clock_t::now();
89 
90  DebugObserverHelper oh{this, getDebugObserver()};
91  oh.setDebugObserverBatchModeEnabled(true);
93 
94  auto obs = getDebugObserver()->ice_batchOneway();
95  obs->setDebugDatafield("DebugPlotter_obs", "field", new Variant(1));
96  obs->setDebugChannel("DebugPlotter_obs_c2",
97  {{"field_1", new Variant(1)}, {"field_2", new Variant(1)}});
98  obs->setDebugDatafield("DebugPlotter_obs", "field_2", new Variant(1));
99  obs->removeDebugDatafield("DebugPlotter_obs", "field_2");
100 
101  const double val =
102  _widget.checkBoxSinValue->isChecked()
103  ? std::sin(std::chrono::steady_clock::now().time_since_epoch().count() / 1e9)
104  : _widget.doubleSpinBoxValue->value();
105 
106  const auto num_instances = _widget.spinBoxNumInstances->value();
107 
108  const auto s = [&](const std::string& name, auto value)
109  {
110  for (int i = 0; i < num_instances; ++i)
111  {
112  const auto n = name + "_" + std::to_string(i);
113  setDebugObserverDatafield("DebugPlotter", n, value);
114  oh.setDebugObserverDatafield("DebugPlotter_via_helper", n, value);
115  }
116  };
117 
118  const bool b = static_cast<std::uint64_t>(val) % 2;
119  s("float", static_cast<float>(val));
120  s("double", static_cast<double>(val));
121 
122  s("uint8", static_cast<unsigned char>(val));
123  s("uint16", static_cast<std::uint16_t>(val));
124  s("uint32", static_cast<std::uint32_t>(val));
125  s("uint64", static_cast<std::uint64_t>(val));
126 
127  s("int8", static_cast<char>(val));
128  s("int16", static_cast<std::int16_t>(val));
129  s("int32", static_cast<std::int32_t>(val));
130  s("int64", static_cast<std::int64_t>(val));
131 
132  s("string", std::to_string(val));
133 
134  s("bool", b);
135 
137  oh.sendDebugObserverBatch();
138  obs->ice_flushBatchRequests();
139  }
140 
141  void
143  {
144  _widget.doubleSpinBoxValue->setSingleStep(_widget.doubleSpinBoxValueStep->value());
145  if (!_widget.checkBoxAutoSend->isChecked())
146  {
147  return;
148  }
149  const auto dtMs =
150  std::chrono::duration_cast<std::chrono::milliseconds>(clock_t::now() - _last_send)
151  .count();
152  if (dtMs >= _widget.spinBoxAutoSendDelay->value())
153  {
154  send();
155  }
156  }
157 } // namespace armarx
armarx::DebugObserverComponentPluginUser::getDebugObserverComponentPlugin
plugins::DebugObserverComponentPlugin & getDebugObserverComponentPlugin()
Definition: DebugObserverComponentPlugin.cpp:89
armarx::DebugObserverHelper::sendDebugObserverBatch
void sendDebugObserverBatch()
Definition: DebugObserverHelper.cpp:71
armarx::plugins::DebugObserverComponentPlugin::setDebugObserverTopic
void setDebugObserverTopic(const std::string &name)
Definition: DebugObserverComponentPlugin.cpp:30
armarx::DebugObserverComponentPluginUser::setDebugObserverDatafield
void setDebugObserverDatafield(Ts &&... ts) const
Definition: DebugObserverComponentPlugin.h:86
armarx::DebugPlotterWidgetWidgetController::DebugPlotterWidgetWidgetController
DebugPlotterWidgetWidgetController()
Controller Constructor.
Definition: DebugPlotterWidgetWidgetController.cpp:72
armarx::DebugObserverComponentPluginUser::getDebugObserver
const DebugObserverInterfacePrx & getDebugObserver() const
Definition: DebugObserverComponentPlugin.cpp:123
armarx::DebugPlotterWidgetWidgetController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: DebugPlotterWidgetWidgetController.cpp:49
armarx::DebugObserverHelper::setDebugObserverBatchModeEnabled
void setDebugObserverBatchModeEnabled(bool enable)
Definition: DebugObserverHelper.cpp:64
armarx::DebugPlotterWidgetWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
Definition: DebugPlotterWidgetWidgetController.cpp:32
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::DebugPlotterWidgetWidgetController::timerEvent
void timerEvent(QTimerEvent *event) override
Definition: DebugPlotterWidgetWidgetController.cpp:142
DebugPlotterWidgetWidgetController.h
armarx::DebugPlotterWidgetWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
Definition: DebugPlotterWidgetWidgetController.cpp:40
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
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:27
armarx::DebugPlotterWidgetWidgetController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: DebugPlotterWidgetWidgetController.cpp:61
armarx::SimpleConfigDialog
A config-dialog containing one (or multiple) proxy finders.
Definition: SimpleConfigDialog.h:84