[chronojump] RunEncoderSegmentCalcs calculates accels



commit 50c4d5a72c4039440bae5498bd75e85e67129309
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 9 12:23:30 2022 +0200

    RunEncoderSegmentCalcs calculates accels

 src/gui/cairo/raceAnalyzer.cs |  2 ++
 src/runEncoder.cs             | 40 +++++++++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/src/gui/cairo/raceAnalyzer.cs b/src/gui/cairo/raceAnalyzer.cs
index 01406ddb2..4204278f5 100644
--- a/src/gui/cairo/raceAnalyzer.cs
+++ b/src/gui/cairo/raceAnalyzer.cs
@@ -136,6 +136,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
                                //vertical
                                if(segmentCalcs.Count > 0)
                                {
+                                       LogB.Information("accels: ");
                                        g.Save();
                                        g.SetDash(new double[]{1, 2}, 0);
                                        for(int i = 0 ; i < segmentCalcs.Count ; i ++)
@@ -145,6 +146,7 @@ public class CairoGraphRaceAnalyzer : CairoXY
                                                //seconds
                                                string xTextBottom = 
Util.TrimDecimals(segmentCalcs.Time_l[i]/1000000.0, 1).ToString();
                                                double xGraph = 
calculatePaintX(segmentCalcs.Time_l[i]/1000000.0);
+                                               LogB.Information(segmentCalcs.Accel_l[i].ToString());
 
                                                if(useListOfDoublesOnY)
                                                        paintVerticalGridLine(g, Convert.ToInt32(xGraph), 
xTextBottom, textHeight-3);
diff --git a/src/runEncoder.cs b/src/runEncoder.cs
index 1448b2530..5028ed0b3 100644
--- a/src/runEncoder.cs
+++ b/src/runEncoder.cs
@@ -355,7 +355,7 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
        private void updateSegmentDistTimeFixed () //m
        {
                if(runEncoderCaptureDistance >= (segmentCm/100.0) * (segmentCalcs.Count +1))
-                       segmentCalcs.Add((segmentCm/100.0) * (segmentCalcs.Count +1), time);
+                       segmentCalcs.Add((segmentCm/100.0) * (segmentCalcs.Count +1), time, 
runEncoderCaptureSpeed);
                //note this is not very precise because time can be a bit later than the selected dist
        }
        private void updateSegmentDistTimeVariable () //cm
@@ -368,7 +368,7 @@ public class RunEncoderCaptureGetSpeedAndDisplacement
                if(runEncoderCaptureDistance >= distToBeat)
                {
                        segmentVariableCmDistAccumulated += segmentVariableCm[segmentCalcs.Count];
-                       segmentCalcs.Add (distToBeat, time);
+                       segmentCalcs.Add (distToBeat, time, runEncoderCaptureSpeed);
                }
        }
 
@@ -408,19 +408,50 @@ public class RunEncoderSegmentCalcs
 {
        private List<double> dist_l;
        private List<double> time_l;
+       private List<double> speedCont_l;
+       private List<double> accel_l;
+
+       /*
        //TODO: a, F, P
+       accel = (V2 - V1)/(T2 - T1)
+       F = m * (a + g*sin(alpha))
+       P = 0.5 * m * (V2^2 - V1^2) + m*g*(h2 - h1)
+       h = pos * sin(alpha)
+       */
 
        public RunEncoderSegmentCalcs ()
        {
                dist_l = new List<double> ();
                time_l = new List<double> ();
+               speedCont_l = new List<double> ();
+               accel_l = new List<double> ();
                //TODO: a, F, P
        }
 
-       public void Add (double dist, double time)
+       //speedCont is continuous (at this instant) (no avg: dist/time of the segment)
+       public void Add (double dist, double time, double speedCont)
        {
+               //store this variable before adding the dist
+               bool isFirstOne = (dist_l.Count == 0);
+
                dist_l.Add (dist);
                time_l.Add (time);
+               speedCont_l.Add(speedCont);
+
+               if(isFirstOne)
+                       accel_l.Add(UtilAll.DivideSafe(speedCont, time/1000000.0));
+               else
+               {
+                       /*
+                       debug:
+                       LogB.Information(string.Format("speed now: {0}, speed pre: {1}, time now: {2}, time 
pre: {3}, result: {4}",
+                                               speedCont, speedCont_l[Count -2], time/1000000.0, 
time_l[Count -2]/1000000.0,
+                                               UtilAll.DivideSafe( (speedCont - speedCont_l[Count -2]), 
(time/1000000.0 - time_l[Count -2]/1000000.0) ) ));
+                                               */
+
+                       accel_l.Add(UtilAll.DivideSafe(
+                                               (speedCont - speedCont_l[Count -2]), (time/1000000.0 - 
time_l[Count -2]/1000000.0) ));
+               }
        }
 
        public int Count
@@ -434,6 +465,9 @@ public class RunEncoderSegmentCalcs
        public List<double> Time_l {
                get { return time_l; }
        }
+       public List<double> Accel_l {
+               get { return accel_l; }
+       }
 }
 
 public class RunEncoderExercise


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