[chronojump] ForceSensor resultant force calculation done (at not elastic)



commit 88654f4bc8e9c490a25cf074658658ed7bc3dc80
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Nov 11 17:35:19 2019 +0100

    ForceSensor resultant force calculation done (at not elastic)

 src/forceSensor.cs            | 44 ++++++++++++++++++++++++++++++++++++-------
 src/gui/forceSensor.cs        | 16 ++++++++--------
 src/gui/forceSensorAnalyze.cs |  2 +-
 3 files changed, 46 insertions(+), 16 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 46c3758a..5163779b 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -179,11 +179,41 @@ public class ForceSensor
        }
 
        //static methods
-       public static double ForceWithCaptureOptionsAndBW (double force, CaptureOptions fsco, int 
percentBodyWeight, double personWeight)
+
+       public static double CalculeForceResultantIfNeeded (double forceRaw, CaptureOptions fsco, 
ForceSensorExercise fse, double personMass)
        {
-               if(percentBodyWeight > 0 && personWeight > 0)
-                       force += 9.81 * percentBodyWeight * personWeight / 100.0;
+               if(! fse.ForceResultant)
+                       return calculeForceWithCaptureOptions(forceRaw, fsco);
+
+               double totalMass = 0;
+               if(fse.PercentBodyWeight > 0 && personMass > 0)
+                       totalMass = fse.PercentBodyWeight * personMass / 100.0;
+
+               //right now only code for non-elastic
+               double accel = 0;
+
+               /*
+                * debug info
+               LogB.Information("--------------");
+               LogB.Information("exercise: " + fse.ToString());
+               LogB.Information("forceRaw: " + forceRaw.ToString());
+               LogB.Information("totalMass: " + totalMass.ToString());
+               LogB.Information("AngleDefault: " + fse.AngleDefault.ToString());
+
+               LogB.Information("horiz: " + (Math.Cos(fse.AngleDefault * Math.PI / 180.0) * (forceRaw + 
totalMass * accel)).ToString());
+               LogB.Information("vertical: " + (Math.Sin(fse.AngleDefault * Math.PI / 180.0) * (forceRaw + 
totalMass * accel) + totalMass * 9.81).ToString());
+               */
+               //TODO: now we are using fse.AngleDefault, but we have to implement especific angle on capture
+
+               double forceResultant = Math.Sqrt(
+                               Math.Pow(Math.Cos(fse.AngleDefault * Math.PI / 180.0) * (forceRaw + totalMass 
* accel),2) +                     //Horizontal component
+                               Math.Pow(Math.Sin(fse.AngleDefault * Math.PI / 180.0) * (forceRaw + totalMass 
* accel) + totalMass * 9.81,2)    //Vertical component
+                               );
 
+               return calculeForceWithCaptureOptions(forceResultant, fsco);
+       }
+       private static double calculeForceWithCaptureOptions(double force, CaptureOptions fsco)
+       {
                if(fsco == CaptureOptions.ABS)
                        return Math.Abs(force);
                if(fsco == CaptureOptions.INVERTED)
@@ -1266,12 +1296,12 @@ public class ForceSensorAnalyzeInstant
        private int graphHeight;
 
        public ForceSensorAnalyzeInstant(string file, int graphWidth, int graphHeight, double start, double 
end,
-                       int exercisePercentBW, double personWeight, ForceSensor.CaptureOptions fsco)
+                       ForceSensorExercise fse, double personWeight, ForceSensor.CaptureOptions fsco)
        {
                this.graphWidth = graphWidth;
                this.graphHeight = graphHeight;
 
-               readFile(file, start, end, exercisePercentBW, personWeight, fsco);
+               readFile(file, start, end, fse, personWeight, fsco);
 
                //on zoom adjust width
                if(start >= 0 || end >= 0)
@@ -1285,7 +1315,7 @@ public class ForceSensorAnalyzeInstant
                        fscAIPoints.Redo();
        }
 
-       private void readFile(string file, double start, double end, int exercisePercentBW, double 
personWeight, ForceSensor.CaptureOptions fsco)
+       private void readFile(string file, double start, double end, ForceSensorExercise fse, double 
personWeight, ForceSensor.CaptureOptions fsco)
        {
                fscAIPoints = new ForceSensorCapturePoints(graphWidth, graphHeight, -1);
 
@@ -1328,7 +1358,7 @@ public class ForceSensorAnalyzeInstant
 
                                        int time = Convert.ToInt32(timeD);
                                        double force = Convert.ToDouble(strFull[1]);
-                                       force = ForceSensor.ForceWithCaptureOptionsAndBW(force, fsco, 
exercisePercentBW, personWeight);
+                                       force = ForceSensor.CalculeForceResultantIfNeeded (force, fsco, fse, 
personWeight);
 
                                        fscAIPoints.Add(time, force);
                                        fscAIPoints.NumCaptured ++;
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index e2c82b8b..a222040c 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -961,21 +961,21 @@ public partial class ChronoJumpWindow
                        time -= firstTime;
 
                        LogB.Information(string.Format("time: {0}, force: {1}", time, force));
-                       //forceWithCaptureOptionsAndBW have abs or inverted
-                       double forceWithCaptureOptionsAndBW = ForceSensor.ForceWithCaptureOptionsAndBW(force, 
forceSensorCaptureOption,
-                                       currentForceSensorExercise.PercentBodyWeight, 
currentPersonSession.Weight);
+                       //forceCalculated have abs or inverted
+                       double forceCalculated = ForceSensor.CalculeForceResultantIfNeeded (force, 
forceSensorCaptureOption,
+                                       currentForceSensorExercise, currentPersonSession.Weight);
 
                        if(forceSensorCaptureOption != ForceSensor.CaptureOptions.NORMAL)
-                               LogB.Information(string.Format("with abs or inverted flag: time: {0}, force: 
{1}", time, forceWithCaptureOptionsAndBW));
+                               LogB.Information(string.Format("with abs or inverted flag: time: {0}, force: 
{1}", time, forceCalculated));
 
                        writer.WriteLine(time.ToString() + ";" + force.ToString()); //on file force is stored 
without flags
 
                        forceSensorValues.TimeLast = time;
-                       forceSensorValues.ForceLast = forceWithCaptureOptionsAndBW;
+                       forceSensorValues.ForceLast = forceCalculated;
 
-                       forceSensorValues.SetMaxMinIfNeeded(forceWithCaptureOptionsAndBW, time);
+                       forceSensorValues.SetMaxMinIfNeeded(forceCalculated, time);
 
-                       fscPoints.Add(time, forceWithCaptureOptionsAndBW);
+                       fscPoints.Add(time, forceCalculated);
                        fscPoints.NumCaptured ++;
                        if(fscPoints.OutsideGraph(preferences.forceSensorCaptureScroll))
                        {
@@ -1872,7 +1872,7 @@ LogB.Information(" fs R ");
                                {
                                        int time = Convert.ToInt32(strFull[0]);
                                        double force = Convert.ToDouble(strFull[1]);
-                                       force = ForceSensor.ForceWithCaptureOptionsAndBW(force, fsco, 
currentForceSensorExercise.PercentBodyWeight, currentPersonSession.Weight);
+                                       force = ForceSensor.CalculeForceResultantIfNeeded(force, fsco, 
currentForceSensorExercise, currentPersonSession.Weight);
 
                                        fscPoints.Add(time, force);
                                        fscPoints.NumCaptured ++;
diff --git a/src/gui/forceSensorAnalyze.cs b/src/gui/forceSensorAnalyze.cs
index 2320c0b3..032d839c 100644
--- a/src/gui/forceSensorAnalyze.cs
+++ b/src/gui/forceSensorAnalyze.cs
@@ -555,7 +555,7 @@ public partial class ChronoJumpWindow
                                force_sensor_ai_drawingarea.Allocation.Width,
                                force_sensor_ai_drawingarea.Allocation.Height,
                                zoomA, zoomB,
-                               currentForceSensorExercise.PercentBodyWeight, currentPersonSession.Weight,
+                               currentForceSensorExercise, currentPersonSession.Weight,
                                getForceSensorCaptureOptions());
 
                /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]