def _set_coeff_string(self, v): cal = self.calibration if cal is None: cal = MeterCalibration() self.calibration = cal cal.coeff_string = v
def load_additional_args(self, config): """ """ self.set_attribute(config, 'request_powermin', 'General', 'power min', cast='float') self.set_attribute(config, 'request_powermax', 'General', 'power max', cast='float') # read in the coefficients from file coeffs = self.config_get(config, 'PowerMeter', 'coefficients') if coeffs is not None: self.power_meter_calibration = MeterCalibration(coeffs) coeffs = self.config_get(config, 'PowerOutput', 'coefficients') if coeffs is not None: p = os.path.join(paths.hidden_dir, '{}_power_calibration'.format(self.name.split('.')[0])) obj = MeterCalibration(coeffs) # dump to the hidden dir # the manager will use it directly try: self.info('loading power calibration from config file') with open(p, 'wb') as f: pickle.dump(obj, f) except (OSError, pickle.PickleError): self.warning('failed loading power output calibration') return super(FusionsCO2LogicBoard, self).load_additional_args(config)
def _dump_calibration(self): pc = MeterCalibration() coeffs = [] bounds = [] for s in self.selected_calibrations: coeffs.append(s.coefficients) bounds.append(s.calibration_bounds) pc.coefficients = coeffs pc.bounds = bounds p = self._get_calibration_path() self.info('saving calibration to {}'.format(p)) with open(p, 'wb') as f: pickle.dump(pc, f)
def load_additional_args(self, config): ''' ''' self.set_attribute(config, 'request_powermin', 'General', 'power min', cast='float') self.set_attribute(config, 'request_powermax', 'General', 'power max', cast='float') # read in the coefficients from file coeffs = self.config_get(config, 'PowerMeter', 'coefficients') if coeffs is not None: self.power_meter_calibration = MeterCalibration(coeffs) coeffs = self.config_get(config, 'PowerOutput', 'coefficients') if coeffs is not None: p = os.path.join(paths.hidden_dir, '{}_power_calibration'.format(self.name.split('.')[0])) obj = MeterCalibration(coeffs) # dump to the hidden dir # the manager will use it directly try: self.info('loading power calibration from config file') with open(p, 'wb') as f: pickle.dump(obj, f) except (OSError, pickle.PickleError): self.warning('failed loading power output calibration') return super(FusionsCO2LogicBoard, self).load_additional_args(config)
def load_power_calibration(self, calibration_path=None, verbose=True, warn=True): # calibration_path = self._get_calibration_path(calibration_path) # if os.path.isfile(calibration_path): # if verbose: # self.info('loading power calibration {}'.format(calibration_path)) # with open(calibration_path, 'rb') as f: # try: # pc = pickle.load(f) # except (pickle.PickleError, EOFError, OSError), e: # self.warning('unpickling error {}'.format(e)) # pc = MeterCalibration([1, 0]) # else: # pc = MeterCalibration([1, 0]) if self.parent is not None: lb = self.parent.laser_controller config = lb.get_configuration() section = 'PowerOutput' if config.has_section(section): coefficients = config.get(section, 'coefficients') cs = self._parse_coefficient_string(coefficients, warn) if cs is None: return else: cs = [1, 0] pc = MeterCalibration(cs) return pc
def _apply_calibration(self): if self.confirmation_dialog('Apply Calibration'): self._calculate_calibration() # pc = PowerCalibrationObject() pc = MeterCalibration(self._coefficients) self.dump_calibration(pc)
def _calibration_factory(self, calibration): coeffs = None if calibration == 'watts': config = self.get_configuration() coeffs = self._get_watt_calibration_coefficients(config) if coeffs is None: coeffs = [1, 0] return MeterCalibration(coeffs)
def _calibration_factory(self, calibration): coeffs = None nmapping = False if calibration == 'watts': path = os.path.join(paths.device_dir, self.configuration_dir_name, 'calibrated_power.cfg') if os.path.isfile(path): config = self.get_configuration(path=path) coeffs, nmapping = self._get_watt_calibration(config) if coeffs is None: coeffs = [1, 0] return MeterCalibration(coeffs, normal_mapping=bool(nmapping))
def load_additional_args(self, config): """ """ self.set_attribute(config, 'use_pid_bin', 'Output', 'use_pid_bin', cast='boolean', default=False) self.set_attribute(config, 'min_output_scale', 'Output', 'scale_low', cast='float') self.set_attribute(config, 'max_output_scale', 'Output', 'scale_high', cast='float') self.set_attribute(config, 'setpointmin', 'Setpoint', 'min', cast='float') self.set_attribute(config, 'setpointmax', 'Setpoint', 'max', cast='float') self.set_attribute(config, 'memory_blocks_enabled', 'MemoryBlock', 'enabled', cast='boolean') if self.memory_blocks_enabled: self.set_attribute(config, 'program_memory_blocks', 'MemoryBlock', 'program', cast='boolean') # if self.program_memory_blocks: # self.memory_blocks=[] # for option in config.options('MemoryBlock'): # if option.startswith('block'): # self.memory_blocks.append(config.get('MemoryBlock',option)) coeffs = self.config_get(config, 'Calibration', 'coefficients') if coeffs: self.calibration = MeterCalibration(coeffs) # self.use_calibrated_temperature = True return True
class FusionsCO2LogicBoard(FusionsLogicBoard): ''' ''' request_power = Property(Float(enter_set=True, auto_set=False), depends_on='_request_power') _request_power = Float request_powermin = Float(0) request_powermax = Float(100) power_meter_calibration = None def load_additional_args(self, config): ''' ''' self.set_attribute(config, 'request_powermin', 'General', 'power min', cast='float') self.set_attribute(config, 'request_powermax', 'General', 'power max', cast='float') # read in the coefficients from file coeffs = self.config_get(config, 'PowerMeter', 'coefficients') if coeffs is not None: self.power_meter_calibration = MeterCalibration(coeffs) coeffs = self.config_get(config, 'PowerOutput', 'coefficients') if coeffs is not None: p = os.path.join(paths.hidden_dir, '{}_power_calibration'.format(self.name.split('.')[0])) obj = MeterCalibration(coeffs) # dump to the hidden dir # the manager will use it directly try: self.info('loading power calibration from config file') with open(p, 'wb') as f: pickle.dump(obj, f) except (OSError, pickle.PickleError): self.warning('failed loading power output calibration') return super(FusionsCO2LogicBoard, self).load_additional_args(config) # def load_power_meter_calibration(self): # p = os.path.join(paths.hidden_dir, # '{}.power_meter_calibration'.format(self.name)) # if os.path.isfile(p): # self.info('loading power meter calibration: {}'.format(p)) # try: # with open(p, 'rb') as f: # c = pickle.load(f) # if isinstance(c, MeterCalibration): # self.power_meter_calibration = c # except (OSError, pickle.PickleError): # pass # # def dump_power_meter_calibration(self): # p = os.path.join(paths.hidden_dir, # '{}.power_meter_calibration'.format(self.name)) # self.info('dumping power meter calibration to {}'.format(p)) # try: # with open(p, 'wb') as f: # pickle.dump(self.power_meter_calibration, f) # except (OSError, pickle.PickleError): # pass def read_power_meter(self, verbose=False, **kw): ''' ''' cmd = self._build_command('ADC1') r = self._parse_response(self.ask(cmd, verbose=verbose)) if r is not None: try: r = float(r) # convert to watts # no calibration of logic board currently available # will have to simple normalize to 100 if self.power_meter_calibration is not None: r = self.power_meter_calibration.get_input(r) else: r = r / 255. * 100 except ValueError: self.warning('*Bad response from ADC ==> {} (len={})'.format(r, len(r))) r = None if self.simulation: r = self.get_random_value() self.internal_meter_response = r return r def _disable_laser(self): ''' ''' # cmd = self._build_command('PDC', '0.00') cmd = ('PDC', '0.00') self._request_power = 0.0 # callback = lambda :self._parse_response(self.ask(cmd)) resp = self.repeat_command(cmd, check_val='OK') if resp is not None: return super(FusionsCO2LogicBoard, self)._disable_laser() else: msg = 'failed to disable co2 laser' self.warning(msg) return msg def _enable_laser(self, **kw): ''' ''' cmd = self._build_command('PWE', '1') # callback = lambda :self._parse_response(self.ask(cmd)) resp = self.repeat_command(cmd, check_val='OK') if resp is not None: return super(FusionsCO2LogicBoard, self)._enable_laser() else: msg = 'failed to enable co2 laser' self.warning(msg) return msg def set_laser_power(self, request_pwr, verbose=True): ''' see Photon Machines Logic Board Command Set Reference version 0.96 this version uses PDC instead of PWW and PWE (pwm mode) to set the laser power request power valid range 0 100 with 0.02 resolution PDC sets the laser Duty Cycle ''' self._request_power = request_pwr cmd = self._build_command('PDC', '{:0.2f}'.format(request_pwr)) self.ask(cmd, verbose=verbose) def _get_request_power(self): ''' ''' return self._request_power def _set_request_power(self, v): ''' ''' self.set_laser_power(v)
class FusionsCO2LogicBoard(FusionsLogicBoard): """ """ request_power = Property(Float(enter_set=True, auto_set=False), depends_on='_request_power') _request_power = Float request_powermin = Float(0) request_powermax = Float(100) power_meter_calibration = None def load_additional_args(self, config): """ """ self.set_attribute(config, 'request_powermin', 'General', 'power min', cast='float') self.set_attribute(config, 'request_powermax', 'General', 'power max', cast='float') # read in the coefficients from file coeffs = self.config_get(config, 'PowerMeter', 'coefficients') if coeffs is not None: self.power_meter_calibration = MeterCalibration(coeffs) coeffs = self.config_get(config, 'PowerOutput', 'coefficients') if coeffs is not None: p = os.path.join(paths.hidden_dir, '{}_power_calibration'.format(self.name.split('.')[0])) obj = MeterCalibration(coeffs) # dump to the hidden dir # the manager will use it directly try: self.info('loading power calibration from config file') with open(p, 'wb') as f: pickle.dump(obj, f) except (OSError, pickle.PickleError): self.warning('failed loading power output calibration') return super(FusionsCO2LogicBoard, self).load_additional_args(config) def read_power_meter(self, verbose=False, **kw): """ """ cmd = self._build_command('ADC1') r = self._parse_response(self.ask(cmd, verbose=verbose)) if r is not None: try: r = float(r) # convert to watts # no calibration of logic board currently available # will have to simple normalize to 100 if self.power_meter_calibration is not None: r = self.power_meter_calibration.get_input(r) else: r = r / 255. * 100 except ValueError: self.warning('*Bad response from ADC ==> {} (len={})'.format(r, len(r))) r = None if self.simulation: r = self.get_random_value() try: self.internal_meter_response = r except TraitError: return return r def get_output(self): pass def get_response(self, **kw): return self.internal_meter_response def get_setpoint(self): return self._request_power def _disable_laser(self): """ """ # cmd = self._build_command('PDC', '0.00') cmd = ('PDC', '0.00') self._request_power = 0.0 # callback = lambda :self._parse_response(self.ask(cmd)) resp = self.repeat_command(cmd, check_val='OK') if resp is not None: return super(FusionsCO2LogicBoard, self)._disable_laser() else: msg = 'failed to disable co2 laser' self.warning(msg) return msg def _enable_laser(self, **kw): """ """ cmd = self._build_command('PWE', '1') # callback = lambda :self._parse_response(self.ask(cmd)) resp = self.repeat_command(cmd, check_val='OK') if resp is not None: return super(FusionsCO2LogicBoard, self)._enable_laser() else: msg = 'failed to enable co2 laser' self.warning(msg) return msg def set_laser_power(self, request_pwr, verbose=True): """ see Photon Machines Logic Board Command Set Reference version 0.96 this version uses PDC instead of PWW and PWE (pwm mode) to set the laser power request power valid range 0 100 with 0.02 resolution PDC sets the laser Duty Cycle """ self._request_power = request_pwr cmd = self._build_command('PDC', '{:0.2f}'.format(request_pwr)) self.ask(cmd, verbose=verbose) def _get_request_power(self): """ """ return self._request_power def _set_request_power(self, v): """ """ self.set_laser_power(v)
def _save_fired(self): # pc = PowerCalibrationObject() pc = MeterCalibration(self.coefficients) self.dump_power_calibration(pc.coefficients)