diff --git a/Ccs/thermal_control.py b/Ccs/thermal_control.py index 1ceb39c9e0d83136a3733d6ea189acac482959fa..a32b8eb78e78b510164df4a4dfcb22e60d319663 100644 --- a/Ccs/thermal_control.py +++ b/Ccs/thermal_control.py @@ -19,7 +19,7 @@ class ThermalController: VCTRLUPPERVOLT = 2.8 MAXDELTAVOLTAGE = 0.2 - def __init__(self, temp_ref, coeffP, coeffI, offset, exec_per, model=None): + def __init__(self, temp_ref, coeffP, coeffI, offset, exec_per, model=None, pi=True, deltaTmax=1.): self.tempRef = temp_ref self.coeffP = coeffP @@ -37,6 +37,13 @@ class ThermalController: self.hctrl_par_exec_per = exec_per self._algo_active = False + if pi: + self.calc_vctrl = self.do_pi_vctrl + else: + self.calc_vctrl = self.on_off_vctrl + + self.deltaTmax = deltaTmax + self.model = model self.log = [] @@ -45,7 +52,7 @@ class ThermalController: def set_temp_ref(self, temp): self.tempRef = temp - def calculate_vctrl(self, temp): + def do_pi_vctrl(self, temp): deltaTime = self.hctrl_par_exec_per * self.ASW_PERIOD_MS / 1000 integ = self.integOld + deltaTime * (self.tempRef - self.tempOld) @@ -69,11 +76,11 @@ class ThermalController: self.voltCtrlUint16 = vctrl_ana_to_dig(self.voltCtrl) - def on_off_vctrl(self, temp, deltaTmax=1.): + def on_off_vctrl(self, temp): - if temp > self.tempRef + deltaTmax: + if temp > self.tempRef + self.deltaTmax: v = self.voltCtrl - self.MAXDELTAVOLTAGE - elif temp < self.tempRef - deltaTmax: + elif temp < self.tempRef - self.deltaTmax: v = self.voltCtrl + self.MAXDELTAVOLTAGE else: v = self.voltCtrl @@ -121,14 +128,13 @@ class ThermalController: 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.calc_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) + self.calc_vctrl(self.temp) def stop_algo(self): self._algo_active = False diff --git a/Ccs/thermal_model.py b/Ccs/thermal_model.py index c0fe87b8a95c8032e4b96d14de5b61f6bb58f83e..5ad00aa4994890384505aa1cbdc185920792a0ed 100644 --- a/Ccs/thermal_model.py +++ b/Ccs/thermal_model.py @@ -140,6 +140,8 @@ class ThermalModel: self.htr_pwr = 0 self.htr_cur = 0 + self.inst_heat = 0 # additional, immediate heat input (e.g., from CCD, etc.) + self._evolving = False self.record = record self.log = [] @@ -179,7 +181,8 @@ class ThermalModel: def heat(self): self.heat_pipe += self.htr_pwr * self.heat_distr - addheat = self.heat_pipe[0] + addheat = self.heat_pipe[0] + self.inst_heat + #print(self.heat_pipe, self.heat_pipe.sum(), self.htr_pwr,self.inst_heat) self.heat_pipe = np.roll(self.heat_pipe, -1) self.heat_pipe[-1] = 0 return addheat