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