-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor_lib.py
165 lines (126 loc) · 4.3 KB
/
motor_lib.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python
"""
Author: Matt Pearson
Date: Feb 2015
Description: Class to hold utility functions
"""
import sys
from epics import caput, caget
from motor_globals import motor_globals
class motor_lib(object):
"""
Library of useful test functions for motor record applications
"""
__g = motor_globals()
def testComplete(self, fail):
"""
Function to be called at end of test
fail = true or false
"""
if not fail:
print "Test Complete"
return self.__g.SUCCESS
else:
print "Test Failed"
return self.__g.FAIL
def move(self, motor, position, timeout):
"""
Move motor to position. We use put_callback
and check final position is within RDBD.
"""
try:
caput(motor, position, wait=True, timeout=timeout)
except:
e = sys.exc_info()
print str(e)
print "ERROR: caput failed."
print (motor + " pos:" + str(position) + " timeout:" + str(timeout))
return self.__g.FAIL
rdbd = motor + ".RDBD"
rbv = motor + ".RBV"
final_pos = caget(rbv)
deadband = caget(rdbd)
success = True
if ((final_pos < position-deadband) or (final_pos > position+deadband)):
print "ERROR: final_pos out of deadband."
print (motor + " " + str(position) + " " + str(timeout) + " "
+ str(final_pos) + " " + str(deadband))
success = False
if (success):
return self.postMoveCheck(motor)
else:
self.postMoveCheck(motor)
return self.__g.FAIL
def setPosition(self, motor, position, timeout):
"""
Set position on motor and check it worked ok.
"""
_set = motor + ".SET"
_rbv = motor + ".RBV"
_dval = motor + ".DVAL"
_off = motor + ".OFF"
offset = caget(_off)
caput(_set, 1, wait=True, timeout=timeout)
caput(_dval, position, wait=True, timeout=timeout)
caput(_off, offset, wait=True, timeout=timeout)
caput(_set, 0, wait=True, timeout=timeout)
if (self.postMoveCheck(motor) != self.__g.SUCCESS):
return self.__g.FAIL
try:
self.verifyPosition(motor, position+offset)
except Exception as e:
print str(e)
return self.__g.FAIL
def checkInitRecord(self, motor):
"""
Check the record for correct state at start of test.
"""
self.postMoveCheck()
def verifyPosition(self, motor, position):
"""
Verify that field == reference.
"""
_rdbd = motor + ".RDBD"
deadband = caget(_rdbd)
_rbv = motor + ".RBV"
current_pos = caget(_rbv)
if ((current_pos < position-deadband) or (current_pos > position+deadband)):
print "ERROR: final_pos out of deadband."
msg = (motor + " " + str(position) + " "
+ str(current_pos) + " " + str(deadband))
raise Exception(__name__ + msg)
return self.__g.SUCCESS
def verifyField(self, pv, field, reference):
"""
Verify that field == reference.
"""
full_pv = pv + "." + field
if (caget(full_pv) != reference):
msg = "ERROR: " + full_pv + " not equal to " + str(reference)
raise Exception(__name__ + msg)
return self.__g.SUCCESS
def postMoveCheck(self, motor):
"""
Check the motor for the correct state at the end of move.
"""
DMOV = 1
MOVN = 0
STAT = 0
SEVR = 0
LVIO = 0
MISS = 0
RHLS = 0
RLLS = 0
try:
self.verifyField(motor, "DMOV", DMOV)
self.verifyField(motor, "MOVN", MOVN)
self.verifyField(motor, "STAT", STAT)
self.verifyField(motor, "SEVR", SEVR)
self.verifyField(motor, "LVIO", LVIO)
self.verifyField(motor, "MISS", MISS)
self.verifyField(motor, "RHLS", RHLS)
self.verifyField(motor, "RLLS", RLLS)
except Exception as e:
print str(e)
return self.__g.FAIL
return self.__g.SUCCESS