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-sigmoidgain.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-sigmoidgain.hpp')
| -rw-r--r-- | common/accel-sigmoidgain.hpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/common/accel-sigmoidgain.hpp b/common/accel-sigmoidgain.hpp index 0a2e54d..99bb146 100644 --- a/common/accel-sigmoidgain.hpp +++ b/common/accel-sigmoidgain.hpp @@ -7,31 +7,27 @@ 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); + struct sigmoidgain_impl { + double rate; + double limit; + double additive_constant; + double integration_constant; + + sigmoidgain_impl(const accel_args& args) : + rate(args.rate), limit(args.limit - 1) + { + additive_constant = exp(rate * args.midpoint); integration_constant = log(1 + additive_constant); } - inline double accelerate(double speed) const { + inline double operator()(double speed) const { //f(x) = k/(1+e^(-m(c-x))) - double scaled_speed = speed_coeff * speed; + double scaled_speed = rate * 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"); - } }; + using accel_sigmoidgain = additive_accel<sigmoidgain_impl>; + } |