[chronojump] Eccentric calculations use only ground phase



commit 799537c81991eabfc6c8f1eaac5be8a6f114643d
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Nov 30 19:46:26 2015 +0100

    Eccentric calculations use only ground phase

 encoder/graph.R |  181 ++++++++++++++++++++++++++++++-------------------------
 encoder/util.R  |   20 ++++++
 2 files changed, 120 insertions(+), 81 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 7ed26c0..dfcacd6 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -999,84 +999,6 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
        
 
 
-       meanSpeedC = mean(speed$y[min(concentric):max(concentric)])
-       if(isPropulsive) {
-               meanSpeedC = mean(speed$y[min(concentric):propulsiveEnd])
-       }
-
-       if(eccon == "c") {
-               if(showSpeed) {
-                       
arrows(x0=min(concentric),y0=meanSpeedC,x1=propulsiveEnd,y1=meanSpeedC,col=cols[1],code=3)
-               }
-       } else {
-               meanSpeedE = mean(speed$y[startX:max(eccentric)])
-               if(showSpeed) {
-                       arrows(x0=startX,y0=meanSpeedE,x1=max(eccentric),y1=meanSpeedE,col=cols[1],code=3)
-                       
arrows(x0=min(concentric),y0=meanSpeedC,x1=propulsiveEnd,y1=meanSpeedC,col=cols[1],code=3)
-               }
-       }
-
-       if(draw) {
-               ylimHeight = max(abs(range(accel$y)))
-               ylim=c(- 1.05 * ylimHeight, 1.05 * ylimHeight)  #put 0 in the middle, and have 5% margin at 
each side
-               if(knRanges[1] != "undefined")
-                       ylim = knRanges$accely
-
-               
-               #always (single or side) show 0 line
-               abline(h=0,lty=3,col="black")
-               
-               #plot the speed axis
-               if(showAxes & showSpeed) {
-                       if(eccon == "c") {
-                               axis(4, at=c(min(axTicks(4)),0,max(axTicks(4)),meanSpeedC),
-                                    labels=c(min(axTicks(4)),0,max(axTicks(4)),
-                                             round(meanSpeedC,1)),
-                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=1, padj=-.5)
-                               axis(4, at=meanSpeedC,
-                                    labels="Xc",
-                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=1, padj=-2)
-                       }
-                       else {
-                               axis(4, at=c(min(axTicks(4)),0,max(axTicks(4)),meanSpeedE,meanSpeedC),
-                                    labels=c(min(axTicks(4)),0,max(axTicks(4)),
-                                             round(meanSpeedE,1),
-                                             round(meanSpeedC,1)),
-                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=1, padj=-.5)
-                               axis(4, at=c(meanSpeedE,meanSpeedC),
-                                    labels=labelsXeXc,
-                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=0, padj=-2)
-                       }
-                       axisLineRight = axisLineRight +2
-               }
-
-               if(showAccel) {
-                       par(new=T)
-                       if(highlight==FALSE)
-                               plot(startX:length(accel$y),accel$y[startX:length(accel$y)],type="l",
-                                    
xlim=c(1,length(displacement)),ylim=ylim,xlab="",ylab="",col="magenta",lty=lty[2],lwd=1,axes=F)
-                       else
-                               plot(startX:length(accel$y),accel$y[startX:length(accel$y)],type="l",
-                                    
xlim=c(1,length(displacement)),ylim=ylim,xlab="",ylab="",col="darkblue",lty=2,lwd=3,axes=F)
-               }
-               
-               #show propulsive stuff if line if differentiation is relevant (propulsivePhase ends before 
the end of the movement)
-               if(isPropulsive & propulsiveEnd < length(displacement)) {
-                       #propulsive stuff
-                       segments(0,-9.81,length(accel$y),-9.81,lty=3,col="magenta")
-                       #abline(v=propulsiveEnd,lty=3,col="magenta") 
-                       abline(v=propulsiveEnd,lty=1,col=cols[2]) 
-                       points(propulsiveEnd, -g, col="magenta")
-                       text(x=length(accel$y),y=-9.81,labels=" g",cex=1,adj=c(0,0),col="magenta")
-               }
-               
-               if(showAxes & showAccel) {
-                       axis(4, col="magenta", lty=lty[1], line=axisLineRight, lwd=1, padj=-.5)
-                       axisLineRight = axisLineRight +2
-               }
-               #mtext(text=paste("max accel:",round(max(accel$y),3)),side=3,at=which(accel$y == 
max(accel$y)),cex=.8,col=cols[1],line=2)
-       }
-
        dynamics = getDynamics(encoderConfigurationName,
                        speed$y, accel$y, massBody, massExtra, exercisePercentBodyWeight, gearedDown, 
anglePush, angleWeight,
                        displacement, diameter, inertiaMomentum, smoothing)
@@ -1134,6 +1056,9 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
                        plot(dynamics$forceBody, col="blue", xlab="", ylab="", 
xlim=c(1,length(displacement)),ylim=ylim, type="p", pch=3, axes=F);
                }
        }
+       
+       #used to define the beginning of the ground phase       
+       landing = -1
 
        #mark when it's air and land
        #if it was a eccon concentric-eccentric, will be useful to calculate flight time
@@ -1182,7 +1107,6 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
                }
 
                if(eccon=="ec") {
-                       landing = -1
                        #landing = min(which(force>=weight))
                
                        if(length(which(force[eccentric] <= weight)) == 0)
@@ -1205,6 +1129,94 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
                              cex=.8,adj=0.5,col=cols[2])
                }
        }
+       
+       #speed (done here because of landing)
+       meanSpeedC = mean(speed$y[min(concentric):max(concentric)])
+       if(isPropulsive) {
+               meanSpeedC = mean(speed$y[min(concentric):propulsiveEnd])
+       }
+
+       if(eccon == "c") {
+               if(showSpeed) {
+                       
arrows(x0=min(concentric),y0=meanSpeedC,x1=propulsiveEnd,y1=meanSpeedC,col=cols[1],code=3)
+               }
+       } else {
+               if(landing == -1)
+                       meanSpeedE = mean(speed$y[startX:max(eccentric)])
+               else
+                       meanSpeedE = mean(speed$y[landing:max(eccentric)])
+
+               if(showSpeed) {
+                       if(landing == -1)
+                               
arrows(x0=startX,y0=meanSpeedE,x1=max(eccentric),y1=meanSpeedE,col=cols[1],code=3)
+                       else
+                               
arrows(x0=landing,y0=meanSpeedE,x1=max(eccentric),y1=meanSpeedE,col=cols[1],code=3)
+
+                       
arrows(x0=min(concentric),y0=meanSpeedC,x1=propulsiveEnd,y1=meanSpeedC,col=cols[1],code=3)
+               }
+       }
+
+       if(draw) {
+               ylimHeight = max(abs(range(accel$y)))
+               ylim=c(- 1.05 * ylimHeight, 1.05 * ylimHeight)  #put 0 in the middle, and have 5% margin at 
each side
+               if(knRanges[1] != "undefined")
+                       ylim = knRanges$accely
+
+               
+               #always (single or side) show 0 line
+               abline(h=0,lty=3,col="black")
+               
+               #plot the speed axis
+               if(showAxes & showSpeed) {
+                       if(eccon == "c") {
+                               axis(4, at=c(min(axTicks(4)),0,max(axTicks(4)),meanSpeedC),
+                                    labels=c(min(axTicks(4)),0,max(axTicks(4)),
+                                             round(meanSpeedC,1)),
+                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=1, padj=-.5)
+                               axis(4, at=meanSpeedC,
+                                    labels="Xc",
+                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=1, padj=-2)
+                       }
+                       else {
+                               axis(4, at=c(min(axTicks(4)),0,max(axTicks(4)),meanSpeedE,meanSpeedC),
+                                    labels=c(min(axTicks(4)),0,max(axTicks(4)),
+                                             round(meanSpeedE,1),
+                                             round(meanSpeedC,1)),
+                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=1, padj=-.5)
+                               axis(4, at=c(meanSpeedE,meanSpeedC),
+                                    labels=labelsXeXc,
+                                    col=cols[1], lty=lty[1], line=axisLineRight, lwd=0, padj=-2)
+                       }
+                       axisLineRight = axisLineRight +2
+               }
+
+               if(showAccel) {
+                       par(new=T)
+                       if(highlight==FALSE)
+                               plot(startX:length(accel$y),accel$y[startX:length(accel$y)],type="l",
+                                    
xlim=c(1,length(displacement)),ylim=ylim,xlab="",ylab="",col="magenta",lty=lty[2],lwd=1,axes=F)
+                       else
+                               plot(startX:length(accel$y),accel$y[startX:length(accel$y)],type="l",
+                                    
xlim=c(1,length(displacement)),ylim=ylim,xlab="",ylab="",col="darkblue",lty=2,lwd=3,axes=F)
+               }
+               
+               #show propulsive stuff if line if differentiation is relevant (propulsivePhase ends before 
the end of the movement)
+               if(isPropulsive & propulsiveEnd < length(displacement)) {
+                       #propulsive stuff
+                       segments(0,-9.81,length(accel$y),-9.81,lty=3,col="magenta")
+                       #abline(v=propulsiveEnd,lty=3,col="magenta") 
+                       abline(v=propulsiveEnd,lty=1,col=cols[2]) 
+                       points(propulsiveEnd, -g, col="magenta")
+                       text(x=length(accel$y),y=-9.81,labels=" g",cex=1,adj=c(0,0),col="magenta")
+               }
+               
+               if(showAxes & showAccel) {
+                       axis(4, col="magenta", lty=lty[1], line=axisLineRight, lwd=1, padj=-.5)
+                       axisLineRight = axisLineRight +2
+               }
+               #mtext(text=paste("max accel:",round(max(accel$y),3)),side=3,at=which(accel$y == 
max(accel$y)),cex=.8,col=cols[1],line=2)
+       }
+
 
 
        if(draw & showPower) {
@@ -1238,8 +1250,15 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
                if(eccon == "c") {
                        
arrows(x0=min(concentric),y0=meanPowerC,x1=propulsiveEnd,y1=meanPowerC,col=cols[3],code=3)
                } else {
-                       meanPowerE = mean(power[startX:max(eccentric)])
-                       arrows(x0=startX,y0=meanPowerE,x1=max(eccentric),y1=meanPowerE,col=cols[3],code=3)
+                       if(landing == -1) {
+                               meanPowerE = mean(power[startX:max(eccentric)])
+                               
arrows(x0=startX,y0=meanPowerE,x1=max(eccentric),y1=meanPowerE,col=cols[3],code=3)
+                       }
+                       else {
+                               meanPowerE = mean(power[landing:max(eccentric)])
+                               
arrows(x0=landing,y0=meanPowerE,x1=max(eccentric),y1=meanPowerE,col=cols[3],code=3)
+                       }
+
                        
arrows(x0=min(concentric),y0=meanPowerC,x1=propulsiveEnd,y1=meanPowerC,col=cols[3],code=3)
                }
 
diff --git a/encoder/util.R b/encoder/util.R
index c7c66e8..b4a044b 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -459,6 +459,26 @@ kinematicsF <- function(displacement, massBody, massExtra, exercisePercentBodyWe
        start <- 1
        end <- length(speed$y)
 
+
+       #on "e", "ec", start on ground
+       if(! isInertial(encoderConfigurationName) && (eccon == "e" || eccon == "ec")) {
+               #if eccentric is undefined, find it
+               if(eccentric == 0) {
+                       if(eccon == "e")
+                               eccentric = 1:length(displacement)
+                       else {  #(eccon=="ec")
+                               phases=findECPhases(displacement,speed$y)
+                               eccentric = phases$eccentric
+                       }
+               }
+               
+               weight = mass * g
+               if(length(which(force[eccentric] <= weight)) > 0) {
+                       landing = max(which(force[eccentric]<=weight))
+                       start = landing
+               }
+       }
+
        if( isPropulsive && ( eccon== "c" || eccon == "ec" ) )
                end <- propulsiveEnd
 


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