From 0c00c91391f2190eb7615bc7bed2096e2b7ea9d9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 30 Jul 2016 12:03:58 +0200 Subject: filter/accela: add rotation nonlinearity switch This only applies to very beginning of gain spline. --- filter-accela/ftnoir_accela_filtercontrols.ui | 156 +++++++++++++++++--------- filter-accela/ftnoir_filter_accela.cpp | 31 +++-- filter-accela/ftnoir_filter_accela.h | 6 +- filter-accela/ftnoir_filter_accela_dialog.cpp | 43 +++++-- 4 files changed, 155 insertions(+), 81 deletions(-) diff --git a/filter-accela/ftnoir_accela_filtercontrols.ui b/filter-accela/ftnoir_accela_filtercontrols.ui index be14f842..86ca57b1 100644 --- a/filter-accela/ftnoir_accela_filtercontrols.ui +++ b/filter-accela/ftnoir_accela_filtercontrols.ui @@ -9,8 +9,8 @@ 0 0 - 657 - 358 + 558 + 411 @@ -24,6 +24,64 @@ 5 + + + + + 0 + 0 + + + + + 7 + + + + QFrame::NoFrame + + + <html><head/><body><p align="right"><br/><span style=" font-size:10pt;">Accela by </span><a href="https://github.com/sthalik"><span style=" font-size:10pt; text-decoration: underline; color:#0057ae;">Stanisław Halik</span></a><span style=" font-size:10pt;"><br/>Thanks to </span><a href="https://github.com/dbaarda"><span style=" font-size:10pt; text-decoration: underline; color:#0057ae;">Donovan Baarda</span></a></p><p align="right"><span style=" font-size:10pt;">2012-2015</span></p><p align="right"><br/><span style=" font-size:8pt;">Visit </span><a href="https://github.com/opentrack/opentrack/wiki/Accela-in-opentrack-2.3"><span style=" font-size:8pt; text-decoration: underline; color:#0000ff;">our wiki</span></a><span style=" font-size:8pt;"> for description of the settings.</span></p></body></html> + + + Qt::RichText + + + false + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + true + + + 0 + + + 0 + + + true + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + + + + + + 0 + 0 + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + @@ -280,61 +338,47 @@ - - - - 0 - 0 - - - - - 7 - - - - QFrame::NoFrame - - - <html><head/><body><p align="right"><br/><span style=" font-size:10pt;">Accela by </span><a href="https://github.com/sthalik"><span style=" font-size:10pt; text-decoration: underline; color:#0057ae;">Stanisław Halik</span></a><span style=" font-size:10pt;"><br/>Thanks to </span><a href="https://github.com/dbaarda"><span style=" font-size:10pt; text-decoration: underline; color:#0057ae;">Donovan Baarda</span></a></p><p align="right"><span style=" font-size:10pt;">2012-2015</span></p><p align="right"><br/><span style=" font-size:8pt;">Visit </span><a href="https://github.com/opentrack/opentrack/wiki/Accela-in-opentrack-2.3"><span style=" font-size:8pt; text-decoration: underline; color:#0000ff;">our wiki</span></a><span style=" font-size:8pt;"> for description of the settings.</span></p></body></html> - - - Qt::RichText - - - false - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - 0 - - - 0 - - - true - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - - - - - - 0 - 0 - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + Rotation nonlinearity + + + + + 134 + + + Qt::Horizontal + + + + + + + + 50 + 0 + + + + + 10 + + + + <html><head/><body><p>x<span style=" vertical-align:super;">2</span></p></body></html> + + + + + + + Value + + + + diff --git a/filter-accela/ftnoir_filter_accela.cpp b/filter-accela/ftnoir_filter_accela.cpp index fe5aad86..11cb1aab 100644 --- a/filter-accela/ftnoir_filter_accela.cpp +++ b/filter-accela/ftnoir_filter_accela.cpp @@ -12,27 +12,28 @@ #include "opentrack/plugin-api.hpp" static constexpr double rot_gains[][2] = { - { 4.0, 350 }, + { 5, 350 }, //{ 3.33, 200 }, { 2.66, 110 }, //{ 2.33, 85 }, - //{ 2, 45 }, - { 1.66, 30 }, - //{ 1.33, 15 }, + { 2, 45 }, + //{ 1.66, 30 }, { 1, 5 }, - { .66, 1.4 }, - { .33, .4 }, + //{ .66, 1.3 }, + //{ .5, .53 }, + //{ .33, .25 }, + { .22, .16 }, { 0, 0 }, { -1, 0 } }; static constexpr double trans_gains[][2] = { //{ 3, 200 }, - { 1.66, 40 }, - { 1.33, 15 }, - { 1, 5 }, + { 2.33, 40 }, + { 1.66, 13 }, + { 1.33, 5 }, { .66, 1 }, - { .33, .6 }, + { .33, .5 }, { 0, 0 }, { -1, 0 } }; @@ -86,6 +87,7 @@ void FTNoIR_Filter::filter(const double* input, double *output) 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(s.rot_nonlinearity).cur(); for (int i = 0; i < 6; i++) { @@ -99,8 +101,13 @@ void FTNoIR_Filter::filter(const double* input, double *output) const double dz = i >= 3 ? rot_dz : trans_dz; const double vec_ = std::max(0., fabs(vec) - dz); const double thres = i >= 3 ? rot_t : trans_t; - const double val = m.getValue(vec_ / thres); - const double result = last_output[i] + (vec < 0 ? -1 : 1) * dt * val; + const double out_ = vec_ / thres; + const double out = i >= 3 && std::fabs(s.max_rot_nl - 1) > 5e-3 + ? (out_ * std::min(1., std::pow(out_/s.max_rot_nl, rot_nl)) * s.max_rot_nl) + : out_; + const double val = m.getValue(float(out)); + const double signum = int(vec < 0) * -2 + 1; + const double result = last_output[i] + signum * dt * val; last_output[i] = output[i] = result; } diff --git a/filter-accela/ftnoir_filter_accela.h b/filter-accela/ftnoir_filter_accela.h index 113e06e6..69db54cd 100644 --- a/filter-accela/ftnoir_filter_accela.h +++ b/filter-accela/ftnoir_filter_accela.h @@ -18,18 +18,21 @@ using namespace options; struct settings_accela : opts { value rot_threshold, trans_threshold, ewma, rot_deadzone, trans_deadzone; + 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) + trans_deadzone(b, "translation-deadzone", 0), + rot_nonlinearity(b, "rotation-nonlinearity", slider_value(1., .66, 2)) {} }; @@ -68,6 +71,7 @@ private slots: void update_trans_display(int value); void update_rot_dz_display(int value); void update_trans_dz_display(int value); + void update_rot_nl_slider(const slider_value& sl); }; class FTNoIR_FilterDll : public Metadata diff --git a/filter-accela/ftnoir_filter_accela_dialog.cpp b/filter-accela/ftnoir_filter_accela_dialog.cpp index 451f476e..c046f986 100644 --- a/filter-accela/ftnoir_filter_accela_dialog.cpp +++ b/filter-accela/ftnoir_filter_accela_dialog.cpp @@ -16,7 +16,7 @@ FilterControls::FilterControls() : accela_filter(nullptr) { - ui.setupUi( this ); + ui.setupUi(this); connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(doOK())); connect(ui.buttonBox, SIGNAL(rejected()), this, SLOT(doCancel())); @@ -26,6 +26,7 @@ FilterControls::FilterControls() : 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_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); @@ -33,24 +34,32 @@ FilterControls::FilterControls() : 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_nl_slider(s.rot_nonlinearity); } void FilterControls::register_filter(IFilter* filter) { accela_filter = static_cast(filter); -//#define LEAKING_DEBUG -#ifdef LEAKING_DEBUG - auto d = new QDialog(); - auto r = new QFunctionConfigurator(d); - r->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); - r->setConfig(&accela_filter->rot, ""); - r->setFixedSize(800, 300); - d->show(); +//#define SPLINE_ROT_DEBUG +#if defined(SPLINE_ROT_DEBUG) || defined(SPLINE_TRANS_DEBUG) + QDialog d; + QFunctionConfigurator r(&d); + r.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); +#if defined(SPLINE_TRANS_DEBUG) + r.setConfig(&accela_filter->trans, ""); +#else + r.setConfig(&accela_filter->rot, ""); +#endif + r.setFixedSize(800, 300); + d.show(); + d.exec(); #endif } @@ -59,16 +68,19 @@ void FilterControls::unregister_filter() accela_filter = nullptr; } -void FilterControls::doOK() { +void FilterControls::doOK() +{ save(); close(); } -void FilterControls::doCancel() { +void FilterControls::doCancel() +{ close(); } -void FilterControls::save() { +void FilterControls::save() +{ s.b->save(); } @@ -97,3 +109,10 @@ void FilterControls::update_trans_dz_display(int value) ui.trans_dz->setText(QString::number(value * s.mult_trans_dz) + "mm"); } +void FilterControls::update_rot_nl_slider(const slider_value& sl) +{ + ui.rot_nl->setText("

x" + + QString::number(sl.cur()) + + "

"); +} + -- cgit v1.2.3