Skip to content
Snippets Groups Projects
Commit 21eaf172 authored by Marko Mecina's avatar Marko Mecina
Browse files

update SXI thermal control

parent b34d8df8
No related branches found
No related tags found
No related merge requests found
......@@ -15,24 +15,24 @@ class ThermalController:
ASW_PERIOD_MS = 125.
VCTRLLOWERVOLT = 0.2
VCTRLUPPERVOLT = 2.9
MAXDELTAVOLTAGE = 0.25
VCTRLLOWERVOLT = 0.4
VCTRLUPPERVOLT = 2.8
MAXDELTAVOLTAGE = 0.2
def __init__(self, temp_ref, cp, ci, offset, exec_per, model=None):
def __init__(self, temp_ref, coeffP, coeffI, offset, exec_per, model=None):
self.tempRef = temp_ref
self.coeffP = cp
self.coeffI = ci
self.coeffP = coeffP
self.coeffI = coeffI
self.offset = offset
self.temp = 0
self.voltCtrl = 0
self.temp = temp_ref
self.voltCtrl = self.VCTRLLOWERVOLT
self.voltCtrlUint16 = vctrl_ana_to_dig(self.voltCtrl)
self.tempOld = temp_ref
self.integOld = 0
self.voltCtrlOld = 0
self.voltCtrlOld = self.VCTRLLOWERVOLT
self.hctrl_par_exec_per = exec_per
self._algo_active = False
......@@ -69,6 +69,22 @@ class ThermalController:
self.voltCtrlUint16 = vctrl_ana_to_dig(self.voltCtrl)
def on_off_vctrl(self, temp, deltaTmax=1.):
if temp > self.tempRef + deltaTmax:
v = self.voltCtrl - self.MAXDELTAVOLTAGE
elif temp < self.tempRef - deltaTmax:
v = self.voltCtrl + self.MAXDELTAVOLTAGE
else:
v = self.voltCtrl
if v > self.VCTRLUPPERVOLT:
self.voltCtrl = self.VCTRLUPPERVOLT
elif v < self.VCTRLLOWERVOLT:
self.voltCtrl = self.VCTRLLOWERVOLT
else:
self.voltCtrl = v
def start_algo(self):
if self._thread is not None and self._thread.is_alive():
......@@ -87,14 +103,10 @@ class ThermalController:
t1 = time.time()
if self.model is not None:
self.temp = self.model.T_noisy
self.calculate_vctrl(self.temp)
self.model.set_heater_power(vctrl=self.voltCtrl)
self.log.append((t1, self.tempRef, self.temp, self.voltCtrl, self.coeffI*self.integOld, self.coeffP * (self.tempRef - self.temp)))
self._step(t1, with_model=True)
else:
self.calculate_vctrl(self.temp)
self._step(t1, with_model=False)
dt = (self.ASW_PERIOD_MS / 1000 * self.hctrl_par_exec_per) - (time.time() - t1)
if dt > 0:
......@@ -106,8 +118,21 @@ class ThermalController:
print('TTC algo stopped')
def _step(self, t1, with_model=True, glitch=0):
if with_model:
self.temp = self.model.T_noisy + glitch
self.calculate_vctrl(self.temp)
# self.on_off_vctrl(self.temp)
self.model.set_heater_power(vctrl=self.voltCtrl)
self.log.append((t1, self.tempRef, self.temp, self.voltCtrl, self.coeffI * self.integOld, self.coeffP * (self.tempRef - self.temp)))
else:
self.calculate_vctrl(self.temp)
def stop_algo(self):
self._algo_active = False
def save_log(self, fname):
np.savetxt(fname, np.array(self.log), header='time\tT_ref\tT\tV_ctrl\tcI*integ\tcP*(T_ref-T)')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment