[chronojump] Fixing capture to have same results than curves
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Fixing capture to have same results than curves
- Date: Wed, 21 Jan 2015 21:22:05 +0000 (UTC)
commit cde9b94816871e2d50982e903e9760a0491c61f0
Author: Xavier de Blas <xaviblas gmail com>
Date: Wed Jan 21 22:20:57 2015 +0100
Fixing capture to have same results than curves
encoder/capture.R | 62 ++++++++++++++++++++++++------
encoder/graph.R | 103 ---------------------------------------------------
encoder/util.R | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 156 insertions(+), 116 deletions(-)
---
diff --git a/encoder/capture.R b/encoder/capture.R
index 65580b6..6b997ec 100644
--- a/encoder/capture.R
+++ b/encoder/capture.R
@@ -44,27 +44,59 @@ while(input[1] != "Q") {
#if data file ends with comma. Last character will be an NA. remove it
#this removes all NAs
displacement = displacement[!is.na(displacement)]
+
+ if(isInertial(op$EncoderConfigurationName))
+ {
+ displacement = fixDisplacementInertial(displacement, op$EncoderConfigurationName,
op$diameter, op$diameterExt)
+
+ displacement = getDisplacementInertialBody(displacement, FALSE, op$Title) #draw: FALSE
+ } else {
+ displacement = getDisplacement(op$EncoderConfigurationName, displacement, op$diameter,
op$diameterExt)
+ }
+ write(displacement,stderr())
position = cumsum(displacement)
+ write(position,stderr())
+
+ #curves=findCurves(displacement, op$Eccon, op$MinHeight, FALSE, op$Title) #draw: FALSE
+ #print("curves",stderr())
+ #print(curves,stderr())
- reduceTemp = reduceCurveBySpeed(op$Eccon, 1,
- 1, 0, #startT, startH
- displacement, #displacement
- op$SmoothingOneC #SmoothingOneC
- )
+ if( ! isInertial(op$EncoderConfigurationName)) {
+ reduceTemp = reduceCurveBySpeed(op$Eccon, 1,
+ #curves[1,1], curves[1,3], #startT, startH
+ 1, 0, #startT, startH
+ displacement, #displacement
+ op$SmoothingOneC #SmoothingOneC
+ )
+
+ #curves[1,1] = reduceTemp[1]
+ #curves[1,2] = reduceTemp[2]
+ #curves[1,3] = reduceTemp[3]
+ }
+
+# SmoothingsEC = findSmoothingsEC(singleFile, displacement, curves, op$Eccon, op$SmoothingOneC)
+# write(c("SmoothingsEC:",SmoothingsEC),stderr())
+
+ write("curves after reduceCurveBySpeed",stderr())
+ #write(as.vector(curves[1,]),stderr())
+
start = reduceTemp[1]
end = reduceTemp[2]
- write("printing reduceTemp2", stderr())
- write(reduceTemp[2], stderr())
+ #write("printing reduceTemp2", stderr())
+ #write(reduceTemp[2], stderr())
if(end > length(displacement))
end = length(displacement)
- write("printing reduceTemp", stderr())
- write(c(start, end, length(displacement)),stderr())
+ #write("printing reduceTemp", stderr())
+ #write(c(start, end, length(displacement)),stderr())
- displacement = displacement[start:end]
+ #displacement = displacement[start:end]
#print("reduced")
+
+ #if(curves[1,2] > length(displacement))
+ # curves[1,2] = length(displacement)
g = 9.81
@@ -81,21 +113,25 @@ while(input[1] != "Q") {
#print("pre kinematicsResult")
+ #kinematicsResult <- kinematicsF(displacement[curves[1,1]:curves[1,2]],
kinematicsResult <- kinematicsF(displacement,
op$MassBody, op$MassExtra, op$ExercisePercentBodyWeight,
op$EncoderConfigurationName, op$diameter, op$diameterExt, op$anglePush, op$angleWeight,
op$inertiaMomentum, op$gearedDown,
+ #SmoothingsEC[1], op$SmoothingOneC,
SmoothingsEC, op$SmoothingOneC,
g, op$Eccon, isPropulsive)
#print("kinematicsResult")
#print(kinematicsResult)
- paf = pafGenerate("c", kinematicsResult, op$MassBody, op$MassExtra)
- #print("paf")
- #print(paf)
+ paf = data.frame()
+ paf = pafGenerate(op$Eccon, kinematicsResult, op$MassBody, op$MassExtra)
+ #write("paf",stderr())
+ #write(paf,stderr())
#do not use print because it shows the [1] first. Use cat:
cat(paste(#start, #start is not used because we have no data of the initial zeros
(end-start), (position[end]-position[start]),
+ #curves[1,2]-curves[1,1], position[curves[1,2]]-curves[1,3],
paf$meanSpeed, paf$maxSpeed, paf$maxSpeedT, paf$meanPower, paf$peakPower, paf$peakPowerT,
paf$pp_ppt, sep=", "))
cat("\n") #mandatory to read this from C#, but beware, there we will need a trim to remove the
windows \r\n
diff --git a/encoder/graph.R b/encoder/graph.R
index 15167d3..40ce183 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -135,52 +135,6 @@ translate <- function(englishWord) {
# return(displacement)
#}
-#separate phases using initial height of full extended person
-#this methods replaces getDisplacement and fixRawdataInertial
-#here comes a signal: (singleFile)
-#it shows the disc rotation and the person movement
-getDisplacementInertialBody <- function(displacement, draw, title)
-{
- position=cumsum(displacement)
- position.ext=extrema(position)
-
- print("at findCurvesInertial")
- print(position.ext)
-
- #Fix if disc goes wrong direction at start
- if(position.ext$maxindex[1] < position.ext$minindex[1]) {
- displacement = displacement * -1
- position=cumsum(displacement)
- position.ext=extrema(position)
- }
-
- firstDownPhaseTime = position.ext$minindex[1]
-
- downHeight = abs(position[1] - position[firstDownPhaseTime])
-
- positionPerson = abs(cumsum(displacement))*-1
- #this is to make "inverted cumsum"
- displacementPerson = c(0,diff(positionPerson))
-
- if(draw) {
- col="black"
- plot((1:length(position))/1000 #ms -> s
- ,position/10, #mm -> cm
- type="l",
- xlim=c(1,length(position))/1000, #ms -> s
- xlab="",ylab="",axes=T,
- lty=2,col=col)
-
- abline(h=0, lty=2, col="gray")
-
- lines((1:length(position))/1000,positionPerson/10,lty=1,lwd=2)
-
- title(title, cex.main=1, font.main=1)
- mtext(paste(translate("time"),"(s)"),side=1,adj=1,line=-1)
- mtext(paste(translate("displacement"),"(cm)"),side=2,adj=1,line=-1)
- }
- return(displacementPerson)
-}
findCurves <- function(displacement, eccon, min_height, draw, title) {
position=cumsum(displacement)
@@ -1632,63 +1586,6 @@ find.yrange <- function(singleFile, displacement, curves) {
#-------------------- EncoderConfiguration conversions --------------------------
-#in signals and curves, need to do conversions (invert, inertiaMomentum, diameter)
-#we use 'data' variable because can be position or displacement
-getDisplacement <- function(encoderConfigurationName, data, diameter, diameterExt) {
- #no change
- #WEIGHTEDMOVPULLEYLINEARONPERSON1, WEIGHTEDMOVPULLEYLINEARONPERSON1INV,
- #WEIGHTEDMOVPULLEYLINEARONPERSON2, WEIGHTEDMOVPULLEYLINEARONPERSON2INV,
- #LINEARONPLANE
- #ROTARYFRICTIONSIDE
- #WEIGHTEDMOVPULLEYROTARYFRICTION
-
- if(
- encoderConfigurationName == "LINEARINVERTED" ||
- encoderConfigurationName == "WEIGHTEDMOVPULLEYLINEARONPERSON1INV" ||
- encoderConfigurationName == "WEIGHTEDMOVPULLEYLINEARONPERSON2INV")
- {
- data = -data
- } else if(encoderConfigurationName == "WEIGHTEDMOVPULLEYONLINEARENCODER") {
- #default is: gearedDown = 2. Future maybe this will be a parameter
- data = data *2
- } else if(encoderConfigurationName == "ROTARYFRICTIONAXIS") {
- data = data * diameter / diameterExt
- } else if(encoderConfigurationName == "ROTARYAXIS" ||
- encoderConfigurationName == "WEIGHTEDMOVPULLEYROTARYAXIS") {
- ticksRotaryEncoder = 200 #our rotary axis encoder send 200 ticks by turn
- #diameter m -> mm
- data = ( data / ticksRotaryEncoder ) * 2 * pi * ( diameter * 1000 / 2 )
- }
-
- return(data)
-}
-
-fixDisplacementInertial <- function(displacement, encoderConfigurationName, diameter, diameterExt)
-{
- #scanned displacement is ticks of rotary axis encoder
- #now convert it to mm of body displacement
- if(encoderConfigurationName == "ROTARYAXISINERTIAL") {
- displacementMeters = displacement / 1000 #mm -> m
- diameterMeters = diameter / 100 #cm -> m
-
- ticksRotaryEncoder = 200 #our rotary axis encoder send 200 ticks by turn
- #angle in radians
- angle = abs(cumsum(displacementMeters * 1000)) * 2 * pi / ticksRotaryEncoder
- position = angle * diameterMeters / 2
- position = position * 1000 #m -> mm
- #this is to make "inverted cumsum"
- displacement = c(0,diff(position)) #this displacement is going to be used now
- }
-
- #on friction side: know displacement of the "person"
- if(encoderConfigurationName == "ROTARYFRICTIONSIDEINERTIAL")
- {
- displacement = displacement * diameter / diameterExt #displacement of the axis
- }
-
- return (displacement)
-}
-
#-------------- end of EncoderConfiguration conversions -------------------------
diff --git a/encoder/util.R b/encoder/util.R
index 6359070..b93f409 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -667,3 +667,110 @@ getDynamicsInertial <- function(encoderConfigurationName, displacement, d, D, ma
return(list(displacement=displacement, mass=mass, force=force, power=power))
}
+
+
+#separate phases using initial height of full extended person
+#this methods replaces getDisplacement and fixRawdataInertial
+#here comes a signal: (singleFile)
+#it shows the disc rotation and the person movement
+getDisplacementInertialBody <- function(displacement, draw, title)
+{
+ position=cumsum(displacement)
+ position.ext=extrema(position)
+
+ print("at findCurvesInertial")
+ print(position.ext)
+
+ #Fix if disc goes wrong direction at start
+ if(position.ext$maxindex[1] < position.ext$minindex[1]) {
+ displacement = displacement * -1
+ position=cumsum(displacement)
+ position.ext=extrema(position)
+ }
+
+ firstDownPhaseTime = position.ext$minindex[1]
+
+ downHeight = abs(position[1] - position[firstDownPhaseTime])
+
+ positionPerson = abs(cumsum(displacement))*-1
+ #this is to make "inverted cumsum"
+ displacementPerson = c(0,diff(positionPerson))
+
+ if(draw) {
+ col="black"
+ plot((1:length(position))/1000 #ms -> s
+ ,position/10, #mm -> cm
+ type="l",
+ xlim=c(1,length(position))/1000, #ms -> s
+ xlab="",ylab="",axes=T,
+ lty=2,col=col)
+
+ abline(h=0, lty=2, col="gray")
+
+ lines((1:length(position))/1000,positionPerson/10,lty=1,lwd=2)
+
+ title(title, cex.main=1, font.main=1)
+ mtext(paste(translate("time"),"(s)"),side=1,adj=1,line=-1)
+ mtext(paste(translate("displacement"),"(cm)"),side=2,adj=1,line=-1)
+ }
+ return(displacementPerson)
+}
+
+
+#in signals and curves, need to do conversions (invert, inertiaMomentum, diameter)
+#we use 'data' variable because can be position or displacement
+getDisplacement <- function(encoderConfigurationName, data, diameter, diameterExt) {
+ #no change
+ #WEIGHTEDMOVPULLEYLINEARONPERSON1, WEIGHTEDMOVPULLEYLINEARONPERSON1INV,
+ #WEIGHTEDMOVPULLEYLINEARONPERSON2, WEIGHTEDMOVPULLEYLINEARONPERSON2INV,
+ #LINEARONPLANE
+ #ROTARYFRICTIONSIDE
+ #WEIGHTEDMOVPULLEYROTARYFRICTION
+
+ if(
+ encoderConfigurationName == "LINEARINVERTED" ||
+ encoderConfigurationName == "WEIGHTEDMOVPULLEYLINEARONPERSON1INV" ||
+ encoderConfigurationName == "WEIGHTEDMOVPULLEYLINEARONPERSON2INV")
+ {
+ data = -data
+ } else if(encoderConfigurationName == "WEIGHTEDMOVPULLEYONLINEARENCODER") {
+ #default is: gearedDown = 2. Future maybe this will be a parameter
+ data = data *2
+ } else if(encoderConfigurationName == "ROTARYFRICTIONAXIS") {
+ data = data * diameter / diameterExt
+ } else if(encoderConfigurationName == "ROTARYAXIS" ||
+ encoderConfigurationName == "WEIGHTEDMOVPULLEYROTARYAXIS") {
+ ticksRotaryEncoder = 200 #our rotary axis encoder send 200 ticks by turn
+ #diameter m -> mm
+ data = ( data / ticksRotaryEncoder ) * 2 * pi * ( diameter * 1000 / 2 )
+ }
+
+ return(data)
+}
+
+fixDisplacementInertial <- function(displacement, encoderConfigurationName, diameter, diameterExt)
+{
+ #scanned displacement is ticks of rotary axis encoder
+ #now convert it to mm of body displacement
+ if(encoderConfigurationName == "ROTARYAXISINERTIAL") {
+ displacementMeters = displacement / 1000 #mm -> m
+ diameterMeters = diameter / 100 #cm -> m
+
+ ticksRotaryEncoder = 200 #our rotary axis encoder send 200 ticks by turn
+ #angle in radians
+ angle = abs(cumsum(displacementMeters * 1000)) * 2 * pi / ticksRotaryEncoder
+ position = angle * diameterMeters / 2
+ position = position * 1000 #m -> mm
+ #this is to make "inverted cumsum"
+ displacement = c(0,diff(position)) #this displacement is going to be used now
+ }
+
+ #on friction side: know displacement of the "person"
+ if(encoderConfigurationName == "ROTARYFRICTIONSIDEINERTIAL")
+ {
+ displacement = displacement * diameter / diameterExt #displacement of the axis
+ }
+
+ return (displacement)
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]