summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-08-20 00:32:11 -0700
committerJacob Palecki <[email protected]>2020-08-20 00:32:11 -0700
commit3dd0bb9163380de64d0df4f0b5c16dd86979714e (patch)
treee5cb12562df1a3e24ba47759813bbbc502aaf381
parentAdd natural gain accel; add scale by DPI, poll rate in GUI (diff)
downloadrawaccel-3dd0bb9163380de64d0df4f0b5c16dd86979714e.tar.xz
rawaccel-3dd0bb9163380de64d0df4f0b5c16dd86979714e.zip
Sigmoid gain
-rw-r--r--common/accel-sigmoid.hpp2
-rw-r--r--common/accel-sigmoidgain.hpp37
-rw-r--r--common/common.vcxitems1
-rw-r--r--common/rawaccel.hpp3
-rw-r--r--grapher/Layouts/OffLayout.cs2
-rw-r--r--grapher/Layouts/SigmoidGainLayout.cs20
-rw-r--r--grapher/Models/Options/AccelOptions.cs1
-rw-r--r--grapher/grapher.csproj1
8 files changed, 64 insertions, 3 deletions
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 0471b5f..2e9265c 100644
--- a/common/common.vcxitems
+++ b/common/common.vcxitems
@@ -23,6 +23,7 @@
<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 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 {
};
/// <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_naturalgain, 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 {
diff --git a/grapher/Layouts/OffLayout.cs b/grapher/Layouts/OffLayout.cs
index 55f44b7..087885f 100644
--- a/grapher/Layouts/OffLayout.cs
+++ b/grapher/Layouts/OffLayout.cs
@@ -12,7 +12,7 @@ namespace grapher.Layouts
: base()
{
Name = "Off";
- Index = 8;
+ Index = 9;
ShowOptions = new bool[] { false, false, false, false };
OptionNames = new string[] { string.Empty, string.Empty, string.Empty, string.Empty };
ShowOptionsXY = new bool[] { false, false };
diff --git a/grapher/Layouts/SigmoidGainLayout.cs b/grapher/Layouts/SigmoidGainLayout.cs
new file mode 100644
index 0000000..c620925
--- /dev/null
+++ b/grapher/Layouts/SigmoidGainLayout.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class SigmoidGainLayout : LayoutBase
+ {
+ public SigmoidGainLayout()
+ : base()
+ {
+ Name = "SigmoidGain";
+ Index = 8;
+ ShowOptions = new bool[] { true, true, true, true };
+ OptionNames = new string[] { Offset, Acceleration, Limit, Midpoint };
+ }
+ }
+}
diff --git a/grapher/Models/Options/AccelOptions.cs b/grapher/Models/Options/AccelOptions.cs
index 03d6ff6..8da873f 100644
--- a/grapher/Models/Options/AccelOptions.cs
+++ b/grapher/Models/Options/AccelOptions.cs
@@ -23,6 +23,7 @@ namespace grapher
new SigmoidLayout(),
new PowerLayout(),
new NaturalGainLayout(),
+ new SigmoidGainLayout(),
new OffLayout()
}.ToDictionary(k => k.Name);
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index cc7a8b4..2d9f4ab 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -48,6 +48,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Layouts\NaturalGainLayout.cs" />
+ <Compile Include="Layouts\SigmoidGainLayout.cs" />
<Compile Include="Models\Calculations\AccelCalculator.cs" />
<Compile Include="Models\Calculations\AccelChartData.cs" />
<Compile Include="Models\Calculations\AccelData.cs" />