-
Notifications
You must be signed in to change notification settings - Fork 11
/
BlissMotor.py
116 lines (92 loc) · 3.56 KB
/
BlissMotor.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
from HardwareRepository.BaseHardwareObjects import Device
from HardwareRepository.TaskUtils import *
import math
import logging
import time
import gevent
import types
from bliss.config.motors import get_axis, set_backend
import os
class BlissMotor(Device):
(NOTINITIALIZED, UNUSABLE, READY, MOVESTARTED, MOVING, ONLIMIT) = (0,1,2,3,4,5)
def __init__(self, name):
Device.__init__(self, name)
def init(self):
self.motorState = BlissMotor.NOTINITIALIZED
self.username = self.motor_name
set_backend("beacon")
self.motor = get_axis(self.motor_name)
self.connect(self.motor, "position", self.positionChanged)
self.connect(self.motor, "state", self.updateState)
self.connect(self.motor, "move_done", self._move_done)
def connectNotify(self, signal):
if signal == 'positionChanged':
self.emit('positionChanged', (self.getPosition(), ))
elif signal == 'stateChanged':
self.updateState()
elif signal == 'limitsChanged':
self.motorLimitsChanged()
def _move_done(self, move_done):
if move_done:
self.updateState("READY")
else:
self.updateState("MOVING")
def updateState(self, state=None):
if state is None:
state = self.motor.state()
# convert from grob state to Hardware Object motor state
if state == "MOVING":
state = BlissMotor.MOVING
elif state == "READY":
state = BlissMotor.READY
elif state == "LIMPOS" or state == 'LIMNEG':
state = BlissMotor.ONLIMIT
else:
state = BlissMotor.UNUSABLE
self.setIsReady(state > BlissMotor.UNUSABLE)
if self.motorState != state:
self.motorState = state
self.emit('stateChanged', (self.motorState, ))
def getState(self):
self.updateState()
return self.motorState
def motorLimitsChanged(self):
self.emit('limitsChanged', (self.getLimits(), ))
def getLimits(self):
# no limit = None, but None is a problematic value
# for some GUI components (like MotorSpinBox), so
# in case of None it is much easier to return very
# large limits
ll, hl = self.motor.limits()
return ll if ll is not None else -1E6, hl if hl is not None else 1E6
def positionChanged(self, absolutePosition):
#print self.name(), absolutePosition
self.emit('positionChanged', (absolutePosition, ))
def getPosition(self):
return self.motor.position()
def getDialPosition(self):
return self.getPosition()
"""@task
def _wait_ready(self):
while self.motorIsMoving():
time.sleep(0.02)
"""
def move(self, position):
#self._wait_ready(timeout=15)
self.motor.move(position, wait=False) #.link(self.updateState)
def moveRelative(self, relativePosition):
self.move(self.getPosition() + relativePosition)
def syncMoveRelative(self, relative_position, timeout=None):
return self.syncMove(self.getPosition() + relative_position)
def waitEndOfMove(self, timeout=None):
with gevent.Timeout(timeout):
self.motor.wait_move()
def syncMove(self, position, timeout=None):
self.move(position)
self.waitEndOfMove(timeout)
def motorIsMoving(self):
return self.motorState == BlissMotor.MOVING
def getMotorMnemonic(self):
return self.motor_name
def stop(self):
self.motor.stop(wait=False)