[chronojump] improving code on inertia and diameter



commit c06b6920cf4cf5299c2d96b4dcede9b74670f69b
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Jan 15 13:48:19 2014 +0100

    improving code on inertia and diameter

 encoder/graph.R        |   40 +++++++++++++++---------------
 glade/chronojump.glade |    4 +-
 src/encoder.cs         |   49 +++++++++++++++++++++++++++---------
 src/gui/encoder.cs     |   64 ++++++++++++++++++++++++++++++------------------
 src/sqlite/encoder.cs  |    8 +++---
 5 files changed, 103 insertions(+), 62 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 6e1adce..61a9c7b 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -101,7 +101,7 @@ cols=c(colSpeed,colForce,colPower); lty=rep(1,3)
 #way A. passing options to a file
 getOptionsFromFile <- function(optionsFile) {
        optionsCon <- file(optionsFile, 'r')
-       options=readLines(optionsCon,n=19)
+       options=readLines(optionsCon,n=22)
        close(optionsCon)
        return (options)
 }
@@ -122,7 +122,7 @@ print(options)
 
 OutputData2 = options[4] #currently used to display processing feedback
 SpecialData = options[5]
-OperatingSystem=options[19]
+OperatingSystem=options[22]
 
 
 write("(1/5) Starting R", OutputData2)
@@ -996,15 +996,15 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
                #Explanation rotatory encoder on inertial machine
                #speed$y comes in mm/ms, is the same than m/s
                #speedw in meters:
-               speedw <- speed$y/inertialDiameter #m radius
+               speedw <- speed$y / diameter #m radius
                #accel$y comes in meters
                #accelw in meters:
-               accelw <- accel$y/inertialDiameter
+               accelw <- accel$y / diameter
 
                #power = power to the inertial machine (rotatory disc) + power to the displaced body mass 
(lineal)
                #power = ( inertia momentum * angular acceleration * angular velocity ) + mass(includes extra 
weight if any) * accel$y * speed$y  
                #abs(speedw) because disc is rolling in the same direction and we don't have to make power to 
change it
-               power <- inertialMomentum * accelw * speedw + mass * (accel$y +g) * speed$y
+               power <- inertiaMomentum * accelw * speedw + mass * (accel$y +g) * speed$y
        
                #print("at Paint")      
                #print(c("mass",mass))
@@ -1645,13 +1645,18 @@ doProcess <- function(options) {
        AnalysisVariables=unlist(strsplit(options[11], "\\;"))
        
        AnalysisOptions=options[12]     
-       SmoothingOneC=options[13]
-       Jump=options[14]
-       Width=as.numeric(options[15])
-       Height=as.numeric(options[16])
-       DecimalSeparator=options[17]
-       Title=options[18]
-       OperatingSystem=options[19]     #if this changes, change it also at start of this R file
+
+       encoderMode=            options[13]     
+       inertiaMomentum=        as.numeric(options[14])/10000   #comes in Kg*cm^2 eg: 100; convert it to 
Kg*m^2 eg: 0.010
+       diameter=               as.numeric(options[15]) #in meters, eg: 0.0175
+       
+       SmoothingOneC=options[16]
+       Jump=options[17]
+       Width=as.numeric(options[18])
+       Height=as.numeric(options[19])
+       DecimalSeparator=options[20]
+       Title=options[21]
+       OperatingSystem=options[22]     #if this changes, change it also at start of this R file
        #IMPORTANT, if this grows, change the readLines value on getOptionsFromFile
 
        print(File)
@@ -1661,18 +1666,13 @@ doProcess <- function(options) {
        print(SpecialData)
 
        #read AnalysisOptions
-       #if is propulsive and rotatory inertial is: "p;ri;0.010" (last is momentum)
-       #if nothing: "-;-;-"
+       #if is propulsive and rotatory inertial is: "p;ri" 
+       #if nothing: "-;-"
        analysisOptionsTemp = unlist(strsplit(AnalysisOptions, "\\;"))
        isPropulsive = (analysisOptionsTemp[1] == "p")
-       inertialType = ""
-       inertialMomentum = 0
+       inertialType = ""       #TODO: use encoderMode
        if(length(analysisOptionsTemp) > 1) {
                inertialType = analysisOptionsTemp[2] #values: "" || "li" || "ri"
-               inertialMomentum = analysisOptionsTemp[3] #in meters, eg: 0.010
-       }
-       if(length(analysisOptionsTemp) > 3) {
-               inertialDiameter = analysisOptionsTemp[4] #in meters, eg: 0.0175
        }
 
        #in "li": linear encoder with inertial machines,
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 44f5b17..553df2d 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -20608,12 +20608,12 @@ comments</property>
                 </child>
                 <child>
                   <widget class="GtkRadioButton" id="radiobutton_encoder_capture_external">
-                    <property name="label" translatable="yes">External</property>
+                    <property name="label" translatable="no">External DEPRECATED</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
                     <property name="has_tooltip">True</property>
-                    <property name="tooltip" translatable="yes">External</property>
+                    <property name="tooltip" translatable="no">External DEPRECATED</property>
                     <property name="image_position">right</property>
                     <property name="draw_indicator">True</property>
                     <property name="group">radiobutton_encoder_capture_safe</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index 26b099d..c875da7 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -35,6 +35,16 @@ public class EncoderParams
        private string analysis;
        private string analysisVariables;
        private string analysisOptions;         //p: propulsive
+                                       
+       //Constants.EncoderSignalMode
+       //in signals and in curves
+       //in signals need to do conversions (invert)
+       //in curves they are already done, is just informative
+       //same for inertiaMomentum and diameter
+       private string encoderMode;     
+       private int inertiaMomentum; 
+       private double diameter;
+       
        private string smoothCon; //to pass always as "." to R
        private int curve;
        private int width;
@@ -51,13 +61,14 @@ public class EncoderParams
        private int peakPowerLowerCondition;
        private string mainVariable;
        private string decimalSeparator;        //used in export data from R to csv
-       private bool inverted;
+       private bool inverted; //used only in runEncoderCapturePython. In graph.R will be used encoderMode
 
        public EncoderParams()
        {
        }
 
-       //to encoder capture (pyserial_pyper.py)
+       //to encoder capture
+       //RunEncoderCapturePython: pyserial_pyper.py and pyserial_pyper_windows.py . This will be deprecated 
soon 
        public EncoderParams(int time, int minHeight, int exercisePercentBodyWeight, string mass, 
                        string smoothCon, string eccon, string analysisOptions,
                        double heightHigherCondition, double heightLowerCondition, 
@@ -87,7 +98,9 @@ public class EncoderParams
                this.mainVariable = mainVariable;
                this.inverted = inverted;
        }
-       
+
+       //to encoder capture
+       //RunEncoderCapturePython: pyserial_pyper.py and pyserial_pyper_windows.py . This will be deprecated 
soon 
        public string ToString1 () 
        {
                string analysisOptionsPrint = analysisOptions;
@@ -108,8 +121,9 @@ public class EncoderParams
        
        //to graph.R    
        public EncoderParams(int minHeight, int exercisePercentBodyWeight, string mass, string eccon, 
-                       string analysis, string analysisVariables, string analysisOptions, string smoothCon,
-                       int curve, int width, int height, string decimalSeparator)
+                       string analysis, string analysisVariables, string analysisOptions, 
+                       string encoderMode, int inertiaMomentum, double diameter,
+                       string smoothCon, int curve, int width, int height, string decimalSeparator)
        {
                this.minHeight = minHeight;
                this.exercisePercentBodyWeight = exercisePercentBodyWeight;
@@ -118,6 +132,9 @@ public class EncoderParams
                this.analysis = analysis;
                this.analysisVariables = analysisVariables;
                this.analysisOptions = analysisOptions;
+               this.encoderMode = encoderMode;
+               this.inertiaMomentum = inertiaMomentum;
+               this.diameter = diameter;
                this.smoothCon = smoothCon;
                this.curve = curve;
                this.width = width;
@@ -128,8 +145,9 @@ public class EncoderParams
        public string ToString2 (string sep) 
        {
                return minHeight + sep + exercisePercentBodyWeight + sep + mass + sep + eccon + 
-                       sep + analysis + sep + analysisVariables + sep + analysisOptions + sep + smoothCon + 
-                       sep + curve + sep + width + sep + height + sep + decimalSeparator;
+                       sep + analysis + sep + analysisVariables + sep + analysisOptions + 
+                       sep + encoderMode + sep + inertiaMomentum.ToString() + sep + 
Util.ConvertToPoint(diameter) +
+                       sep + smoothCon + sep + curve + sep + width + sep + height + sep + decimalSeparator;
        }
        
        public string Analysis {
@@ -266,9 +284,16 @@ public class EncoderSQL
        public string description;
        public string status;   //active or inactive curves
        public string videoURL; //URL of video of signals
-       public string mode;     //Constants.EncoderSignalMode (only on signals??)
-       public int inertiaMomentum;
+       
+       //Constants.EncoderSignalMode
+       //in signals and in curves
+       //in signals need to do conversions (invert)
+       //in curves they are already done, is just informative
+       //same for inertiaMomentum and diameter
+       public string encoderMode;
+       public int inertiaMomentum; //kg*cm^2
        public double diameter;
+       
        public string future1;
        public string future2;
        public string future3;
@@ -284,8 +309,8 @@ public class EncoderSQL
        public EncoderSQL (string uniqueID, int personID, int sessionID, int exerciseID, 
                        string eccon, string laterality, string extraWeight, string signalOrCurve, 
                        string filename, string url, int time, int minHeight, double smooth, 
-                       string description, string status, string videoURL, string mode,
-                       int inertiaMomentum, double diameter,
+                       string description, string status, string videoURL, 
+                       string encoderMode, int inertiaMomentum, double diameter,
                        string future1, string future2, string future3, 
                        string exerciseName
                        )
@@ -306,7 +331,7 @@ public class EncoderSQL
                this.description = description;
                this.status = status;
                this.videoURL = videoURL;
-               this.mode = mode;
+               this.encoderMode = encoderMode;
                this.inertiaMomentum = inertiaMomentum;
                this.diameter = diameter;
                this.future1 = future1;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index b6c596b..af6e65e 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -46,7 +46,9 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.CheckButton checkbutton_encoder_capture_inertial;
        [Widget] Gtk.Box hbox_encoder_capture_rotary_f_a;
        
-       //this is Kg*cm^2 because there's limitation of Glade on 3 decimals. The rest of the software uses 
Kg*m^2 ( /10000 )
+       //this is Kg*cm^2 because there's limitation of Glade on 3 decimals. 
+       //at SQL it's in Kg*cm^2 also because it's stored as int
+       //at graph.R is converted to Kg*m^2 ( /10000 )
        [Widget] Gtk.SpinButton spin_encoder_capture_inertial; 
        
        [Widget] Gtk.SpinButton spin_encoder_capture_diameter;
@@ -232,7 +234,7 @@ public partial class ChronoJumpWindow
                createEncoderCombos();
                
                spin_encoder_capture_inertial.Value = Convert.ToDouble(Util.ChangeDecimalSeparator(
-                                       SqlitePreferences.Select("inertialmomentum"))) * 10000;
+                                       SqlitePreferences.Select("inertialmomentum")));
                
                encoderCaptureOptionsWin = EncoderCaptureOptionsWindow.Create();
                encoderCaptureOptionsWin.FakeButtonClose.Clicked += new 
EventHandler(on_encoder_capture_options_closed);
@@ -324,7 +326,7 @@ public partial class ChronoJumpWindow
 
                //Update inertia momentum of encoder if needed
                SqlitePreferences.Update("inertialmomentum", 
-                               Util.ConvertToPoint((double) spin_encoder_capture_inertial.Value / 10000), 
false);
+                               Util.ConvertToPoint((double) spin_encoder_capture_inertial.Value), false);
 
                if (encoderCaptureOptionsWin.radiobutton_encoder_capture_external.Active) {
                        encoderStartVideoRecord();
@@ -588,7 +590,7 @@ public partial class ChronoJumpWindow
                encoderAnalyzeListStore = new Gtk.ListStore (typeof (EncoderCurve));
        }
 
-       //arraylist with: mode, inertial value (or zero), diameter value (or zero)
+       //arraylist with: encoderMode, inertial value (or zero), diameter value (or zero)
        private ArrayList getEncoderTypeByCombos() {
                ArrayList data = new ArrayList(3);
                if(radiobutton_encoder_capture_linear.Active) {
@@ -612,7 +614,7 @@ public partial class ChronoJumpWindow
                }
                        
                if(checkbutton_encoder_capture_inertial.Active)
-                       data.Add(Util.ConvertToPoint((double) spin_encoder_capture_inertial.Value / 10000)); 
//Kg*cm^2 -> Kg*m^2
+                       data.Add((int) spin_encoder_capture_inertial.Value);
                else
                        data.Add(0);
                
@@ -626,26 +628,26 @@ public partial class ChronoJumpWindow
        private void setEncoderCombos(EncoderSQL eSQL) {
                //TODO diferentiate both rotary encoders
                if (
-                               eSQL.mode == Constants.EncoderSignalMode.LINEARINERTIAL.ToString() ||
-                               eSQL.mode == Constants.EncoderSignalMode.LINEARINVERTEDINERTIAL.ToString() ||
-                               eSQL.mode == Constants.EncoderSignalMode.ROTARYINERTIAL.ToString()
+                               eSQL.encoderMode == Constants.EncoderSignalMode.LINEARINERTIAL.ToString() ||
+                               eSQL.encoderMode == 
Constants.EncoderSignalMode.LINEARINVERTEDINERTIAL.ToString() ||
+                               eSQL.encoderMode == Constants.EncoderSignalMode.ROTARYINERTIAL.ToString()
                   ) {
                        //inertial machines
                        checkbutton_encoder_capture_inertial.Active = true;
                        //TODO: check this is ok
                        spin_encoder_capture_inertial.Value = 
-                               Convert.ToDouble(eSQL.inertiaMomentum) * 10000; //Kg*m^2 -> Kg*cm^2
+                               Convert.ToInt32(eSQL.inertiaMomentum);
                } else
                        checkbutton_encoder_capture_inertial.Active = false;
                                
        
-               if(eSQL.mode == Constants.EncoderSignalMode.LINEARINVERTED.ToString()) {
+               if(eSQL.encoderMode == Constants.EncoderSignalMode.LINEARINVERTED.ToString()) {
                        radiobutton_encoder_capture_linear.Active = true;
                        checkbutton_encoder_capture_inverted.Active = true;
-               } else if(eSQL.mode == Constants.EncoderSignalMode.ROTARY.ToString()) {
+               } else if(eSQL.encoderMode == Constants.EncoderSignalMode.ROTARY.ToString()) {
                        radiobutton_encoder_capture_rotary.Active = true;
                        checkbutton_encoder_capture_inverted.Active = false;
-               } else { //default to linear: (eSQL.mode == Constants.EncoderSignalMode.LINEAR.ToString()) 
+               } else { //default to linear: (eSQL.encoderMode == 
Constants.EncoderSignalMode.LINEAR.ToString()) 
                        radiobutton_encoder_capture_linear.Active = true;
                        checkbutton_encoder_capture_inverted.Active = false;
                }
@@ -657,6 +659,8 @@ public partial class ChronoJumpWindow
 
        private string getEncoderAnalysisOptions(bool captureOrAnalyze) {
                /*
+                * OLD: now only first two rows: "p", and "l","li", ...
+                *
                 * analysisOptions, separated by ';'
                 * 1: "p" or "-". Propulsive or all
                 * 2: "l", "li", "rf" or "ra". Linear, linear inverted, rotatory friction, rotatory axes
@@ -679,19 +683,15 @@ public partial class ChronoJumpWindow
                if(encoderPropulsive)
                        analysisOptions = "p";
 
-               //inertial momentum with '.' for R
-               string im = Util.ConvertToPoint((double) spin_encoder_capture_inertial.Value / 10000);
-               string diameter = Util.ConvertToPoint((double) spin_encoder_capture_diameter.Value);
-
                if(checkbutton_encoder_capture_inertial.Active) {
                        if(captureOrAnalyze || radiobutton_encoder_analyze_data_current_signal.Active) 
                        {
                                if(radiobutton_encoder_capture_rotary.Active)
-                                       analysisOptions += ";ri;" + im + ";" + diameter;
+                                       analysisOptions += ";ri";
                                else    //(radiobutton_encoder_capture_linear.Active || 
checkbutton_encoder_capture_inverted.Active)
-                                       analysisOptions += ";li;" + im + ";" + diameter;
+                                       analysisOptions += ";li";
                        } else 
-                               analysisOptions += ";-;-;-";
+                               analysisOptions += ";-";
                }
 
                return analysisOptions;
@@ -726,7 +726,7 @@ public partial class ChronoJumpWindow
                                -1,             //Since 1.3.7 smooth is not stored in curves
                                "",             //desc,
                                "","",          //status, videoURL
-                               encoderTypeArray[0].ToString(), //mode  
+                               encoderTypeArray[0].ToString(),         //encoderMode   
                                Convert.ToInt32(encoderTypeArray[1]),   //inertiaMomentum
                                Convert.ToDouble(encoderTypeArray[2]),  //diameter
                                "","","",       //future1, 2, 3
@@ -743,6 +743,9 @@ public partial class ChronoJumpWindow
                                analysis,
                                "none",                         //analysisVariables (not needed in create 
curves). Cannot be blank
                                analysisOptions,
+                               encoderTypeArray[0].ToString(),         //encoderMode   
+                               Convert.ToInt32(encoderTypeArray[1]),   //inertiaMomentum
+                               Convert.ToDouble(encoderTypeArray[2]),  //diameter
                                Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: '.'
                                0,                      //curve is not used here
                                image_encoder_width, image_encoder_height,
@@ -1298,6 +1301,8 @@ public partial class ChronoJumpWindow
                                        getExercisePercentBodyWeightFromName(lastEncoderSQL.exerciseName) *
                                        currentPersonSession.Weight
                                        ) );    
+               
+               ArrayList encoderTypeArray = getEncoderTypeByCombos();
 
                EncoderParams ep = new EncoderParams(
                                lastEncoderSQL.minHeight, 
@@ -1307,6 +1312,9 @@ public partial class ChronoJumpWindow
                                "exportCSV",
                                "none",                                         //analysisVariables (not 
needed in create curves). Cannot be blank
                                analysisOptions,
+                               encoderTypeArray[0].ToString(),         //encoderMode   
+                               Convert.ToInt32(encoderTypeArray[1]),   //inertiaMomentum
+                               Convert.ToDouble(encoderTypeArray[2]),  //diameter
                                Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: '.'
                                -1,
                                image_encoder_width,
@@ -1647,11 +1655,11 @@ public partial class ChronoJumpWindow
 
                if(mode == "signal") {
                        ArrayList encoderTypeArray = getEncoderTypeByCombos();
-                       eSQL.mode = encoderTypeArray[0].ToString();
-                       eSQL.inertiaMomentum = Convert.ToInt32(encoderTypeArray[1]);
-                       eSQL.diameter = Convert.ToDouble(encoderTypeArray[2]);
+                       eSQL.encoderMode =      encoderTypeArray[0].ToString();
+                       eSQL.inertiaMomentum =  Convert.ToInt32(encoderTypeArray[1]);
+                       eSQL.diameter =         Convert.ToDouble(encoderTypeArray[2]);
                } else {
-                       eSQL.mode = "";
+                       eSQL.encoderMode = "";
                        eSQL.inertiaMomentum = 0;
                        eSQL.diameter = 0; 
                }
@@ -2065,6 +2073,8 @@ public partial class ChronoJumpWindow
                if(sendAnalysis == "powerBars" || sendAnalysis == "single" || sendAnalysis == "side")
                        analysisVariables = getAnalysisVariables(sendAnalysis);
 
+               ArrayList encoderTypeArray = getEncoderTypeByCombos();
+
                if(radiobutton_encoder_analyze_data_user_curves.Active) {
                        string myEccon = "ec";
                        if(! check_encoder_analyze_eccon_together.Active)
@@ -2160,6 +2170,9 @@ public partial class ChronoJumpWindow
                                        sendAnalysis,
                                        analysisVariables,
                                        analysisOptions,
+                                       encoderTypeArray[0].ToString(),         //encoderMode   
+                                       Convert.ToInt32(encoderTypeArray[1]),   //inertiaMomentum
+                                       Convert.ToDouble(encoderTypeArray[2]),  //diameter
                                        Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: 
'.'
                                        myCurveNum,
                                        image_encoder_width, 
@@ -2260,6 +2273,9 @@ Log.WriteLine(str);
                                        sendAnalysis,
                                        analysisVariables, 
                                        analysisOptions,
+                                       encoderTypeArray[0].ToString(),         //encoderMode   
+                                       Convert.ToInt32(encoderTypeArray[1]),   //inertiaMomentum
+                                       Convert.ToDouble(encoderTypeArray[2]),  //diameter
                                        Util.ConvertToPoint(encoderSmoothCon),                  //R decimal: 
'.'
                                        
Convert.ToInt32(UtilGtk.ComboGetActive(combo_encoder_analyze_curve_num_combo)),
                                        image_encoder_width,
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index cc33f79..f147644 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -110,8 +110,8 @@ class SqliteEncoder : Sqlite
                        es.signalOrCurve + "', '" + es.filename + "', '" +
                        es.url + "', " + es.time + ", " + es.minHeight + ", " +
                        Util.ConvertToPoint(es.smooth) + ", '" + es.description + 
-                       "', 'active', '" + es.videoURL + "', '" + es.mode + "', " + 
-                       es.inertiaMomentum + ", " + es.diameter + ", '" +
+                       "', 'active', '" + es.videoURL + "', '" + es.encoderMode + "', " + 
+                       es.inertiaMomentum + ", " + Util.ConvertToPoint(es.diameter) + ", '" +
                        es.future1 + "', '" + es.future2 + "', '" +
                        es.future3 + "')";
                Log.WriteLine(dbcmd.CommandText.ToString());
@@ -153,7 +153,7 @@ class SqliteEncoder : Sqlite
                                ", description = '" + es.description + 
                                "', status = '" + es.status + 
                                "', videoURL = '" + es.videoURL + 
-                               "', mode = '" + es.mode + 
+                               "', mode = '" + es.encoderMode + 
                                "', inertiaMomentum = " + es.inertiaMomentum + 
                                ", diameter = " + es.diameter + 
                                ", future1 = '" + es.future1 + 
@@ -242,7 +242,7 @@ class SqliteEncoder : Sqlite
                                        reader[13].ToString(),                  //description
                                        reader[14].ToString(),                  //status
                                        reader[15].ToString(),                  //videoURL
-                                       reader[16].ToString(),                  //mode
+                                       reader[16].ToString(),                  //encoderMode
                                        Convert.ToInt32(reader[17].ToString()), //inertiaMomentum
                                        Convert.ToDouble(Util.ChangeDecimalSeparator(reader[18].ToString())), 
//diameter
                                        reader[19].ToString(),                  //future1


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