FTSensorCalibrationGuiWidgetController.h
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 RobotAPI::gui-plugins::FTSensorCalibrationGuiWidgetController
17  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
18  * @date 2020
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 #pragma once
23 
24 #include <fstream>
25 
28 
32 
33 #include <RobotAPI/gui-plugins/FTSensorCalibrationGui/ui_FTSensorCalibrationGuiWidget.h>
37 
38 //compensation_table
39 namespace armarx
40 {
41  template <class T>
43  {
44  using value_t = T;
45  using entry_t = std::array<value_t, 3>;
46  std::vector<entry_t> table;
47 
48  value_t compensate(value_t decision, value_t value) const;
49 
50  private:
51  value_t apply(const entry_t& f, value_t value) const;
52  value_t
53  interpolate(value_t decision, const entry_t& lo, const entry_t& hi, value_t value) const;
54 
55  mutable std::size_t last_idx = 0;
56  mutable entry_t search_dummy;
57  };
58 
59  template <class T>
60  inline typename compensation_table<T>::value_t
62  {
63  if (table.empty())
64  {
65  return value;
66  }
67  search_dummy.at(0) = decision;
68 
69  const auto lower =
70  std::lower_bound(table.begin(),
71  table.end(),
72  decision,
73  [](const entry_t& e, value_t v) { return e.at(0) < v; });
74  if (lower == table.end())
75  {
76  return apply(table.back(), value);
77  }
78  if (lower == table.begin())
79  {
80  return apply(table.front(), value);
81  }
82  //interpolate
83  return interpolate(decision, *(lower - 1), *lower, value);
84  }
85 
86  template <class T>
87  inline typename compensation_table<T>::value_t
88  compensation_table<T>::apply(const entry_t& f, value_t value) const
89  {
90  return f.at(1) * value + f.at(2);
91  }
92 
93  template <class T>
94  inline typename compensation_table<T>::value_t
95  compensation_table<T>::interpolate(value_t decision,
96  const entry_t& lo,
97  const entry_t& hi,
98  value_t value) const
99  {
100  const value_t t = (decision - lo.at(0)) / (hi.at(0) - lo.at(0));
101  const value_t a = lo.at(1) * (1 - t) + hi.at(1) * t;
102  const value_t b = lo.at(2) * (1 - t) + hi.at(2) * t;
103  return a * value + b;
104  }
105 } // namespace armarx
106 
107 namespace armarx
108 {
109  /**
110  \page RobotAPI-GuiPlugins-FTSensorCalibrationGui FTSensorCalibrationGui
111  \brief The FTSensorCalibrationGui allows visualizing ...
112 
113  \image html FTSensorCalibrationGui.png
114  The user can
115 
116  API Documentation \ref FTSensorCalibrationGuiWidgetController
117 
118  \see FTSensorCalibrationGuiGuiPlugin
119  */
120 
121  /**
122  * \class FTSensorCalibrationGuiWidgetController
123  * \brief FTSensorCalibrationGuiWidgetController brief one line description
124  *
125  * Detailed description
126  */
129  FTSensorCalibrationGuiWidgetController>,
130  public virtual RobotUnitComponentPluginUser,
131  public virtual RobotStateComponentPluginUser,
132  public virtual DebugObserverComponentPluginUser
133  {
134  Q_OBJECT
135 
136  public:
139 
140  void loadSettings(QSettings* settings) override;
141  void saveSettings(QSettings* settings) override;
142  QPointer<QDialog> getConfigDialog(QWidget* parent) override;
143  void configured() override;
144 
145  /**
146  * Returns the Widget name displayed in the ArmarXGui to create an
147  * instance of this class.
148  */
149  static QString
151  {
152  return "Debugging.FTSensorCalibrationGui";
153  }
154 
155  void
156  onInitComponent() override
157  {
158  }
159 
160  void onConnectComponent() override;
161  void onDisconnectComponent() override;
162 
163  void
164  onExitComponent() override
165  {
166  }
167 
168  protected:
169  void timerEvent(QTimerEvent* event) override;
170 
171  private slots:
172  void loadCalibFromFile();
173  void startRecording();
174  void stopRecording();
175  void updateCalibration();
176  void updateCompensation();
177  void loadDefaultArmar6FTL();
178  void loadDefaultArmar6FTR();
179 
180  private:
181  QPointer<SimpleConfigDialog> _dialog;
182  mutable std::recursive_mutex _all_mutex;
183  VirtualRobot::RobotPtr _robot;
184  Ui::FTSensorCalibrationGuiWidget _widget;
185  bool _recording = false;
186  bool _comboboxes_are_set_up = false;
187  std::set<std::string> _all_logging_names;
188 
189  Eigen::Matrix6f _conversion_matrix;
190  Eigen::Vector6f _offset;
191  Eigen::Vector6i _channel_order;
192  float _ticks_to_volt_factor;
193 
194  RobotUnitDataStreamingReceiverPtr _streaming_handler;
195  std::array<RobotUnitDataStreaming::DataEntry, 6> _adc;
196  std::array<RobotUnitDataStreaming::DataEntry, 6> _adc_temp;
197  std::vector<RobotUnitDataStreaming::DataEntry> _joints;
198  std::ofstream _logfile;
199 
200  compensation_table<float> _comp_table;
201  };
202 } // namespace armarx
armarx::RobotUnitComponentPluginUser
Provides a ready-to-use RobotUnit.
Definition: RobotUnitComponentPlugin.h:98
armarx::compensation_table
Definition: FTSensorCalibrationGuiWidgetController.h:42
armarx::FTSensorCalibrationGuiWidgetController
FTSensorCalibrationGuiWidgetController brief one line description.
Definition: FTSensorCalibrationGuiWidgetController.h:127
RobotStateComponentPlugin.h
armarx::RobotUnitDataStreamingReceiverPtr
std::shared_ptr< class RobotUnitDataStreamingReceiver > RobotUnitDataStreamingReceiverPtr
Definition: RobotUnitReader.h:30
lo
#define lo(x)
Definition: AbstractInterface.h:47
armarx::ArmarXComponentWidgetControllerTemplate
Definition: ArmarXComponentWidgetController.h:69
SimpleConfigDialog.h
armarx::FTSensorCalibrationGuiWidgetController::onInitComponent
void onInitComponent() override
Pure virtual hook for the subclass.
Definition: FTSensorCalibrationGuiWidgetController.h:156
ArmarXGuiPlugin.h
RobotUnitDataStreamingReceiver.h
armarx::compensation_table< float >::entry_t
std::array< value_t, 3 > entry_t
Definition: FTSensorCalibrationGuiWidgetController.h:45
armarx::compensation_table::compensate
value_t compensate(value_t decision, value_t value) const
Definition: FTSensorCalibrationGuiWidgetController.h:61
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
ArmarXComponentWidgetController.h
ARMARXCOMPONENT_IMPORT_EXPORT
#define ARMARXCOMPONENT_IMPORT_EXPORT
Definition: ImportExportComponent.h:38
armarx::compensation_table< float >::value_t
float value_t
Definition: FTSensorCalibrationGuiWidgetController.h:44
armarx::FTSensorCalibrationGuiWidgetController::onExitComponent
void onExitComponent() override
Hook for subclass.
Definition: FTSensorCalibrationGuiWidgetController.h:164
DebugObserverComponentPlugin.h
armarx::compensation_table::table
std::vector< entry_t > table
Definition: FTSensorCalibrationGuiWidgetController.h:46
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
hi
#define hi(x)
Definition: AbstractInterface.h:46
armarx::DebugObserverComponentPluginUser
Definition: DebugObserverComponentPlugin.h:73
armarx::FTSensorCalibrationGuiWidgetController::GetWidgetName
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
Definition: FTSensorCalibrationGuiWidgetController.h:150
Eigen::Matrix< Ice::Float, 6, 6 >
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
armarx::RobotStateComponentPluginUser
Definition: RobotStateComponentPlugin.h:165
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
RobotUnitComponentPlugin.h
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
ImportExportComponent.h