forked from mxcube/HardwareObjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MicrodiffBeamstop.py
106 lines (85 loc) · 3.11 KB
/
MicrodiffBeamstop.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
from HardwareRepository.BaseHardwareObjects import Equipment
import logging
"""
Move the beamstop or the capillary, using the exporter protocol
Example xml file:
<equipment class="MicrodiffBeamstop">
<username>Beamstop</username>
<device role="beamstop" hwrid="/udiff_beamstop"></device>
<save_cmd_name>saveBeamstopBeamPosition</save_cmd_name>
<motors>
<device role="horizontal" hwrid="/bstopy"></device>
<device role="vertical" hwrid="/bstopz"></device>
</motors>
</equipment>
Example udiff_beamstop.xml
<device class="MicrodiffInOut">
<username>Beamstop</username>
<exporter_address>wid30bmd2s:9001</exporter_address>
<cmd_name>BeamstopPosition</cmd_name>
<private_state>{"OFF":"out", "BEAM":"in"}</private_state>
<timeout>100</timeout>
</device>
Example bstopy.xml (for bstopz only the motor name changes)
<device class="MD2Motor">
<username>bstopy</username>
<exporter_address>wid30bmd2s:9001</exporter_address>
<motor_name>BeamstopY</motor_name>
<GUIstep>0.01</GUIstep>
<unit>1e-3</unit>
</device>
When used with capillary, only the command and motor names change.
Example capillary xml file:
<equipment class="MicrodiffBeamstop">
<username>Capillary</username>
<device role="beamstop" hwrid="/udiff_capillary"></device>
<save_cmd_name>saveCapillaryBeamPosition</save_cmd_name>
<motors>
<device role="horizontal" hwrid="/capy"></device>
<device role="vertical" hwrid="/capz"></device>
</motors>
</equipment>
"""
class MicrodiffBeamstop(Equipment):
def init(self):
self.beamstop = self.getObjectByRole('beamstop')
self.beamstop.state_attr.connectSignal("update", self.checkPosition)
self.motors = self["motors"]
self.roles = self.motors.getRoles()
save_cmd_name = self.getProperty("save_cmd_name")
self.beamstopSetInPosition = self.beamstop.addCommand({"type":"exporter", "name":"bs_set_in", "address":self.beamstop.getProperty('exporter_address')},save_cmd_name)
#next two lines - just to make the beamstop brick happy
self.amplitude = 0
self.positions = self.beamstop.moves
def moveToPosition(self, name):
if name == "in":
self.beamstop.actuatorIn(wait=True)
elif name == "out":
self.beamstop.actuatorOut(wait=True)
self.checkPosition()
def connectNotify(self, signal):
self.checkPosition()
def isReady(self):
return True
def getState(self):
return "READY"
def getPosition(self):
return self.checkPosition(noEmit=True)
def checkPosition(self, pos=None, noEmit=False):
if pos is None:
pos = self.beamstop.getActuatorState()
try:
pos = self.beamstop.states[pos]
except:
pass
if not noEmit:
if pos:
self.emit("positionReached", pos)
else:
self.emit("noPosition", ())
return pos
def setNewPositions(self, name, newPositions):
if name == "in":
self.beamstopSetInPosition()
def getRoles(self):
return self.roles