def finalize_unmount(auto_unmount, raising=False): evlog = Controller.getInstance().logEvent if not auto_unmount: evlog("setting magnet to default current and no detection") smart_magnet.set_default_current() smart_magnet.set_supress(True) if raising: evlog(">>>>>>>>> raising exception") evlog("############### UNMOUNT-FINISHED ####################") def unmount(segment = None, puck = None, sample = None, force=True, auto_unmount = False, next_segment="-*-", mounting_in_same_segment=False): """ """ evlog = Controller.getInstance().logEvent tg = time.time t1 = tg() if (segment is None) or (puck is None) or (sample is None): pos = get_setting("mounted_sample_position") if pos is None: evlog("Mounted sample position is not defined") raise Exception("Mounted sample position is not defined") segment, puck , sample = pos[0:1], int(pos[1]), int(pos[2:]) print "%4.1f Mounted sample position: %s%s-%s" % (tg() - t1, segment, puck , sample) sampleAddress = str(segment) + str(puck) + "-" + str(sample) evlog(">>>>>>>>>>>>>>> UNMOUNT <<<<<<<<<<<<<<<<<<<<<") msg = "unmount() Unmounting %s" % (sampleAddress,) evlog(msg) is_aux = (segment == AUX_SEGMENT) is_rt = (segment == RT_SEGMENT) is_cryo_sample = not (is_aux or is_rt) was_cold = robot.is_cold() was_warm = not was_cold needs_chilling = not is_rt and was_warm needs_drying = is_rt and was_cold move_cold_at_end = str(next_segment) in COLD_SEGMENTS try: assert_puck_detected(segment, puck) except: msg = "PUCK DISLODGED: puck no longer detected" evlog(msg) finalize_unmount(auto_unmount, raising=True) raise Exception(msg) #Initial checks if not auto_unmount: print "%4.1f s asserting" % (tg() - t1,) print " assert valid address" assert_valid_address(segment, puck, sample) print " assert puck detected" assert_puck_detected(segment, puck) if robot.simulated: time.sleep(3.0) update_samples_info_sample_unmount(get_puck_name(segment, puck), sample) set_setting("mounted_sample_position", None) return False print " assert no task" robot.assert_no_task() print " reset motion" robot.reset_motion() print " wait ready" robot.wait_ready() print " assert cleared" robot.assert_cleared() #robot.assert_in_known_point() print " assert homed" hexiposi.assert_homed() print " assert mount pos" assert_mount_position() set_status("Unmounting: " + str(segment) + str(puck) + str(sample)) hasSample = robot.gripper_has_sample() if hasSample: msg = "unmount() CRITICAL GRIPPER-TEST - the gripper has a sample already!!!" evlog(msg) finalize_unmount(auto_unmount, raising=True) raise Exception("CRITICAL ERROR: the gripper has a sample stuck to it, call local contact.") if smart_magnet.get_supress() == True: smart_magnet.set_supress(False) time.sleep(0.2) if not force: sample_det = smart_magnet.check_mounted(idle_time=0.5, timeout = 3.0) evlog("Sample Detection", str(sample_det)) if sample_det == False: evlog("No pin detected on gonio") finalize_unmount(auto_unmount, raising=True) raise Exception("No pin detected on gonio") evlog("enabling motion") try: enable_motion() except: evlog("error in enable_motion()") finalize_unmount(auto_unmount, raising=True) raise Exception("error in enable_motion()") if is_cryo_sample: evlog("set_hexiposi(%s)" % (segment,)) try: set_hexiposi(segment) except: evlog("failed to move hexiposi for unmount") finalize_unmount(auto_unmount, raising=True) raise Exception("failed to move hexiposi for unmount") if needs_chilling: evlog("unmount() cooling gripper for 30s prior to unmount") try: robot.move_cold() except: evlog("failure moving gripper into cold position") finalize_unmount(auto_unmount, raising=True) raise Exception("failure moving gripper into cold position") time.sleep(30.) else: if needs_drying: evlog("drying gripper before unmount") try: dry(wait_cold=-1) except: evlog("problems drying gripper dry(wait_cold=-1)") finalize_unmount(auto_unmount, raising=True) raise Exception("problems drying gripper dry(wait_cold=-1)") evlog("moving arm to gonio") try: if not robot.is_gonio(): robot.move_gonio() except: evlog("error in move_gonio()") finalize_unmount(auto_unmount, raising=True) raise Exception("error in move_gonio()") evlog("retracting cryojet if necessary") try: curpos = cryopos.getPosition() if is_room_temperature_enabled(): if curpos < 50: cryopos.move(50.) else: speed = cryopos.getSpeed() / 1000. movetime = int(round(3000 + abs(15. - curpos) / speed)) cryopos.move(15.0, movetime) cryopos.waitValueInRange(15.0, 1.0, movetime) except: evlog("error retracting cryojet") finalize_unmount(auto_unmount, raising=True) raise Exception("error retracting cryojet") evlog("getting gonio") try: robot.get_gonio() except: evlog("error in get_gonio()") finalize_unmount(auto_unmount, raising=True) raise Exception("error in get_gonio()") evlog("returning sample") try: if is_aux: robot.move_aux() robot.put_aux(sample) elif is_rt: robot.move_rt() robot.put_rt(puck, sample) else: #TODO: Should check if smart magnet detection is off? update_samples_info_sample_unmount(get_puck_name(segment, puck), sample) robot.move_dewar() robot.put_dewar(segment, puck, sample, mounting_in_same_segment=mounting_in_same_segment) except: evlog("error in move/put (aux, rt, dewar)") finalize_unmount(auto_unmount, raising=True) raise Exception("error in move/put (aux, rt, dewar)") # FIXME, this check is necessary in case the puck was lifted/flipped during unmount evlog("checking for puck dislodgement") try: time.sleep(1.0) assert_puck_detected(segment, puck) except: msg = "PUCK DISLODGED: puck no longer detected after put_dewar()" evlog(msg) finalize_unmount(auto_unmount, raising=True) raise Exception(msg) robot.close_tool() # closes gripper has_sample_after_get = robot.gripper_has_sample() evlog("unmount() sample detections after put_(dewar,rt,aux):") evlog(" GRIPPER: ", str(has_sample_after_get)) smart_magnet.apply_reverse() smart_magnet.apply_resting() mount_sample_detected = smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0) evlog(" SMC: ", str(mount_sample_detected)) evlog("moving gripper to either cold or park") try: if is_cryo_sample: robot.move_cold() else: robot.move_park() except: evlog("error in move_(cold/park)") finalize_unmount(auto_unmount, raising=True) raise Exception("error in move_(cold/park)") evlog("checking if gripper really empty") reallyEmpty = is_gripper_really_empty(0.8) if not reallyEmpty: msg = "unmount() CRITICAL gripper still has a sample {} after puck delivery attempt, call local contact!".format(sampleAddress) evlog(msg) finalize_unmount(auto_unmount, raising=True) raise Exception(msg) robot.open_tool() set_setting("mounted_sample_position", None) finalize_unmount(auto_unmount) return mount_sample_detected