[chronojump] Doing encoder con-ecc li,ri power calculation



commit b7503575ead60a92d37d19dd1603ac4e992b8a91
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Jul 30 16:45:31 2013 +0200

    Doing encoder con-ecc li,ri power calculation

 encoder/graph.R    |   68 +++++++++++++++++++++++++++++++++++++++++++--------
 src/gui/encoder.cs |   61 +++++++++++++++++++++-------------------------
 2 files changed, 85 insertions(+), 44 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 7aa3cc9..6e9ecfd 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -515,7 +515,7 @@ kinematicRanges <- function(singleFile,rawdata,curves,mass,smoothingOneEC,smooth
 
 paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highlight,
        startX, startH, smoothingOneEC, smoothingOneC, mass, title, subtitle, draw, showLabels, marShrink, 
showAxes, legend,
-       Analysis, isPropulsive, isRotatoryInertial, exercisePercentBodyWeight 
+       Analysis, isPropulsive, inertialType, exercisePercentBodyWeight 
        ) {
 
        meanSpeedE = 0
@@ -609,7 +609,7 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
        
                speedPlot=speed$y
                #on rotatory inertial, concentric-eccentric, plot speed as ABS)
-               #if(isRotatoryInertial && eccon == "ce")
+               #if(inertialType == "ri" && eccon == "ce")
                #       speedPlot=abs(speed$y)
 
                if(highlight==FALSE)
@@ -691,7 +691,7 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
        }
                
        #on rotatory inertial, concentric-eccentric, use speed as ABS)
-       #if(isRotatoryInertial && eccon == "ce")
+       #if(inertialType == "ri" && eccon == "ce")
        #       speed$y=abs(speed$y)
 
        accel <- predict( speed, deriv=1 )
@@ -827,7 +827,38 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
        #F=m*a          #bar
        #F=(m*a)+(m*g) #jump m*(a+g) F=m*0
 
-       power <- force*speed$y
+
+
+       power = NULL
+
+       if(inertialType == "li" || inertialType == "ri") {
+               #Explanation rotatory encoder on inertial machine
+               #speed$y comes in mm/ms, is the same than m/s
+               #speedw in meters:
+               speedw <- speed$y/0.0125 #m radius
+               #accel$y comes in meters
+               #accelw in meters:
+               accelw <- accel$y/0.0125
+
+               #inertia momentums
+               #meters: 0.010
+               #meters: 0.067
+
+               #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  
+               power <- 0.067 * accelw * speedw + mass * accel$y * speed$y
+       }
+       else #(inertialType == "")
+               power <- force*speed$y
+
+
+       print(c("mass",mass))
+       print(c("speed$y",speed$y))
+       print(c("speedw",speedw))
+       print(c("accel$y",accel$y))
+       print(c("accelw",accelw))
+       print(c("power",power))
+
        if(draw) {
                ylim=c(-max(abs(range(power))),max(abs(range(power))))  #put 0 in the middle
                if(knRanges[1] != "undefined")
@@ -882,9 +913,24 @@ paint <- function(rawdata, eccon, xmin, xmax, yrange, knRanges, superpose, highl
        if(draw & !superpose) {
                abline(v=peakPowerT, col=cols[3])
                points(peakPowerT, max(power),col=cols[3])
-               mtext(text=paste(round(max(power),1),"W",sep=""),side=3,at=peakPowerT,cex=.8,col=cols[3])
+               
mtext(text=paste(round(max(power),1),"W",sep=""),side=3,at=peakPowerT,adj=0,cex=.8,col=cols[3])
                mtext(text=peakPowerT,side=1,at=peakPowerT,cex=.8,col=cols[3])
        }
+       #time to arrive to peak power negative on con-ecc
+       if(eccon=="ce") {
+               peakPowerTneg=min(which(power == min(power)))
+               if(draw & !superpose) {
+                       abline(v=peakPowerTneg, col=cols[3])
+                       points(peakPowerTneg, min(power),col=cols[3])
+                       
mtext(text=paste(round(min(power),1),"W",sep=""),side=3,at=peakPowerTneg,adj=1,cex=.8,col=cols[3])
+                       mtext(text=peakPowerTneg,side=1,at=peakPowerTneg,cex=.8,col=cols[3])
+               }
+
+               segments(peakPowerTneg,min(power),peakPowerT,min(power),lty=3,col="red")
+               segments(peakPowerTneg,max(power),peakPowerT,max(power),lty=3,col="red")
+               points(peakPowerTneg,(min(power) * -1),col="red")
+               points(peakPowerT,(max(power) * -1),col="red")
+       }
 
        #legend, axes and title
        if(draw) {
@@ -1363,8 +1409,8 @@ doProcess <- function(options) {
        #if nothing: "-;-;-"
        analysisOptionsTemp = unlist(strsplit(AnalysisOptions, "\\;"))
        isPropulsive = (analysisOptionsTemp[1] == "p")
-       isRotatoryInertial = (analysisOptionsTemp[2] == "ri")
-       inertiaMomentum = analysisOptionsTemp[3]
+       inertialType = analysisOptionsTemp[2] #values: "" || "li" || "ri"
+       inertialMomentum = analysisOptionsTemp[3]
 
        
        if(Analysis != "exportCSV") {
@@ -1525,7 +1571,7 @@ doProcess <- function(options) {
                        quit()
                }
 
-               if(isRotatoryInertial) 
+               if(inertialType == "ri") 
                        rawdata = fixRawdataRI(rawdata)
                
                curves=findCurves(rawdata, Eccon, MinHeight, curvesPlot, Title)
@@ -1615,7 +1661,7 @@ doProcess <- function(options) {
                              FALSE,    #marShrink
                              TRUE,     #showAxes
                              TRUE,     #legend
-                             Analysis, isPropulsive, isRotatoryInertial, myExPercentBodyWeight 
+                             Analysis, isPropulsive, inertialType, myExPercentBodyWeight 
                              ) 
                }
        }
@@ -1656,7 +1702,7 @@ doProcess <- function(options) {
                              TRUE,     #marShrink
                              FALSE,    #showAxes
                              FALSE,    #legend
-                             Analysis, isPropulsive, isRotatoryInertial, myExPercentBodyWeight 
+                             Analysis, isPropulsive, inertialType, myExPercentBodyWeight 
                              )
                }
                par(mfrow=c(1,1))
@@ -1692,7 +1738,7 @@ doProcess <- function(options) {
 #                            FALSE,    #marShrink
 #                            (i==1),   #showAxes
 #                            TRUE,     #legend
-#                            Analysis, isPropulsive, isRotatoryInertial, ExercisePercentBodyWeight 
+#                            Analysis, isPropulsive, inertialType, ExercisePercentBodyWeight 
 #                            )
 #                      par(new=T)
 #              }
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 58b4cce..49e5a0d 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -550,6 +550,31 @@ public partial class ChronoJumpWindow
                }
        }
 
+       private string getEncoderAnalysisOptions(bool captureOrAnalyze) {
+               //capture == true; analyze == false
+
+               string analysisOptions = "-";
+               if(encoderPropulsive)
+                       analysisOptions = "p";
+
+               //inertial momentum with '.' for R
+               string im = Util.ConvertToPoint((double) spin_encoder_capture_inertial.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;
+                               else    //(radiobutton_encoder_capture_linear.Active || 
radiobutton_encoder_capture_linear_inverted.Active)
+                                       analysisOptions += ";li;" + im;
+                       } else 
+                               analysisOptions += ";-;-";
+               }
+
+               return analysisOptions;
+       }
+
+
        //this is called by non gtk thread. Don't do gtk stuff here
        //I suppose reading gtk is ok, changing will be the problem
        //called on calculatecurves, recalculate and load
@@ -557,16 +582,7 @@ public partial class ChronoJumpWindow
        {
                string analysis = "curves";
 
-               string analysisOptions = "-";
-               if(encoderPropulsive)
-                       analysisOptions = "p";
-               
-               //if(capturingRotaryInertial)
-               if(radiobutton_encoder_capture_rotary.Active && checkbutton_encoder_capture_inertial.Active)
-                       analysisOptions += ";ri;" + Util.ConvertToPoint( //inertial momentum with '.' for R
-                                       (double) spin_encoder_capture_inertial.Value);
-               else 
-                       analysisOptions += ";-;-";
+               string analysisOptions = getEncoderAnalysisOptions(true);
 
                string future3 = getEncoderTypeByCombos();
                
@@ -1146,16 +1162,7 @@ public partial class ChronoJumpWindow
        
        void on_button_encoder_export_all_curves_file_selected (string selectedFileName) 
        {
-               string analysisOptions = "-";
-               if(encoderPropulsive)
-                       analysisOptions = "p";
-               
-               //if(capturingRotaryInertial)
-               if(radiobutton_encoder_capture_rotary.Active && checkbutton_encoder_capture_inertial.Active)
-                       analysisOptions += ";ri;" + Util.ConvertToPoint( //inertial momentum with '.' for R
-                                       (double) spin_encoder_capture_inertial.Value);
-               else 
-                       analysisOptions += ";-;-";
+               string analysisOptions = getEncoderAnalysisOptions(true);
 
                string displacedMass = Util.ConvertToPoint( lastEncoderSQL.extraWeight + (
                                        getExercisePercentBodyWeightFromName(lastEncoderSQL.exerciseName) *
@@ -1734,19 +1741,7 @@ public partial class ChronoJumpWindow
                EncoderParams ep = new EncoderParams();
                string dataFileName = "";
                
-               string analysisOptions = "-";
-               if(encoderPropulsive)
-                       analysisOptions = "p";
-                       
-               //if(capturingRotaryInertial)
-               if(
-                               radiobutton_encoder_analyze_data_current_signal.Active &&
-                               radiobutton_encoder_capture_rotary.Active && 
-                               checkbutton_encoder_capture_inertial.Active )
-                       analysisOptions += ";ri;" + Util.ConvertToPoint( //inertial momentum with '.' for R
-                                       (double) spin_encoder_capture_inertial.Value);
-               else 
-                       analysisOptions += ";-;-";
+               string analysisOptions = getEncoderAnalysisOptions(false);
 
                //use this send because we change it to send it to R
                //but we don't want to change encoderAnalysis because we want to know again if == "cross" 


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