[chronojump] EncoderConfigs at updateEncoderCaptureGraph



commit 9747c6aefa676b240853de62eecc065a89645d49
Author: Xavier de Blas <xaviblas gmail com>
Date:   Mon Feb 3 16:34:46 2014 +0100

    EncoderConfigs at updateEncoderCaptureGraph

 encoder/graph.R    |   18 +++++-----
 src/gui/encoder.cs |   15 ++++++--
 src/utilEncoder.cs |  103 ++++++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 103 insertions(+), 33 deletions(-)
---
diff --git a/encoder/graph.R b/encoder/graph.R
index 858b405..14b02af 100644
--- a/encoder/graph.R
+++ b/encoder/graph.R
@@ -331,13 +331,13 @@ findSmoothingsEC <- function(displacement, curves, eccon, smoothingOneC) {
                        concentric=displacement[(curves[i,1]+start):(curves[i,1]+end)]
 
                        #get max speed at "c"
-                       speed <- smooth.spline( 1:length(concentric), concentric, spar=smoothingOneC) 
+                       speed <- getSpeed(concentric, smoothingOneC)
                        maxSpeedC=max(speed$y)
 
                        #find max speed at "ec" that's similar to maxSpeedC
                        smoothingOneEC = smoothingOneC
                        for(j in seq(as.numeric(smoothingOneC),0,by=-.01)) {
-                               speed <- smooth.spline( 1:length(eccentric.concentric), eccentric.concentric, 
spar=j)
+                               speed <- getSpeed(eccentric.concentric, j)
                                smoothingOneEC = j
                                maxSpeedEC=max(speed$y)
                                print(c("maxC",maxSpeedC,"maxEC",maxSpeedEC))
@@ -365,7 +365,7 @@ reduceCurveBySpeed <- function(eccon, row, startT, displacement, smoothingOneEC,
        if(eccon == "c" || eccon == "ecS" || eccon == "ceS")
                smoothing = smoothingOneC
 
-       speed <- smooth.spline( 1:length(displacement), displacement, spar=smoothing) 
+       speed <- getSpeed(displacement, smoothing)
        
        speed.ext=extrema(speed$y)
 
@@ -528,12 +528,12 @@ kinematicsF <- function(displacement, massBody, massExtra, exercisePercentBodyWe
 
        #x vector should contain at least 4 different values
        if(length(displacement) >= 4)
-               speed <- smooth.spline( 1:length(displacement), displacement, spar=smoothing)
+               speed <- getSpeed(displacement, smoothing)
        else
                speed=list(y=rep(0,length(displacement)))
        
        if(length(displacement) >= 4)
-               accel <- predict( speed, deriv=1 )
+               accel <- getAcceleration(speed)
        else
                accel=list(y=rep(0,length(displacement)))
        
@@ -717,7 +717,7 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
                        par(mar=c(1, 1, 4, 1))
        
                #plot distance
-               #plot(a,type="h",xlim=c(xmin,xmax),xlab="time (ms)",ylab="Left: distance (mm); Right: speed 
(m/s), accelration (m/s^2)",col="gray", axes=F) #this shows background on distance (nice when plotting 
distance and speed, but confusing when there are more variables)
+               #plot(a,type="h",xlim=c(xmin,xmax),xlab="time (ms)",ylab="Left: distance (mm); Right: speed 
(m/s), acceleration (m/s^2)",col="gray", axes=F) #this shows background on distance (nice when plotting 
distance and speed, but confusing when there are more variables)
                xlab="";ylab="";
                #if(showLabels) {
                #       xlab="time (ms)"
@@ -765,7 +765,7 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
        }
 
        #speed
-       speed <- smooth.spline( 1:length(displacement), displacement, spar=smoothing)
+       speed <- getSpeed(displacement, smoothing)
                
        if(draw & showSpeed) {
                ylim=c(-max(abs(range(displacement))),max(abs(range(displacement))))    #put 0 in the middle 
@@ -860,7 +860,7 @@ paint <- function(displacement, eccon, xmin, xmax, yrange, knRanges, superpose,
        #if(inertialType == "ri" && eccon == "ce")
        #       speed$y=abs(speed$y)
 
-       accel <- predict( speed, deriv=1 )
+       accel <- getAcceleration(speed)
        #speed comes in mm/ms when derivate to accel its mm/ms^2 to convert it to m/s^2 need to *1000 because 
it's quadratic
        accel$y <- accel$y * 1000
        
@@ -2059,7 +2059,7 @@ doProcess <- function(options) {
 
                        #plot speed
                        par(new=T)      
-                       speed <- smooth.spline( 1:length(displacement), displacement, spar=smoothingAll)
+                       speed <- getSpeed(displacement, smoothingAll)
                        plot((1:length(displacement))/1000, speed$y, col="green2",
                                type="l", 
                                xlim=c(1,length(displacement))/1000,    #ms -> s
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index ebeeaaa..0f07ce9 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -1802,8 +1802,7 @@ public partial class ChronoJumpWindow
                        if(byteReadedRaw > 128)
                                byteReadedRaw = byteReadedRaw - 256;
 
-                       byteReaded = UtilEncoder.EncoderConfigurationConversions(
-                                       byteReadedRaw, encoderConfigurationCurrent);
+                       byteReaded = UtilEncoder.GetDisplacement(byteReadedRaw, encoderConfigurationCurrent);
 
                        i=i+1;
                        if(i >= 0) {
@@ -3807,6 +3806,7 @@ Log.WriteLine(str);
        }
 
        string encoderCaptureStringR;
+       double massDisplacedEncoder = 0;
        
        private void updateEncoderCaptureGraphRCalc() 
        {
@@ -3995,9 +3995,10 @@ Log.WriteLine(str);
                        }
                        //end of propulsive stuff
 
-                       NumericVector mass = rengine.CreateNumericVector(new double[] 
{findMass(Constants.MassType.DISPLACED)});
-                       rengine.SetSymbol("mass", mass);
 
+                       NumericVector mass = rengine.CreateNumericVector(new double[] { massDisplacedEncoder 
});
+                       rengine.SetSymbol("mass", mass);
+               
 
                        //if isJump == "True":
                        rengine.Evaluate("force <- mass*(accel$y+9.81)");
@@ -4160,6 +4161,12 @@ Log.WriteLine(str);
                                
                                capturingCsharp = true;
                                eccaCreated = false;
+                       
+                               //TODO: add demult and angle    
+                               massDisplacedEncoder = 
UtilEncoder.GetMassByEncoderConfiguration(encoderConfigurationCurrent, 
+                                       findMass(Constants.MassType.BODY), findMass(Constants.MassType.EXTRA),
+                                       getExercisePercentBodyWeightFromCombo(), 1, 90
+                                       );
 
                                encoderThreadCapture = new Thread(new ThreadStart(captureCsharp));
                                GLib.Idle.Add (new GLib.IdleHandler (pulseGTKEncoderCapture));
diff --git a/src/utilEncoder.cs b/src/utilEncoder.cs
index 153f25d..06e1175 100644
--- a/src/utilEncoder.cs
+++ b/src/utilEncoder.cs
@@ -15,7 +15,7 @@
  *  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-2012   Xavier de Blas <xaviblas gmail com> 
+ *  Copyright (C) 2004-2014   Xavier de Blas <xaviblas gmail com> 
  */
 
 using System;
@@ -441,25 +441,6 @@ public class UtilEncoder
                return fileCurve;
        }
 
-       //this == encoder/graph.R encoderConfigurationConversions
-       
-       public static double EncoderConfigurationConversions(
-                       int byteReaded, EncoderConfiguration ec) {
-               double byteConverted = byteReaded;
-
-               //invert sign if inverted is selected
-               if(ec.name == Constants.EncoderConfigurationNames.LINEARINVERTED)
-                       byteConverted *= -1;
-               else if(ec.name == Constants.EncoderConfigurationNames.ROTARYAXIS) {
-                       int ticksRotaryEncoder = 200; //our rotary axis encoder send 200 ticks by turn
-                       //diameter m -> mm
-                       byteConverted = ( byteConverted / ticksRotaryEncoder ) * 2 * Math.PI * ( ec.d * 1000 
/ 2 );
-               }
-               //Log.Write(" " + byteReaded + ":" + byteConverted);
-
-               return byteConverted;
-       }
-
        public static ArrayList EncoderConfigurationList(Constants.EncoderType encoderType) {
                ArrayList list = new ArrayList();
                if(encoderType == Constants.EncoderType.LINEAR) {
@@ -501,4 +482,86 @@ public class UtilEncoder
                return list;
        }
 
+       /* -------- EncoderConfiguration, kinematics and Dynamics ---- 
+        *
+        *              this is the same than graph.R
+        * -------------------------------------------------------- */
+
+       /*
+        * in signals and curves, need to do conversions (invert, inertiaMomentum, diameter)
+        * we use 'data' variable because can be position or displacement
+        */
+
+       public static double GetDisplacement(int byteReaded, EncoderConfiguration ec) {
+               /* no change:
+                * WEIGHTEDMOVPULLEYLINEARONPERSON1, WEIGHTEDMOVPULLEYLINEARONPERSON1INV,
+                * WEIGHTEDMOVPULLEYLINEARONPERSON2, WEIGHTEDMOVPULLEYLINEARONPERSON2INV,
+                * LINEARONPLANE, ROTARYFRICTIONSIDE, WEIGHTEDMOVPULLEYROTARYFRICTION
+                */
+
+               double data = byteReaded;
+               if(ec.name == Constants.EncoderConfigurationNames.LINEARINVERTED) {
+                       data *= -1;
+               } else if(ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYONLINEARENCODER) {
+                       //default is: demultiplication = 2. Future maybe this will be a parameter
+                       data *= 2;
+               } else if(ec.name == Constants.EncoderConfigurationNames.ROTARYFRICTIONAXIS) {
+                       data = data * ec.d / ec.d2;
+               } else if(
+                               ec.name == Constants.EncoderConfigurationNames.ROTARYAXIS || 
+                               ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYROTARYAXIS) 
+               {
+                       int ticksRotaryEncoder = 200; //our rotary axis encoder send 200 ticks by turn
+                       //diameter m -> mm
+                       data = ( data / ticksRotaryEncoder ) * 2 * Math.PI * ( ec.d * 1000 / 2 );
+               }
+               return data;
+       }
+
+       //demult is positive, normally 2
+       private static double getMass(double mass, int demult, int angle) {
+               if(mass == 0)
+                       return 0;
+
+               return ( ( mass / demult ) * Math.Sin( angle * Math.PI / 180 ) );
+       }
+
+       private static double getMassBodyByExercise(double massBody, int exercisePercentBodyWeight) {
+               if(massBody == 0 || exercisePercentBodyWeight == 0)
+                       return 0;
+
+               return (massBody * exercisePercentBodyWeight / 100.0);
+       }
+
+       public static double GetMassByEncoderConfiguration(
+                       EncoderConfiguration ec, double massBody, double massExtra, 
+                       int exercisePercentBodyWeight, int demult, int angle)
+       {
+               massBody = getMassBodyByExercise(massBody, exercisePercentBodyWeight);
+
+               if(
+                       ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYLINEARONPERSON1 ||
+                       ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYLINEARONPERSON1INV ||
+                       ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYLINEARONPERSON2 ||
+                       ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYLINEARONPERSON2INV ||
+                       ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYROTARYFRICTION ||
+                       ec.name == Constants.EncoderConfigurationNames.WEIGHTEDMOVPULLEYROTARYAXIS 
+                 ) {
+                       /*
+                        * angle will be 90 degrees. We assume this.
+                        * Maybe in the future, person or person and extra weight, 
+                        * can have different angles
+                        */
+                       massExtra = getMass(massExtra, demult, angle);
+               } 
+               else if(ec.name == Constants.EncoderConfigurationNames.LINEARONPLANE) {
+                       massBody = getMass(massBody, demult, angle);
+                       massExtra = getMass(massExtra, demult, angle);
+               }
+
+               return (massBody + massExtra);
+       }
+
+       /* ----end of EncoderConfiguration, kinematics and Dynamics ---- */ 
+
 }


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