- refactored dt
This commit is contained in:
@@ -9,7 +9,7 @@ from components.plant import Pot
|
||||
from components.actor import HeaterFactory, StirrerFactory
|
||||
from tasks import TaskManager, TempSensorTask, HeaterTask, PotTask, TcTask, StirrerTask, TracerTask
|
||||
|
||||
DT_CTRL = 0.1
|
||||
DT_TASK = 0.1
|
||||
|
||||
if __name__ == '__main__':
|
||||
config = json.load(open("config.json"))
|
||||
@@ -17,40 +17,41 @@ if __name__ == '__main__':
|
||||
server = WsServerMultiUser(listener=dispatcher)
|
||||
taskmgr = TaskManager()
|
||||
|
||||
DT_CTRL = 1.0/config['Controller']['sim_warp_factor']
|
||||
DT = config['Controller']['dt']
|
||||
DT_TASK = 1.0 / config['Controller']['sim_warp_factor']
|
||||
|
||||
# Sensor
|
||||
sensor = TempSensorFactory.create(config['Controller']['sensor_name'])
|
||||
taskmgr.add(TempSensorTask(sensor, DT_CTRL, dispatcher.msgio_get("Sensor")))
|
||||
taskmgr.add(TempSensorTask(sensor, DT_TASK, dispatcher.msgio_get("Sensor")))
|
||||
|
||||
# Plant
|
||||
pot_params = config['Plant']
|
||||
pot = Pot(pot_params, 20)
|
||||
pot = Pot(DT, pot_params, 20)
|
||||
if "sim" in config['Controller']['sensor_name']:
|
||||
pot.set_on_changed("temp", ChangedFloat(sensor.set_fake_temp, prec=3).set)
|
||||
taskmgr.add(PotTask(pot, DT_CTRL, dispatcher.msgio_get("Pot")))
|
||||
taskmgr.add(PotTask(pot, DT_TASK, dispatcher.msgio_get("Pot")))
|
||||
|
||||
# Heater
|
||||
heater = HeaterFactory.create(config['Controller']['heater_name'], config['Heater'])
|
||||
heater = HeaterFactory.create(config['Controller']['heater_name'], DT, config['Heater'])
|
||||
heater.set_on_changed("power_eff", ChangedFloat(pot.set_power, prec=0).set)
|
||||
heater_task = HeaterTask(heater, DT_CTRL, dispatcher.msgio_get("Heater"))
|
||||
heater_task = HeaterTask(heater, DT_TASK, dispatcher.msgio_get("Heater"))
|
||||
taskmgr.add(heater_task)
|
||||
|
||||
# Temperature Controller
|
||||
tc_params = config['TempCtrl']
|
||||
tc = TempController(tc_params)
|
||||
tc = TempController(DT, tc_params)
|
||||
tc.set_on_changed("y", heater_task.actor)
|
||||
tc_task = TcTask(tc, DT_CTRL, dispatcher.msgio_get("TempCtrl"))
|
||||
tc_task = TcTask(tc, DT_TASK, dispatcher.msgio_get("TempCtrl"))
|
||||
taskmgr.add(tc_task)
|
||||
sensor.set_on_changed("temp", ChangedFloat(tc.set_theta_ist, prec=2).set)
|
||||
|
||||
# Stirrer
|
||||
stirrer = StirrerFactory.create(config['Controller']['stirrer_name'], config['Stirrer'])
|
||||
stirrer_task = StirrerTask(stirrer, DT_CTRL, dispatcher.msgio_get("Stirrer"))
|
||||
stirrer = StirrerFactory.create(config['Controller']['stirrer_name'], DT, config['Stirrer'])
|
||||
stirrer_task = StirrerTask(stirrer, DT_TASK, dispatcher.msgio_get("Stirrer"))
|
||||
taskmgr.add(stirrer_task)
|
||||
|
||||
# Tracer
|
||||
taskmgr.add(TracerTask(sensor, heater, tc, DT_CTRL, dispatcher.msgio_get("Tracer")))
|
||||
taskmgr.add(TracerTask(sensor, heater, tc, DT_TASK, dispatcher.msgio_get("Tracer")))
|
||||
|
||||
# Message dispatcher
|
||||
h_dispatcher = taskmgr.start()
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
class HeaterFactory:
|
||||
@staticmethod
|
||||
def create(name, params):
|
||||
def create(name, dt, params):
|
||||
if "sim" in name:
|
||||
from components.actor.heater_sim import HeaterSim
|
||||
return HeaterSim()
|
||||
elif "Hendi" in name:
|
||||
from components.actor.heater_hendi import HeaterHendi
|
||||
return HeaterHendi(params)
|
||||
return HeaterHendi(dt, params)
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
class StirrerFactory:
|
||||
@staticmethod
|
||||
def create(name, params):
|
||||
def create(name, dt, params):
|
||||
if "sim" in name:
|
||||
from components.actor.stirrersim import StirrerSim
|
||||
return StirrerSim(params)
|
||||
return StirrerSim(dt)
|
||||
elif "1376" in name:
|
||||
from components.actor.stirrerpololu1376 import StirrerPololu1376
|
||||
return StirrerPololu1376(params)
|
||||
return StirrerPololu1376(dt, params)
|
||||
|
||||
@@ -8,8 +8,8 @@ class StirrerPololu1376(AStirrer):
|
||||
def name(self):
|
||||
return "Pololu1376"
|
||||
|
||||
def __init__(self, params):
|
||||
AStirrer.__init__(self, params['dt'])
|
||||
def __init__(self, dt, params):
|
||||
AStirrer.__init__(self, dt)
|
||||
self.isMasterOn = 0
|
||||
|
||||
self.ser_speed = params['speed']
|
||||
|
||||
@@ -3,8 +3,8 @@ import time
|
||||
|
||||
|
||||
class StirrerSim(AStirrer):
|
||||
def __init__(self, params):
|
||||
AStirrer.__init__(self, params['dt'])
|
||||
def __init__(self, dt):
|
||||
AStirrer.__init__(self, dt)
|
||||
|
||||
def activate(self, enable):
|
||||
print("activate {}".format(enable))
|
||||
|
||||
@@ -13,9 +13,8 @@ class States(Enum):
|
||||
|
||||
|
||||
class TempController(AttributeChange):
|
||||
def __init__(self, params):
|
||||
def __init__(self, dt, params):
|
||||
AttributeChange.__init__(self)
|
||||
dt = params['dt']
|
||||
self.pid_hold = Pid(dt)
|
||||
self.pid_rate = Pid(dt)
|
||||
self.theta_ist_set = 20
|
||||
@@ -108,8 +107,9 @@ class TempController(AttributeChange):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
dt = 1.0
|
||||
|
||||
tc_params = {
|
||||
"dt": 1.0,
|
||||
"Kalman": {
|
||||
"var_P" : 1.0,
|
||||
"var_Q" : 0.0001,
|
||||
@@ -130,7 +130,6 @@ if __name__ == '__main__':
|
||||
}
|
||||
|
||||
pot_params = {
|
||||
"dt" : 1.0,
|
||||
"theta" : 20,
|
||||
"C" : 4190,
|
||||
"M" : 20,
|
||||
@@ -141,8 +140,8 @@ if __name__ == '__main__':
|
||||
|
||||
temp_ist = 0
|
||||
temp_soll = 20
|
||||
ctrl = TempController(tc_params)
|
||||
plant = Pot(pot_params)
|
||||
ctrl = TempController(dt, tc_params)
|
||||
plant = Pot(dt, pot_params)
|
||||
_temp_ist = np.empty(0)
|
||||
_temp_soll = np.empty(0)
|
||||
_y = np.empty(0)
|
||||
|
||||
@@ -3,9 +3,9 @@ from components.plant.delay import Delay
|
||||
|
||||
|
||||
class Pot(APlant):
|
||||
def __init__(self, params, theta_amb=20):
|
||||
def __init__(self, dt, params, theta_amb=20):
|
||||
APlant.__init__(self)
|
||||
self.dt = params['dt']
|
||||
self.dt = dt
|
||||
self.alpha = 1.0
|
||||
|
||||
self.e = 0
|
||||
|
||||
Reference in New Issue
Block a user