[chronojump] encoder races. Added laptimes each 5m.



commit 566bf1d8897a11a7ab0e78b508f490caae941e31
Author: Xavier Padullés <x padulles gmail com>
Date:   Tue Apr 17 12:49:21 2018 +0200

    encoder races. Added laptimes each 5m.

 r-scripts/maximumIsometricForce.R |    2 ++
 r-scripts/sprintEncoder.R         |   37 ++++++++++++++++++++++++++++++++++++-
 r-scripts/sprintPhotocells.R      |   31 +++++++++++++++----------------
 3 files changed, 53 insertions(+), 17 deletions(-)
---
diff --git a/r-scripts/maximumIsometricForce.R b/r-scripts/maximumIsometricForce.R
index c55703e..3dbe17a 100644
--- a/r-scripts/maximumIsometricForce.R
+++ b/r-scripts/maximumIsometricForce.R
@@ -733,6 +733,7 @@ readImpulseOptions <- function(optionsStr)
 }
 
 #Function to get the interpolated force at a given time in seconds)
+#TODO: use interpolateXAtY from scripts-util.R
 getForceAtTime <- function(time, force, desiredTime){
         #find the closest sample
         closestSample = which.min(abs(time - desiredTime))
@@ -759,6 +760,7 @@ getForceAtTime <- function(time, force, desiredTime){
 }
 
 #Function to get the interpolated time at a given force in N
+#TODO: use interpolateXAtY from scripts-util.R
 getTimeAtForce <- function(time, force, desiredForce){
         #find the closest sample
         nextSample = 1
diff --git a/r-scripts/sprintEncoder.R b/r-scripts/sprintEncoder.R
index 542c87c..ea3b4e6 100644
--- a/r-scripts/sprintEncoder.R
+++ b/r-scripts/sprintEncoder.R
@@ -93,11 +93,27 @@ drawSprintFromEncoder <- function(sprint, sprintDynamics, title = "Test graph")
              main = paste(50, "PPR"), xlab = "Time (s)", ylab = "Position (m)", type = "l")
         print(sprint$time)
         print(sprint$rawPosition)
-        raceTime = sprint$time[sprint$endSample]   #TODO: interpolate values as in force sensor.
+        raceTime = interpolateXAtY(sprint$time, sprint$rawPosition, sprint$testLength)
         abline(v = raceTime)
+        abline(h = sprint$testLength, lty = 3)
+        points(raceTime, sprint$testLength)
         mtext(side = 3, at = raceTime, text = paste(sprint$testLength, "m", sep=""))
         mtext(side = 1, at = raceTime, text = paste(round(raceTime, digits = 3), "s", sep=""))
         
+        #Calculing 5m lap times
+        lapPosition = 5
+        while(lapPosition < sprint$testLength)
+        {
+                lapTime = interpolateXAtY(sprint$time, sprint$rawPosition, lapPosition)
+                
+                abline(v = lapTime)
+                abline(h = lapPosition, lty = 3)
+                points(lapTime, lapPosition)
+                mtext(side = 3, at = lapTime, text = paste(lapPosition, "m", sep=""))
+                mtext(side = 1, at = lapTime, text = paste(round(lapTime, digits = 3), "s", sep=""))
+                lapPosition = lapPosition + 5
+        }
+        
         # Getting values from the exponential model. Used for numerical calculations
         time.fitted = seq(0,sprint$time[length(sprint$time)], by = 0.01)      
         v.fitted=sprintDynamics$Vmax.fitted*(1-exp(-sprintDynamics$K.fitted*time.fitted))
@@ -145,6 +161,25 @@ getTrimmingSamples <- function(totalTime, position, speed, accel, testLength)
         return(list(start = start, end = end ))
 }
 
+#Function to get the interpolated x at a given y
+#TODO: Include this function in scripts-util.R
+interpolateXAtY <- function(X, Y, desiredY){
+        #find the closest sample
+        nextSample = 1
+        while (Y[nextSample] < desiredY){
+                nextSample = nextSample +1
+        }
+        
+        previousSample = nextSample - 1
+        
+        if(Y[nextSample] == desiredY){
+                desiredX = X[nextSample]
+        } else {
+                desiredX = X[previousSample] + (desiredY  - Y[previousSample]) * (X[nextSample] - 
X[previousSample]) / (Y[nextSample] - Y[previousSample])
+        }
+        return(desiredX)
+}
+
 testEncoderCJ <- function(filename, testLength, mass, personHeight, tempC)
 {
         sprint = getSprintFromEncoder(filename, testLength)
diff --git a/r-scripts/sprintPhotocells.R b/r-scripts/sprintPhotocells.R
index c6baaef..a5a2249 100644
--- a/r-scripts/sprintPhotocells.R
+++ b/r-scripts/sprintPhotocells.R
@@ -34,12 +34,25 @@ options <- scan(optionsFile, comment.char="#", what=character(), sep="\n")
 #options[1] is scriptsPath
 source(paste(options[1], "/sprintUtil.R", sep=""))
 
+
+assignOptions <- function(options) {
+        return(list(
+                scriptsPath    = options[1],
+                positions      = as.numeric(unlist(strsplit(options[2], "\\;"))),
+                splitTimes     = as.numeric(unlist(strsplit(options[3], "\\;"))),
+                mass   = as.numeric(options[4]),
+                personHeight = as.numeric(options[5]),
+                tempC  = as.numeric(options[6]),
+                os             = options[7],
+                graphWidth     = as.numeric(options[8]),
+                graphHeight    = as.numeric(options[9])
+        ))
+}
+
 #-------------- assign options -------------
 op <- assignOptions(options)
 #print(op$positions)
 
-
-
 #Returns the K and Vmax parameters of the sprint using a number of pairs (time, position)
 getSprintFromPhotocell <- function(positions, splitTimes, noise=0)
 {
@@ -210,20 +223,6 @@ testPhotocellsCJ <- function(positions, splitTimes, mass, personHeight, tempC)
        drawSprintFromPhotocells(sprintDynamics = sprintDynamics, splitTimes, positions, title = "Testing 
graph")
 }
 
-assignOptions <- function(options) {
-        return(list(
-                scriptsPath    = options[1],
-                positions      = as.numeric(unlist(strsplit(options[2], "\\;"))),
-                splitTimes     = as.numeric(unlist(strsplit(options[3], "\\;"))),
-                mass   = as.numeric(options[4]),
-                personHeight = as.numeric(options[5]),
-                tempC  = as.numeric(options[6]),
-                os             = options[7],
-                graphWidth     = as.numeric(options[8]),
-                graphHeight    = as.numeric(options[9])
-        ))
-}
-
 #----- execute code
 
 prepareGraph(op$os, pngFile, op$graphWidth, op$graphHeight)


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