diff options
| author | JacobPalecki <[email protected]> | 2020-08-31 23:03:46 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-08-31 23:03:46 -0700 |
| commit | 471fe599bab6ba0632ddd1dacd20c7fc42db0eee (patch) | |
| tree | 90a82ee14dbb112621657efbd2523ed35f59d154 /common/accel-sigmoid.hpp | |
| parent | Merge pull request #16 from JacobPalecki/Misc (diff) | |
| parent | add independent xy accel to driver (diff) | |
| download | rawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.tar.xz rawaccel-471fe599bab6ba0632ddd1dacd20c7fc42db0eee.zip | |
Merge pull request #17 from a1xd/indep
Indep
Diffstat (limited to 'common/accel-sigmoid.hpp')
| -rw-r--r-- | common/accel-sigmoid.hpp | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/common/accel-sigmoid.hpp b/common/accel-sigmoid.hpp index dc2066d..c8112ee 100644 --- a/common/accel-sigmoid.hpp +++ b/common/accel-sigmoid.hpp @@ -7,26 +7,22 @@ namespace rawaccel { /// <summary> Struct to hold sigmoid (s-shaped) acceleration implementation. </summary> - struct accel_sigmoid : accel_base { - double limit = 1; - double midpoint = 0; + struct sigmoid_impl { + double rate; + double limit; + double midpoint; - accel_sigmoid(const accel_args& args) : accel_base(args) { - verify(args); + sigmoid_impl(const accel_args& args) : + rate(args.accel), limit(args.limit - 1), midpoint(args.midpoint) + {} - limit = args.limit - 1; - midpoint = args.midpoint; - } - - inline double accelerate(double speed) const { + inline double operator()(double speed) const { //f(x) = k/(1+e^(-m(x-c))) - return limit / (exp(-speed_coeff * (speed - midpoint)) + 1); + return limit / (exp(-rate * (speed - midpoint)) + 1); } - 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"); - } }; + using accel_sigmoid = additive_accel<sigmoid_impl>; + } |