summaryrefslogtreecommitdiff
path: root/common/accel-logarithm.hpp
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-09-09 19:56:54 -0700
committerJacob Palecki <[email protected]>2020-09-09 19:56:54 -0700
commit9b4556c59f063e5c6816338c1608b354e1441fb0 (patch)
tree5232bf3bf9c3f0c75569a2f3a03262931e71e9bc /common/accel-logarithm.hpp
parentFurther work on guide (diff)
downloadrawaccel-9b4556c59f063e5c6816338c1608b354e1441fb0.tar.xz
rawaccel-9b4556c59f063e5c6816338c1608b354e1441fb0.zip
Add improved logarithm style
Diffstat (limited to 'common/accel-logarithm.hpp')
-rw-r--r--common/accel-logarithm.hpp33
1 files changed, 33 insertions, 0 deletions
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 <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary>
+ 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<logarithm_impl>;
+
+}