summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-08-22 22:33:45 -0400
committerGitHub <[email protected]>2020-08-22 22:33:45 -0400
commit252637e53ca42353061dc3118e8625af6edc348f (patch)
tree26ea73edae996242eaef559485309fb9c66f4d30 /common
parentMerge pull request #15 from JacobPalecki/GUI (diff)
parentdelete personal settings.json left in repo (diff)
downloadrawaccel-252637e53ca42353061dc3118e8625af6edc348f.tar.xz
rawaccel-252637e53ca42353061dc3118e8625af6edc348f.zip
Merge pull request #16 from JacobPalecki/Misc
Gain Styles, Settings File, and other miscellaneous
Diffstat (limited to 'common')
-rw-r--r--common/accel-base.hpp2
-rw-r--r--common/accel-naturalgain.hpp32
-rw-r--r--common/accel-sigmoid.hpp2
-rw-r--r--common/accel-sigmoidgain.hpp37
-rw-r--r--common/common.vcxitems2
-rw-r--r--common/rawaccel.hpp7
6 files changed, 79 insertions, 3 deletions
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 {
/// <summary> Coefficients applied to acceleration per axis.</summary>
vec2d weight = { 1, 1 };
- /// <summary> Generally, the acceleration ramp rate.
+ /// <summary> Generally, the acceleration ramp rate.</summary>
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 <math.h>
+
+#include "accel-base.hpp"
+
+namespace rawaccel {
+
+ /// <summary> Struct to hold "natural" (vanishing difference) gain implementation. </summary>
+ 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/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 <math.h>
+
+#include "accel-base.hpp"
+
+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);
+ 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 9696ac6..2e9265c 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -19,9 +19,11 @@
<ClInclude Include="$(MSBuildThisFileDirectory)accel-linear.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-logarithmic.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-natural.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-naturalgain.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-noaccel.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-power.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoid.hpp" />
+ <ClInclude Include="$(MSBuildThisFileDirectory)accel-sigmoidgain.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-error.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel-io.hpp" />
<ClInclude Include="$(MSBuildThisFileDirectory)rawaccel.hpp" />
diff --git a/common/rawaccel.hpp b/common/rawaccel.hpp
index 8dc4825..23a8214 100644
--- a/common/rawaccel.hpp
+++ b/common/rawaccel.hpp
@@ -9,8 +9,10 @@
#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-sigmoidgain.hpp"
#include "accel-power.hpp"
#include "accel-noaccel.hpp"
@@ -76,7 +78,7 @@ namespace rawaccel {
};
/// <summary> Tagged union to hold all accel implementations and allow "polymorphism" via a visitor call. </summary>
- using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_noaccel>;
+ using accel_impl_t = tagged_union<accel_linear, accel_classic, accel_natural, accel_logarithmic, accel_sigmoid, accel_power, accel_naturalgain, accel_sigmoidgain, accel_noaccel>;
/// <summary> Struct to hold information about applying a gain cap. </summary>
struct velocity_gain_cap {
@@ -183,6 +185,8 @@ namespace rawaccel {
vec2<accel_scale_clamp> 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");
@@ -190,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;