165 lines
5.7 KiB
Python
165 lines
5.7 KiB
Python
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:
|
|
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_normal = 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
|
|
|
|
|
|
#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)
|
|
raise Exception("CRITICAL ERROR: the gripper has a sample stuck to it, call local contact.")
|
|
# raise Exception("CRITICAL ERROR: the gripper has a sample stuck to it, call local contact.")
|
|
|
|
|
|
try:
|
|
if smart_magnet.get_supress() == True:
|
|
smart_magnet.set_supress(False)
|
|
time.sleep(0.2)
|
|
|
|
#smart_magnet.apply_reverse()
|
|
#smart_magnet.apply_resting()
|
|
|
|
if not force:
|
|
sample_det = smart_magnet.check_mounted(idle_time=0.5, timeout = 3.0)
|
|
Controller.getInstance().logEvent("Sample Detection", str(sample_det))
|
|
if sample_det == False:
|
|
raise Exception("No pin detected on gonio")
|
|
|
|
#Enabling
|
|
enable_motion()
|
|
|
|
if is_normal:
|
|
evlog("unmount() set_hexiposi(%s)" % (segment,))
|
|
set_hexiposi(segment)
|
|
|
|
if not force:
|
|
visual_check_hexiposi(segment)
|
|
if needs_chilling:
|
|
robot.move_cold()
|
|
time.sleep(30.)
|
|
else:
|
|
if needs_drying:
|
|
dry(wait_cold=-1)
|
|
|
|
#location = robot.get_current_point()
|
|
|
|
if not robot.is_gonio():
|
|
robot.move_gonio()
|
|
|
|
#smart_magnet.set_unmount_current()
|
|
|
|
curpos = cryopos.getPosition()
|
|
speed = cryopos.getSpeed() / 1000.
|
|
movetime = int(round(3000 + abs(15. - curpos) / speed))
|
|
cryopos.move(15.0, movetime)
|
|
cryopos.waitValueInRange(15.0, 1.0, movetime)
|
|
|
|
robot.get_gonio()
|
|
|
|
if is_aux:
|
|
robot.move_aux()
|
|
robot.put_aux(sample)
|
|
elif is_rt:
|
|
robot.move_rt()
|
|
robot.put_rt(puck, sample)
|
|
else:
|
|
update_samples_info_sample_unmount(get_puck_name(segment, puck), sample)
|
|
robot.move_dewar()
|
|
robot.put_dewar(segment, puck, sample)
|
|
|
|
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))
|
|
|
|
if not auto_unmount:
|
|
if was_cold:
|
|
robot.move_cold()
|
|
else:
|
|
robot.move_park()
|
|
|
|
|
|
# Check gripper for frozen sample after trying to put back to puck
|
|
# if we detect a sample after closing gripper then we move the
|
|
# gripper back to cold/park and call for local contact or give user
|
|
# option to dry gripper and lose the sample
|
|
|
|
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)
|
|
raise Exception(msg)
|
|
|
|
robot.open_tool() # open gripper
|
|
|
|
set_setting("mounted_sample_position", None)
|
|
return mount_sample_detected
|
|
finally:
|
|
if not auto_unmount:
|
|
smart_magnet.set_default_current()
|
|
smart_magnet.set_supress(True)
|
|
evlog("############### UNMOUNT-FINISHED ####################")
|
|
|