diff --git a/measurement_scripts/inprints.py b/measurement_scripts/inprints.py index 7d602ad..e4fc74c 100644 --- a/measurement_scripts/inprints.py +++ b/measurement_scripts/inprints.py @@ -4,23 +4,144 @@ import numpy as np #from epics import PV #from slic.utils import nice_arange #from slic.devices.general.motor import Motor +import matplotlib.pyplot as plt +import epics +from slic.devices.xoptics.aramis_attenuator import Attenuator +attenuator = Attenuator("SAROP31-OATA150", description="Cristallina attenuator OATA150") + +from slic.devices.xoptics.kb import KBBase,KBHor,KBVer +kbHor = KBHor( + "SAROP31-OKBH154", + description="Cristallina horizontal KB mirror" +) + +kbVer = KBVer( + "SAROP31-OKBV153", + description="Cristallina vertical KB mirror" +) + +do_not_move_benders = True +testing_flag = True +pos = np.array([0,0]) # parameters -n_same_holes = 5 -attenuations = np.logspace(1e-6,1,num=12) +n_same_holes = 3 +attenuations = np.logspace(-3,0,num=4) +KBv_home = [1.5,1.7] +KBh_home = [1.6,1.8] -def shoot(): - raise NotImplementedError("not done yet") +# Spacings +between_same_shots = 50 +between_attenuations = 60 +KBvs =[[1,2],[1,3]] +KBhs = [[1,2],[1,2]] -def change_benders(bender_1,bender_2,KB = None): + +def shoot(pos=pos,testing=testing_flag): + if testing: + print(f'Shot at: {pos}') + return pos + else: + epics.caput("SAR-CCTA-ESC:seq0Ctrl-Start-I",1) + + +def change_benders(bender_1,bender_2,KB = None,do_not_move_benders = do_not_move_benders): check_KB_value(KB) + + current_values = get_bender_values(KB) + + if current_values[0] > bender_1 or current_values[1] > bender_2: + print('Unbending first because of backlash') + if do_not_move_benders != True: + # Move home first + if KB == 'h' or KB == 'H': + kbHor.bend1.set_target_value(KBh_home[0]).wait() + sleep(1) + kbHor.bend2.set_target_value(KBh_home[1]).wait() + else: + kbVer.bend1.set_target_value(KBv_home[0]).wait() + sleep(1) + kbVer.bend2.set_target_value(KBv_home[1]).wait() + + + if do_not_move_benders: + print(f'Bender 1 to: {bender_1}') + print(f'Bender 2 to: {bender_2}') + return + + # Move to the new position + print(f'Changing {KB} bender to: [{bender_1} , {bender_2}]') + if KB == 'h' or KB == 'H': + kbHor.bend1.set_target_value(bender_1).wait() + sleep(1) + kbHor.bend2.set_target_value(bender_2).wait() + else: + kbVer.bend1.set_target_value(bender_1).wait() + sleep(1) + kbVer.bend2.set_target_value(bender_2).wait() + def check_KB_value(KB): if KB not in ['H','h','V','v']: raise KeyError(f"KB can only be horizontal (H) or vertical (V), not {KB}") -def get_bender_value(KB=None): +def get_bender_values(KB=None): check_KB_value(KB) + if KB == 'h' or KB == 'H': + return [kbHor.bend1.get(),kbHor.bend2.get()] + else: + return [kbVer.bend1.get(),kbVer.bend2.get()] + + +def move_x_rel(distance,testing=testing_flag,pos=pos): + if testing == True: + pos = pos + [distance,0] + return pos + else: + attocube.X.set_target_value(distance, relative=True) + +def move_y_rel(distance,testing=testing_flag,pos=pos): + if testing == True: + pos = pos + [0,distance] + return pos + else: + attocube.Y.set_target_value(distance, relative=True) + +def make_same_shots(n_same_holes,testing=testing_flag,pos=pos): + if testing == True: + original_position = pos + else: + original_position = attocube.X.get_current_value() + + # Make holes + for shot in range(n_same_holes): + shoot(pos=pos) + pos = move_x_rel(between_same_shots,pos=pos) + #plt.plot(pos,'o') + # Return back to where you started + if testing == True: + pos = original_position + else: + attocube.X.set_target_value(original_position, relative=True) + return pos + + +plt.figure() +for KBv in KBvs: + change_benders(KBv[0],KBv[1],KB = 'v') + + for KBh in KBhs: + change_benders(KBh[0],KBh[1],KB = 'h') + + for attenuation in attenuations: + print(f'Setting attenuation to: {attenuation}') + #attenuator.trans1st(attenuation) + print('Making same shots') + make_same_shots(n_same_holes,pos=pos) + pos = move_y_rel(between_attenuations,pos=pos) + + +