From 53c9025337166a408febc15078af3e9b136b3bab Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Wed, 19 Aug 2020 15:26:25 -0700 Subject: Add natural gain accel; add scale by DPI, poll rate in GUI --- common/accel-base.hpp | 2 +- common/accel-naturalgain.hpp | 32 ++++++++++++++++++++++++++++++++ common/common.vcxitems | 1 + common/rawaccel.hpp | 3 ++- 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 common/accel-naturalgain.hpp (limited to 'common') diff --git a/common/accel-base.hpp b/common/accel-base.hpp index 60b7362..f280e3e 100644 --- a/common/accel-base.hpp +++ b/common/accel-base.hpp @@ -36,7 +36,7 @@ namespace rawaccel { /// Coefficients applied to acceleration per axis. vec2d weight = { 1, 1 }; - /// Generally, the acceleration ramp rate. + /// Generally, the acceleration ramp rate. double speed_coeff = 0; accel_base(const accel_args& args) { diff --git a/common/accel-naturalgain.hpp b/common/accel-naturalgain.hpp new file mode 100644 index 0000000..95c0be2 --- /dev/null +++ b/common/accel-naturalgain.hpp @@ -0,0 +1,32 @@ +#pragma once + +#include + +#include "accel-base.hpp" + +namespace rawaccel { + + /// Struct to hold "natural" (vanishing difference) gain implementation. + struct accel_naturalgain : accel_base { + double limit = 1; + double midpoint = 0; + + accel_naturalgain(const accel_args& args) : accel_base(args) { + verify(args); + + limit = args.limit - 1; + speed_coeff /= limit; + } + + inline double accelerate(double speed) const { + // f(x) = k((e^(-mx)-1)/mx + 1) + double scaled_speed = speed_coeff * speed; + return limit * (((exp(-scaled_speed) - 1) / scaled_speed) + 1); + } + + void verify(const accel_args& args) const { + if (args.limit <= 1) bad_arg("limit must be greater than 1"); + } + }; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index 9696ac6..0471b5f 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -19,6 +19,7 @@ + diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 8dc4825..37418cd 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -9,6 +9,7 @@ #include "accel-linear.hpp" #include "accel-classic.hpp" #include "accel-natural.hpp" +#include "accel-naturalgain.hpp" #include "accel-logarithmic.hpp" #include "accel-sigmoid.hpp" #include "accel-power.hpp" @@ -76,7 +77,7 @@ namespace rawaccel { }; /// Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. - using accel_impl_t = tagged_union; + using accel_impl_t = tagged_union; /// Struct to hold information about applying a gain cap. struct velocity_gain_cap { -- cgit v1.2.3 From 3dd0bb9163380de64d0df4f0b5c16dd86979714e Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 20 Aug 2020 00:32:11 -0700 Subject: Sigmoid gain --- common/accel-sigmoid.hpp | 2 +- common/accel-sigmoidgain.hpp | 37 +++++++++++++++++++++++++++++++++++++ common/common.vcxitems | 1 + common/rawaccel.hpp | 3 ++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 common/accel-sigmoidgain.hpp (limited to 'common') diff --git a/common/accel-sigmoid.hpp b/common/accel-sigmoid.hpp index 5bbe58f..dc2066d 100644 --- a/common/accel-sigmoid.hpp +++ b/common/accel-sigmoid.hpp @@ -19,7 +19,7 @@ namespace rawaccel { } inline double accelerate(double speed) const { - //f(x) = k/(1+e^(-m(c-x))) + //f(x) = k/(1+e^(-m(x-c))) return limit / (exp(-speed_coeff * (speed - midpoint)) + 1); } diff --git a/common/accel-sigmoidgain.hpp b/common/accel-sigmoidgain.hpp new file mode 100644 index 0000000..0a2e54d --- /dev/null +++ b/common/accel-sigmoidgain.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include + +#include "accel-base.hpp" + +namespace rawaccel { + + /// Struct to hold sigmoid (s-shaped) gain implementation. + 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); + integration_constant = log(1 + additive_constant); + } + + inline double accelerate(double speed) const { + //f(x) = k/(1+e^(-m(c-x))) + double scaled_speed = speed_coeff * 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"); + } + }; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index 0471b5f..2e9265c 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -23,6 +23,7 @@ + diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 37418cd..7e72f20 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -12,6 +12,7 @@ #include "accel-naturalgain.hpp" #include "accel-logarithmic.hpp" #include "accel-sigmoid.hpp" +#include "accel-sigmoidgain.hpp" #include "accel-power.hpp" #include "accel-noaccel.hpp" @@ -77,7 +78,7 @@ namespace rawaccel { }; /// Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. - using accel_impl_t = tagged_union; + using accel_impl_t = tagged_union; /// Struct to hold information about applying a gain cap. struct velocity_gain_cap { -- cgit v1.2.3 From fe17d04e571d180e663c7014e803ce790693f4b1 Mon Sep 17 00:00:00 2001 From: Jacob Palecki Date: Thu, 20 Aug 2020 12:51:33 -0700 Subject: Display active values --- common/rawaccel.hpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'common') diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 7e72f20..23a8214 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -185,6 +185,8 @@ namespace rawaccel { vec2 clamp; velocity_gain_cap gain_cap = velocity_gain_cap(); + + accel_args impl_args; accel_function(const accel_fn_args& args) { if (args.time_min <= 0) bad_arg("min time must be positive"); @@ -192,6 +194,7 @@ namespace rawaccel { accel.tag = args.accel_mode; accel.visit([&](auto& impl) { impl = { args.acc_args }; }); + impl_args = args.acc_args; time_min = args.time_min; speed_offset = args.acc_args.offset; -- cgit v1.2.3