def init(self): # Internal values ----------------------------------------------------- self.ready_event = gevent.event.Event() self.user_clicked_event = gevent.event.AsyncResult() self.user_confirms_centring = True # Hardware objects ---------------------------------------------------- self.camera_hwobj = self.getObjectByRole("camera") self.camera = self.camera_hwobj if self.camera_hwobj is not None: self.image_height = self.camera_hwobj.getHeight() self.image_width = self.camera_hwobj.getWidth() else: logging.getLogger("HWR").debug( "Diffractometer: " + "Camera hwobj is not defined" ) self.beam_info_hwobj = self.getObjectByRole("beam_info") if self.beam_info_hwobj is not None: self.beam_position = self.beam_info_hwobj.get_beam_position() self.connect( self.beam_info_hwobj, "beamPosChanged", self.beam_position_changed ) else: self.beam_position = [self.image_width / 2, self.image_height / 2] logging.getLogger("HWR").warning( "Diffractometer: " + "BeamInfo hwobj is not defined" ) self.front_light_swtich = self.getObjectByRole("frontlightswtich") self.back_light_swtich = self.getObjectByRole("backlightswtich") # Channels ----------------------------------------------------------- ss = self.getProperty("used_channels") if ss: try: self.used_channels_list = eval(ss) except BaseException: pass # used the default value for channel_name in self.used_channels_list: self.channel_dict[channel_name] = self.getChannelObject(channel_name) if self.channel_dict[channel_name] is None: continue if channel_name == "TransferMode": self.connect( self.channel_dict["TransferMode"], "update", self.transfer_mode_changed, ) elif channel_name == "CurrentPhase": self.connect( self.channel_dict["CurrentPhase"], "update", self.current_phase_changed, ) elif channel_name == "HeadType": self.connect( self.channel_dict["HeadType"], "update", self.head_type_changed ) elif channel_name == "State": self.connect(self.channel_dict["State"], "update", self.state_changed) # Commands ----------------------------------------------------------- try: self.used_commands_list = eval(self.getProperty("used_commands", "[]")) except BaseException: pass # used the default value for command_name in self.used_commands_list: self.command_dict[command_name] = self.getCommandObject(command_name) # Centring motors ---------------------------------------------------- try: self.centring_motors_list = eval(self.getProperty("centring_motors")) except BaseException: self.centring_motors_list = GenericDiffractometer.CENTRING_MOTORS_NAME queue_model_objects.CentredPosition.set_diffractometer_motor_names( *self.centring_motors_list ) for motor_name in self.centring_motors_list: temp_motor_hwobj = self.getObjectByRole(motor_name) if temp_motor_hwobj is not None: logging.getLogger("HWR").debug( "Diffractometer: Adding " + "%s motor to centring motors" % motor_name ) self.motor_hwobj_dict[motor_name] = temp_motor_hwobj self.connect(temp_motor_hwobj, "stateChanged", self.motor_state_changed) self.connect( temp_motor_hwobj, "positionChanged", self.centring_motor_moved ) if motor_name == "phi": self.connect( temp_motor_hwobj, "positionChanged", self.emit_diffractometer_moved, ) elif motor_name == "zoom": self.connect( temp_motor_hwobj, "predefinedPositionChanged", self.zoom_motor_predefined_position_changed, ) self.connect( temp_motor_hwobj, "stateChanged", self.zoom_motor_state_changed ) else: logging.getLogger("HWR").warning( "Diffractometer: Motor " + "%s listed in the centring motor list, but not initalized" % motor_name ) # sample changer ----------------------------------------------------- self.sample_changer = self.getObjectByRole("samplechanger") if self.sample_changer is None: logging.getLogger("HWR").warning( "Diffractometer: Sample Changer is not defined" ) else: # By default use sample changer if it's defined and transfer_mode # is set to SAMPLE_CHANGER. # if not defined, set use_sc to True if self.transfer_mode is None or self.transfer_mode == "SAMPLE_CHANGER": self.use_sc = True try: self.use_sample_centring = self.getProperty("sample_centring") if self.use_sample_centring: self.centring_phi = sample_centring.CentringMotor( self.motor_hwobj_dict["phi"], direction=-1 ) self.centring_phiz = sample_centring.CentringMotor( self.motor_hwobj_dict["phiz"] ) self.centring_phiy = sample_centring.CentringMotor( self.motor_hwobj_dict["phiy"], direction=-1 ) self.centring_sampx = sample_centring.CentringMotor( self.motor_hwobj_dict["sampx"] ) self.centring_sampy = sample_centring.CentringMotor( self.motor_hwobj_dict["sampy"] ) except BaseException: pass # used the default value try: self.delay_state_polling = self.getProperty("delay_state_polling") except BaseException: pass # Other parameters --------------------------------------------------- try: self.zoom_centre = eval(self.getProperty("zoom_centre")) except BaseException: if self.image_width is not None and self.image_height is not None: self.zoom_centre = { "x": self.image_width / 2, "y": self.image_height / 2, } self.beam_position = [self.image_width / 2, self.image_height / 2] logging.getLogger("HWR").warning( "Diffractometer: Zoom center is " + "not defined. Continuing with the middle: %s" % self.zoom_centre ) else: self.zoom_centre = {"x": 0, "y": 0} logging.getLogger("HWR").warning( "Diffractometer: " + "Neither zoom centre nor camera size is defined" ) self.reversing_rotation = self.getProperty("reversing_rotation") try: # grid_direction describes how a grid is collected # 'fast' is collection direction and 'slow' describes # move to the next collection line self.grid_direction = eval(self.getProperty("grid_direction")) except BaseException: self.grid_direction = {"fast": (0, 1), "slow": (1, 0), "omega_ref": 0} logging.getLogger("HWR").warning( "Diffractometer: Grid " + "direction is not defined. Using default." ) try: self.phase_list = eval(self.getProperty("phase_list")) except BaseException: self.phase_list = [ GenericDiffractometer.PHASE_TRANSFER, GenericDiffractometer.PHASE_CENTRING, GenericDiffractometer.PHASE_COLLECTION, GenericDiffractometer.PHASE_BEAM, ] # Compatibility # TODO remove this self.getCentringStatus = self.get_centring_status self.getPositions = self.get_positions self.moveMotors = self.move_motors self.isReady = self.is_ready
def init(self): # Internal values ----------------------------------------------------- self.ready_event = gevent.event.Event() self.user_clicked_event = gevent.event.AsyncResult() self.user_confirms_centring = True self.beamstop = self.get_object_by_role("beamstop") self.aperture = self.get_object_by_role("aperture") self.capillary = self.get_object_by_role("capillary") self.cryo = self.get_object_by_role("cryo") # Hardware objects ---------------------------------------------------- # if HWR.beamline.sample_view.camera is not None: # self.image_height = HWR.beamline.sample_view.camera.get_height() # self.image_width = HWR.beamline.sample_view.camera.get_width() # else: # logging.getLogger("HWR").debug( # "Diffractometer: " + "Camera hwobj is not defined" # ) if HWR.beamline.beam is not None: self.beam_position = HWR.beamline.beam.get_beam_position_on_screen( ) self.connect(HWR.beamline.beam, "beamPosChanged", self.beam_position_changed) else: self.beam_position = [0, 0] logging.getLogger("HWR").warning("Diffractometer: " + "BeamInfo hwobj is not defined") self.front_light_swtich = self.get_object_by_role("frontlightswtich") self.back_light_swtich = self.get_object_by_role("backlightswtich") # Channels ----------------------------------------------------------- ss0 = self.get_property("used_channels") if ss0: try: self.used_channels_list = eval(ss0) except Exception: pass # used the default value for channel_name in self.used_channels_list: self.channel_dict[channel_name] = self.get_channel_object( channel_name) if self.channel_dict[channel_name] is None: continue if channel_name == "TransferMode": self.connect( self.channel_dict["TransferMode"], "update", self.transfer_mode_changed, ) elif channel_name == "CurrentPhase": self.connect( self.channel_dict["CurrentPhase"], "update", self.current_phase_changed, ) elif channel_name == "HeadType": self.connect(self.channel_dict["HeadType"], "update", self.head_type_changed) elif channel_name == "State": self.connect(self.channel_dict["State"], "update", self.state_changed) # Commands ----------------------------------------------------------- try: self.used_commands_list = eval( self.get_property("used_commands", "[]")) except Exception: pass # used the default value for command_name in self.used_commands_list: self.command_dict[command_name] = self.get_command_object( command_name) # Centring motors ---------------------------------------------------- try: self.centring_motors_list = eval( self.get_property("centring_motors")) except Exception: self.centring_motors_list = GenericDiffractometer.CENTRING_MOTORS_NAME queue_model_objects.CentredPosition.set_diffractometer_motor_names( *self.centring_motors_list) for motor_name in self.centring_motors_list: # NBNB TODO refactor configuration, and set properties directly (see below) temp_motor_hwobj = self.get_object_by_role(motor_name) if temp_motor_hwobj is not None: logging.getLogger("HWR").debug("Diffractometer: Adding " + "%s motor to centring motors" % motor_name) self.motor_hwobj_dict[motor_name] = temp_motor_hwobj self.connect(temp_motor_hwobj, "stateChanged", self.motor_state_changed) self.connect(temp_motor_hwobj, "valueChanged", self.centring_motor_moved) if motor_name == "phi": self.connect( temp_motor_hwobj, "valueChanged", self.emit_diffractometer_moved, ) elif motor_name == "zoom": self.connect( temp_motor_hwobj, "predefinedPositionChanged", self.zoom_motor_predefined_position_changed, ) self.connect(temp_motor_hwobj, "stateChanged", self.zoom_motor_state_changed) else: logging.getLogger("HWR").warning( "Diffractometer: Motor " + "%s listed in the centring motor list, but not initalized" % motor_name) # sample changer ----------------------------------------------------- if HWR.beamline.sample_changer is None: logging.getLogger("HWR").warning( "Diffractometer: Sample Changer is not defined") else: # By default use sample changer if it's defined and transfer_mode # is set to SAMPLE_CHANGER. # if not defined, set use_sc to True if self.transfer_mode is None or self.transfer_mode == "SAMPLE_CHANGER": self.use_sc = True try: self.use_sample_centring = self.get_property("sample_centring") if self.use_sample_centring: self.centring_phi = sample_centring.CentringMotor( self.motor_hwobj_dict["phi"], direction=-1) self.centring_phiz = sample_centring.CentringMotor( self.motor_hwobj_dict["phiz"]) self.centring_phiy = sample_centring.CentringMotor( self.motor_hwobj_dict["phiy"], direction=-1) self.centring_sampx = sample_centring.CentringMotor( self.motor_hwobj_dict["sampx"]) self.centring_sampy = sample_centring.CentringMotor( self.motor_hwobj_dict["sampy"]) except Exception: pass # used the default value try: self.delay_state_polling = self.get_property("delay_state_polling") except Exception: pass # Other parameters --------------------------------------------------- try: self.zoom_centre = eval(self.get_property("zoom_centre")) except Exception: self.zoom_centre = {"x": 0, "y": 0} logging.getLogger("HWR").warning("Diffractometer: " + "zoom centre not configured") self.reversing_rotation = self.get_property("reversing_rotation") try: # grid_direction describes how a grid is collected # 'fast' is collection direction and 'slow' describes # move to the next collection line self.grid_direction = eval(self.get_property("grid_direction")) except Exception: self.grid_direction = { "fast": (0, 1), "slow": (1, 0), "omega_ref": 0 } logging.getLogger( "HWR").warning("Diffractometer: Grid " + "direction is not defined. Using default.") try: self.phase_list = eval(self.get_property("phase_list")) except Exception: self.phase_list = [ GenericDiffractometer.PHASE_TRANSFER, GenericDiffractometer.PHASE_CENTRING, GenericDiffractometer.PHASE_COLLECTION, GenericDiffractometer.PHASE_BEAM, ]
def init(self): self.centringMethods = { MiniDiff.MANUAL3CLICK_MODE: self.start_manual_centring, MiniDiff.C3D_MODE: self.start_auto_centring, } self.cancel_centring_methods = {} self.current_centring_procedure = None self.currentCentringMethod = None self.centringStatus = {"valid": False} self.chiAngle = self.getProperty("chi", 0) try: phiz_ref = self["centringReferencePosition"].getProperty("phiz") except: phiz_ref = None try: phiy_ref = self["centringReferencePosition"].getProperty("phiy") except: phiy_ref = None self.phiMotor = self.getObjectByRole("phi") self.phizMotor = self.getObjectByRole("phiz") self.phiyMotor = self.getObjectByRole("phiy") self.zoomMotor = self.getObjectByRole("zoom") self.lightMotor = self.getObjectByRole("light") self.focusMotor = self.getObjectByRole("focus") self.sampleXMotor = self.getObjectByRole("sampx") self.sampleYMotor = self.getObjectByRole("sampy") self.kappaMotor = self.getObjectByRole("kappa") self.kappaPhiMotor = self.getObjectByRole("kappa_phi") # mh 2013-11-05:why is the channel read directly? disabled for the moment # HWR.beamline.sample_view.camera.add_channel({ 'type': 'tango', 'name': 'jpegImage' }, "JpegImage") self.centringPhi = sample_centring.CentringMotor(self.phiMotor, direction=-1) self.centringPhiz = sample_centring.CentringMotor( self.phizMotor, reference_position=phiz_ref) self.centringPhiy = sample_centring.CentringMotor( self.phiyMotor, reference_position=phiy_ref) self.centringSamplex = sample_centring.CentringMotor(self.sampleXMotor) self.centringSampley = sample_centring.CentringMotor(self.sampleYMotor) roles_to_add = ["aperture", "beamstop", "cryostream", "capillary"] for role in roles_to_add: self.if_role_set_attr(role) hwr = HWR.getHardwareRepository() wl_prop = self.getProperty("wagolight") if wl_prop is not None: try: self.lightWago = hwr.getHardwareObject(wl_prop) except Exception: pass if self.phiMotor is not None: self.connect(self.phiMotor, "stateChanged", self.phiMotorStateChanged) self.connect(self.phiMotor, "valueChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: phi motor is not defined in minidiff equipment %s", str(self.name()), ) if self.phizMotor is not None: self.connect(self.phizMotor, "stateChanged", self.phizMotorStateChanged) self.connect(self.phizMotor, "valueChanged", self.phizMotorMoved) self.connect(self.phizMotor, "valueChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: phiz motor is not defined in minidiff equipment %s", str(self.name()), ) if self.phiyMotor is not None: self.connect(self.phiyMotor, "stateChanged", self.phiyMotorStateChanged) self.connect(self.phiyMotor, "valueChanged", self.phiyMotorMoved) self.connect(self.phiyMotor, "valueChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: phiy motor is not defined in minidiff equipment %s", str(self.name()), ) if self.zoomMotor is not None: self.connect(self.zoomMotor, "valueChanged", self.zoomMotorPredefinedPositionChanged) self.connect( self.zoomMotor, "predefinedPositionChanged", self.zoomMotorPredefinedPositionChanged, ) self.connect(self.zoomMotor, "stateChanged", self.zoomMotorStateChanged) else: logging.getLogger("HWR").error( "MiniDiff: zoom motor is not defined in minidiff equipment %s", str(self.name()), ) if self.sampleXMotor is not None: self.connect(self.sampleXMotor, "stateChanged", self.sampleXMotorStateChanged) self.connect(self.sampleXMotor, "valueChanged", self.sampleXMotorMoved) self.connect(self.sampleXMotor, "valueChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: sampx motor is not defined in minidiff equipment %s", str(self.name()), ) if self.sampleYMotor is not None: self.connect(self.sampleYMotor, "stateChanged", self.sampleYMotorStateChanged) self.connect(self.sampleYMotor, "valueChanged", self.sampleYMotorMoved) self.connect(self.sampleYMotor, "valueChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: sampx motor is not defined in minidiff equipment %s", str(self.name()), ) # if HWR.beamline.sample_view.camera is None: # logging.getLogger("HWR").error( # "MiniDiff: camera is not defined in minidiff equipment %s", # str(self.name()), # ) # else: # self.imgWidth, self.imgHeight = ( # HWR.beamline.sample_view.camera.getWidth(), # HWR.beamline.sample_view.camera.getHeight(), # ) if HWR.beamline.sample_changer is None: logging.getLogger("HWR").warning( "MiniDiff: sample changer is not defined in minidiff equipment %s", str(self.name()), ) else: try: self.connect( HWR.beamline.sample_changer, "sampleIsLoaded", self.sampleChangerSampleIsLoaded, ) except Exception: logging.getLogger("HWR").exception( "MiniDiff: could not connect to sample changer smart magnet" ) if self.lightWago is not None: self.connect(self.lightWago, "wagoStateChanged", self.wagoLightStateChanged) else: logging.getLogger("HWR").warning( "MiniDiff: wago light is not defined in minidiff equipment %s", str(self.name()), ) if self.aperture is not None: self.connect(self.aperture, "predefinedPositionChanged", self.apertureChanged) self.connect(self.aperture, "positionReached", self.apertureChanged)
def init(self): self.centringMethods = { MiniDiff.MANUAL3CLICK_MODE: self.start3ClickCentring, MiniDiff.C3D_MODE: self.startAutoCentring, } self.cancelCentringMethods = {} self.currentCentringProcedure = None self.currentCentringMethod = None self.centringStatus = {"valid": False} self.chiAngle = self.getProperty("chi", 0) try: phiz_ref = self["centringReferencePosition"].getProperty("phiz") except BaseException: phiz_ref = None self.phiMotor = self.getDeviceByRole("phi") self.phizMotor = self.getDeviceByRole("phiz") self.phiyMotor = self.getObjectByRole("phiy") self.zoomMotor = self.getDeviceByRole("zoom") self.lightMotor = self.getDeviceByRole("light") self.focusMotor = self.getDeviceByRole("focus") self.sampleXMotor = self.getDeviceByRole("sampx") self.sampleYMotor = self.getDeviceByRole("sampy") self.camera = self.getDeviceByRole("camera") self.kappaMotor = self.getDeviceByRole("kappa") self.kappaPhiMotor = self.getDeviceByRole("kappa_phi") self.beam_info = self.getObjectByRole("beam_info") # mh 2013-11-05:why is the channel read directly? disabled for the moment # self.camera.addChannel({ 'type': 'tango', 'name': 'jpegImage' }, "JpegImage") self.centringPhi = sample_centring.CentringMotor(self.phiMotor, direction=-1) self.centringPhiz = sample_centring.CentringMotor( self.phizMotor, reference_position=phiz_ref) self.centringPhiy = sample_centring.CentringMotor(self.phiyMotor) self.centringSamplex = sample_centring.CentringMotor(self.sampleXMotor) self.centringSampley = sample_centring.CentringMotor(self.sampleYMotor) hwr = HardwareRepository.getHardwareRepository() sc_prop = self.getProperty("samplechanger") if sc_prop is not None: try: self.sampleChanger = hwr.getHardwareObject(sc_prop) except BaseException: pass wl_prop = self.getProperty("wagolight") if wl_prop is not None: try: self.lightWago = hwr.getHardwareObject(wl_prop) except BaseException: pass aperture_prop = self.getProperty("aperture") if aperture_prop is not None: try: self.aperture = hwr.getHardwareObject(aperture_prop) except BaseException: pass if self.phiMotor is not None: self.connect(self.phiMotor, "stateChanged", self.phiMotorStateChanged) self.connect(self.phiMotor, "positionChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: phi motor is not defined in minidiff equipment %s", str(self.name()), ) if self.phizMotor is not None: self.connect(self.phizMotor, "stateChanged", self.phizMotorStateChanged) self.connect(self.phizMotor, "positionChanged", self.phizMotorMoved) self.connect(self.phizMotor, "positionChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: phiz motor is not defined in minidiff equipment %s", str(self.name()), ) if self.phiyMotor is not None: self.connect(self.phiyMotor, "stateChanged", self.phiyMotorStateChanged) self.connect(self.phiyMotor, "positionChanged", self.phiyMotorMoved) self.connect(self.phiyMotor, "positionChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: phiy motor is not defined in minidiff equipment %s", str(self.name()), ) if self.zoomMotor is not None: self.connect( self.zoomMotor, "predefinedPositionChanged", self.zoomMotorPredefinedPositionChanged, ) self.connect(self.zoomMotor, "stateChanged", self.zoomMotorStateChanged) else: logging.getLogger("HWR").error( "MiniDiff: zoom motor is not defined in minidiff equipment %s", str(self.name()), ) if self.sampleXMotor is not None: self.connect(self.sampleXMotor, "stateChanged", self.sampleXMotorStateChanged) self.connect(self.sampleXMotor, "positionChanged", self.sampleXMotorMoved) self.connect(self.sampleXMotor, "positionChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: sampx motor is not defined in minidiff equipment %s", str(self.name()), ) if self.sampleYMotor is not None: self.connect(self.sampleYMotor, "stateChanged", self.sampleYMotorStateChanged) self.connect(self.sampleYMotor, "positionChanged", self.sampleYMotorMoved) self.connect(self.sampleYMotor, "positionChanged", self.emitDiffractometerMoved) else: logging.getLogger("HWR").error( "MiniDiff: sampx motor is not defined in minidiff equipment %s", str(self.name()), ) if self.camera is None: logging.getLogger("HWR").error( "MiniDiff: camera is not defined in minidiff equipment %s", str(self.name()), ) else: self.imgWidth, self.imgHeight = ( self.camera.getWidth(), self.camera.getHeight(), ) if self.sampleChanger is None: logging.getLogger("HWR").warning( "MiniDiff: sample changer is not defined in minidiff equipment %s", str(self.name()), ) else: try: self.connect( self.sampleChanger, "sampleIsLoaded", self.sampleChangerSampleIsLoaded, ) except BaseException: logging.getLogger("HWR").exception( "MiniDiff: could not connect to sample changer smart magnet" ) if self.lightWago is not None: self.connect(self.lightWago, "wagoStateChanged", self.wagoLightStateChanged) else: logging.getLogger("HWR").warning( "MiniDiff: wago light is not defined in minidiff equipment %s", str(self.name()), ) if self.aperture is not None: self.connect(self.aperture, "predefinedPositionChanged", self.apertureChanged) self.connect(self.aperture, "positionReached", self.apertureChanged)