diff options
| author | Jacob Palecki <[email protected]> | 2020-09-21 14:26:04 -0700 |
|---|---|---|
| committer | Jacob Palecki <[email protected]> | 2020-09-21 14:26:04 -0700 |
| commit | e1acbaa344c2c571a9f7730afba6cd4fbd36ecf6 (patch) | |
| tree | 6ffdee3a16c7b5c89b6f12117e8a9b78b1112e6f /common | |
| parent | Merge pull request #21 from JacobPalecki/GUI (diff) | |
| parent | conditional around lookup map (diff) | |
| download | rawaccel-e1acbaa344c2c571a9f7730afba6cd4fbd36ecf6.tar.xz rawaccel-e1acbaa344c2c571a9f7730afba6cd4fbd36ecf6.zip | |
Merge remote-tracking branch 'downstream/experiment' into Experiment
Diffstat (limited to 'common')
| -rw-r--r-- | common/accel-experimentone.hpp | 33 | ||||
| -rw-r--r-- | common/accel-experimenttwo.hpp | 82 | ||||
| -rw-r--r-- | common/common.vcxitems | 2 | ||||
| -rw-r--r-- | common/rawaccel-settings.h | 2 | ||||
| -rw-r--r-- | common/rawaccel.hpp | 3 |
5 files changed, 121 insertions, 1 deletions
diff --git a/common/accel-experimentone.hpp b/common/accel-experimentone.hpp new file mode 100644 index 0000000..7d21b58 --- /dev/null +++ b/common/accel-experimentone.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +namespace rawaccel { + + /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary> + struct experimentone_impl { + double rate; + double limit; + double midpoint; + double subtractive_constant; + + experimentone_impl(const accel_args& args) : + rate(pow(10,args.rate)), limit(2*log10(args.limit)), midpoint(log10(args.midpoint)) + { + subtractive_constant = limit / 2; + } + + inline double operator()(double speed) const { + double log_speed = log10(speed); + return pow(10, limit / (exp(-rate * (log_speed - midpoint)) + 1) - subtractive_constant); + + } + + inline double legacy_offset(double speed) const { return operator()(speed); } + }; + + using accel_experimentone = nonadditive_accel<experimentone_impl>; + +} diff --git a/common/accel-experimenttwo.hpp b/common/accel-experimenttwo.hpp new file mode 100644 index 0000000..73428f7 --- /dev/null +++ b/common/accel-experimenttwo.hpp @@ -0,0 +1,82 @@ +#pragma once + +#include <math.h> + +#include "accel-base.hpp" + +namespace rawaccel { + + /// <summary> Struct to hold sigmoid (s-shaped) gain implementation. </summary> + struct experimenttwo_impl { + double rate; + double limit; + double midpoint; + double subtractive_constant; + + experimenttwo_impl(const accel_args& args) : + rate(pow(10,args.rate)), limit(2*log10(args.limit)), midpoint(log10(args.midpoint)) + { + subtractive_constant = limit / 2; + } + + inline double operator()(double speed) const { + double log_speed = log10(speed); + return pow(10, limit / (exp(-rate * (log_speed - midpoint)) + 1) - subtractive_constant); + + } + + inline double legacy_offset(double speed) const { return operator()(speed); } + + inline double apply(double* lookup, double speed) + { + int index = map(speed); + double slope = lookup[index]; + double intercept = lookup[index + 1]; + return slope + intercept / speed; + } + + inline int map(double speed) + { + int index = speed > 0 ? (int)floor(200*log10(speed)+402) : 0; + + if (index < 0) return 0; + if (index > 1200) return 1200; + + return index; + } + + inline double fill(double* lookup) + { + double lookup_speed = 0; + double gain_integral_speed = 0; + double gain = 0; + double intercept = 0; + double output = 0; + int index = 0; + + lookup[index] = gain; + lookup[index + 1] = intercept; + + for (double x = -2.0; x <= 4.0; x += 0.01) + { + index+=2; + lookup_speed = pow(10,x); + + while (gain_integral_speed < lookup_speed) + { + gain_integral_speed += 0.001; + gain = operator()(gain_integral_speed); + output += gain*0.001; + } + + intercept = gain * lookup_speed - output; + lookup[index] = gain; + lookup[index + 1] = intercept; + } + + } + }; + + using accel_experimentone = nonadditive_accel<experimenttwo_impl>; + +} diff --git a/common/common.vcxitems b/common/common.vcxitems index fcd3ae8..b5cd374 100644 --- a/common/common.vcxitems +++ b/common/common.vcxitems @@ -16,6 +16,8 @@ <ItemGroup> <ClInclude Include="$(MSBuildThisFileDirectory)accel-base.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-classic.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-experimentone.hpp" /> + <ClInclude Include="$(MSBuildThisFileDirectory)accel-experimenttwo.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-linear.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-logarithm.hpp" /> <ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" /> diff --git a/common/rawaccel-settings.h b/common/rawaccel-settings.h index 8c483eb..db5e192 100644 --- a/common/rawaccel-settings.h +++ b/common/rawaccel-settings.h @@ -6,7 +6,7 @@ namespace rawaccel { enum class accel_mode { - linear, classic, natural, naturalgain, sigmoidgain, power, logarithm, noaccel + linear, classic, natural, naturalgain, sigmoidgain, power, logarithm, experimentone, noaccel }; struct settings { diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp index 8819302..2914225 100644 --- a/common/rawaccel.hpp +++ b/common/rawaccel.hpp @@ -13,6 +13,7 @@ #include "accel-naturalgain.hpp" #include "accel-power.hpp" #include "accel-sigmoidgain.hpp" +#include "accel-experimentone.hpp" #include "accel-noaccel.hpp" namespace rawaccel { @@ -86,6 +87,7 @@ namespace rawaccel { case accel_mode::sigmoidgain: return vis(var.u.sigmoidgain); case accel_mode::power: return vis(var.u.power); case accel_mode::logarithm: return vis(var.u.logarithm); + case accel_mode::experimentone: return vis(var.u.experimentone); default: return vis(var.u.noaccel); } } @@ -101,6 +103,7 @@ namespace rawaccel { accel_sigmoidgain sigmoidgain; accel_power power; accel_logarithm logarithm; + accel_experimentone experimentone; accel_noaccel noaccel = {}; } u = {}; |