[chronojump] Several fixes on curves inertial
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Several fixes on curves inertial
- Date: Mon, 31 Mar 2014 23:50:52 +0000 (UTC)
commit b84fd536a198707abab4c0235b0d12ef0e744d31
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Apr 1 01:44:15 2014 +0200
Several fixes on curves inertial
encoder/graph.R | 61 +++++++++++++++++++++--------------
src/gui/encoder.cs | 25 ++++++++++++++-
src/utilEncoder.cs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 147 insertions(+), 28 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 1fdafc2..2f957e4 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -1770,6 +1770,32 @@ getDisplacement <- function(encoderConfigurationName, data, diameter, diameterEx
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)
+}
+
getSpeed <- function(displacement, smoothing) {
#no change affected by encoderConfiguration
@@ -1888,8 +1914,8 @@ getDynamicsInertial <- function(encoderConfigurationName, displacement, d, D, ma
powerBody = mass * (accel + g) * speed
powerWheel = abs((inertiaMomentum * angleAccel) * angleSpeed)
- print(c("displacement",displacement))
- print(c("displacement cumsum",cumsum(displacement)))
+ #print(c("displacement",displacement))
+ #print(c("displacement cumsum",cumsum(displacement)))
print(c("inertia momentum",inertiaMomentum))
#print(c("d",d))
#print(c("mass",mass))
@@ -2095,7 +2121,12 @@ doProcess <- function(options) {
#this removes all NAs on a curve
dataTempFile = dataTempFile[!is.na(dataTempFile)]
- dataTempFile = getDisplacement(inputMultiData$econfName[i], dataTempFile, diameter,
diameterExt)
+ if(isInertial(inputMultiData$econfName[i])) {
+ dataTempFile = fixDisplacementInertial(dataTempFile,
inputMultiData$econfName[i], diameter, diameterExt)
+ } else {
+ dataTempFile = getDisplacement(inputMultiData$econfName[i], dataTempFile,
diameter, diameterExt)
+ }
+
dataTempPhase=dataTempFile
processTimes = 1
@@ -2138,7 +2169,7 @@ doProcess <- function(options) {
econfD[(i+newLines)] = inputMultiData$econfD[i]
econfAnglePush[(i+newLines)] = inputMultiData$econfAnglePush[i]
econfAngleWeight[(i+newLines)] = inputMultiData$econfAngleWeight[i]
- econfInertia[(i+newLines)] = inputMultiData$econfInertia[i]
+ econfInertia[(i+newLines)] = inputMultiData$econfInertia[i]/10000.0 #comes in
Kg*cm^2 eg: 100; convert it to Kg*m^2 eg: 0.010
econfGearedDown[(i+newLines)] = inputMultiData$econfGearedDown[i]
curvesHeight[(i+newLines)] = sum(dataTempPhase)
@@ -2204,28 +2235,10 @@ doProcess <- function(options) {
if(isInertial(EncoderConfigurationName))
{
- #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
- }
+ displacement = fixDisplacementInertial(displacement, EncoderConfigurationName,
diameter, diameterExt)
displacement = getDisplacementInertialBody(displacement, curvesPlot, Title)
+
curvesPlot = FALSE
} else {
displacement = getDisplacement(EncoderConfigurationName, displacement, diameter,
diameterExt)
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 481cd21..fcd8329 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1620,6 +1620,7 @@ public partial class ChronoJumpWindow
int curveStart = Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curve.Start)));
int duration = Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curve.Duration)));
+
if(ecconLast != "c") {
EncoderCurve curveNext =
treeviewEncoderCaptureCurvesGetCurve(selectedID+1,false);
@@ -1635,12 +1636,34 @@ public partial class ChronoJumpWindow
//duration is duration of ecc + duration of iso + duration of concentric
duration += (isometricDuration + curveConDuration);
}
+
+ /*
+ * at inertial signals, first curve is eccentric (can be to left or right, maybe
positive or negative)
+ * graph.R manages correctly this
+ * But, when saved a curve, eg. concentric this can be positive or negative
+ * (depending on the rotating sign of inertial machine at that curve)
+ * if it's concentric, and it's full of -1,-2,... we have to change sign
+ * if it's eccentric-concentric, and in the eccentric phase is positive, then we
should change sign of both phases
+ */
+ int inertialCheckStart = 0;
+ int inertialCheckDuration = 0;
+ if(encoderConfigurationCurrent.has_inertia) {
+ inertialCheckStart = curveStart;
+ if(ecconLast == "c")
+ inertialCheckDuration = duration;
+ else {
+ //see if sign is ok just looking if eccentric phase is negative or not
+ inertialCheckDuration =
Convert.ToInt32(decimal.Truncate(Convert.ToDecimal(curve.Duration)));
+ }
+ }
desc = Util.RemoveTildeAndColonAndDot(entry_encoder_curve_comment.Text.ToString());
Log.WriteLine(curveStart + "->" + duration);
int curveIDMax = Sqlite.Max(Constants.EncoderTable, "uniqueID", false);
- fileSaved = UtilEncoder.EncoderSaveCurve(UtilEncoder.GetEncoderDataTempFileName(),
curveStart, duration,
+ fileSaved = UtilEncoder.EncoderSaveCurve(UtilEncoder.GetEncoderDataTempFileName(),
+ curveStart, duration,
+ inertialCheckStart, inertialCheckDuration, (ecconLast == "c"),
currentSession.UniqueID, currentPerson.UniqueID,
currentPerson.Name, encoderTimeStamp, curveIDMax);
path = UtilEncoder.GetEncoderSessionDataCurveDir(currentSession.UniqueID);
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 2033f5a..485d18b 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -523,12 +523,68 @@ public class UtilEncoder
((IDisposable)writer).Dispose();
}
- public static string EncoderSaveCurve(string fileNameSignal, int start, int duration,
+ public static string EncoderSaveCurve(string fileNameSignal,
+ int start, int duration,
+ int inertialCheckStart, int inertialCheckDuration,
+ bool inertialCheckPositive, //has to be positive (true) or negative (false)
int sessionID, int uniqueID, string personName, string timeStamp, int curveIDMax)
{
string contents = Util.ReadFile(fileNameSignal, false);
- string [] startAndDuration = encoderFindPos(contents, start, duration);
+
+
+ /*
+ * at inertial signals, first curve is eccentric (can be to left or right, maybe positive or
negative)
+ * graph.R manages correctly this
+ * But, when saved a curve, eg. concentric this can be positive or negative
+ * (depending on the rotating sign of inertial machine at that curve)
+ * if it's concentric, and it's full of -1,-2,... we have to change sign
+ * if it's eccentric-concentric, and in the eccentric phase is positive, then we should
change sign of both phases
+ */
+ bool reverseSign = false;
+ if(inertialCheckStart != 0 && inertialCheckDuration != 0) {
+ string [] startAndDurationCheckInertial = encoderFindPos(contents,
inertialCheckStart, inertialCheckDuration);
+ string contentsCheckInertial = contents.Substring(
+ Convert.ToInt32(startAndDurationCheckInertial[0]),
+ Convert.ToInt32(startAndDurationCheckInertial[1])-1); //-1 is for not
ending file with a comma
+
+ //see mean of contentsCheckInertial
+ int sum = 0;
+ int count = 0;
+ using (StringReader reader = new StringReader (contentsCheckInertial)) {
+ do {
+ string line = reader.ReadLine ();
+ if (line == null)
+ break;
+ string [] values = line.Split(new char[] {','});
+ foreach(string str in values) {
+ if (str == null || str == "" || str == " ")
+ break;
+
+ //Log.Write ("(" + str + ":");
+ int num = Convert.ToInt32(str);
+ //Log.Write (num.ToString() + ")");
+ sum += num;
+ count ++;
+ }
+ } while(true);
+
+ if(sum == 0 || count == 0)
+ Log.WriteLine("inertial check == 0, no data");
+ else {
+ double average = sum * 1.0 / count * 1.0;
+ Log.WriteLine("inertial check == " + average.ToString());
+ if(
+ (average < 0 && inertialCheckPositive) ||
+ (average > 0 && ! inertialCheckPositive) ) {
+ reverseSign = true;
+ }
+ }
+ }
+ }
+
+
+ string [] startAndDuration = encoderFindPos(contents, start, duration);
contents = contents.Substring(
Convert.ToInt32(startAndDuration[0]),
Convert.ToInt32(startAndDuration[1])-1); //-1 is for not ending file with a
comma
@@ -538,10 +594,37 @@ public class UtilEncoder
//in the meantime this NA in reading in graph.R has been deleted
//dataTempFile = dataTempFile[!is.na(dataTempFile)]
-
string fileCurve = uniqueID.ToString() + "-" + personName + "-" +
(++ curveIDMax).ToString() + "-" + timeStamp + ".txt";
string fileCurveFull = GetEncoderSessionDataCurveDir(sessionID) + Path.DirectorySeparatorChar
+ fileCurve;
+
+
+ if(reverseSign) {
+ Log.WriteLine("reversingSign");
+ string contentsReversed = "";
+ string sep = "";
+ using (StringReader reader = new StringReader (contents)) {
+ do {
+ string line = reader.ReadLine ();
+ if (line == null)
+ break;
+
+ string [] values = line.Split(new char[] {','});
+ foreach(string str in values) {
+ if (str == null || str == "" || str == " ")
+ break;
+
+ //Log.Write ("(" + str + ":");
+ int num = Convert.ToInt32(str) * -1;
+ //Log.Write (num.ToString() + ")");
+ contentsReversed += sep + num.ToString();
+ sep = ", ";
+ }
+ } while(true);
+ }
+ contents = contentsReversed;
+ }
+
TextWriter writer = File.CreateText(fileCurveFull);
writer.Write(contents);
[
Date Prev][Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]