def open(self): start = perf_counter() self.determine_state() log.debug(f"door.open() state: {self.state}") if self.state != State.OPEN: while (self.state != State.OPEN) \ & ((perf_counter() - start) < self.max_time_open): self.motor.backward() self.determine_state() else: self.motor.stop() return self.state
def close(self): start = perf_counter() self.determine_state() log.debug(f"door.close() state: {self.state}") if self.state != State.CLOSE: while (self.state != State.CLOSE) \ & ((perf_counter() - start) < self.max_time_close): self.motor.forward() self.determine_state() else: self.motor.stop() return self.state
def open_door(): open_led.blink() close_led.off() if main_door.open() == State.OPEN: log.info("door control: opened") notification("Door opened") open_led.on() else: open_led.blink() close_led.blink() log.debug(f"open_door(): {main_door.state}") notification("Door in intermediate state while opening", priority=2) # priority=2 sometimes not working sleep(3) notification("Door in intermediate state while opening", priority=1)
def loop(): while True: # local time used to account for daylight savings time in calculation # of local sunset/sunrise s = sun(city.observer, date=datetime.now(city.tzinfo), tzinfo=city.tzinfo) open_start_time = s['sunrise'] + timedelta(minutes=45) open_end_time = s['sunrise'] + timedelta(minutes=45 + config["BUFFER_TIME"]) close_start_time = s['sunset'] close_end_time = s['sunset'] + timedelta(minutes=config["BUFFER_TIME"]) checkin_start_time = s['sunset'] - timedelta( minutes=config["CHECKIN_BUFFER"]) checkin_end_time = s['sunset'] now = datetime.now(city.tzinfo) ######## RFID ########## if (checkin_end_time > now > checkin_start_time) \ & (main_door.state != State.CLOSE): log.debug("in checkin time") name = reader.read_tag(timeout=10) # wait timeout or return name if name is not None: counter.checkin([name]) log.info(f'checkin {name}') notification(f"{name} checked-in") if counter.all_inside(): log.info("all_inside") notification("All chickens checked-in") sleep(60) close_door() food_servo.close() ######## SCHEDULE ########## if (open_end_time > now > open_start_time) \ & (main_door.state != State.OPEN): s_ost = open_start_time.strftime("%H:%M") s_oet = open_end_time.strftime("%H:%M") message = f"In scheduled open time: {s_ost} - {s_oet}" log.debug(message) notification(message) open_door() counter.reset() food_servo.open() if (close_end_time > now > close_start_time) \ & (main_door.state == State.OPEN): s_cst = close_start_time.strftime("%H:%M") s_cet = close_end_time.strftime("%H:%M") message = (f"In scheduled close time: {s_cst} - {s_cet}. " f"{counter.which_inside()}") log.debug(message) notification(message, priority=1) close_door() food_servo.close()
def close(self): log.debug("close servo") self.move(self.open_angle, self.close_angle, 1 * self.incr)
def open(self): log.debug("open servo") self.move(self.close_angle, self.open_angle, -1 * self.incr)