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
39namespace 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;
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
107namespace 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,
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
157 {
158 }
159
160 void onConnectComponent() override;
161 void onDisconnectComponent() override;
162
163 void
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;
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
#define lo(x)
#define hi(x)
#define ARMARXCOMPONENT_IMPORT_EXPORT
void onInitComponent() override
Pure virtual hook for the subclass.
void loadSettings(QSettings *settings) override
Implement to load the settings that are part of the GUI configuration.
void saveSettings(QSettings *settings) override
Implement to save the settings as part of the GUI configuration.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
static QString GetWidgetName()
Returns the Widget name displayed in the ArmarXGui to create an instance of this class.
QPointer< QDialog > getConfigDialog(QWidget *parent) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Matrix< Ice::Float, 6, 6 > Matrix6f
Definition FramedPose.h:54
Matrix< float, 6, 1 > Vector6f
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< class RobotUnitDataStreamingReceiver > RobotUnitDataStreamingReceiverPtr
value_t compensate(value_t decision, value_t value) const