import matplotlib.pyplot as plt
temperatures = [25,22.5,20,17.5,15,12.5,10,5,0,-2.5,-5]
def regulator(outsideTemp):
""" regulator that based on outside temperatur created a metric to adjust
MaxPower in tempSystem function
"""
if outsideTemp >= 17:
r = (((outsideTemp - 17.5)/2.5 ) * -250 ) -150
elif outsideTemp < 17 and outsideTemp >= 0:
r = (outsideTemp / 5) * (-500) + 2000
elif outsideTemp < 0 :
r = ((outsideTemp / -2.5) * (1000)) + 2000
return r
outsideTemp= 5 # temperature outside of room
time=0; # in minutes
deltaT= 1 # do not change!
temp= 5 # actual room temperature
desiredTemp=17 # desired room temperatureß
maxPower=1000 # for heater fan
timeList = []
tempList = []
desiredTempList = []
frame = []
timeList.append(time)
tempList.append(temp)
desiredTempList.append(desiredTemp)
maxPower = regulator(outsideTemp)
def tempSystem(outsideTemp):
""" System that based on Outside temprature regulates Maxpower to seek
Goal temperature of 17 degrees celisus
"""
time=0; # in minutes
deltaT= 1 # do not change!
temp= 5 # actual room temperature
desiredTemp=17 # desired room temperature
maxPower=1000 # for heater fan
timeList = []
tempList = []
desiredTempList = []
frame = []
timeList.append(time)
tempList.append(temp)
desiredTempList.append(desiredTemp)
maxPower = regulator(outsideTemp)
accError=0
for i in range(60):
# you can change the controller and the maxPower of the heater
# heater allows change once a minute to any value within 0 <= power <= maxPower
#power = maxPower * regulator(outsideTemp)
# simple thermostat control - try to replace with something better!
if temp < desiredTemp:
power = maxPower
else:
power = 0
# simulate the physical system according to the laws of physics
# you cannot change below!
# enforce heater constraint
if power>maxPower: power=maxPower
time = time + deltaT # time always increased with deltaT
# effect of outside temperature and heater
tempChange = 0.11 * (outsideTemp-temp) + 0.0009 * power
temp = temp + tempChange * deltaT
# THIS IS JUST TO PUT THE MOST RECENT VALUES IN THE LISTS
timeList.append(time)
tempList.append(temp)
desiredTempList.append(desiredTemp)
container = [ outsideTemp, regulator(outsideTemp) , round(tempList[len(tempList)-1],1)]
return container
for t in temperatures:
print('\nWhen Outside temperature is ' + str(t) + ' the regulator will provide metric ' + str(tempSystem(t)[1]) + ' and inside temperattur will be ' + str(tempSystem(t)[2]))