Second guiding tool
This commit is contained in:
+3
-3
@@ -1,3 +1,3 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Deployment specific global definitions - executed after startup.groovy
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Deployment specific global definitions - executed after startup.groovy
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Deployment specific global definitions - executed after startup.js
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Deployment specific global definitions - executed after startup.js
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
+424
-421
@@ -1,431 +1,434 @@
|
||||
###################################################################################################
|
||||
# Deployment specific global definitions - executed after startup.py
|
||||
###################################################################################################
|
||||
import traceback
|
||||
from ch.psi.pshell.serial import TcpDevice
|
||||
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")
|
||||
###################################################################################################
|
||||
# Deployment specific global definitions - executed after startup.py
|
||||
###################################################################################################
|
||||
import traceback
|
||||
from ch.psi.pshell.serial import TcpDevice
|
||||
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")
|
||||
run("data/reports")
|
||||
|
||||
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Configuration
|
||||
###################################################################################################
|
||||
|
||||
IMAGING_ENABLED_PREFERENCE = "imaging_enabled"
|
||||
PUCK_TYPES_PREFERENCE = "puck_types"
|
||||
BARCODE_READER_SCAN_PUCKS = "barcode_reader_scan_pucks"
|
||||
ROOM_TEMPERATURE_ENABLED_PREFERENCE = "room_temperature_enabled"
|
||||
BEAMLINE_STATUS_ENABLED_PREFERENCE = "beamline_status_enabled"
|
||||
VALVE_CONTROL_ENABLED_PREFERENCE = "valve_control"
|
||||
|
||||
def is_imaging_enabled():
|
||||
setting = get_setting(IMAGING_ENABLED_PREFERENCE)
|
||||
return not (str(setting).lower() == 'false')
|
||||
|
||||
def set_imaging_enabled(value):
|
||||
set_setting(IMAGING_ENABLED_PREFERENCE, (True if value else False) )
|
||||
|
||||
def assert_imaging_enabled():
|
||||
if is_imaging_enabled() == False:
|
||||
raise Exception ("Imaging is disabled")
|
||||
|
||||
#"unipuck", "minispine" or "mixed"
|
||||
def set_puck_types(value):
|
||||
set_setting(PUCK_TYPES_PREFERENCE, True if value else False )
|
||||
|
||||
def get_puck_types():
|
||||
setting = get_setting(PUCK_TYPES_PREFERENCE)
|
||||
if setting == "unipuck" or setting == "minispine":
|
||||
return setting
|
||||
return "mixed"
|
||||
|
||||
|
||||
def is_barcode_reader_scan_pucks():
|
||||
setting = get_setting(BARCODE_READER_SCAN_PUCKS)
|
||||
return False if setting is None else setting.lower() == "true"
|
||||
|
||||
def set_barcode_reader_scan_pucks(value):
|
||||
set_setting(BARCODE_READER_SCAN_PUCKS, True if value else False )
|
||||
|
||||
def is_valve_controlled():
|
||||
setting = get_setting(VALVE_CONTROL_ENABLED_PREFERENCE)
|
||||
return False if setting is None else setting.lower() == "true"
|
||||
|
||||
def set_valve_controlled(value):
|
||||
set_setting(VALVE_CONTROL_ENABLED_PREFERENCE, True if value else False )
|
||||
|
||||
def reset_mounted_sample_position():
|
||||
set_setting("mounted_sample_position", None)
|
||||
|
||||
|
||||
def get_puck_barcode_reader():
|
||||
if is_barcode_reader_scan_pucks():
|
||||
return barcode_reader
|
||||
else:
|
||||
return barcode_reader_puck
|
||||
|
||||
#In order to apply current config
|
||||
set_imaging_enabled(is_imaging_enabled())
|
||||
set_puck_types(get_puck_types())
|
||||
set_barcode_reader_scan_pucks(is_barcode_reader_scan_pucks())
|
||||
set_valve_controlled(is_valve_controlled())
|
||||
|
||||
|
||||
force_dry_mount_count = get_setting("force_dry_mount_count")
|
||||
if force_dry_mount_count is None:
|
||||
set_setting("force_dry_mount_count", 0)
|
||||
|
||||
force_dry_timeout = get_setting("force_dry_timeout")
|
||||
if force_dry_timeout is None:
|
||||
set_setting("force_dry_timeout", 0)
|
||||
|
||||
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Configuration
|
||||
###################################################################################################
|
||||
|
||||
IMAGING_ENABLED_PREFERENCE = "imaging_enabled"
|
||||
PUCK_TYPES_PREFERENCE = "puck_types"
|
||||
BARCODE_READER_SCAN_PUCKS = "barcode_reader_scan_pucks"
|
||||
ROOM_TEMPERATURE_ENABLED_PREFERENCE = "room_temperature_enabled"
|
||||
BEAMLINE_STATUS_ENABLED_PREFERENCE = "beamline_status_enabled"
|
||||
VALVE_CONTROL_ENABLED_PREFERENCE = "valve_control"
|
||||
|
||||
def is_imaging_enabled():
|
||||
setting = get_setting(IMAGING_ENABLED_PREFERENCE)
|
||||
return not (str(setting).lower() == 'false')
|
||||
|
||||
def set_imaging_enabled(value):
|
||||
set_setting(IMAGING_ENABLED_PREFERENCE, (True if value else False) )
|
||||
|
||||
def assert_imaging_enabled():
|
||||
if is_imaging_enabled() == False:
|
||||
raise Exception ("Imaging is disabled")
|
||||
|
||||
#"unipuck", "minispine" or "mixed"
|
||||
def set_puck_types(value):
|
||||
set_setting(PUCK_TYPES_PREFERENCE, True if value else False )
|
||||
|
||||
def get_puck_types():
|
||||
setting = get_setting(PUCK_TYPES_PREFERENCE)
|
||||
if setting == "unipuck" or setting == "minispine":
|
||||
return setting
|
||||
return "mixed"
|
||||
|
||||
|
||||
def is_barcode_reader_scan_pucks():
|
||||
setting = get_setting(BARCODE_READER_SCAN_PUCKS)
|
||||
return False if setting is None else setting.lower() == "true"
|
||||
|
||||
def set_barcode_reader_scan_pucks(value):
|
||||
set_setting(BARCODE_READER_SCAN_PUCKS, True if value else False )
|
||||
|
||||
def is_valve_controlled():
|
||||
setting = get_setting(VALVE_CONTROL_ENABLED_PREFERENCE)
|
||||
return False if setting is None else setting.lower() == "true"
|
||||
|
||||
def set_valve_controlled(value):
|
||||
set_setting(VALVE_CONTROL_ENABLED_PREFERENCE, True if value else False )
|
||||
|
||||
def reset_mounted_sample_position():
|
||||
set_setting("mounted_sample_position", None)
|
||||
|
||||
|
||||
def get_puck_barcode_reader():
|
||||
if is_barcode_reader_scan_pucks():
|
||||
return barcode_reader
|
||||
else:
|
||||
return barcode_reader_puck
|
||||
|
||||
#In order to apply current config
|
||||
set_imaging_enabled(is_imaging_enabled())
|
||||
set_puck_types(get_puck_types())
|
||||
set_barcode_reader_scan_pucks(is_barcode_reader_scan_pucks())
|
||||
set_valve_controlled(is_valve_controlled())
|
||||
|
||||
|
||||
force_dry_mount_count = get_setting("force_dry_mount_count")
|
||||
if force_dry_mount_count is None:
|
||||
set_setting("force_dry_mount_count", 0)
|
||||
|
||||
force_dry_timeout = get_setting("force_dry_timeout")
|
||||
if force_dry_timeout is None:
|
||||
set_setting("force_dry_timeout", 0)
|
||||
|
||||
|
||||
cold_position_timeout = get_setting("cold_position_timeout")
|
||||
if cold_position_timeout is None:
|
||||
set_setting("cold_position_timeout", 0)
|
||||
|
||||
|
||||
def is_room_temperature_enabled():
|
||||
setting = get_setting(ROOM_TEMPERATURE_ENABLED_PREFERENCE)
|
||||
return str(setting).lower() == 'true'
|
||||
|
||||
set_setting(ROOM_TEMPERATURE_ENABLED_PREFERENCE, is_room_temperature_enabled())
|
||||
|
||||
|
||||
def is_beamline_status_enabled():
|
||||
setting = get_setting(BEAMLINE_STATUS_ENABLED_PREFERENCE)
|
||||
return str(setting).lower() == 'true'
|
||||
|
||||
set_setting(BEAMLINE_STATUS_ENABLED_PREFERENCE, is_beamline_status_enabled())
|
||||
|
||||
###################################################################################################
|
||||
# Scripted devices and pseudo-devices
|
||||
###################################################################################################
|
||||
|
||||
for script in ["devices/RobotSC", "devices/Wago", "devices/BarcodeReader", "devices/LaserDistance", \
|
||||
"devices/LedCtrl", "devices/SmartMagnet", "devices/HexiPosi", "devices/Gonio"]:
|
||||
try:
|
||||
run(script)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
#if is_imaging_enabled():
|
||||
if get_device("img") is not None:
|
||||
add_device(img.getContrast(), force = True)
|
||||
add_device(img.getCamera(), force = True)
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Utility modules
|
||||
###################################################################################################
|
||||
|
||||
run("data/samples")
|
||||
run("data/pucks")
|
||||
run("motion/tools")
|
||||
run("motion/mount")
|
||||
run("motion/unmount")
|
||||
run("motion/get_dewar")
|
||||
run("motion/put_dewar")
|
||||
run("motion/get_gonio")
|
||||
run("motion/put_gonio")
|
||||
run("motion/move_dewar")
|
||||
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/move_aux")
|
||||
run("motion/get_aux")
|
||||
run("motion/put_aux")
|
||||
run("motion/dry")
|
||||
run("motion/trash")
|
||||
run("motion/homing_hexiposi")
|
||||
run("motion/calibrate_tool")
|
||||
run("motion/scan_pin")
|
||||
run("motion/robot_recover")
|
||||
run("motion/recover")
|
||||
run("tools/Math")
|
||||
if is_imaging_enabled():
|
||||
run("imgproc/Utils")
|
||||
|
||||
def system_check(robot_move=True):
|
||||
if not air_pressure_ok.read():
|
||||
raise Exception("Air pressure is not ok")
|
||||
if not n2_pressure_ok.read():
|
||||
raise Exception("N2 pressure is not ok")
|
||||
hexiposi.assert_in_known_position()
|
||||
|
||||
if robot_move:
|
||||
if not feedback_local_safety.read():
|
||||
raise Exception("Local safety not released")
|
||||
auto = not is_manual_mode()
|
||||
if auto:
|
||||
if not feedback_psys_safety.read():
|
||||
raise Exception("Psys safety not released")
|
||||
if not guiding_tool_park.read():
|
||||
raise Exception("Guiding tool not parked")
|
||||
|
||||
def system_check_msg():
|
||||
try:
|
||||
system_check(True)
|
||||
return "Ok"
|
||||
except:
|
||||
return sys.exc_info()[1]
|
||||
|
||||
def get_puck_dev(segment, puck):
|
||||
if type(segment) is int:
|
||||
segment = chr( ord('A') + (segment-1))
|
||||
|
||||
return Controller.getInstance().getPuck(str(segment).upper() + str(puck))
|
||||
|
||||
def get_puck_elect_detection(segment, puck):
|
||||
return str(get_puck_dev(segment, puck).detection)
|
||||
|
||||
def get_puck_img_detection(segment, puck):
|
||||
return str(Controller.getInstance().getPuck(str(segment).upper() + str(puck)).imageDetection)
|
||||
|
||||
def assert_puck_detected(segment, puck):
|
||||
if (segment == AUX_SEGMENT) and (puck == 1):
|
||||
return
|
||||
if get_puck_elect_detection(segment, puck) != "Present":
|
||||
raise Exception ("Puck " + str(segment).upper() + str(puck) + " not present")
|
||||
|
||||
|
||||
def start_puck_detection():
|
||||
run("tools/RestartPuckDetection")
|
||||
|
||||
def check_puck_detection():
|
||||
return run("tools/CheckPuckDetection")
|
||||
|
||||
def stop_puck_detection():
|
||||
run("tools/StopPuckDetection")
|
||||
|
||||
|
||||
|
||||
def get_detected_pucks():
|
||||
ret = []
|
||||
for i in range(30):
|
||||
p = BasePlate.getPucks()[i]
|
||||
if (str(p.getDetection()) == "Present"):
|
||||
ret.append(str(p.getName()))
|
||||
return ret
|
||||
|
||||
def get_pucks_info():
|
||||
ret = []
|
||||
for i in range(30):
|
||||
p = BasePlate.getPucks()[i]
|
||||
name = p.getName()
|
||||
det = str(p.getDetection())
|
||||
barcode = "" if p.getId() is None else p.getId()
|
||||
|
||||
ret.append({"puckAddress": name, "puckState": det, "puckBarcode":barcode})
|
||||
return json.dumps(ret)
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Device initialization
|
||||
###################################################################################################
|
||||
|
||||
try:
|
||||
set_heater(False)
|
||||
set_air_stream(False)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
|
||||
try:
|
||||
release_local_safety.write(False)
|
||||
release_psys_safety.write(False)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
try:
|
||||
hexiposi.polling=500
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
try:
|
||||
robot.setPolling(DEFAULT_ROBOT_POLLING)
|
||||
robot.set_tool(TOOL_DEFAULT)
|
||||
robot.set_frame(FRAME_DEFAULT)
|
||||
robot.set_motors_enabled(True)
|
||||
robot.set_joint_motors_enabled(True)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
if is_imaging_enabled():
|
||||
try:
|
||||
import ch.psi.pshell.device.Camera as Camera
|
||||
#img.camera.setColorMode(Camera.ColorMode.Mono)
|
||||
#img.camera.setDataType(Camera.DataType.UInt8)
|
||||
img.camera.setGrabMode(Camera.GrabMode.Continuous)
|
||||
img.camera.setTriggerMode(Camera.TriggerMode.Fixed_Rate)
|
||||
img.camera.setExposure(25.00)
|
||||
img.camera.setAcquirePeriod(200.00)
|
||||
img.camera.setGain(0.0)
|
||||
#img.camera.setROI(200, 0,1200,1200)
|
||||
"""
|
||||
img.camera.setROI(300, 200,1000,1000)
|
||||
img.config.rotation=17
|
||||
img.config.rotationCrop=True
|
||||
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight = 50,50,900,900
|
||||
"""
|
||||
img.camera.setROI(int(get_setting("roi_x")), int(get_setting("roi_y")), int(get_setting("roi_w")), int(get_setting("roi_h")))
|
||||
|
||||
img.camera.stop()
|
||||
img.camera.start()
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
#TODO: The Smart Magnet keeps moving sample if detecting is enabled
|
||||
# Detection keeps disabled unless during moount/unmount
|
||||
try:
|
||||
smart_magnet.set_supress(True)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
#gripper_cam.paused = True
|
||||
###################################################################################################
|
||||
# Device monitoring
|
||||
###################################################################################################
|
||||
|
||||
DEWAR_LEVEL_RT = 5.0
|
||||
is_room_temperature = False
|
||||
|
||||
def is_room_temp():
|
||||
return is_room_temperature
|
||||
|
||||
|
||||
class DewarLevelListener (DeviceListener):
|
||||
def onValueChanged(self, device, value, former):
|
||||
global is_room_temperature
|
||||
if value is not None:
|
||||
is_room_temperature = value <= DEWAR_LEVEL_RT
|
||||
dewar_level_listener = DewarLevelListener()
|
||||
|
||||
for l in dewar_level.listeners:
|
||||
#if isinstance(l, DewarLevelListener): #Class changes...
|
||||
if Nameable.getShortClassName(l.getClass()) == "DewarLevelListener":
|
||||
dewar_level.removeListener(l)
|
||||
|
||||
dewar_level.addListener(dewar_level_listener)
|
||||
dewar_level_listener.onValueChanged(dewar_level, dewar_level.take(), None)
|
||||
|
||||
|
||||
|
||||
|
||||
class HexiposiListener (DeviceListener):
|
||||
def onValueChanging(self, device, value, former):
|
||||
robot.assert_cleared()
|
||||
|
||||
hexiposi_listener = HexiposiListener()
|
||||
hexiposi.addListener(hexiposi_listener)
|
||||
|
||||
###################################################################################################
|
||||
# Global variables & application state
|
||||
###################################################################################################
|
||||
|
||||
|
||||
context = get_context()
|
||||
|
||||
cover_detection_debug = False
|
||||
|
||||
in_mount_position = False
|
||||
|
||||
|
||||
def assert_mount_position():
|
||||
print "Source: ", get_exec_pars().source
|
||||
if not in_mount_position and get_exec_pars().source == CommandSource.server :
|
||||
raise Exception("Not in mount position")
|
||||
|
||||
|
||||
def is_puck_loading():
|
||||
return robot.state == State.Ready and robot.take()["pos"] == 'pPark' and \
|
||||
feedback_psys_safety.take() == False and \
|
||||
not guiding_tool_park.read()
|
||||
|
||||
def set_pin_offset(val):
|
||||
if abs(val) >5:
|
||||
raise Exception("Invalid pin offset: " + str(val))
|
||||
try:
|
||||
set_setting("pin_offset",float(val))
|
||||
except:
|
||||
log("Error setting pin offset: " + str(sys.exc_info()[1]), False)
|
||||
|
||||
def get_pin_offset():
|
||||
try:
|
||||
ret = float(get_setting("pin_offset"))
|
||||
if abs(ret) >5:
|
||||
raise Exception("Invalid configured pin offset: " + str(ret))
|
||||
return ret
|
||||
except:
|
||||
log("Error getting pin offset: " + str(sys.exc_info()[1]), False)
|
||||
return 0.0
|
||||
|
||||
|
||||
def set_pin_angle_offset(val):
|
||||
if (abs(val) > 180.0) or (abs(val) < -180.0):
|
||||
raise Exception("Invalid pin angle offset: " + str(val))
|
||||
try:
|
||||
set_setting("pin_angle_offset",float(val))
|
||||
except:
|
||||
log("Error setting pin angle offset: " + str(sys.exc_info()[1]), False)
|
||||
|
||||
def get_pin_angle_offset():
|
||||
try:
|
||||
ret = float(get_setting("pin_angle_offset"))
|
||||
if (abs(ret) > 180.0) or (abs(ret) < -180.0):
|
||||
raise Exception("Invalid configured pin angle offset: " + str(ret))
|
||||
return ret
|
||||
except:
|
||||
log("Error getting pin angle offset: " + str(sys.exc_info()[1]), False)
|
||||
return 0.0
|
||||
|
||||
def is_force_dry():
|
||||
try:
|
||||
dry_mount_counter = int(get_setting("dry_mount_counter"))
|
||||
except:
|
||||
dry_mount_counter = 0
|
||||
|
||||
try:
|
||||
dry_timespan = time.time() - float( get_setting("dry_timestamp"))
|
||||
except:
|
||||
dry_timespan = 3600
|
||||
|
||||
try:
|
||||
force_dry_mount_count = int(get_setting("force_dry_mount_count"))
|
||||
if force_dry_mount_count>0 and dry_mount_counter>=force_dry_mount_count:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
force_dry_timeout = float(get_setting("force_dry_timeout"))
|
||||
if force_dry_timeout>0 and dry_timespan>=force_dry_timeout:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def is_room_temperature_enabled():
|
||||
setting = get_setting(ROOM_TEMPERATURE_ENABLED_PREFERENCE)
|
||||
return str(setting).lower() == 'true'
|
||||
|
||||
set_setting(ROOM_TEMPERATURE_ENABLED_PREFERENCE, is_room_temperature_enabled())
|
||||
|
||||
|
||||
def is_beamline_status_enabled():
|
||||
setting = get_setting(BEAMLINE_STATUS_ENABLED_PREFERENCE)
|
||||
return str(setting).lower() == 'true'
|
||||
|
||||
set_setting(BEAMLINE_STATUS_ENABLED_PREFERENCE, is_beamline_status_enabled())
|
||||
|
||||
###################################################################################################
|
||||
# Scripted devices and pseudo-devices
|
||||
###################################################################################################
|
||||
|
||||
for script in ["devices/RobotSC", "devices/Wago", "devices/BarcodeReader", "devices/LaserDistance", \
|
||||
"devices/LedCtrl", "devices/SmartMagnet", "devices/HexiPosi", "devices/Gonio"]:
|
||||
try:
|
||||
run(script)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
#if is_imaging_enabled():
|
||||
if get_device("img") is not None:
|
||||
add_device(img.getContrast(), force = True)
|
||||
add_device(img.getCamera(), force = True)
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Utility modules
|
||||
###################################################################################################
|
||||
|
||||
run("data/samples")
|
||||
run("data/pucks")
|
||||
run("motion/tools")
|
||||
run("motion/mount")
|
||||
run("motion/unmount")
|
||||
run("motion/get_dewar")
|
||||
run("motion/put_dewar")
|
||||
run("motion/get_gonio")
|
||||
run("motion/put_gonio")
|
||||
run("motion/move_dewar")
|
||||
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/move_aux")
|
||||
run("motion/get_aux")
|
||||
run("motion/put_aux")
|
||||
run("motion/dry")
|
||||
run("motion/trash")
|
||||
run("motion/homing_hexiposi")
|
||||
run("motion/calibrate_tool")
|
||||
run("motion/scan_pin")
|
||||
run("motion/robot_recover")
|
||||
run("motion/recover")
|
||||
run("tools/Math")
|
||||
if is_imaging_enabled():
|
||||
run("imgproc/Utils")
|
||||
|
||||
def system_check(robot_move=True):
|
||||
if not air_pressure_ok.read():
|
||||
raise Exception("Air pressure is not ok")
|
||||
if not n2_pressure_ok.read():
|
||||
raise Exception("N2 pressure is not ok")
|
||||
hexiposi.assert_in_known_position()
|
||||
|
||||
if robot_move:
|
||||
if not feedback_local_safety.read():
|
||||
raise Exception("Local safety not released")
|
||||
auto = not is_manual_mode()
|
||||
if auto:
|
||||
if not feedback_psys_safety.read():
|
||||
raise Exception("Psys safety not released")
|
||||
if not guiding_tool_park.read():
|
||||
raise Exception("Guiding tool 1 not parked")
|
||||
if not guiding_tool_park_2.read():
|
||||
raise Exception("Guiding tool 2 not parked")
|
||||
|
||||
def system_check_msg():
|
||||
try:
|
||||
system_check(True)
|
||||
return "Ok"
|
||||
except:
|
||||
return sys.exc_info()[1]
|
||||
|
||||
def get_puck_dev(segment, puck):
|
||||
if type(segment) is int:
|
||||
segment = chr( ord('A') + (segment-1))
|
||||
|
||||
return Controller.getInstance().getPuck(str(segment).upper() + str(puck))
|
||||
|
||||
def get_puck_elect_detection(segment, puck):
|
||||
return str(get_puck_dev(segment, puck).detection)
|
||||
|
||||
def get_puck_img_detection(segment, puck):
|
||||
return str(Controller.getInstance().getPuck(str(segment).upper() + str(puck)).imageDetection)
|
||||
|
||||
def assert_puck_detected(segment, puck):
|
||||
if (segment == AUX_SEGMENT) and (puck == 1):
|
||||
return
|
||||
if get_puck_elect_detection(segment, puck) != "Present":
|
||||
raise Exception ("Puck " + str(segment).upper() + str(puck) + " not present")
|
||||
|
||||
|
||||
def start_puck_detection():
|
||||
run("tools/RestartPuckDetection")
|
||||
|
||||
def check_puck_detection():
|
||||
return run("tools/CheckPuckDetection")
|
||||
|
||||
def stop_puck_detection():
|
||||
run("tools/StopPuckDetection")
|
||||
|
||||
|
||||
|
||||
def get_detected_pucks():
|
||||
ret = []
|
||||
for i in range(30):
|
||||
p = BasePlate.getPucks()[i]
|
||||
if (str(p.getDetection()) == "Present"):
|
||||
ret.append(str(p.getName()))
|
||||
return ret
|
||||
|
||||
def get_pucks_info():
|
||||
ret = []
|
||||
for i in range(30):
|
||||
p = BasePlate.getPucks()[i]
|
||||
name = p.getName()
|
||||
det = str(p.getDetection())
|
||||
barcode = "" if p.getId() is None else p.getId()
|
||||
|
||||
ret.append({"puckAddress": name, "puckState": det, "puckBarcode":barcode})
|
||||
return json.dumps(ret)
|
||||
|
||||
|
||||
###################################################################################################
|
||||
# Device initialization
|
||||
###################################################################################################
|
||||
|
||||
try:
|
||||
set_heater(False)
|
||||
set_air_stream(False)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
|
||||
try:
|
||||
release_local_safety.write(False)
|
||||
release_psys_safety.write(False)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
try:
|
||||
hexiposi.polling=500
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
try:
|
||||
robot.setPolling(DEFAULT_ROBOT_POLLING)
|
||||
robot.set_tool(TOOL_DEFAULT)
|
||||
robot.set_frame(FRAME_DEFAULT)
|
||||
robot.set_motors_enabled(True)
|
||||
robot.set_joint_motors_enabled(True)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
if is_imaging_enabled():
|
||||
try:
|
||||
import ch.psi.pshell.device.Camera as Camera
|
||||
#img.camera.setColorMode(Camera.ColorMode.Mono)
|
||||
#img.camera.setDataType(Camera.DataType.UInt8)
|
||||
img.camera.setGrabMode(Camera.GrabMode.Continuous)
|
||||
img.camera.setTriggerMode(Camera.TriggerMode.Fixed_Rate)
|
||||
img.camera.setExposure(25.00)
|
||||
img.camera.setAcquirePeriod(200.00)
|
||||
img.camera.setGain(0.0)
|
||||
#img.camera.setROI(200, 0,1200,1200)
|
||||
"""
|
||||
img.camera.setROI(300, 200,1000,1000)
|
||||
img.config.rotation=17
|
||||
img.config.rotationCrop=True
|
||||
img.config.roiX,img.config.roiY, img.config.roiWidth,img.config.roiHeight = 50,50,900,900
|
||||
"""
|
||||
img.camera.setROI(int(get_setting("roi_x")), int(get_setting("roi_y")), int(get_setting("roi_w")), int(get_setting("roi_h")))
|
||||
|
||||
img.camera.stop()
|
||||
img.camera.start()
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
#TODO: The Smart Magnet keeps moving sample if detecting is enabled
|
||||
# Detection keeps disabled unless during moount/unmount
|
||||
try:
|
||||
smart_magnet.set_supress(True)
|
||||
except:
|
||||
print >> sys.stderr, traceback.format_exc()
|
||||
|
||||
#gripper_cam.paused = True
|
||||
###################################################################################################
|
||||
# Device monitoring
|
||||
###################################################################################################
|
||||
|
||||
DEWAR_LEVEL_RT = 5.0
|
||||
is_room_temperature = False
|
||||
|
||||
def is_room_temp():
|
||||
return is_room_temperature
|
||||
|
||||
|
||||
class DewarLevelListener (DeviceListener):
|
||||
def onValueChanged(self, device, value, former):
|
||||
global is_room_temperature
|
||||
if value is not None:
|
||||
is_room_temperature = value <= DEWAR_LEVEL_RT
|
||||
dewar_level_listener = DewarLevelListener()
|
||||
|
||||
for l in dewar_level.listeners:
|
||||
#if isinstance(l, DewarLevelListener): #Class changes...
|
||||
if Nameable.getShortClassName(l.getClass()) == "DewarLevelListener":
|
||||
dewar_level.removeListener(l)
|
||||
|
||||
dewar_level.addListener(dewar_level_listener)
|
||||
dewar_level_listener.onValueChanged(dewar_level, dewar_level.take(), None)
|
||||
|
||||
|
||||
|
||||
|
||||
class HexiposiListener (DeviceListener):
|
||||
def onValueChanging(self, device, value, former):
|
||||
robot.assert_cleared()
|
||||
|
||||
hexiposi_listener = HexiposiListener()
|
||||
hexiposi.addListener(hexiposi_listener)
|
||||
|
||||
###################################################################################################
|
||||
# Global variables & application state
|
||||
###################################################################################################
|
||||
|
||||
|
||||
context = get_context()
|
||||
|
||||
cover_detection_debug = False
|
||||
|
||||
in_mount_position = False
|
||||
|
||||
|
||||
def assert_mount_position():
|
||||
print "Source: ", get_exec_pars().source
|
||||
if not in_mount_position and get_exec_pars().source == CommandSource.server :
|
||||
raise Exception("Not in mount position")
|
||||
|
||||
|
||||
def is_puck_loading():
|
||||
guiding_tools_parked = guiding_tool_park.read() and guiding_tool_park_2.read()
|
||||
return robot.state == State.Ready and robot.take()["pos"] == 'pPark' and \
|
||||
feedback_psys_safety.take() == False and \
|
||||
not guiding_tools_parked
|
||||
|
||||
def set_pin_offset(val):
|
||||
if abs(val) >5:
|
||||
raise Exception("Invalid pin offset: " + str(val))
|
||||
try:
|
||||
set_setting("pin_offset",float(val))
|
||||
except:
|
||||
log("Error setting pin offset: " + str(sys.exc_info()[1]), False)
|
||||
|
||||
def get_pin_offset():
|
||||
try:
|
||||
ret = float(get_setting("pin_offset"))
|
||||
if abs(ret) >5:
|
||||
raise Exception("Invalid configured pin offset: " + str(ret))
|
||||
return ret
|
||||
except:
|
||||
log("Error getting pin offset: " + str(sys.exc_info()[1]), False)
|
||||
return 0.0
|
||||
|
||||
|
||||
def set_pin_angle_offset(val):
|
||||
if (abs(val) > 180.0) or (abs(val) < -180.0):
|
||||
raise Exception("Invalid pin angle offset: " + str(val))
|
||||
try:
|
||||
set_setting("pin_angle_offset",float(val))
|
||||
except:
|
||||
log("Error setting pin angle offset: " + str(sys.exc_info()[1]), False)
|
||||
|
||||
def get_pin_angle_offset():
|
||||
try:
|
||||
ret = float(get_setting("pin_angle_offset"))
|
||||
if (abs(ret) > 180.0) or (abs(ret) < -180.0):
|
||||
raise Exception("Invalid configured pin angle offset: " + str(ret))
|
||||
return ret
|
||||
except:
|
||||
log("Error getting pin angle offset: " + str(sys.exc_info()[1]), False)
|
||||
return 0.0
|
||||
|
||||
def is_force_dry():
|
||||
try:
|
||||
dry_mount_counter = int(get_setting("dry_mount_counter"))
|
||||
except:
|
||||
dry_mount_counter = 0
|
||||
|
||||
try:
|
||||
dry_timespan = time.time() - float( get_setting("dry_timestamp"))
|
||||
except:
|
||||
dry_timespan = 3600
|
||||
|
||||
try:
|
||||
force_dry_mount_count = int(get_setting("force_dry_mount_count"))
|
||||
if force_dry_mount_count>0 and dry_mount_counter>=force_dry_mount_count:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
force_dry_timeout = float(get_setting("force_dry_timeout"))
|
||||
if force_dry_timeout>0 and dry_timespan>=force_dry_timeout:
|
||||
return True
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
|
||||
def onPuckLoadingChange(puck_loading):
|
||||
set_led_state(puck_loading)
|
||||
#pass
|
||||
|
||||
update()
|
||||
add_device(Controller.getInstance().basePlate, True)
|
||||
restore_samples_info()
|
||||
|
||||
|
||||
print "Initialization complete"
|
||||
#pass
|
||||
|
||||
update()
|
||||
add_device(Controller.getInstance().basePlate, True)
|
||||
restore_samples_info()
|
||||
|
||||
|
||||
print "Initialization complete"
|
||||
|
||||
+7
-28
@@ -62,21 +62,11 @@ def mount(segment, puck, sample, force=False, read_dm=False, auto_unmount=False)
|
||||
assert_mount_position()
|
||||
do_unmount = False
|
||||
print "%4.1f s asserted " % (tg() - t1,)
|
||||
|
||||
# detect sample before moving to cold
|
||||
if smart_magnet.get_supress() == True:
|
||||
smart_magnet.set_supress(False)
|
||||
time.sleep(0.2)
|
||||
sample_det = smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0)
|
||||
Controller.getInstance().logEvent("Sample Detection", str(sample_det))
|
||||
|
||||
print "%4.1f s SMC checked" % (tg() - t1,)
|
||||
|
||||
|
||||
|
||||
mounting_in_same_segment = False
|
||||
|
||||
|
||||
try:
|
||||
if sample_det == True:
|
||||
if previous_mounted is not None:
|
||||
if was_warm and previous_segment in COLD_SEGMENTS:
|
||||
print " was warm previous %s %s %s" % (previous_segment, COLD_SEGMENTS, previous_mounted)
|
||||
robot.move_cold()
|
||||
@@ -91,9 +81,6 @@ def mount(segment, puck, sample, force=False, read_dm=False, auto_unmount=False)
|
||||
print "%4.1f s ....done" % (tg() - t1,)
|
||||
|
||||
do_unmount = True
|
||||
if sample_det == True:
|
||||
raise Exception("Pin detected on gonio")
|
||||
|
||||
|
||||
if is_normal and not robot.is_cold():
|
||||
print "mount():83 needs_chilling"
|
||||
@@ -130,7 +117,7 @@ def mount(segment, puck, sample, force=False, read_dm=False, auto_unmount=False)
|
||||
if (not robot.is_dewar()) and (not mounting_in_same_segment):
|
||||
robot.move_dewar()
|
||||
print "%4.1f s get_dewar" % (tg() - t1,)
|
||||
robot.get_dewar(segment, puck, sample, mounting_in_same_segment=mounting_in_same_segment)
|
||||
robot.get_dewar(segment, puck, sample)
|
||||
|
||||
|
||||
if read_dm:
|
||||
@@ -192,22 +179,14 @@ def mount(segment, puck, sample, force=False, read_dm=False, auto_unmount=False)
|
||||
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 == False:
|
||||
raise Exception("No pin detected on gonio")
|
||||
update_samples_info_sample_mount(get_puck_name(segment, puck), sample, True, mount_sample_id)
|
||||
|
||||
|
||||
if is_force_dry():
|
||||
smart_magnet.set_default_current()
|
||||
print "%4.1f Auto dry async" % (tg() - t1,)
|
||||
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]
|
||||
return [True, mount_sample_id]
|
||||
finally:
|
||||
print "%4.1f s magnet suppress/default current" % (tg() - t1,)
|
||||
smart_magnet.set_default_current()
|
||||
smart_magnet.set_supress(True)
|
||||
pass
|
||||
@@ -55,20 +55,6 @@ def unmount(segment = None, puck = None, sample = None, force=False, auto_unmoun
|
||||
Controller.getInstance().logEvent("Unmount Sample", str(segment) + str(puck) + str(sample))
|
||||
|
||||
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:
|
||||
@@ -87,8 +73,6 @@ def unmount(segment = None, puck = None, sample = None, force=False, auto_unmoun
|
||||
|
||||
if not robot.is_gonio():
|
||||
robot.move_gonio()
|
||||
|
||||
#smart_magnet.set_unmount_current()
|
||||
|
||||
curpos = cryopos.getPosition()
|
||||
speed = cryopos.getSpeed() / 1000.
|
||||
@@ -98,11 +82,6 @@ def unmount(segment = None, puck = None, sample = None, force=False, auto_unmoun
|
||||
|
||||
robot.get_gonio()
|
||||
|
||||
smart_magnet.apply_reverse()
|
||||
smart_magnet.apply_resting()
|
||||
mount_sample_detected = smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0)
|
||||
Controller.getInstance().logEvent("Sample Detection", str(mount_sample_detected))
|
||||
|
||||
if is_aux:
|
||||
robot.move_aux()
|
||||
robot.put_aux(sample)
|
||||
@@ -115,8 +94,6 @@ def unmount(segment = None, puck = None, sample = None, force=False, auto_unmoun
|
||||
robot.put_dewar(segment, puck, sample)
|
||||
|
||||
set_setting("mounted_sample_position", None)
|
||||
return mount_sample_detected
|
||||
return False
|
||||
finally:
|
||||
if not auto_unmount:
|
||||
smart_magnet.set_default_current()
|
||||
smart_magnet.set_supress(True)
|
||||
pass
|
||||
Reference in New Issue
Block a user