-
Notifications
You must be signed in to change notification settings - Fork 0
/
motorstatus.py
168 lines (139 loc) · 3.81 KB
/
motorstatus.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
164
165
166
167
168
from PyQt5.QtWidgets import QWidget, QApplication, QLabel, QLineEdit, QPushButton, QVBoxLayout, QHBoxLayout, QGridLayout
from PyQt5.QtCore import QTimer
from communication import AsynRecord, Axis
from base import Base
status_bit_names = """Motor activated
Negative limit
Positive limit
Ext. servo alg.
Amplifier enabled
Open loop mode
Move timer
Integration mode
Dwell in progress
Data block error
Desired velocity
Abort decel. in
Block request
Home search in
User phase
User servo
Y-addr commute
Commutation
Posn follow offset
Posn follow enbl.
Capture on error
Software capture
Sign/magnitude
Rapid max
CS-1 # bit 3
CS-1 # bit 2
CS-1 # bit 1
CS-1 # bit 0
CS Axis definition
CS Axis definition
CS Axis definition
CS Axis definition
Assigned to CS
(Reserved)
Foreground in
Desired pos. limit
Stopped on limit
Home complete
Motor phase
Phasing search
Trigger move
Integrated fatal
I2T amplifier fault
Backlash
Amplifier fault
Fatal following
Warning following
In-position true"""
status_bit_names = status_bit_names.split("\n")
class MotorStatusGrid(QWidget):
def clearLayout(self):
for i in reversed(range(self.layout().count())):
widgetToRemove = self.layout().itemAt(i).widget()
self.layout().removeWidget(widgetToRemove)
widgetToRemove.setParent(None)
def updateStatusFromBits(self, bits):
self.clearLayout()
for i in range(3):
for j in range(16):
count = i*16 + j
n = 47 - count
bitVal = (2**n & bits) > 0
self.layout().addWidget(QLabel(status_bit_names[count]), j, 2*i)
self.layout().addWidget(QLabel(str(bitVal)), j, 2*i+1)
def readMotor(self):
try:
bits = self.axis.get_status()
except TimeoutError:
self.parent().emit_timeout_error()
return
self.updateStatusFromBits(bits)
def __init__(self, axis_num, parent=None):
super().__init__(parent)
#self.connection = AsynRecord("XF:21IDD-CT{MC:PRV}Asyn")
#self.axis = Axis(axis_num)
self.axis = self.parent().controller.getAxis(axis_num)
self.setLayout(QGridLayout())
class AxisSelector(QWidget):
def setTargetAxis(self, n):
self.jump_to_motor.setText(str(n))
def targetAxis(self):
return int(self.jump_to_motor.text())
def updateAxis(self):
self.axis.set_axis_num(self.targetAxis())
def setAxis(self, n):
self.setTargetAxis(n)
self.updateAxis()
def incrPage(self, n):
current_page = self.axis.axis_num
next_page = current_page + n
self.setAxis(next_page)
def nextPage(self):
self.incrPage(1)
def prevPage(self):
self.incrPage(-1)
def makeControlRow(self):
layout = QHBoxLayout()
jump_to_motor = QLineEdit()
jump_to_motor.returnPressed.connect(self.updateAxis)
self.jump_to_motor = jump_to_motor
layout.addWidget(jump_to_motor)
next_button = QPushButton(">")
prev_button = QPushButton("<")
next_button.clicked.connect(self.nextPage)
prev_button.clicked.connect(self.prevPage)
layout.addWidget(prev_button)
layout.addWidget(next_button)
return layout
def __init__(self, axis, parent=None):
super().__init__(parent)
self.axis = axis
self.setLayout(self.makeControlRow())
class MotorStatus(QWidget, Base):
def doShowPage(self):
if not self.guiErrorBit:
self.motorgrid.readMotor()
def __init__(self, axis_num=1, parent=None):
super().__init__(parent)
self.setLayout(QVBoxLayout())
self.motorgrid = MotorStatusGrid(axis_num, self)
self.layout().addWidget(self.motorgrid)
control_row = AxisSelector(self.motorgrid.axis, self)
self.layout().addWidget(control_row)
control_row.setAxis(axis_num)
self.timer = QTimer(self)
self.timer.timeout.connect(self.doShowPage)
self.timer.setInterval(1500)
self.timer.start()
if __name__ == "__main__":
app = QApplication([])
motorstatus = MotorStatus()
motorstatus.controller.set_pmac_socket("192.168.11.21", 1025)
#motorstatus.updateStatusFromBits(hexstring_to_int("E40044000001"))
motorstatus.show()
app.exec()