diff --git a/config/config.properties b/config/config.properties index bd42d04..0b4b39a 100644 --- a/config/config.properties +++ b/config/config.properties @@ -1,4 +1,4 @@ -#Wed Feb 06 11:13:25 CET 2019 +#Tue Mar 19 08:37:33 CET 2019 autoSaveScanData=true commandExecutionEvents=false createSessionFiles=true @@ -10,6 +10,7 @@ dataScanPreserveTypes=false dataScanReleaseRecords=false dataServerPort=-1 depthDimension=0 +hideServerMessages=true hostName=null instanceName=X06SA logDaysToLive=30 diff --git a/config/devices.properties b/config/devices.properties index d3f0723..5c89c68 100644 --- a/config/devices.properties +++ b/config/devices.properties @@ -1,4 +1,4 @@ -img=ch.psi.pshell.prosilica.Prosilica|204464 "PacketSize=1504;PixelFormat=Mono8;BinningX=1;BinningY=1;RegionX=300;RegionY=200;Width=1000;Height=1000;MulticastEnable=Off"||-200|false +img=ch.psi.pshell.prosilica.Prosilica|204464 "PacketSize=1504;PixelFormat=Mono8;BinningX=1;BinningY=1;RegionX=290;RegionY=130;Width=1000;Height=1000;MulticastEnable=Off"||-200|false gripper_cam=ch.psi.pshell.imaging.MjpegSource|http://axis-accc8ea5e463.psi.ch/axis-cgi/mjpg/video.cgi?camera=1 reopen||-200|false monitoring_cam=ch.psi.pshell.imaging.MjpegSource|http://axis-accc8ea5e463.psi.ch/axis-cgi/mjpg/video.cgi?camera=2 reopen||-200| #top_cam=ch.psi.pshell.imaging.MjpegSource|http://axis-accc8ea5e463.psi.ch/axis-cgi/mjpg/video.cgi?camera=3 true||-200| diff --git a/config/settings.properties b/config/settings.properties index 1f0c014..ec63f39 100644 --- a/config/settings.properties +++ b/config/settings.properties @@ -1,12 +1,17 @@ -#Tue Feb 19 12:07:34 CET 2019 +#Tue Mar 19 08:36:08 CET 2019 barcode_reader_scan_pucks=false beamline_status_enabled=false dry_mount_counter=0 -dry_timestamp=1.550572774662E9 +dry_timestamp=1.552980281686E9 force_dry_mount_count=15 force_dry_timeout=0 imaging_enabled=false led_level=0.0 pin_offset=0.0 puck_types=true +roi_h=1000 +roi_w=1000 +roi_x=286 +roi_y=127 room_temperature_enabled=false +valve_control=false diff --git a/devices/C5.properties b/devices/C5.properties index c4df46c..5df0b2a 100644 --- a/devices/C5.properties +++ b/devices/C5.properties @@ -1,3 +1,3 @@ -#Wed Feb 06 11:02:19 CET 2019 +#Mon Mar 11 10:22:44 CET 2019 detection=Mechanical -disabled=false +disabled=true diff --git a/devices/img.properties b/devices/img.properties index 9dffde8..966291b 100644 --- a/devices/img.properties +++ b/devices/img.properties @@ -1,4 +1,4 @@ -#Wed Sep 12 14:06:31 CEST 2018 +#Tue Mar 12 14:02:05 CET 2019 colormap=Grayscale colormapAutomatic=false colormapMax=18.133 @@ -9,16 +9,16 @@ grayscale=false invert=false rescaleFactor=1.0 rescaleOffset=0.0 -roiHeight=899 -roiWidth=893 -roiX=48 -roiY=45 -rotation=230.05382605006437 +roiHeight=959 +roiWidth=958 +roiX=21 +roiY=20 +rotation=90.09354404670171 rotationCrop=true scale=1.0 -spatialCalOffsetX=-447.0 -spatialCalOffsetY=-450.0 -spatialCalScaleX=0.5262180258614136 -spatialCalScaleY=0.5227145226413789 +spatialCalOffsetX=-479.0 +spatialCalOffsetY=-480.0 +spatialCalScaleX=0.49018322600904013 +spatialCalScaleY=0.489795265579423 spatialCalUnits=mm transpose=false diff --git a/devices/led_ctrl_1.properties b/devices/led_ctrl_1.properties index 6867617..5aed24d 100644 --- a/devices/led_ctrl_1.properties +++ b/devices/led_ctrl_1.properties @@ -1,4 +1,4 @@ -#Wed Feb 13 10:40:48 CET 2019 +#Mon Mar 11 10:54:31 CET 2019 maxValue=1.0 minValue=0.0 offset=0.0 diff --git a/devices/led_ctrl_2.properties b/devices/led_ctrl_2.properties index 6867617..5aed24d 100644 --- a/devices/led_ctrl_2.properties +++ b/devices/led_ctrl_2.properties @@ -1,4 +1,4 @@ -#Wed Feb 13 10:40:48 CET 2019 +#Mon Mar 11 10:54:31 CET 2019 maxValue=1.0 minValue=0.0 offset=0.0 diff --git a/devices/led_ctrl_3.properties b/devices/led_ctrl_3.properties index 6867617..5aed24d 100644 --- a/devices/led_ctrl_3.properties +++ b/devices/led_ctrl_3.properties @@ -1,4 +1,4 @@ -#Wed Feb 13 10:40:48 CET 2019 +#Mon Mar 11 10:54:31 CET 2019 maxValue=1.0 minValue=0.0 offset=0.0 diff --git a/plugins/Commands.java b/plugins/Commands.java index c1f41b5..46bcbbb 100644 --- a/plugins/Commands.java +++ b/plugins/Commands.java @@ -838,12 +838,12 @@ public class Commands extends Panel { private void buttonGetAuxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGetAuxActionPerformed int sample = (Integer) spinnerSample.getValue(); - execute("get_aux('" + sample + ")"); + execute("get_aux('" + sample + "')"); }//GEN-LAST:event_buttonGetAuxActionPerformed private void buttonPutAuxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonPutAuxActionPerformed int sample = (Integer) spinnerSample.getValue(); - execute("put_aux('" + sample + ")"); + execute("put_aux('" + sample + "')"); }//GEN-LAST:event_buttonPutAuxActionPerformed private void checkAuxiliaryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkAuxiliaryActionPerformed diff --git a/plugins/MXSC-1.10.0.jar b/plugins/MXSC-1.10.0.jar index e03fb60..04ee834 100644 Binary files a/plugins/MXSC-1.10.0.jar and b/plugins/MXSC-1.10.0.jar differ diff --git a/plugins/PuckDetectionPanel.form b/plugins/PuckDetectionPanel.form index 550d155..8045142 100644 --- a/plugins/PuckDetectionPanel.form +++ b/plugins/PuckDetectionPanel.form @@ -75,7 +75,7 @@ - + @@ -111,16 +111,18 @@ - + - + + + + + + + + - - - - - diff --git a/plugins/PuckDetectionPanel.java b/plugins/PuckDetectionPanel.java index 1326665..e07dde6 100644 --- a/plugins/PuckDetectionPanel.java +++ b/plugins/PuckDetectionPanel.java @@ -83,7 +83,7 @@ public class PuckDetectionPanel extends DevicePanel { jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Raspberry Pi ")); - buttonPuckDetCheck.setText("Ckeck"); + buttonPuckDetCheck.setText("Check"); buttonPuckDetCheck.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { buttonPuckDetCheckActionPerformed(evt); @@ -200,12 +200,13 @@ public class PuckDetectionPanel extends DevicePanel { jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() - .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addGap(0, 0, Short.MAX_VALUE) + .addComponent(buttonConfigure) + .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap()) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(buttonConfigure) - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) diff --git a/script/imgproc/CameraCalibration.py b/script/imgproc/CameraCalibration.py index 07b123c..a89510d 100644 --- a/script/imgproc/CameraCalibration.py +++ b/script/imgproc/CameraCalibration.py @@ -2,9 +2,10 @@ import ch.psi.pshell.device.Camera as Camera import ch.psi.pshell.imaging.RendererMode as RendererMode import ch.psi.pshell.imaging.Calibration as Calibration from ch.psi.pshell.imaging.Overlays import * +import ch.psi.pshell.imaging.Pen as Pen import ch.psi.utils.swing.SwingUtils as SwingUtils import javax.swing.SwingUtilities as SwingUtilities -from swingutils.threads.swing import callSwing +#from swingutils.threads.swing import callSwing #SIMULATION = ch.psi.pshell.imaging.FileSource """ img.camera.setColorMode(Camera.ColorMode.Mono) @@ -17,7 +18,7 @@ img.camera.setGain(0.0) img.config.rotationCrop=True """ -MOVE_HEXIPOSI = True +MOVE_HEXIPOSI = not is_manual_mode() ROTATION_OFFSET = 180.0 if MOVE_HEXIPOSI: diff --git a/script/local.py b/script/local.py index 738f1ad..5ab54a5 100644 --- a/script/local.py +++ b/script/local.py @@ -1,413 +1,422 @@ ################################################################################################### # 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") - - - -################################################################################################### -# 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" - -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 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()) - - -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) - - - -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 - - -update() -add_device(Controller.getInstance().basePlate, True) -restore_samples_info() - - -print "Initialization complete" +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") + + + +################################################################################################### +# 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) + + + +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 + + +update() +add_device(Controller.getInstance().basePlate, True) +restore_samples_info() + + +print "Initialization complete" \ No newline at end of file diff --git a/script/motion/tools.py b/script/motion/tools.py index 3cb76ef..027f46f 100644 --- a/script/motion/tools.py +++ b/script/motion/tools.py @@ -134,18 +134,18 @@ def assert_valid_address(segment, puck, sample): return if is_string(segment): segment = ord(segment.upper()) - ord('A') +1 - if segment<=0 or segment >6: - raise Exception ("Invalid segment") - if puck<=0 or puck >5: - raise Exception ("Invalid puck") - if sample<=0 or sample >16: - raise Exception ("Invalid sample") + if (segment<=0) or (segment >6): + raise Exception ("Invalid segment: " + str(segment)) + if (puck<=0) or (puck >5): + raise Exception ("Invalid puck: " + str(puck)) + if (sample<=0) or (sample >16): + raise Exception ("Invalid sample: " + str(sample)) if get_puck_dev(segment, puck).isDisabled(): raise Exception ("Puck is disabled") def assert_valid_sample(sample): - if sample<=0 or sample >16: - raise Exception ("Invalid sample") + if (sample<=0) or (sample >16): + raise Exception ("Invalid sample: " + str(sample)) def get_puck_name(segment, puck): try: