def updatingplot(self,
                     sleeptime=.1,
                     figurename="Displacementsensor",
                     noofpoints=50,
                     showpos=True):
        update = True
        pl.ion()
        plt = Plot2D(10, windowtitle='Displacement Sensor')
        plt.set_xlabel('Time')
        plt.set_ylabel('Position / mm')

        val = []
        tt = []
        pos = []

        quit = keypress.KeyPress(esc_key="q")
        while not quit.isq():
            tval = Pv.get(self.pv)
            val.append(tval)
            pos.append(self.poslims[0] + tval *
                       (np.diff(self.voltlims) / np.diff(self.poslims)))
            tt.append(datetime.datetime.now())
            tt = tt[-100:]
            pos = pos[-100:]
            val = val[-100:]
            if showpos:
                plt.setdata(tt, pos)
            else:
                pl.gca().lines[-1].set_ydata(val[-noofpoints:])
                pl.gca().lines[-1].set_xdata(tt[-noofpoints:])
            sleep(sleeptime)
            pl.draw()
Exemple #2
0
def tweak2D(moth,motv,mothstep=0.1,motvstep=0.1,mothname=None,motvname=None,dirh=1,dirv=1):
  if mothname is None:
    mothname = moth.name
  if motvname is None:
    motvname = motv.name
  help_text ="left = moth neg dir; right = moth pos dir; up = motv pos dir, down = motv neg dir\n"
  help_text += "<shift>-down = motv-step/2; <shift>-up = step*2, <shift>-left = moth-step/2; <shift>-right = moth-step*2\n"
  help_text += "s: enter new stepsize\n"
  help_text += 'q = quit'
  print "current position (%s,%s) = (%s,%s)" % (mothname,motvname,moth.wm_string(),motv.wm_string())
  if abs(dirh) != 1 or abs(dirv) != 1:
    raise ValueError("direction needs to be +1 or -1")
  mothstep = float(mothstep)
  motvstep = float(motvstep)
  oldmothstep = 0
  oldmotvstep = 0
  k=keypress.KeyPress()
  while (k.isq() is False):
    if (oldmothstep != mothstep):
      print "%s stepsize: %g" % (mothname, mothstep)
      sys.stdout.flush()
      oldmothstep = mothstep
    if (oldmotvstep != motvstep):
      print "%s stepsize: %g" % (motvname, motvstep)
      sys.stdout.flush()
      oldmotvstep = motvstep
    k.waitkey()
    if ( k.issr() ):
      mothstep = mothstep*2.
    elif ( k.issl() ):
      mothstep = mothstep/2.
    elif ( k.isr() ):
      moth.umvr(mothstep*dirh,show_previous=False)
    elif ( k.isl() ):
      moth.umvr(-mothstep*dirh,show_previous=False)
    elif ( k.issu() ):
      motvstep = motvstep*2.
    elif ( k.issd() ):
      motvstep = motvstep/2.
    elif ( k.isu() ):
      motv.umvr(motvstep*dirv,show_previous=False)
    elif ( k.isd() ):
      motv.umvr(-motvstep*dirv,show_previous=False)
    elif ( k.iskey("s") ):
      v = raw_input("enter step size (one value for both horizontal and vertical)")
      try:
        v = float(v.strip())
        motvstep = v
        mothstep = v
      except:
        print "value cannot be converted to float, exit go to mode ..."
        sys.stdout.flush()
    elif ( k.isq() ):
      break
    else:
      print help_text
 def tweak(self, step=0.1):
     help = "q = exit; up = step*2; down = step/2, left = neg dir, right = pos dir\n"
     help = help + "g = go abs, s = set"
     print "tweaking virtual motor %s " % (self.name)
     print "current position %s" % (self.wm_string())
     step = float(step)
     oldstep = 0
     k = keypress.KeyPress()
     while (k.isq() is False):
         if (oldstep != step):
             print "stepsize: %g" % step
             sys.stdout.flush()
             oldstep = step
         k.waitkey()
         if (k.isu()):
             step = step * 2.
         elif (k.isd()):
             step = step / 2.
         elif (k.isr()):
             self.mvr(step)
             self.wait()
             print self.wm()
         elif (k.isl()):
             self.mvr(-step)
             self.wait()
             print self.wm()
         elif (k.iskey("g")):
             print "enter absolute position (char to abort go to)"
             sys.stdout.flush()
             v = sys.stdin.readline()
             try:
                 v = float(v.strip())
                 self.mv(v)
             except:
                 print "value cannot be converted to float, exit go to mode ..."
                 sys.stdout.flush()
         elif (k.iskey("s")):
             print "enter new set value (char to abort setting)"
             sys.stdout.flush()
             v = sys.stdin.readline()
             try:
                 v = float(v[0:-1])
                 self.set(v)
             except:
                 print "value cannot be converted to float, exit go to mode ..."
                 sys.stdout.flush()
         elif (k.isq()):
             self.stop()
             break
         else:
             print help
     print "final position: %s" % self.wm_string()
Exemple #4
0
def tweak_mvr(motor,step=0.1,direction=1):
  help_text = "q = exit; up = step*2; down = step/2, left = neg dir, right = pos dir\n"
  help_text += "g = go abs, s = set"
  print "tweaking motor %s (pv=%s)" % (motor.name,motor.pvname)
  print "current position %s" % (motor.wm_string())
  if abs(direction) != 1:
    raise ValueError("direction needs to be +1 or -1")
  step = float(step)
  oldstep = 0
  k=keypress.KeyPress()
  while (k.isq() is False):
    if (oldstep != step):
      nstr = "stepsize: %f" % step
      notice(nstr)
      sys.stdout.flush()
      oldstep = step
    k.waitkey()
    if ( k.isu() ):
      step = step*2.
    elif ( k.isd() ):
      step = step/2.
    elif ( k.isr() ):
      motor.umvr(step*direction,show_previous=False)
    elif ( k.isl() ):
      motor.umvr(-step*direction,show_previous=False)
    elif ( k.iskey("g") ):
      print "enter absolute position (char to abort go to)"
      sys.stdout.flush()
      v=sys.stdin.readline()
      try:
        v = float(v.strip())
        motor.umv(v)
      except:
        print "value cannot be converted to float, exit go to mode ..."
        sys.stdout.flush()
    elif ( k.iskey("s") ):
      print "enter new set value (char to abort setting)"
      sys.stdout.flush()
      v=sys.stdin.readline()
      try:
        v = float(v[0:-1])
        motor.set(v)
      except:
        print "value cannot be converted to float, exit go to mode ..."
        sys.stdout.flush()
    elif ( k.isq() ):
      break
    else:
      print help_text
  print "final position: %s" % motor.wm_string()
Exemple #5
0
def tweak_velo(motor,step=0.1):
  help_text = "q = exit; up = step*2; down = step/2, left = neg dir, right = pos dir\n"
  help_text += "g = go abs, s = set"
  print "tweaking motor %s (pv=%s)" % (motor.name,motor.pvname)
  print "current speed %s" % (motor.get_speed())
  step = float(step)
  oldstep = 0
  k=keypress.KeyPress()
  while (k.isq() is False):
    if (oldstep != step):
      notice("stepsize: %f" % step)
      sys.stdout.flush()
      oldstep = step
    k.waitkey()
    if ( k.isu() ):
      step = step*2.
    elif ( k.isd() ):
      step = step/2.
    elif ( k.isr() ):
      motor.set_speed(motor.get_speed()+step)
      print "current speed %s" % (motor.get_speed())
    elif ( k.isl() ):
      motor.set_speed(motor.get_speed()-step)
      print "current speed %s" % (motor.get_speed())
    elif ( k.iskey("g") ):
      print "enter absolute speed (char to abort go to)"
      sys.stdout.flush()
      v=sys.stdin.readline()
      try:
        v = float(v.strip())
        motor.set_speed(v)
        print "current speed %s" % (motor.get_speed())
      except:
        print "value cannot be converted to float, exit go to mode ..."
        sys.stdout.flush()
    elif ( k.iskey("s") ):
      print "enter new set value (char to abort setting)"
      sys.stdout.flush()
      v=sys.stdin.readline()
      try:
        v = float(v[0:-1])
        motor.set(v)
      except:
        print "value cannot be converted to float, exit go to mode ..."
        sys.stdout.flush()
    elif ( k.isq() ):
      break
    else:
      print help_text
  print "final speed: %s" % motor.get_speed()
    def updatingplot_old(self,
                         sleeptime=.2,
                         figurename="Displacementsensor",
                         noofpoints=100,
                         showpos=True):
        update = True
        val = [0]
        tt = [datetime.datetime.now()]
        pos = [0]
        pl.ion()

        tools.nfigure(figurename)
        if showpos:
            lh = pl.plot(tt[-noofpoints:], pos[-noofpoints:], 'ko-')
            pl.xlabel('Time')
            pl.ylabel('Position / mm')
        else:
            lh = pl.plot(tt[-noofpoints:], val[-noofpoints:], 'ko-')
            pl.xlabel('Time')
            pl.ylabel('Volt / mm')
        pl.draw()
        lh = pl.gca().lines[0]
        val = []
        tt = []
        pos = []
        quit = keypress.KeyPress(key="q")
        while quit.isq() is not True:
            tval = Pv.get(self.pv)
            val.append(tval)
            pos.append(self.poslims[0] + tval *
                       (np.diff(self.voltlims) / np.diff(self.poslims)))
            tt.append(datetime.datetime.now())
            tt = tt[-noofpoints:]
            pos = pos[-noofpoints:]
            if showpos:
                pl.gca().lines[-1].set_ydata(pos[-noofpoints:])
                pl.gca().lines[-1].set_xdata(tt[-noofpoints:])
                print pos, tt
            else:
                pl.gca().lines[-1].set_ydata(val[-noofpoints:])
                pl.gca().lines[-1].set_xdata(tt[-noofpoints:])
            sleep(sleeptime)
            pl.draw()
Exemple #7
0
    def recordscan_autogain(self,
                            motor,
                            range,
                            camera,
                            images_per_z=1,
                            name=None,
                            cal=None,
                            pulselength=None,
                            energy=None,
                            landa=800e-9,
                            new=False,
                            FilterChange=True):
        '''records a full focal scan with motor and camera.range=(begin,end,#steps).
           range is in the motor units, which is assumed to be mm. So this is multiplied by e-3 and put in the z register.
           useage:recordscan(self,motor,range,camera,name=None,cal=None,pulselength=None,energy=None,landa=800e-9,new=False): 
           It adds the images, unless new=True, in which case the scan is first cleared
           The camera takes a first images, which is used to set the gain such that the maximum count is around 200counts.
           If FilterChange=True, and the gain needed for this is out of range (either below 0 or above 32), the user is prompted
           to place a ND or take one away.
        '''
        print("AUTOGAIN FUNCTION NOT IMPLEMENTED YET")
        gain_high_lim = 32
        gain_low_lim = 0
        count_goal = 210.0  # the number of counts we want in the maximum. Should be close but below 256. 210 seem safe.
        zpositions = linspace(range[0], range[1], range[2])
        k = keypress.KeyPress()
        no_filte_change = not (FilterChange)
        for zpos in zpositions:
            motor.umv(zpos)
            ### Set gain correctly: we want 210counts in the maximum.
            wait_for_gain = True
            while wait_for_gain:
                factor = count_goal / camera.grab().max()
                current_gain = camera.gain()
                new_gain = current_gain + 20.0 * log10(factor)
                if (gain_low_lim <= new_gain <=
                        gain_high_lim) or no_filter_change:
                    wait_for_gain = False
                    camera.gain(new_gain)
                elif new_gain < gain_low_lim:
                    print(
                        "Camera saturated. Add OD~1. Press any key when done or 'c' to continue without further warnings."
                    )
                    k.waitkey()
                    if k.iskey("c"): no_filter_change = True
                elif new_gain > gain_high_lim:
                    print(
                        "Camera counts low. Remove OD~1. Press any key when done or 'c' to continue without further warnings."
                    )
                    k.waitkey()
                    if k.iskey("c"): no_filter_change = True

            time.sleep(0.01)

            for index in arange(images_per_z):
                self.grab(camera,
                          z=zpos * 1e-3,
                          cal=cal,
                          pulselength=pulselength,
                          energy=energy,
                          landa=landa)
                time.sleep(0.1)