def vfd_state(self, dic): try: self.vfd_shm.lock() d = self.vfd_shm.data() d.timestamp = c.current_timestamp() d.act_rpm = self.check_value(dic["act_rpm"]) self.calculate_work_time(d.act_rpm) d.current_work_time = self.work_time self.save_work_time_to_file() self.save_yesterday_work_time_to_file() d.yesterday_work_time = self.yesterday_work_time d.active_power = float(dic["active_power"]) d.target_speed = self.check_value(dic["target_speed"]) d.fout = float(dic["fout"]) d.vout = float(dic["vout"]) d.vint = float(dic["vint"]) d.act_cur = float(dic["act_cur"]) d.act_mom = float(dic["act_mom"]) d.discrete_signals = self.check_value(dic["discrete_signals"]) d.vfd_working_mode = self.vfd_mode(d.discrete_signals) d.cos_phi = float(dic["cos_phi"]) d.error_code = self.check_value(dic["error_code"]) d.warning_code = self.check_value(dic["warning_code"]) d.energy_sum = float(dic["energy_sum"]) d.energy_expended = float(dic["energy_expended"]) d.recuperation = float(dic["recuperation"]) d.max_rpm = float(dic["max_rpm"]) d.nominal_rpm = float(dic["nominal_rpm"]) finally: self.vfd_shm.unlock()
def check_error_code(self): rl.debug("\n========== ERROR CODE FOUND ==========\n") if int(self.vfd_state['error_code']) == df.FAULT_OVER_CURRENT: self.error_code(self.vfd_state['error_code'], True) rl.debug("ERROR check = %s", self.vfd_state['error_code']) alarm_timestamp = self.alarm_shmem.is_vfd_error_code_in_mem( self.vfd_state['error_code']) current_timestamp = c.current_timestamp() delta_timestamp = current_timestamp - alarm_timestamp rl.debug( "ERROR check! Curr timestamp = %s\talarm_timestamp = %s\t" "delta = %s\tDELTA_TIME = %s", current_timestamp, alarm_timestamp, delta_timestamp, self.DELTA_TIME) if delta_timestamp < self.DELTA_TIME: self.emergency_stop = True rl.debug("Second repeated alarm in %s seconds! STOP VFD!", self.DELTA_TIME) if not self.alarm_shmem.is_vfd_error_code_repeat_in_mem( self.vfd_state['error_code']): self.set_alarm(self.vfd_state['error_code'], self.emergency_stop) if not self.emergency_stop: self.g120.flash_errors() self.g120.send_telegram(VFD_READY_COMMAND) rl.debug("Timeout started, vfd will restart after 30 seconds") time.sleep(30) rl.debug("\n========== END ERROR ==========\n") return
def set_alarm(self, error_code, emergency_stop=False): self.alarm_shmem.set_alarm({ 'timestamp': c.current_timestamp(), 'isu_alarm_code': defines.ALARM_VFD, 'value': error_code, 'emergency_stop': emergency_stop, })
def set_alarm(alarm_shm, alarm_value=0, emergency_stop=False): alarm_shm.set_alarm({ 'timestamp': c.current_timestamp(), 'isu_alarm_code': defines.ALARM_VFD, 'value': alarm_value, 'emergency_stop': emergency_stop, }) return
def calculate_work_time(self, rpm): if rpm > 0: if self.beginning_work_time == 0: self.beginning_work_time = c.current_timestamp() self.beginning_down_time = 0 self.shm_work_time = self.read_work_time_from_file() self.work_time = (self.shm_work_time + c.current_timestamp() - self.beginning_work_time) rl.debug("VFD working time = %s : %s", self.work_time, time.strftime("%H:%M:%S", time.localtime(self.work_time))) else: if self.beginning_down_time == 0: self.beginning_down_time = c.current_timestamp() self.beginning_work_time = 0 self.down_time = c.current_timestamp() - self.beginning_down_time rl.debug("VFD downtime = %s : %s", self.down_time, time.strftime("%H:%M:%S", time.gmtime(self.down_time)))
def save_yesterday_work_time_to_file(self): if c.current_timestamp() >= self.next_date_timestamp: with open(self.YESTERDAY_WORK_TIME_FILE, "w") as f: f.write('%s' % self.work_time) self.yesterday_work_time = self.work_time self.next_date_timestamp = self.get_next_date_timestamp() self.beginning_work_time = 0 self.work_time = 1 self.save_work_time_to_file()
def check_alarm_broken_belt(moment, alarm_shmem): rl.debug("CHECK ALARM BROKEN BELT") max_moment = max(moment) min_moment = min(moment) s = max_moment - min_moment rl.debug("Min moment = %s\tMax moment = %s\tdelta = %s", min_moment, max_moment, s) if (s > 0) and (s < 20): alarm_shmem.set_alarm({ 'timestamp': c.current_timestamp(), 'isu_alarm_code': defines.ALARM_BROKEN_BELT, 'value': 0, 'emergency_stop': True }) return
def check_vfd_state(self): if not self.vfd_state: self.vfd_prev_mode = -1 self.vfd_prev_speed = 0 if not self.alarm_start: self.alarm_start_time = c.current_timestamp() self.alarm_start = True if self.alarm_start: delta = c.current_timestamp() - self.alarm_start_time rl.debug('delta = %s', delta) if delta > self.DELTA_ALARM: set_alarm(self.alarm_shmem) else: # self.alarm_start = False # self.alarm_shmem.remove_alarm(defines.ALARM_VFD) # if self.vfd_state['act_rpm'] == 0: # self.diagnoctic_shmem.cycles_per_min(0) rl.debug('cnt = %s', self.cnt) self.current.append(self.vfd_state["act_cur"]) self.voltage.append(self.vfd_state["vout"]) if self.cnt >= self.LIST_CNT: rl.debug('Current = %s', self.current) rl.debug('Voltage = %s', self.voltage) # set_parameters_to_shmem(self.vfd_shmem, self.d, self.current, self.voltage) self.voltage = [] self.current = [] self.cnt = 0 self.cnt += 1 self.moment.append(self.vfd_state["act_mom"]) self.broken_belt_cnt += 1 rl.debug("BROKEN_BELT_CNT = %s", self.broken_belt_cnt) # if self.broken_belt_cnt >= self.BROKEN_BELT_MAX_CNT: # check_alarm_broken_belt(self.moment, self.alarm_shmem) # self.broken_belt_cnt = 0 # self.moment = [] # if self.vfd_shmem.is_alarm_stop(): # self.g120.send_telegram(VFD_READY_COMMAND) # self.vfd_prev_speed = 0 # vfd_mode_speed = self.vfd_shmem.get_vfd_mode_and_speed() # rl.debug("Shared memory vfd = %s", vfd_mode_speed) # if self.vfd_state['error_code']: # self.check_error_code() # if vfd_mode_speed["vfd_working_mode"] == VFD_MANUAL_MODE: # if self.vfd_prev_mode != VFD_MANUAL_MODE: # self.alarm_shmem.reset_alarm() # self.emergency_stop = False # stop_vfd_auto_mode(self.g120) # set_manual_mode(self.g120) # self.vfd_prev_mode = VFD_MANUAL_MODE # self.vfd_prev_speed = 0 # elif vfd_mode_speed["vfd_working_mode"] == VFD_AUTO_MODE: # if self.vfd_prev_mode != VFD_AUTO_MODE: # set_auto_mode(self.g120) # self.vfd_prev_mode = VFD_AUTO_MODE # stop_vfd = self.alarm_shmem.get_alarm_vfd_state() # rl.debug("STOP VFD BY ALARM = %s", stop_vfd) # if stop_vfd: # stop_vfd_auto_mode(self.g120) # self.vfd_prev_speed = 0 # else: # if self.vfd_prev_speed != vfd_mode_speed["current_speed"]: # if vfd_mode_speed["current_speed"] == 0: # self.g120.stop() # else: # self.g120.set_rpn(vfd_mode_speed["current_speed"]) # self.vfd_prev_speed = vfd_mode_speed["current_speed"] # self.g120.send_telegram() print "------------------------------start-------------------------------" # self.g120.set_rpn(50) # # self.g120.stop() # self.g120.send_telegram() rl.debug("Current working mode = %s", self.vfd_prev_mode)