Ejemplo n.º 1
0
def center_on_click(x,y,maglevel=0,source="screen",jog=0): #maglevel=0 means lowmag, high fov, #1 = himag with digizoom option, 
  #source=screen = from screen click, otherwise from macro with full pixel dimensions
  if (source == "screen"):
    beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_scale","B",daq_utils.screenPixX) #these are video dimensions in the gui
    beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_scale","B",daq_utils.screenPixY)
    beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_center","A",daq_utils.screenPixX/2)
    beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_center","A",daq_utils.screenPixY/2)
  else:
    if (int(maglevel)==0):
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_scale","B",daq_utils.lowMagPixX)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_scale","B",daq_utils.lowMagPixY)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_center","A",daq_utils.lowMagPixX/2)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_center","A",daq_utils.lowMagPixY/2)
    else:
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_scale","B",daq_utils.highMagPixX)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_scale","B",daq_utils.highMagPixY)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_center","A",daq_utils.highMagPixX/2)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_center","A",daq_utils.highMagPixY/2)

  if (int(maglevel)==0):
    beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_scale","C",daq_utils.lowMagFOVx)
    beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_scale","C",daq_utils.lowMagFOVy)
  else:
    if (beamline_support.get_any_epics_pv("FAMX-cam1:MJPGZOOM:NDArrayPort","VAL") == "ROI2"):
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_scale","C",daq_utils.highMagFOVx)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_scale","C",daq_utils.highMagFOVy)
    else:
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_X_scale","C",daq_utils.highMagFOVx/2.0)
      beamline_support.set_any_epics_pv(daq_utils.gonioPvPrefix+"image_Y_scale","C",daq_utils.highMagFOVy/2.0)
  omega_mod = beamline_lib.get_epics_motor_pos("Omega")%360.0
#  daq_utils.broadcast_output("\ncenter on x = %s, y = %s, omega = %f, phi = %f\n" % (x,y,omega_mod,0))
  lib_gon_center_xtal(x,y,omega_mod,0)
  if (jog):
    beamline_lib.mvr("Omega",float(jog))
Ejemplo n.º 2
0
def get_epics_pv(motcode,field_name): #gets any epics pv with error handling
  mcode = "%s%s" % (beamline_support.beamline_designation,motcode)
  try:
    return beamline_support.get_any_epics_pv(mcode,field_name)
  except CaChannelException, status:
    print ca.message(status)
    print "\n\nHandled Epics Error in get pv\n\n"
    return -99
Ejemplo n.º 3
0
def unmountRobotSample(puckPos, pinPos,
                       sampID):  #will somehow know where it came from

    absPos = (pinsPerPuck * (puckPos % 3)) + pinPos + 1
    robotOnline = getBlConfig('robot_online')
    logger.info("robot online = " + str(robotOnline))
    if (robotOnline):
        detDist = beamline_lib.motorPosFromDescriptor("detectorDist")
        if (detDist < ROBOT_MIN_DISTANCE):
            setPvDesc("govRobotDetDistOut", ROBOT_MIN_DISTANCE)
            setPvDesc("govHumanDetDistOut", ROBOT_MIN_DISTANCE)
        daq_lib.setRobotGovState("SE")
        logger.info("unmounting " + str(puckPos) + " " + str(pinPos) + " " +
                    str(sampID))
        logger.info("absPos = " + str(absPos))
        platePos = int(puckPos / 3)
        rotMotTarget = daq_utils.dewarPlateMap[platePos][0]
        rotCP = beamline_lib.motorPosFromDescriptor("dewarRot")
        logger.info("dewar target,CP")
        logger.info("%s %s" % (rotMotTarget, rotCP))
        if (abs(rotMotTarget - rotCP) > 1):
            logger.info("rot dewar")
            try:
                RobotControlLib.runCmd("park")
            except Exception as e:
                e_s = str(e)
                message = "ROBOT park ERROR: " + e_s
                daq_lib.gui_message(message)
                logger.error(message)
                return 0
            beamline_lib.mvaDescriptor("dewarRot", rotMotTarget)
        try:
            par_init = (beamline_support.get_any_epics_pv(
                "SW:RobotState", "VAL") != "Ready")
            par_cool = (getPvDesc("gripTemp") > -170)
            RobotControlLib.unmount1(init=par_init, cooldown=par_cool)
        except Exception as e:
            e_s = str(e)
            message = "ROBOT unmount ERROR: " + e_s
            daq_lib.gui_message(message)
            logger.error(message)
            return 0
        if daq_utils.beamline == "fmx":
            det_z_pv = 'XF:17IDC-ES:FMX{Det-Ax:Z}Mtr'
            detDist = caget(f'{det_z_pv}.RBV')
            if detDist < ROBOT_MIN_DISTANCE:
                caput(
                    f'{det_z_pv}.VAL', ROBOT_MIN_DISTANCE, wait=True
                )  # TODO shouldn't this wait for SE transition or something??
            detDist = caget(f'{det_z_pv}.RBV')
        else:
            detDist = beamline_lib.motorPosFromDescriptor("detectorDist")
        if detDist < ROBOT_MIN_DISTANCE and abs(
                detDist - ROBOT_MIN_DISTANCE) > ROBOT_DISTANCE_TOLERANCE:
            logger.error(
                f"ERROR - Detector closer than {ROBOT_MIN_DISTANCE} and move than {ROBOT_DISTANCE_TOLERANCE} from {ROBOT_MIN_DISTANCE}! actual distance: {detDist}. Stopping."
            )
            return 0
        try:
            RobotControlLib.unmount2(absPos)
        except Exception as e:
            e_s = str(e)
            if (e_s.find("Fatal") != -1):
                daq_macros.robotOff()
                daq_macros.disableMount()
                daq_lib.gui_message(
                    e_s +
                    ". FATAL ROBOT ERROR - CALL STAFF! robotOff() executed.")
                return 0
            message = "ROBOT unmount2 ERROR: " + e_s
            daq_lib.gui_message(message)
            logger.error(message)
            return 0
        if (not daq_lib.waitGovRobotSE()):
            daq_lib.clearMountedSample()
            logger.info("could not go to SE")
            return 0
    return 1
Ejemplo n.º 4
0
def mountRobotSample(puckPos, pinPos, sampID, init=0, warmup=0):
    global retryMountCount
    global sampXadjust, sampYadjust, sampZadjust

    absPos = (pinsPerPuck * (puckPos % 3)) + pinPos + 1
    logger.info(f'init: {init} warmup: {warmup}')
    if (getBlConfig('robot_online')):
        if (not daq_lib.waitGovRobotSE()):
            daq_lib.setGovRobot('SE')
        if (getBlConfig(TOP_VIEW_CHECK) == 1):
            try:
                sample = db_lib.getSampleByID(sampID)
                sampName = sample['name']
                reqCount = sample['request_count']
                prefix1 = sampName + "_" + str(puckPos) + "_" + str(
                    pinPos) + "_" + str(reqCount) + "_PA_0"
                prefix90 = sampName + "_" + str(puckPos) + "_" + str(
                    pinPos) + "_" + str(reqCount) + "_PA_90"
                daq_macros.topViewSnap(prefix1,
                                       os.getcwd() + "/pinAlign",
                                       1,
                                       acquire=0)
            except Exception as e:
                e_s = str(e)
                message = "TopView check ERROR, will continue: " + e_s
                daq_lib.gui_message(message)
                logger.error(message)
        logger.info("mounting " + str(puckPos) + " " + str(pinPos) + " " +
                    str(sampID))
        logger.info("absPos = " + str(absPos))
        platePos = int(puckPos / 3)
        rotMotTarget = daq_utils.dewarPlateMap[platePos][0]
        rotCP = beamline_lib.motorPosFromDescriptor("dewarRot")
        logger.info("dewar target,CP")
        logger.info("%s %s" % (rotMotTarget, rotCP))
        if (abs(rotMotTarget - rotCP) > 1):
            logger.info("rot dewar")
            try:
                if (init == 0):
                    RobotControlLib.runCmd("park")
            except Exception as e:
                e_s = str(e)
                message = "ROBOT Park ERROR: " + e_s
                daq_lib.gui_message(message)
                logger.error(message)
                return 0
            beamline_lib.mvaDescriptor("dewarRot", rotMotTarget)
        try:
            if (init):
                logger.debug('main loading part')
                setPvDesc("boostSelect", 0)
                if (getPvDesc("sampleDetected") == 0
                    ):  #reverse logic, 0 = true
                    setPvDesc("boostSelect", 1)
                else:
                    robotStatus = beamline_support.get_any_epics_pv(
                        "SW:RobotState", "VAL")
                    if (robotStatus != "Ready"):
                        if (daq_utils.beamline == "fmx"):
                            daq_macros.homePins()
                            time.sleep(3.0)
                        if (not daq_lib.setGovRobot('SE')):
                            return
                if (getBlConfig(TOP_VIEW_CHECK) == 1):
                    omegaCP = beamline_lib.motorPosFromDescriptor("omega")
                    if (omegaCP > 89.5 and omegaCP < 90.5):
                        beamline_lib.mvrDescriptor("omega", 85.0)
                    logger.info("calling thread")
                    _thread.start_new_thread(wait90TopviewThread,
                                             (prefix1, prefix90))
                    logger.info("called thread")
                setPvDesc("boostSelect", 0)
                if (getPvDesc("gripTemp") > -170):
                    try:
                        logger.debug('mounting')
                        RobotControlLib.mount(absPos)
                    except Exception as e:
                        e_s = str(e)
                        message = "ROBOT mount ERROR: " + e_s
                        daq_lib.gui_message(message)
                        logger.error(message)
                        return 0
                else:
                    time.sleep(0.5)
                    if (getPvDesc("sampleDetected") == 0):
                        logger.info("full mount")
                        RobotControlLib.mount(absPos)
                    else:
                        logger.debug('quick mount')
                        RobotControlLib.initialize()
                        RobotControlLib._mount(absPos)
                setPvDesc("boostSelect", 1)
            else:
                if (getBlConfig(TOP_VIEW_CHECK) == 1):
                    omegaCP = beamline_lib.motorPosFromDescriptor("omega")
                    if (omegaCP > 89.5 and omegaCP < 90.5):
                        beamline_lib.mvrDescriptor("omega", 85.0)
                    logger.info("calling thread")
                    _thread.start_new_thread(wait90TopviewThread,
                                             (prefix1, prefix90))
                    logger.info("called thread")
                if (warmup):
                    RobotControlLib._mount(absPos, warmup=True)
                else:
                    RobotControlLib._mount(absPos)
            logger.info(f'{getBlConfig(TOP_VIEW_CHECK)} {daq_utils.beamline}')
            if (getBlConfig(TOP_VIEW_CHECK) == 1):
                if (sampYadjust == 0):
                    logger.info("Cannot align pin - Mount next sample.")

            daq_lib.setGovRobot('SA')
            return 1
        except Exception as e:
            logger.error(e)
            e_s = str(e)
            if (e_s.find("Fatal") != -1):
                daq_macros.robotOff()
                daq_macros.disableMount()
                daq_lib.gui_message(
                    e_s +
                    ". FATAL ROBOT ERROR - CALL STAFF! robotOff() executed.")
                return 0
            if (e_s.find("tilted") != -1
                    or e_s.find("Load Sample Failed") != -1):
                if (getBlConfig("queueCollect") == 0):
                    daq_lib.gui_message(e_s + ". Try mounting again")
                    return 0
                else:
                    if (retryMountCount == 0):
                        retryMountCount += 1
                        mountStat = mountRobotSample(puckPos, pinPos, sampID,
                                                     init)
                        if (mountStat == 1):
                            retryMountCount = 0
                        return mountStat
                    else:
                        retryMountCount = 0
                        daq_lib.gui_message("ROBOT: Could not recover from " +
                                            e_s)
                        return 2
            daq_lib.gui_message("ROBOT mount ERROR: " + e_s)
            return 0
        return 1
    else:
        return 1
Ejemplo n.º 5
0
def mountRobotSample(puckPos,pinPos,sampID,init=0,warmup=0):
  global retryMountCount

#  absPos = (pinsPerPuck*puckPos)+pinPos+1
  absPos = (pinsPerPuck*(puckPos%3))+pinPos+1  
  if (db_lib.getBeamlineConfigParam(daq_utils.beamline,'robot_online')):
    if (not daq_lib.waitGovRobotSE()):
      daq_lib.setGovRobotSE()
    print("mounting " + str(puckPos) + " " + str(pinPos) + " " + str(sampID))
    print("absPos = " + str(absPos))
    platePos = int(puckPos/3)
    rotMotTarget = daq_utils.dewarPlateMap[platePos][0]
    rotCP = beamline_lib.motorPosFromDescriptor("dewarRot")
    print("dewar target,CP")
    print(rotMotTarget,rotCP)
    if (abs(rotMotTarget-rotCP)>1):
      print("rot dewar")
      try:
        if (init == 0):
          RobotControlLib.runCmd("park")
      except Exception as e:
        e_s = str(e)        
        daq_lib.gui_message("ROBOT Park ERROR: " + e_s)                  
        print(e)
        return 0
      beamline_lib.mvaDescriptor("dewarRot",rotMotTarget)
    try:
      if (init):
        beamline_support.setPvValFromDescriptor("boostSelect",0)
        if (beamline_support.getPvValFromDescriptor("sampleDetected") == 0): #reverse logic, 0 = true
          beamline_support.setPvValFromDescriptor("boostSelect",1)
        else:
#            if (beamline_support.getPvValFromDescriptor("gripTemp") > 20.0): #gripper warm
          robotStatus = beamline_support.get_any_epics_pv("SW:RobotState","VAL")
          if (robotStatus != "Ready"):
            if (daq_utils.beamline == "fmx"):
              daq_macros.homePins()
              time.sleep(3.0)
            if (not daq_lib.setGovRobotSE()):
              return
        RobotControlLib.mount(absPos)
      else:
        if (warmup):
          RobotControlLib._mount(absPos,warmup=True)
        else:
          RobotControlLib._mount(absPos)                    
      daq_lib.setGovRobotSA()
      return 1
    except Exception as e:
      print(e)
      e_s = str(e)
      if (e_s.find("Fatal") != -1):
        daq_macros.robotOff()
        daq_macros.disableMount()
        daq_lib.gui_message(e_s + ". FATAL ROBOT ERROR - CALL STAFF! robotOff() executed.")
        return 0                    
      if (e_s.find("tilted") != -1 or e_s.find("Load Sample Failed") != -1):
        if (db_lib.getBeamlineConfigParam(daq_utils.beamline,"queueCollect") == 0):          
          daq_lib.gui_message(e_s + ". Try mounting again")
          return 0            
        else:
          if (retryMountCount == 0):
            retryMountCount+=1
            mountStat = mountRobotSample(puckPos,pinPos,sampID,init)
            if (mountStat == 1):
              retryMountCount = 0
            return mountStat
          else:
            retryMountCount = 0
            daq_lib.gui_message("ROBOT: Could not recover from " + e_s)
            return 2
      daq_lib.gui_message("ROBOT mount ERROR: " + e_s)
      return 0
    return 1
  else:
    return 1
Ejemplo n.º 6
0
def unmountRobotSample(puckPos,pinPos,sampID): #will somehow know where it came from

#  absPos = (pinsPerPuck*puckPos)+pinPos+1
  absPos = (pinsPerPuck*(puckPos%3))+pinPos+1  
  robotOnline = db_lib.getBeamlineConfigParam(daq_utils.beamline,'robot_online')
  print("robot online = " + str(robotOnline))
  if (robotOnline):
    detDist = beamline_lib.motorPosFromDescriptor("detectorDist")    
    if (detDist<199.0):
      beamline_support.setPvValFromDescriptor("govRobotDetDistOut",200.0)
      beamline_support.setPvValFromDescriptor("govHumanDetDistOut",200.0)          
    daq_lib.setRobotGovState("SE")    
    print("unmounting " + str(puckPos) + " " + str(pinPos) + " " + str(sampID))
    print("absPos = " + str(absPos))
    platePos = int(puckPos/3)
    rotMotTarget = daq_utils.dewarPlateMap[platePos][0]
    rotCP = beamline_lib.motorPosFromDescriptor("dewarRot")
    print("dewar target,CP")
    print(rotMotTarget,rotCP)
    if (abs(rotMotTarget-rotCP)>1):
      print("rot dewar")
      try:
        RobotControlLib.runCmd("park")
      except Exception as e:
        e_s = str(e)        
        daq_lib.gui_message("ROBOT park ERROR: " + e_s)        
        print(e)
        return 0
      beamline_lib.mvaDescriptor("dewarRot",rotMotTarget)
    try:
      par_init=(beamline_support.get_any_epics_pv("SW:RobotState","VAL")!="Ready")
      par_cool=(beamline_support.getPvValFromDescriptor("gripTemp")>-170)
      if par_cool == False and daq_utils.beamline == "fmx": 
        time.sleep(3)
      RobotControlLib.unmount1(init=par_init,cooldown=par_cool)
    except Exception as e:
      e_s = str(e)        
      daq_lib.gui_message("ROBOT unmount ERROR: " + e_s)        
      print(e)
      return 0
    detDist = beamline_lib.motorPosFromDescriptor("detectorDist")
    if (detDist<200.0):
      beamline_lib.mvaDescriptor("detectorDist",200.0)
    if (beamline_lib.motorPosFromDescriptor("detectorDist") < 199.0):
      print("ERROR - Detector < 200.0!")
      return 0
    try:
      RobotControlLib.unmount2(absPos)
    except Exception as e:
      e_s = str(e)
      if (e_s.find("Fatal") != -1):
        daq_macros.robotOff()
        daq_macros.disableMount()          
        daq_lib.gui_message(e_s + ". FATAL ROBOT ERROR - CALL STAFF! robotOff() executed.")
        return 0
      daq_lib.gui_message("ROBOT unmount2 ERROR: " + e_s)        
      print(e)
      return 0
    if (not daq_lib.waitGovRobotSE()):
      daq_lib.clearMountedSample()
      print("could not go to SE")    
      return 0
  return 1
Ejemplo n.º 7
0
def unmountRobotSample(puckPos, pinPos,
                       sampID):  #will somehow know where it came from

    absPos = (pinsPerPuck * (puckPos % 3)) + pinPos + 1
    robotOnline = getBlConfig('robot_online')
    logger.info("robot online = " + str(robotOnline))
    if (robotOnline):
        detDist = beamline_lib.motorPosFromDescriptor("detectorDist")
        if (detDist < 200.0):
            setPvDesc("govRobotDetDistOut", 200.0)
            setPvDesc("govHumanDetDistOut", 200.0)
        daq_lib.setRobotGovState("SE")
        logger.info("unmounting " + str(puckPos) + " " + str(pinPos) + " " +
                    str(sampID))
        logger.info("absPos = " + str(absPos))
        platePos = int(puckPos / 3)
        rotMotTarget = daq_utils.dewarPlateMap[platePos][0]
        rotCP = beamline_lib.motorPosFromDescriptor("dewarRot")
        logger.info("dewar target,CP")
        logger.info("%s %s" % (rotMotTarget, rotCP))
        if (abs(rotMotTarget - rotCP) > 1):
            logger.info("rot dewar")
            try:
                RobotControlLib.runCmd("park")
            except Exception as e:
                e_s = str(e)
                message = "ROBOT park ERROR: " + e_s
                daq_lib.gui_message(message)
                logger.error(message)
                return 0
            beamline_lib.mvaDescriptor("dewarRot", rotMotTarget)
        try:
            par_init = (beamline_support.get_any_epics_pv(
                "SW:RobotState", "VAL") != "Ready")
            par_cool = (getPvDesc("gripTemp") > -170)
            RobotControlLib.unmount1(init=par_init, cooldown=par_cool)
        except Exception as e:
            e_s = str(e)
            message = "ROBOT unmount ERROR: " + e_s
            daq_lib.gui_message(message)
            logger.error(message)
            return 0
        detDist = beamline_lib.motorPosFromDescriptor("detectorDist")
        if (detDist < 200.0):
            beamline_lib.mvaDescriptor("detectorDist", 200.0)
        if (beamline_lib.motorPosFromDescriptor("detectorDist") < 199.0):
            logger.error("ERROR - Detector < 200.0!")
            return 0
        try:
            RobotControlLib.unmount2(absPos)
        except Exception as e:
            e_s = str(e)
            if (e_s.find("Fatal") != -1):
                daq_macros.robotOff()
                daq_macros.disableMount()
                daq_lib.gui_message(
                    e_s +
                    ". FATAL ROBOT ERROR - CALL STAFF! robotOff() executed.")
                return 0
            message = "ROBOT unmount2 ERROR: " + e_s
            daq_lib.gui_message(message)
            logger.error(message)
            return 0
        if (not daq_lib.waitGovRobotSE()):
            daq_lib.clearMountedSample()
            logger.info("could not go to SE")
            return 0
    return 1