[chronojump] Encoder moving smooth-2015.R to tests



commit 191116803c2fa98df10f46812aea15b9cd46c720
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Apr 13 19:53:16 2015 +0200

    Encoder moving smooth-2015.R to tests

 encoder/tests/smooth-2015.R |   33 +++++++++++++++++++++++++++++++++
 encoder/util.R              |    8 --------
 2 files changed, 33 insertions(+), 8 deletions(-)
---
diff --git a/encoder/tests/smooth-2015.R b/encoder/tests/smooth-2015.R
new file mode 100644
index 0000000..81e30dc
--- /dev/null
+++ b/encoder/tests/smooth-2015.R
@@ -0,0 +1,33 @@
+source("util.R")
+
+getSpeedByPosition <- function(displacement, smoothing) {
+       position <- cumsum(displacement)
+       position_smooth <- smooth.spline( 1:length(position), position, spar=smoothing)
+       speed = list()
+       speed$y <- diff(position_smooth$y)
+       speed$x <- 1:length(speed$y)
+       return(speed)
+       
+       #x <- 1:length(position)
+       #speed <- predict(lm(position~x), deriv=1)
+
+       #return(speed)
+}
+
+displacement = c(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 
0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 
1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 
0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1,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1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 
0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
+
+#fer reduceCurveBySpeed (que te un getSpeed)
+#de fet el que cal provar es dos metodes diferents de getSpeed
+
+speed = getSpeed(displacement, 0.7)
+
+speed2_02 = getSpeedByPosition(displacement, 0.2)
+speed2_05 = getSpeedByPosition(displacement, 0.5)
+speed2_07 = getSpeedByPosition(displacement, 0.7)
+
+png("speeds.png", width=1024, height=700)
+plot(speed$y, type="l")
+lines(speed2_02, col="red")
+lines(speed2_05, col="green")
+points(speed2_07, col="blue")
+dev.off()
diff --git a/encoder/util.R b/encoder/util.R
index 1fcf0e8..7d67363 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -56,7 +56,6 @@ assignOptions <- function(options) {
                    AnalysisOptions     = options[13],
                    EncoderConfigurationName =  options[14],    #just the name of the EncoderConfiguration    
  
                    diameter            = as.numeric(unlist(strsplit(options[15], "\\;"))), #comes in cm, 
will be converted to m. Since 1.5.1 can be different diameters separated by ;
-                   #diameter           = as.numeric(unlist(strsplit("1.5;1.5;1.5;1.5;2;2.5;2.7;2.9;2.95;3", 
"\\;"))), #comes in cm, will be converted to m. Since 1.5.1 can be different diameters separated by ;
                    diameterExt         = as.numeric(options[16]),      #comes in cm, will be converted to m
                    anglePush           = as.numeric(options[17]),
                    angleWeight         = as.numeric(options[18]),
@@ -208,13 +207,6 @@ getSpeed <- function(displacement, smoothing) {
 
        return (smooth.spline( 1:length(displacement), displacement, spar=smoothing))
 }
-#experimental. unused
-getSpeedByPosition <- function(displacement, smoothing) {
-       position <- cumsum(displacement)
-       speed <- smooth.spline( 1:length(position), position, spar=smoothing)
-       speed$y <- diff(speed$y)
-       return(speed)
-}
 
 getAcceleration <- function(speed) {
        #no change affected by encoderConfiguration


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