def scan_gap(und, minv, maxv, n, t_scan = 1):
    '''
    gap scan -- going up and down one time
    '''
    gmd = np.zeros(n)
    gap_val = np.zeros(n)


    #sleep(7.0)

    for i in range(len(gmd)):
        
        if i < n:
            gap_val[i] = minv + (maxv - minv) * i / float(n)
        else:
            gap_val[i] = maxv - (maxv - minv)*(i - n) / float(n)
        
        gap_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/GAP.SET'
        gap_ch_rbv = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/GAP'
        gap_speed_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/GAP.SPEED'
        gap_start_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/CMD'
	res =  dcs.set_device_val(gap_ch, gap_val[i])
        dcs.set_device_val(gap_start_ch, 1)

	print 'setting...', gap_val[i]
	if i==0: sleep(10.0)
	sleep(2.0)
	gmd[i] = get_sase(detector = 'sflash.mcp')

    return gap_val, gmd
def seq_4():
   #scan sflash phase shifters

   ps = 'P1SFUND3'
   
   ps_m_ch = 'TTF2.MAGNETS/DIPOLE/'+ps+'M/PS' # main coil
   ps_m_ch_rbv = 'TTF2.MAGNETS/DIPOLE/'+ps+'M/PS.RBV' # maiin coil
   ps_c_ch = 'TTF2.MAGNETS/DIPOLE/'+ps+'C/PS' # correction coil
   ps_c_ch_rbv = 'TTF2.MAGNETS/DIPOLE/'+ps+'C/PS.RBV' # correction coil

   print 'ps main start ', dcs.get_device_val(ps_m_ch), '/', dcs.get_device_val(ps_m_ch_rbv)
   print 'ps cor start ', dcs.get_device_val(ps_c_ch), '/', dcs.get_device_val(ps_c_ch_rbv)
   res = dcs.set_device_val(ps_m_ch, 0.0)
   res = dcs.set_device_val(ps_c_ch, 0.0)
def scan_ps(dev, minv, maxv, n, t_scan = 1):
    '''
    phase shifter scan -- going up and down one time
    '''
    mcp = np.zeros(n)
    cor_val = np.zeros(n)

    #sleep(7.0)

    for i in range(len(mcp)):
        
        if i < n:
            cor_val[i] = minv + (maxv - minv) * i / float(n)
        else:
            cor_val[i] = maxv - (maxv - minv)*(i - n) / float(n)


        #ps_ch = 'TTF2.MAGNETS/STEERER/P3'+dev+'/PS' 
        ps_ch = 'TTF2.FEEDBACK/FL2.WAVELENGTHCONTROL/P' + dev + '/DELTA_PHI'

	res =  dcs.set_device_val(ps_ch, cor_val[i])

	print 'setting...', cor_val[i]
	if i==0: sleep(20.0)
	sleep(2.0)
	mcp[i] = get_sase(detector = 'flash2.mcp')

    return cor_val, mcp
def scan_rf_knob1(dev, minv, maxv, n, t_scan = 1):
    '''
    scan rf knob using acc1 and acc39 (chirp, 2nd and 3rd order chirp)
    '''
    gmd = np.zeros(n)
    cor_val = np.zeros(n)


    #sleep(7.0)

    for i in range(len(gmd)):
        
        if i < n:
            cor_val[i] = minv + (maxv - minv) * i / float(n)
        else:
            cor_val[i] = maxv - (maxv - minv)*(i - n) / float(n)
        
        #gmd[i] = get_sase(cor_val[i], dt=t_scan)

	rf_channel_ampl = 'FLASH.RF/LLRF.CONTROLLER/CTRL.'+dev+'/SP.AMPL'
	rf_channel_ph = 'FLASH.RF/LLRF.CONTROLLER/CTRL.'+dev+'/SP.PHASE'

	res =  dcs.set_device_val(rf_channel_ph, cor_val[i])
	print 'setting...', cor_val[i]
	if i==0: sleep(10.0)
	sleep(2.0)
	gmd[i] = get_sase()

    return cor_val, gmd
def scan_rf(dev, minv, maxv, n, t_scan = 1):
    '''
    rf device (single phase/amplitude) scan -- going up and down one time
    '''
    gmd = np.zeros(n)
    cor_val = np.zeros(n)


    #sleep(7.0)

    for i in range(len(gmd)):
        
        if i < n:
            cor_val[i] = minv + (maxv - minv) * i / float(n)
        else:
            cor_val[i] = maxv - (maxv - minv)*(i - n) / float(n)
        
        #gmd[i] = get_sase(cor_val[i], dt=t_scan)

	rf_channel_ampl = 'FLASH.RF/LLRF.CONTROLLER/CTRL.'+dev+'/SP.AMPL'
	rf_channel_ph = 'FLASH.RF/LLRF.CONTROLLER/CTRL.'+dev+'/SP.PHASE'

	res =  dcs.set_device_val(rf_channel_ph, cor_val[i])
	print 'setting...', cor_val[i]
	if i==0: sleep(10.0)
	sleep(2.0)
	gmd[i] = get_sase()

    return cor_val, gmd
def scan_cor(device_name, minv, maxv, n, t_scan = 1):
    '''
    device scan (magnets) -- going up and down one time
    '''
    gmd = np.zeros(n)
    cor_val = np.zeros(n)


    #sleep(7.0)

    for i in range(len(gmd)):
        
        if i < n:
            cor_val[i] = minv + (maxv - minv) * i / float(n)
        else:
            cor_val[i] = maxv - (maxv - minv)*(i - n) / float(n)
        
        #gmd[i] = get_sase(cor_val[i], dt=t_scan)
	mag_channel = 'TTF2.MAGNETS/STEERER/' + device_name + '/PS'
	res =  dcs.set_device_val(mag_channel, cor_val[i])
	print 'setting...', cor_val[i]
	if i==0: sleep(10.0)
	sleep(0.5)
	gmd[i] = get_sase()

    return cor_val, gmd
    def error_func_ps(x):
        
        pen_max = 100.0

        #print 'error_func: ', bpm_names, '->',  planes

        for i in xrange(len(unds)):
            #mag_channel = 'TTF2.MAGNETS/DIPOLE/'+unds[i]+'/PS'
            mag_channel = 'TTF2.MAGNETS/STEERER/P3'+unds[i]+'/PS' 
            print 'setting', mag_channel, '->',x[i]
            res =  dcs.set_device_val(mag_channel, x[i])

        sleep(1.0)

	sase = get_sase(detector = 'flash2.mcp')
        alarm = np.max(get_alarms())

	print 'alarm:', alarm
	print 'sase:', sase

        pen = 0.0

        if alarm > 1.0:
            return pen_max
        if alarm > 0.7:
            return alarm * 50.0
        pen += alarm
        
	pen -= sase	
        
        print 'penalty:', pen

        return pen   
def seq_5():
   #scan sflash undulator gaps

   und = '1SFUND2'
   
   gap_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/GAP.SET'
   gap_ch_rbv = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/GAP'
   gap_speed_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/GAP.SPEED'
   gap_start_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+und+'/CMD'
   val = dcs.get_device_val(gap_ch_rbv)
   print 'gap start ', val
   print 'gap speed ', dcs.get_device_val(gap_speed_ch), 'mm/s'
   res = dcs.set_device_val(gap_ch, 210.0)
   val = dcs.get_device_val(gap_ch_rbv)
   print 'gap start ', val
   dcs.set_device_val(gap_start_ch, 1)
    def error_func(x):
        
        pen_max = 100.0

        #print 'error_func: ', bpm_names, '->',  planes

        for i in xrange(len(x)):

           print 'setting ->',x[i]

           
        v1, phi1, v39, phi39=find_parameters_RF1(c0,c1,x[0],c3)
        v2, phi2 = find_parameters_RF2(c4,c5)

        dcs.set_device_val(rf_ch_amp_1, v1)
        dcs.set_device_val(rf_ch_ph_1, phi1)
        dcs.set_device_val(rf_ch_amp_39, v39)
        dcs.set_device_val(rf_ch_ph_39, phi39)
            #dcs.set_device_val(rf_ch_amp_2, v2)
            #dcs.set_device_val(rf_ch_ph_2, phi2)

        print 'c:', c0, c1, c2, c3, c4, c5  


        sleep(1.0)

	sase = get_sase()
        alarm = np.max(get_alarms())
        f, spec = get_spectrum()

	print 'alarm:', alarm
	print 'sase:', sase
        print 'max spec:', np.max(spec) 

        pen = 0.0

        if alarm > 1.0:
            return pen_max
        if alarm > 0.7:
            return alarm * 50.0
        pen += alarm

        sase_weight = 1.0
        spec_weight = 1.0

	pen -= sase * sase_weight
        #pen -= np.max(spec) * spec_weight

        return pen
def scan_one_qmover(device_name, step = 0.004, stop_alarm_level = 0.6):

    '''
    go up then down and then up again. Change direction when 
    stop_alarm_level of alarm level reached.
    '''
    mover_ch = 'TTF2.MAGNETS/QUAD.MOVER/' + device_name + '/FODOMETER.REFERENCE'
    mover_ch_rbv = 'TTF2.MAGNETS/QAUD.MOVER/' + device_name + '/FODOMETER'
    start_ch = 'TTF2.MAGNETS/QUAD.MOVER/' + device_name + '/CMD'

    val = dcs.get_device_val(mover_ch)

    vals = []
    rbvs = []
    
    n_max = 500
    i_set = 0
    while True:
        i_set += 1
        val += step

        # set device
        res =  dcs.set_device_val(mover_ch, val)
	dcs.set_device_val(start_ch, 7)

	sleep(1.0)

	#rbvs.append(rbv)
	vals.append(val)

        alarm = np.max(get_alarms())
        #print "\n\n rbv = {2} nval={0} alarm={1}\n\n".format(val, alarm, rbv)

        if alarm >= stop_alarm_level or val > 0.9 or val < -0.9:
            step = - step
	if i_set > n_max:
           break

    return vals
    def error_func(x):
        
        pen_max = 100.0

        #print 'error_func: ', bpm_names, '->',  planes

        for i in xrange(len(x)):
            print 'x[{0}]={1}'.format(i, x[i])
            if abs(x[i]) > 50.5:
                return pen_max


        for i in xrange(len(correctors)):
            mag_channel = 'TTF2.MAGNETS/STEERER/' + correctors[i] + '/PS'
            print 'setting', mag_channel, '->',x[i]
            res =  dcs.set_device_val(mag_channel, x[i])

        sleep(1.6)

	sase = get_sase(detector='gmd_fl1_slow')
        alarm = np.max(get_alarms())
	z1, z2 = get_sase_pos()



	print 'alarm:', alarm
	print 'sase:', sase
	print 'pointing', z1, z2, 'weights', weight_gmd_bpm_1, weight_gmd_bpm_2


        pen = 0.0

        if alarm > 1.0:
            return pen_max
        if alarm > 0.7:
            return alarm * 50.0
        pen += alarm

	pen -= sase	
	#pen += weight_gmd_bpm_1* 0*(z1[1]**2 + 0*z1[0]**2) + weight_gmd_bpm_2 * (z2[0]**2 + 0*z2[1]**2)
        #if sase < 0.9 * sase_ref: pen += 1000.0
        #pen += np.abs(z1[1])

        print 'penalty:', pen

        return pen
def seq_6():
   #flash2 phase shifters

   und = 'FL2SASE13'
   
   gap_ch = 'FLASH.UTIL/FL2.UND.MOTOR/'+und+'/GAP.SET'
   gap_ch_rbv = 'FLASH.UTIL/FL2.UND.MOTOR/'+und+'/GAP'
   gap_speed_ch = 'FLASH.UTIL/FL2.UND.MOTOR/'+und+'/GAP.SPEED'
   gap_start_ch = 'FLASH.UTIL/FL2.UND.MOTOR/'+und+'/CMD'
   print 'gap start ', dcs.get_device_val(gap_ch_rbv)
   print 'gap speed ', dcs.get_device_val(gap_speed_ch), 'mm/s'

   ps_ch = 'TTF2.MAGNETS/STEERER/P3'+und+'/PS' 
   ps_ch_rbv = 'TTF2.MAGNETS/STEERER/P3'+und+'/PS.RBV' 

   print 'ps start ', dcs.get_device_val(ps_ch), '/', dcs.get_device_val(ps_ch_rbv)

   res = dcs.set_device_val(ps_ch, 2.0)
    def error_func_gap(x):
        
        pen_max = 100.0

        for i in xrange(len(x)):
            print 'x[{0}]={1}'.format(i, x[i])
            if x[i] < 10.0 or x[i] > 220.0:
                return pen_max


        #print 'error_func: ', bpm_names, '->',  planes

        for i in xrange(len(unds)):
              gap_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+unds[i]+'/GAP.SET'
              gap_ch_rbv = 'TTF2.EXP/SFLASH.UND.MOTOR/'+unds[i]+'/GAP'
              gap_speed_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+unds[i]+'/GAP.SPEED'
              gap_start_ch = 'TTF2.EXP/SFLASH.UND.MOTOR/'+unds[i]+'/CMD'
              print 'setting', gap_ch, '->',x[i]
              res =  dcs.set_device_val(gap_ch, x[i])
              #dcs.set_device_val(gap_start_ch, 1)

        sleep(1.0)

	sase = get_sase(detector = 'flash2.mcp')
        alarm = np.max(get_alarms())

	print 'alarm:', alarm
	print 'sase:', sase

        pen = 0.0

        if alarm > 1.0:
            return pen_max
        if alarm > 0.7:
            return alarm * 50.0
        pen += alarm

	pen -= sase	

        print 'penalty:', pen

        return pen
def scan_one_cor(device_name, start_val = 0.0, step = 0.01, stop_alarm_level = 0.6):

    '''
    go up then down and then up again. Change direction when 
    stop_alarm_level of alarm level reached.
    '''
    mag_channel = 'TTF2.MAGNETS/STEERER/' + device_name + '/PS'
    mag_channel_rbv = 'TTF2.MAGNETS/STEERER/' + device_name + '/PS.RBV'

    val = start_val

    vals = []
    rbvs = []
    
    n_max = 5000
    i_set = 0
    while True:
        i_set += 1
        val += step

        # set device
        res =  dcs.set_device_val(mag_channel, val)
	sleep(2.0)
	rbv = dcs.get_device_val(mag_channel_rbv)

	rbvs.append(rbv)
	vals.append(val)

        alarm = np.max(get_alarms())
        print "\n\n rbv = {2} nval={0} alarm={1}\n\n".format(val, alarm, rbv)

        if alarm >= stop_alarm_level:
            step = - step
	if i_set > n_max:
           break

    return (vals, rbvs) 
from pylab import *

import ocelot.mint.swig.dcs as dcs

print 'corrector setting test...'

#mag_name = 'H3UND2'
mag_name = 'V14SMATCH'

mag_channel_rbv = 'TTF2.MAGNETS/STEERER/' + mag_name + '/PS.RBV'
mag_channel = 'TTF2.MAGNETS/STEERER/' + mag_name + '/PS'

val = dcs.get_device_val(mag_channel_rbv)
print 'before rbv:', val

res =  dcs.set_device_val(mag_channel, 1.255)

print 'setting result returned ', res

val = dcs.get_device_val(mag_channel_rbv)
print 'after. rbv:', val
Exemple #16
0
def measure_response_2(steerer1, steerer2, step1, step2, n_steps = 3):
   '''
   response for blms, bpms, sase, 
   '''
   bpm_names = ['4UND3', '5UND3']


   bpm_names = ['1TCOL',
                '6TCOL',
                '8TCOL',
                '3ECOL',
                '5ECOL',
                '2ORS',
                '7ORS',
                '9ORS',
                '12ORS',
                '1SFUND2',
                '1SFUND3',
                '1SFUND4',
                '1SFELC',
                '1SMATCH',
                '6SMATCH',
                '13SMATCH',
                '14SMATCH',
                '2UND1',
                '4UND1',
                '5UND1',
                '2UND2',
                '4UND2',
                '5UND2',
                '2UND3',
                '4UND3',
                '5UND3',
                '2UND4',
                '4UND4',
                '5UND4',
                '2UND5',
                '4UND5',
                '5UND5',
                '2UND6',
                '4UND6',
                '5UND6']


   bpms = []
   for bpm_name in bpm_names:
	bpm = dcs.BPM("TTF2.DIAG/BPM/" + bpm_name)
	bpms.append(bpm)


   blms = []

   resp_funcs = []


   rf = ResponseFunction()
   rf.device = steerer1 + ':' + steerer2
   rf.set_vals = []
   rf.rb_vals = []

   rf.bpm_vals = {}
   for bpm in bpm_names:
      rf.bpm_vals[bpm] = []


   rf.blm_vals = {}
   rf.sase_vals = []
      
   mag_channel_1 = 'TTF2.MAGNETS/STEERER/' + steerer1 + '/PS' 
   mag_channel_rbv_1 = 'TTF2.MAGNETS/STEERER/' + steerer1 + '/PS.RBV' 

   mag_channel_2 = 'TTF2.MAGNETS/STEERER/' + steerer2 + '/PS' 
   mag_channel_rbv_2 = 'TTF2.MAGNETS/STEERER/' + steerer2 + '/PS.RBV' 
      
   rbv_1 = dcs.get_device_val(mag_channel_rbv_1)
   init_v_1 = dcs.get_device_val(mag_channel_1)
   print 'reading ', mag_channel_1, init_v_1, rbv_1

   rbv_2 = dcs.get_device_val(mag_channel_rbv_2)
   init_v_2 = dcs.get_device_val(mag_channel_2)
   print 'reading ', mag_channel_2, init_v_2, rbv_2

   set_val_1 = init_v_1
   set_val_2 = init_v_2

   t_out = 10.0

   for i in range(n_steps):
      print '...', set_val_1, set_val_2, '...'
      set_val_1 += step1
      set_val_2 += step2
      dcs.set_device_val(mag_channel_1, set_val_1)
      dcs.set_device_val(mag_channel_2, set_val_2)
      sleep(t_out)
      rbv_1 = dcs.get_device_val(mag_channel_rbv_1)
      rbv_2 = dcs.get_device_val(mag_channel_rbv_2)
      rf.set_vals.append(set_val_1)
      rf.rb_vals.append(rbv_1)

      for i_bpm in range(len(bpms)):
         dcs.get_bpm_val(bpms[i_bpm])
         rf.bpm_vals[bpm_names[i_bpm]].append((bpms[i_bpm].x,bpms[i_bpm].y)) 

      rf.sase_vals.append( get_sase() )

   for i in range(2*n_steps):
      print '...', set_val_1, set_val_2, '...'
      set_val_1 -= step1
      set_val_2 -= step2
      dcs.set_device_val(mag_channel_1, set_val_1)
      dcs.set_device_val(mag_channel_2, set_val_2)
      sleep(t_out)
      rbv_1 = dcs.get_device_val(mag_channel_rbv_1)
      rbv_2 = dcs.get_device_val(mag_channel_rbv_2)
      rf.set_vals.append(set_val_1)
      rf.rb_vals.append(rbv_1)

      for i_bpm in range(len(bpms)):
         dcs.get_bpm_val(bpms[i_bpm])
         rf.bpm_vals[bpm_names[i_bpm]].append((bpms[i_bpm].x,bpms[i_bpm].y)) 

      rf.sase_vals.append( get_sase() )

   for i in range(n_steps):
      print '...', set_val_1, set_val_2, '...'
      set_val_1 += step1
      set_val_2 += step2
      dcs.set_device_val(mag_channel_1, set_val_1)
      dcs.set_device_val(mag_channel_2, set_val_2)
      sleep(t_out)
      rbv_1 = dcs.get_device_val(mag_channel_rbv_1)
      rbv_2 = dcs.get_device_val(mag_channel_rbv_2)
      rf.set_vals.append(set_val_1)
      rf.rb_vals.append(rbv_1)
      for i_bpm in range(len(bpms)):
         dcs.get_bpm_val(bpms[i_bpm])
         rf.bpm_vals[bpm_names[i_bpm]].append((bpms[i_bpm].x,bpms[i_bpm].y)) 
      rf.sase_vals.append( get_sase() )

      #dcs.set_device_val(mag_channel, init_v)

   resp_funcs.append(rf)
   return resp_funcs 
Exemple #17
0
def measure_response(steerers, step = 0.01, n_steps = 3):
   '''
   response for blms, bpms, sase, 
   '''
   bpm_names = ['4UND3', '5UND3']


   bpm_names = ['1TCOL',
                '6TCOL',
                '8TCOL',
                '3ECOL',
                '5ECOL',
                '2ORS',
                '7ORS',
                '9ORS',
                '12ORS',
                '1SFUND2',
                '1SFUND3',
                '1SFUND4',
                '1SFELC',
                '1SMATCH',
                '6SMATCH',
                '13SMATCH',
                '14SMATCH',
                '2UND1',
                '4UND1',
                '5UND1',
                '2UND2',
                '4UND2',
                '5UND2',
                '2UND3',
                '4UND3',
                '5UND3',
                '2UND4',
                '4UND4',
                '5UND4',
                '2UND5',
                '4UND5',
                '5UND5',
                '2UND6',
                '4UND6',
                '5UND6']


   bpms = []
   for bpm_name in bpm_names:
	bpm = dcs.BPM("TTF2.DIAG/BPM/" + bpm_name)
	bpms.append(bpm)


   blms = []

   resp_funcs = []

   for s in steerers:

      rf = ResponseFunction()
      rf.device = s
      rf.set_vals = []
      rf.rb_vals = []

      rf.bpm_vals = {}
      for bpm in bpm_names:
         rf.bpm_vals[bpm] = []


      rf.blm_vals = {}
      rf.sase_vals = []
      
      mag_channel = 'TTF2.MAGNETS/STEERER/' + s + '/PS' 
      mag_channel_rbv = 'TTF2.MAGNETS/STEERER/' + s + '/PS.RBV' 
      
      rf_channel_ampl = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC23/SP.AMPL'
      rf_channel_ph = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC23/SP.PHASE'

      # TODO: rename mag_channel dev_channel
      #mag_channel = mag_channel_rbv = rf_channel_ph

      rbv = dcs.get_device_val(mag_channel_rbv)
      init_v = dcs.get_device_val(mag_channel)
      print 'reading ', mag_channel, init_v, rbv

      set_val = init_v

      for i in range(n_steps):
         set_val += step
	 # set value
         dcs.set_device_val(mag_channel, set_val)
         sleep(1.0)
	 rbv = dcs.get_device_val(mag_channel_rbv)
	 rf.set_vals.append(set_val)
	 rf.rb_vals.append(rbv)

	 for i_bpm in range(len(bpms)):
            #x, y = set_val**2, set_val**3	 
            dcs.get_bpm_val(bpms[i_bpm])
            rf.bpm_vals[bpm_names[i_bpm]].append((bpms[i_bpm].x,bpms[i_bpm].y)) 

         rf.sase_vals.append( get_sase() )

      for i in range(2*n_steps):
         set_val -= step
	 # set value
         dcs.set_device_val(mag_channel, set_val)
         sleep(1.0)
	 rbv = dcs.get_device_val(mag_channel_rbv)
	 rf.set_vals.append(set_val)
	 rf.rb_vals.append(rbv)
	 for i_bpm in range(len(bpms)):
            #x, y = set_val**2, set_val**3	 
            dcs.get_bpm_val(bpms[i_bpm])
            rf.bpm_vals[bpm_names[i_bpm]].append((bpms[i_bpm].x,bpms[i_bpm].y)) 
         rf.sase_vals.append( get_sase() )

      for i in range(n_steps):
         set_val += step
	 # set value
         dcs.set_device_val(mag_channel, set_val)
	 rbv = dcs.get_device_val(mag_channel_rbv)
         sleep(1.0)
	 rf.set_vals.append(set_val)
	 rf.rb_vals.append(rbv)
	 for i_bpm in range(len(bpms)):
            #x, y = set_val**2, set_val**3	 
            dcs.get_bpm_val(bpms[i_bpm])
            rf.bpm_vals[bpm_names[i_bpm]].append((bpms[i_bpm].x,bpms[i_bpm].y)) 
         rf.sase_vals.append( get_sase() )

      #dcs.set_device_val(mag_channel, init_v)

      resp_funcs.append(rf)
   return resp_funcs 
def seq_7():
   #chicane
   print 'chicane setting ', dcs.get_device_val('TTF2.FEEDBACK/CHICANECTRL/V2-6SFELC/ALPHA'), 'mrad'
   dcs.set_device_val('TTF2.FEEDBACK/CHICANECTRL/V2-6SFELC/ALPHA', 0.0)
   dcs.set_device_val('TTF2.FEEDBACK/CHICANECTRL/V2-6SFELC/WRITE', 1)
Exemple #19
0
def measure_response(rf_params, init_v = None, step = 10.0, n_steps = 3, delay=0.5):
   '''
   response of sase, orbit, spectrum vs. rf knobs, 
   '''
   bpm_names = ['1TCOL',
                '6TCOL',
                '8TCOL',
                '3ECOL',
                '5ECOL',
                '2ORS',
                '7ORS',
                '9ORS',
                '12ORS',
                '1SFUND2',
                '1SFUND3',
                '1SFUND4',
                '1SFELC',
                '1SMATCH',
                '6SMATCH',
                '13SMATCH',
                '14SMATCH',
                '2UND1',
                '4UND1',
                '5UND1',
                '2UND2',
                '4UND2',
                '5UND2',
                '2UND3',
                '4UND3',
                '5UND3',
                '2UND4',
                '4UND4',
                '5UND4',
                '2UND5',
                '4UND5',
                '5UND5',
                '2UND6',
                '4UND6',
                '5UND6']


   bpms = []
   for bpm_name in bpm_names:
	bpm = dcs.BPM("TTF2.DIAG/BPM/" + bpm_name)
	bpms.append(bpm)


   blms = []

   resp_funcs = []

   for s in rf_params:

      rf = ResponseFunction()
      rf.device = s
      rf.set_vals = []
      rf.rb_vals = []

      rf.bpm_vals = {}
      for bpm in bpm_names:
         rf.bpm_vals[bpm] = []


      rf.blm_vals = {}
      rf.sase_vals = []
      rf.spec_vals = []
            
      rf_ch_amp_1 = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC1/SP.AMPL'
      rf_ch_ph_1 = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC1/SP.PHASE'

      rf_ch_amp_39 = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC39/SP.AMPL'
      rf_ch_ph_39 = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC39/SP.PHASE'

      rf_ch_amp_2 = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC23/SP.AMPL'
      rf_ch_ph_2 = 'FLASH.RF/LLRF.CONTROLLER/CTRL.ACC23/SP.PHASE'

      init_amp_1 = dcs.get_device_val(rf_ch_amp_1)
      init_ph_1 = dcs.get_device_val(rf_ch_ph_1)
      
      init_amp_39 = dcs.get_device_val(rf_ch_amp_39)
      init_ph_39 = dcs.get_device_val(rf_ch_ph_39)
      
      init_amp_2 = dcs.get_device_val(rf_ch_amp_2)
      init_ph_2 = dcs.get_device_val(rf_ch_ph_2)

      print 'reading rf params', init_amp_1, init_ph_1, init_amp_39, init_ph_39, init_amp_2, init_ph_2
      c0,c1,c2,c3 = find_knob_val_RF1(init_amp_1, init_ph_1, init_amp_39, init_ph_39)
      c4, c5 = find_knob_val_RF2(init_amp_2, init_ph_2)
      print 'init knobs:', c0,c1,c2,c3, c4, c5

      cur_step = step

      '''
      v1, phi1, v39, phi39=find_parameters_RF1(c0,-692.8,c2,c3)
      dcs.set_device_val(rf_ch_amp_1, v1)
      dcs.set_device_val(rf_ch_ph_1, phi1)
      dcs.set_device_val(rf_ch_amp_39, v39)
      dcs.set_device_val(rf_ch_ph_39, phi39)

      return None
      '''

      '''
      v2, phi2 = find_parameters_RF2(c4,-1588.0)
      dcs.set_device_val(rf_ch_amp_2, v2)
      dcs.set_device_val(rf_ch_ph_2, phi2)
      return None
      '''

      for i in range(n_steps*4):

         if i == n_steps:
            cur_step = - step
         if i == n_steps*3:
            cur_step = step

         if s == 'c0': c0 += cur_step
         if s == 'c1': c1 += cur_step
         if s == 'c2': c2 += cur_step
         if s == 'c3': c3 += cur_step
         if s == 'c4': c4 += cur_step
         if s == 'c5': c5 += cur_step

         v1, phi1, v39, phi39=find_parameters_RF1(c0,c1,c2,c3)
         v2, phi2 = find_parameters_RF2(c4,c5)

         if s in ['c0','c1','c2','c3']:
            dcs.set_device_val(rf_ch_amp_1, v1)
            dcs.set_device_val(rf_ch_ph_1, phi1)
            dcs.set_device_val(rf_ch_amp_39, v39)
            dcs.set_device_val(rf_ch_ph_39, phi39)
            print 'BC1'
         else:
            dcs.set_device_val(rf_ch_amp_2, v2)
            dcs.set_device_val(rf_ch_ph_2, phi2)
            print 'BC2'

         print 'knobs:', c0,c1,c2,c3, c4, c5
         print 'rf:', v1, phi1, v39, phi39, v2, phi2            
         sleep(delay)
	 rf.set_vals.append(locals()[s])

	 for i_bpm in range(len(bpms)):
            dcs.get_bpm_val(bpms[i_bpm])
            rf.bpm_vals[bpm_names[i_bpm]].append((bpms[i_bpm].x,bpms[i_bpm].y)) 

         rf.sase_vals.append( get_sase() )
         f, spec = get_spectrum()
         rf.f = f
         rf.spec_vals.append(spec)

      resp_funcs.append(rf)
   return resp_funcs