From 07d24688c4165177e48b06280e2681d875c8d0da Mon Sep 17 00:00:00 2001
From: Jessica McChesney <jmcchesn@anl.gov>
Date: Thu, 25 Aug 2022 11:02:26 -0500
Subject: [PATCH] debugging

---
 build/lib/iexcode/instruments/ARPES.py        | 165 ++---------
 .../iexcode/instruments/IEX_endstations.py    |  13 +-
 build/lib/iexcode/instruments/Kappa.py        | 278 +++---------------
 build/lib/iexcode/instruments/Motors.py       | 224 +++++++++++++-
 build/lib/iexcode/instruments/beamline.py     |  68 -----
 build/lib/iexcode/instruments/scalers.py      |   2 +-
 build/lib/iexcode/instruments/scanRecord.py   |  50 +++-
 build/lib/iexcode/instruments/xrays.py        |  38 ++-
 iexcode/instruments/ARPES.py                  | 125 +-------
 iexcode/instruments/IEX_endstations.py        |  12 +-
 iexcode/instruments/Kappa.py                  | 278 +++---------------
 iexcode/instruments/Logfile.py                |  31 ++
 iexcode/instruments/MPA.py                    |   3 +-
 iexcode/instruments/Motors.py                 | 222 +++++++++++++-
 iexcode/instruments/beamline.py               |  63 ----
 iexcode/instruments/cfg.py                    |   1 +
 iexcode/instruments/scalers.py                |   2 +-
 iexcode/instruments/scanRecord.py             |  50 +++-
 iexcode/instruments/xrays.py                  |  17 +-
 19 files changed, 715 insertions(+), 927 deletions(-)

diff --git a/build/lib/iexcode/instruments/ARPES.py b/build/lib/iexcode/instruments/ARPES.py
index 0ade96a..c256ea7 100644
--- a/build/lib/iexcode/instruments/ARPES.py
+++ b/build/lib/iexcode/instruments/ARPES.py
@@ -18,23 +18,30 @@ from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import *
 from iexcode.instruments.gate_valves import valve_close, branch_valves
 from iexcode.instruments.shutters import branch_shutter_close
-from iexcode.instruments.slits import slit3C_get
 
+#branch specific
+from iexcode.instruments.slits import slit3C_get
+#endstation specific
 from iexcode.instruments.Lakeshore_335 import Lakeshore_reset
 from iexcode.instruments.electron_analyzer import EA_init_Motors,folders_EA,EA
 
 default_ioc = '29idARPES:'
+#detector objects used with in module and returned by init
 global tey, ca15
 
 #############################################################################
 def ARPES_init(*userName,**kwargs):
     """
-        userName is an optional parameter
-        kwargs:
-        set_folders: sets the mda and EA folders (default => True)  
-        reset: to reset the detectors in the IOC, etc (default => True)  
-        xrays: sets global variable and detectors for x-ray (default => True) 
-        mode: used sets the detectors 'user ' / 'staff' (default => 'user' )  
+    used to intialize the Endstation class which carries scanRecord, logging ... parameters
+    returns global detectors relavent to this endstation (tey,ca15)
+
+        *userName is an optional parameter, will be prompted if set_folders=True
+
+        **kwargs:
+            set_folders: sets the mda and EA folders (default => True)  
+            reset: to reset the detectors in the IOC, etc (default => True)  
+            xrays: sets global variable and detectors for x-ray (default => True) 
+            mode: used sets the detectors 'user ' / 'staff' (default => 'user' )  
     """
     kwargs.setdefault('scan_ioc',default_ioc)
     kwargs.setdefault('xrays',True)
@@ -178,7 +185,6 @@ def folders_ARPES(user_name,**kwargs):
     kwargs.setdefault('ftp',False)
     kwargs.setdefault('debug',False)
 
-    #global BL
     run = kwargs['run']
 
     if kwargs['debug']:
@@ -191,12 +197,7 @@ def folders_ARPES(user_name,**kwargs):
     if kwargs["set_folders"]:
         # Set up MDA folder:
         folder_mda(run,iex.BL.folder,user_name,iex.BL.prefix,iex.BL.ioc)
-        sleep(5)
-        logfile_name_set(iex.BL.endstation)
-        sleep(2)
-        logfile_header(iex.BL.endstation,iex.BL.ioc,ARPES_log_header())
 
-        
         #Set up Scienta folders:
         if EA.connected: 
             userPath = "/net/s29data/export/data_29id"+iex.BL.folder+"/"+run+"/"+user_name+"/"
@@ -207,27 +208,27 @@ def folders_ARPES(user_name,**kwargs):
 def ARPES_reset(**kwargs):
     """
     resets scanRecord, current amplifiers, mono limits and lakeshore
-    """
-    #global BL
-    #resetting the scanRecord
+    """   
+    #writing default parameters to iex.BL.mda
     if iex.BL.mode=='staff':
         iex.BL.mda.detector_dictionary = staff_detector_dictionary(kwargs['xrays'])
     else:
         iex.BL.mda.detector_dictionary = ARPES_detector_dictionary(kwargs['xrays'])
-    
     iex.BL.mda.trigger_dictionary = ARPES_trigger_dictionary(**kwargs)
     iex.BL.mda.scan_before_sequence = ARPES_scan_before_sequence(**kwargs)
     iex.BL.mda.scan_after_sequence = ARPES_scan_after_sequence(**kwargs)
-    
+    #resetting the scanRecord
+    print("resetting the scanRecord - "+iex.BL.ioc)
     iex.BL.mda.reset_all()
 
     #resetting the current amplifiers
+    print("resetting the current amplifiers")
     if iex.BL.xrays:
         ca_reset_all()
     else:
         tey.reset()
 
-    #resetting mono and anyother beamline stuff
+    #resetting mono and other beamline stuff
     if iex.BL.xrays:
         xrays_reset()
 
@@ -239,6 +240,7 @@ def ARPES_reset(**kwargs):
         "TC1:OUT2:Cntrl":"B",
         "TC1:OUT1:Mode":"Closed Loop"
     }
+    print("resetting ARPES Lakeshore")
     Lakeshore_reset(pv,LS_355_defaults)
 
 ##############################################################################################################
@@ -323,8 +325,6 @@ def ARPES_scan_before_sequence(**kwargs):
     kwargs.setdefault('seq_num',9)
     seq_num=kwargs['seq_num']
 
-    #global BL
-
     scan_ioc = iex.BL.ioc
 
     before_scan_pv,before_scan_proc = userStringSeq_pvs(scan_ioc,seq_num)
@@ -346,7 +346,6 @@ def ARPES_ca_live_sequence(**kwargs):
     """
     """
     kwargs.setdefault('seq_num',7)
-    #global BL
 
     ca_live_sequence_proc = ca_live_sequence(iex.BL.ioc,kwargs['seq_num'],ARPES_detector_list())
     return ca_live_sequence_proc
@@ -368,7 +367,6 @@ def ARPES_scan_after_sequence(**kwargs):
     seq_num = kwargs['seq_num']
     scan_dim = kwargs['scan_dim']
 
-    #global BL
     scan_ioc = iex.BL.ioc
     
     after_scan_pv,after_scan_proc = userStringSeq_pvs(scan_ioc, seq_num)
@@ -409,7 +407,6 @@ def ARPES_detector_triggers_sequence(**kwargs):    # do we need to add 29idb:ca5
     kwargs.setdefault('seq_num',8)
     seq_num=kwargs['seq_num']
 
-    #global BL
     scan_ioc = iex.BL.ioc
     detector_triggers_pv,detector_triggers_proc = userStringSeq_pvs(scan_ioc, seq_num)
        
@@ -644,109 +641,6 @@ def ARPES_safe_state(**kwargs):
 ##############################################################################################################
 ##############################              ARPES motors       ##############################
 ##############################################################################################################
-### x ###
-def mvx(val,**kwargs):
-    """ moves x motor in the endstation"""
-    ARPES_Motors.move('x',val,**kwargs)
-
-def dmvx(val):
-    """ relative x motor in the endstation"""
-    ARPES_Motors.move('x',val,relative=True)
-
-def scanx(start,stop,step,**kwargs):
-    """ scans the x motor in the endstation"""
-    ARPES_Motors.scan("x",start,stop,step,**kwargs)
-
-def dscanx(start,stop,step):
-    """relative scans of the x motor in the endstation """
-    ARPES_Motors.scan("x",start,stop,step,relative=True)
-
-### y ###
-def mvy(val,**kwargs):
-    """ moves y motor in the endstation"""
-    ARPES_Motors.move('y',val,**kwargs)
-
-def dmvy(val):
-    """ relative y motor in the endstation"""
-    ARPES_Motors.move('y',val,relative=True)
-
-def scany(start,stop,step,**kwargs):
-    """ scans the y motor in the endstation"""
-    ARPES_Motors.scan("y",start,stop,step,**kwargs)
-
-def dscany(start,stop,step):
-    """relative scans of the y motor in the endstation """
-    ARPES_Motors.scan("y",start,stop,step,relative=True)
-
-### z ###
-def mvz(val,**kwargs):
-    """ moves z motor in the endstation"""
-    ARPES_Motors.move('z',val,**kwargs)
-
-def dmvz(val):
-    """ relative z motor in the endstation"""
-    ARPES_Motors.move('z',val,relative=True)
-
-def scanz(start,stop,step,**kwargs):
-    """ scans the z motor in the endstation"""
-    ARPES_Motors.scan("z",start,stop,step,**kwargs)
-
-def dscanz(start,stop,step):
-    """relative scans of the z motor in the endstation """
-    ARPES_Motors.scan("z",start,stop,step,relative=True)
-
-### th ###
-def mvth(val,**kwargs):
-    """ moves th motor in the endstation"""
-    ARPES_Motors.move('th',val,**kwargs)
-
-def dmvth(val):
-    """ relative th motor in the endstation"""
-    ARPES_Motors.move('th',val,relative=True)
-
-def scanth(start,stop,step,**kwargs):
-    """ scans the th motor in the endstation"""
-    ARPES_Motors.scan("th",start,stop,step,**kwargs)
-
-def dscanth(start,stop,step):
-    """relative scans of the th motor in the endstation """
-    ARPES_Motors.scan("th",start,stop,step,relative=True)
-
-### chi ###
-def mvchi(val,**kwargs):
-    """ moves chi motor in the endstation"""
-    ARPES_Motors.move('chi',val,**kwargs)
-
-def dmvchi(val):
-    """ relative chi motor in the endstation"""
-    ARPES_Motors.move('chi',val,relative=True)
-
-def scanchi(start,stop,step,**kwargs):
-    """ scans the chi motor in the endstation"""
-    ARPES_Motors.scan("chi",start,stop,step,**kwargs)
-
-def dscanchi(start,stop,step):
-    """relative scans of the chi motor in the endstation """
-    ARPES_Motors.scan("chi",start,stop,step,relative=True)
-
-### phi ###
-def mvphi(val,**kwargs):
-    """ moves phi motor in the endstation"""
-    ARPES_Motors.move('phi',val,**kwargs)
-
-def dmvphi(val):
-    """ relative phi motor in the endstation"""
-    ARPES_Motors.move('phi',val,relative=True)
-
-def scanphi(start,stop,step,**kwargs):
-    """ scans the phi motor in the endstation"""
-    ARPES_Motors.scan("phi",start,stop,step,**kwargs)
-
-def dscanphi(start,stop,step):
-    """relative scans of the phi motor in the endstation """
-    ARPES_Motors.scan("phi",start,stop,step,relative=True)
-
-
 def mvfocus(x_val):
     """ 
     Moves APPES x and compensates y motor so that the beam stays in the same sample position but the focus is moved
@@ -793,20 +687,3 @@ def ARPES_sample_map2D(step_y=0.5,step_z=0.5):
     print("Scan_ARPES_2Dmotor(\"y\",0,4,"+str(step_y)+",\"z\",12,16,"+str(step_z)+")")
     ARPES_Motors.scan2D(["y",0,4,step_y],["z",12,16,step_z])
 
-
-######## mprint and mvsample ###################
-def mprint():
-    """
-    prints current position of the physical motors
-    """
-    ARPES_Motors.mprint()
-
-def mvsample(position_list):
-    """
-    moves the sample to the position sepcified by position_list
-    position_list = ['description',x,y,z,th,chi,phi]
-
-    Previously: sample
-    """
-    ARPES_Motors.mvsample(position_list)
-
diff --git a/build/lib/iexcode/instruments/IEX_endstations.py b/build/lib/iexcode/instruments/IEX_endstations.py
index 2013e71..b24b05b 100644
--- a/build/lib/iexcode/instruments/IEX_endstations.py
+++ b/build/lib/iexcode/instruments/IEX_endstations.py
@@ -6,6 +6,7 @@ from tkinter.messagebox import NO
 from epics import caput
 
 from iexcode.instruments.scanRecord import ScanRecord
+
 import iexcode.instruments.cfg as iex
 
 """
@@ -16,6 +17,8 @@ it makes the default stuff work
 this will prompt for the endstation and will set the default parameters, look at the 
 init kwargs to see which defaults you can change.
 """
+#For new endstation modify here:
+endstations_list = ['ARPES','Kappa']   
 
 class Endstation:
     """
@@ -68,8 +71,8 @@ class Endstation:
         self.mda = ScanRecord(scan_ioc)
         self.Motors = Motors
 
-        global BL
-        endstations_list = ['ARPES','Kappa']   
+        #global BL here
+        
         BL_mode_list = ['user','staff']
 
         if endstation_name in endstations_list:
@@ -84,6 +87,7 @@ class Endstation:
 
             self.mode = BL_mode
             if BL_mode == 'user':
+                #For new endstation modify here:
                 if endstation_name == 'ARPES':
                     self.folder = 'c'
                     self.prefix = 'ARPES_'
@@ -96,15 +100,14 @@ class Endstation:
                     print('folder and prefix not set')
 
             elif BL_mode == 'staff':
-                self.folder = 'b' #overwrite folder for staff mode
+                #overwrite folder for staff mode
+                self.folder = 'b' 
                 self.prefix = endstation_name+"_"
         else:
             print('Not a valid BL_mode choice')
             print('BL_modes: '+BL_mode_list) 
             return  
 
-
-
     def set_logfile_path():
         """
         sets the default logfile path
diff --git a/build/lib/iexcode/instruments/Kappa.py b/build/lib/iexcode/instruments/Kappa.py
index eab7ca3..0f40c56 100644
--- a/build/lib/iexcode/instruments/Kappa.py
+++ b/build/lib/iexcode/instruments/Kappa.py
@@ -4,52 +4,65 @@ from math import floor
 
 from epics import caget, caput,PV
 
-#from iexcode.instruments.IEX_endstations import *
-import iexcode.instruments.IEX_endstations as iex
+import iexcode.instruments.cfg as iex
+from iexcode.instruments.IEX_endstations import Endstation
+
+iex.BL = Endstation(endstation_name,scan_ioc,xrays,BL_mode,Motors=None)
 
-from iexcode.instruments.staff import staff_detector_dictionary
 
+from iexcode.instruments.staff import staff_detector_dictionary
 from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda
 from iexcode.instruments.staff import staff_detector_dictionary
-from iexcode.instruments.Logfile import logfile_name_set,logfile_header
+from iexcode.instruments.xrays import xrays_detector_dictionary,xrays_reset,xrays_get_all
 
 from iexcode.instruments.conversions_constants import *
 from iexcode.instruments.utilities import *
-
 from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs, userCalcOut_clear
-from iexcode.instruments.scanRecord import ScanRecord
-#from iexcode.instruments.xrays import xrays_reset,xrays_get_all
 
 from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import SRS, ca_reset_all, Keithley_pv
 from iexcode.instruments.gate_valves import valve_close, branch_valves
 from iexcode.instruments.shutters import branch_shutter_close
-from iexcode.instruments.slits import slit3D_get
 
+#branch specific
+from iexcode.instruments.slits import slit3D_get
+#endstation specific
 from iexcode.instruments.Kappa_det import Kappa_Detector
 from iexcode.instruments.scalers import scaler_cts
 from iexcode.instruments.MPA import MPA
 from iexcode.instruments.spec_stuff import folders_spec
 
+default_ioc = '29idKappa:'
 
-global Kappa_Motors
-global tey, d3, d4, mesh, Kappa_scaler_pv, mpa
-global tthdet
+global tey, d3, d4, mesh, tthdet
 
-default_ioc = '29idKappa:'
 #############################################################################
-def Kappa_init(set_folders=False,reset=False,**kwargs):
+def Kappa_init(*userName,**kwargs):
     """
+    used to intialize the Endstation class which carries scanRecord, logging ... parameters
+    returns global detectors relavent to this endstation (tey,ca15)
 
-    set_folders: sets the mda and EA folders; default => False
-    reset: resets the scanRecord (detectors,triggers...)
-    **kwargs:
-        xrays: sets global variable; default => True
-        BL_mode: 'user' / 'staff' => used for saving, detectors... 
-    """
+        *userName is an optional parameter, will be prompted if set_folders=True
+
+        **kwargs:
+            set_folders: sets the mda and EA folders (default => True)  
+            reset: to reset the detectors in the IOC, etc (default => True)  
+            xrays: sets global variable and detectors for x-ray (default => True) 
+            mode: used sets the detectors 'user ' / 'staff' (default => 'user' )  
+     """
     kwargs.setdefault('scan_ioc',default_ioc)
     kwargs.setdefault('xrays',True)
     kwargs.setdefault('BL_mode','user')
+    kwargs.setdefault('set_folders',True)
+    kwargs.setdefault('reset',True)
+
+    #motors
+    physical_motors = ['x','y','z','tth','kth','kap','kphi']
+    psuedo_motors = ['th','chi','phi']
+    Kappa_Motors = Motors('Kappa',Kappa_motor_dictionary(),physical_motors,psuedo_motors)
+
+    #endstation
+    iex.BL = Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],ARPES_Motors)
 
     #scan
     if kwargs['BL_mode']=='staff':
@@ -60,8 +73,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs):
     mda_scanRecord = ScanRecord(kwargs['scan_ioc'],detector_dictionary,
     Kappa_trigger_dictionary(scan_ioc,scan_dim,),Kappa_scan_before_sequence(scan_ioc,scan_dim),Kappa_scan_after_sequence(scan_ioc,scan_dim))
 
-    #endstation
-    BL=Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],mda_scanRecord,Kappa_log_header,Kappa_log_entries)
+    
 
     #global detectors
     tey = SRS("29idMZ0:scaler1.S2", '29idd:A1')
@@ -70,8 +82,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs):
     mesh = SRS("29idMZ0:scaler1.S14", '29idd:A4')
     Kappa_scaler_pv = '29idMZ0:scaler1.CNT'
     tth_pv = Kappa_motor_dictionary('tth')[3]
-    mpa = MPA(tth_pv)
-
+    iex.mpa = MPA()
     tthdet = Kappa_Detector(Kappa_Motors)
 
     #setting folders
@@ -86,10 +97,6 @@ def Kappa_init(set_folders=False,reset=False,**kwargs):
     if 'reset':
         Kappa_reset()
 
-    #motors
-    physical_motors = ['x','y','z','tth','kth','kap','kphi']
-    psuedo_motors = ['th','chi','phi']
-    Kappa_Motors = Motors('Kappa',Kappa_motor_dictionary(),physical_motors,psuedo_motors)
 
 ##############################################################################################################
 ##############################                    detectors and motors                ##############################
@@ -258,8 +265,8 @@ def folders_Kappa(user_name,**kwargs):
     if kwargs["set_folders"]:
         # Set up MDA folder:
         folder_mda(run,iex.BL.folder,user_name,iex.BL.prefix,iex.BL.ioc)
-        logfile_name_set(iex.BL.endstation)
-        logfile_header(iex.BL.endstation,iex.BL.ioc,Kappa_log_header())
+        #logfile_name_set(iex.BL.endstation)
+        #logfile_header(iex.BL.endstation,iex.BL.ioc,Kappa_log_header())
 
 
         # Set up SPEC folder:
@@ -371,7 +378,7 @@ def Kappa_log_entries():
     tey_current = tey.current
     mesh_current = mesh.current
     det_name = tthdet.name
-    mpa_HV = mpa.HV_get()
+    mpa_HV = iex.mpa.HV_get()
     m3r_centroid = vals['kphi']
 
     entry_list = ["x","y","z","tth","kth","kap","kphi","TA","TB","TEY","mesh","det_name","mpa_HV","m3r_centroid"]
@@ -930,7 +937,7 @@ def Kappa_safe_state(**kwargs):
     
     if kwargs["mpa_off"]:
         try:
-            mpa.HV_off()
+            iex.mpa.HV_off()
         except:
             print('MPA is not running')
 
@@ -939,211 +946,4 @@ def Kappa_safe_state(**kwargs):
 
     if kwargs['shutter_close']:
         branch_shutter_close('d')
-    
-##############################################################################################################
-##############################              Kappa motors       ##############################
-##############################################################################################################
-### x ###
-def mvx(val,**kwargs):
-    """ moves x motor in the endstation"""
-    Kappa_Motors.move('x',val,**kwargs)
-
-def dmvx(val):
-    """ relative x motor in the endstation"""
-    Kappa_Motors.move('x',val,relative=True)
-
-def scanx(start,stop,step,**kwargs):
-    """ scans the x motor in the endstation"""
-    Kappa_Motors.scan("x",start,stop,step,**kwargs)
-
-def dscanx(start,stop,step):
-    """relative scans of the x motor in the endstation """
-    Kappa_Motors.scan("x",start,stop,step,relative=True)
-
-### y ###
-def mvy(val,**kwargs):
-    """ moves y motor in the endstation"""
-    Kappa_Motors.move('y',val,**kwargs)
-
-def dmvy(val):
-    """ relative y motor in the endstation"""
-    Kappa_Motors.move('y',val,relative=True)
-
-def scany(start,stop,step,**kwargs):
-    """ scans the y motor in the endstation"""
-    Kappa_Motors.scan("y",start,stop,step,**kwargs)
-
-def dscany(start,stop,step):
-    """relative scans of the y motor in the endstation """
-    Kappa_Motors.scan("y",start,stop,step,relative=True)
-
-### z ###
-def mvz(val,**kwargs):
-    """ moves z motor in the endstation"""
-    Kappa_Motors.move('z',val,**kwargs)
-
-def dmvz(val):
-    """ relative z motor in the endstation"""
-    Kappa_Motors.move('z',val,relative=True)
-
-def scanz(start,stop,step,**kwargs):
-    """ scans the z motor in the endstation"""
-    Kappa_Motors.scan("z",start,stop,step,**kwargs)
-
-def dscanz(start,stop,step):
-    """relative scans of the z motor in the endstation """
-    Kappa_Motors.scan("z",start,stop,step,relative=True)
-
-### kth ###
-def mvkth(val,**kwargs):
-    """ moves kth motor in the endstation"""
-    Kappa_Motors.move('kth',val,**kwargs)
-
-def dmvkth(val):
-    """ relative kth motor in the endstation"""
-    Kappa_Motors.move('kth',val,relative=True)
-
-def scankth(start,stop,step,**kwargs):
-    """ scans the kth motor in the endstation"""
-    Kappa_Motors.scan("kth",start,stop,step,**kwargs)
-
-def dscankth(start,stop,step):
-    """relative scans of the kth motor in the endstation """
-    Kappa_Motors.scan("kth",start,stop,step,relative=True)
-
-### kphi ###
-def mvkphi(val,**kwargs):
-    """ moves kphi motor in the endstation"""
-    Kappa_Motors.move('kphi',val,**kwargs)
-
-def dmvkphi(val):
-    """ relative kphi motor in the endstation"""
-    Kappa_Motors.move('kphi',val,relative=True)
-
-def scankphi(start,stop,step,**kwargs):
-    """ scans the kphi motor in the endstation"""
-    Kappa_Motors.scan("kphi",start,stop,step,**kwargs)
-
-def dscankphi(start,stop,step):
-    """relative scans of the kphi motor in the endstation """
-    Kappa_Motors.scan("kphi",start,stop,step,relative=True)   
-
-### kap ###
-def mvkap(val,**kwargs):
-    """ moves kap motor in the endstation"""
-    Kappa_Motors.move('kap',val,**kwargs)
-
-def dmvkap(val):
-    """ relative kap motor in the endstation"""
-    Kappa_Motors.move('kap',val,relative=True)
-
-def scankap(start,stop,step,**kwargs):
-    """ scans the kap motor in the endstation"""
-    Kappa_Motors.scan("kap",start,stop,step,**kwargs)
-
-def dscankap(start,stop,step):
-    """relative scans of the kap motor in the endstation """
-    Kappa_Motors.scan("kap",start,stop,step,relative=True)
-
-### tth ###
-def mvtth(val,**kwargs):
-    """ moves tth motor in the endstation"""
-    Kappa_Motors.move('tth',val,**kwargs)
-
-def dmvtth(val):
-    """ relative tth motor in the endstation"""
-    Kappa_Motors.move('tth',val,relative=True)
-
-def scantth(start,stop,step,**kwargs):
-    """ scans the tth motor in the endstation"""
-    Kappa_Motors.scan("tth",start,stop,step,**kwargs)
-
-def dscantth(start,stop,step):
-    """relative scans of the tth motor in the endstation """
-    Kappa_Motors.scan("tth",start,stop,step,relative=True)
-
-### th ###
-def mvth(val,**kwargs):
-    """ moves th motor in the endstation"""
-    Kappa_Motors.move('th',val,**kwargs)
-
-def dmvth(val):
-    """ relative th motor in the endstation"""
-    Kappa_Motors.move('th',val,relative=True)
-
-def scanth(start,stop,step,**kwargs):
-    """ scans the th motor in the endstation"""
-    Kappa_Motors.scan("th",start,stop,step,**kwargs)
-
-def dscanth(start,stop,step):
-    """relative scans of the th motor in the endstation """
-    Kappa_Motors.scan("th",start,stop,step,relative=True)
-
-### chi ###
-def mvchi(val,**kwargs):
-    """ moves chi motor in the endstation"""
-    Kappa_Motors.move('chi',val,**kwargs)
-
-def dmvchi(val):
-    """ relative chi motor in the endstation"""
-    Kappa_Motors.move('chi',val,relative=True)
-
-def scanchi(start,stop,step,**kwargs):
-    """ scans the chi motor in the endstation"""
-    Kappa_Motors.scan("chi",start,stop,step,**kwargs)
-
-def dscanchi(start,stop,step):
-    """relative scans of the chi motor in the endstation """
-    Kappa_Motors.scan("chi",start,stop,step,relative=True)
-
-### phi ###
-def mvphi(val,**kwargs):
-    """ moves phi motor in the endstation"""
-    Kappa_Motors.move('phi',val,**kwargs)
-
-def dmvphi(val):
-    """ relative phi motor in the endstation"""
-    Kappa_Motors.move('phi',val,relative=True)
-
-def scanphi(start,stop,step,**kwargs):
-    """ scans the phi motor in the endstation"""
-    Kappa_Motors.scan("phi",start,stop,step,**kwargs)
-
-def dscanphi(start,stop,step):
-    """relative scans of the phi motor in the endstation """
-    Kappa_Motors.scan("phi",start,stop,step,relative=True)
-
-### uan moves tth and th simultaneously 
-def uan(tth,th):
-    """ Moves tth and th motors simultaneously in the in the Kappa chamber
-    """
-    #move tth and th
-    mvth(th,wait=False)
-    mvtth(tth,wait=False)
-    sleep(0.2)     
-
-    while True:
-        status = Kappa_Motors.status()
-        if status == 0:
-            sleep(0.2)
-        else:
-            tth_RBV=round(Kappa_Motors.get('tth',verbose=False),3)
-            th_RBV=round(Kappa_Motors.get('th',verbose=False),3)
-            print('tth='+str(tth_RBV)+' th='+str(th_RBV))
-            break
-
-######## mprint and mvsample ###################
-def mprint():
-    """
-    prints current position of the physical motors
-    """
-    Kappa_Motors.mprint()
-
-def mvsample(position_list):
-    """
-    moves the sample to the position sepcified by position_list
-    position_list = ['description',x,y,z,th,chi,phi]
-
-    Previously: sample
-    """
-    Kappa_Motors.mvsample(position_list)
\ No newline at end of file
+    
\ No newline at end of file
diff --git a/build/lib/iexcode/instruments/Motors.py b/build/lib/iexcode/instruments/Motors.py
index fb75d61..43229d9 100644
--- a/build/lib/iexcode/instruments/Motors.py
+++ b/build/lib/iexcode/instruments/Motors.py
@@ -3,14 +3,15 @@ from math import floor
 
 from epics import caget, caput
 
-#from iexcode.instruments.IEX_endstations import *
-#import iexcode.instruments.IEX_endstations as iex
 import iexcode.instruments.cfg as iex
 
+from iexcode.instruments.utilities import print_warning_message
 from iexcode.instruments.scalers import scaler_cts
 
 
-
+##############################################################################################################
+##############################            Motor Class        ##############################
+##############################################################################################################
 class Motors:
     """ 
     short hand to move motors in endstation
@@ -165,8 +166,12 @@ class Motors:
         #for kappa only
         kwargs.setdefault('cts',0.1)
         kwargs.setdefault('mpa',False)
-
-        rbv_pv,val_pv,sgm_pv,pv =self._motor_dictionary[name]
+        motor_pvs = self._motor_dictionary.get(name)
+        if motor_pvs:
+            rbv_pv,val_pv,sgm_pv,pv = motor_pvs
+        else:#here
+            print_warning_message('motor = "'+str(name)+'" is not defined for '+iex.BL.endstation)
+            return
 
         if kwargs['relative']:
             current_value = caget(rbv_pv)
@@ -241,3 +246,212 @@ class Motors:
 
 
 
+##############################################################################################################
+##############################            Motor Short Names         ##############################
+##############################################################################################################
+### x ###
+def mvx(val,**kwargs):
+    """ moves x motor in the endstation"""
+    iex.BL.Motors.move('x',val,**kwargs)
+
+def dmvx(val):
+    """ relative x motor in the endstation"""
+    iex.BL.Motors.move('x',val,relative=True)
+
+def scanx(start,stop,step,**kwargs):
+    """ scans the x motor in the endstation"""
+    iex.BL.Motors.scan("x",start,stop,step,**kwargs)
+
+def dscanx(start,stop,step):
+    """relative scans of the x motor in the endstation """
+    iex.BL.Motors.scan("x",start,stop,step,relative=True)
+
+### y ###
+def mvy(val,**kwargs):
+    """ moves y motor in the endstation"""
+    iex.BL.Motors.move('y',val,**kwargs)
+
+def dmvy(val):
+    """ relative y motor in the endstation"""
+    iex.BL.Motors.move('y',val,relative=True)
+
+def scany(start,stop,step,**kwargs):
+    """ scans the y motor in the endstation"""
+    iex.BL.Motors.scan("y",start,stop,step,**kwargs)
+
+def dscany(start,stop,step):
+    """relative scans of the y motor in the endstation """
+    iex.BL.Motors.scan("y",start,stop,step,relative=True)
+
+### z ###
+def mvz(val,**kwargs):
+    """ moves z motor in the endstation"""
+    iex.BL.Motors.move('z',val,**kwargs)
+
+def dmvz(val):
+    """ relative z motor in the endstation"""
+    iex.BL.Motors.move('z',val,relative=True)
+
+def scanz(start,stop,step,**kwargs):
+    """ scans the z motor in the endstation"""
+    iex.BL.Motors.scan("z",start,stop,step,**kwargs)
+
+def dscanz(start,stop,step):
+    """relative scans of the z motor in the endstation """
+    iex.BL.Motors.scan("z",start,stop,step,relative=True)
+
+### kth ###
+def mvkth(val,**kwargs):
+    """ moves kth motor in the endstation"""
+    iex.BL.Motors.move('kth',val,**kwargs)
+
+def dmvkth(val):
+    """ relative kth motor in the endstation"""
+    iex.BL.Motors.move('kth',val,relative=True)
+
+def scankth(start,stop,step,**kwargs):
+    """ scans the kth motor in the endstation"""
+    iex.BL.Motors.scan("kth",start,stop,step,**kwargs)
+
+def dscankth(start,stop,step):
+    """relative scans of the kth motor in the endstation """
+    iex.BL.Motors.scan("kth",start,stop,step,relative=True)
+
+### kphi ###
+def mvkphi(val,**kwargs):
+    """ moves kphi motor in the endstation"""
+    iex.BL.Motors.move('kphi',val,**kwargs)
+
+def dmvkphi(val):
+    """ relative kphi motor in the endstation"""
+    iex.BL.Motors.move('kphi',val,relative=True)
+
+def scankphi(start,stop,step,**kwargs):
+    """ scans the kphi motor in the endstation"""
+    iex.BL.Motors.scan("kphi",start,stop,step,**kwargs)
+
+def dscankphi(start,stop,step):
+    """relative scans of the kphi motor in the endstation """
+    iex.BL.Motors.scan("kphi",start,stop,step,relative=True)   
+
+### kap ###
+def mvkap(val,**kwargs):
+    """ moves kap motor in the endstation"""
+    iex.BL.Motors.move('kap',val,**kwargs)
+
+def dmvkap(val):
+    """ relative kap motor in the endstation"""
+    iex.BL.Motors.move('kap',val,relative=True)
+
+def scankap(start,stop,step,**kwargs):
+    """ scans the kap motor in the endstation"""
+    iex.BL.Motors.scan("kap",start,stop,step,**kwargs)
+
+def dscankap(start,stop,step):
+    """relative scans of the kap motor in the endstation """
+    iex.BL.Motors.scan("kap",start,stop,step,relative=True)
+
+### tth ###
+def mvtth(val,**kwargs):
+    """ moves tth motor in the endstation"""
+    iex.BL.Motors.move('tth',val,**kwargs)
+
+def dmvtth(val):
+    """ relative tth motor in the endstation"""
+    iex.BL.Motors.move('tth',val,relative=True)
+
+def scantth(start,stop,step,**kwargs):
+    """ scans the tth motor in the endstation"""
+    iex.BL.Motors.scan("tth",start,stop,step,**kwargs)
+
+def dscantth(start,stop,step):
+    """relative scans of the tth motor in the endstation """
+    iex.BL.Motors.scan("tth",start,stop,step,relative=True)
+
+### th ###
+def mvth(val,**kwargs):
+    """ moves th motor in the endstation"""
+    iex.BL.Motors.move('th',val,**kwargs)
+
+def dmvth(val):
+    """ relative th motor in the endstation"""
+    iex.BL.Motors.move('th',val,relative=True)
+
+def scanth(start,stop,step,**kwargs):
+    """ scans the th motor in the endstation"""
+    iex.BL.Motors.scan("th",start,stop,step,**kwargs)
+
+def dscanth(start,stop,step):
+    """relative scans of the th motor in the endstation """
+    iex.BL.Motors.scan("th",start,stop,step,relative=True)
+
+### chi ###
+def mvchi(val,**kwargs):
+    """ moves chi motor in the endstation"""
+    iex.BL.Motors.move('chi',val,**kwargs)
+
+def dmvchi(val):
+    """ relative chi motor in the endstation"""
+    iex.BL.Motors.move('chi',val,relative=True)
+
+def scanchi(start,stop,step,**kwargs):
+    """ scans the chi motor in the endstation"""
+    iex.BL.Motors.scan("chi",start,stop,step,**kwargs)
+
+def dscanchi(start,stop,step):
+    """relative scans of the chi motor in the endstation """
+    iex.BL.Motors.scan("chi",start,stop,step,relative=True)
+
+### phi ###
+def mvphi(val,**kwargs):
+    """ moves phi motor in the endstation"""
+    iex.BL.Motors.move('phi',val,**kwargs)
+
+def dmvphi(val):
+    """ relative phi motor in the endstation"""
+    iex.BL.Motors.move('phi',val,relative=True)
+
+def scanphi(start,stop,step,**kwargs):
+    """ scans the phi motor in the endstation"""
+    iex.BL.Motors.scan("phi",start,stop,step,**kwargs)
+
+def dscanphi(start,stop,step):
+    """relative scans of the phi motor in the endstation """
+    iex.BL.Motors.scan("phi",start,stop,step,relative=True)
+
+### uan moves tth and th simultaneously 
+def uan(tth,th):
+    """ Moves tth and th motors simultaneously in the in the Kappa chamber
+    """
+    if iex.BL.endstation == 'Kappa':
+        #move tth and th
+        mvth(th,wait=False)
+        mvtth(tth,wait=False)
+        sleep(0.2)     
+
+        while True:
+            status = iex.BL.Motors.status()
+            if status == 0:
+                sleep(0.2)
+            else:
+                tth_RBV=round(iex.BL.Motors.get('tth',verbose=False),3)
+                th_RBV=round(iex.BL.Motors.get('th',verbose=False),3)
+                print('tth='+str(tth_RBV)+' th='+str(th_RBV))
+                break
+    else:
+        print("not a defined move")
+######## mprint and mvsample ###################
+def mprint():
+    """
+    prints current position of the physical motors
+    """
+    iex.BL.Motors.mprint()
+
+def mvsample(position_list):
+    """
+    moves the sample to the position sepcified by position_list
+    position_list = ['description',x,y,z,th,chi,phi]
+
+    Previously: sample
+    """
+    iex.BL.Motors.mvsample(position_list)
\ No newline at end of file
diff --git a/build/lib/iexcode/instruments/beamline.py b/build/lib/iexcode/instruments/beamline.py
index 7981938..f8de3a0 100644
--- a/build/lib/iexcode/instruments/beamline.py
+++ b/build/lib/iexcode/instruments/beamline.py
@@ -9,80 +9,12 @@ from time import sleep
 
 from epics import PV
 
-#from iexcode.instruments.IEX_endstations import *
-#import iexcode.instruments.IEX_endstations as iex
 import iexcode.instruments.cfg as iex
 
-##############################################################################################################
-##############################             logging           ##############################
-##############################################################################################################
-def log_print(comment=''):
-    """
-    prints a comment to the logfile
-    """
-    #global BL
-    try:
-        iex.BL.mda.log.print(comment='')
-    except:
-        print('No logfile written')
-
-def log_update():
-    """
-    updates the log file with the last scan info
-    """
-    #global BL
-    try:
-        entry_list,pv_list, format_list = iex.BLlog.entries_function()
-        iex.BL.mda.log.update(entry_list,pv_list,format_list)
-    except:
-        print('No logfile written')
-
-def log_name_set(file_name):
-    #global BL
-    try: 
-        iex.BL.mda.log.name_set(filename=file_name)
-    except:
-        print('No logfile name change')
     
 
 
 
-##############################################################################################################
-###########################                      Scan stuff                     ######################
-##############################################################################################################
-def scan_fillin(VAL,RBV,start,stop,steps_points,**kwargs):
-    """
-    fills in the scan record for the curretn beamline ioc
-    """
-    iex.BL.mda.fillin(VAL,RBV,start,stop,steps_points,**kwargs)
-
-def scan_fillin_table(VAL,RBV,my_table,**kwargs):
-    """
-    fills in the scan record for the curretn beamline ioc
-    """
-    iex.BL.mda.fillin_table(VAL,RBV,my_table,**kwargs)
-
-def scan_go(**kwargs):
-    """
-    Starts a scan 
-    by default: scanDIM=1  
-    Logging is automatic: use **kwargs or the optional logging arguments see scanlog() for details
-    kwargs:
-        X-ray = True (default), does shutter checks
-             = False no shutter checks
-    """
-    iex.BL.mda.go(verbose=True,**kwargs)
-
-
-def last_mda():
-    """
-    returns the last mda file number in the ioc defined by BL_ioc
-    Previously: LastMDA
-    """
-    filenum = iex.BL.mda.lastFileNum()
-    return filenum
-
-
 
 ##############################################################################################################
 ##############################               Beeper          ##############################
diff --git a/build/lib/iexcode/instruments/scalers.py b/build/lib/iexcode/instruments/scalers.py
index 1ae03b5..9f608be 100644
--- a/build/lib/iexcode/instruments/scalers.py
+++ b/build/lib/iexcode/instruments/scalers.py
@@ -1,7 +1,7 @@
 from math import floor
 
 from epics import caput,PV
-#import iexcode.instruments.IEX_endstations as iex
+
 import iexcode.instruments.cfg as iex
 
 def scaler_cts(time_seconds=0.1,verbose=True):
diff --git a/build/lib/iexcode/instruments/scanRecord.py b/build/lib/iexcode/instruments/scanRecord.py
index 3d4e9d9..566a82d 100644
--- a/build/lib/iexcode/instruments/scanRecord.py
+++ b/build/lib/iexcode/instruments/scanRecord.py
@@ -4,10 +4,56 @@ import time
 
 from epics import caget, caput, PV
 
+import iexcode.instruments.cfg as iex
+
 from iexcode.instruments.utilities import dateandtime, print_warning_message
 from iexcode.instruments.userCalcs import userStringSeq_pvs,userStringSeq_clear
 
 
+def scan_fillin(VAL,RBV,start,stop,steps_points,**kwargs):
+    """
+    fills in the scan record for the curretn beamline ioc
+    """
+    try:
+        iex.BL.mda.fillin(VAL,RBV,start,stop,steps_points,**kwargs)
+    except:
+        print("IEX_endstations has not been initialized")
+
+def scan_fillin_table(VAL,RBV,my_table,**kwargs):
+    """
+    fills in the scan record for the curretn beamline ioc
+    """
+    try:
+        iex.BL.mda.fillin_table(VAL,RBV,my_table,**kwargs)
+    except:
+        print("IEX_endstations has not been initialized")  
+
+def scan_go(**kwargs):
+    """
+    Starts a scan 
+    by default: scanDIM=1  
+    Logging is automatic: use **kwargs or the optional logging arguments see scanlog() for details
+    kwargs:
+        X-ray = True (default), does shutter checks
+             = False no shutter checks
+    """
+    try:
+        iex.BL.mda.go(verbose=True,**kwargs)
+    except:
+        print("IEX_endstations has not been initialized")
+
+
+def last_mda():
+    """
+    returns the last mda file number in the ioc defined by BL_ioc
+    Previously: LastMDA
+    """
+    try:
+        filenum = iex.BL.mda.lastFileNum()
+        return filenum
+    except:
+        print("IEX_endstations has not been initialized")
+
 def saveData_get_all(ioc_pv):
     """
     returns saveData info: 
@@ -33,7 +79,9 @@ def saveData_get_all(ioc_pv):
 
    
     
-
+##############################################################################################################
+###########################                      Scan class                     ######################
+##############################################################################################################
 default_positioner_settling_time = 0.05
 default_detector_settling_time = 0.1
 
diff --git a/build/lib/iexcode/instruments/xrays.py b/build/lib/iexcode/instruments/xrays.py
index 62bf9d9..783f6bc 100644
--- a/build/lib/iexcode/instruments/xrays.py
+++ b/build/lib/iexcode/instruments/xrays.py
@@ -6,8 +6,7 @@ import numpy as np
 from time import sleep
 
 from epics import caget,caput
-#from iexcode.instruments.IEX_endstations import *
-#import iexcode.instruments.IEX_endstations as iex
+
 import iexcode.instruments.cfg as iex
 
 from iexcode.instruments.IEX_VPU import *
@@ -17,22 +16,22 @@ from iexcode.instruments.shutters import *
 from iexcode.instruments.gate_valves import *
 from iexcode.instruments.diagnostics import *
 from iexcode.instruments.m3r import *
-#from iexcode.instruments.Logfile import *
+from iexcode.instruments.beamline import endstation_cams_enable
 from iexcode.instruments.utilities import print_warning_message,make_table, take_closest_value
 from iexcode.instruments.current_amplifiers import ca_average
-from iexcode.instruments.beamline import endstation_cams_enable
-
-from iexcode.instruments.MPA import MPA
+from iexcode.instruments.Logfile import log_update
 
+mpa = iex.mpa
 
 ##############################################################################################################
 ##############################            resets and detector lists         ##############################
 ##############################################################################################################
-def test_function():
-    print('hello world')
-    
-def xrays_reset():
+def xrays_reset(verbose=True):
+    if verbose:
+        print("resetting the mono limits")
     mono_limits_reset()
+    if verbose:
+        print("resetting beamline encoders")
     xray_motor_encoder_sync()
 
 
@@ -181,7 +180,7 @@ def xrays_log_entries(**kwargs):
     format_list.append("s","s")
 
     try:
-        logfile_update(iex.BL.endstation,iex.BL.ioc,entry_list,pv_list,format_list)
+        log_update(iex.BL.endstation,iex.BL.ioc,entry_list,pv_list,format_list)
     except:
         print("scanlog did not write to file, check for errors.")
         
@@ -427,7 +426,6 @@ def scanXAS(ID_eV,start_stop_step_lists,**kwargs):
     kwargs.setdefault("mcp",True)    
     kwargs.setdefault('execute',True)   
 
-    #global BL
     scan_dim=kwargs['scan_dim']
     
     #Setting up the ScanRecord for Mono in Table mode
@@ -443,8 +441,8 @@ def scanXAS(ID_eV,start_stop_step_lists,**kwargs):
     energy(ID_eV,m3r=kwargs["m3r"])
 
     #mpa
-    if iex.BL.branch == "d" and kwargs["mcp"]:
-        mpa_HV_on()
+    if iex.BL.endstation == "Kappa" and kwargs["mcp"]:
+        mpa.HV_on()
 
     #Scanning
     if kwargs['execute']:
@@ -456,9 +454,9 @@ def scanXAS(ID_eV,start_stop_step_lists,**kwargs):
         mono_scan_after(BL.mda,scan_dim)
         BL.mda.table_reset_after(scan_dim)
 
-        if BL.branch == "d": 
+        if BL.endstation == "Kappa": 
             if kwargs["mcp"]: 
-                mpa_HV_off()
+                mpa.HV_off()
             print("WARNING: Mesh"+BL.branch+" is still In")        
 
 def scanXAS_BL(start_stop_step_lists,**kwargs):
@@ -508,8 +506,8 @@ def scanXAS_BL(start_stop_step_lists,**kwargs):
     slits_set_BL(mono_array[0],m3r=kwargs["m3r"])
 
     #mpa
-    if BL.branch == "d" and kwargs["mcp"]:
-        mpa_HV_on()
+    if BL.endstation == "Kappa" and kwargs["mcp"]:
+        mpa.HV_on()
         
     #Scanning
     if kwargs['execute']:
@@ -522,9 +520,9 @@ def scanXAS_BL(start_stop_step_lists,**kwargs):
         mono_scan_after(BL.mda,scan_dim)
         BL.mda.table_reset_after(scan_dim)
 
-        if BL.branch == "d": 
+        if BL.endstation == "Kappa": 
             if kwargs["mcp"]: 
-                mpa_HV_off()
+                mpa.HV_off()
             print("WARNING: Mesh"+BL.branch+" is still In")  
 
 def BL_energy_tables(start_stop_step_lists):
diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py
index 333e956..c256ea7 100644
--- a/iexcode/instruments/ARPES.py
+++ b/iexcode/instruments/ARPES.py
@@ -18,12 +18,15 @@ from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import *
 from iexcode.instruments.gate_valves import valve_close, branch_valves
 from iexcode.instruments.shutters import branch_shutter_close
-from iexcode.instruments.slits import slit3C_get
 
+#branch specific
+from iexcode.instruments.slits import slit3C_get
+#endstation specific
 from iexcode.instruments.Lakeshore_335 import Lakeshore_reset
 from iexcode.instruments.electron_analyzer import EA_init_Motors,folders_EA,EA
 
 default_ioc = '29idARPES:'
+#detector objects used with in module and returned by init
 global tey, ca15
 
 #############################################################################
@@ -638,109 +641,6 @@ def ARPES_safe_state(**kwargs):
 ##############################################################################################################
 ##############################              ARPES motors       ##############################
 ##############################################################################################################
-### x ###
-def mvx(val,**kwargs):
-    """ moves x motor in the endstation"""
-    ARPES_Motors.move('x',val,**kwargs)
-
-def dmvx(val):
-    """ relative x motor in the endstation"""
-    ARPES_Motors.move('x',val,relative=True)
-
-def scanx(start,stop,step,**kwargs):
-    """ scans the x motor in the endstation"""
-    ARPES_Motors.scan("x",start,stop,step,**kwargs)
-
-def dscanx(start,stop,step):
-    """relative scans of the x motor in the endstation """
-    ARPES_Motors.scan("x",start,stop,step,relative=True)
-
-### y ###
-def mvy(val,**kwargs):
-    """ moves y motor in the endstation"""
-    ARPES_Motors.move('y',val,**kwargs)
-
-def dmvy(val):
-    """ relative y motor in the endstation"""
-    ARPES_Motors.move('y',val,relative=True)
-
-def scany(start,stop,step,**kwargs):
-    """ scans the y motor in the endstation"""
-    ARPES_Motors.scan("y",start,stop,step,**kwargs)
-
-def dscany(start,stop,step):
-    """relative scans of the y motor in the endstation """
-    ARPES_Motors.scan("y",start,stop,step,relative=True)
-
-### z ###
-def mvz(val,**kwargs):
-    """ moves z motor in the endstation"""
-    ARPES_Motors.move('z',val,**kwargs)
-
-def dmvz(val):
-    """ relative z motor in the endstation"""
-    ARPES_Motors.move('z',val,relative=True)
-
-def scanz(start,stop,step,**kwargs):
-    """ scans the z motor in the endstation"""
-    ARPES_Motors.scan("z",start,stop,step,**kwargs)
-
-def dscanz(start,stop,step):
-    """relative scans of the z motor in the endstation """
-    ARPES_Motors.scan("z",start,stop,step,relative=True)
-
-### th ###
-def mvth(val,**kwargs):
-    """ moves th motor in the endstation"""
-    ARPES_Motors.move('th',val,**kwargs)
-
-def dmvth(val):
-    """ relative th motor in the endstation"""
-    ARPES_Motors.move('th',val,relative=True)
-
-def scanth(start,stop,step,**kwargs):
-    """ scans the th motor in the endstation"""
-    ARPES_Motors.scan("th",start,stop,step,**kwargs)
-
-def dscanth(start,stop,step):
-    """relative scans of the th motor in the endstation """
-    ARPES_Motors.scan("th",start,stop,step,relative=True)
-
-### chi ###
-def mvchi(val,**kwargs):
-    """ moves chi motor in the endstation"""
-    ARPES_Motors.move('chi',val,**kwargs)
-
-def dmvchi(val):
-    """ relative chi motor in the endstation"""
-    ARPES_Motors.move('chi',val,relative=True)
-
-def scanchi(start,stop,step,**kwargs):
-    """ scans the chi motor in the endstation"""
-    ARPES_Motors.scan("chi",start,stop,step,**kwargs)
-
-def dscanchi(start,stop,step):
-    """relative scans of the chi motor in the endstation """
-    ARPES_Motors.scan("chi",start,stop,step,relative=True)
-
-### phi ###
-def mvphi(val,**kwargs):
-    """ moves phi motor in the endstation"""
-    ARPES_Motors.move('phi',val,**kwargs)
-
-def dmvphi(val):
-    """ relative phi motor in the endstation"""
-    ARPES_Motors.move('phi',val,relative=True)
-
-def scanphi(start,stop,step,**kwargs):
-    """ scans the phi motor in the endstation"""
-    ARPES_Motors.scan("phi",start,stop,step,**kwargs)
-
-def dscanphi(start,stop,step):
-    """relative scans of the phi motor in the endstation """
-    ARPES_Motors.scan("phi",start,stop,step,relative=True)
-
-
 def mvfocus(x_val):
     """ 
     Moves APPES x and compensates y motor so that the beam stays in the same sample position but the focus is moved
@@ -787,20 +687,3 @@ def ARPES_sample_map2D(step_y=0.5,step_z=0.5):
     print("Scan_ARPES_2Dmotor(\"y\",0,4,"+str(step_y)+",\"z\",12,16,"+str(step_z)+")")
     ARPES_Motors.scan2D(["y",0,4,step_y],["z",12,16,step_z])
 
-
-######## mprint and mvsample ###################
-def mprint():
-    """
-    prints current position of the physical motors
-    """
-    ARPES_Motors.mprint()
-
-def mvsample(position_list):
-    """
-    moves the sample to the position sepcified by position_list
-    position_list = ['description',x,y,z,th,chi,phi]
-
-    Previously: sample
-    """
-    ARPES_Motors.mvsample(position_list)
-
diff --git a/iexcode/instruments/IEX_endstations.py b/iexcode/instruments/IEX_endstations.py
index 02c8c14..b24b05b 100644
--- a/iexcode/instruments/IEX_endstations.py
+++ b/iexcode/instruments/IEX_endstations.py
@@ -17,6 +17,8 @@ it makes the default stuff work
 this will prompt for the endstation and will set the default parameters, look at the 
 init kwargs to see which defaults you can change.
 """
+#For new endstation modify here:
+endstations_list = ['ARPES','Kappa']   
 
 class Endstation:
     """
@@ -69,8 +71,8 @@ class Endstation:
         self.mda = ScanRecord(scan_ioc)
         self.Motors = Motors
 
-        global BL
-        endstations_list = ['ARPES','Kappa']   
+        #global BL here
+        
         BL_mode_list = ['user','staff']
 
         if endstation_name in endstations_list:
@@ -85,6 +87,7 @@ class Endstation:
 
             self.mode = BL_mode
             if BL_mode == 'user':
+                #For new endstation modify here:
                 if endstation_name == 'ARPES':
                     self.folder = 'c'
                     self.prefix = 'ARPES_'
@@ -97,15 +100,14 @@ class Endstation:
                     print('folder and prefix not set')
 
             elif BL_mode == 'staff':
-                self.folder = 'b' #overwrite folder for staff mode
+                #overwrite folder for staff mode
+                self.folder = 'b' 
                 self.prefix = endstation_name+"_"
         else:
             print('Not a valid BL_mode choice')
             print('BL_modes: '+BL_mode_list) 
             return  
 
-
-
     def set_logfile_path():
         """
         sets the default logfile path
diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py
index eab7ca3..0f40c56 100644
--- a/iexcode/instruments/Kappa.py
+++ b/iexcode/instruments/Kappa.py
@@ -4,52 +4,65 @@ from math import floor
 
 from epics import caget, caput,PV
 
-#from iexcode.instruments.IEX_endstations import *
-import iexcode.instruments.IEX_endstations as iex
+import iexcode.instruments.cfg as iex
+from iexcode.instruments.IEX_endstations import Endstation
+
+iex.BL = Endstation(endstation_name,scan_ioc,xrays,BL_mode,Motors=None)
 
-from iexcode.instruments.staff import staff_detector_dictionary
 
+from iexcode.instruments.staff import staff_detector_dictionary
 from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda
 from iexcode.instruments.staff import staff_detector_dictionary
-from iexcode.instruments.Logfile import logfile_name_set,logfile_header
+from iexcode.instruments.xrays import xrays_detector_dictionary,xrays_reset,xrays_get_all
 
 from iexcode.instruments.conversions_constants import *
 from iexcode.instruments.utilities import *
-
 from iexcode.instruments.userCalcs import userStringSeq_clear, userStringSeq_pvs, userCalcOut_clear
-from iexcode.instruments.scanRecord import ScanRecord
-#from iexcode.instruments.xrays import xrays_reset,xrays_get_all
 
 from iexcode.instruments.Motors import Motors
 from iexcode.instruments.current_amplifiers import SRS, ca_reset_all, Keithley_pv
 from iexcode.instruments.gate_valves import valve_close, branch_valves
 from iexcode.instruments.shutters import branch_shutter_close
-from iexcode.instruments.slits import slit3D_get
 
+#branch specific
+from iexcode.instruments.slits import slit3D_get
+#endstation specific
 from iexcode.instruments.Kappa_det import Kappa_Detector
 from iexcode.instruments.scalers import scaler_cts
 from iexcode.instruments.MPA import MPA
 from iexcode.instruments.spec_stuff import folders_spec
 
+default_ioc = '29idKappa:'
 
-global Kappa_Motors
-global tey, d3, d4, mesh, Kappa_scaler_pv, mpa
-global tthdet
+global tey, d3, d4, mesh, tthdet
 
-default_ioc = '29idKappa:'
 #############################################################################
-def Kappa_init(set_folders=False,reset=False,**kwargs):
+def Kappa_init(*userName,**kwargs):
     """
+    used to intialize the Endstation class which carries scanRecord, logging ... parameters
+    returns global detectors relavent to this endstation (tey,ca15)
 
-    set_folders: sets the mda and EA folders; default => False
-    reset: resets the scanRecord (detectors,triggers...)
-    **kwargs:
-        xrays: sets global variable; default => True
-        BL_mode: 'user' / 'staff' => used for saving, detectors... 
-    """
+        *userName is an optional parameter, will be prompted if set_folders=True
+
+        **kwargs:
+            set_folders: sets the mda and EA folders (default => True)  
+            reset: to reset the detectors in the IOC, etc (default => True)  
+            xrays: sets global variable and detectors for x-ray (default => True) 
+            mode: used sets the detectors 'user ' / 'staff' (default => 'user' )  
+     """
     kwargs.setdefault('scan_ioc',default_ioc)
     kwargs.setdefault('xrays',True)
     kwargs.setdefault('BL_mode','user')
+    kwargs.setdefault('set_folders',True)
+    kwargs.setdefault('reset',True)
+
+    #motors
+    physical_motors = ['x','y','z','tth','kth','kap','kphi']
+    psuedo_motors = ['th','chi','phi']
+    Kappa_Motors = Motors('Kappa',Kappa_motor_dictionary(),physical_motors,psuedo_motors)
+
+    #endstation
+    iex.BL = Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],ARPES_Motors)
 
     #scan
     if kwargs['BL_mode']=='staff':
@@ -60,8 +73,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs):
     mda_scanRecord = ScanRecord(kwargs['scan_ioc'],detector_dictionary,
     Kappa_trigger_dictionary(scan_ioc,scan_dim,),Kappa_scan_before_sequence(scan_ioc,scan_dim),Kappa_scan_after_sequence(scan_ioc,scan_dim))
 
-    #endstation
-    BL=Endstation('Kappa',kwargs['scan_ioc'],kwargs['xrays'],kwargs['BL_mode'],mda_scanRecord,Kappa_log_header,Kappa_log_entries)
+    
 
     #global detectors
     tey = SRS("29idMZ0:scaler1.S2", '29idd:A1')
@@ -70,8 +82,7 @@ def Kappa_init(set_folders=False,reset=False,**kwargs):
     mesh = SRS("29idMZ0:scaler1.S14", '29idd:A4')
     Kappa_scaler_pv = '29idMZ0:scaler1.CNT'
     tth_pv = Kappa_motor_dictionary('tth')[3]
-    mpa = MPA(tth_pv)
-
+    iex.mpa = MPA()
     tthdet = Kappa_Detector(Kappa_Motors)
 
     #setting folders
@@ -86,10 +97,6 @@ def Kappa_init(set_folders=False,reset=False,**kwargs):
     if 'reset':
         Kappa_reset()
 
-    #motors
-    physical_motors = ['x','y','z','tth','kth','kap','kphi']
-    psuedo_motors = ['th','chi','phi']
-    Kappa_Motors = Motors('Kappa',Kappa_motor_dictionary(),physical_motors,psuedo_motors)
 
 ##############################################################################################################
 ##############################                    detectors and motors                ##############################
@@ -258,8 +265,8 @@ def folders_Kappa(user_name,**kwargs):
     if kwargs["set_folders"]:
         # Set up MDA folder:
         folder_mda(run,iex.BL.folder,user_name,iex.BL.prefix,iex.BL.ioc)
-        logfile_name_set(iex.BL.endstation)
-        logfile_header(iex.BL.endstation,iex.BL.ioc,Kappa_log_header())
+        #logfile_name_set(iex.BL.endstation)
+        #logfile_header(iex.BL.endstation,iex.BL.ioc,Kappa_log_header())
 
 
         # Set up SPEC folder:
@@ -371,7 +378,7 @@ def Kappa_log_entries():
     tey_current = tey.current
     mesh_current = mesh.current
     det_name = tthdet.name
-    mpa_HV = mpa.HV_get()
+    mpa_HV = iex.mpa.HV_get()
     m3r_centroid = vals['kphi']
 
     entry_list = ["x","y","z","tth","kth","kap","kphi","TA","TB","TEY","mesh","det_name","mpa_HV","m3r_centroid"]
@@ -930,7 +937,7 @@ def Kappa_safe_state(**kwargs):
     
     if kwargs["mpa_off"]:
         try:
-            mpa.HV_off()
+            iex.mpa.HV_off()
         except:
             print('MPA is not running')
 
@@ -939,211 +946,4 @@ def Kappa_safe_state(**kwargs):
 
     if kwargs['shutter_close']:
         branch_shutter_close('d')
-    
-##############################################################################################################
-##############################              Kappa motors       ##############################
-##############################################################################################################
-### x ###
-def mvx(val,**kwargs):
-    """ moves x motor in the endstation"""
-    Kappa_Motors.move('x',val,**kwargs)
-
-def dmvx(val):
-    """ relative x motor in the endstation"""
-    Kappa_Motors.move('x',val,relative=True)
-
-def scanx(start,stop,step,**kwargs):
-    """ scans the x motor in the endstation"""
-    Kappa_Motors.scan("x",start,stop,step,**kwargs)
-
-def dscanx(start,stop,step):
-    """relative scans of the x motor in the endstation """
-    Kappa_Motors.scan("x",start,stop,step,relative=True)
-
-### y ###
-def mvy(val,**kwargs):
-    """ moves y motor in the endstation"""
-    Kappa_Motors.move('y',val,**kwargs)
-
-def dmvy(val):
-    """ relative y motor in the endstation"""
-    Kappa_Motors.move('y',val,relative=True)
-
-def scany(start,stop,step,**kwargs):
-    """ scans the y motor in the endstation"""
-    Kappa_Motors.scan("y",start,stop,step,**kwargs)
-
-def dscany(start,stop,step):
-    """relative scans of the y motor in the endstation """
-    Kappa_Motors.scan("y",start,stop,step,relative=True)
-
-### z ###
-def mvz(val,**kwargs):
-    """ moves z motor in the endstation"""
-    Kappa_Motors.move('z',val,**kwargs)
-
-def dmvz(val):
-    """ relative z motor in the endstation"""
-    Kappa_Motors.move('z',val,relative=True)
-
-def scanz(start,stop,step,**kwargs):
-    """ scans the z motor in the endstation"""
-    Kappa_Motors.scan("z",start,stop,step,**kwargs)
-
-def dscanz(start,stop,step):
-    """relative scans of the z motor in the endstation """
-    Kappa_Motors.scan("z",start,stop,step,relative=True)
-
-### kth ###
-def mvkth(val,**kwargs):
-    """ moves kth motor in the endstation"""
-    Kappa_Motors.move('kth',val,**kwargs)
-
-def dmvkth(val):
-    """ relative kth motor in the endstation"""
-    Kappa_Motors.move('kth',val,relative=True)
-
-def scankth(start,stop,step,**kwargs):
-    """ scans the kth motor in the endstation"""
-    Kappa_Motors.scan("kth",start,stop,step,**kwargs)
-
-def dscankth(start,stop,step):
-    """relative scans of the kth motor in the endstation """
-    Kappa_Motors.scan("kth",start,stop,step,relative=True)
-
-### kphi ###
-def mvkphi(val,**kwargs):
-    """ moves kphi motor in the endstation"""
-    Kappa_Motors.move('kphi',val,**kwargs)
-
-def dmvkphi(val):
-    """ relative kphi motor in the endstation"""
-    Kappa_Motors.move('kphi',val,relative=True)
-
-def scankphi(start,stop,step,**kwargs):
-    """ scans the kphi motor in the endstation"""
-    Kappa_Motors.scan("kphi",start,stop,step,**kwargs)
-
-def dscankphi(start,stop,step):
-    """relative scans of the kphi motor in the endstation """
-    Kappa_Motors.scan("kphi",start,stop,step,relative=True)   
-
-### kap ###
-def mvkap(val,**kwargs):
-    """ moves kap motor in the endstation"""
-    Kappa_Motors.move('kap',val,**kwargs)
-
-def dmvkap(val):
-    """ relative kap motor in the endstation"""
-    Kappa_Motors.move('kap',val,relative=True)
-
-def scankap(start,stop,step,**kwargs):
-    """ scans the kap motor in the endstation"""
-    Kappa_Motors.scan("kap",start,stop,step,**kwargs)
-
-def dscankap(start,stop,step):
-    """relative scans of the kap motor in the endstation """
-    Kappa_Motors.scan("kap",start,stop,step,relative=True)
-
-### tth ###
-def mvtth(val,**kwargs):
-    """ moves tth motor in the endstation"""
-    Kappa_Motors.move('tth',val,**kwargs)
-
-def dmvtth(val):
-    """ relative tth motor in the endstation"""
-    Kappa_Motors.move('tth',val,relative=True)
-
-def scantth(start,stop,step,**kwargs):
-    """ scans the tth motor in the endstation"""
-    Kappa_Motors.scan("tth",start,stop,step,**kwargs)
-
-def dscantth(start,stop,step):
-    """relative scans of the tth motor in the endstation """
-    Kappa_Motors.scan("tth",start,stop,step,relative=True)
-
-### th ###
-def mvth(val,**kwargs):
-    """ moves th motor in the endstation"""
-    Kappa_Motors.move('th',val,**kwargs)
-
-def dmvth(val):
-    """ relative th motor in the endstation"""
-    Kappa_Motors.move('th',val,relative=True)
-
-def scanth(start,stop,step,**kwargs):
-    """ scans the th motor in the endstation"""
-    Kappa_Motors.scan("th",start,stop,step,**kwargs)
-
-def dscanth(start,stop,step):
-    """relative scans of the th motor in the endstation """
-    Kappa_Motors.scan("th",start,stop,step,relative=True)
-
-### chi ###
-def mvchi(val,**kwargs):
-    """ moves chi motor in the endstation"""
-    Kappa_Motors.move('chi',val,**kwargs)
-
-def dmvchi(val):
-    """ relative chi motor in the endstation"""
-    Kappa_Motors.move('chi',val,relative=True)
-
-def scanchi(start,stop,step,**kwargs):
-    """ scans the chi motor in the endstation"""
-    Kappa_Motors.scan("chi",start,stop,step,**kwargs)
-
-def dscanchi(start,stop,step):
-    """relative scans of the chi motor in the endstation """
-    Kappa_Motors.scan("chi",start,stop,step,relative=True)
-
-### phi ###
-def mvphi(val,**kwargs):
-    """ moves phi motor in the endstation"""
-    Kappa_Motors.move('phi',val,**kwargs)
-
-def dmvphi(val):
-    """ relative phi motor in the endstation"""
-    Kappa_Motors.move('phi',val,relative=True)
-
-def scanphi(start,stop,step,**kwargs):
-    """ scans the phi motor in the endstation"""
-    Kappa_Motors.scan("phi",start,stop,step,**kwargs)
-
-def dscanphi(start,stop,step):
-    """relative scans of the phi motor in the endstation """
-    Kappa_Motors.scan("phi",start,stop,step,relative=True)
-
-### uan moves tth and th simultaneously 
-def uan(tth,th):
-    """ Moves tth and th motors simultaneously in the in the Kappa chamber
-    """
-    #move tth and th
-    mvth(th,wait=False)
-    mvtth(tth,wait=False)
-    sleep(0.2)     
-
-    while True:
-        status = Kappa_Motors.status()
-        if status == 0:
-            sleep(0.2)
-        else:
-            tth_RBV=round(Kappa_Motors.get('tth',verbose=False),3)
-            th_RBV=round(Kappa_Motors.get('th',verbose=False),3)
-            print('tth='+str(tth_RBV)+' th='+str(th_RBV))
-            break
-
-######## mprint and mvsample ###################
-def mprint():
-    """
-    prints current position of the physical motors
-    """
-    Kappa_Motors.mprint()
-
-def mvsample(position_list):
-    """
-    moves the sample to the position sepcified by position_list
-    position_list = ['description',x,y,z,th,chi,phi]
-
-    Previously: sample
-    """
-    Kappa_Motors.mvsample(position_list)
\ No newline at end of file
+    
\ No newline at end of file
diff --git a/iexcode/instruments/Logfile.py b/iexcode/instruments/Logfile.py
index f4a1a97..7a0093a 100644
--- a/iexcode/instruments/Logfile.py
+++ b/iexcode/instruments/Logfile.py
@@ -3,9 +3,39 @@ from os.path import join,isfile
 from epics import caget, caput
 
 from iexcode.instruments.utilities import today
+import iexcode.instruments.cfg as iex
 
 ## To do: make this work if User Folder doesn't already exist
 
+
+##############################################################################################################
+##############################             logging           ##############################
+##############################################################################################################
+def log_print(comment=''):
+    """
+    prints a comment to the logfile
+    """
+    try:
+        iex.BL.mda.log.print(comment='')
+    except:
+        print('No logfile written')
+
+def log_update():
+    """
+    updates the log file with the last scan info
+    """
+    try:
+        entry_list,pv_list, format_list = iex.BLlog.entries_function()
+        iex.BL.mda.log.update(entry_list,pv_list,format_list)
+    except:
+        print('No logfile written')
+
+def log_name_set(file_name):
+    try: 
+        iex.BL.mda.log.name_set(filename=file_name)
+    except:
+        print('No logfile name change')
+
 ##############################################################################################################
 ##############################            general   logfile functions          ##############################
 ##############################################################################################################
@@ -34,6 +64,7 @@ class Logfile:
 
         Previously: logname_pv
         """
+        #For new endstation modify here:
         pv_dict={
             'Test':'29idb:userStringSeq10.STR1',
             'ARPES':'29idb:userStringSeq10.STR2',
diff --git a/iexcode/instruments/MPA.py b/iexcode/instruments/MPA.py
index 39dd7f3..b63e3f8 100644
--- a/iexcode/instruments/MPA.py
+++ b/iexcode/instruments/MPA.py
@@ -28,13 +28,14 @@ userCalc_ioc = "29idTest:"
 DAC_pv = '29iddau1:dau1:011:DAC'
 HV_val_pv = "29idKappa:userCalcOut9.A"
 HV_rbv_pv = "29idKappa:userCalcOut10.OVAL"
+tth_pv = '29idKappa:m2.RBV'
 
 class MPA:
     """
     class for the MPA detector
     """
 
-    def __init__(self,tth_pv, max_HV = 2990,ratio = 500,tth_dLLM=13.73,tth_dHLM=23.73):
+    def __init__(self, max_HV = 2990,ratio = 500,tth_dLLM=13.73,tth_dHLM=23.73):
         self.pv = mpa_pv
         self._reset_pv = mpa_pv+'C1O'
         self._det_pv = mpa_pv + "det1:"
diff --git a/iexcode/instruments/Motors.py b/iexcode/instruments/Motors.py
index ade2e46..43229d9 100644
--- a/iexcode/instruments/Motors.py
+++ b/iexcode/instruments/Motors.py
@@ -5,10 +5,13 @@ from epics import caget, caput
 
 import iexcode.instruments.cfg as iex
 
+from iexcode.instruments.utilities import print_warning_message
 from iexcode.instruments.scalers import scaler_cts
 
 
-
+##############################################################################################################
+##############################            Motor Class        ##############################
+##############################################################################################################
 class Motors:
     """ 
     short hand to move motors in endstation
@@ -163,8 +166,12 @@ class Motors:
         #for kappa only
         kwargs.setdefault('cts',0.1)
         kwargs.setdefault('mpa',False)
-
-        rbv_pv,val_pv,sgm_pv,pv =self._motor_dictionary[name]
+        motor_pvs = self._motor_dictionary.get(name)
+        if motor_pvs:
+            rbv_pv,val_pv,sgm_pv,pv = motor_pvs
+        else:#here
+            print_warning_message('motor = "'+str(name)+'" is not defined for '+iex.BL.endstation)
+            return
 
         if kwargs['relative']:
             current_value = caget(rbv_pv)
@@ -239,3 +246,212 @@ class Motors:
 
 
 
+##############################################################################################################
+##############################            Motor Short Names         ##############################
+##############################################################################################################
+### x ###
+def mvx(val,**kwargs):
+    """ moves x motor in the endstation"""
+    iex.BL.Motors.move('x',val,**kwargs)
+
+def dmvx(val):
+    """ relative x motor in the endstation"""
+    iex.BL.Motors.move('x',val,relative=True)
+
+def scanx(start,stop,step,**kwargs):
+    """ scans the x motor in the endstation"""
+    iex.BL.Motors.scan("x",start,stop,step,**kwargs)
+
+def dscanx(start,stop,step):
+    """relative scans of the x motor in the endstation """
+    iex.BL.Motors.scan("x",start,stop,step,relative=True)
+
+### y ###
+def mvy(val,**kwargs):
+    """ moves y motor in the endstation"""
+    iex.BL.Motors.move('y',val,**kwargs)
+
+def dmvy(val):
+    """ relative y motor in the endstation"""
+    iex.BL.Motors.move('y',val,relative=True)
+
+def scany(start,stop,step,**kwargs):
+    """ scans the y motor in the endstation"""
+    iex.BL.Motors.scan("y",start,stop,step,**kwargs)
+
+def dscany(start,stop,step):
+    """relative scans of the y motor in the endstation """
+    iex.BL.Motors.scan("y",start,stop,step,relative=True)
+
+### z ###
+def mvz(val,**kwargs):
+    """ moves z motor in the endstation"""
+    iex.BL.Motors.move('z',val,**kwargs)
+
+def dmvz(val):
+    """ relative z motor in the endstation"""
+    iex.BL.Motors.move('z',val,relative=True)
+
+def scanz(start,stop,step,**kwargs):
+    """ scans the z motor in the endstation"""
+    iex.BL.Motors.scan("z",start,stop,step,**kwargs)
+
+def dscanz(start,stop,step):
+    """relative scans of the z motor in the endstation """
+    iex.BL.Motors.scan("z",start,stop,step,relative=True)
+
+### kth ###
+def mvkth(val,**kwargs):
+    """ moves kth motor in the endstation"""
+    iex.BL.Motors.move('kth',val,**kwargs)
+
+def dmvkth(val):
+    """ relative kth motor in the endstation"""
+    iex.BL.Motors.move('kth',val,relative=True)
+
+def scankth(start,stop,step,**kwargs):
+    """ scans the kth motor in the endstation"""
+    iex.BL.Motors.scan("kth",start,stop,step,**kwargs)
+
+def dscankth(start,stop,step):
+    """relative scans of the kth motor in the endstation """
+    iex.BL.Motors.scan("kth",start,stop,step,relative=True)
+
+### kphi ###
+def mvkphi(val,**kwargs):
+    """ moves kphi motor in the endstation"""
+    iex.BL.Motors.move('kphi',val,**kwargs)
+
+def dmvkphi(val):
+    """ relative kphi motor in the endstation"""
+    iex.BL.Motors.move('kphi',val,relative=True)
+
+def scankphi(start,stop,step,**kwargs):
+    """ scans the kphi motor in the endstation"""
+    iex.BL.Motors.scan("kphi",start,stop,step,**kwargs)
+
+def dscankphi(start,stop,step):
+    """relative scans of the kphi motor in the endstation """
+    iex.BL.Motors.scan("kphi",start,stop,step,relative=True)   
+
+### kap ###
+def mvkap(val,**kwargs):
+    """ moves kap motor in the endstation"""
+    iex.BL.Motors.move('kap',val,**kwargs)
+
+def dmvkap(val):
+    """ relative kap motor in the endstation"""
+    iex.BL.Motors.move('kap',val,relative=True)
+
+def scankap(start,stop,step,**kwargs):
+    """ scans the kap motor in the endstation"""
+    iex.BL.Motors.scan("kap",start,stop,step,**kwargs)
+
+def dscankap(start,stop,step):
+    """relative scans of the kap motor in the endstation """
+    iex.BL.Motors.scan("kap",start,stop,step,relative=True)
+
+### tth ###
+def mvtth(val,**kwargs):
+    """ moves tth motor in the endstation"""
+    iex.BL.Motors.move('tth',val,**kwargs)
+
+def dmvtth(val):
+    """ relative tth motor in the endstation"""
+    iex.BL.Motors.move('tth',val,relative=True)
+
+def scantth(start,stop,step,**kwargs):
+    """ scans the tth motor in the endstation"""
+    iex.BL.Motors.scan("tth",start,stop,step,**kwargs)
+
+def dscantth(start,stop,step):
+    """relative scans of the tth motor in the endstation """
+    iex.BL.Motors.scan("tth",start,stop,step,relative=True)
+
+### th ###
+def mvth(val,**kwargs):
+    """ moves th motor in the endstation"""
+    iex.BL.Motors.move('th',val,**kwargs)
+
+def dmvth(val):
+    """ relative th motor in the endstation"""
+    iex.BL.Motors.move('th',val,relative=True)
+
+def scanth(start,stop,step,**kwargs):
+    """ scans the th motor in the endstation"""
+    iex.BL.Motors.scan("th",start,stop,step,**kwargs)
+
+def dscanth(start,stop,step):
+    """relative scans of the th motor in the endstation """
+    iex.BL.Motors.scan("th",start,stop,step,relative=True)
+
+### chi ###
+def mvchi(val,**kwargs):
+    """ moves chi motor in the endstation"""
+    iex.BL.Motors.move('chi',val,**kwargs)
+
+def dmvchi(val):
+    """ relative chi motor in the endstation"""
+    iex.BL.Motors.move('chi',val,relative=True)
+
+def scanchi(start,stop,step,**kwargs):
+    """ scans the chi motor in the endstation"""
+    iex.BL.Motors.scan("chi",start,stop,step,**kwargs)
+
+def dscanchi(start,stop,step):
+    """relative scans of the chi motor in the endstation """
+    iex.BL.Motors.scan("chi",start,stop,step,relative=True)
+
+### phi ###
+def mvphi(val,**kwargs):
+    """ moves phi motor in the endstation"""
+    iex.BL.Motors.move('phi',val,**kwargs)
+
+def dmvphi(val):
+    """ relative phi motor in the endstation"""
+    iex.BL.Motors.move('phi',val,relative=True)
+
+def scanphi(start,stop,step,**kwargs):
+    """ scans the phi motor in the endstation"""
+    iex.BL.Motors.scan("phi",start,stop,step,**kwargs)
+
+def dscanphi(start,stop,step):
+    """relative scans of the phi motor in the endstation """
+    iex.BL.Motors.scan("phi",start,stop,step,relative=True)
+
+### uan moves tth and th simultaneously 
+def uan(tth,th):
+    """ Moves tth and th motors simultaneously in the in the Kappa chamber
+    """
+    if iex.BL.endstation == 'Kappa':
+        #move tth and th
+        mvth(th,wait=False)
+        mvtth(tth,wait=False)
+        sleep(0.2)     
+
+        while True:
+            status = iex.BL.Motors.status()
+            if status == 0:
+                sleep(0.2)
+            else:
+                tth_RBV=round(iex.BL.Motors.get('tth',verbose=False),3)
+                th_RBV=round(iex.BL.Motors.get('th',verbose=False),3)
+                print('tth='+str(tth_RBV)+' th='+str(th_RBV))
+                break
+    else:
+        print("not a defined move")
+######## mprint and mvsample ###################
+def mprint():
+    """
+    prints current position of the physical motors
+    """
+    iex.BL.Motors.mprint()
+
+def mvsample(position_list):
+    """
+    moves the sample to the position sepcified by position_list
+    position_list = ['description',x,y,z,th,chi,phi]
+
+    Previously: sample
+    """
+    iex.BL.Motors.mvsample(position_list)
\ No newline at end of file
diff --git a/iexcode/instruments/beamline.py b/iexcode/instruments/beamline.py
index 0883de0..f8de3a0 100644
--- a/iexcode/instruments/beamline.py
+++ b/iexcode/instruments/beamline.py
@@ -11,73 +11,10 @@ from epics import PV
 
 import iexcode.instruments.cfg as iex
 
-##############################################################################################################
-##############################             logging           ##############################
-##############################################################################################################
-def log_print(comment=''):
-    """
-    prints a comment to the logfile
-    """
-    try:
-        iex.BL.mda.log.print(comment='')
-    except:
-        print('No logfile written')
-
-def log_update():
-    """
-    updates the log file with the last scan info
-    """
-    try:
-        entry_list,pv_list, format_list = iex.BLlog.entries_function()
-        iex.BL.mda.log.update(entry_list,pv_list,format_list)
-    except:
-        print('No logfile written')
-
-def log_name_set(file_name):
-    try: 
-        iex.BL.mda.log.name_set(filename=file_name)
-    except:
-        print('No logfile name change')
     
 
 
 
-##############################################################################################################
-###########################                      Scan stuff                     ######################
-##############################################################################################################
-def scan_fillin(VAL,RBV,start,stop,steps_points,**kwargs):
-    """
-    fills in the scan record for the curretn beamline ioc
-    """
-    iex.BL.mda.fillin(VAL,RBV,start,stop,steps_points,**kwargs)
-
-def scan_fillin_table(VAL,RBV,my_table,**kwargs):
-    """
-    fills in the scan record for the curretn beamline ioc
-    """
-    iex.BL.mda.fillin_table(VAL,RBV,my_table,**kwargs)
-
-def scan_go(**kwargs):
-    """
-    Starts a scan 
-    by default: scanDIM=1  
-    Logging is automatic: use **kwargs or the optional logging arguments see scanlog() for details
-    kwargs:
-        X-ray = True (default), does shutter checks
-             = False no shutter checks
-    """
-    iex.BL.mda.go(verbose=True,**kwargs)
-
-
-def last_mda():
-    """
-    returns the last mda file number in the ioc defined by BL_ioc
-    Previously: LastMDA
-    """
-    filenum = iex.BL.mda.lastFileNum()
-    return filenum
-
-
 
 ##############################################################################################################
 ##############################               Beeper          ##############################
diff --git a/iexcode/instruments/cfg.py b/iexcode/instruments/cfg.py
index ddd518f..9de5488 100644
--- a/iexcode/instruments/cfg.py
+++ b/iexcode/instruments/cfg.py
@@ -1,2 +1,3 @@
 BL=None
 
+mpa=None
\ No newline at end of file
diff --git a/iexcode/instruments/scalers.py b/iexcode/instruments/scalers.py
index 1ae03b5..9f608be 100644
--- a/iexcode/instruments/scalers.py
+++ b/iexcode/instruments/scalers.py
@@ -1,7 +1,7 @@
 from math import floor
 
 from epics import caput,PV
-#import iexcode.instruments.IEX_endstations as iex
+
 import iexcode.instruments.cfg as iex
 
 def scaler_cts(time_seconds=0.1,verbose=True):
diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py
index 3d4e9d9..566a82d 100644
--- a/iexcode/instruments/scanRecord.py
+++ b/iexcode/instruments/scanRecord.py
@@ -4,10 +4,56 @@ import time
 
 from epics import caget, caput, PV
 
+import iexcode.instruments.cfg as iex
+
 from iexcode.instruments.utilities import dateandtime, print_warning_message
 from iexcode.instruments.userCalcs import userStringSeq_pvs,userStringSeq_clear
 
 
+def scan_fillin(VAL,RBV,start,stop,steps_points,**kwargs):
+    """
+    fills in the scan record for the curretn beamline ioc
+    """
+    try:
+        iex.BL.mda.fillin(VAL,RBV,start,stop,steps_points,**kwargs)
+    except:
+        print("IEX_endstations has not been initialized")
+
+def scan_fillin_table(VAL,RBV,my_table,**kwargs):
+    """
+    fills in the scan record for the curretn beamline ioc
+    """
+    try:
+        iex.BL.mda.fillin_table(VAL,RBV,my_table,**kwargs)
+    except:
+        print("IEX_endstations has not been initialized")  
+
+def scan_go(**kwargs):
+    """
+    Starts a scan 
+    by default: scanDIM=1  
+    Logging is automatic: use **kwargs or the optional logging arguments see scanlog() for details
+    kwargs:
+        X-ray = True (default), does shutter checks
+             = False no shutter checks
+    """
+    try:
+        iex.BL.mda.go(verbose=True,**kwargs)
+    except:
+        print("IEX_endstations has not been initialized")
+
+
+def last_mda():
+    """
+    returns the last mda file number in the ioc defined by BL_ioc
+    Previously: LastMDA
+    """
+    try:
+        filenum = iex.BL.mda.lastFileNum()
+        return filenum
+    except:
+        print("IEX_endstations has not been initialized")
+
 def saveData_get_all(ioc_pv):
     """
     returns saveData info: 
@@ -33,7 +79,9 @@ def saveData_get_all(ioc_pv):
 
    
     
-
+##############################################################################################################
+###########################                      Scan class                     ######################
+##############################################################################################################
 default_positioner_settling_time = 0.05
 default_detector_settling_time = 0.1
 
diff --git a/iexcode/instruments/xrays.py b/iexcode/instruments/xrays.py
index b6195ce..783f6bc 100644
--- a/iexcode/instruments/xrays.py
+++ b/iexcode/instruments/xrays.py
@@ -16,18 +16,16 @@ from iexcode.instruments.shutters import *
 from iexcode.instruments.gate_valves import *
 from iexcode.instruments.diagnostics import *
 from iexcode.instruments.m3r import *
-from iexcode.instruments.beamline import log_update, endstation_cams_enable
+from iexcode.instruments.beamline import endstation_cams_enable
 from iexcode.instruments.utilities import print_warning_message,make_table, take_closest_value
 from iexcode.instruments.current_amplifiers import ca_average
-from iexcode.instruments.Kappa import mpa
+from iexcode.instruments.Logfile import log_update
 
+mpa = iex.mpa
 
 ##############################################################################################################
 ##############################            resets and detector lists         ##############################
 ##############################################################################################################
-def test_function():
-    print('hello world')
-    
 def xrays_reset(verbose=True):
     if verbose:
         print("resetting the mono limits")
@@ -428,7 +426,6 @@ def scanXAS(ID_eV,start_stop_step_lists,**kwargs):
     kwargs.setdefault("mcp",True)    
     kwargs.setdefault('execute',True)   
 
-    #global BL
     scan_dim=kwargs['scan_dim']
     
     #Setting up the ScanRecord for Mono in Table mode
@@ -444,7 +441,7 @@ def scanXAS(ID_eV,start_stop_step_lists,**kwargs):
     energy(ID_eV,m3r=kwargs["m3r"])
 
     #mpa
-    if iex.BL.branch == "d" and kwargs["mcp"]:
+    if iex.BL.endstation == "Kappa" and kwargs["mcp"]:
         mpa.HV_on()
 
     #Scanning
@@ -457,7 +454,7 @@ def scanXAS(ID_eV,start_stop_step_lists,**kwargs):
         mono_scan_after(BL.mda,scan_dim)
         BL.mda.table_reset_after(scan_dim)
 
-        if BL.branch == "d": 
+        if BL.endstation == "Kappa": 
             if kwargs["mcp"]: 
                 mpa.HV_off()
             print("WARNING: Mesh"+BL.branch+" is still In")        
@@ -509,7 +506,7 @@ def scanXAS_BL(start_stop_step_lists,**kwargs):
     slits_set_BL(mono_array[0],m3r=kwargs["m3r"])
 
     #mpa
-    if BL.branch == "d" and kwargs["mcp"]:
+    if BL.endstation == "Kappa" and kwargs["mcp"]:
         mpa.HV_on()
         
     #Scanning
@@ -523,7 +520,7 @@ def scanXAS_BL(start_stop_step_lists,**kwargs):
         mono_scan_after(BL.mda,scan_dim)
         BL.mda.table_reset_after(scan_dim)
 
-        if BL.branch == "d": 
+        if BL.endstation == "Kappa": 
             if kwargs["mcp"]: 
                 mpa.HV_off()
             print("WARNING: Mesh"+BL.branch+" is still In")  
-- 
GitLab