def check_button(self): for key in mover_controller.MoverController.DEVICE_LIST: self.mover_enable[key].set( param_manager.get(f'device_id_{key}') is not None) if not self.mover_enable[key].get(): self.config_disabled(self.mover_check[key]) self.set_manual[key] = False
def goto_center(self): for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if self.mover_enable[key].get(): center = float(param_manager.get(f'center_{key}')) if self.mover.go_to(val, center): utility.print_info( f'MVC ID = {val} go to center: {center}')
def __init__(self, param_file): self.mover_good = False self.mover_status = 'IDLE' self.daq_status = 'IDLE' self.step_status = 'IDLE' self.hpc_status = 'IDLE' if USE_REF: self.ref_status = 'IDLE' if USE_NMR: self.nmr_status = 'IDLE' self.alarm_list = alarm_list.AlarmListWindow() self.progress = progress.ProgressWindow() tkinter.Frame.__init__(self) self.__make_menu() self.__make_label() self.__make_button() self.__make_status() param_manager.initialize(param_file) step_manager.initialize(param_manager.get('step_file')) self.data_path = param_manager.get('data_path') self.output_name = None if not os.path.isdir(self.data_path): os.mkdir(self.data_path) self.mover = mover_controller.MoverController() self.servo_status = {'x': 0, 'y': 0, 'z': 0} self.zero_return_status = {'x': 0, 'y': 0, 'z': 0} self.zero_return_status_all = 0 self.mover_position_mon = {'x': 0., 'y': 0., 'z': 0.} self.mover_position_set = {'x': 0., 'y': 0., 'z': 0.} self.last_move = time.time() self.last_free_daq_time = 0 if self.mover.device is None: utility.print_error( f'MVC failed to open: {self.mover.device_name}') self.hallprobe = hall_probe.HallProbeController() if USE_REF: self.ref = ref_probe.RefProbeController() if USE_NMR: self.nmr = nmr.NMRController() self.temp = temp_monitor.TempMonitor() self.master.title(f'Field Mapping Controller (pid={os.getpid()})') self.master.resizable(0, 1) self.pack(fill=tkinter.Y, expand=True) self.check_files() self.check_button() self.last_under_transition = 0 self.sound_file = self.__class__.SOUND_FILE
def update_step(self): if self.mover_status == 'ERROR': self.stop() return if self.free_daq_mode.get(): return self.set_step() step_manager.step_number = self.get_step() device_list = mover_controller.MoverController.DEVICE_LIST if self.daq_status == 'RUNNING': if (self.mover_status == 'IDLE' and self.step_status == 'IDLE' and self.hallprobe.dev_status and self.ref.status): self.config_disabled(self.step_e) self.last_step = step_manager.step() if self.last_step is not None: self.config_normal(self.step_e) self.step_e.delete(0, tkinter.END) self.step_e.insert(0, str(step_manager.step_number)) self.config_disabled(self.step_e) for key, val in device_list.items(): if self.mover_enable[key].get(): self.mover.go_to(val, float(self.last_step[key])) self.step_status = 'STEPPING' self.last_step_time = time.time() else: self.stop() else: status = True for key, val in device_list.items(): if self.mover_enable[key].get(): if (abs(self.mover_position_set[key] - self.last_step[key]) >= float(param_manager.get('position_dev')) * 1e-3): status = False if self.mover_status == 'IDLE': utility.print_warning( f'STP ID = {val} ' + 'step might be failed -> RE-ADJUST') self.mover.go_to(val, float(self.last_step[key])) if (status and self.hallprobe.dev_status and self.ref.status and time.time() - self.last_step_time > 3.0): # for i in range(10): now = str(datetime.datetime.now()) #[:19] # utility.print_info(f'DAQ save step : {self.get_step()}') self.step_status = 'IDLE' buf = f'{now} {self.get_step():>6} ' # for key, val in device_list.items(): # buf += f'{self.last_step[key]:9.1f} ' for key, val in device_list.items(): buf += f'{self.mover_position_mon[key]:9.3f} ' for key in hall_probe.HallProbeController.CHANNEL_LIST: field = self.hallprobe.field_mean[key] # field = self.hallprobe.field[key][0] if 'mT' in self.hallprobe.field[key][1]: field *= 1e-3 buf += f'{field:13.8f} ' if USE_REF: buf += f'{self.ref.field:10.7f}' if USE_NMR: buf += f'{self.nmr.field:10.7f}' # utility.print_info(f'STP step#{step_manager.step_number} {buf}') buf += f'{self.temp.temp[0]:6.1f}' buf += f'{self.temp.temp[1]:6.1f}' self.output_file.write(buf + '\n') self.output_file.flush() elif time.time() - self.last_step_time > 180: utility.print_warning('STP too long time to step?') else: self.config_normal(self.step_e)
def update_mover(self): self.mover_good = False self.mover_status = 'IDLE' if self.mover.device is None: self.mover_status = 'ERROR' # utility.print_error(f'MVC failed to update (device is None)') return count = self.n_enable() self.config_normal(self.menu1, 'Print mover parameter') for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): continue if not self.set_manual[key]: self.set_manual[key] = self.mover.set_manual(val) if not self.set_manual[key]: self.mover_status = 'ERROR' # utility.print_warning(f'MVC failed to update (set manual)') return self.mover.device_info(val) self.mover.version(val) if self.set_manual[key]: utility.print_info(f'MVC ID = {val} initialized') for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): continue o_status = self.mover.io_status(val) if o_status is None: self.mover_status = 'ERROR' utility.print_debug(f'MVC failed to update (io status)') return is_moving = (o_status >> 6) & 0x1 alarm_off = (o_status >> 15) & 0x1 if is_moving == 1 and self.mover_status != 'ERROR': self.mover_status = 'MOVING' if alarm_off == 0: self.mover_status = 'ERROR' alarm_status = dict() alarm_status_all = 0 for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): self.lalarm_status[key].config(text='Alarm N/A', fg='gray25') continue alarm_status[key] = self.mover.alarm_status(val) alarm_status_all += alarm_status[key] if alarm_status[key] == 0: self.lalarm_status[key].config(text='Alarm OFF', fg='blue') else: self.mover_status = 'ERROR' self.lalarm_status[key].config( text=f'Alarm #{alarm_status[key]}', fg='red') if alarm_status_all == 0: self.config_disabled(self.menu1, 'Alarm reset') else: self.config_normal(self.menu1, 'Alarm reset') # if count == 0: # self.mover_good = True # return servo_status_all = 0 self.zero_return_status_all = 0 for key, val in mover_controller.MoverController.DEVICE_LIST.items(): if not self.mover_enable[key].get(): self.lservo_status[key].config(text='Servo N/A', fg='gray25') continue self.servo_status[key] = self.mover.servo_status(val) servo_status_all += self.servo_status[key] self.zero_return_status[key] = self.mover.zero_return_status(val) self.zero_return_status_all += self.zero_return_status[key] if self.servo_status[key] == 1: self.lservo_status[key].config(text=f'Servo ON', fg='green') elif self.servo_status[key] == 0: self.lservo_status[key].config(text=f'Servo OFF', fg='blue') pos_txt = f' {"mon":^8} {"set":^8} {"mag":^8}\n' for key, val in mover_controller.MoverController.DEVICE_LIST.items(): zero = ' ' if self.zero_return_status[key] == 1 else '*' if val is not None: #self.mover_enable[key].get(): vmon, vset = self.mover.get_position(val) center = float(param_manager.get(f'center_{key}')) if 'x' in key: vmag = vmon - center else: vmag = center - vmon self.mover_position_mon[key] = vmon self.mover_position_set[key] = vset if (abs(vmon - vset) > int(param_manager.get('position_dev')) and self.servo_status[key] == 1): self.mover_status = 'MOVING' if vmon != -999999. and vset != -999999.: pos_txt += ( f'{zero}{key.upper()} {vmon:9.1f}({vset:9.1f})' + f'{vmag:9.1f}\n') else: pos_txt += f'{zero}{key.upper()} {"-"*9}({"-"*9}){"-"*9}\n' else: pos_txt += f'{zero}{key.upper()} {"-"*9:9}({"-"*9:9}){"-"*9}\n' self.lmover_position.config(text=pos_txt) if not self.mover.check_limit(): self.mover_status = 'ERROR' if count == servo_status_all: self.config_disabled(self.bservo_on) # if count == zero_return_status_all and count > 0: if self.mover_status == 'MOVING': # or count != zero_return_status_all: # self.config_disabled(self.menu1, 'Zero return') self.config_disabled(self.menu1, 'Go to center') self.config_disabled(self.bservo_off) else: if count > 0: # self.config_normal(self.menu1, 'Zero return') if count == self.zero_return_status_all: self.config_normal(self.menu1, 'Go to center') self.config_normal(self.bservo_off) else: if alarm_status_all == 0: self.config_normal(self.bservo_on) else: self.config_disabled(self.bservo_on) if servo_status_all == 0: self.config_disabled(self.bservo_off) else: self.config_normal(self.bservo_off) # self.config_disabled(self.menu1, 'Zero return') self.config_disabled(self.menu1, 'Go to center') self.set_speed() self.set_manual_inching() if (alarm_status_all == 0 and #count == zero_return_status_all and self.mover_status != 'ERROR'): self.mover_good = True if (count == servo_status_all and count > 0 and self.mover_status != 'MOVING' and self.daq_status == 'IDLE'): self.config_normal(self.binching_up) self.config_normal(self.binching_dw) else: self.config_disabled(self.binching_up) self.config_disabled(self.binching_dw) else: self.config_disabled(self.binching_up) self.config_disabled(self.binching_dw) if self.mover_status == 'MOVING' or self.daq_status == 'RUNNING': self.config_disabled(self.bservo_on) self.config_disabled(self.bservo_off) # self.config_disabled(self.menu1, 'Zero return') self.config_disabled(self.menu1, 'Go to center') self.config_normal(self.bstop) self.config_disabled(self.speed_e) self.config_disabled(self.manual_inching_e) else: self.config_disabled(self.bstop) self.config_normal(self.speed_e) self.config_normal(self.manual_inching_e)