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]))
When Outside temperature is 25 the regulator will provide metric -900.0 and inside temperattur will be 17.6
When Outside temperature is 22.5 the regulator will provide metric -650.0 and inside temperattur will be 17.2
When Outside temperature is 20 the regulator will provide metric -400.0 and inside temperattur will be 16.7
When Outside temperature is 17.5 the regulator will provide metric -150.0 and inside temperattur will be 16.3
When Outside temperature is 15 the regulator will provide metric 500.0 and inside temperattur will be 16.9
When Outside temperature is 12.5 the regulator will provide metric 750.0 and inside temperattur will be 17.1
When Outside temperature is 10 the regulator will provide metric 1000.0 and inside temperattur will be 17.1
When Outside temperature is 5 the regulator will provide metric 1500.0 and inside temperattur will be 16.7
When Outside temperature is 0 the regulator will provide metric 2000.0 and inside temperattur will be 16.4
When Outside temperature is -2.5 the regulator will provide metric 3000.0 and inside temperattur will be 16.5
When Outside temperature is -5 the regulator will provide metric 4000.0 and inside temperattur will be 16.9