From 9b4556c59f063e5c6816338c1608b354e1441fb0 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 9 Sep 2020 19:56:54 -0700 Subject: Add improved logarithm style --- common/accel-logarithm.hpp | 33 +++++++++++++++++++++++++++++++++ common/common.vcxitems | 1 + common/rawaccel-settings.h | 2 +- common/rawaccel.hpp | 3 +++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 common/accel-logarithm.hpp (limited to 'common') diff --git a/common/accel-logarithm.hpp b/common/accel-logarithm.hpp new file mode 100644 index 0000000..0dbf433 --- /dev/null +++ b/common/accel-logarithm.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include "accel-base.hpp" + +namespace rawaccel { + + /// Struct to hold sigmoid (s-shaped) gain implementation. + struct logarithm_impl { + double rate; + double offset; + double additive_const; + + logarithm_impl (const accel_args& args) : + rate(args.rate), offset (args.offset) { + additive_const = offset * rate; + } + + inline double operator()(double speed) const { + //f(x) = k/(1+e^(-m(c-x))) + double scaled_speed = rate * speed + 1; + double base_speed = speed + offset; + + return (scaled_speed * log(scaled_speed) + additive_const ) / ( rate * base_speed) - 1; + } + + inline double legacy_offset(double speed) const { return operator()(speed); } + }; + + using accel_logarithm = additive_accel; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index 2913080..fcd3ae8 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -17,6 +17,7 @@ + diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index 12f136d..8c483eb 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -6,7 +6,7 @@ namespace rawaccel { enum class accel_mode { - linear, classic, natural, naturalgain, sigmoidgain, power, noaccel + linear, classic, natural, naturalgain, sigmoidgain, power, logarithm, noaccel }; struct settings { diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 08ac322..8819302 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -8,6 +8,7 @@ #include "accel-linear.hpp" #include "accel-classic.hpp" +#include "accel-logarithm.hpp" #include "accel-natural.hpp" #include "accel-naturalgain.hpp" #include "accel-power.hpp" @@ -84,6 +85,7 @@ namespace rawaccel { case accel_mode::naturalgain: return vis(var.u.naturalgain); case accel_mode::sigmoidgain: return vis(var.u.sigmoidgain); case accel_mode::power: return vis(var.u.power); + case accel_mode::logarithm: return vis(var.u.logarithm); default: return vis(var.u.noaccel); } } @@ -98,6 +100,7 @@ namespace rawaccel { accel_naturalgain naturalgain; accel_sigmoidgain sigmoidgain; accel_power power; + accel_logarithm logarithm; accel_noaccel noaccel = {}; } u = {}; -- cgit v1.2.3 From 3953ba0d5f4f30f9eed0c94a15c98dd5ba7cd43b Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 9 Sep 2020 19:57:28 -0700 Subject: Remove misleading comment --- common/accel-logarithm.hpp | 1 - 1 file changed, 1 deletion(-) (limited to 'common') diff --git a/common/accel-logarithm.hpp b/common/accel-logarithm.hpp index 0dbf433..044d23c 100644 --- a/common/accel-logarithm.hpp +++ b/common/accel-logarithm.hpp @@ -18,7 +18,6 @@ namespace rawaccel { } inline double operator()(double speed) const { - //f(x) = k/(1+e^(-m(c-x))) double scaled_speed = rate * speed + 1; double base_speed = speed + offset; -- cgit v1.2.3 From 47730d5fcc629e7ffb93fdee1568aa846bc4c887 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 9 Sep 2020 20:05:19 -0700 Subject: Fix weight --- common/accel-base.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'common') diff --git a/common/accel-base.hpp b/common/accel-base.hpp index 714162f..d536923 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -40,7 +40,7 @@ namespace rawaccel { inline double operator()(double speed) const { double offset_speed = speed - offset; - return offset_speed > 0 ? ( legacy_offset ? 1 + fn.legacy_offset(offset_speed) * weight : 1 + fn(offset_speed) ) : 1; + return offset_speed > 0 ? ( legacy_offset ? 1 + fn.legacy_offset(offset_speed) * weight : 1 + fn(offset_speed) * weight) : 1; } }; -- cgit v1.2.3