Files
x06da/script/motion/unmount.py
alexgobbo ba17725e75 V2
2025-09-12 16:16:15 +02:00

137 lines
4.7 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
cover_info = get_cover_location_mm()
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 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:
if needs_chilling:
#added bt domi 26.8.2025
set_setting("dry_timestamp",time.time())
set_setting("dry_mount_counter", 0)
robot.move_dewar(*cover_info)
robot.move_cold()
time.sleep(30.)
invalidate_cover_info(cover_info)
else:
if needs_drying:
dry(wait_cold=-1)
#location = robot.get_current_point()
cryostage.moveAsync(15.0)
#cryostage.waitInPosition(15.0, 3500)
#time.sleep(0.05)
#if cryostage.getDoneChannel().getValue()=0
if not robot.is_gonio():
robot.move_gonio()
#smart_magnet.set_unmount_current()
cryostage.waitInPosition(15.0, 3500)
robot.get_gonio()
#set_pin_cleaner(True)
smart_magnet.apply_reverse()
smart_magnet.apply_resting()
#reducing waiting time by 0.3sec
mount_sample_detected = smart_magnet.check_mounted(idle_time=0.3, timeout = 2.0)
#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: Should check if smart magnet detection is off?
update_samples_info_sample_unmount(get_puck_name(segment, puck), sample)
robot.move_dewar(*cover_info)
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)