- use thread for controller
- leave plot stuff in main thread git-svn-id: http://moon:8086/svn/projects/HendiControl@127 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
@@ -2,11 +2,37 @@
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
import configparser
|
|
||||||
from pid import Pid
|
|
||||||
from controller import Controller
|
from controller import Controller
|
||||||
from mass import Mass
|
from mass import Mass
|
||||||
from stirrer import Stirrer
|
from stirrer import Stirrer
|
||||||
|
from matplotlib.pyplot import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show, subplot
|
||||||
|
|
||||||
|
def results_plot(self):
|
||||||
|
|
||||||
|
figure(1)
|
||||||
|
subplot(4, 1, 1)
|
||||||
|
plot(self.time_v, self.theta_v, 'b-', linewidth=1)
|
||||||
|
title('Temperature')
|
||||||
|
grid(True)
|
||||||
|
ylabel('°C')
|
||||||
|
subplot(4, 1, 2)
|
||||||
|
plot(self.time_v, self.power_v, 'r-', linewidth=1)
|
||||||
|
title('Power')
|
||||||
|
grid(True)
|
||||||
|
ylabel('W')
|
||||||
|
subplot(4, 1, 3)
|
||||||
|
plot(self.time_v, self.error_v, 'b-', linewidth=1)
|
||||||
|
title('Error')
|
||||||
|
grid(True)
|
||||||
|
ylabel('°C')
|
||||||
|
subplot(4, 1, 4)
|
||||||
|
plot(self.time_v, self.heatrate_v, 'r-', linewidth=1)
|
||||||
|
title('Heatrate')
|
||||||
|
grid(True)
|
||||||
|
ylabel('°C/min')
|
||||||
|
xlabel('t/min')
|
||||||
|
show()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
@@ -21,7 +47,9 @@ if __name__ == '__main__':
|
|||||||
recipeJson = json.load(fp)
|
recipeJson = json.load(fp)
|
||||||
|
|
||||||
ablauf.start(recipeJson)
|
ablauf.start(recipeJson)
|
||||||
ablauf.stop()
|
ablauf.wait_finished()
|
||||||
|
|
||||||
|
results_plot(ablauf)
|
||||||
|
|
||||||
print ("End of program.")
|
print ("End of program.")
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import numpy as np
|
|||||||
import json
|
import json
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from pid import Pid
|
from pid import Pid
|
||||||
from matplotlib.pyplot import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show, subplot
|
|
||||||
from utils import Smoother, Stable
|
from utils import Smoother, Stable
|
||||||
import time
|
import time
|
||||||
|
import threading
|
||||||
|
|
||||||
ovenStates = Enum('ovenStates', 'NOP HEAT HOLD')
|
ovenStates = Enum('ovenStates', 'NOP HEAT HOLD')
|
||||||
controllerStates = Enum('controllerStates', 'ACQU TRACK')
|
controllerStates = Enum('controllerStates', 'ACQU TRACK')
|
||||||
@@ -33,6 +33,9 @@ class Controller():
|
|||||||
self.sim_warp_factor = 100
|
self.sim_warp_factor = 100
|
||||||
self.report_interval = 1.0
|
self.report_interval = 1.0
|
||||||
self.report_last_time = 0
|
self.report_last_time = 0
|
||||||
|
self.thread = None
|
||||||
|
self.rast_abort = False
|
||||||
|
self.receipe_sema = threading.Semaphore(0)
|
||||||
|
|
||||||
def log(self, s):
|
def log(self, s):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@@ -54,6 +57,22 @@ class Controller():
|
|||||||
def start(self, recipe):
|
def start(self, recipe):
|
||||||
print(json.dumps({recipe['Name'] : recipe}, indent=4, sort_keys=True))
|
print(json.dumps({recipe['Name'] : recipe}, indent=4, sort_keys=True))
|
||||||
|
|
||||||
|
self.thread = threading.Thread(target=self.receipe_run, args=(recipe,))
|
||||||
|
self.thread.start()
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
if self.thread != None:
|
||||||
|
self.rast_abort = True
|
||||||
|
self.thread.join()
|
||||||
|
self.thread = None
|
||||||
|
self.rast_abort = False
|
||||||
|
|
||||||
|
def wait_finished(self):
|
||||||
|
self.receipe_sema.acquire()
|
||||||
|
pass
|
||||||
|
|
||||||
|
def receipe_run(self, recipe):
|
||||||
|
|
||||||
# Stirrer
|
# Stirrer
|
||||||
self.stirrRpmHeat = recipe['stirrRpmHeat']
|
self.stirrRpmHeat = recipe['stirrRpmHeat']
|
||||||
self.stirrRpmRast = recipe['stirrRpmRast']
|
self.stirrRpmRast = recipe['stirrRpmRast']
|
||||||
@@ -65,30 +84,7 @@ class Controller():
|
|||||||
for rast in recipe['Rasten']:
|
for rast in recipe['Rasten']:
|
||||||
self.rast(rast)
|
self.rast(rast)
|
||||||
|
|
||||||
def stop(self):
|
self.receipe_sema.release()
|
||||||
figure(1)
|
|
||||||
subplot(4, 1, 1)
|
|
||||||
plot(self.time_v, self.theta_v, 'b-', linewidth=1)
|
|
||||||
title('Temperature')
|
|
||||||
grid(True)
|
|
||||||
ylabel('°C')
|
|
||||||
subplot(4, 1, 2)
|
|
||||||
plot(self.time_v, self.power_v, 'r-', linewidth=1)
|
|
||||||
title('Power')
|
|
||||||
grid(True)
|
|
||||||
ylabel('W')
|
|
||||||
subplot(4, 1, 3)
|
|
||||||
plot(self.time_v, self.error_v, 'b-', linewidth=1)
|
|
||||||
title('Error')
|
|
||||||
grid(True)
|
|
||||||
ylabel('°C')
|
|
||||||
subplot(4, 1, 4)
|
|
||||||
plot(self.time_v, self.heatrate_v, 'r-', linewidth=1)
|
|
||||||
title('Heatrate')
|
|
||||||
grid(True)
|
|
||||||
ylabel('°C/min')
|
|
||||||
xlabel('t/min')
|
|
||||||
show()
|
|
||||||
|
|
||||||
def rast(self, rast):
|
def rast(self, rast):
|
||||||
|
|
||||||
@@ -113,6 +109,9 @@ class Controller():
|
|||||||
theta_err_sm = Smoother(0.5)
|
theta_err_sm = Smoother(0.5)
|
||||||
heatrate_err_sm = Smoother(0.5)
|
heatrate_err_sm = Smoother(0.5)
|
||||||
while(doLoop):
|
while(doLoop):
|
||||||
|
if self.rast_abort:
|
||||||
|
break
|
||||||
|
|
||||||
time_start = time.time()
|
time_start = time.time()
|
||||||
|
|
||||||
controllerStateNext = self.controllerState
|
controllerStateNext = self.controllerState
|
||||||
|
|||||||
Reference in New Issue
Block a user