160 lines
4.9 KiB
Python
160 lines
4.9 KiB
Python
###################################################################################################
|
|
# 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
|
|
|
|
|
|
run("setup/Layout")
|
|
|
|
|
|
###################################################################################################
|
|
# Scripted devices and pseudo-devices
|
|
###################################################################################################
|
|
|
|
for script in ["devices/RobotSC", "devices/Wago", "devices/BarcodeReader", "devices/LaserDistance", \
|
|
"devices/LedCtrl", "devices/SmartMagnet", "devices/HexiPosi"]:
|
|
try:
|
|
run(script)
|
|
except:
|
|
print >> sys.stderr, traceback.format_exc()
|
|
|
|
add_device(img.getContrast(), force = True)
|
|
add_device(img.getCamera(), force = True)
|
|
|
|
|
|
###################################################################################################
|
|
# Utility modules
|
|
###################################################################################################
|
|
|
|
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_scanner")
|
|
run("motion/dry")
|
|
run("motion/homing_hexiposi")
|
|
run("motion/robot_recover")
|
|
run("imgproc/Utils")
|
|
run("tools/Math")
|
|
|
|
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")
|
|
if robot_move:
|
|
if not feedback_local_safety.read():
|
|
raise Exception("Local safety not released")
|
|
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 get_puck_elect_detection(segment, puck):
|
|
return str(Controller.getInstance().getPuck(str(segment).upper() + str(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 get_puck_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")
|
|
|
|
DEWAR_LEVEL_RT = 5.0
|
|
|
|
def is_room_temp():
|
|
return dewar_level.read() <= DEWAR_LEVEL_RT
|
|
|
|
|
|
###################################################################################################
|
|
# 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_CALIBRATION)
|
|
robot.set_motors_enabled(True)
|
|
robot.set_joint_motors_enabled(True)
|
|
except:
|
|
print >> sys.stderr, traceback.format_exc()
|
|
|
|
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(50.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()
|
|
|
|
|
|
#gripper_cam.paused = True
|
|
|
|
###################################################################################################
|
|
# Global variables
|
|
###################################################################################################
|
|
|
|
|
|
context = get_context()
|
|
|
|
cover_detection_debug = False
|
|
|
|
|
|
|
|
update()
|
|
|
|
print "Initialization complete"
|
|
|