forked from mxcube/HardwareObjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robodiff.py
130 lines (105 loc) · 6.15 KB
/
Robodiff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from HardwareRepository.TaskUtils import *
import MiniDiff
import sample_centring
import os
import sys
import logging
import time
import queue_model_objects_v1 as qmo
import copy
import gevent
class Robodiff(MiniDiff.MiniDiff):
def __init__(self, name):
MiniDiff.MiniDiff.__init__(self, name)
qmo.CentredPosition.set_diffractometer_motor_names("phi",
"focus",
"phiz",
"phiy",
"zoom",
"sampx",
"sampy",
"kappa",
"kappa_phi",
"chi",
"y",
"z")
def init(self):
self.controller = self.getObjectByRole("controller")
MiniDiff.MiniDiff.init(self)
self.chiMotor = self.getDeviceByRole('chi')
self.zMotor = self.getDeviceByRole('z')
self.yMotor = self.getDeviceByRole('y')
self.centringPhiz=sample_centring.CentringMotor(self.zMotor) #, reference_position=phiz_ref)
self.centringPhiy=sample_centring.CentringMotor(self.yMotor)
self.connect(self.zMotor, 'stateChanged', self.phizMotorStateChanged)
self.connect(self.zMotor, 'positionChanged', self.phizMotorMoved)
self.connect(self.zMotor, "positionChanged", self.emitDiffractometerMoved)
self.connect(self.yMotor, 'stateChanged', self.phiyMotorStateChanged)
self.connect(self.yMotor, 'positionChanged', self.phiyMotorMoved)
self.connect(self.yMotor, "positionChanged", self.emitDiffractometerMoved)
def oscil(self, *args, **kwargs):
self.controller.oscil(*args, **kwargs)
def helical_oscil(self, *args, **kwargs):
self.controller.helical_oscil(*args, **kwargs)
def getPositions(self, *args, **kwargs):
res=MiniDiff.MiniDiff.getPositions(self,*args, **kwargs)
res["chi"]=self.chiMotor.getPosition()
res["y"]=self.yMotor.getPosition()
res["z"]=self.zMotor.getPosition()
return res
def start3ClickCentring(self, sample_info=None):
self.currentCentringProcedure = sample_centring.start({"phi":self.centringPhi,
"phiy":self.centringPhiy,
"sampx": self.centringSamplex,
"sampy": self.centringSampley,
"phiz": self.centringPhiz },
self.pixelsPerMmY, self.pixelsPerMmZ,
self.getBeamPosX(), self.getBeamPosY(),
chi_angle=-self.chiMotor.getPosition())
self.currentCentringProcedure.link(self.manualCentringDone)
def startAutoCentring(self, sample_info=None, loop_only=False):
self.lightWago.wagoIn()
self.currentCentringProcedure = sample_centring.start_auto(self.camera,
{"phi":self.centringPhi,
"phiy":self.centringPhiy,
"sampx": self.centringSamplex,
"sampy": self.centringSampley,
"phiz": self.centringPhiz },
self.pixelsPerMmY, self.pixelsPerMmZ,
self.getBeamPosX(), self.getBeamPosY(),
chi_angle=-self.chiMotor.getPosition(),
msg_cb=self.emitProgressMessage,
new_point_cb=lambda point: self.emit("newAutomaticCentringPoint", point))
self.currentCentringProcedure.link(self.autoCentringDone)
self.emitProgressMessage("Starting automatic centring procedure...")
def motor_positions_to_screen(self, centred_positions_dict):
centred_pos_dict = copy.deepcopy(centred_positions_dict)
centred_pos_dict["phiy"]=centred_positions_dict['y']
centred_pos_dict["phiz"]=centred_positions_dict['z']
return MiniDiff.MiniDiff.motor_positions_to_screen(self, centred_pos_dict)
def moveMotors(self, roles_positions_dict):
motor = { "phi": self.phiMotor,
"focus": self.focusMotor,
"phiy": self.phiyMotor,
"phiz": self.phizMotor,
"sampx": self.sampleXMotor,
"sampy": self.sampleYMotor,
"kappa": self.kappaMotor,
"kappa_phi": self.kappaPhiMotor,
"chi": self.chiMotor,
"y": self.yMotor,
"z": self.zMotor,
"zoom": self.zoomMotor }
_aperture_move = gevent.spawn(self.controller.move_to_last_known_aperture)
for role, pos in roles_positions_dict.items():
logging.info("moving motor %s to %f", role, pos)
motor[role].move(pos)
# TODO: remove this sleep, the motors states should
# be MOVING since the beginning (or READY if move is
# already finished)
time.sleep(1)
while any([m.getState() == m.MOVING for m in motor.values()]):
time.sleep(0.1)
_aperture_move.get()
if any([m.getState() == m.ONLIMIT for m in motor.values()]):
raise RuntimeError("Motor %s on limit" % m.username)