diff --git a/brewpi/brewpi.py b/brewpi/brewpi.py index 3a829d6..29b1fd2 100755 --- a/brewpi/brewpi.py +++ b/brewpi/brewpi.py @@ -29,6 +29,7 @@ if __name__ == '__main__': DT = config['Controller']['dt'] DT_TASK = 1.0 / config['Controller']['sim_warp_factor'] DT_TASK_TRACER = DT_TASK / DT + theta_amb = config['ambient_temperature'] # Sensor sensor = TempSensorFactory.create(config['Controller']['sensor_name'], temp_offset=-0.15, variance=0.01) @@ -37,7 +38,7 @@ if __name__ == '__main__': # Plant pot_params = config['Plant'] - pot = Pot(DT, pot_params, 20) + pot = Pot(DT, pot_params, theta_amb) taskmgr.add(PotTask(pot, DT_TASK, dispatcher.msgio_get("Pot"))) # Heater @@ -47,7 +48,7 @@ if __name__ == '__main__': taskmgr.add(heater_task) # Temperature Controller - tc = PidFactory.create(config['Controller']['pid_type'], DT, config['TempCtrl'], config['Model']) + tc = PidFactory.create(config['Controller']['pid_type'], DT, config['TempCtrl'], config['Model'], theta_amb=theta_amb) tc_task = TcTask(tc, DT_TASK, dispatcher.msgio_get("TempCtrl")) taskmgr.add(tc_task) diff --git a/components/pid/temp_controller_smith.py b/components/pid/temp_controller_smith.py index 39ef492..ee336fb 100755 --- a/components/pid/temp_controller_smith.py +++ b/components/pid/temp_controller_smith.py @@ -3,7 +3,7 @@ from components.pid.temp_controller_base import TempControllerBase, States class TempController(TempControllerBase): - def __init__(self, dt, params, model_params): + def __init__(self, dt, params, model_params, theta_amb=20): TempControllerBase.__init__(self, dt, params) self.dt = dt self.last_theta_ist = 20 @@ -11,10 +11,10 @@ class TempController(TempControllerBase): # Fast model: same plant model but with zero transport delay, used # to predict the current temperature without the dead time. - self.model = Pot(dt, {**model_params, 'Td': 0}) + self.model = Pot(dt, {**model_params, 'Td': 0}, theta_amb) # Delayed model: keeps the plant's assumed transport delay, so it # can be compared like-for-like against the real (delayed) measurement. - self.model_delay = Pot(dt, model_params) + self.model_delay = Pot(dt, model_params, theta_amb) self.theta_ist_plant = 0 self.theta_ist_model = 0 diff --git a/config.json.sim b/config.json.sim index 6148917..563b6e3 100755 --- a/config.json.sim +++ b/config.json.sim @@ -1,4 +1,5 @@ { + "ambient_temperature": 20, "Controller" : { "dt": 0.1, "sim_warp_factor": 10.0, diff --git a/config.json.templ b/config.json.templ index c0a323c..2c581a5 100644 --- a/config.json.templ +++ b/config.json.templ @@ -1,4 +1,5 @@ { + "ambient_temperature": 20, "Controller" : { "dt": 1, "sim_warp_factor": 10.0, diff --git a/scripts/demos/pid/demo_temp_controller.py b/scripts/demos/pid/demo_temp_controller.py index 9e0b8a1..9b6e765 100644 --- a/scripts/demos/pid/demo_temp_controller.py +++ b/scripts/demos/pid/demo_temp_controller.py @@ -31,13 +31,14 @@ if __name__ == '__main__': } dt = 1.0 + theta_amb = 20 k_noise = 0.001 temp_ist = 0 temp_soll = 20 heatrate_soll = 1.25 ctrl = TempController(dt, ctrl_params) - plant = Pot(dt, plant_params) + plant = Pot(dt, plant_params, theta_amb) _y = np.empty(0) _fb = np.empty(0) _t = np.empty(0) diff --git a/scripts/demos/pid/demo_temp_controller_smith.py b/scripts/demos/pid/demo_temp_controller_smith.py index 31e7027..0723ae7 100644 --- a/scripts/demos/pid/demo_temp_controller_smith.py +++ b/scripts/demos/pid/demo_temp_controller_smith.py @@ -31,13 +31,14 @@ if __name__ == '__main__': } dt = 1.0 + theta_amb = 20 k_noise = 0.001 temp_ist = 0 temp_soll = 20 heatrate_soll = 1.25 - ctrl = TempController(dt, ctrl_params, plant_params) - plant = Pot(dt, plant_params) + ctrl = TempController(dt, ctrl_params, plant_params, theta_amb) + plant = Pot(dt, plant_params, theta_amb) _y = np.empty(0) _fb = np.empty(0) _t = np.empty(0) diff --git a/scripts/demos/plant/demo_pot.py b/scripts/demos/plant/demo_pot.py index 181d5be..bf06a06 100644 --- a/scripts/demos/plant/demo_pot.py +++ b/scripts/demos/plant/demo_pot.py @@ -5,6 +5,7 @@ from components.plant.pot import Pot if __name__ == '__main__': dt = 1.0 + theta_amb = 20 power_on = 3500 steps_heat = 4000 steps_cool = 40000 @@ -18,7 +19,7 @@ if __name__ == '__main__': "gain" : 1.0 } - pot = Pot(dt, pot_params) + pot = Pot(dt, pot_params, theta_amb) _t = np.empty(0) _temp = np.empty(0)