diff --git a/config/devices.properties b/config/devices.properties index 35117ce..c06ce8f 100755 --- a/config/devices.properties +++ b/config/devices.properties @@ -106,4 +106,6 @@ eta=ch.psi.pshell.device.DummyMotor||||true chi=ch.psi.pshell.device.DummyMotor||||true phi=ch.psi.pshell.device.DummyMotor||||true sixc=ch.psi.pshell.device.MotorGroupBase|mu delta gam eta chi phi||| +fivec=ch.psi.pshell.device.MotorGroupBase|delta gam eta chi phi||| +fourc=ch.psi.pshell.device.MotorGroupBase|delta eta chi phi||| en=ch.psi.pshell.device.DummyPositioner||||true diff --git a/devices/hkl_group.properties b/devices/hkl_group.properties index c24fe48..0aa7810 100644 --- a/devices/hkl_group.properties +++ b/devices/hkl_group.properties @@ -1,2 +1,2 @@ -#Mon Apr 16 15:45:44 CEST 2018 -precision=-1 +#Wed Apr 18 09:33:05 CEST 2018 +precision=4 diff --git a/plugins/MXSC-1.9.0.jar b/plugins/MXSC-1.9.0.jar index fe8ae7a..36f7cca 100755 Binary files a/plugins/MXSC-1.9.0.jar and b/plugins/MXSC-1.9.0.jar differ diff --git a/script/diffcalc/diffutils.py b/script/diffcalc/diffutils.py index 0768c94..3e0a7ea 100644 --- a/script/diffcalc/diffutils.py +++ b/script/diffcalc/diffutils.py @@ -16,10 +16,12 @@ ################################################################################################### #1- Create a MontorGroup with the diffractometer motors -# e.g named 'sixc', containing mu, delta, gam, eta, chi, phi motors +# e.g. 'sixc', containing mu, delta, gam, eta, chi, phi motors +# or 'fivec', containing delta, gam, eta, chi, phi motors +# or 'fourc', containing delta, eta, chi, phi motors #2- Create positioner to read/set the energy in kEv, e.g. named 'en' #3- Execute: run("diffutils") -#4- Execute: setup_sixc(sixc, en) +#4- Execute: setup_diff(sixc, en) from __future__ import absolute_import @@ -29,15 +31,15 @@ import traceback import Jama.Matrix diffcalc_path = os.path.abspath(get_context().setup.expandPath("{script}/Lib/diffcalc")) if not diffcalc_path in sys.path: - sys.path.append('/Users/gobbo_a/dev/pshell/config/home/script/Lib/diffcalc') + sys.path.append(diffcalc_path) import diffcalc from diffcalc import settings -from diffcalc.hkl.you.geometry import SixCircle +from diffcalc.hkl.you.geometry import SixCircle, FiveCircle, FourCircle from diffcalc.hardware import HardwareAdapter from diffcalc.ub.persistence import UbCalculationNonPersister -from diffcalc.gdasupport.minigda.scannable import * -from diffcalc.gdasupport.minigda import command +from diffcalc.gdasupport.minigda.scannable import ScannableBase, ScannableGroup +#from diffcalc.gdasupport.minigda import command from diffcalc.hardware import HardwareAdapter @@ -54,7 +56,6 @@ import ch.psi.pshell.device.Register as Register # Device mapping to difcalc ################################################################################################### class PositionerScannable(ScannableBase): - def __init__(self, positioner): self.positioner = positioner self.name = positioner.name @@ -79,15 +80,31 @@ class PositionerScannable(ScannableBase): class PositionerScannableGroup(ScannableGroup): def __init__(self, name, motors): self.name = name - [mu, delta, gam, eta, chi, phi] = motors - self.mu = PositionerScannable(mu) - self.delta = PositionerScannable(delta) - self.gam = PositionerScannable(gam) - self.eta = PositionerScannable(eta) - self.chi = PositionerScannable(chi) - self.phi = PositionerScannable(phi) - ScannableGroup.__init__(self, self.name, [self.mu, self.delta, self.gam, self.eta, self.chi, self.phi]) - + if len(motors)==6: + [mu, delta, gam, eta, chi, phi] = motors + self.mu = PositionerScannable(mu) + self.delta = PositionerScannable(delta) + self.gam = PositionerScannable(gam) + self.eta = PositionerScannable(eta) + self.chi = PositionerScannable(chi) + self.phi = PositionerScannable(phi) + ScannableGroup.__init__(self, self.name, [self.mu, self.delta, self.gam, self.eta, self.chi, self.phi]) + elif len(motors)==5: + [delta, gam, eta, chi, phi] = motors + self.delta = PositionerScannable(delta) + self.gam = PositionerScannable(gam) + self.eta = PositionerScannable(eta) + self.chi = PositionerScannable(chi) + self.phi = PositionerScannable(phi) + ScannableGroup.__init__(self, self.name, [self.delta, self.gam, self.eta, self.chi, self.phi]) + elif len(motors)==4: + [delta, eta, chi, phi] = motors + self.delta = PositionerScannable(delta) + self.eta = PositionerScannable(eta) + self.chi = PositionerScannable(chi) + self.phi = PositionerScannable(phi) + ScannableGroup.__init__(self, self.name, [self.delta, self.eta, self.chi, self.phi]) + class MotorGroupScannable(PositionerScannableGroup): def __init__(self, motor_group): self.motor_group = motor_group @@ -125,10 +142,10 @@ class ScannableAdapter(HardwareAdapter): class MotorGroupAdapter(ScannableAdapter): def __init__(self, diffractometer, energy, energy_multiplier_to_kev=1): - self.sixc = MotorGroupScannable(sixc) - self.en = PositionerScannable(en) - self.en.level = 3 - ScannableAdapter.__init__(self, self.sixc, self.en, energy_multiplier_to_kev) + self.diffractometer = MotorGroupScannable(diffractometer) + self.energy = PositionerScannable(energy) + self.energy.level = 3 + ScannableAdapter.__init__(self, self.diffractometer, self.energy, energy_multiplier_to_kev) class Wavelength(RegisterBase): def doRead(self): @@ -205,15 +222,30 @@ class HklGroup(RegisterBase, Register.RegisterArray): ################################################################################################### you = None dc, ub, hardware, hkl = None, None, None, None -#en in kev -def setup_sixc(sixc, en): - global you, dc, ub, hardware, hkl +_motor_group = None +def setup_diff(diffractometer, energy): + """ + diffractometer: Motor group containing: + - mu, delta, gam, eta, chi, phi (six circle) or + - delta, gam, eta, chi, phi (ficve circle) or + - delta, eta, chi, phi (four circle) + energy: Positioner having energy in kev + """ + global you, dc, ub, hardware, hkl, _motor_group + _motor_group = diffractometer you =None - settings.hardware = MotorGroupAdapter(sixc, en) - settings.geometry = SixCircle() + if len(diffractometer.motors) == 6: + settings.geometry = SixCircle() + elif len(diffractometer.motors) == 5: + settings.geometry = FiveCircle() + elif len(diffractometer.motors) == 4: + settings.geometry = FourCircle() + else: + raise Exception("Invalid motor group") + settings.hardware = MotorGroupAdapter(diffractometer, energy) settings.ubcalc_persister = UbCalculationNonPersister() - settings.axes_scannable_group = settings.hardware.sixc - settings.energy_scannable = settings.hardware.en + settings.axes_scannable_group = settings.hardware.diffractometer + settings.energy_scannable = settings.hardware.energy settings.ubcalc_strategy = diffcalc.hkl.you.calc.YouUbCalcStrategy() settings.angles_to_hkl_function = diffcalc.hkl.you.calc.youAnglesToHkl from diffcalc.gdasupport import you @@ -242,10 +274,13 @@ def print_axis_setup(): # Acceess functions ################################################################################################### def get_diff(): - return settings.hardware.sixc + return settings.hardware.diffractometer def get_en(): - return settings.hardware.en + return settings.hardware.energy + +def get_motor_group(): + return _motor_group def get_wl(): return you.wl @@ -302,7 +337,11 @@ def hklscan(vector, readables,latency = 0.0, passes = 1, **pars): for pos in vector: #print "Writing ", pos hkl_group.write(pos) - time.sleep(1.0) + time.sleep(0.1) #Make sure is busy + get_motor_group().update() + get_motor_group().waitReady(-1) + time.sleep(latency) + hkl_group.update() scan.append ([h.take(), k.take(), l.take()], [h.getPosition(), k.getPosition(), l.getPosition()], [readable.read() for readable in readables ]) finally: scan.end() diff --git a/script/diffcalc/testfivec.py b/script/diffcalc/testfivec.py new file mode 100644 index 0000000..1fdb9d5 --- /dev/null +++ b/script/diffcalc/testfivec.py @@ -0,0 +1,86 @@ +en.move(20.0) +delta.config.maxSpeed = 50.0 +delta.speed = 50.0 +delta.move(1.0) + +run("diffcalc/diffutils") +###################################################################################################\ +#Setup +################################################################################################### + +setup_diff(fivec, en) +# Set some limits +setup_axis('gam', 0, 179) +setup_axis('delta', 0, 179) +setup_axis('delta', min=0) +setup_axis('phi', cut=-180.0) + +print_axis_setup() + +###################################################################################################\ +#Orientation +################################################################################################### +help(ub.ub) +ub.listub() + +# Create a new ub calculation and set lattice parameters +ub.newub('test') +ub.setlat('cubic', 1, 1, 1, 90, 90, 90) + +# Add 1st reflection (demonstrating the hardware adapter) +settings.hardware.wavelength = 1 +ub.c2th([1, 0, 0]) # energy from hardware +settings.hardware.position = 0, 60, 0, 30, 0, 0 +ub.addref([1, 0, 0])# energy and position from hardware + +# Add 2nd reflection (this time without the harware adapter) +ub.c2th([0, 1, 0], 12.39842) +ub.addref([0, 1, 0], [60, 0, 30, 0, 90], 12.39842) + +# check the state +ub.ub() +ub.checkub() + + + +###################################################################################################\ +#Constraints +################################################################################################### +help(hkl.con) +hkl.con('qaz', 90) +hkl.con('a_eq_b') +hkl.con() + +###################################################################################################\ +#Motion +################################################################################################### +print angles_to_hkl((60., 0., 30., 0., 0.)) +print hkl_to_angles(1, 0, 0) +fivec.write([60, 0, 30, 90, 0]) +print "fivec=" , fivec.position +wl.write(1.0) +print "wl = ", wl.read() + +# Load the last ub calculation used +ub.lastub() +ub.setu ([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) +ub.showref() +ub.swapref(1,2) + +#print you.hkl +#pos(get_hkl()) +hkl_group.read() +#you.hkl.simulateMoveTo([0,1,1]) +#sim(get_hkl(), [0,1,1]) +hkl_group.sim([0.0,1.0,1.0]) +#pos(get_hkl(), [0,1,1]) +hkl_group.write([0.0,1.0,1.0]) + + +###################################################################################################\ +#Scans +################################################################################################### +lscan(l, [sin], 1.0, 1.5, 0.1) +ascan([k,l], [sin], [1.0, 1.0], [1.2, 1.3], [0.1, 0.1], zigzag=True, parallel_positioning = False) +vector = [[1.0,1.0,1.0], [1.0,1.0,1.1], [1.0,1.0,1.2], [1.0,1.0,1.4]] +hklscan(vector, [sin, arr], 0.9) \ No newline at end of file diff --git a/script/diffcalc/testfourc.py b/script/diffcalc/testfourc.py new file mode 100644 index 0000000..2b5bd9d --- /dev/null +++ b/script/diffcalc/testfourc.py @@ -0,0 +1,84 @@ +en.move(20.0) +delta.config.maxSpeed = 50.0 +delta.speed = 50.0 +delta.move(1.0) + +run("diffcalc/diffutils") +###################################################################################################\ +#Setup +################################################################################################### + +setup_diff(fourc, en) +# Set some limits +setup_axis('delta', 0, 179) +setup_axis('delta', min=0) +setup_axis('phi', cut=-180.0) + +print_axis_setup() + +###################################################################################################\ +#Orientation +################################################################################################### +help(ub.ub) +ub.listub() + +# Create a new ub calculation and set lattice parameters +ub.newub('test') +ub.setlat('cubic', 1, 1, 1, 90, 90, 90) + +# Add 1st reflection (demonstrating the hardware adapter) +settings.hardware.wavelength = 1 +ub.c2th([1, 0, 0]) # energy from hardware +settings.hardware.position = 0, 60, 0, 30, 0, 0 +ub.addref([1, 0, 0])# energy and position from hardware + +# Add 2nd reflection (this time without the harware adapter) +ub.c2th([0, 1, 0], 12.39842) +ub.addref([0, 1, 0], [60, 30, 0, 90], 12.39842) + +# check the state +ub.ub() +ub.checkub() + + + +###################################################################################################\ +#Constraints +################################################################################################### +help(hkl.con) +hkl.con('a_eq_b') +hkl.con() + +###################################################################################################\ +#Motion +################################################################################################### +print angles_to_hkl((60., 30., 0., 0.)) +print hkl_to_angles(1, 0, 0) +fourc.write([60, 30, 90, 0]) +print "fourc=" , fourc.position +wl.write(1.0) +print "wl = ", wl.read() + +# Load the last ub calculation used +ub.lastub() +ub.setu ([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) +ub.showref() +ub.swapref(1,2) + +#print you.hkl +#pos(get_hkl()) +hkl_group.read() +#you.hkl.simulateMoveTo([0,1,1]) +#sim(get_hkl(), [0,1,1]) +hkl_group.sim([0.0,1.0,1.0]) +#pos(get_hkl(), [0,1,1]) +hkl_group.write([0.0,1.0,1.0]) + + +###################################################################################################\ +#Scans +################################################################################################### +#lscan(l, [sin], 1.0, 1.5, 0.1) +#ascan([k,l], [sin], [1.0, 1.0], [1.2, 1.3], [0.1, 0.1], zigzag=True, parallel_positioning = False) +vector = [[1.0,1.0,1.0], [1.0,1.0,1.1], [1.0,1.0,1.2], [1.0,1.0,1.4]] +hklscan(vector, [sin, arr]) \ No newline at end of file diff --git a/script/diffcalc/difftest.py b/script/diffcalc/testsixc.py similarity index 99% rename from script/diffcalc/difftest.py rename to script/diffcalc/testsixc.py index 00e5161..f69e368 100644 --- a/script/diffcalc/difftest.py +++ b/script/diffcalc/testsixc.py @@ -8,7 +8,7 @@ run("diffcalc/diffutils") #Setup ################################################################################################### -setup_sixc(sixc, en) +setup_diff(sixc, en) # Set some limits setup_axis('gam', 0, 179) setup_axis('delta', 0, 179) diff --git a/script/test/ExampleContinuousMultipass.py b/script/test/ExampleContinuousMultipass.py index 607c28f..a31ad46 100644 --- a/script/test/ExampleContinuousMultipass.py +++ b/script/test/ExampleContinuousMultipass.py @@ -1,8 +1,9 @@ +import traceback THETA_RANGE = (0.0, 5.0) THETA_STEP = 1.0 PHI_RANGE = (-160.0, +160.0) -PHI_STEP = 40.0 +PHI_STEP = 160.0 #40.0 LATENCY = 0.0 ZIGZAG = True @@ -30,21 +31,21 @@ print "phi_positions: ", phi_positions def before_pass(pass_num, scan): print "Initializing pass ", pass_num - phi = phi_positions[pass_num] + phi = phi_positions[pass_num-1] inp.write(phi) - print "phi = ", phi - - #phi = phi_positions[record.index/THETA_NSTEPS] - #ManipulatorPhi.write(phi) #print "phi = ", phi - #ManipulatorPhi.waitValueInRange(phi, 1.0, 100) + + try: - try: - cscan(MOTORS, SENSORS, THETA_RANGE[0], THETA_RANGE[1], THETA_NSTEPS - 1, time=theta_time, passes = len(phi_positions), zigzag = ZIGZAG, before_pass=before_pass) + while(True): + cscan(MOTORS, SENSORS, THETA_RANGE[0], THETA_RANGE[1], THETA_NSTEPS - 1, latency=0.1, time=theta_time, passes = len(phi_positions), zigzag = ZIGZAG, before_pass=before_pass, check_positions = False) except Exception: - print sys.exc_info()[1] + #print sys.exc_info() + traceback.print_exc() + traceback.print_stack() + print "Caught" finally: if ENDSCAN: