summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-09-03 13:21:45 -0700
committerJacob Palecki <[email protected]>2020-09-03 13:21:45 -0700
commitc7e9641e8688c82874dbfa067f7dc8cb4d40e23d (patch)
treef621b568c8fac71126829f8db1bc72808ab4e059
parentStart adding gain offsets (diff)
downloadrawaccel-c7e9641e8688c82874dbfa067f7dc8cb4d40e23d.tar.xz
rawaccel-c7e9641e8688c82874dbfa067f7dc8cb4d40e23d.zip
Change classic, natural, naturalgain to use gain offset
-rw-r--r--common/accel-classic.hpp12
-rw-r--r--common/accel-natural.hpp6
-rw-r--r--common/accel-naturalgain.hpp3
3 files changed, 15 insertions, 6 deletions
diff --git a/common/accel-classic.hpp b/common/accel-classic.hpp
index 4cc52ca..3f409c3 100644
--- a/common/accel-classic.hpp
+++ b/common/accel-classic.hpp
@@ -10,14 +10,20 @@ namespace rawaccel {
struct classic_impl {
double accel;
double power;
+ double power_inc;
+ double offset;
+ double multiplicative_const;
classic_impl(const accel_args& args) :
- accel(args.accel), power(args.exponent - 1)
- {}
+ accel(args.accel), power(args.exponent - 1), offset(args.offset) {
+ multiplicative_const = pow(accel, power);
+ power_inc = power + 1;
+ }
inline double operator()(double speed) const {
//f(x) = (mx)^(k-1)
- return pow(accel * speed, power);
+ double base_speed = speed + offset;
+ return multiplicative_const * pow(speed, power_inc) / base_speed;
}
};
diff --git a/common/accel-natural.hpp b/common/accel-natural.hpp
index c7d0dcd..32bc365 100644
--- a/common/accel-natural.hpp
+++ b/common/accel-natural.hpp
@@ -10,16 +10,18 @@ namespace rawaccel {
struct natural_impl {
double rate;
double limit;
+ double offset;
natural_impl(const accel_args& args) :
- rate(args.accel), limit(args.limit - 1)
+ rate(args.accel), limit(args.limit - 1), offset(args.offset)
{
rate /= limit;
}
inline double operator()(double speed) const {
// f(x) = k(1-e^(-mx))
- return limit - (limit * exp(-rate * speed));
+ double base_speed = speed + offset;
+ return limit * (1 - ((exp(-rate * speed) * speed + offset) / base_speed));
}
};
diff --git a/common/accel-naturalgain.hpp b/common/accel-naturalgain.hpp
index 03d749f..5979d92 100644
--- a/common/accel-naturalgain.hpp
+++ b/common/accel-naturalgain.hpp
@@ -18,8 +18,9 @@ namespace rawaccel {
return 0;
}
+ double base_speed = speed + offset;
double scaled_speed = rate * speed;
- return limit * (((exp(-scaled_speed) - 1) / scaled_speed) + 1);
+ return limit * (((exp(-scaled_speed) - 1) / (base_speed * rate) ) + 1 - offset / base_speed);
}
};