summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-08-20 00:32:11 -0700
committerJacob Palecki <[email protected]>2020-08-20 00:32:11 -0700
commit3dd0bb9163380de64d0df4f0b5c16dd86979714e (patch)
treee5cb12562df1a3e24ba47759813bbbc502aaf381 /common
parentAdd natural gain accel; add scale by DPI, poll rate in GUI (diff)
downloadrawaccel-3dd0bb9163380de64d0df4f0b5c16dd86979714e.tar.xz
rawaccel-3dd0bb9163380de64d0df4f0b5c16dd86979714e.zip
Sigmoid gain
Diffstat (limited to 'common')
-rw-r--r--common/accel-sigmoid.hpp2
-rw-r--r--common/accel-sigmoidgain.hpp37
-rw-r--r--common/common.vcxitems1
-rw-r--r--common/rawaccel.hpp3
4 files changed, 41 insertions, 2 deletions
diff --git a/common/accel-sigmoid.hpp b/common/accel-sigmoid.hpp
index 5bbe58f..dc2066d 100644
--- a/common/accel-sigmoid.hpp
+++ b/common/accel-sigmoid.hpp
@@ -19,7 +19,7 @@ namespace rawaccel {
}
inline double accelerate(double speed) const {
- //f(x) = k/(1+e^(-m(c-x)))
+ //f(x) = k/(1+e^(-m(x-c)))
return limit / (exp(-speed_coeff * (speed - midpoint)) + 1);
}
diff --git a/common/accel-sigmoidgain.hpp b/common/accel-sigmoidgain.hpp
new file mode 100644
index 0000000..0a2e54d
--- /dev/null
+++ b/common/accel-sigmoidgain.hpp
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary>
+ struct accel_sigmoidgain : accel_base {
+ double limit = 1;
+ double midpoint = 0;
+ double additive_constant = 0;
+ double integration_constant = 0;
+
+ accel_sigmoidgain(const accel_args& args) : accel_base(args) {
+ verify(args);
+
+ limit = args.limit - 1;
+ midpoint = args.midpoint;
+ additive_constant = exp(speed_coeff*midpoint);
+ integration_constant = log(1 + additive_constant);
+ }
+
+ inline double accelerate(double speed) const {
+ //f(x) = k/(1+e^(-m(c-x)))
+ double scaled_speed = speed_coeff * speed;
+ return limit * ((log(additive_constant+exp(scaled_speed)) - integration_constant)/scaled_speed);
+ }
+
+ void verify(const accel_args& args) const {
+ if (args.limit <= 1) bad_arg("exponent must be greater than 1");
+ if (args.midpoint < 0) bad_arg("midpoint must not be negative");
+ }
+ };
+
+}
diff --git a/common/common.vcxitems b/common/common.vcxitems
index 0471b5f..2e9265c 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -23,6 +23,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoid.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoidgain.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-error.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 37418cd..7e72f20 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -12,6 +12,7 @@
#include "accel-naturalgain.hpp"
#include "accel-logarithmic.hpp"
#include "accel-sigmoid.hpp"
+#include "accel-sigmoidgain.hpp"
#include "accel-power.hpp"
#include "accel-noaccel.hpp"
@@ -77,7 +78,7 @@ namespace rawaccel {
};
/// <summary> Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. </summary>
- using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_naturalgain, accel_noaccel>;
+ using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_naturalgain, accel_sigmoidgain, accel_noaccel>;
/// <summary> Struct to hold information about applying a gain cap. </summary>
struct velocity_gain_cap {