[chronojump] Reorganized graph.R code
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Reorganized graph.R code
- Date: Thu, 11 Feb 2016 19:00:18 +0000 (UTC)
commit 5e938423210e4ebb9903253bc3f4480905e6ae30
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Feb 11 19:58:19 2016 +0100
Reorganized graph.R code
encoder/Makefile.am | 1 +
encoder/call_graph.R | 1 +
encoder/graph.R | 243 -----------------------------------------
encoder/graphSmoothingEC.R | 261 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 263 insertions(+), 243 deletions(-)
---
diff --git a/encoder/Makefile.am b/encoder/Makefile.am
index 9edd899..90a437e 100644
--- a/encoder/Makefile.am
+++ b/encoder/Makefile.am
@@ -5,6 +5,7 @@ dist_encoderdata_DATA = pyserial_pyper.py \
call_graph.R \
capture.R \
graph.R \
+ graphSmoothingEC.R \
inertia-momentum.R \
neuromuscularProfile.R \
util.R
diff --git a/encoder/call_graph.R b/encoder/call_graph.R
index 58daf63..6503e4e 100644
--- a/encoder/call_graph.R
+++ b/encoder/call_graph.R
@@ -28,6 +28,7 @@ English = unlist(strsplit(options[28], "\\;"))
Translated = unlist(strsplit(options[29], "\\;"))
source(paste(options[4], "/util.R", sep=""))
+source(paste(options[4], "/graphSmoothingEC.R", sep=""))
#Note:
diff --git a/encoder/graph.R b/encoder/graph.R
index 90f3f3b..d0e959b 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -472,249 +472,6 @@ findCurvesNew <- function(displacement, eccon, inertial, min_height, draw, title
return(as.data.frame(cbind(startStored,endStored,startHStored)))
}
-
-findSmoothingsECGetPowerNI <- function(speed)
-{
- acceleration <- getAcceleration(speed)
- acceleration$y <- acceleration$y * 1000
- force <- 50 * (acceleration$y + 9.81) #Do always with 50Kg right now. TODO: See if there's a need of
real mass value
- power <- force * speed$y
- return(power)
-}
-findSmoothingsECGetPowerI <- function(displacement, encoderConfigurationName, diameter, massTotal,
inertiaMomentum, smoothing)
-{
- dynamics = getDynamicsInertial(encoderConfigurationName, displacement, diameter, massTotal,
inertiaMomentum, smoothing)
- return(dynamics$power)
-}
-splinesPredict <- function(x,y)
-{
- smodel = smooth.spline(y,x)
- #plot(x,y)
- for (i in seq(y[1], y[length(y)], length.out=30)) {
- predicted <- predict(smodel,i)
- #points(predicted$y, predicted$x, col="red")
- }
- return(smodel)
-
-}
-findSmoothingsECYPoints <- function(eccentric.concentric, conStart, conEnd, x, maxPowerConAtCon,
- encoderConfigurationName, diameter, massTotal, inertiaMomentum)
-{
- y <- NULL
- count <- 1
- for(j in x)
- {
- speed <- getSpeed(eccentric.concentric, j)
- smoothingOneEC = j
-
- powerTemp = NULL
- if(! isInertial(encoderConfigurationName) )
- powerTemp <- findSmoothingsECGetPowerNI(speed)
- else
- powerTemp <- findSmoothingsECGetPowerI(eccentric.concentric,
encoderConfigurationName,
- diameter, massTotal, inertiaMomentum,
smoothingOneEC)
-
- #find the max power in concentric phase of this ecc-con movement
- maxPowerConAtFullrep <- max(powerTemp[conStart:conEnd])
- y[count] = maxPowerConAtFullrep
-
- #write("kkYPoints", stderr())
- #write(paste("smoothingOneEC, maxPowerConAtFullrep, maxPowerConAtCon, diff",
- # smoothingOneEC,
- # round(maxPowerConAtFullrep,2),
- # round(maxPowerConAtCon,2),
- # round( (maxPowerConAtFullrep - maxPowerConAtCon),2 ))
- #, stderr())
-
- count <- count +1
- }
-
- return(y)
-}
-
-#called on "ec" and "ce" to have a smoothingOneEC for every curve
-#this smoothingOneEC has produce same speeds than smoothing "c"
-findSmoothingsEC <- function(singleFile, displacement, curves, eccon, smoothingOneC,
- singleFileEncoderConfigurationName, singleFileDiameter,
singleFileInertiaMomentum)
-{
- ptm <- as.vector(proc.time()[3])
- write("time start", stderr())
- write(ptm, stderr())
-
- #print(c("findSmoothingsEC: eccon smoothingOneC", eccon, smoothingOneC))
-
- smoothings = NULL
- n=length(curves[,1])
-
- #if not "ec" or "ce" just have a value of 0 every curve,
- #no problem, this value will not be used
- #is just to not make crash other parts of the software like reduceCurveBySpeed
- if(eccon != "ec" && eccon != "ce") {
- for(i in 1:n) {
- smoothings[i] = 0
- }
- } else {
- #on every curve...
- for(i in 1:n) {
- #maybe the global eccon == "ec" or "ce" but the individual eccon of each curve is
"c", then just do the same as above
- if( (singleFile && eccon == "c") || (! singleFile && curves[i,8] == "c") )
- smoothings[i] = 0
- else {
-#0 find concentric
- eccentric.concentric = displacement[curves[i,1]:curves[i,2]]
-
- #get the position
- position=cumsum(displacement[curves[i,1]:curves[i,2]])
-
- #analyze the "c" phase
- #Note dividing phases can be done using the speed,
- #but there's no need of this small difference here
- conStart = 0
- conEnd = 0
- if(eccon=="ec") {
- conStart = mean(which(position == min(position)))
- conEnd = length(position) -1
- #the -1 is because the line below: "concentric=" will fail in
curves[i,1]+end
- #and will add an NA
- } else { #(eccon=="ce")
- conStart = 0
- conEnd = mean(which(position == max(position)))
- }
-
- concentric=displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)]
-
-#1 get max power concentric at concentric phase with current smoothing
-
- speed <- getSpeed(concentric, smoothingOneC)
-
- #assign values from Roptions.txt (singleFile), or from curves
- myEncoderConfigurationName = singleFileEncoderConfigurationName;
- myDiameter = singleFileDiameter;
- myInertiaMomentum = singleFileInertiaMomentum;
- if(! singleFile) {
- myEncoderConfigurationName = curves[i,11];
- myDiameter = curves[i,12];
- myInertiaMomentum = curves[i,16];
- }
-
- powerTemp = NULL
- if(! isInertial(myEncoderConfigurationName) )
- powerTemp <- findSmoothingsECGetPowerNI(speed)
- else
- powerTemp <- findSmoothingsECGetPowerI(concentric,
myEncoderConfigurationName,
- myDiameter, 100,
myInertiaMomentum, smoothingOneC)
-
- maxPowerConAtCon <- max(powerTemp)
-
-#2 get max power concentric (y) at eccentric-concentric phase with current smoothing of an interval of
possible smoothings (x)
-
- x <- seq(from = as.numeric(smoothingOneC),
- to = as.numeric(smoothingOneC)/2,
- length.out = 5)
- y <- findSmoothingsECYPoints(eccentric.concentric, conStart, conEnd, x,
maxPowerConAtCon,
- myEncoderConfigurationName, myDiameter, 100,
myInertiaMomentum)
- #write(paste("x, y", x, y), stderr())
-
-
- smodel <- splinesPredict(x,y)
- smoothingOneEC <- predict(smodel, maxPowerConAtCon)$y
- write(paste("smoothingOneEC", smoothingOneEC), stderr())
-
- #check how it worked
-
- speed <- getSpeed(eccentric.concentric, smoothingOneEC)
-
- if(! isInertial(myEncoderConfigurationName) )
- powerTemp <- findSmoothingsECGetPowerNI(speed)
- else
- powerTemp <- findSmoothingsECGetPowerI( eccentric.concentric,
myEncoderConfigurationName,
- myDiameter, 100,
myInertiaMomentum, smoothingOneEC)
-
- #find the max power in concentric phase of this ecc-con movement
- maxPowerConAtFullrep <- max(powerTemp[conStart:conEnd])
-
-#3 check if first aproximation is OK
-
- #write(paste("MID i, smoothingOneEC, maxPowerConAtFullrep, maxPowerConAtCon,
diff",
- # i, smoothingOneEC,
- # round(maxPowerConAtFullrep,2),
- # round(maxPowerConAtCon,2),
- # round( (maxPowerConAtFullrep - maxPowerConAtCon),2 ))
- #, stderr())
-
-#4 create new x values closer
-
- #eg
- #x: .7, .6125, .525, .4375, .35
- #y: 1156, 1190 , 1340 , 1736 , 2354
- #lowerValue ald it's lowerPos are reffered to the x vector. 1 means the first
(0.7)
- #A) if we find the x for an y = 1900, x should be between .4375 (lowerValue)
and .35 (upperValue)
- #B) if we find the x for an y = 2500, x should be between .35 (lowerValue)
and (right of .35) (upperValue)
- #C) if we find the x for an y = 1000, x should be between (left of .7)
(lowerValue) and .7 (upperValue)
-
- xUpperValue = NULL
- xLowerValue = NULL
-
- upperPos <- min(which(y > maxPowerConAtCon)) #A: 5, C:1
- if(is.infinite(upperPos)) {
- xUpperValue <- x[length(x)] - (x[length(x) -1] - x[length(x)]) #B:
.35 - (.4375-.35) = .2625
- xLowerValue <- x[length(x)] #B:
.35
- }
- else {
- xUpperValue <- x[upperPos] #A: .35
- lowerPos <- upperPos -1
-
- if(lowerPos >= 1)
- xLowerValue <- x[lowerPos] #A: .4375
- else
- xLowerValue <- x[1] + (x[1] - x[2]) #C: .7 + (.7-.6125) =
.7875
- }
-
-
-#5 get max power concentric (y) at eccentric-concentric phase with current smoothing of an interval of
possible smoothings (x)
-
- x <- seq(
- from = xUpperValue,
- to = xLowerValue,
- length.out = 5)
- y <- findSmoothingsECYPoints(eccentric.concentric, conStart, conEnd, x,
maxPowerConAtCon,
- myEncoderConfigurationName, myDiameter, 100,
myInertiaMomentum)
-
-
- smodel <- splinesPredict(x,y)
- smoothingOneEC <- predict(smodel, maxPowerConAtCon)$y
-
-#6 check if aproximation is OK
-
- if(! isInertial(myEncoderConfigurationName) )
- powerTemp <- findSmoothingsECGetPowerNI(speed)
- else
- powerTemp <- findSmoothingsECGetPowerI( eccentric.concentric,
myEncoderConfigurationName,
- myDiameter, 100,
myInertiaMomentum, smoothingOneEC)
-
- #find the max power in concentric phase of this ecc-con movement
- maxPowerConAtFullrep <- max(powerTemp[conStart:conEnd])
-
- write(paste("FINAL smooth EC: i, smoothingOneEC, maxPowerConAtFullrep,
maxPowerConAtCon, diff",
- i, smoothingOneEC,
- round(maxPowerConAtFullrep,2),
- round(maxPowerConAtCon,2),
- round( (maxPowerConAtFullrep - maxPowerConAtCon),2 ))
- , stderr())
-
- #use smoothingOneEC
- smoothings[i] = smoothingOneEC
- }
- }
- }
-
- write("time end", stderr())
- write(as.vector(proc.time()[3]) - ptm, stderr())
-
- return(smoothings)
-}
-
-
kinematicRanges <- function(singleFile, displacement, curves,
massBody, massExtra, exercisePercentBodyWeight,
encoderConfigurationName,diameter,diameterExt,anglePush,angleWeight,inertiaMomentum,gearedDown,
diff --git a/encoder/graphSmoothingEC.R b/encoder/graphSmoothingEC.R
new file mode 100644
index 0000000..6112680
--- /dev/null
+++ b/encoder/graphSmoothingEC.R
@@ -0,0 +1,261 @@
+#
+# This file is part of ChronoJump
+#
+# ChronoJump is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# ChronoJump is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Copyright (C) 2004-2015 Xavier de Blas <xaviblas gmail com>
+# Copyright (C) 2014-2015 Xavier Padullés <x padulles gmail com>
+#
+
+findSmoothingsECGetPowerNI <- function(speed)
+{
+ acceleration <- getAcceleration(speed)
+ acceleration$y <- acceleration$y * 1000
+ force <- 50 * (acceleration$y + 9.81) #Do always with 50Kg right now. TODO: See if there's a need of
real mass value
+ power <- force * speed$y
+ return(power)
+}
+findSmoothingsECGetPowerI <- function(displacement, encoderConfigurationName, diameter, massTotal,
inertiaMomentum, smoothing)
+{
+ dynamics = getDynamicsInertial(encoderConfigurationName, displacement, diameter, massTotal,
inertiaMomentum, smoothing)
+ return(dynamics$power)
+}
+#splinesPredictGraph <- function(x,y)
+#{
+# smodel = smooth.spline(y,x)
+# plot(x,y)
+# for (i in seq(y[1], y[length(y)], length.out=30)) {
+# predicted <- predict(smodel,i)
+# points(predicted$y, predicted$x, col="red")
+# }
+# return(smodel)
+#
+#}
+findSmoothingsECYPoints <- function(eccentric.concentric, conStart, conEnd, x, maxPowerConAtCon,
+ encoderConfigurationName, diameter, massTotal, inertiaMomentum)
+{
+ y <- NULL
+ count <- 1
+ for(j in x)
+ {
+ speed <- getSpeed(eccentric.concentric, j)
+ smoothingOneEC = j
+
+ powerTemp = NULL
+ if(! isInertial(encoderConfigurationName) )
+ powerTemp <- findSmoothingsECGetPowerNI(speed)
+ else
+ powerTemp <- findSmoothingsECGetPowerI(eccentric.concentric,
encoderConfigurationName,
+ diameter, massTotal, inertiaMomentum,
smoothingOneEC)
+
+ #find the max power in concentric phase of this ecc-con movement
+ maxPowerConAtFullrep <- max(powerTemp[conStart:conEnd])
+ y[count] = maxPowerConAtFullrep
+
+ #write("kkYPoints", stderr())
+ #write(paste("smoothingOneEC, maxPowerConAtFullrep, maxPowerConAtCon, diff",
+ # smoothingOneEC,
+ # round(maxPowerConAtFullrep,2),
+ # round(maxPowerConAtCon,2),
+ # round( (maxPowerConAtFullrep - maxPowerConAtCon),2 ))
+ #, stderr())
+
+ count <- count +1
+ }
+
+ return(y)
+}
+
+#called on "ec" and "ce" to have a smoothingOneEC for every curve
+#this smoothingOneEC has produce same speeds than smoothing "c"
+findSmoothingsEC <- function(singleFile, displacement, curves, eccon, smoothingOneC,
+ singleFileEncoderConfigurationName, singleFileDiameter,
singleFileInertiaMomentum)
+{
+ ptm <- as.vector(proc.time()[3])
+ write("time start", stderr())
+ write(ptm, stderr())
+
+ #print(c("findSmoothingsEC: eccon smoothingOneC", eccon, smoothingOneC))
+
+ smoothings = NULL
+ n=length(curves[,1])
+
+ #if not "ec" or "ce" just have a value of 0 every curve,
+ #no problem, this value will not be used
+ #is just to not make crash other parts of the software like reduceCurveBySpeed
+ if(eccon != "ec" && eccon != "ce") {
+ for(i in 1:n) {
+ smoothings[i] = 0
+ }
+ } else {
+ #on every curve...
+ for(i in 1:n) {
+ #maybe the global eccon == "ec" or "ce" but the individual eccon of each curve is
"c", then just do the same as above
+ if( (singleFile && eccon == "c") || (! singleFile && curves[i,8] == "c") )
+ smoothings[i] = 0
+ else {
+#0 find concentric
+ eccentric.concentric = displacement[curves[i,1]:curves[i,2]]
+
+ #get the position
+ position=cumsum(displacement[curves[i,1]:curves[i,2]])
+
+ #analyze the "c" phase
+ #Note dividing phases can be done using the speed,
+ #but there's no need of this small difference here
+ conStart = 0
+ conEnd = 0
+ if(eccon=="ec") {
+ conStart = mean(which(position == min(position)))
+ conEnd = length(position) -1
+ #the -1 is because the line below: "concentric=" will fail in
curves[i,1]+end
+ #and will add an NA
+ } else { #(eccon=="ce")
+ conStart = 0
+ conEnd = mean(which(position == max(position)))
+ }
+
+ concentric=displacement[(curves[i,1]+conStart):(curves[i,1]+conEnd)]
+
+#1 get max power concentric at concentric phase with current smoothing
+
+ speed <- getSpeed(concentric, smoothingOneC)
+
+ #assign values from Roptions.txt (singleFile), or from curves
+ myEncoderConfigurationName = singleFileEncoderConfigurationName;
+ myDiameter = singleFileDiameter;
+ myInertiaMomentum = singleFileInertiaMomentum;
+ if(! singleFile) {
+ myEncoderConfigurationName = curves[i,11];
+ myDiameter = curves[i,12];
+ myInertiaMomentum = curves[i,16];
+ }
+
+ powerTemp = NULL
+ if(! isInertial(myEncoderConfigurationName) )
+ powerTemp <- findSmoothingsECGetPowerNI(speed)
+ else
+ powerTemp <- findSmoothingsECGetPowerI(concentric,
myEncoderConfigurationName,
+ myDiameter, 100,
myInertiaMomentum, smoothingOneC)
+
+ maxPowerConAtCon <- max(powerTemp)
+
+#2 get max power concentric (y) at eccentric-concentric phase with current smoothing of an interval of
possible smoothings (x)
+
+ x <- seq(from = as.numeric(smoothingOneC),
+ to = as.numeric(smoothingOneC)/2,
+ length.out = 5)
+ y <- findSmoothingsECYPoints(eccentric.concentric, conStart, conEnd, x,
maxPowerConAtCon,
+ myEncoderConfigurationName, myDiameter, 100,
myInertiaMomentum)
+ #write(paste("x, y", x, y), stderr())
+
+
+ smodel <- smooth.spline(y,x)
+ smoothingOneEC <- predict(smodel, maxPowerConAtCon)$y
+ write(paste("smoothingOneEC", smoothingOneEC), stderr())
+
+ #check how it worked
+
+ speed <- getSpeed(eccentric.concentric, smoothingOneEC)
+
+ if(! isInertial(myEncoderConfigurationName) )
+ powerTemp <- findSmoothingsECGetPowerNI(speed)
+ else
+ powerTemp <- findSmoothingsECGetPowerI( eccentric.concentric,
myEncoderConfigurationName,
+ myDiameter, 100,
myInertiaMomentum, smoothingOneEC)
+
+ #find the max power in concentric phase of this ecc-con movement
+ maxPowerConAtFullrep <- max(powerTemp[conStart:conEnd])
+
+#3 check if first aproximation is OK
+
+ #write(paste("MID i, smoothingOneEC, maxPowerConAtFullrep, maxPowerConAtCon,
diff",
+ # i, smoothingOneEC,
+ # round(maxPowerConAtFullrep,2),
+ # round(maxPowerConAtCon,2),
+ # round( (maxPowerConAtFullrep - maxPowerConAtCon),2 ))
+ #, stderr())
+
+#4 create new x values closer
+
+ #eg
+ #x: .7, .6125, .525, .4375, .35
+ #y: 1156, 1190 , 1340 , 1736 , 2354
+ #lowerValue ald it's lowerPos are reffered to the x vector. 1 means the first
(0.7)
+ #A) if we find the x for an y = 1900, x should be between .4375 (lowerValue)
and .35 (upperValue)
+ #B) if we find the x for an y = 2500, x should be between .35 (lowerValue)
and (right of .35) (upperValue)
+ #C) if we find the x for an y = 1000, x should be between (left of .7)
(lowerValue) and .7 (upperValue)
+
+ xUpperValue = NULL
+ xLowerValue = NULL
+
+ upperPos <- min(which(y > maxPowerConAtCon)) #A: 5, C:1
+ if(is.infinite(upperPos)) {
+ xUpperValue <- x[length(x)] - (x[length(x) -1] - x[length(x)]) #B:
.35 - (.4375-.35) = .2625
+ xLowerValue <- x[length(x)] #B:
.35
+ }
+ else {
+ xUpperValue <- x[upperPos] #A: .35
+ lowerPos <- upperPos -1
+
+ if(lowerPos >= 1)
+ xLowerValue <- x[lowerPos] #A: .4375
+ else
+ xLowerValue <- x[1] + (x[1] - x[2]) #C: .7 + (.7-.6125) =
.7875
+ }
+
+
+#5 get max power concentric (y) at eccentric-concentric phase with current smoothing of an interval of
possible smoothings (x)
+
+ x <- seq(
+ from = xUpperValue,
+ to = xLowerValue,
+ length.out = 5)
+ y <- findSmoothingsECYPoints(eccentric.concentric, conStart, conEnd, x,
maxPowerConAtCon,
+ myEncoderConfigurationName, myDiameter, 100,
myInertiaMomentum)
+
+
+ smodel <- smooth.spline(y,x)
+ smoothingOneEC <- predict(smodel, maxPowerConAtCon)$y
+
+#6 check if aproximation is OK
+
+ if(! isInertial(myEncoderConfigurationName) )
+ powerTemp <- findSmoothingsECGetPowerNI(speed)
+ else
+ powerTemp <- findSmoothingsECGetPowerI( eccentric.concentric,
myEncoderConfigurationName,
+ myDiameter, 100,
myInertiaMomentum, smoothingOneEC)
+
+ #find the max power in concentric phase of this ecc-con movement
+ maxPowerConAtFullrep <- max(powerTemp[conStart:conEnd])
+
+ write(paste("FINAL smooth EC: i, smoothingOneEC, maxPowerConAtFullrep,
maxPowerConAtCon, diff",
+ i, smoothingOneEC,
+ round(maxPowerConAtFullrep,2),
+ round(maxPowerConAtCon,2),
+ round( (maxPowerConAtFullrep - maxPowerConAtCon),2 ))
+ , stderr())
+
+ #use smoothingOneEC
+ smoothings[i] = smoothingOneEC
+ }
+ }
+ }
+
+ write("time end", stderr())
+ write(as.vector(proc.time()[3]) - ptm, stderr())
+
+ return(smoothings)
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]