Files
X10SA/script/motion/mount.py
T
2021-05-12 09:14:17 +02:00

171 lines
6.4 KiB
Python

mount_sample_id = None
mount_sample_detected = None
def mount(segment, puck, sample, force=False, read_dm=False, auto_unmount=False):
"""
"""
global mount_sample_id, mount_sample_detected
print "mount: ", segment, puck, sample, force
start = time.time()
#time.sleep(2)
is_aux = (segment == AUX_SEGMENT)
is_rt = (segment == RT_SEGMENT)
#ZACH
needs_chilling = (not is_aux) and (not is_rt) and (not robot.is_cold())
needs_drying = (is_aux or is_rt ) and robot.is_cold()
puck_address = get_puck_address(puck)
if puck_address is None:
puck_obj = get_puck_obj_by_id(puck)
if puck_obj is not None:
puck_address = puck_obj.name
if puck_address is not None:
print "puck address: ", puck_address
segment = puck_address[:1]
puck = int(puck_address[1:])
#Initial checks
assert_valid_address(segment, puck, sample)
assert_puck_detected(segment, puck)
if robot.simulated:
time.sleep(3.0)
mount_sample_detected = True
mount_sample_id = "YYY0001"
update_samples_info_sample_mount(get_puck_name(segment, puck), sample, mount_sample_detected, mount_sample_id)
set_setting("mounted_sample_position", get_sample_name(segment, puck, sample))
return [mount_sample_detected, mount_sample_id]
robot.assert_no_task()
robot.reset_motion()
robot.wait_ready()
robot.assert_cleared()
#robot.assert_in_known_point()
hexiposi.assert_homed()
assert_mount_position()
do_unmount = False
mounting_in_same_segment = False
try:
#ZACH
if needs_chilling:
robot.move_cold()
time.sleep(30.0)
if smart_magnet.get_supress() == True:
smart_magnet.set_supress(False)
time.sleep(0.2)
#To better dectect sample
#smart_magnet.apply_reverse()
#smart_magnet.apply_resting()
#time.sleep(0.5)
sample_det = smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0)
Controller.getInstance().logEvent("Sample Detection", str(sample_det))
if sample_det == True:
if auto_unmount and (get_setting("mounted_sample_position") is not None):
pos = get_setting("mounted_sample_position")
former_segment = pos[0:1]
mounting_in_same_segment = (former_segment == segment)
if mounting_in_same_segment:
print "Mounting from the same segment"
#auto_unmount set to true so detection remains enabled
sample_det = unmount(force = True, auto_unmount = True, mounting_in_same_segment=mounting_in_same_segment)
do_unmount = True
if sample_det == True:
raise Exception("Pin detected on gonio")
set_status("Mounting: " + str(segment) + str(puck) + str(sample))
Controller.getInstance().logEvent("Mount Sample", str(segment) + str(puck) + str(sample))
#location = robot.get_current_point()
#Enabling. If did unmount then it is already enabled.
if not do_unmount:
enable_motion()
#ZACH
# a room temp pin is being mounted but the gripper is cold
if needs_drying:
dry(wait_cold=-1) # move to park after dry
if is_aux:
if not robot.is_aux():
robot.move_aux()
robot.get_aux(sample)
elif is_rt:
if not robot.is_rt():
robot.move_rt()
robot.get_rt(puck, sample)
else:
set_hexiposi(segment)
if not force:
visual_check_hexiposi(segment)
if (not robot.is_dewar()) and (not mounting_in_same_segment):
robot.move_dewar()
robot.get_dewar(segment, puck, sample, mounting_in_same_segment=mounting_in_same_segment)
piked_sample = robot.gripper_has_sample()
log("Sample Detection - mount: after get_dewar: " + str(piked_sample) + str(segment) + str(puck) + str(sample), False)
if read_dm:
barcode_reader.start_read(10.0)
robot.move_scanner()
#time.sleep(1.0)
robot.move_gonio()
if read_dm:
mount_sample_id = barcode_reader.get_readout()
print "Datamatrix: " , mount_sample_id
else:
mount_sample_id = None
robot.put_gonio()
#has_sample_after_put = robot.gripper_has_sample()
#log("Sample Detection - mount after put: " + str(has_sample_after_put), False)
try:
dry_mount_count = int(get_setting("dry_mount_counter"))
except:
dry_mount_count = 0
set_setting("dry_mount_counter", dry_mount_count+1)
if is_aux or is_rt:
robot.move_home()
else:
robot.move_cold()
mount_sample_detected = smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0)
Controller.getInstance().logEvent("Sample Detection", str(mount_sample_detected))
update_samples_info_sample_mount(get_puck_name(segment, puck), sample, mount_sample_detected, mount_sample_id)
if mount_sample_detected != piked_sample:
log("Sample Detection Error - after put on SM:" + str(mount_sample_detected) + " gripper:" + str(piked_sample), False)
#if has_sample_after_put and mount_sample_detected:
# log("Sample Detection Error - put SM:" + str(mount_sample_detected) + " gripper:" + str(has_sample_after_put), False)
if mount_sample_detected == False:
raise Exception("No pin detected on gonio")
if is_force_dry():
smart_magnet.set_default_current()
print "Auto dry"
log("Starting auto dry", False)
set_exec_pars(then = "dry()")
set_setting("mounted_sample_position", get_sample_name(segment, puck, sample))
return [mount_sample_detected, mount_sample_id]
finally:
smart_magnet.set_default_current()
smart_magnet.set_supress(True)