This commit is contained in:
gac-S_Changer
2018-06-22 11:09:37 +02:00
parent da06e0af71
commit 51858eb819
32 changed files with 621 additions and 43 deletions

View File

@@ -1,11 +1,48 @@
def enable_barcode_reader():
microscan_cmd.write("<H>")
def disable_barcode_reader():
microscan_cmd.write("<I>")
def read_barcode(timeout):
try:
return microscan.waitString(int(timeout * 1000))
except:
return None
class BarcodeReader(DeviceBase):
def doInitialize(self):
self.disable()
def enable(self):
microscan_cmd.write("<H>")
self.setState(State.Ready)
def disable(self):
microscan_cmd.write("<I>")
self.setState(State.Disabled)
def get(self,timeout=1.0):
self.state.assertReady()
try:
self.setState(State.Busy)
ret = microscan.waitString(int(timeout * 1000))
self.setCache(ret, None)
return ret
except:
self.setCache(None, None)
return None
finally:
self.setState(State.Ready)
def doUpdate(self):
self.get()
def read(self,timeout=1.0):
initial = self.state
if initial == State.Disabled:
self.enable()
try:
return self.get()
finally:
if initial == State.Disabled:
self.disable()
add_device(BarcodeReader("barcode_reader"), force = True)

View File

@@ -48,6 +48,12 @@ class Hexiposi(DiscretePositionerBase):
self.rback = rback
return self.status
def set_deadband(self, value = 0.1): #degrees
ret = self.get_response(requests.get(url=self.url+"setDeadband?deadband=" + str(value), timeout=self.timeout))
if ret["deadbandOutput"] == value:
return value
raise Excepiton("Error setting deadband: " + str(ret))
def move_pos(self, pos):
return self.get_response(requests.get(url=self.url+"set?pos=" + str(pos), timeout=self.timeout))

View File

@@ -0,0 +1,107 @@
class SmartMagnet(DeviceBase):
def __init__(self, name):
#DeviceBase.__init__(self, name, get_context().pluginManager.getDynamicClass("SmartMagnetConfig")())
DeviceBase.__init__(self, name, DeviceConfig({
"holdingCurrent":0.0,
"restingCurrent":0.0,
"mountCurrent":0.0,
"unmountCurrent":0.0,
"remanenceCurrent":0.0,
}))
def doInitialize(self):
DeviceBase.doInitialize(self)
self.get_current()
def set_current(self, current):
self.setCache(current, None)
smc_current.write(current)
def get_current(self):
cur = smc_current.read()
self.setCache(cur, None)
return cur
def get_current_rb(self):
self.assert_status()
return smc_current_rb.read()
def get_status(self):
return smc_magnet_status.read()
def assert_status(self):
if self.get_status() == False:
raise Exception("Smart Magnet is in faulty status.")
def is_mounted(self):
self.assert_status()
m1 = smc_mounted_1.read()
m2 = smc_mounted_2.read()
if m2==m1:
raise Exception("Smart Magnet has invalid detection.")
return m2
def set_supress(self, value):
smc_sup_det.write(value)
def get_supress(self):
return smc_sup_det.read()
def check_mounted(self, idle_time =1.0, timeout = -1):
self.assert_status()
start = time.time()
last = None
while True:
try:
det = self.is_mounted()
except:
det = None
if det != last:
settling_timestamp = time.time()
last = det
else:
if det is not None:
if (time.time()-settling_timestamp > idle_time):
return det
if timeout >= 0:
if (time.time() - start) > timeout:
raise Exception("Timeout waiting for Smart Magnet detection.")
time.sleep(0.01)
def doUpdate(self):
try:
if self.is_mounted():
self.setState(State.Busy)
else:
self.setState(State.Ready)
except:
self.setState(State.Fault)
def set_holding_current(self):
self.set_current(self.config.getFieldValue("holdingCurrent"))
def set_resting_current(self):
self.set_current(self.config.getFieldValue("restingCurrent"))
def set_mount_current(self):
self.set_current(self.config.getFieldValue("mountCurrent"))
def set_unmount_current(self):
self.set_current(self.config.getFieldValue("unmountCurrent"))
def set_remanence_current(self):
self.set_current(self.config.getFieldValue("remanenceCurrent"))
def set_default_current():
if self.is_mounted():
self.set_holding_current()
else:
self.set_resting_current()
add_device(SmartMagnet("smart_magnet"), force = True)
smart_magnet.polling = 1000
smart_magnet.set_default_current()

View File

@@ -14,7 +14,7 @@ run("setup/Layout")
###################################################################################################
for script in ["devices/RobotSC", "devices/Wago", "devices/BarcodeReader", "devices/LaserDistance", \
"devices/LedCtrl", "devices/HexiPosi"]:
"devices/LedCtrl", "devices/SmartMagnet", "devices/HexiPosi"]:
try:
run(script)
except:

View File

@@ -11,6 +11,10 @@ def mount(segment, puck, sample, force=False):
robot.assert_cleared()
#robot.assert_in_known_point()
hexiposi.assert_homed()
if smart_magnet.check_mounted(idle_time=0.25, timeout = 1.0) == True:
raise Exception("Pin detected on gonio")
#location = robot.get_current_point()
#Enabling
@@ -26,5 +30,12 @@ def mount(segment, puck, sample, force=False):
robot.get_dewar(segment, puck, sample)
robot.move_gonio()
robot.put_gonio()
robot.move_dewar()
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:
raise Exception("No pin detected on gonio")
finally:
smart_magnet.set_default_current()