From 36266cacc451d468f450fd42e4a4e7de403f6144 Mon Sep 17 00:00:00 2001 From: DaMichel Date: Tue, 2 Aug 2016 12:55:58 +0200 Subject: filter/kalman: slider resolution shall be limited by pixels on screen, not by quantization of slider values. --- filter-kalman/ftnoir_kalman_filtercontrols.ui | 8 +++--- filter-kalman/kalman.cpp | 39 ++++++++++++++++----------- 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 @@ - 100 + 10000 1 @@ -67,7 +67,7 @@ false - QSlider::TicksAbove + QSlider::NoTicks 10 @@ -84,13 +84,13 @@ - 100 + 10000 Qt::Horizontal - QSlider::TicksAbove + QSlider::NoTicks 10 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(s.noise_pos_slider_value); + prev_slider_pos[1] = static_cast(s.noise_rot_slider_value); minimal_state_var = PoseVector::Constant(std::numeric_limits::max()); @@ -211,8 +211,8 @@ void FTNoIR_Filter::filter(const double* input_, double *output_) Eigen::Map input(input_, PoseVector::RowsAtCompileTime, 1); Eigen::Map 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 noise_rot_slider_value; - value noise_pos_slider_value; + value noise_rot_slider_value; + 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&); }; -- cgit v1.2.3