[chronojump] All encoder getSpeed calls are safe now



commit 76e8b3b2c9c5433f72d9e11b480c7d2434fc0821
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Apr 26 23:28:13 2017 +0200

    All encoder getSpeed calls are safe now

 encoder/graph.R                |    4 ++--
 encoder/graphSmoothingEC.R     |    2 +-
 encoder/neuromuscularProfile.R |   12 ++++++------
 encoder/util.R                 |   17 +++++++----------
 4 files changed, 16 insertions(+), 19 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 9c611ed..dd2d1e3 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -2755,7 +2755,7 @@ doProcess <- function(options)
                        maxPowerAtAnyRep <- 0
                        for(i in 1:n) {
                                i.displ <- displacement[curves[i,1]:curves[i,2]]        
-                               speed <- getSpeedSafe(i.displ, op$SmoothingOneC)
+                               speed <- getSpeed(i.displ, op$SmoothingOneC)
                                accel <- getAccelerationSafe(speed)
                                #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to 
m/s^2 need to *1000 because it's quadratic
                                accel$y <- accel$y * 1000 
@@ -2818,7 +2818,7 @@ doProcess <- function(options)
                        debugParameters(listN(x, y, maxPowerAtAnyRep, smoothingAll), "paint all smoothing 3")
 
                        #4) create dynamics data for this smoothing
-                       speed <- getSpeedSafe(displacementAllSet, smoothingAll)
+                       speed <- getSpeed(displacementAllSet, smoothingAll)
                        accel <- getAccelerationSafe(speed)
                        #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need 
to *1000 because it's quadratic
                        accel$y <- accel$y * 1000
diff --git a/encoder/graphSmoothingEC.R b/encoder/graphSmoothingEC.R
index 12c284e..d4fdfd3 100644
--- a/encoder/graphSmoothingEC.R
+++ b/encoder/graphSmoothingEC.R
@@ -300,7 +300,7 @@ smoothAllSetYPoints <- function(smooth.seq, displacement,
        count <- 1
        for (i in smooth.seq) {
                #print(c("i",i))
-               speed <- getSpeedSafe(displacement, i)
+               speed <- getSpeed(displacement, i)
                accel <- getAccelerationSafe(speed)
                #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 
because it's quadratic
                accel$y <- accel$y * 1000 
diff --git a/encoder/neuromuscularProfile.R b/encoder/neuromuscularProfile.R
index 268d489..c4429d8 100644
--- a/encoder/neuromuscularProfile.R
+++ b/encoder/neuromuscularProfile.R
@@ -47,7 +47,7 @@ neuromuscularProfileJump <- function(l.context, e1, c, mass, smoothingC)
 
        #e1f (when force is done)
        #from max(abs(speed$y)) at e1, to end of e1
-       e1.speed <- getSpeedSafe(e1, smoothingC)
+       e1.speed <- getSpeed(e1, smoothingC)
        e1.maxspeed.pos <- mean(which(abs(e1.speed$y) == max(abs(e1.speed$y))))
        e1f <- e1[e1.maxspeed.pos:length(e1)] #TODO: check if has to be determined by force > 0 or a > -9.81 
instead of maxspeed
 
@@ -58,7 +58,7 @@ neuromuscularProfileJump <- function(l.context, e1, c, mass, smoothingC)
        e1f.t <- length(e1f)
 
        #e1f.fmax <- max Force on e1f
-       e1f.speed <- getSpeedSafe(e1f, smoothingC)
+       e1f.speed <- getSpeed(e1f, smoothingC)
        e1f.accel <- getAccelerationSafe(e1f.speed)
        e1f.accel$y <- e1f.accel$y * 1000
        e1f.force <- mass * (e1f.accel$y + g)
@@ -89,7 +89,7 @@ neuromuscularProfileJump <- function(l.context, e1, c, mass, smoothingC)
        #----------------
 
        #find takeoff
-       c.speed <- getSpeedSafe(c, smoothingC)
+       c.speed <- getSpeed(c, smoothingC)
        c.accel = getAccelerationSafe(c.speed) 
        #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 because 
it's quadratic
        c.accel$y <- c.accel$y * 1000
@@ -120,7 +120,7 @@ neuromuscularProfileJump <- function(l.context, e1, c, mass, smoothingC)
        cl.t <- length(cl)
        
        #cl.rfd.avg = average force on cl / cl.t (s) / mass (Kg) #bars EXPLODE
-       cl.speed <- getSpeedSafe(cl, smoothingC)
+       cl.speed <- getSpeed(cl, smoothingC)
        cl.accel = getAccelerationSafe(cl.speed)
        #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 because 
it's quadratic
        cl.accel$y <- cl.accel$y * 1000
@@ -188,7 +188,7 @@ neuromuscularProfileGetData <- function(singleFile, displacement, curves, mass,
        count = 1
        for(i in seq(2,length(curves[,1]),by=2)) {
                d = displacement[curves[i,1]:curves[i,2]]
-               speed <- getSpeedSafe(d, smoothingC)
+               speed <- getSpeed(d, smoothingC)
                
                accel = getAccelerationSafe(speed) 
                #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 
because it's quadratic
@@ -342,7 +342,7 @@ neuromuscularProfilePlotOther <- function(displacement, l.context, l.mass, smoot
 
        for(i in 1:3) {
                d = displacement[as.integer(l.context[[i]]$start.e1):as.integer(l.context[[i]]$end.c)]
-               speed <- getSpeedSafe(d, smoothingC)
+               speed <- getSpeed(d, smoothingC)
 
                accel = getAccelerationSafe(speed) 
                #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 
because it's quadratic
diff --git a/encoder/util.R b/encoder/util.R
index 6fd6564..0199b7e 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -265,20 +265,17 @@ findDistanceAbsoluteEC <- function(position)
        return ( (maxA - minB) + (maxC - minB) )
 }
        
-
-getSpeedSafe <- function(displacement, smoothing) {
-       #x vector should contain at least 4 different values
-       if(length(displacement) >= 4)
-               return(getSpeed(displacement, smoothing))
-       else
-               return(list(y=rep(0,length(displacement))))
-}
 #unused since 1.6.0 because first and last displacement values make change too much the initial and end curve
 #getSpeedOld <- function(displacement, smoothing) {
 #      #no change affected by encoderConfiguration
 #      return (smooth.spline( 1:length(displacement), displacement, spar=smoothing))
 #}
-getSpeed <- function(displacement, smoothing) {
+getSpeed <- function(displacement, smoothing)
+{
+       #x vector should contain at least 4 different values
+       if(length(displacement) < 4)
+               return(list(y=rep(0,length(displacement))))
+
        #no change affected by encoderConfiguration
        
        #use position because this does not make erronously change the initial and end of the curve
@@ -532,7 +529,7 @@ kinematicsF <- function(displacement, repOp, smoothingOneEC, smoothingOneC, g, i
 
        print(c("repOp$eccon, smoothing:", repOp$eccon, smoothing))
 
-       speed <- getSpeedSafe(displacement, smoothing)
+       speed <- getSpeed(displacement, smoothing)
        
        accel <- getAccelerationSafe(speed)
        


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