Exemplo n.º 1
0
    def run(self):
        print "Thread PID no", self.taskid, "is readry!\n > Based on James Ward's PID algorithm"

        drive = 0.0
        lastdrive = 0.0
        #based on James Ward's PID algorithm
        while not self._stopevent.isSet():
            #PID computation
            #timestamp
            next = time.time()
            #get current boiler temp
            latestTemp = self.maximBoiler.getTemp()
            #controle de la chaudiere
            lastdrive = drive

            #if temperature read is correct, start algorithm
            if (latestTemp > 0.5):
                #calculate next time step
                next += self.m_timeStep
                #get current target temperature
                cTargetTemp = self.getTargetTemp()

                #calculate PID update
                #boost mode only if boiler target temp is higher than 100C (ECO mode is 90)
                if ((BOILER_BOOST_MODE == 1) and (cTargetTemp > 100)):
                    tgroupe = self.maximGroupe.getTemp()
                    #stop the boost mode when group temp is higher than boiler temp - 30C (approximate)
                    bBoostLimit = cTargetTemp - 30
                    #boost boiler target temperature if we are under a certain value
                    if ((tgroupe > 0.5) and (tgroupe < bBoostLimit)):
                        drive = self.pid_update(BOILER_MAX_TEMP - latestTemp,
                                                latestTemp)
                    else:
                        drive = self.pid_update(cTargetTemp - latestTemp,
                                                latestTemp)
                else:
                    drive = self.pid_update(cTargetTemp - latestTemp,
                                            latestTemp)
                #drive = self.pid_update( self.getTargetTemp() - latestTemp, latestTemp )

            #clamp the output power to sensible range
            if (drive > 1.0):
                drive = 1.0
            if (drive < 0.0):
                drive = 0.0

            #update the boiler power (with PWM) if last state changed
            if (drive != lastdrive):
                drv = int(drive * 100)
                self.setCurrentDrive(drv)
                SSRControl.setBoilerPWM(drv)

            #wait the remaining time (typically, slot = 1 second)
            remain = next - time.time()
            if (remain > 0.0):
                self._stopevent.wait(remain)
Exemplo n.º 2
0
    def run(self):
    	print "Thread PID no", self.taskid, "is readry!\n > Based on James Ward's PID algorithm"
	
	drive = 0.0
	lastdrive = 0.0
	#based on James Ward's PID algorithm	
	while not self._stopevent.isSet(): 
		#PID computation
		#timestamp
		next = time.time()
		#get current boiler temp
		latestTemp = self.maximBoiler.getTemp()
		#controle de la chaudiere
		lastdrive = drive	
		
		#if temperature read is correct, start algorithm
		if ( latestTemp > 0.5 ):
			#calculate next time step
			next += self.m_timeStep
			#get current target temperature
			cTargetTemp = self.getTargetTemp()

			#calculate PID update
			#boost mode only if boiler target temp is higher than 100C (ECO mode is 90)
			if((BOILER_BOOST_MODE == 1) and (cTargetTemp > 100)):
				tgroupe = self.maximGroupe.getTemp()
				#stop the boost mode when group temp is higher than boiler temp - 30C (approximate)
				bBoostLimit = cTargetTemp - 30
				#boost boiler target temperature if we are under a certain value
				if ((tgroupe > 0.5) and (tgroupe < bBoostLimit)):					
					drive = self.pid_update( BOILER_MAX_TEMP - latestTemp, latestTemp )
				else:
					drive = self.pid_update( cTargetTemp - latestTemp, latestTemp )
			else:
				drive = self.pid_update( cTargetTemp - latestTemp, latestTemp )
			#drive = self.pid_update( self.getTargetTemp() - latestTemp, latestTemp )
				
		
		#clamp the output power to sensible range
		if ( drive > 1.0 ):
			drive = 1.0
		if ( drive < 0.0 ):
			drive = 0.0

		#update the boiler power (with PWM) if last state changed
		if ( drive != lastdrive ):
			drv = int(drive * 100)
			self.setCurrentDrive( drv )
			SSRControl.setBoilerPWM( drv )

		#wait the remaining time (typically, slot = 1 second)
		remain = next - time.time()
		if ( remain > 0.0 ):
			self._stopevent.wait(remain)
Exemplo n.º 3
0
def quitApplicationNicely():
	done = True
	#be sure to shut down the boiler as well
	SSRControl.setBoilerPWM(0)
	saveSettings()
	task1.stop()
	task2.stop()
	task3.stop()
	task4.stop()
	task5.stop()
	task7.stop()
	task6PID.stop()
	time.sleep(0.1)
	pygame.quit()
        sys.exit(0)
Exemplo n.º 4
0
def quitApplicationNicely():
	done = True
	#be sure to shut down the boiler as well
	SSRControl.setBoilerPWM(0)
	saveSettings()
	task1.stop()
#	task2.stop()
#	task3.stop()
	task4.stop()
	task5.stop()
	task7.stop()
	task6PID.stop()
	task8.stop()
	time.sleep(0.1)
	pygame.quit()
        sys.exit(0)