[chronojump] Fixed reduceCurveBySpeed on 1 cross aftr maxSpeedT



commit 3c8f1939c6bc6462a7bcb3039d80206f76197017
Author: Xavier de Blas <xaviblas gmail com>
Date:   Thu Jul 4 20:57:53 2013 +0200

    Fixed reduceCurveBySpeed on 1 cross aftr maxSpeedT

 encoder/graph.R                   |   17 ++++++++++++++---
 encoder/pyserial_pyper.py         |    3 ++-
 encoder/pyserial_pyper_windows.py |    3 ++-
 3 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index b09b96f..67533f1 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -196,6 +196,7 @@ reduceCurveBySpeed <- function(eccon, row, startT, rawdata, smoothingOneEC, smoo
                smoothing = smoothingOneC
 
        speed <- smooth.spline( 1:length(a), a, spar=smoothing) 
+       
        b=extrema(speed$y)
 
        #from searchValue, go to the left, searchValue is at max speed on going up
@@ -216,7 +217,8 @@ reduceCurveBySpeed <- function(eccon, row, startT, rawdata, smoothingOneEC, smoo
        if(bcrossLen == 0)
                x.ini = 0
        else if(bcrossLen == 1)
-               x.ini = b$cross[,2]
+               if(b$cross[,2] < maxSpeedT) 
+                       x.ini = b$cross[,2]
        else 
                for(i in b$cross[,2]) 
                        if(i < maxSpeedT) 
@@ -300,8 +302,17 @@ kinematicsF <- function(a, mass, smoothingOneEC, smoothingOneC, g, eccon, analys
        else
                smoothing = smoothingOneEC
 
-       speed <- smooth.spline( 1:length(a), a, spar=smoothing)
-       accel <- predict( speed, deriv=1 )
+       #x vector should contain at least 4 different values
+       if(length(a) >= 4)
+               speed <- smooth.spline( 1:length(a), a, spar=smoothing)
+       else
+               speed=list(y=rep(0,length(a)))
+       
+       if(length(a) >= 4)
+               accel <- predict( speed, deriv=1 )
+       else
+               accel=list(y=rep(0,length(a)))
+       
        #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 
        errorSearching = FALSE
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index a624391..7bee9b7 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -197,7 +197,8 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now,
                        if bcrossLen == 0:
                                x_ini = 0
                        if bcrossLen == 1:
-                               x_ini = bcross  #if bcross has only one item, then this fails: 'bcross[0]'. 
Just do 'bcross'
+                               if bcross < maxSpeedT:
+                                       x_ini = bcross  #if bcross has only one item, then this fails: 
'bcross[0]'. Just do 'bcross'
                        else:
                                x_ini = bcross[0]       #not 1, we are in python now
                                for i in bcross:
diff --git a/encoder/pyserial_pyper_windows.py b/encoder/pyserial_pyper_windows.py
index 75b06fb..e83e532 100644
--- a/encoder/pyserial_pyper_windows.py
+++ b/encoder/pyserial_pyper_windows.py
@@ -210,7 +210,8 @@ def calculate_all_in_r(temp, top_values, bottom_values, direction_now,
                        if bcrossLen == 0:
                                x_ini = 0
                        if bcrossLen == 1:
-                               x_ini = bcross  #if bcross has only one item, then this fails: 'bcross[0]'. 
Just do 'bcross'
+                               if bcross < maxSpeedT:
+                                       x_ini = bcross  #if bcross has only one item, then this fails: 
'bcross[0]'. Just do 'bcross'
                        else:
                                x_ini = bcross[0]       #not 1, we are in python now
                                for i in bcross:


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