Commit 8fefca90 authored by Xavier de Blas's avatar Xavier de Blas

RunEncoder -> RaceAnalyzer, and reads/stores force column

parent 1b9eb1c0
......@@ -60,7 +60,7 @@ getSprintFromEncoder <- function(filename, testLength, Mass, Temperature = 25, H
Ka = 0.5*ro*Af*Cd
encoderCarrera = read.csv2(file = filename, sep = ";")
colnames(encoderCarrera) = c("displacement", "time")
colnames(encoderCarrera) = c("displacement", "time", "force")
totalTime = encoderCarrera$time/1E6 #Converting microseconds to seconds
elapsedTime = diff(c(0,totalTime)) #The elapsed time between each sample
......
......@@ -272,7 +272,7 @@ public class ChronoJump
//to store (encoder, force sensor, run encoder) data and graphs
UtilEncoder.CreateEncoderDirIfNeeded();
Util.CreateForceSensorDirIfNeeded();
Util.CreateRunEncoderDirIfNeeded();
Util.CreateRaceAnalyzerDirIfNeeded();
//TODO: when a session is deleted, encoder data has to be deleted, also multimedia videos, I suppose. Show message to user warning about it
//TODO: encoder weight auto written depending on person loaded, and changes if it changes person or weight
......
......@@ -266,19 +266,19 @@ public partial class ChronoJumpWindow
//forceCaptureStartMark = true;
capturingRunEncoder = arduinoCaptureStatus.CAPTURING;
Util.CreateRunEncoderSessionDirIfNeeded (currentSession.UniqueID);
Util.CreateRaceAnalyzerSessionDirIfNeeded (currentSession.UniqueID);
string nameDate = currentPerson.Name + "_" + UtilDate.ToFile(DateTime.Now);
//fileName to save the csv
string fileName = Util.GetRunEncoderSessionDir(currentSession.UniqueID) + Path.DirectorySeparatorChar + nameDate + ".csv";
string fileName = Util.GetRaceAnalyzerSessionDir(currentSession.UniqueID) + Path.DirectorySeparatorChar + nameDate + ".csv";
//lastRunEncoderFile to save the images
lastRunEncoderFile = nameDate;
TextWriter writer = File.CreateText(fileName);
writer.WriteLine("Pulses;Time(useconds)");
writer.WriteLine("Pulses;Time(useconds);Force(N)");
str = "";
int firstTime = 0;
......@@ -302,11 +302,13 @@ public partial class ChronoJumpWindow
continue;
//check if there is one and only one ';'
if( ! (str.Contains(";") && str.IndexOf(";") == str.LastIndexOf(";")) )
continue;
//if( ! (str.Contains(";") && str.IndexOf(";") == str.LastIndexOf(";")) )
string [] strFull = str.Split(new char[] {';'});
//LogB.Information("str: " + str);
LogB.Information("captured str: " + str);
if(strFull.Length != 3)
continue;
LogB.Information("pulses: " + strFull[0]);
if(! Util.IsNumber(strFull[0], false))
......@@ -316,6 +318,10 @@ public partial class ChronoJumpWindow
if(! Util.IsNumber(strFull[1], false))
continue;
LogB.Information("force avg (N): " + strFull[1]);
if(! Util.IsNumber(strFull[2], false))
continue;
/*
int time = Convert.ToInt32(strFull[0]);
......@@ -330,7 +336,8 @@ public partial class ChronoJumpWindow
*/
int pulse = Convert.ToInt32(strFull[0]);
int time = Convert.ToInt32(strFull[1]);
writer.WriteLine(pulse.ToString() + ";" + time.ToString());
int force = Convert.ToInt32(strFull[2]);
writer.WriteLine(pulse.ToString() + ";" + time.ToString() + ";" + force.ToString());
}
LogB.Information(string.Format("FINISHED WITH conditions: {0}-{1}-{2}",
runEncoderProcessFinish, runEncoderProcessCancel, runEncoderProcessError));
......@@ -367,7 +374,7 @@ public partial class ChronoJumpWindow
Util.FileDelete(fileName);
else {
//call graph. Prepare data
File.Copy(fileName, UtilEncoder.GetRunEncoderCSVFileName(), true); //can be overwritten
File.Copy(fileName, UtilEncoder.GetRaceAnalyzerCSVFileName(), true); //can be overwritten
lastRunEncoderFullPath = fileName;
//create graph
......@@ -389,7 +396,7 @@ public partial class ChronoJumpWindow
LogB.Information("File exists on png, trying to copy");
try {
File.Copy(UtilEncoder.GetSprintEncoderImage(),
Util.GetRunEncoderSessionDir(currentSession.UniqueID) + Path.DirectorySeparatorChar +
Util.GetRaceAnalyzerSessionDir(currentSession.UniqueID) + Path.DirectorySeparatorChar +
lastRunEncoderFile + //nameDate
".png",
true); //can be overwritten
......@@ -412,7 +419,7 @@ public partial class ChronoJumpWindow
string str = "";
if (portRE.BytesToRead > 0)
str = portRE.ReadLine();
//LogB.Information("PRE_get_calibrationfactor bytes: " + portFS.ReadExisting());
//LogB.Information("PRE_get_calibrationfactor bytes: " + portRE.ReadExisting());
return str;
}
......
......@@ -41,7 +41,7 @@ public class RunEncoderGraph
{
LogB.Information("\nrunEncoder CallR ----->");
writeOptionsFile(graphWidth, graphHeight);
return ExecuteProcess.CallR(UtilEncoder.GetRunEncoderScript());
return ExecuteProcess.CallR(UtilEncoder.GetRaceAnalyzerScript());
}
private void writeOptionsFile(int graphWidth, int graphHeight)
......@@ -55,7 +55,7 @@ public class RunEncoderGraph
string scriptOptions =
"#scriptsPath\n" + UtilEncoder.GetScriptsPath() + "\n" +
"#filename\n" + UtilEncoder.GetRunEncoderCSVFileName() + "\n" +
"#filename\n" + UtilEncoder.GetRaceAnalyzerCSVFileName() + "\n" +
"#mass\n" + Util.ConvertToPoint(mass) + "\n" +
"#personHeight\n" + Util.ConvertToPoint(personHeight / 100.0) + "\n" + //send it in meters
"#tempC\n" + tempC + "\n" +
......
......@@ -980,15 +980,15 @@ public class Util
*/
//to store run encoder data and graphs
public static string GetRunEncoderDir()
public static string GetRaceAnalyzerDir()
{
return Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Chronojump" + Path.DirectorySeparatorChar + "runEncoder");
"Chronojump" + Path.DirectorySeparatorChar + "raceAnalyzer");
}
public static void CreateRunEncoderDirIfNeeded ()
public static void CreateRaceAnalyzerDirIfNeeded ()
{
string dir = GetRunEncoderDir();
string dir = GetRaceAnalyzerDir();
if( ! Directory.Exists(dir)) {
Directory.CreateDirectory (dir);
LogB.Information ("created dir:", dir);
......@@ -996,13 +996,13 @@ public class Util
}
//runEncoder organized by sessions.
public static string GetRunEncoderSessionDir (int sessionID)
public static string GetRaceAnalyzerSessionDir (int sessionID)
{
return GetRunEncoderDir() + Path.DirectorySeparatorChar + sessionID.ToString();
return GetRaceAnalyzerDir() + Path.DirectorySeparatorChar + sessionID.ToString();
}
public static void CreateRunEncoderSessionDirIfNeeded (int sessionID)
public static void CreateRaceAnalyzerSessionDirIfNeeded (int sessionID)
{
string dir = GetRunEncoderSessionDir(sessionID);
string dir = GetRaceAnalyzerSessionDir(sessionID);
if( ! Directory.Exists(dir)) {
Directory.CreateDirectory (dir);
LogB.Information ("created dir:", dir);
......
......@@ -254,14 +254,14 @@ public class UtilEncoder
return System.IO.Path.Combine(Util.GetDataDir(), "r-scripts");
}
public static string GetRunEncoderScript() {
public static string GetRaceAnalyzerScript() {
return System.IO.Path.Combine(GetSprintPath(), "sprintEncoder.R");
}
public static string GetRunEncoderCSVFileName() {
return Path.Combine(Path.GetTempPath(), "cj_run_encoder_data.csv");
public static string GetRaceAnalyzerCSVFileName() {
return Path.Combine(Path.GetTempPath(), "cj_race_analyzer_data.csv");
}
public static string GetRunEncoderTempFileName() {
return Path.Combine(Path.GetTempPath(), "cj_run_encoder_graph.png");
public static string GetRaceAnalyzerTempFileName() {
return Path.Combine(Path.GetTempPath(), "cj_race_analyzer_graph.png");
}
public static string GetmifScript() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment