diff options
-rw-r--r-- | filter-accela/accela-settings.hpp | 60 | ||||
-rw-r--r-- | filter-accela/ftnoir_accela_filtercontrols.ui | 53 | ||||
-rw-r--r-- | filter-accela/ftnoir_filter_accela.cpp | 23 | ||||
-rw-r--r-- | filter-accela/ftnoir_filter_accela.h | 79 | ||||
-rw-r--r-- | filter-accela/ftnoir_filter_accela_dialog.cpp | 44 |
5 files changed, 137 insertions, 122 deletions
diff --git a/filter-accela/accela-settings.hpp b/filter-accela/accela-settings.hpp new file mode 100644 index 00000000..9f0af413 --- /dev/null +++ b/filter-accela/accela-settings.hpp @@ -0,0 +1,60 @@ +#pragma once + +#include "options/options.hpp" +using namespace options; +#include "spline-widget/spline.hpp" + +struct settings_accela : opts +{ + static constexpr double rot_gains[16][2] = + { + { 12, 500 }, + { 11, 450 }, + { 10, 400 }, + { 9, 350 }, + { 8, 300 }, + { 7, 250 }, + { 6, 200 }, + { 2.66, 50 }, + { 1.66, 17 }, + { 1, 4 }, + { .5, .53 }, + { 0, 0 }, + { -1, 0 } + }; + + static constexpr double trans_gains[16][2] = + { + { 12, 400 }, + { 11, 350 }, + { 10, 300 }, + { 9, 250 }, + { 8, 200 }, + { 7, 150 }, + { 5, 80 }, + { 3, 32 }, + { 2, 10 }, + { 1.66, 6 }, + { 1.33, 3 }, + { .66, 1 }, + { .33, .5 }, + { 0, 0 }, + { -1, 0 } + }; + + static void make_splines(spline& rot, spline& trans); + + value<slider_value> rot_sensitivity, trans_sensitivity; + value<slider_value> rot_deadzone, trans_deadzone; + value<slider_value> ewma; + value<slider_value> rot_nonlinearity; + settings_accela() : + opts("accela-sliders"), + rot_sensitivity(b, "rotation-sensitivity", slider_value(1.8, .05, 3)), + trans_sensitivity(b, "translation-sensitivity", slider_value(1.8, .05, 3)), + rot_deadzone(b, "rotation-deadzone", slider_value(0, 0, .5)), + trans_deadzone(b, "translation-deadzone", slider_value(0, 0, .5)), + ewma(b, "ewma", slider_value(0, 0, 15)), + rot_nonlinearity(b, "rotation-nonlinearity", slider_value(1, 1, 1.75)) + {} +}; diff --git a/filter-accela/ftnoir_accela_filtercontrols.ui b/filter-accela/ftnoir_accela_filtercontrols.ui index 3a3f43d8..5b2dec16 100644 --- a/filter-accela/ftnoir_accela_filtercontrols.ui +++ b/filter-accela/ftnoir_accela_filtercontrols.ui @@ -14,10 +14,10 @@ </rect> </property> <property name="windowTitle"> - <string>Accela filter settings</string> + <string>Filter settings</string> </property> <property name="windowIcon"> - <iconset resource="../gui/ui-res.qrc"> + <iconset resource="../gui/opentrack-res.qrc"> <normaloff>:/images/filter-16.png</normaloff>:/images/filter-16.png</iconset> </property> <layout class="QGridLayout" name="gridLayout_3"> @@ -116,14 +116,14 @@ </item> <item> <widget class="QSlider" name="ewma_slider"> - <property name="maximum"> - <number>100</number> + <property name="minimum"> + <number>0</number> </property> - <property name="singleStep"> - <number>10</number> + <property name="maximum"> + <number>30</number> </property> <property name="pageStep"> - <number>25</number> + <number>3</number> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -185,11 +185,14 @@ </item> <item row="0" column="2"> <widget class="QSlider" name="rotation_slider"> + <property name="minimum"> + <number>0</number> + </property> <property name="maximum"> - <number>99</number> + <number>295</number> </property> <property name="pageStep"> - <number>5</number> + <number>15</number> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -224,8 +227,14 @@ </item> <item row="1" column="2"> <widget class="QSlider" name="rot_dz_slider"> + <property name="minimum"> + <number>0</number> + </property> <property name="maximum"> - <number>100</number> + <number>50</number> + </property> + <property name="pageStep"> + <number>5</number> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -281,11 +290,14 @@ </item> <item row="0" column="2"> <widget class="QSlider" name="translation_slider"> + <property name="minimum"> + <number>0</number> + </property> <property name="maximum"> - <number>99</number> + <number>295</number> </property> <property name="pageStep"> - <number>5</number> + <number>15</number> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -320,8 +332,14 @@ </item> <item row="1" column="2"> <widget class="QSlider" name="trans_dz_slider"> + <property name="minimum"> + <number>0</number> + </property> <property name="maximum"> - <number>100</number> + <number>50</number> + </property> + <property name="pageStep"> + <number>5</number> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -349,10 +367,13 @@ <number>0</number> </property> <property name="maximum"> - <number>100</number> + <number>15</number> + </property> + <property name="pageStep"> + <number>2</number> </property> <property name="value"> - <number>0</number> + <number>1</number> </property> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -393,7 +414,7 @@ <tabstop>buttonBox</tabstop> </tabstops> <resources> - <include location="../gui/ui-res.qrc"/> + <include location="../gui/opentrack-res.qrc"/> </resources> <connections/> <slots> diff --git a/filter-accela/ftnoir_filter_accela.cpp b/filter-accela/ftnoir_filter_accela.cpp index 7f79bafa..98e2eb36 100644 --- a/filter-accela/ftnoir_filter_accela.cpp +++ b/filter-accela/ftnoir_filter_accela.cpp @@ -11,12 +11,6 @@ #include <QMutexLocker> #include "api/plugin-api.hpp" -constexpr double settings_accela::mult_rot; -constexpr double settings_accela::mult_trans; -constexpr double settings_accela::mult_rot_dz; -constexpr double settings_accela::mult_trans_dz; -constexpr double settings_accela::mult_ewma; - constexpr double settings_accela::rot_gains[16][2]; constexpr double settings_accela::trans_gains[16][2]; @@ -41,17 +35,18 @@ void FTNoIR_Filter::filter(const double* input, double *output) return; } - const double rot_t = (1+s.rot_threshold) * s.mult_rot; - const double trans_t = (1+s.trans_threshold) * s.mult_trans; + const double rot_t = s.rot_sensitivity->cur(); + const double trans_t = s.trans_sensitivity->cur(); const double dt = t.elapsed_seconds(); t.start(); - const double RC = s.mult_ewma * s.ewma / 1000.; // seconds + const double RC = s.ewma->cur() / 1000.; // seconds const double alpha = dt/(dt+RC); - const double rot_dz = s.rot_deadzone * s.mult_rot_dz; - const double trans_dz = s.trans_deadzone * s.mult_trans_dz; - const double rot_nl = static_cast<const slider_value&>(s.rot_nonlinearity).cur(); + const double rot_dz = s.rot_deadzone->cur(); + const double trans_dz = s.trans_deadzone->cur(); + const slider_value rot_nl_ = s.rot_nonlinearity; + const double rot_nl = rot_nl_.cur(); for (int i = 0; i < 6; i++) { @@ -66,8 +61,8 @@ void FTNoIR_Filter::filter(const double* input, double *output) const double vec_ = std::max(0., fabs(vec) - dz); const double thres = i >= 3 ? rot_t : trans_t; const double out_ = vec_ / thres; - const double out = i >= 3 && std::fabs(rot_nl - 1) > 5e-3 && vec_ < s.max_rot_nl - ? (std::pow(out_/s.max_rot_nl, rot_nl) * s.max_rot_nl) + const double out = i >= 3 && std::fabs(rot_nl - 1) > 5e-3 && vec_ < rot_nl_.max() + ? (std::pow(out_/rot_nl_.max(), rot_nl)) : out_; const double val = double(m.getValue(out)); last_output[i] = output[i] = last_output[i] + signum(vec) * dt * val; diff --git a/filter-accela/ftnoir_filter_accela.h b/filter-accela/ftnoir_filter_accela.h index 38518931..7fd62f88 100644 --- a/filter-accela/ftnoir_filter_accela.h +++ b/filter-accela/ftnoir_filter_accela.h @@ -5,76 +5,15 @@ * copyright notice and this permission notice appear in all copies. */ #pragma once -#include "ui_ftnoir_accela_filtercontrols.h" +#include "accela-settings.hpp" #include "api/plugin-api.hpp" -#include "spline-widget/spline.hpp" +#include "compat/timer.hpp" +#include "ui_ftnoir_accela_filtercontrols.h" + #include <atomic> #include <QMutex> #include <QTimer> -#include "options/options.hpp" -using namespace options; -#include "compat/timer.hpp" - -struct settings_accela : opts -{ - static constexpr double rot_gains[16][2] = - { - { 12, 500 }, - { 11, 450 }, - { 10, 400 }, - { 9, 350 }, - { 8, 300 }, - { 7, 250 }, - { 6, 200 }, - { 2.66, 50 }, - { 1.66, 17 }, - { 1, 4 }, - { .5, .53 }, - { 0, 0 }, - { -1, 0 } - }; - - static constexpr double trans_gains[16][2] = - { - { 12, 400 }, - { 11, 350 }, - { 10, 300 }, - { 9, 250 }, - { 8, 200 }, - { 7, 150 }, - { 5, 80 }, - { 3, 32 }, - { 2, 10 }, - { 1.66, 6 }, - { 1.33, 3 }, - { .66, 1 }, - { .33, .5 }, - { 0, 0 }, - { -1, 0 } - }; - - static void make_splines(spline& rot, spline& trans); - - value<int> rot_threshold, trans_threshold, ewma, rot_deadzone, trans_deadzone; - value<slider_value> rot_nonlinearity; - static constexpr double mult_rot = 4. / 100.; - static constexpr double mult_trans = 4. / 100.; - static constexpr double mult_rot_dz = 2. / 100.; - static constexpr double mult_trans_dz = 2. / 100.; - static constexpr double mult_ewma = 1.25; - static constexpr double max_rot_nl = 1.33; - settings_accela() : - opts("Accela"), - rot_threshold(b, "rotation-threshold", 45), - trans_threshold(b, "translation-threshold", 50), - ewma(b, "ewma", 2), - rot_deadzone(b, "rotation-deadzone", 0), - trans_deadzone(b, "translation-deadzone", 0), - rot_nonlinearity(b, "rotation-nonlinearity", slider_value(1, 1, 2)) - {} -}; - class FTNoIR_Filter : public IFilter { public: @@ -122,11 +61,11 @@ private: private slots: void doOK(); void doCancel(); - void update_ewma_display(int value); - void update_rot_display(int value); - void update_trans_display(int value); - void update_rot_dz_display(int value); - void update_trans_dz_display(int value); + void update_ewma_display(const slider_value& value); + void update_rot_display(const slider_value& value); + void update_trans_display(const slider_value& value); + void update_rot_dz_display(const slider_value& value); + void update_trans_dz_display(const slider_value&); void update_rot_nl_slider(const slider_value& sl); }; diff --git a/filter-accela/ftnoir_filter_accela_dialog.cpp b/filter-accela/ftnoir_filter_accela_dialog.cpp index 594d04fd..b861f7be 100644 --- a/filter-accela/ftnoir_filter_accela_dialog.cpp +++ b/filter-accela/ftnoir_filter_accela_dialog.cpp @@ -20,26 +20,26 @@ FilterControls::FilterControls() connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); - connect(ui.rotation_slider, SIGNAL(valueChanged(int)), this, SLOT(update_rot_display(int))); - connect(ui.translation_slider, SIGNAL(valueChanged(int)), this, SLOT(update_trans_display(int))); - connect(ui.ewma_slider, SIGNAL(valueChanged(int)), this, SLOT(update_ewma_display(int))); - connect(ui.rot_dz_slider, SIGNAL(valueChanged(int)), this, SLOT(update_rot_dz_display(int))); - connect(ui.trans_dz_slider, SIGNAL(valueChanged(int)), this, SLOT(update_trans_dz_display(int))); + connect(&s.rot_sensitivity, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_rot_display(const slider_value&))); + connect(&s.trans_sensitivity, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_trans_display(const slider_value&))); + connect(&s.ewma, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_ewma_display(const slider_value&))); + connect(&s.rot_deadzone, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_rot_dz_display(const slider_value&))); + connect(&s.trans_deadzone, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_trans_dz_display(const slider_value&))); connect(&s.rot_nonlinearity, SIGNAL(valueChanged(const slider_value&)), this, SLOT(update_rot_nl_slider(const slider_value&))); - tie_setting(s.rot_threshold, ui.rotation_slider); - tie_setting(s.trans_threshold, ui.translation_slider); + tie_setting(s.rot_sensitivity, ui.rotation_slider); + tie_setting(s.trans_sensitivity, ui.translation_slider); tie_setting(s.ewma, ui.ewma_slider); tie_setting(s.rot_deadzone, ui.rot_dz_slider); tie_setting(s.trans_deadzone, ui.trans_dz_slider); tie_setting(s.rot_nonlinearity, ui.rot_nl_slider); - update_rot_display(ui.rotation_slider->value()); - update_trans_display(ui.translation_slider->value()); - update_ewma_display(ui.ewma_slider->value()); - update_rot_dz_display(ui.rot_dz_slider->value()); - update_trans_dz_display(ui.trans_dz_slider->value()); + update_rot_display(s.rot_sensitivity); + update_trans_display(s.trans_sensitivity); + update_ewma_display(s.ewma); + update_rot_dz_display(s.rot_deadzone); + update_trans_dz_display(s.trans_deadzone); update_rot_nl_slider(s.rot_nonlinearity); { @@ -87,29 +87,29 @@ void FilterControls::save() s.b->save(); } -void FilterControls::update_rot_display(int value) +void FilterControls::update_rot_display(const slider_value& val) { - ui.rot_gain->setText(QString::number((value + 1) * s.mult_rot) + "°"); + ui.rot_gain->setText(QString::number(val.cur()) + "°"); } -void FilterControls::update_trans_display(int value) +void FilterControls::update_trans_display(const slider_value& val) { - ui.trans_gain->setText(QString::number((value + 1) * s.mult_trans) + "mm"); + ui.trans_gain->setText(QString::number(val.cur()) + "mm"); } -void FilterControls::update_ewma_display(int value) +void FilterControls::update_ewma_display(const slider_value& val) { - ui.ewma_label->setText(QString::number(value * s.mult_ewma) + "ms"); + ui.ewma_label->setText(QString::number(val.cur()) + "ms"); } -void FilterControls::update_rot_dz_display(int value) +void FilterControls::update_rot_dz_display(const slider_value& val) { - ui.rot_dz->setText(QString::number(value * s.mult_rot_dz) + "°"); + ui.rot_dz->setText(QString::number(val.cur()) + "°"); } -void FilterControls::update_trans_dz_display(int value) +void FilterControls::update_trans_dz_display(const slider_value& val) { - ui.trans_dz->setText(QString::number(value * s.mult_trans_dz) + "mm"); + ui.trans_dz->setText(QString::number(val.cur()) + "mm"); } void FilterControls::update_rot_nl_slider(const slider_value& sl) |