From 0b50f9c85568e5b8b6ee32e40990e39cfdf515b5 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 2 Sep 2020 21:13:18 -0700 Subject: Start adding gain offsets --- common/accel-linear.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'common/accel-linear.hpp') diff --git a/common/accel-linear.hpp b/common/accel-linear.hpp index a943594..95ba261 100644 --- a/common/accel-linear.hpp +++ b/common/accel-linear.hpp @@ -7,11 +7,18 @@ namespace rawaccel { /// Struct to hold linear acceleration implementation. struct linear_impl { double accel; + double offset; + double subtractive_const; + double divisive_const; - linear_impl(const accel_args& args) : accel(args.accel) {} + linear_impl(const accel_args& args) : accel(args.accel), offset(args.offset) { + subtractive_const = 2 * accel * offset; + divisive_const = accel * offset * offset; + } inline double operator()(double speed) const { - return accel * speed; + double base_speed = speed + offset; + return accel * base_speed - subtractive_const + divisive_const / base_speed; } }; -- cgit v1.2.3 From 01f870a493378a62ab76dcbf5dc37c0390ca7afe Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 3 Sep 2020 19:36:44 -0700 Subject: Refactor for nice gain offset --- common/accel-linear.hpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common/accel-linear.hpp') diff --git a/common/accel-linear.hpp b/common/accel-linear.hpp index 95ba261..2bd57b8 100644 --- a/common/accel-linear.hpp +++ b/common/accel-linear.hpp @@ -21,6 +21,9 @@ namespace rawaccel { return accel * base_speed - subtractive_const + divisive_const / base_speed; } + inline double legacy_offset(double speed) const { + return accel * speed; + } }; using accel_linear = additive_accel; -- cgit v1.2.3