Files
x06da/script/motion/unmount.py
alexgobbo 75400ca453
2024-09-11 16:17:17 +02:00

143 lines
5.1 KiB
Python

def safe_unmount():
return unmount(force = True, auto_unmount = True)
def unmount(segment = None, puck = None, sample = None, force=False, auto_unmount = False):
"""
Returns if sample is detected in the end
"""
evlog = Controller.getInstance().logEvent
print "unmount: ", segment, puck, sample, force
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")
try:
segment, puck , sample = pos[0:1], int(pos[1]), int(pos[2:])
print "Mounted sample position: ", segment, puck , sample
except:
set_setting("mounted_sample_position", None)
raise Exception("Invalid mounted sample position: " + str(pos) + " - setting to None")
was_cold = robot.is_cold()
is_aux = segment == AUX_SEGMENT
is_rt = segment == RT_SEGMENT
is_cold = segment in COLD_SEGMENTS
needs_chilling = is_cold and not was_cold
needs_drying = is_rt and was_cold
#Initial checks
if not auto_unmount:
print "assert detector safe"
assert_detector_safe()
print "assert valid address"
assert_valid_address(segment, puck, sample)
print "asser 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()
sample_name = str(segment) + str(puck) + str(sample)
set_status("Unmounting: " + sample_name)
evlog("Unmount Sample", sample_name)
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.6, timeout = 3.0)
evlog("SMC Detection", str(sample_det))
if sample_det == False:
raise Exception("No pin detected on gonio")
#Enabling
enable_motion()
if not is_aux:
set_hexiposi(segment, force=False)
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()
cryostage.moveAsync(17.0)
cryostage.waitInPosition(17.0, 3500)
if not robot.is_gonio():
robot.move_gonio()
#smart_magnet.set_unmount_current()
robot.get_gonio()
set_pin_cleaner(True)
smart_magnet.apply_reverse()
smart_magnet.apply_resting()
mount_sample_detected = smart_magnet.check_mounted(idle_time=0.6, timeout = 2.0)
evlog("SMC Detection: ", "sample on gonio" if mount_sample_detected else "gonio free")
if is_aux:
robot.move_aux()
robot.put_aux(sample)
robot.move_park()
else:
#TODO: remove this check when issue with Hexiposi is fixed (moving to dfifferent position (B) when commanding to position where it was already)
if hexiposi.position != segment:
robot.move_cold() #Save the sample
log_str = "Hexiposi detected in wrong position " + str(hexiposi.readback.take()) + " - not in " + str(segment)
evlog(log_str); log(log_str, False) ; print log_str
set_hexiposi(segment, force=False)
if hexiposi.position != segment:
log_str = "Cannot restore hexiposi position"
Controller.getInstance().logEvent(log_str); log(log_str, False) ; print log_str
raise Exception(log_str)
#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)
if mount_sample_detected:
evlog("failed to unmount sample " + sample_name)
raise Exception("failed to unmount sample " + sample_name)
else:
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)