-
Notifications
You must be signed in to change notification settings - Fork 11
/
MicrodiffZoomMockup.py
80 lines (65 loc) · 2.87 KB
/
MicrodiffZoomMockup.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
#from MD2Motor import MD2Motor
from HardwareRepository.BaseHardwareObjects import Device
import logging
import math
class MicrodiffZoomMockup(Device):
(NOTINITIALIZED, UNUSABLE, READY, MOVESTARTED, MOVING, ONLIMIT) = (0,1,2,3,4,5)
def init(self):
self.motor_name = "Zoom"
self.motor_pos_attr_suffix = "Position"
self._last_position_name = None
self.predefined_position_attr = 1
self.predefinedPositions = {"Zoom 1": 1,
"Zoom 2": 2,
"Zoom 3": 3,
"Zoom 4": 4,
"Zoom 5": 5,
"Zoom 6": 6,
"Zoom 7": 7,
"Zoom 8": 8,
"Zoom 9": 9,
"Zoom 10":10}
self.sortPredefinedPositionsList()
def isReady(self):
return True
def sortPredefinedPositionsList(self):
self.predefinedPositionsNamesList = self.predefinedPositions.keys()
self.predefinedPositionsNamesList.sort(lambda x, y: int(round(self.predefinedPositions[x] - self.predefinedPositions[y])))
def connectNotify(self, signal):
if signal == 'predefinedPositionChanged':
positionName = self.getCurrentPositionName()
try:
pos = self.predefinedPositions[positionName]
except KeyError:
self.emit(signal, ('', None))
else:
self.emit(signal, (positionName, pos))
else:
return True#.connectNotify.im_func(self, signal)
def getState(self):
return 2
def getLimits(self):
return (1,10)
def getState(self):
return MicrodiffZoomMockup.READY
def getPredefinedPositionsList(self):
return self.predefinedPositionsNamesList
def motorPositionChanged(self, absolutePosition, private={}):
#MD2Motor.motorPositionChanged.im_func(self, absolutePosition, private)
positionName = self.getCurrentPositionName(absolutePosition)
if self._last_position_name != positionName:
self._last_position_name = positionName
self.emit('predefinedPositionChanged', (positionName, positionName and absolutePosition or None, ))
def getCurrentPositionName(self, pos=None):
pos = self.predefined_position_attr
for positionName in self.predefinedPositions:
if math.fabs(self.predefinedPositions[positionName] - pos) <= 1E-3:
return positionName
return ''
def moveToPosition(self, positionName):
try:
self.predefined_position_attr = self.predefinedPositions[positionName]
self.motorPositionChanged(self.predefined_position_attr)
return True
except:
return False