def lighting(self, Outdorr, Parameter, Control): # 补光策略,在currenttime 加了一个get_time()函数 while True: if Control.get_lighting_1() == "off" and Control.get_lighting_2( ) == "off": if get_current_month( ) > Parameter.month_to_open_lighting and get_current_month( ) < Parameter.month_to_close_lighting: if get_current_time( ) > Parameter.period1_start_lighting and get_current_time( ) < Parameter.period1_stop_lighting: if Outdoor.radiation < Parameter.radiation1_to_open_lighting: Control.set_lighting_1("on") open_time = get_time() elif get_current_time( ) > Parameter.period2_start_lighting and get_current_time( ) < Parameter.period2_stop_lighting: if Outdoor.radiation < Parameter.radiation2_to_open_lighting: Control.set_lighting_1("on") open_time2 = get_time() elif Control.get_lighting_1() == "on" and Control.get_lighting_2( ) == "off": t1 = int(get_time() - open_time) t2 = int(get_time() - open_time2) if t1 > 1750 and t1 < 1850: Control.set_lighting_2("on") if t2 > 1750 and t2 < 1850: Control.set_lighting_2("on") elif Control.get_lighting_1() == "on" and Control.get_lighting_2( ) == "on": if get_current_time( ) > Parameter.period1_start_lighting and get_current_time( ) < Parameter.period1_stop_lighting: if Outdoor.radiation > Parameter.radiation1_to_open_lighting: Control.set_lighting_1("off") stop_time = get_time() elif get_current_time( ) > Parameter.period2_start_lighting and get_current_time( ) < Parameter.period2_stop_lighting: if Outdoor.radiation > Parameter.radiation2_to_open_lighting: Control.set_lighting_1("off") stop_time2 = get_time() else: Control.set_lighting_1("off") stop_time3 = get_time() elif Control.get_lighting_1() == "off" and Control.get_lighting_2( ) == "on": t3 = get_time() - stop_time3 t4 = get_time() - stop_time2 t5 = get_time() - stop_time if t3 > 1750 and t3 < 1850: Control.set_lighting_2("off") if t4 > 1750 and t4 < 1850: Control.set_lighting_2("off") if t5 > 1750 and t5 < 1850: Control.set_lighting_2("off")
def lighting_control(Outdoor, Parameter): global t1, t2, t3, t4, t5, lighting_stop_time, lighting_stop_time2, lighting_stop_time3, lighting_open_time, lighting_open_time2 global auto_lighting_1, auto_lighting_2 month = int(get_current_month()) hour = int(get_current_hour()) if auto_lighting_1 == "off" and auto_lighting_2 == "off": if month > Parameter.get_month_to_open_lighting() and month < Parameter.get_month_to_close_lighting(): if hour > Parameter.get_period_1_start_lighting() and hour < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation() < Parameter.get_radiation_1_to_open_lighting(): bi_state_relay_output("lighting_1", "on") auto_lighting_1 = "on" lighting_open_time = get_time() elif hour > Parameter.get_period_2_start_lighting() and hour < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation() < Parameter.get_radiation_2_to_open_lighting(): bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" lighting_open_time2 = get_time() elif auto_lighting_1 == "on" and auto_lighting_2 == "off": t1 = float(get_time() - lighting_open_time) t2 = float(get_time() - lighting_open_time2) if t1 > 30 and t1 < 60: bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" if t2 > 30 and t2 < 60: bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" elif auto_lighting_1 == "on" and auto_lighting_2 == "on": if hour > Parameter.get_period_1_start_lighting() and hour < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation() > Parameter.get_radiation_1_to_open_lighting(): bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time = get_time() elif hour > Parameter.get_period_2_start_lighting() and hour < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation() > Parameter.get_radiation_2_to_open_lighting(): bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time2 = get_time() else: bi_state_relay_output("lighting_1", "off") auto_lighting_1 = "off" lighting_stop_time3 = get_time() elif auto_lighting_1 == "off" and auto_lighting_2 == "on": t3 = get_time() - lighting_stop_time3 t4 = get_time() - lighting_stop_time2 t5 = get_time() - lighting_stop_time if t3 > 30 and t3 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off" if t4 > 30 and t4 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off" if t5 > 30 and t5 < 60: bi_state_relay_output("lighting_2", "off") auto_lighting_2 = "off"
def lighting(self,Outdorr,Parameter,Control):#补光策略,在currenttime 加了一个get_time()函数 while True: if Control.get_lighting_1()=="off" and Control.get_lighting_2()=="off": if get_current_month()>Parameter.month_to_open_lighting and get_current_month()<Parameter.month_to_close_lighting: if get_current_time()>Parameter.period1_start_lighting and get_current_time()<Parameter.period1_stop_lighting: if Outdoor.radiation<Parameter.radiation1_to_open_lighting: Control.set_lighting_1("on") open_time=get_time() elif get_current_time()>Parameter.period2_start_lighting and get_current_time()<Parameter.period2_stop_lighting: if Outdoor.radiation<Parameter.radiation2_to_open_lighting: Control.set_lighting_1("on") open_time2=get_time() elif Control.get_lighting_1()=="on" and Control.get_lighting_2()=="off": t1=int(get_time()-open_time) t2=int(get_time()-open_time2) if t1>1750 and t1<1850: Control.set_lighting_2("on") if t2>1750 and t2<1850: Control.set_lighting_2("on") elif Control.get_lighting_1()=="on" and Control.get_lighting_2()=="on": if get_current_time()>Parameter.period1_start_lighting and get_current_time()<Parameter.period1_stop_lighting: if Outdoor.radiation>Parameter.radiation1_to_open_lighting: Control.set_lighting_1("off") stop_time=get_time() elif get_current_time()>Parameter.period2_start_lighting and get_current_time()<Parameter.period2_stop_lighting: if Outdoor.radiation>Parameter.radiation2_to_open_lighting: Control.set_lighting_1("off") stop_time2=get_time() else: Control.set_lighting_1("off") stop_time3=get_time() elif Control.get_lighting_1()=="off" and Control.get_lighting_2()=="on": t3=get_time()-stop_time3 t4=get_time()-stop_time2 t5=get_time()-stop_time if t3>1750 and t3<1850: Control.set_lighting_2("off") if t4>1750 and t4<1850: Control.set_lighting_2("off") if t5>1750 and t5<1850: Control.set_lighting_2("off")
def lighting_control(Control, Outdoor, Parameter): global lighting_stop_time, lighting_stop_time2, lighting_stop_time3 auto_lighting_1 = Control.get_lighting_1() auto_lighting_2 = Control.get_lighting_2() if auto_lighting_1 == "off" and auto_lighting_2 == "off": if get_current_month() > Parameter.get_month_to_open_lighting() and get_current_month() < Parameter.get_month_to_close_lighting(): if get_current_time() > Parameter.get_period_1_start_lighting() and get_current_time() < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation() < Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_1", "on") auto_lighting_1 = "on" lighting_open_time = get_time() elif get_current_time() > Parameter.get_period_2_start_lighting() and get_current_time() < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation() < Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" lighting_open_time2 = get_time() elif auto_lighting_1 == "on" and auto_lighting_2 == "off": t1 = int(get_time() - lighting_open_time) t2 = int(get_time() - lighting_open_time2) if t1 > 1750 and t1 < 1850: bi_state_relay_output("ligting_2", "on") auto_lighting_2 = "on" # Control.set_lighting_2("on") if t2 > 1750 and t2 < 1850: # Control.set_lighting_2("on") bi_state_relay_output("ligting_2", "on") auto_lighting_2 = "on" elif auto_lighting_1 == "on" and auto_lighting_2 == "on": if get_current_time() > Parameter.get_period_1_start_lighting() and get_current_time() < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation() > Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time = get_time() elif get_current_time() > Parameter.get_period_2_start_lighting() and get_current_time() < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation() > Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time2 = get_time() else: # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time3 = get_time() elif auto_lighting_1 == "off" and auto_lighting_2 == "on": t3 = get_time() - lighting_stop_time3 t4 = get_time() - lighting_stop_time2 t5 = get_time() - lighting_stop_time if t3 > 1750 and t3 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t4 > 1750 and t4 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t5 > 1750 and t5 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") else: bi_state_relay_output("ligting_2", "off") bi_state_relay_output("ligting_1", "off")
def roof_vent_control(Outdoor, Parameter, Indoor): global temperature_set_temp0, temperature_set_temp1, temperature_set_temp2, angle, auto_roof_vent_north, auto_roof_vent_south, roof_start_time, roof_state current_hour = get_current_hour() roof_start_time = get_time() if bad_weather == "true": if auto_roof_vent_north == "on" and auto_roof_vent_south == "on": roof_state = "open all to close" if angle == "half": roof_state = "open half to close" elif angle == "small": roof_state = "open small to close" auto_roof_vent_north = "off" auto_roof_vent_south = "off" angle = "zero" else: if current_hour >= Parameter.get_time_1( ) and current_hour < Parameter.get_time_2(): temperature_set_temp0 = float(Parameter.get_temperature_1()) elif current_hour >= Parameter.get_time_2( ) and current_hour < Parameter.get_time_3(): temperature_set_temp0 = float(Parameter.get_temperature_2()) elif current_hour >= Parameter.get_time_3( ) and current_hour < Parameter.get_time_4(): temperature_set_temp0 = float(Parameter.get_temperature_3()) else: temperature_set_temp0 = float(Parameter.get_temperature_4()) # humidity influence on temperature if float(Parameter.get_humidity_influence_range_of_air_temperature() ) == 0: print "humidity_influence_range_of_air_temperature can not be 0" elif float(Parameter.get_expect_humidity()) == 95: print "expect_humidity can not be 95%" else: if float(Outdoor.get_humidity()) <= ( float(Parameter.get_expect_humidity()) - 5 - float(Parameter. get_humidity_influence_range_of_air_temperature())): temperature_set_temp1 = temperature_set_temp0 + float( Parameter.get_low_humidity_influence_on_air_temperature()) elif float(Outdoor.get_humidity()) <= ( float(Parameter.get_expect_humidity()) - 5): tmpt = (float(Parameter.get_expect_humidity( )) - 5 - float(Outdoor.get_humidity())) * float( Parameter.get_low_humidity_influence_on_air_temperature() ) / float(Parameter. get_humidity_influence_range_of_air_temperature()) temperature_set_temp1 = temperature_set_temp0 + tmpt elif float(Outdoor.get_humidity()) >= ( float(Parameter.get_expect_humidity()) + 5): tmpt = (float(Outdoor.get_humidity()) - float( Parameter.get_expect_humidity()) - 5) * float( Parameter. get_high_humidity_influence_on_air_temperature()) / ( 100 - 5 - float(Parameter.get_expect_humidity())) temperature_set_temp1 = temperature_set_temp0 + tmpt else: temperature_set_temp1 = temperature_set_temp0 # light influence on temperature if Outdoor.get_radiation() < Parameter.get_expect_light(): temperature_set_temp2 = temperature_set_temp1 else: temperature_set_temp2 = temperature_set_temp1 - float( Parameter.get_light_influence_on_air_temperature_slope()) * ( float(Outdoor.get_radiation()) - float(Parameter.get_expect_light())) if temperature_set_temp2 > (temperature_set_temp1 + float( Parameter.get_low_light_influence_on_temperature())): temperature_set_temp2 = temperature_set_temp1 + float( Parameter.get_low_light_influence_on_temperature()) elif temperature_set_temp2 < (temperature_set_temp1 - float( Parameter.get_high_light_influence_on_temperature())): temperature_set_temp2 = temperature_set_temp1 - float( Parameter.get_high_light_influence_on_temperature()) else: if temperature_set_temp2 == 0: temperature_set_temp2 = 0 if Outdoor.get_temperature() <= Parameter.get_frost_temperature(): if auto_roof_vent_north == "on" and auto_roof_vent_south == "on": roof_state = "open all to close" if angle == "half": roof_state = "open half to close" else: roof_state = "open small to close" auto_roof_vent_north = "off" auto_roof_vent_south = "off" angle = "zero" elif Outdoor.get_temperature( ) <= Parameter.get_indoor_temperature_lower_limit(): # small angle if auto_roof_vent_north == "off" and auto_roof_vent_south == "off": roof_state = "close to open small" if angle == "all": roof_state = "open all to open small" elif angle == "half": roof_state = "open half to open small" auto_roof_vent_north = "on" auto_roof_vent_south = "on" angle = "small" elif Outdoor.get_temperature() <= temperature_set_temp2: # open half if auto_roof_vent_north == "off" and auto_roof_vent_south == "off": roof_state = "close to open half" if angle == "small": roof_state = "open small to half" elif angle == "all": roof_state = "open all to open half" roof_start_time = get_time() auto_roof_vent_north = "on" auto_roof_vent_south = "on" angle = "half" else: # if auto_roof_vent_north == "off" and auto_roof_vent_south == "off": roof_state = "close to open all" if angle == "small": roof_state = "open half to all" elif angle == "half": roof_state = "open half to open all" auto_roof_vent_north = "on" auto_roof_vent_south = "on" angle = "all" return roof_state
def lighting_control(Control, Outdoor, Parameter): global lighting_stop_time, lighting_stop_time2, lighting_stop_time3 auto_lighting_1 = Control.get_lighting_1() auto_lighting_2 = Control.get_lighting_2() if auto_lighting_1 == "off" and auto_lighting_2 == "off": if get_current_month() > Parameter.get_month_to_open_lighting( ) and get_current_month() < Parameter.get_month_to_close_lighting(): if get_current_time() > Parameter.get_period_1_start_lighting( ) and get_current_time() < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation( ) < Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_1", "on") auto_lighting_1 = "on" lighting_open_time = get_time() elif get_current_time() > Parameter.get_period_2_start_lighting( ) and get_current_time() < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation( ) < Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("on") bi_state_relay_output("lighting_2", "on") auto_lighting_2 = "on" lighting_open_time2 = get_time() elif auto_lighting_1 == "on" and auto_lighting_2 == "off": t1 = int(get_time() - lighting_open_time) t2 = int(get_time() - lighting_open_time2) if t1 > 1750 and t1 < 1850: bi_state_relay_output("ligting_2", "on") auto_lighting_2 = "on" # Control.set_lighting_2("on") if t2 > 1750 and t2 < 1850: # Control.set_lighting_2("on") bi_state_relay_output("ligting_2", "on") auto_lighting_2 = "on" elif auto_lighting_1 == "on" and auto_lighting_2 == "on": if get_current_time() > Parameter.get_period_1_start_lighting( ) and get_current_time() < Parameter.get_period_1_stop_lighting(): if Outdoor.get_radiation( ) > Parameter.get_radiation_1_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time = get_time() elif get_current_time() > Parameter.get_period_2_start_lighting( ) and get_current_time() < Parameter.get_period_2_stop_lighting(): if Outdoor.get_radiation( ) > Parameter.get_radiation_2_to_open_lighting(): # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time2 = get_time() else: # Control.set_lighting_1("off") bi_state_relay_output("ligting_1", "off") auto_lighting_1 = "off" lighting_stop_time3 = get_time() elif auto_lighting_1 == "off" and auto_lighting_2 == "on": t3 = get_time() - lighting_stop_time3 t4 = get_time() - lighting_stop_time2 t5 = get_time() - lighting_stop_time if t3 > 1750 and t3 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t4 > 1750 and t4 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") if t5 > 1750 and t5 < 1850: bi_state_relay_output("ligting_2", "off") # Control.set_lighting_2("off") else: bi_state_relay_output("ligting_2", "off") bi_state_relay_output("ligting_1", "off")
@author: Zxh ''' from autorun import auto_run_main from currenttime import get_time from indoor import Indoor from outdoor import Outdoor from parameter import Parameter from arm_project.control import Control node0 = Indoor('node0') o = Outdoor() c = Control() p = Parameter() p.set_expect_humidity("80") p.set_humidity_influence_range_of_air_temperature("5") p.set_high_humidity_influence_on_air_temperature("3") p.set_low_humidity_influence_on_air_temperature("4") p.set_light_influence_on_air_temperature_slope("0.7") p.set_roof_vent_open_time("10") p.set_shade_screen_in_time("5") p.set_shade_screen_out_time("7") p.set_side_vent_time("9") start_time = get_time() auto_run_main(node0, o, c, p)
def roof_vent_control(Outdoor, Parameter, Indoor): global temperature_set_temp0, temperature_set_temp1, temperature_set_temp2, angle, auto_roof_vent_north, auto_roof_vent_south, roof_start_time, roof_state current_hour = get_current_hour() roof_start_time = get_time() if bad_weather == "true": if auto_roof_vent_north == "on" and auto_roof_vent_south == "on": roof_state = "open all to close" if angle == "half": roof_state = "open half to close" elif angle == "small": roof_state = "open small to close" auto_roof_vent_north = "off" auto_roof_vent_south = "off" angle = "zero" else: if current_hour >= Parameter.get_time_1() and current_hour < Parameter.get_time_2(): temperature_set_temp0 = float(Parameter.get_temperature_1()) elif current_hour >= Parameter.get_time_2() and current_hour < Parameter.get_time_3(): temperature_set_temp0 = float(Parameter.get_temperature_2()) elif current_hour >= Parameter.get_time_3() and current_hour < Parameter.get_time_4(): temperature_set_temp0 = float(Parameter.get_temperature_3()) else: temperature_set_temp0 = float(Parameter.get_temperature_4()) # humidity influence on temperature if float(Parameter.get_humidity_influence_range_of_air_temperature()) == 0: print "humidity_influence_range_of_air_temperature can not be 0" elif float(Parameter.get_expect_humidity()) == 95: print "expect_humidity can not be 95%" else: if float(Outdoor.get_humidity()) <= (float(Parameter.get_expect_humidity()) - 5 - float( Parameter.get_humidity_influence_range_of_air_temperature())): temperature_set_temp1 = temperature_set_temp0 + float( Parameter.get_low_humidity_influence_on_air_temperature()) elif float(Outdoor.get_humidity()) <= (float(Parameter.get_expect_humidity()) - 5): tmpt = (float(Parameter.get_expect_humidity()) - 5 - float(Outdoor.get_humidity())) * float( Parameter.get_low_humidity_influence_on_air_temperature()) / float( Parameter.get_humidity_influence_range_of_air_temperature()) temperature_set_temp1 = temperature_set_temp0 + tmpt elif float(Outdoor.get_humidity()) >= (float(Parameter.get_expect_humidity()) + 5): tmpt = (float(Outdoor.get_humidity()) - float(Parameter.get_expect_humidity()) - 5) * float( Parameter.get_high_humidity_influence_on_air_temperature()) / ( 100 - 5 - float(Parameter.get_expect_humidity())) temperature_set_temp1 = temperature_set_temp0 + tmpt else: temperature_set_temp1 = temperature_set_temp0 # light influence on temperature if Outdoor.get_radiation() < Parameter.get_expect_light(): temperature_set_temp2 = temperature_set_temp1 else: temperature_set_temp2 = temperature_set_temp1 - float( Parameter.get_light_influence_on_air_temperature_slope()) * (float(Outdoor.get_radiation()) - float( Parameter.get_expect_light())) if temperature_set_temp2 > (temperature_set_temp1 + float(Parameter.get_low_light_influence_on_temperature())): temperature_set_temp2 = temperature_set_temp1 + float(Parameter.get_low_light_influence_on_temperature()) elif temperature_set_temp2 < ( temperature_set_temp1 - float(Parameter.get_high_light_influence_on_temperature())): temperature_set_temp2 = temperature_set_temp1 - float(Parameter.get_high_light_influence_on_temperature()) else: if temperature_set_temp2 == 0: temperature_set_temp2 = 0 if Outdoor.get_temperature() <= Parameter.get_frost_temperature(): if auto_roof_vent_north == "on" and auto_roof_vent_south == "on": roof_state = "open all to close" if angle == "half": roof_state = "open half to close" else: roof_state = "open small to close" auto_roof_vent_north = "off" auto_roof_vent_south = "off" angle = "zero" elif Outdoor.get_temperature() <= Parameter.get_indoor_temperature_lower_limit(): # small angle if auto_roof_vent_north == "off" and auto_roof_vent_south == "off": roof_state = "close to open small" if angle == "all": roof_state = "open all to open small" elif angle == "half": roof_state = "open half to open small" auto_roof_vent_north = "on" auto_roof_vent_south = "on" angle = "small" elif Outdoor.get_temperature() <= temperature_set_temp2: # open half if auto_roof_vent_north == "off" and auto_roof_vent_south == "off": roof_state = "close to open half" if angle == "small": roof_state = "open small to half" elif angle == "all": roof_state = "open all to open half" roof_start_time = get_time() auto_roof_vent_north = "on" auto_roof_vent_south = "on" angle = "half" else: # if auto_roof_vent_north == "off" and auto_roof_vent_south == "off": roof_state = "close to open all" if angle == "small": roof_state = "open half to all" elif angle == "half": roof_state = "open half to open all" auto_roof_vent_north = "on" auto_roof_vent_south = "on" angle = "all" return roof_state
''' @author: Zxh ''' from currenttime import get_time from time import sleep a = "2016-06-15 8:30" b = "1015" print a > b a = [1, 3, 5] print a a = 0.0 print a == 0 a = 7 b = "6" print a > b a = get_time() sleep(10) b = get_time() print b - a