Added VO2 calculate function

This commit is contained in:
Janco Kock
2015-11-01 21:22:44 +01:00
parent 4f322fd866
commit 171b1b95d7
3 changed files with 54 additions and 12 deletions
@@ -13,11 +13,11 @@ namespace ErgometerApplication
private int age;
private char gender;
private enum state {WARMUP, WORKLOAD, COOLINGDOWN};
private enum state {WARMUP, WORKLOAD, COOLINGDOWN, STOP};
private state currentstate;
private int workloadStarted;
private int workloadHearthbeat;
private int workloadnumber;
private List<Workload> workloads;
public ErgometerTest(int weight, int length , int age, char gender)
{
@@ -26,8 +26,10 @@ namespace ErgometerApplication
this.age = age;
this.gender = gender;
currentstate = state.WARMUP;
workloadnumber = 1;
workloads = new List<Workload>();
MainClient.ComPort.Write("SET PW 25");
Console.WriteLine(CalculateVOMaxTest());
}
public void timerTick()
@@ -58,15 +60,15 @@ namespace ErgometerApplication
//Checken of de heartrate niet groter is dan 75%, anders stoppen
if (workloadHearthbeat > CalculateMaximumHeartRate())
{
workloadStarted = MainClient.GetLastMeting().Seconds;
currentstate = state.COOLINGDOWN;
}
MainClient.ComPort.Write("PW " + GetWorkloadPower(workloadnumber));
workloads.Add(new Workload(MainClient.GetLastMeting().Power, workloadHearthbeat));
MainClient.ComPort.Write("PW " + GetWorkloadPower(workloads.Count-1));
workloadStarted = MainClient.GetLastMeting().Seconds;
workloadHearthbeat = 0;
workloadnumber++;
Console.WriteLine("3:00 gefietst, workload" + workloadnumber + " af, nieuwe waardes maken");
Console.WriteLine("3:00 gefietst, workload" + (workloads.Count - 1) + " af, nieuwe waardes maken");
}
else if (MainClient.GetLastMeting().Seconds - workloadStarted > 160 && workloadHearthbeat == 0)
{
@@ -75,19 +77,23 @@ namespace ErgometerApplication
Console.WriteLine("2:40 gefiets, gemiddelde harstslag berekenen:" + workloadHearthbeat);
}
break;
case state.COOLINGDOWN:
case state.COOLINGDOWN:
MainClient.ComPort.Write("SET PW 25");
if(MainClient.GetLastMeting().Seconds - workloadStarted > 360)
{
currentstate = state.STOP;
}
break;
}
}
// WORKLOAD //
private int GetWorkloadPower(int workload)
{
if (gender == 'V')
{
if (workloadnumber == 1)
if (workload == 1)
{
if (workloadHearthbeat < 80)
return 125;
@@ -105,7 +111,7 @@ namespace ErgometerApplication
}
else if(gender == 'M')
{
if(workloadnumber == 1)
if(workload == 1)
{
if (workloadHearthbeat < 90)
return 150;
@@ -114,7 +120,7 @@ namespace ErgometerApplication
else
return 100;
}
else if(workloadnumber == 2)
else if(workload == 2)
{
if(workloadHearthbeat < 120)
{
@@ -153,6 +159,16 @@ namespace ErgometerApplication
return 25;
}
// CALCULATOR FUNCTIONS //
public double CalculateVOMax()
{
Workload wa = workloads[workloads.Count - 2];
Workload wb = workloads.Last();
var LmA = 0.32643 + 0.55275 * wa.getKiloponds() + 0.014429 * Math.Pow(wa.getKiloponds(), 2) + 0.00025271 * Math.Pow(wa.getKiloponds(), 3); var LmB = 0.32643 + 0.55275 * wb.getKiloponds() + 0.014429 * Math.Pow(wb.getKiloponds(), 2) + 0.00025271 * Math.Pow(wb.getKiloponds(), 3); var VOABS = LmB + ((LmB - LmA) / (wb.heartrate - wa.heartrate)) * (220 - age - wb.heartrate); return VOABS * 1000 / weight;
}
// HELPER FUNCTIONS //