from components.pid.temp_controller_base import TempControllerBase


class TempController(TempControllerBase):
	def __init__(self, dt):
		TempControllerBase.__init__(self, dt)
		# last_theta_ist / theta_ist_filtered / beta / dt all live in the base -
		# see TempControllerBase.__init__ and _compute_heatrate().

	def process(self):
		self._require_params()

		self.theta_ist = self.theta_ist_set
		self._compute_heatrate(self.theta_ist)

		# Compensate for max heat rate to reduce overshoot
		hold_scale = 1.0/self.heatrate_soll_set if self.heatrate_soll_set > 0 else 1.0

		self.heatrate_soll = self.heatrate_soll_set * self.pid_hold.get_y()
		theta_err = self.theta_soll_set - self.theta_ist
		heatrate_err = self.heatrate_soll - self.heatrate_ist

		diff = self.theta_soll_set - self.theta_ist
		self.process_fsm(diff)
		self.process_pid(theta_err, heatrate_err, hold_scale)
