This commit is contained in:
14
script/data/pucks.py
Normal file
14
script/data/pucks.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def get_puck_names():
|
||||
return [str(a)+str(b) for a in BLOCKS for b in range(1,6)]
|
||||
|
||||
|
||||
def get_puck_info():
|
||||
ret = []
|
||||
#for puck in get_puck_names():
|
||||
for puck in BasePlate.pucks:
|
||||
ret.append({"address" : str(puck.name), "status": str(puck.status), "barcode" : str(puck.id)})
|
||||
return ret
|
||||
|
||||
|
||||
def get_puck_obj(address):
|
||||
return BasePlate.getChild(address)
|
||||
@@ -1,23 +1,279 @@
|
||||
import json
|
||||
import org.python.core.PyDictionary as PyDictionary
|
||||
|
||||
|
||||
SAMPLE_INFO_KEYS = ["userName", "dewarName", "puckName", "puckBarcode", "puckType", "puckAddress",
|
||||
"sampleName", "samplePosition", "sampleStatus", "sampleMountCount"]
|
||||
samples_info = []
|
||||
|
||||
|
||||
def set_samples_info(info):
|
||||
global samples_info
|
||||
if (is_string(info)):
|
||||
info = json.loads(info)
|
||||
if not is_list(info):
|
||||
raise Exception("Sample info must be a list (given object type is " + str(type(info)) + ")")
|
||||
#for sample in info:
|
||||
# if not (type(sample) is PyDictionary):
|
||||
# raise Exception("Sample info element must be a dictionary (given object type is " + str(type(sample)) + ")")
|
||||
#Sanitize list
|
||||
remove = []
|
||||
for sample in info:
|
||||
try:
|
||||
if set(sample.keys()) != set(SAMPLE_INFO_KEYS):
|
||||
raise Exception()
|
||||
except:
|
||||
remove.append(sample)
|
||||
for el in remove:
|
||||
info.remove(el)
|
||||
print "Invalid samples info element: " + str(el)
|
||||
samples_info = info
|
||||
return samples_info
|
||||
save_samples_info()
|
||||
#Trust beamline on assignments, so update puck info
|
||||
update_puck_table()
|
||||
|
||||
|
||||
def clear_samples_info():
|
||||
set_samples_info([])
|
||||
|
||||
def save_samples_info():
|
||||
data = get_samples_info(True)
|
||||
output_file = open( get_context().setup.expandPath("{context}/samples_info.json") , "w")
|
||||
output_file.write(data)
|
||||
output_file.close()
|
||||
|
||||
def restore_samples_info():
|
||||
try:
|
||||
inputfile = open(get_context().setup.expandPath("{context}/samples_info.json"), "r")
|
||||
info = inputfile.read()
|
||||
except:
|
||||
print >> sys.stderr, "Error reading sample info file: " + str(sys.exc_info()[1])
|
||||
info = []
|
||||
set_samples_info(info)
|
||||
|
||||
def get_samples_info(as_json=True):
|
||||
global sample_info
|
||||
return json.dumps(samples_info) if as_json else samples_info
|
||||
return json.dumps(samples_info) if as_json else samples_info
|
||||
|
||||
def has_puck_datamatrix(datamatrix):
|
||||
if samples_info is not None:
|
||||
for si in samples_info:
|
||||
if si["puckBarcode"] == datamatrix:
|
||||
return True
|
||||
return False
|
||||
|
||||
def add_puck_datamatrix(barcode, address = "", dewar = "Unknown", user = "Unknown", puck = "Unknown", type = "unipuck", sample_prefix = "Sample"):
|
||||
if has_puck_datamatrix(barcode):
|
||||
raise Exception("Datamatrix already defined: " + str(barcode))
|
||||
for s in range(1,17):
|
||||
info = \
|
||||
{ "userName": user, \
|
||||
"dewarName": dewar, \
|
||||
"puckName": puck, \
|
||||
"puckBarcode": address if barcode is None else barcode, \
|
||||
"puckType": type, \
|
||||
"puckAddress": address,\
|
||||
"sampleName": sample_prefix + " " + str(s), \
|
||||
"samplePosition": str(s),\
|
||||
"sampleStatus": "Unknown", \
|
||||
"sampleMountCount": "0",
|
||||
}
|
||||
samples_info.append(info)
|
||||
save_samples_info()
|
||||
|
||||
def remove_puck_datamatrix(barcode):
|
||||
remove = []
|
||||
for si in samples_info:
|
||||
if si["puckBarcode"] == barcode:
|
||||
remove.append(si)
|
||||
for el in remove: samples_info.remove(el)
|
||||
save_samples_info()
|
||||
|
||||
def set_puck_datamatrix(puck, datamatrix):
|
||||
if puck is None:
|
||||
puck = ""
|
||||
if datamatrix is None:
|
||||
datamatrix = ""
|
||||
if samples_info is not None:
|
||||
for si in samples_info:
|
||||
if si["puckBarcode"] == datamatrix:
|
||||
si["puckAddress"] = puck
|
||||
elif si["puckAddress"] == puck:
|
||||
si["puckAddress"] = ""
|
||||
save_samples_info()
|
||||
|
||||
def reset_puck_datamatrix(puck = None):
|
||||
if samples_info is not None:
|
||||
for si in samples_info:
|
||||
if (si["puckAddress"] == puck) or (puck is None):
|
||||
si["puckAddress"] = ""
|
||||
save_samples_info()
|
||||
|
||||
def get_puck_datamatrix():
|
||||
ret = {}
|
||||
for si in samples_info:
|
||||
if si["puckBarcode"] is not None and si["puckBarcode"]!="":
|
||||
ret[si["puckBarcode"]] = si["puckAddress"]
|
||||
return ret
|
||||
|
||||
def get_puck_address(barcode):
|
||||
try:
|
||||
return get_puck_datamatrix()[barcode]
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
def update_puck_table():
|
||||
dms = get_puck_datamatrix()
|
||||
for barcode in dms.keys():
|
||||
address = dms[barcode]
|
||||
puck = get_puck_obj(address)
|
||||
if puck is not None:
|
||||
puck.id = barcode
|
||||
|
||||
|
||||
#Sample mount/unmount
|
||||
|
||||
def update_samples_info_sample_mount(puck_address, sample_position, sample_detected):
|
||||
try:
|
||||
if (samples_info is not None) and (puck_address is not None):
|
||||
for si in samples_info:
|
||||
if str(si["puckAddress"]) == str(puck_address) and str(si["samplePosition"]) == str(sample_position):
|
||||
if sample_detected:
|
||||
if si["sampleStatus"] != "Mounted":
|
||||
si["sampleStatus"] = "Mounted"
|
||||
try:
|
||||
mount_count = int(si["sampleMountCount"])
|
||||
except:
|
||||
mount_count = 0
|
||||
si["sampleMountCount"] = mount_count + 1
|
||||
else:
|
||||
si["sampleStatus"] = "Unknown"
|
||||
save_samples_info()
|
||||
return
|
||||
except:
|
||||
pass
|
||||
|
||||
def update_samples_info_sample_unmount(puck_address, sample_position):
|
||||
try:
|
||||
if (samples_info is not None) and (puck_address is not None):
|
||||
for si in samples_info:
|
||||
if str(si["puckAddress"]) == str(puck_address) and str(si["samplePosition"]) == str(sample_position):
|
||||
si["sampleStatus"] = "HasBeenMounted"
|
||||
save_samples_info()
|
||||
return
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
|
||||
test_sample_data = [ \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0001", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "A1",\
|
||||
"sampleName": "MySample 1", \
|
||||
"samplePosition": 1,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0001", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "A1",\
|
||||
"sampleName": "MySample 2", \
|
||||
"samplePosition": 2,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0001", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "A1",\
|
||||
"sampleName": "MySample 3", \
|
||||
"samplePosition": 3,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0001", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "A1",\
|
||||
"sampleName": "MySample 4", \
|
||||
"samplePosition": 4,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0001", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "A1",\
|
||||
"sampleName": "MySample 5", \
|
||||
"samplePosition": 5,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0002", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "C2",\
|
||||
"sampleName": "MySample 1", \
|
||||
"samplePosition": 1,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0002", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "C2",\
|
||||
"sampleName": "MySample 2", \
|
||||
"samplePosition": 2,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0002", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "C2",\
|
||||
"sampleName": "MySample 3", \
|
||||
"samplePosition": 3,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0002", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "C2",\
|
||||
"sampleName": "MySample 4", \
|
||||
"samplePosition": 4,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
{ "userName": "Alexandre", \
|
||||
"dewarName": "TEST", \
|
||||
"puckName": "My puck", \
|
||||
"puckBarcode": "AAA0002", \
|
||||
"puckType": "unipuck", \
|
||||
"puckAddress": "C2",\
|
||||
"sampleName": "MySample 5", \
|
||||
"samplePosition": 5,\
|
||||
"sampleStatus": "Present", \
|
||||
"sampleMountCount": 0,
|
||||
} , \
|
||||
]
|
||||
|
||||
@@ -22,8 +22,8 @@ joint_forces = False
|
||||
class RobotSC(RobotTCP):
|
||||
def __init__(self, name, server, timeout = 1000, retries = 1):
|
||||
RobotTCP.__init__(self, name, server, timeout, retries)
|
||||
self.set_tasks(["getDewar", "putDewar", "putGonio", "getGonio", "robotRecover", "moveDewar", "movePark", "moveGonio","moveHeater", "moveScanner","moveHome"])
|
||||
self.set_known_points(["pPark", "pGonioHome", "pDewarWait", "pGonioGet", "pScanHome", "pHeaterHome", "pHeater", "pHeaterBottom", "pScanStop","pHelium", "pHome"])
|
||||
self.set_tasks(["getDewar", "putDewar", "putGonio", "getGonio", "robotRecover", "moveDewar", "moveCold", "movePark", "moveGonio","moveHeater", "moveScanner","moveHome"])
|
||||
self.set_known_points(["pPark", "pGonioHome", "pDewarWait", "pGonioGet", "pScanHome", "pHeaterHome", "pHeater", "pHeaterBottom", "pScanStop","pHelium", "pHome", "pCold"])
|
||||
self.setPolling(DEFAULT_ROBOT_POLLING)
|
||||
|
||||
def move_dewar(self):
|
||||
@@ -31,6 +31,11 @@ class RobotSC(RobotTCP):
|
||||
self.wait_task_finished(TASK_WAIT_ROBOT_POLLING)
|
||||
self.assert_dewar()
|
||||
|
||||
def move_cold(self):
|
||||
self.start_task('moveCold')
|
||||
self.wait_task_finished(TASK_WAIT_ROBOT_POLLING)
|
||||
self.assert_cold()
|
||||
|
||||
def move_home(self):
|
||||
self.start_task('moveHome')
|
||||
self.wait_task_finished(TASK_WAIT_ROBOT_POLLING)
|
||||
@@ -141,6 +146,9 @@ class RobotSC(RobotTCP):
|
||||
|
||||
def is_park(self):
|
||||
return self.is_in_point("pPark")
|
||||
|
||||
def is_cold(self):
|
||||
return self.is_in_point("pCold")
|
||||
|
||||
def is_home(self):
|
||||
return self.is_in_point("pHome")
|
||||
@@ -175,6 +183,9 @@ class RobotSC(RobotTCP):
|
||||
|
||||
def assert_heater_home(self):
|
||||
self.assert_in_point("pHeaterHome")
|
||||
|
||||
def assert_cold(self):
|
||||
self.assert_in_point("pCold")
|
||||
|
||||
def assert_heater(self):
|
||||
self.assert_in_point("pHeater")
|
||||
|
||||
@@ -125,7 +125,7 @@ def release_psys():
|
||||
# Drier
|
||||
###################################################################################################
|
||||
|
||||
MAX_HEATER_TIME = 15000
|
||||
MAX_HEATER_TIME = 45000
|
||||
|
||||
|
||||
def set_air_stream(state):
|
||||
|
||||
@@ -7,6 +7,8 @@ from ch.psi.pshell.modbus import ModbusTCP
|
||||
import ch.psi.mxsc.Controller as Controller
|
||||
import ch.psi.pshell.core.Nameable as Nameable
|
||||
import ch.psi.utils.Chrono as Chrono
|
||||
import ch.psi.mxsc.Controller as Controller
|
||||
|
||||
|
||||
|
||||
run("setup/Layout")
|
||||
@@ -76,6 +78,7 @@ add_device(img.getCamera(), force = True)
|
||||
###################################################################################################
|
||||
|
||||
run("data/samples")
|
||||
run("data/pucks")
|
||||
run("motion/tools")
|
||||
run("motion/mount")
|
||||
run("motion/unmount")
|
||||
@@ -88,6 +91,7 @@ run("motion/move_gonio")
|
||||
run("motion/move_heater")
|
||||
run("motion/move_home")
|
||||
run("motion/move_park")
|
||||
run("motion/move_cold")
|
||||
run("motion/move_scanner")
|
||||
run("motion/dry")
|
||||
run("motion/homing_hexiposi")
|
||||
@@ -216,7 +220,7 @@ for l in dewar_level.listeners:
|
||||
|
||||
dewar_level.addListener(dewar_level_listener)
|
||||
dewar_level_listener.onValueChanged(dewar_level, dewar_level.take(), None)
|
||||
|
||||
|
||||
|
||||
|
||||
###################################################################################################
|
||||
@@ -230,10 +234,15 @@ cover_detection_debug = False
|
||||
|
||||
|
||||
def is_puck_loading():
|
||||
return robot.state == State.Ready and robot.take()["pos"] == 'pPark' and feedback_psys_safety.take() == False
|
||||
return robot.state == State.Ready and robot.take()["pos"] == 'pPark' and \
|
||||
feedback_psys_safety.take() == False and \
|
||||
not guiding_tool_park.read()
|
||||
|
||||
|
||||
update()
|
||||
add_device(Controller.getInstance().basePlate, True)
|
||||
restore_samples_info()
|
||||
|
||||
|
||||
print "Initialization complete"
|
||||
|
||||
@@ -4,7 +4,7 @@ def get_dewar(segment, puck, sample, force=False):
|
||||
print "get_dewar: ", segment, puck, sample, force
|
||||
|
||||
#Initial checks
|
||||
assertValidAddress(segment, puck, sample)
|
||||
assert_valid_address(segment, puck, sample)
|
||||
assert_puck_detected(segment, puck)
|
||||
|
||||
robot.assert_no_task()
|
||||
|
||||
@@ -4,7 +4,7 @@ def mount(segment, puck, sample, force=False, read_dm=False):
|
||||
print "mount: ", segment, puck, sample, force
|
||||
start = time.time()
|
||||
#Initial checks
|
||||
assertValidAddress(segment, puck, sample)
|
||||
assert_valid_address(segment, puck, sample)
|
||||
assert_puck_detected(segment, puck)
|
||||
|
||||
robot.assert_no_task()
|
||||
@@ -45,8 +45,11 @@ def mount(segment, puck, sample, force=False, read_dm=False):
|
||||
smart_magnet.set_mount_current()
|
||||
try:
|
||||
robot.put_gonio()
|
||||
robot.move_dewar()
|
||||
if smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0) == False:
|
||||
robot.move_dewar()
|
||||
sample_detected = smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0)
|
||||
#TODO: Should do on finally?
|
||||
update_samples_info_sample_mount(get_puck_name(segment, puck), sample, sample_detected)
|
||||
if sample_detected == False:
|
||||
raise Exception("No pin detected on gonio")
|
||||
finally:
|
||||
smart_magnet.set_default_current()
|
||||
|
||||
18
script/motion/move_cold.py
Normal file
18
script/motion/move_cold.py
Normal file
@@ -0,0 +1,18 @@
|
||||
def move_cold():
|
||||
"""
|
||||
"""
|
||||
print "move_cold"
|
||||
|
||||
#Initial checks
|
||||
robot.assert_no_task()
|
||||
robot.reset_motion()
|
||||
robot.wait_ready()
|
||||
robot.assert_cleared()
|
||||
#robot.assert_in_known_point()
|
||||
|
||||
#Enabling
|
||||
enable_motion()
|
||||
|
||||
|
||||
if not robot.is_cold():
|
||||
robot.move_cold()
|
||||
@@ -4,7 +4,7 @@ def put_dewar(segment, puck, sample, force=False):
|
||||
print "put_dewar: ", segment, puck, sample, force
|
||||
|
||||
#Initial checks
|
||||
assertValidAddress(segment, puck, sample)
|
||||
assert_valid_address(segment, puck, sample)
|
||||
assert_puck_detected(segment, puck)
|
||||
|
||||
robot.assert_no_task()
|
||||
|
||||
@@ -128,7 +128,7 @@ def update_tool(tool=None, x_offset=0.0, y_offset=0.0, z_offset=0.0):
|
||||
robot.save_program()
|
||||
|
||||
|
||||
def assertValidAddress(segment, puck, sample):
|
||||
def assert_valid_address(segment, puck, sample):
|
||||
if is_string(segment):
|
||||
segment = ord(segment.upper()) - ord('A') +1
|
||||
if segment<=0 or segment >6:
|
||||
@@ -137,4 +137,20 @@ def assertValidAddress(segment, puck, sample):
|
||||
raise Exception ("Invalid puck")
|
||||
if sample<=0 or sample >16:
|
||||
raise Exception ("Invalid sample")
|
||||
|
||||
|
||||
def get_puck_name(segment, puck):
|
||||
try:
|
||||
assert_valid_address(segment, puck, 1)
|
||||
if type(segment) is int:
|
||||
segment = chr( ord('A') + (pos-1))
|
||||
elif type(segment) is str:
|
||||
segment = pos.upper()
|
||||
else:
|
||||
return None
|
||||
return segment + str(puck)
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ def unmount(segment, puck, sample, force=False):
|
||||
print "unmount: ", segment, puck, sample, force
|
||||
|
||||
#Initial checks
|
||||
assertValidAddress(segment, puck, sample)
|
||||
assert_valid_address(segment, puck, sample)
|
||||
assert_puck_detected(segment, puck)
|
||||
|
||||
robot.assert_no_task()
|
||||
@@ -34,6 +34,8 @@ def unmount(segment, puck, sample, force=False):
|
||||
smart_magnet.set_unmount_current()
|
||||
try:
|
||||
robot.get_gonio()
|
||||
#TODO: Shuld check if smart magnet detection is off?
|
||||
update_samples_info_sample_unmount(get_puck_name(segment, puck))
|
||||
robot.move_dewar()
|
||||
robot.put_dewar(segment, puck, sample)
|
||||
finally:
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
cover_detection_debug=False
|
||||
|
||||
for pos in ['A', 'B', 'C', 'D', 'E', 'F']:
|
||||
print "Moving to ", pos
|
||||
hexiposi.move(pos)
|
||||
ret = run("imgproc/CoverDetection")
|
||||
det = ret[0]
|
||||
print "Detected: ", det
|
||||
if det != pos:
|
||||
raise "Position error"
|
||||
cover_detection_debug=True
|
||||
while True:
|
||||
for pos in ['A', 'B', 'C', 'D', 'E', 'F']:
|
||||
print "Moving to ", pos
|
||||
hexiposi.move(pos)
|
||||
move_home()
|
||||
move_park()
|
||||
time.sleep(2.0)
|
||||
ret = run("imgproc/CoverDetection")
|
||||
det = ret[0]
|
||||
print "Detected: ", det
|
||||
if det != pos:
|
||||
raise Exception("Position error")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user