summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Palecki <[email protected]>2020-09-21 14:26:04 -0700
committerJacob Palecki <[email protected]>2020-09-21 14:26:04 -0700
commite1acbaa344c2c571a9f7730afba6cd4fbd36ecf6 (patch)
tree6ffdee3a16c7b5c89b6f12117e8a9b78b1112e6f
parentMerge pull request #21 from JacobPalecki/GUI (diff)
parentconditional around lookup map (diff)
downloadrawaccel-e1acbaa344c2c571a9f7730afba6cd4fbd36ecf6.tar.xz
rawaccel-e1acbaa344c2c571a9f7730afba6cd4fbd36ecf6.zip
Merge remote-tracking branch 'downstream/experiment' into Experiment
-rw-r--r--common/accel-experimentone.hpp33
-rw-r--r--common/accel-experimenttwo.hpp82
-rw-r--r--common/common.vcxitems2
-rw-r--r--common/rawaccel-settings.h2
-rw-r--r--common/rawaccel.hpp3
-rw-r--r--grapher/Layouts/ExperimentOneLayout.cs26
-rw-r--r--grapher/Layouts/LayoutBase.cs1
-rw-r--r--grapher/Models/Calculations/AccelCalculator.cs1
-rw-r--r--grapher/Models/Options/AccelTypeOptions.cs1
-rw-r--r--grapher/Models/Serialized/DriverSettings.cs2
-rw-r--r--grapher/grapher.csproj1
11 files changed, 152 insertions, 2 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 = {};
diff --git a/grapher/Layouts/ExperimentOneLayout.cs b/grapher/Layouts/ExperimentOneLayout.cs
new file mode 100644
index 0000000..1853fbc
--- /dev/null
+++ b/grapher/Layouts/ExperimentOneLayout.cs
@@ -0,0 +1,26 @@
+using grapher.Models.Serialized;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace grapher.Layouts
+{
+ public class ExperimentOneLayout : LayoutBase
+ {
+ public ExperimentOneLayout()
+ : base()
+ {
+ Name = "Experiment 1";
+ Index = (int)AccelMode.experimentone;
+
+ AccelLayout = new OptionLayout(true, Acceleration);
+ CapLayout = new OptionLayout(false, string.Empty);
+ WeightLayout = new OptionLayout(true, Weight);
+ OffsetLayout = new OptionLayout(false, string.Empty);
+ LimExpLayout = new OptionLayout(true, Motility);
+ MidpointLayout = new OptionLayout(true, Midpoint);
+ }
+ }
+}
diff --git a/grapher/Layouts/LayoutBase.cs b/grapher/Layouts/LayoutBase.cs
index 6ed8fee..067ce44 100644
--- a/grapher/Layouts/LayoutBase.cs
+++ b/grapher/Layouts/LayoutBase.cs
@@ -10,6 +10,7 @@ namespace grapher.Layouts
public const string Exponent = "Exponent";
public const string Limit = "Limit";
public const string Midpoint = "Midpoint";
+ public const string Motility = "Motility";
public const string Offset = "Offset";
public const string Cap = "Cap";
public const string Weight = "Weight";
diff --git a/grapher/Models/Calculations/AccelCalculator.cs b/grapher/Models/Calculations/AccelCalculator.cs
index a140c90..8865939 100644
--- a/grapher/Models/Calculations/AccelCalculator.cs
+++ b/grapher/Models/Calculations/AccelCalculator.cs
@@ -66,6 +66,7 @@ namespace grapher.Models.Calculations
{
var output = accel.Accelerate(magnitudeDatum.x, magnitudeDatum.y, MeasurementTime);
var outMagnitude = Magnitude(output.Item1, output.Item2);
+
var ratio = magnitudeDatum.magnitude > 0 ? outMagnitude / magnitudeDatum.magnitude : starter;
var inDiff = magnitudeDatum.magnitude - lastInputMagnitude;
diff --git a/grapher/Models/Options/AccelTypeOptions.cs b/grapher/Models/Options/AccelTypeOptions.cs
index 917ac5c..6f547cd 100644
--- a/grapher/Models/Options/AccelTypeOptions.cs
+++ b/grapher/Models/Options/AccelTypeOptions.cs
@@ -21,6 +21,7 @@ namespace grapher
new LogarithmLayout(),
new NaturalGainLayout(),
new SigmoidGainLayout(),
+ new ExperimentOneLayout(),
new OffLayout()
}.ToDictionary(k => k.Name);
diff --git a/grapher/Models/Serialized/DriverSettings.cs b/grapher/Models/Serialized/DriverSettings.cs
index d42187c..03c5687 100644
--- a/grapher/Models/Serialized/DriverSettings.cs
+++ b/grapher/Models/Serialized/DriverSettings.cs
@@ -8,7 +8,7 @@ namespace grapher.Models.Serialized
public enum AccelMode
{
- linear, classic, natural, naturalgain, sigmoidgain, power, logarithm, noaccel
+ linear, classic, natural, naturalgain, sigmoidgain, power, logarithm, experimentone, noaccel
}
#endregion Enumerations
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index d451a91..ebe224a 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -54,6 +54,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Constants\Constants.cs" />
+ <Compile Include="Layouts\ExperimentOneLayout.cs" />
<Compile Include="Layouts\LogarithmLayout.cs" />
<Compile Include="Layouts\NaturalGainLayout.cs" />
<Compile Include="Layouts\SigmoidGainLayout.cs" />