[chronojump] ForceSensor interpolate working with config params on load set (to test it)



commit ac339b0f5dfe636effc1813fc8f6307cba2ccd7d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon May 10 23:05:02 2021 +0200

    ForceSensor interpolate working with config params on load set (to test it)

 glade/repetitive_conditions.glade | 245 +++++++++++++++++++++++++++++++++++++-
 src/gui/app1/forceSensor.cs       |  77 +++++++++---
 src/gui/repetitiveConditions.cs   |  33 +++++
 src/utilMath.cs                   |  13 +-
 4 files changed, 344 insertions(+), 24 deletions(-)
---
diff --git a/glade/repetitive_conditions.glade b/glade/repetitive_conditions.glade
index 927150fd..868132c4 100644
--- a/glade/repetitive_conditions.glade
+++ b/glade/repetitive_conditions.glade
@@ -4575,7 +4575,7 @@
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
                         <property name="border_width">14</property>
-                        <property name="spacing">12</property>
+                        <property name="spacing">16</property>
                         <child>
                           <widget class="GtkVBox" id="vbox18">
                             <property name="visible">True</property>
@@ -4616,7 +4616,7 @@
                                           <widget class="GtkLabel" id="label395">
                                             <property name="visible">True</property>
                                             <property name="can_focus">False</property>
-                                            <property name="label">at</property>
+                                            <property name="label" translatable="yes">at</property>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>
@@ -4673,7 +4673,7 @@
                                           <widget class="GtkLabel" id="label396">
                                             <property name="visible">True</property>
                                             <property name="can_focus">False</property>
-                                            <property name="label">range</property>
+                                            <property name="label" translatable="yes">range</property>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>
@@ -4741,6 +4741,7 @@
                           <widget class="GtkVBox" id="vbox19">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
+                            <property name="spacing">12</property>
                             <child>
                               <widget class="GtkCheckButton" id="check_force_sensor_capture_feedback_path">
                                 <property name="label" translatable="yes">Show path</property>
@@ -4757,12 +4758,244 @@
                               </packing>
                             </child>
                             <child>
-                              <placeholder/>
+                              <widget class="GtkAlignment" id="alignment18">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="left_padding">20</property>
+                                <child>
+                                  <widget class="GtkVBox" id="vbox_force_sensor_capture_feedback_path">
+                                    <property name="visible">True</property>
+                                    <property name="sensitive">False</property>
+                                    <property name="can_focus">False</property>
+                                    <property name="spacing">12</property>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox50">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="spacing">4</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label58">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes">Maximum</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkSpinButton" 
id="spin_force_sensor_capture_feedback_path_max">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="invisible_char">●</property>
+                                            <property name="invisible_char_set">True</property>
+                                            <property name="primary_icon_activatable">False</property>
+                                            <property name="secondary_icon_activatable">False</property>
+                                            <property name="primary_icon_sensitive">True</property>
+                                            <property name="secondary_icon_sensitive">True</property>
+                                            <property name="adjustment">100 0 9999 1 10 0</property>
+                                            <property name="climb_rate">1</property>
+                                            <property name="numeric">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkLabel" id="label61">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label">N</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">True</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">2</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox51">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="spacing">4</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label62">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes">Minimum</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkSpinButton" 
id="spin_force_sensor_capture_feedback_path_min">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="invisible_char">●</property>
+                                            <property name="invisible_char_set">True</property>
+                                            <property name="primary_icon_activatable">False</property>
+                                            <property name="secondary_icon_activatable">False</property>
+                                            <property name="primary_icon_sensitive">True</property>
+                                            <property name="secondary_icon_sensitive">True</property>
+                                            <property name="adjustment">50 0 9999 1 10 0</property>
+                                            <property name="climb_rate">1</property>
+                                            <property name="numeric">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkLabel" id="label63">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label">N</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">True</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">2</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox52">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="spacing">4</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label">Master points</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkSpinButton" 
id="spin_force_sensor_capture_feedback_path_masters">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="invisible_char">●</property>
+                                            <property name="invisible_char_set">True</property>
+                                            <property name="primary_icon_activatable">False</property>
+                                            <property name="secondary_icon_activatable">False</property>
+                                            <property name="primary_icon_sensitive">True</property>
+                                            <property name="secondary_icon_sensitive">True</property>
+                                            <property name="adjustment">6 3 20 1 10 0</property>
+                                            <property name="climb_rate">1</property>
+                                            <property name="numeric">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <widget class="GtkHBox" id="hbox53">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="spacing">4</property>
+                                        <child>
+                                          <widget class="GtkLabel" id="label64">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label">Seconds between masters</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkSpinButton" 
id="spin_force_sensor_capture_feedback_path_master_seconds">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="invisible_char">●</property>
+                                            <property name="invisible_char_set">True</property>
+                                            <property name="primary_icon_activatable">False</property>
+                                            <property name="secondary_icon_activatable">False</property>
+                                            <property name="primary_icon_sensitive">True</property>
+                                            <property name="secondary_icon_sensitive">True</property>
+                                            <property name="adjustment">2 1 10 1 10 0</property>
+                                            <property name="climb_rate">1</property>
+                                            <property name="numeric">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="position">1</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkLabel" id="label66">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label">s</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">True</property>
+                                            <property name="fill">True</property>
+                                            <property name="position">2</property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">False</property>
+                                        <property name="position">3</property>
+                                      </packing>
+                                    </child>
+                                  </widget>
+                                </child>
+                              </widget>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">1</property>
+                              </packing>
                             </child>
                           </widget>
                           <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
                             <property name="position">1</property>
                           </packing>
                         </child>
diff --git a/src/gui/app1/forceSensor.cs b/src/gui/app1/forceSensor.cs
index 4cb5bf1b..eb233cc3 100644
--- a/src/gui/app1/forceSensor.cs
+++ b/src/gui/app1/forceSensor.cs
@@ -193,7 +193,7 @@ public partial class ChronoJumpWindow
 
                pen_blue_light_force_capture_interpolated_feedback = new 
Gdk.GC(force_capture_drawingarea.GdkWindow);
                pen_blue_light_force_capture_interpolated_feedback.Foreground = UtilGtk.LIGHT_BLUE_PLOTS;
-               pen_blue_light_force_capture_interpolated_feedback.SetLineAttributes (60, 
Gdk.LineStyle.Solid, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Round);
+               pen_blue_light_force_capture_interpolated_feedback.SetLineAttributes (40, 
Gdk.LineStyle.Solid, Gdk.CapStyle.NotLast, Gdk.JoinStyle.Round);
 
                //pen_yellow_force_capture = new Gdk.GC(force_capture_drawingarea.GdkWindow);
                //pen_yellow_force_capture.Foreground = UtilGtk.YELLOW;
@@ -1944,7 +1944,10 @@ LogB.Information(" fs R ");
                                );
                //showForceSensorTriggers (); TODO until know where to put it
 
-               createForceSensorCaptureInterpolateSignal();
+               if(repetitiveConditionsWin.GetForceSensorFeedbackPathActive)
+                       createForceSensorCaptureInterpolateSignal();
+               else
+                       interpolate_l = null;
 
                forceSensorCopyTempAndDoGraphs(forceSensorGraphsEnum.SIGNAL);
                //image_force_sensor_graph.Sensitive = false; //unsensitivize the RFD image (can contain info 
of previous data)
@@ -2036,10 +2039,39 @@ LogB.Information(" fs R ");
        List<PointF> interpolate_l;
        private void createForceSensorCaptureInterpolateSignal()
        {
+               /*
                //create random forces from 1200 to 2400, 4000 ms aprox, 4 points (4000/1000)
                //between each of the points interpolation will happen
                InterpolateSignal interpolateS = new InterpolateSignal(1200, 2400, 4000, 1000);
+               */
+
+               //need at least 3 masters
+               if(repetitiveConditionsWin.GetForceSensorFeedbackPathMasters < 3)
+               {
+                       interpolate_l = null;
+                       return;
+               }
+
+               /*
+               3rd param on InterpolateSignal is maxx.
+               points = maxx / step , so: maxx = points * step
+               */
+               int maxx = repetitiveConditionsWin.GetForceSensorFeedbackPathMasters *
+                       repetitiveConditionsWin.GetForceSensorFeedbackPathMasterSeconds;
+
+               InterpolateSignal interpolateS = new InterpolateSignal(
+                               repetitiveConditionsWin.GetForceSensorFeedbackPathMin,
+                               repetitiveConditionsWin.GetForceSensorFeedbackPathMax,
+                               maxx * 1000,
+                               repetitiveConditionsWin.GetForceSensorFeedbackPathMasterSeconds * 1000
+                               );
+
                interpolate_l = interpolateS.GetCubicInterpolated();
+               /*
+               LogB.Information("interpolate_l: ");
+               for(int i=0; i < interpolate_l.Count; i++)
+                       LogB.Information(interpolate_l[i].ToString());
+                       */
        }
 
        // ----start of forceSensorDeleteTest stuff -------
@@ -2362,23 +2394,34 @@ LogB.Information(" fs R ");
                //draw interpolated feedback
                if(interpolate_l != null)
                {
-                       //LogB.Information(string.Format("interpolate counts: {0} {1}",
-                       //      fscPoints.Points.Count, interpolate_l.Count));
+                       /*
+                       LogB.Information("fscPoints:");
+                       for(int k = 0; k < fscPoints.Points.Count; k ++)
+                               LogB.Information(string.Format("{0} ({1},{2})", k, fscPoints.Points[k].X, 
fscPoints.Points[k].Y));
 
-                       Gdk.Point [] paintPointsInterpolate = new Gdk.Point[fscPoints.Points.Count];
-                       for(int i = 0, j= 0; i < fscPoints.Points.Count; i ++, j ++)
-                       {
-                               //to cycle
-                               if(j == interpolate_l.Count)
-                                       j = 0;
-
-                               paintPointsInterpolate[i].X = fscPoints.Points[i].X;
-                               paintPointsInterpolate[i].Y = fscPoints.GetForceInPx(interpolate_l[j].Y);
-                               //LogB.Information(string.Format("interpolate_l: {0} {1}",
-                               //                      interpolate_l[i].X, interpolate_l[i].Y));
-                       }
+                       LogB.Information("paintPointsInterpolate:");
+                       */
+                       int timeCount = 0;
+                       int timeStep = (1000 * 
repetitiveConditionsWin.GetForceSensorFeedbackPathMasterSeconds/10) //if each 1000 ms, then: advance by 100 
(to have 10 interpolated between each master)
+                                               * 1000; //to micros
+
+                       List<Gdk.Point> paintPointsInterpolate = new List<Gdk.Point>();
+                       do {
+                               for(int interY = 0;
+                                               interY < interpolate_l.Count && timeCount < 
fscPoints.GetLastTime();
+                                               interY ++)
+                               {
+                                       paintPointsInterpolate.Add(new Gdk.Point(
+                                                       fscPoints.GetTimeInPx(timeCount), //note we are not 
using interpolate_l[*].X
+                                                       fscPoints.GetForceInPx(interpolate_l[interY].Y)
+                                                       ));
+
+                                       timeCount += timeStep;
+                               }
+                       } while (timeCount < fscPoints.GetLastTime());
 
-                       force_capture_pixmap.DrawLines(pen_blue_light_force_capture_interpolated_feedback, 
paintPointsInterpolate);
+                       //paint the points
+                       force_capture_pixmap.DrawLines(pen_blue_light_force_capture_interpolated_feedback, 
paintPointsInterpolate.ToArray());
                }
 
 
diff --git a/src/gui/repetitiveConditions.cs b/src/gui/repetitiveConditions.cs
index db4c8b85..48117a72 100644
--- a/src/gui/repetitiveConditions.cs
+++ b/src/gui/repetitiveConditions.cs
@@ -186,10 +186,18 @@ public class RepetitiveConditionsWindow
        [Widget] Gtk.CheckButton check_rhythm_rest_reps;
 
        //forceSensor
+       //rectangle
        [Widget] Gtk.CheckButton check_force_sensor_capture_feedback_rectangle;
        [Widget] Gtk.HBox hbox_force_sensor_capture_feedback_rectangle;
        [Widget] Gtk.SpinButton spin_force_sensor_capture_feedback_rectangle_at;
        [Widget] Gtk.SpinButton spin_force_sensor_capture_feedback_rectangle_range;
+       //path
+       [Widget] Gtk.CheckButton check_force_sensor_capture_feedback_path;
+       [Widget] Gtk.VBox vbox_force_sensor_capture_feedback_path;
+       [Widget] Gtk.SpinButton spin_force_sensor_capture_feedback_path_max;
+       [Widget] Gtk.SpinButton spin_force_sensor_capture_feedback_path_min;
+       [Widget] Gtk.SpinButton spin_force_sensor_capture_feedback_path_masters;
+       [Widget] Gtk.SpinButton spin_force_sensor_capture_feedback_path_master_seconds;
 
        const int JUMPSRUNSPAGE = 0;
        const int ENCODERAUTOPAGE = 1;
@@ -418,6 +426,8 @@ public class RepetitiveConditionsWindow
                        spin_force_sensor_capture_feedback_rectangle_at.Value = forceSensorCaptureFeedbackAt;
                        spin_force_sensor_capture_feedback_rectangle_range.Value = 
forceSensorCaptureFeedbackRange;
 
+                       //TODO: define values of path widgets
+
                        notebook_main.GetNthPage(FORCESENSORPAGE).Show();
                }
 
@@ -952,8 +962,10 @@ public class RepetitiveConditionsWindow
 
        private void on_check_force_sensor_capture_feedback_path_toggled (object o, EventArgs args)
        {
+               vbox_force_sensor_capture_feedback_path.Sensitive = 
check_force_sensor_capture_feedback_path.Active;
        }
 
+       //force sensor feedback rectangle
        public bool GetForceSensorFeedbackRectangleActive {
                get { return check_force_sensor_capture_feedback_rectangle.Active; }
        }
@@ -964,6 +976,27 @@ public class RepetitiveConditionsWindow
                get { return Convert.ToInt32(spin_force_sensor_capture_feedback_rectangle_range.Value); }
        }
 
+       //force sensor feedback path
+       public bool GetForceSensorFeedbackPathActive {
+               get { return check_force_sensor_capture_feedback_path.Active; }
+               //get { return true; }
+       }
+       public int GetForceSensorFeedbackPathMax {
+               get { return Convert.ToInt32(spin_force_sensor_capture_feedback_path_max.Value); }
+               //get { return 1000; }
+       }
+       public int GetForceSensorFeedbackPathMin {
+               get { return Convert.ToInt32(spin_force_sensor_capture_feedback_path_min.Value); }
+               //get { return 0; }
+       }
+       public int GetForceSensorFeedbackPathMasters {
+               get { return Convert.ToInt32(spin_force_sensor_capture_feedback_path_masters.Value); }
+               //get { return 5; }
+       }
+       public int GetForceSensorFeedbackPathMasterSeconds {
+               get { return Convert.ToInt32(spin_force_sensor_capture_feedback_path_master_seconds.Value); }
+               //get { return 5; }
+       }
 
        /* JUMPS */
        public bool TfTcBest {
diff --git a/src/utilMath.cs b/src/utilMath.cs
index 76c02ed2..5c0688aa 100644
--- a/src/utilMath.cs
+++ b/src/utilMath.cs
@@ -404,8 +404,18 @@ public class InterpolateSignal
                this.point_l = new List<PointF>();
                int range = maxY - minY;
 
+               //LogB.Information(string.Format("InterpolateSignal maxX: {0}, stepX: {1}", maxX, stepX));
+
                for(int i = 0; i < maxX; i += stepX)
+               {
                        point_l.Add(new PointF(i, minY + (random.NextDouble() * range)));
+
+                       /*
+                       PointF p = new PointF(i, minY + (random.NextDouble() * range));
+                       point_l.Add(p);
+                       LogB.Information(string.Format("point: {0}", p));
+                       */
+               }
        }
 
        //thanks to: http://paulbourke.net/miscellaneous/interpolation/
@@ -459,9 +469,10 @@ public class InterpolateSignal
        {
                List<PointF> interpolated_l = new List<PointF>();
 
+               //point_l.Count has to be >= 3
                for(int i = 0; i < point_l.Count; i ++) //each known point
                {
-                       for(double j = 0; j < 1 ; j += .01) //each interpolated value
+                       for(double j = 0.05; j < 1 ; j += .1) //10 interpolated value for each master (see 
timeCount on gui/app1/forceSensor.cs)
                        {
                                if (type == types.COSINE)
                                {


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