[chronojump] inertial capture not fully extended correction DONE. Need tests.
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] inertial capture not fully extended correction DONE. Need tests.
- Date: Thu, 21 Jul 2016 12:50:10 +0000 (UTC)
commit 7983609ae26f71e1cf68931d6c98e16f9c1fafa7
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Jul 21 14:44:56 2016 +0200
inertial capture not fully extended correction DONE. Need tests.
encoder/graph.R | 36 ++++++++++++++++++++++--------------
encoder/util.R | 24 ++++++++++++++++++------
src/gui/encoder.cs | 14 ++++++++++----
3 files changed, 50 insertions(+), 24 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 3b87e03..d79f6da 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -2228,7 +2228,7 @@ doProcess <- function(options)
# titleType="jump"
curvesPlot = FALSE
- if(op$Analysis == "curves") {
+ if(op$Analysis == "curves" || op$Analysis == "curvesAC") {
curvesPlot = TRUE
par(mar=c(2,2.5,2,1))
}
@@ -2431,26 +2431,33 @@ doProcess <- function(options)
NULL, NULL, NULL, NULL) #this row is only needed for
singleFile (signal)
print(c("SmoothingsEC:",SmoothingsEC))
} else { #singleFile == True. reads a signal file
- displacement=scan(file=op$File,sep=",")
+ displacement <- scan(file=op$File,sep=",")
#if data file ends with comma. Last character will be an NA. remove it
#this removes all NAs
- displacement = displacement[!is.na(displacement)]
+ displacement <- displacement[!is.na(displacement)]
displacementInertialNotBody <- NULL
if(isInertial(op$EncoderConfigurationName))
{
- diametersPerMs = getInertialDiametersPerMs(displacement, op$diameter)
- displacement = getDisplacementInertial(displacement, op$EncoderConfigurationName,
+ #This process is only done on the curves after capture (not on recalculate or load)
+ if(op$Analysis == "curvesAC")
+ displacement <- fixInertialSignalIfNotFullyExtended(displacement,
+ paste(op$EncoderTempPath,
+
"/chronojump-last-encoder-data.txt",
+ sep=""),
+ FALSE)
+
+ diametersPerMs <- getInertialDiametersPerMs(displacement, op$diameter)
+ displacement <- getDisplacementInertial(displacement, op$EncoderConfigurationName,
diametersPerMs, op$diameterExt, op$gearedDown)
-
displacementInertialNotBody <- displacement #store a copy to be used on "single" (all
set) to have a better set smooth
- displacement = getDisplacementInertialBody(0, displacement, curvesPlot, op$Title)
+ displacement <- getDisplacementInertialBody(0, displacement, curvesPlot, op$Title)
#positionStart is 0 in graph.R. It is different on capture.R because depends on the
start of every repetition
- curvesPlot = FALSE
+ curvesPlot <- FALSE
} else {
- displacement = getDisplacement(op$EncoderConfigurationName, displacement,
op$diameter, op$diameterExt)
+ displacement <- getDisplacement(op$EncoderConfigurationName, displacement,
op$diameter, op$diameterExt)
}
#TODO: is this needed at all?
@@ -2467,7 +2474,7 @@ doProcess <- function(options)
curves=findCurvesNew(displacement, op$Eccon, isInertial(op$EncoderConfigurationName),
op$MinHeight, curvesPlot, op$Title)
- if(op$Analysis == "curves")
+ if(op$Analysis == "curves" || op$Analysis == "curvesAC")
curvesPlot = TRUE
n=length(curves[,1])
@@ -2917,7 +2924,8 @@ doProcess <- function(options)
if(
op$Analysis == "powerBars" || op$Analysis == "cross" ||
op$Analysis == "1RMBadillo2010" || op$Analysis == "1RMAnyExercise" ||
- op$Analysis == "curves" || op$Analysis == "neuromuscularProfile" ||
+ op$Analysis == "curves" || op$Analysis == "curvesAC" ||
+ op$Analysis == "neuromuscularProfile" ||
writeCurves)
{
paf = data.frame()
@@ -3125,7 +3133,7 @@ doProcess <- function(options)
neuromuscularProfileWriteData(npj, op$OutputData1)
}
- if(op$Analysis == "curves" || writeCurves) {
+ if(op$Analysis == "curves" || op$Analysis == "curvesAC" || writeCurves) {
#create pafCurves to be printed on CSV. This columns are going to be removed:
#print("---- 1 ----")
@@ -3171,8 +3179,8 @@ doProcess <- function(options)
)
- #Add "Max", "AVG" and "SD" when analyzing, not on "curves"
- if(op$Analysis != "curves") {
+ #Add "Max", "AVG" and "SD" when analyzing, not on "curves", not on "curvesAC"
+ if(op$Analysis != "curves" && op$Analysis != "curvesAC") {
addSD = FALSE
if(length(pafCurves[,1]) > 1)
addSD = TRUE
diff --git a/encoder/util.R b/encoder/util.R
index 683722c..a229c2b 100644
--- a/encoder/util.R
+++ b/encoder/util.R
@@ -1102,7 +1102,8 @@ getDisplacementInertialBody <- function(positionStart, displacement, draw, title
#used when user captures without string fully extended
#d is displacement, graph is to debug
-fixInertialSignalNotFullyExtendedString <- function(d, graph)
+#see codeExplained/image detect-and-fix-inertial-string-not-fully-extended.png
+fixInertialSignalIfNotFullyExtended <- function(d, saveFile, graph)
{
pos <- cumsum(d)
@@ -1129,7 +1130,7 @@ fixInertialSignalNotFullyExtendedString <- function(d, graph)
#return if no data
if(length(maximums) < 1 | length(minimums) < 1)
- return()
+ return(d)
#ensure both maximums and minimums have same length
while(length(maximums) != length(minimums))
@@ -1143,10 +1144,13 @@ fixInertialSignalNotFullyExtendedString <- function(d, graph)
meanByExtrema <- mean(c(pos[maximums], pos[minimums]))
posCorrected <- pos - meanByExtrema
+ #remove the initial part of the signal. Remove from ms 1 to when posCorrected crosses 0
+ posCorrectedCrossZero = extrema(posCorrected)$cross[1,1]
+
if(graph) {
par(mfrow=c(1,2))
- #1st graph
+ #1st graph (left)
plot(pos, type="l", lty=2, xlab="time", ylab="position", main="String NOT fully extended")
lines(abs(pos)*-1, lwd=2)
points(maximumsCopy, pos[maximumsCopy], col="black", cex=1)
@@ -1155,14 +1159,22 @@ fixInertialSignalNotFullyExtendedString <- function(d, graph)
points(minimums, pos[minimums], col="green", cex=3)
abline(h = meanByExtrema, col="red")
- #2nd graph
- plot(posCorrected, type="l", lty=2, xlab="time", ylab="position", main="Set corrected")
+ #2nd graph (right)
+ plot(posCorrected, type="l", lty=2, xlab="time", ylab="position", main="Corrected set")
lines(abs(posCorrected)*-1, lwd=2)
+ abline(v=c(posCorrectedCrossZero, length(posCorrected)), col="green")
+ mtext("Start", at=posCorrectedCrossZero, side=3, col="green")
+ mtext("End", at=length(posCorrected), side=3, col="green")
par(mfrow=c(1,1))
}
- return()
+ #define new displacement
+ d <- d[posCorrectedCrossZero:length(d)]
+
+ #write to file and return displacement to be used
+ write(d, file=saveFile, ncolumns=length(d), sep=", ")
+ return(d)
}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 79bca07..6fc151e 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -932,13 +932,19 @@ public partial class ChronoJumpWindow
}
+ private void encoderDoCurvesGraphR_curves() {
+ encoderDoCurvesGraphR("curves");
+ }
+ private void encoderDoCurvesGraphR_curvesAC() {
+ encoderDoCurvesGraphR("curvesAC");
+ }
//this is called by non gtk thread. Don't do gtk stuff here
//I suppose reading gtk is ok, changing will be the problem
//called on calculatecurves, recalculate and load
- private void encoderDoCurvesGraphR()
+ private void encoderDoCurvesGraphR(string analysisSent)
{
LogB.Debug("encoderDoCurvesGraphR() start");
- string analysis = "curves";
+ string analysis = analysisSent;
string analysisOptions = getEncoderAnalysisOptions();
@@ -4570,7 +4576,7 @@ public partial class ChronoJumpWindow
//don't need because ItemToggled is deactivated during capture
//treeview_encoder_capture_curves.Sensitive = false;
- encoderThread = new Thread(new ThreadStart(encoderDoCurvesGraphR));
+ encoderThread = new Thread(new ThreadStart(encoderDoCurvesGraphR_curves));
if(action == encoderActions.CURVES)
GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCurves));
else // action == encoderActions.LOAD
@@ -4591,7 +4597,7 @@ public partial class ChronoJumpWindow
//_______ 2) run stuff
//this does not run a pulseGTK
- encoderDoCurvesGraphR();
+ encoderDoCurvesGraphR_curvesAC();
encoderButtonsSensitive(encoderSensEnum.PROCESSINGR);
}
} else { //encoderActions.ANALYZE
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]