From 58e7eb247d004a567c731d2c45cc49fb69a1ee94 Mon Sep 17 00:00:00 2001
From: Carl Philipp Klemm <philipp@uvos.xyz>
Date: Mon, 11 Dec 2023 17:25:30 +0100
Subject: [PATCH] Randomize temperature charge is preformed

---
 coincell.cpp     | 10 ++++++++++
 coincell.h       |  3 +++
 expiramentimpl.h | 52 ++++++++++++++++++++++++++++++++++++++++++------
 3 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/coincell.cpp b/coincell.cpp
index 542b7c3..4780119 100644
--- a/coincell.cpp
+++ b/coincell.cpp
@@ -34,6 +34,16 @@ bool CoinCell::measureOcv(float& ocv)
 	return ret;
 }
 
+void CoinCell::setLastKnownCapacity(double cap)
+{
+	lastKnownCap = cap;
+}
+
+double CoinCell::getLastKnownCapacity()
+{
+	return lastKnownCap;
+}
+
 bool  CoinCell::getTemperature(float& temperature)
 {
 	bool ret = heaters->getTemperature(heaterId, temperature);
diff --git a/coincell.h b/coincell.h
index 2284d23..795481a 100644
--- a/coincell.h
+++ b/coincell.h
@@ -16,6 +16,7 @@ private:
 	int multiplexerCh;
 	Heaters* heaters;
 	Multiplexers* multiplexers;
+	double lastKnownCap = -1;
 
 	static BioControl biocontrol;
 
@@ -34,6 +35,8 @@ public:
 	bool isShorted(bool& detected);
 	bool measureEis(std::filesystem::path path, std::string userStr = "");
 	bool setEnabled(bool enable);
+	double getLastKnownCapacity();
+	void setLastKnownCapacity(double cap);
 
 	static void setBiocontrol(const BioControl& biocontrol);
 };
diff --git a/expiramentimpl.h b/expiramentimpl.h
index 780c9d4..1592f99 100644
--- a/expiramentimpl.h
+++ b/expiramentimpl.h
@@ -1,5 +1,8 @@
 #include "expirament.h"
 #include <memory>
+#include <algorithm>
+
+#include "randomgen.h"
 
 bool Expirament::step(size_t startsubstep)
 {
@@ -11,6 +14,8 @@ bool Expirament::step(size_t startsubstep)
 	saveStep(startsubstep);
 
 	std::vector<double> steps = createStepSequence(3, 2, 0, 1);
+	std::vector<double> chargeThermalSteps(5);
+	std::for_each(chargeThermalSteps.begin(), chargeThermalSteps.end(), [](double& in){in = rd::rand(1, 0);});
 
 	bool ret = true;
 	switch(globalstep % STEP_COUNT)
@@ -19,36 +24,71 @@ bool Expirament::step(size_t startsubstep)
 			ret = thermalCycle(CYCLES_PER_STEP, startsubstep);
 			break;
 		case 1:
+			Log(Log::INFO)<<"Charing for globalstep "<<globalstep<<" will be executed at "<<chargeThermalSteps[0]<<" temperature";
+			setTemperatures(chargeThermalSteps[0]);
+			ret = heaters->allReady();
+			if(!ret)
+			{
+				Log(Log::ERROR)<<"Not all heaters moved to ready state in globalstep"<<globalstep;
+				break;
+			}
 			ret = charge(steps[0]);
-			ret &= takeMesurements();
 			break;
 		case 2:
 			ret = thermalCycle(CYCLES_PER_STEP, startsubstep);
 			break;
 		case 3:
+			Log(Log::INFO)<<"Charing for globalstep "<<globalstep<<" will be executed at "<<chargeThermalSteps[0]<<" temperature";
+			setTemperatures(chargeThermalSteps[1]);
+			ret = heaters->allReady();
+			if(!ret)
+			{
+				Log(Log::ERROR)<<"Not all heaters moved to ready state in globalstep"<<globalstep;
+				break;
+			}
 			ret = charge(steps[1]);
-			ret &= takeMesurements();
 			break;
 		case 4:
 			ret = thermalCycle(CYCLES_PER_STEP, startsubstep);
 			break;
 		case 5:
+			Log(Log::INFO)<<"Charing for globalstep "<<globalstep<<" will be executed at "<<chargeThermalSteps[0]<<" temperature";
+			setTemperatures(chargeThermalSteps[2]);
+			ret = heaters->allReady();
+			if(!ret)
+			{
+				Log(Log::ERROR)<<"Not all heaters moved to ready state in globalstep"<<globalstep;
+				break;
+			}
 			ret = charge(steps[2]);
-			ret &= takeMesurements();
 			break;
 		case 6:
-			ret = thermalCycle(CYCLES_PER_STEP);
+			ret = thermalCycle(CYCLES_PER_STEP, startsubstep);
 			break;
 		case 7:
+			Log(Log::INFO)<<"Charing for globalstep "<<globalstep<<" will be executed at "<<chargeThermalSteps[0]<<" temperature";
+			setTemperatures(chargeThermalSteps[3]);
+			ret = heaters->allReady();
+			if(!ret)
+			{
+				Log(Log::ERROR)<<"Not all heaters moved to ready state in globalstep"<<globalstep;
+				break;
+			}
 			ret = charge(steps[3]);
-			ret &= takeMesurements();
 			break;
 		case 8:
 			ret = thermalCycle(CYCLES_PER_STEP, startsubstep);
 			break;
 		case 9:
+			Log(Log::INFO)<<"Charing for globalstep "<<globalstep<<" will be executed at "<<chargeThermalSteps[0]<<" temperature";
+			setTemperatures(chargeThermalSteps[4]);
+			ret = heaters->allReady();
+			if(!ret)
+			{
+				Log(Log::ERROR)<<"Not all heaters moved to ready state in globalstep"<<globalstep;
+				break;
+			}
 			ret = charge(steps[4]);
-			ret &= takeMesurements();
 			break;
 		case 10:
 			ret = thermalCycle(CYCLES_PER_STEP, startsubstep);
-- 
GitLab