def atScanEnd(self): '''clean up after scan finished successfully: stop rocking motion thread''' ScannableMotionBase.atScanEnd() self.runThread = False #self.thread.interrupt() self.thread = None self.pd.stop()
def atScanEnd(self): '''clean up after scan finished successfully: stop rocking motion thread''' ScannableMotionBase.atScanEnd() self.runThread=False #self.thread.interrupt() self.thread=None self.pd.stop()
class ContinuouslyRockingScannable(ScannableMotionBase): def __init__(self, name, scannable): self.scannable=ScannableMotionBase() self.setName(name) assert len(scannable.getInputNames())==1 assert len(scannable.getExtraNames())==0 assert len(scannable.getOutputFormat())==1 self.setInputNames(["centre", "delta"]) self.setExtraNames(["rocks"]) self.setOutputFormat([scannable.getOutputFormat()[0], "%3.3f", "%d"]) self.scannable = scannable self.setLevel(5) self.rockCount = 0 self.thread=None self.runningAtStart = False self.verbose=True def atScanStart(self): if self.thread and self.thread.running: self.runningAtStart = True self.rockCount = 0 def stop(self): if self.thread: self.thread.running=False self.scannable.stop() def atScanEnd(self): if not self.runningAtStart: self.stop() self.thread.join() self.scannable.moveTo(self.thread.centre) def getPosition(self): if self.thread and self.thread.running: return [ self.thread.centre, self.thread.delta, self.rockCount ] return [ self.scannable.getPosition(), 0, self.rockCount ] def asynchronousMoveTo(self, position): assert(len(position)==2) if self.thread and self.thread.running: if (abs(self.thread.centre-position[0]) < 0.00001 and abs(self.thread.delta-position[1]) < 0.00001): simpleLog(self.name + ": New positions same as old.") return self.stop() self.thread.join() self.thread=RockerThread(self.name, self.scannable, position[0], position[1], self.rockCount, self) simpleLog(self.name + ": Starting RockerThread...") self.thread.start() def isBusy(self): return False
def __init__(self, name, followed_scannable, follower_scannable): self.logger = LoggerFactory.getLogger("FollowerScannable:%s" % name) self.followed_scannable = ScannableMotionBase() self.follower_scannable = ScannableMotionBase() assert len(followed_scannable.getInputNames()) == 1 and len( followed_scannable.getExtraNames()) == 0 and len( followed_scannable.getOutputFormat()) == 1 #assert len(follower_scannable.getInputNames())==1 and len(follower_scannable.getExtraNames())==0 and len(follower_scannable.getOutputFormat())==1 assert (issubclass(type(follower_scannable), EnergyScannableBase)) assert (issubclass(type(followed_scannable), ScannableMotor)) self.followed_scannable = followed_scannable self.follower_scannable = follower_scannable self.follower_tolerance = 0 self.setName(name) self.inputNames = [name] self.extraNames = self.getExtraNames() self.outputFormat = self.getOutputFormat() self.setLevel(5) self.thread = None self.verbose = True
def __init__(self, name, scannable): self.scannable=ScannableMotionBase() self.setName(name) assert len(scannable.getInputNames())==1 assert len(scannable.getExtraNames())==0 assert len(scannable.getOutputFormat())==1 self.setInputNames(["centre", "delta"]) self.setExtraNames(["rocks"]) self.setOutputFormat([scannable.getOutputFormat()[0], "%3.3f", "%d"]) self.scannable = scannable self.setLevel(5) self.rockCount = 0 self.thread=None self.runningAtStart = False self.verbose=True
class FollowerScannable(ScannableMotionBase): def __init__(self, name, followed_scannable, follower_scannable): self.logger = LoggerFactory.getLogger("FollowerScannable:%s" % name) self.followed_scannable = ScannableMotionBase() self.follower_scannable = ScannableMotionBase() assert len(followed_scannable.getInputNames()) == 1 and len( followed_scannable.getExtraNames()) == 0 and len( followed_scannable.getOutputFormat()) == 1 #assert len(follower_scannable.getInputNames())==1 and len(follower_scannable.getExtraNames())==0 and len(follower_scannable.getOutputFormat())==1 assert (issubclass(type(follower_scannable), EnergyScannableBase)) assert (issubclass(type(followed_scannable), ScannableMotor)) self.followed_scannable = followed_scannable self.follower_scannable = follower_scannable self.follower_tolerance = 0 self.setName(name) self.inputNames = [name] self.extraNames = self.getExtraNames() self.outputFormat = self.getOutputFormat() self.setLevel(5) self.thread = None self.verbose = True def atScanStart(self): if self.thread and self.thread.running: self.stop() self.thread = FollowerThread(self) self.follower_tolerance = -1 self.thread.start() self.logger.info( "%s now following %s with a tolerance of %r ..." % (self.follower_scannable.name, self.followed_scannable.name, self.follower_tolerance)) def stop(self): if self.thread and self.thread.running: self.logger.info("FollowerThread running, stopping thread...") self.thread.running = False self.follower_scannable.stop() self.thread.join() self.logger.info("...FollowerThread stopped.") else: self.logger.info("FollowerThread %r not running." % self.thread) def atScanEnd(self): self.stop() self.thread.join() #self.follower_scannable.moveTo(self.thread.centre) def getExtraNames(self): return list(self.follower_scannable.getInputNames()) + list( self.follower_scannable.getExtraNames()) def getOutputFormat(self): return ['%f'] + list(self.follower_scannable.getOutputFormat()) def getPosition(self): follower = self.follower_scannable.getPosition() return [self.follower_tolerance] + list(follower) def asynchronousMoveTo(self, position): self.follower_tolerance = position if position == 0: self.stop() elif self.thread and self.thread.running: self.logger.info( "%s following %s now with a tolerance of %r ..." % (self.follower_scannable.name, self.followed_scannable.name, self.follower_tolerance)) else: self.thread = FollowerThread(self) self.thread.start() self.logger.info( "%s now following %s with a tolerance of %r ..." % (self.follower_scannable.name, self.followed_scannable.name, self.follower_tolerance)) def isBusy(self): # If we have started the follower and we are before the first point in a scan then we are busy if the followed scannable is busy # This allows the scan mechanism to sync the move to the start positions for both follower and followed scannables. if self.thread and self.thread.running and self.follower_tolerance < 0: return self.followed_scannable.isBusy( ) and self.follower_scannable.isBusy() return False
def getUpperGdaLimits(self): return ScannableMotionBase.getUpperGdaLimits()
def setUpperGdaLimits(self, upperlimit): ScannableMotionBase.setUpperGdaLimits(upperlimit)
def setLowerGdaLimits(self, lowerlimit): ScannableMotionBase.setLowerGdaLimits(lowerlimit)
def atScanStart(self): '''prepare to start scan: start rocking motion thread''' ScannableMotionBase.atScanStart() self.thread = Thread(self, "Thread: " + self.getName()) self.runThread = True self.thread.start()
def atScanStart(self): '''prepare to start scan: start rocking motion thread''' ScannableMotionBase.atScanStart() self.thread=Thread(self, "Thread: "+self.getName()) self.runThread=True self.thread.start()