diff options
-rw-r--r-- | filter-kalman/ftnoir_kalman_filtercontrols.ui | 8 | ||||
-rw-r--r-- | filter-kalman/kalman.cpp | 39 | ||||
-rw-r--r-- | filter-kalman/kalman.h | 18 |
3 files changed, 38 insertions, 27 deletions
diff --git a/filter-kalman/ftnoir_kalman_filtercontrols.ui b/filter-kalman/ftnoir_kalman_filtercontrols.ui index 848e5424..2e9bcae7 100644 --- a/filter-kalman/ftnoir_kalman_filtercontrols.ui +++ b/filter-kalman/ftnoir_kalman_filtercontrols.ui @@ -52,7 +52,7 @@ <item row="0" column="1"> <widget class="QSlider" name="noiseRotSlider"> <property name="maximum"> - <number>100</number> + <number>10000</number> </property> <property name="singleStep"> <number>1</number> @@ -67,7 +67,7 @@ <bool>false</bool> </property> <property name="tickPosition"> - <enum>QSlider::TicksAbove</enum> + <enum>QSlider::NoTicks</enum> </property> <property name="tickInterval"> <number>10</number> @@ -84,13 +84,13 @@ <item row="1" column="1"> <widget class="QSlider" name="noisePosSlider"> <property name="maximum"> - <number>100</number> + <number>10000</number> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> <property name="tickPosition"> - <enum>QSlider::TicksAbove</enum> + <enum>QSlider::NoTicks</enum> </property> <property name="tickInterval"> <number>10</number> diff --git a/filter-kalman/kalman.cpp b/filter-kalman/kalman.cpp index 804d15da..513ebf51 100644 --- a/filter-kalman/kalman.cpp +++ b/filter-kalman/kalman.cpp @@ -196,8 +196,8 @@ void FTNoIR_Filter::reset() first_run = true; dt_since_last_input = 0; - prev_slider_pos[0] = s.noise_pos_slider_value; - prev_slider_pos[1] = s.noise_rot_slider_value; + prev_slider_pos[0] = static_cast<slider_value>(s.noise_pos_slider_value); + prev_slider_pos[1] = static_cast<slider_value>(s.noise_rot_slider_value); minimal_state_var = PoseVector::Constant(std::numeric_limits<double>::max()); @@ -211,8 +211,8 @@ void FTNoIR_Filter::filter(const double* input_, double *output_) Eigen::Map<const PoseVector> input(input_, PoseVector::RowsAtCompileTime, 1); Eigen::Map<PoseVector> output(output_, PoseVector::RowsAtCompileTime, 1); - if (prev_slider_pos[0] != s.noise_pos_slider_value || - prev_slider_pos[1] != s.noise_rot_slider_value) + if (!(prev_slider_pos[0] == s.noise_pos_slider_value && + prev_slider_pos[1] == s.noise_rot_slider_value)) { reset(); } @@ -265,19 +265,28 @@ FilterControls::FilterControls() ui.setupUi(this); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - connect(ui.noiseRotSlider, &QSlider::valueChanged, [=](int value) { - this->ui.noiseRotLabel->setText( - // M$ hates unicode! (M$ autoconverts source code of one kind of utf-8 format, the one without BOM, to another kind that QT does not like) - // We could use QChar(0x00b0). It should be totally backward compatible. - // u8"°" is c++11. u8 means that the string is encoded in utf8. It happens to be compatible with QT. - QString::number(settings::map_slider_value(value), 'f', 3) + u8" °"); - }); - connect(ui.noisePosSlider, &QSlider::valueChanged, [=](int value) { - this->ui.noisePosLabel->setText( - QString::number(settings::map_slider_value(value), 'f', 3) + " cm"); - }); + tie_setting(s.noise_rot_slider_value, ui.noiseRotSlider); tie_setting(s.noise_pos_slider_value, ui.noisePosSlider); + + connect(&s.noise_rot_slider_value, SIGNAL(valueChanged(const slider_value&)), this, SLOT(updateLabels(const slider_value&))); + connect(&s.noise_pos_slider_value, SIGNAL(valueChanged(const slider_value&)), this, SLOT(updateLabels(const slider_value&))); + + updateLabels(slider_value()); +} + + +void FilterControls::updateLabels(const slider_value&) +{ + // M$ hates unicode! (M$ autoconverts source code of one kind of utf-8 format, + // the one without BOM, to another kind that QT does not like) + // Previous attempt to use c++11 utf8 strings like u8" °" now failed for unkown + // reasons where it worked before. Hence fallback to QChar(0x00b0). + this->ui.noiseRotLabel->setText( + QString::number(settings::map_slider_value(s.noise_rot_slider_value), 'f', 3) + " " + QChar(0x00b0)); + + this->ui.noisePosLabel->setText( + QString::number(settings::map_slider_value(s.noise_pos_slider_value), 'f', 3) + " cm"); } diff --git a/filter-kalman/kalman.h b/filter-kalman/kalman.h index a9771b8e..cb3041ea 100644 --- a/filter-kalman/kalman.h +++ b/filter-kalman/kalman.h @@ -87,25 +87,26 @@ struct DeadzoneFilter struct settings : opts { - value<int> noise_rot_slider_value; - value<int> noise_pos_slider_value; + value<slider_value> noise_rot_slider_value; + value<slider_value> noise_pos_slider_value; static constexpr double adaptivity_window_length = 0.5; // seconds static constexpr double deadzone_scale = 2.; static constexpr double deadzone_exponent = 4.0; // these values worked best for me (MW) when taken with acompanying measured noise stddev of ca 0.1 (rot) and 0.01 (pos). - static constexpr double process_sigma_pos = 0.05; + static constexpr double process_sigma_pos = 0.5; static constexpr double process_simga_rot = 0.5; - static double map_slider_value(int v) + static double map_slider_value(const slider_value &v) { - return std::pow(10., v * 0.04 - 3.); + //return std::pow(4., v * 5. - 4.) / 4. * 10.; // not so much difference, except that it is harder to adjust the min-max range. + return std::pow(10., v * 4. - 3.); } settings() : opts("kalman-filter"), - noise_rot_slider_value(b, "noise-rotation-slider", 40), - noise_pos_slider_value(b, "noise-position-slider", 40) + noise_rot_slider_value(b, "noise-rotation-slider", slider_value(0.5, 0., 1.)), + noise_pos_slider_value(b, "noise-position-slider", slider_value(0.5, 0., 1.)) {} }; @@ -128,7 +129,7 @@ public: KalmanProcessNoiseScaler kf_adaptive_process_noise_cov; PoseVector minimal_state_var; DeadzoneFilter dz_filter; - int prev_slider_pos[2]; + slider_value prev_slider_pos[2]; EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; @@ -153,4 +154,5 @@ public: public slots: void doOK(); void doCancel(); + void updateLabels(const slider_value&); }; |