Beispiel #1
0
    def __init__(self, parent=None):
        # Set up device
        self.dev = reflow.Reflow()
        self.dev.set_pwm_period(PWM_PERIOD) 
        self.dev.set_mode('off')
        temp = self.dev.get_therm_value()

        # Create set point function
        self.reflow_profile = reflow_profile.Reflow_Profile(start_T=temp)
        stop_t = self.reflow_profile.stop_time()

        # Setup controller
        self.model = delay_model.Therm_Delay_Model(T_amb=temp)
        self.model.load_param('model_param.pkl')
        self.pgain = PGAIN 
        self.igain = IGAIN 
        self.controller = controller.PI_Controller(
            self.reflow_profile.func, 
            self.pgain,
            self.igain,
            ff_func = self.model.ctl_for_steady_state
        )

        # Set Gui main window
        QtGui.QWidget.__init__(self,parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Connect buttons and checkbox
        self.connect(self.ui.startButton, QtCore.SIGNAL('clicked()'), self.on_start_clicked)
        self.connect(self.ui.stopButton, QtCore.SIGNAL('clicked()'), self.on_stop_clicked)
        self.connect(self.ui.resetButton, QtCore.SIGNAL('clicked()'), self.on_reset_clicked)
        self.connect(self.ui.controlCheckbox, QtCore.SIGNAL('clicked()'), self.on_control_clicked)

        # Set up event timer
        self.timer = QtCore.QTimer()
        self.connect(self.timer, QtCore.SIGNAL('timeout()'), self.on_timer_update)
        self.timer.setInterval(TIMER_INTERVAL)
        self.timer.start()

        # Set lcd display
        self.update_lcd(temp)
        
        # Set up plot - may want to autoset x axis scale
        print stop_t
        self.ui.tempPlot.setCanvasBackground(QtCore.Qt.black)
        self.ui.tempPlot.setAxisTitle(Qwt.QwtPlot.xBottom, '(sec)')
        self.ui.tempPlot.setAxisTitle(Qwt.QwtPlot.yLeft, '(C)')
        self.ui.tempPlot.setAxisScale(Qwt.QwtPlot.xBottom, 0, 500, 100)
        self.ui.tempPlot.setAxisScale(Qwt.QwtPlot.yLeft, 0, 300, 100)

        # Setup setpoint curve
        self.setp_curve = Qwt.QwtPlotCurve('')
        self.setp_curve.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
        self.pen = QtGui.QPen(QtGui.QColor('limegreen'))
        self.pen.setWidth(2)
        self.setp_curve.setPen(self.pen)
        self.setp_curve.attach(self.ui.tempPlot)
        t = scipy.linspace(0.0, stop_t, 1000)
        T = scipy.array([self.reflow_profile.func(tt-self.model.t_delay) for tt in t])
        self.setp_curve.setData(t, T)
        self.ui.tempPlot.replot()

        # Set data curve 
        self.data_curve = Qwt.QwtPlotCurve('')
        self.data_curve.setRenderHint(Qwt.QwtPlotItem.RenderAntialiased)
        self.pen = QtGui.QPen(QtGui.QColor('red'))
        self.pen.setWidth(2)
        self.data_curve.setPen(self.pen)
        self.data_curve.attach(self.ui.tempPlot)

        self.state = 'stopped'
        self.t0 = None
        self.t_stop = None  
        self.t_offset = 0.0
        self.update_status()

        # Lists for time and temp samples
        self.temp_samples = []
        self.time_samples = []