-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathasgard.py
More file actions
596 lines (528 loc) · 23.3 KB
/
asgard.py
File metadata and controls
596 lines (528 loc) · 23.3 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from gui import Ui_MainWindow
from about import Ui_Dialog as About_Ui_Dialog
import serial_port_finder as spf
import serial, time
s0 = serial.Serial()
class AboutDialog(About_Ui_Dialog):
def __init__(self, dialog):
About_Ui_Dialog.__init__(self)
self.setupUi(dialog)
class AsgardGUI(Ui_MainWindow):
def __init__(self, dialog):
Ui_MainWindow.__init__(self)
self.setupUi(dialog)
self.getSerialPorts()
self.SerialThreadClass = SerialThreadClass()
self.SerialThreadClass.serialSignal.connect(self.updateConsole)
self.actionAbout.triggered.connect(self.launchAboutWindow)
self.actionExit.triggered.connect(self.close_application)
self.HomeButton.pressed.connect(self.sendHomingCycleCommand)
self.ZeroPositionButton.pressed.connect(self.sendZeroPositionCommand)
self.KillAlarmLockButton.pressed.connect(self.sendKillAlarmCommand)
self.G0MoveRadioButton.clicked.connect(self.FeedRateBoxHide)
self.G1MoveRadioButton.clicked.connect(self.FeedRateBoxHide)
self.FKGoButtonArt1.pressed.connect(self.FKMoveArt1)
self.FKSliderArt1.valueChanged.connect(self.FKSliderUpdateArt1)
self.SpinBoxArt1.valueChanged.connect(self.FKSpinBoxUpdateArt1)
self.FKDec10ButtonArt1.pressed.connect(self.FKDec10Art1)
self.FKDec1ButtonArt1.pressed.connect(self.FKDec1Art1)
self.FKDec0_1ButtonArt1.pressed.connect(self.FKDec0_1Art1)
self.FKInc0_1ButtonArt1.pressed.connect(self.FKInc0_1Art1)
self.FKInc1ButtonArt1.pressed.connect(self.FKInc1Art1)
self.FKInc10ButtonArt1.pressed.connect(self.FKInc10Art1)
self.FKGoButtonArt2.pressed.connect(self.FKMoveArt2)
self.FKSliderArt2.valueChanged.connect(self.FKSliderUpdateArt2)
self.SpinBoxArt2.valueChanged.connect(self.FKSpinBoxUpdateArt2)
self.FKDec10ButtonArt2.pressed.connect(self.FKDec10Art2)
self.FKDec1ButtonArt2.pressed.connect(self.FKDec1Art2)
self.FKDec0_1ButtonArt2.pressed.connect(self.FKDec0_1Art2)
self.FKInc0_1ButtonArt2.pressed.connect(self.FKInc0_1Art2)
self.FKInc1ButtonArt2.pressed.connect(self.FKInc1Art2)
self.FKInc10ButtonArt2.pressed.connect(self.FKInc10Art2)
self.FKGoButtonArt3.pressed.connect(self.FKMoveArt3)
self.FKSliderArt3.valueChanged.connect(self.FKSliderUpdateArt3)
self.SpinBoxArt3.valueChanged.connect(self.FKSpinBoxUpdateArt3)
self.FKDec10ButtonArt3.pressed.connect(self.FKDec10Art3)
self.FKDec1ButtonArt3.pressed.connect(self.FKDec1Art3)
self.FKDec0_1ButtonArt3.pressed.connect(self.FKDec0_1Art3)
self.FKInc0_1ButtonArt3.pressed.connect(self.FKInc0_1Art3)
self.FKInc1ButtonArt3.pressed.connect(self.FKInc1Art3)
self.FKInc10ButtonArt3.pressed.connect(self.FKInc10Art3)
self.FKGoButtonArt4.pressed.connect(self.FKMoveArt4)
self.FKSliderArt4.valueChanged.connect(self.FKSliderUpdateArt4)
self.SpinBoxArt4.valueChanged.connect(self.FKSpinBoxUpdateArt4)
self.FKDec10ButtonArt4.pressed.connect(self.FKDec10Art4)
self.FKDec1ButtonArt4.pressed.connect(self.FKDec1Art4)
self.FKDec0_1ButtonArt4.pressed.connect(self.FKDec0_1Art4)
self.FKInc0_1ButtonArt4.pressed.connect(self.FKInc0_1Art4)
self.FKInc1ButtonArt4.pressed.connect(self.FKInc1Art4)
self.FKInc10ButtonArt4.pressed.connect(self.FKInc10Art4)
self.FKGoButtonArt5.pressed.connect(self.FKMoveArt5)
self.FKSliderArt5.valueChanged.connect(self.FKSliderUpdateArt5)
self.SpinBoxArt5.valueChanged.connect(self.FKSpinBoxUpdateArt5)
self.FKDec10ButtonArt5.pressed.connect(self.FKDec10Art5)
self.FKDec1ButtonArt5.pressed.connect(self.FKDec1Art5)
self.FKDec0_1ButtonArt5.pressed.connect(self.FKDec0_1Art5)
self.FKInc0_1ButtonArt5.pressed.connect(self.FKInc0_1Art5)
self.FKInc1ButtonArt5.pressed.connect(self.FKInc1Art5)
self.FKInc10ButtonArt5.pressed.connect(self.FKInc10Art5)
self.FKGoButtonArt6.pressed.connect(self.FKMoveArt6)
self.FKSliderArt6.valueChanged.connect(self.FKSliderUpdateArt6)
self.SpinBoxArt6.valueChanged.connect(self.FKSpinBoxUpdateArt6)
self.FKDec10ButtonArt6.pressed.connect(self.FKDec10Art6)
self.FKDec1ButtonArt6.pressed.connect(self.FKDec1Art6)
self.FKDec0_1ButtonArt6.pressed.connect(self.FKDec0_1Art6)
self.FKInc0_1ButtonArt6.pressed.connect(self.FKInc0_1Art6)
self.FKInc1ButtonArt6.pressed.connect(self.FKInc1Art6)
self.FKInc10ButtonArt6.pressed.connect(self.FKInc10Art6)
self.FKGoAllButton.pressed.connect(self.FKMoveAll)
self.GoButtonGripper.pressed.connect(self.MoveGripper)
self.SliderGripper.valueChanged.connect(self.SliderUpdateGripper)
self.SpinBoxGripper.valueChanged.connect(self.SpinBoxUpdateGripper)
self.Dec10ButtonGripper.pressed.connect(self.Dec10Gripper)
self.Dec1ButtonGripper.pressed.connect(self.Dec1Gripper)
self.Inc1ButtonGripper.pressed.connect(self.Inc1Gripper)
self.Inc10ButtonGripper.pressed.connect(self.Inc10Gripper)
self.SerialPortRefreshButton.pressed.connect(self.getSerialPorts)
self.ConnectButton.pressed.connect(self.connectSerial)
self.ConsoleButtonSend.pressed.connect(self.sendSerialCommand)
self.ConsoleInput.returnPressed.connect(self.sendSerialCommand)
def close_application(self):
sys.exit()
def launchAboutWindow(self):
self.dialogAbout = QtWidgets.QDialog()
self.ui = AboutDialog(self.dialogAbout)
self.dialogAbout.exec_()
def sendHomingCycleCommand(self):
if s0.isOpen():
messageToSend="$H"
messageToConsole=">>> " + messageToSend
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
def sendZeroPositionCommand(self):
if s0.isOpen():
messageToSend="G0 A0 B0 C0 D0 X0 Y0 Z0"
messageToConsole=">>> " + messageToSend
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
def sendKillAlarmCommand(self):
if s0.isOpen():
messageToSend="$X"
messageToConsole=">>> " + messageToSend
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
def FeedRateBoxHide(self):
if self.G1MoveRadioButton.isChecked():
self.FeedRateLabel.setEnabled(True)
self.FeedRateInput.setEnabled(True)
else:
self.FeedRateLabel.setEnabled(False)
self.FeedRateInput.setEnabled(False)
#FK Art1 Functions
def FKMoveArt1(self):
if s0.isOpen():
if self.G1MoveRadioButton.isChecked():
typeOfMovement="G1 "
feedRate=" F" + str(self.FeedRateInput.value())
else:
typeOfMovement="G0 "
feedRate=""
message=typeOfMovement + "A" + str(self.SpinBoxArt1.value()) + feedRate
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
def FKSliderUpdateArt1(self):
val=self.FKSliderArt1.value()/10
self.SpinBoxArt1.setValue(val)
def FKSpinBoxUpdateArt1(self):
val=int(self.SpinBoxArt1.value()*10)
self.FKSliderArt1.setValue(val)
def FKDec10Art1(self):
val=self.SpinBoxArt1.value()-10
self.SpinBoxArt1.setValue(val)
def FKDec1Art1(self):
val=self.SpinBoxArt1.value()-1
self.SpinBoxArt1.setValue(val)
def FKDec0_1Art1(self):
val=self.SpinBoxArt1.value()-0.1
self.SpinBoxArt1.setValue(val)
def FKInc0_1Art1(self):
val=self.SpinBoxArt1.value()+0.1
self.SpinBoxArt1.setValue(val)
def FKInc1Art1(self):
val=self.SpinBoxArt1.value()+1
self.SpinBoxArt1.setValue(val)
def FKInc10Art1(self):
val=self.SpinBoxArt1.value()+10
self.SpinBoxArt1.setValue(val)
#FK Art2 Functions
def FKMoveArt2(self):
if s0.isOpen():
if self.G1MoveRadioButton.isChecked():
typeOfMovement="G1 "
feedRate=" F" + str(self.FeedRateInput.value())
else:
typeOfMovement="G0 "
feedRate=""
message=typeOfMovement + "B" + str(self.SpinBoxArt2.value()) + " C" + str(self.SpinBoxArt2.value()) + feedRate
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
def FKSliderUpdateArt2(self):
val=self.FKSliderArt2.value()/10
self.SpinBoxArt2.setValue(val)
def FKSpinBoxUpdateArt2(self):
val=int(self.SpinBoxArt2.value()*10)
self.FKSliderArt2.setValue(val)
def FKDec10Art2(self):
val=self.SpinBoxArt2.value()-10
self.SpinBoxArt2.setValue(val)
def FKDec1Art2(self):
val=self.SpinBoxArt2.value()-1
self.SpinBoxArt2.setValue(val)
def FKDec0_1Art2(self):
val=self.SpinBoxArt2.value()-0.1
self.SpinBoxArt2.setValue(val)
def FKInc0_1Art2(self):
val=self.SpinBoxArt2.value()+0.1
self.SpinBoxArt2.setValue(val)
def FKInc1Art2(self):
val=self.SpinBoxArt2.value()+1
self.SpinBoxArt2.setValue(val)
def FKInc10Art2(self):
val=self.SpinBoxArt2.value()+10
self.SpinBoxArt2.setValue(val)
#FK Art3 Functions
def FKMoveArt3(self):
if s0.isOpen():
if self.G1MoveRadioButton.isChecked():
typeOfMovement="G1 "
feedRate=" F" + str(self.FeedRateInput.value())
else:
typeOfMovement="G0 "
feedRate=""
message=typeOfMovement + "D" + str(self.SpinBoxArt3.value()) + feedRate
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
def FKSliderUpdateArt3(self):
val=self.FKSliderArt3.value()/10
self.SpinBoxArt3.setValue(val)
def FKSpinBoxUpdateArt3(self):
val=int(self.SpinBoxArt3.value()*10)
self.FKSliderArt3.setValue(val)
def FKDec10Art3(self):
val=self.SpinBoxArt3.value()-10
self.SpinBoxArt3.setValue(val)
def FKDec1Art3(self):
val=self.SpinBoxArt3.value()-1
self.SpinBoxArt3.setValue(val)
def FKDec0_1Art3(self):
val=self.SpinBoxArt3.value()-0.1
self.SpinBoxArt3.setValue(val)
def FKInc0_1Art3(self):
val=self.SpinBoxArt3.value()+0.1
self.SpinBoxArt3.setValue(val)
def FKInc1Art3(self):
val=self.SpinBoxArt3.value()+1
self.SpinBoxArt3.setValue(val)
def FKInc10Art3(self):
val=self.SpinBoxArt3.value()+10
self.SpinBoxArt3.setValue(val)
#FK Art4 Functions
def FKMoveArt4(self):
if s0.isOpen():
if self.G1MoveRadioButton.isChecked():
typeOfMovement="G1 "
feedRate=" F" + str(self.FeedRateInput.value())
else:
typeOfMovement="G0 "
feedRate=""
message=typeOfMovement + "X" + str(self.SpinBoxArt4.value()) + feedRate
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
def FKSliderUpdateArt4(self):
val=self.FKSliderArt4.value()/10
self.SpinBoxArt4.setValue(val)
def FKSpinBoxUpdateArt4(self):
val=int(self.SpinBoxArt4.value()*10)
self.FKSliderArt4.setValue(val)
def FKDec10Art4(self):
val=self.SpinBoxArt4.value()-10
self.SpinBoxArt4.setValue(val)
def FKDec1Art4(self):
val=self.SpinBoxArt4.value()-1
self.SpinBoxArt4.setValue(val)
def FKDec0_1Art4(self):
val=self.SpinBoxArt4.value()-0.1
self.SpinBoxArt4.setValue(val)
def FKInc0_1Art4(self):
val=self.SpinBoxArt4.value()+0.1
self.SpinBoxArt4.setValue(val)
def FKInc1Art4(self):
val=self.SpinBoxArt4.value()+1
self.SpinBoxArt4.setValue(val)
def FKInc10Art4(self):
val=self.SpinBoxArt4.value()+10
self.SpinBoxArt4.setValue(val)
#FK Art5 Functions
def FKMoveArt5(self): # En realidad esto no va así, hay que calcular el movimiento acoplado. Proximamente.
if s0.isOpen():
if self.G1MoveRadioButton.isChecked():
typeOfMovement="G1 "
feedRate=" F" + str(self.FeedRateInput.value())
else:
typeOfMovement="G0 "
feedRate=""
message=typeOfMovement + "Y" + str(self.SpinBoxArt5.value()) + feedRate
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
def FKSliderUpdateArt5(self):
val=self.FKSliderArt5.value()/10
self.SpinBoxArt5.setValue(val)
def FKSpinBoxUpdateArt5(self):
val=int(self.SpinBoxArt5.value()*10)
self.FKSliderArt5.setValue(val)
def FKDec10Art5(self):
val=self.SpinBoxArt5.value()-10
self.SpinBoxArt5.setValue(val)
def FKDec1Art5(self):
val=self.SpinBoxArt5.value()-1
self.SpinBoxArt5.setValue(val)
def FKDec0_1Art5(self):
val=self.SpinBoxArt5.value()-0.1
self.SpinBoxArt5.setValue(val)
def FKInc0_1Art5(self):
val=self.SpinBoxArt5.value()+0.1
self.SpinBoxArt5.setValue(val)
def FKInc1Art5(self):
val=self.SpinBoxArt5.value()+1
self.SpinBoxArt5.setValue(val)
def FKInc10Art5(self):
val=self.SpinBoxArt5.value()+10
self.SpinBoxArt5.setValue(val)
#FK Art6 Functions
def FKMoveArt6(self): # En realidad esto no va así, hay que calcular el movimiento acoplado. Proximamente.
if s0.isOpen():
if self.G1MoveRadioButton.isChecked():
typeOfMovement="G1 "
feedRate=" F" + str(self.FeedRateInput.value())
else:
typeOfMovement="G0 "
feedRate=""
message=typeOfMovement + "Z" + str(self.SpinBoxArt6.value()) + feedRate
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
def FKSliderUpdateArt6(self):
val=self.FKSliderArt6.value()/10
self.SpinBoxArt6.setValue(val)
def FKSpinBoxUpdateArt6(self):
val=int(self.SpinBoxArt6.value()*10)
self.FKSliderArt6.setValue(val)
def FKDec10Art6(self):
val=self.SpinBoxArt6.value()-10
self.SpinBoxArt6.setValue(val)
def FKDec1Art6(self):
val=self.SpinBoxArt6.value()-1
self.SpinBoxArt6.setValue(val)
def FKDec0_1Art6(self):
val=self.SpinBoxArt6.value()-0.1
self.SpinBoxArt6.setValue(val)
def FKInc0_1Art6(self):
val=self.SpinBoxArt6.value()+0.1
self.SpinBoxArt6.setValue(val)
def FKInc1Art6(self):
val=self.SpinBoxArt6.value()+1
self.SpinBoxArt6.setValue(val)
def FKInc10Art6(self):
val=self.SpinBoxArt6.value()+10
self.SpinBoxArt6.setValue(val)
#FK Every Articulation Functions
def FKMoveAll(self): # En realidad esto no va así, hay que calcular el movimiento acoplado. Proximamente.
if s0.isOpen():
if self.G1MoveRadioButton.isChecked():
typeOfMovement="G1 "
feedRate=" F" + str(self.FeedRateInput.value())
else:
typeOfMovement="G0 "
feedRate=""
message=typeOfMovement + "A" + str(self.SpinBoxArt1.value()) + " B" + str(self.SpinBoxArt2.value()) + " C" + str(self.SpinBoxArt2.value()) + " D" + str(self.SpinBoxArt3.value()) + " X" + str(self.SpinBoxArt4.value()) + " Y" + str(self.SpinBoxArt5.value()) + " Z" + str(self.SpinBoxArt6.value()) + feedRate
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
# Gripper Functions
def MoveGripper(self): # En realidad esto no va así, hay que calcular el movimiento acoplado. Proximamente.
if s0.isOpen():
message="M3 S" + str((255/100)*self.SpinBoxGripper.value())
messageToSend = message + "\n"
messageToConsole = ">>> " + message
s0.write(messageToSend.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
else:
self.noSerialConnection()
def SliderUpdateGripper(self):
val=self.SliderGripper.value()
self.SpinBoxGripper.setValue(val)
def SpinBoxUpdateGripper(self):
val=int(self.SpinBoxGripper.value())
self.SliderGripper.setValue(val)
def Dec10Gripper(self):
val=self.SpinBoxGripper.value()-10
self.SpinBoxGripper.setValue(val)
def Dec1Gripper(self):
val=self.SpinBoxGripper.value()-1
self.SpinBoxGripper.setValue(val)
def Inc1Gripper(self):
val=self.SpinBoxGripper.value()+1
self.SpinBoxGripper.setValue(val)
def Inc10Gripper(self):
val=self.SpinBoxGripper.value()+10
self.SpinBoxGripper.setValue(val)
# Serial Connection functions
def getSerialPorts(self):
self.SerialPortComboBox.clear()
self.SerialPortComboBox.addItems(spf.serial_ports())
def connectSerial(self):
serialPort = self.SerialPortComboBox.currentText()
baudrate = self.BaudRateComboBox.currentText()
if serialPort != "":
if baudrate!="":
s0.port = serialPort
s0.baudrate = baudrate
s0.timeout = 1
try:
s0.close()
s0.open()
self.SerialThreadClass.start()
except Exception as e:
print ("error opening serial port: " + str(e))
else:
self.blankBaudRate()
else:
self.blankSerialPort()
def serialDisconnected(self):
self.RobotStateDisplay.setStyleSheet('background-color: rgb(255, 0, 0)')
self.RobotStateDisplay.setText("Disconnected")
def updateConsole(self, dataRead):
verboseShow=self.ConsoleShowVerbosecheckBox.isChecked()
okShow=self.ConsoleShowOkRespcheckBox.isChecked()
isDataReadVerbose = "MPos" in dataRead
isDataOkResponse = "ok" in dataRead
if dataRead=="SERIAL-DISCONNECTED":
s0.close()
self.serialDisconnected()
print ("Serial Connection Lost")
else:
if not isDataReadVerbose and not isDataOkResponse:
self.ConsoleOutput.appendPlainText(dataRead)
elif isDataOkResponse and okShow:
self.ConsoleOutput.appendPlainText(dataRead)
elif isDataReadVerbose:
self.updateFKPosDisplay(dataRead)
if verboseShow:
self.ConsoleOutput.appendPlainText(dataRead)
def sendSerialCommand(self):
messageToSent=self.ConsoleInput.text()+"\n"
messageToConsole= ">>> "+self.ConsoleInput.text()
if s0.isOpen():
if messageToSent!="":
s0.write(messageToSent.encode('UTF-8'))
self.ConsoleOutput.appendPlainText(messageToConsole)
self.ConsoleInput.clear()
else:
self.noSerialConnection()
def updateFKPosDisplay(self,dataRead):
data=dataRead[1:][:-1].split(",")
self.updateCurrentState(data[0])
self.FKCurrentPosValueArt1.setText(data[1][5:][:-2]+"º")
self.FKCurrentPosValueArt2.setText(data[2][:-2]+"º")
self.FKCurrentPosValueArt3.setText(data[4][:-2]+"º")
self.FKCurrentPosValueArt4.setText(data[5][:-2]+"º")
self.FKCurrentPosValueArt5.setText(data[6][:-2]+"º")
self.FKCurrentPosValueArt6.setText(data[7][:-2]+"º")
def updateCurrentState(self, state):
self.RobotStateDisplay.setText(state)
if state=="Idle" or state=="Run":
self.RobotStateDisplay.setStyleSheet('background-color: rgb(0, 255, 0)')
elif state=="Home":
self.RobotStateDisplay.setStyleSheet('background-color: rgb(85, 255, 255)')
elif state=="Alarm":
self.RobotStateDisplay.setStyleSheet('background-color: rgb(255, 255, 0)')
elif state=="Hold":
self.RobotStateDisplay.setStyleSheet('background-color: rgb(255, 0, 0)')
else:
self.RobotStateDisplay.setStyleSheet('background-color: rgb(255, 255, 255)')
def blankSerialPort(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Warning)
msgBox.setText("There is not Serial Port value indicated to establish the connection.\nPlease check it and try to connect again.")
msgBox.exec_()
def blankBaudRate(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Warning)
msgBox.setText("There is not Baud Rate value indicated to establish the connection.\nPlease check it and try to connect again.")
msgBox.exec_()
def noSerialConnection(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setIcon(QtWidgets.QMessageBox.Warning)
msgBox.setText("The connection has not been established yet. Please establish the connection before trying to control.")
msgBox.exec_()
############### SERIAL READ THREAD CLASS ###############
class SerialThreadClass(QtCore.QThread):
elapsedTime = time.time()
serialSignal = pyqtSignal(str)
def __init__(self, parent=None):
super(SerialThreadClass,self).__init__(parent)
def run(self):
while True:
if s0.isOpen():
try:
s0.inWaiting()
except:
self.serialSignal.emit("SERIAL-DISCONNECTED")
print ("Lost Serial connection!")
try:
if time.time()-self.elapsedTime>0.1:
self.elapsedTime=time.time()
s0.write("?\n".encode('UTF-8'))
dataRead = str(s0.readline())
dataCropped=dataRead[2:][:-5]
if dataCropped!="":
self.serialSignal.emit(dataCropped)
except Exception as e:
print ("Something failed: " + str(e))
############### SERIAL READ THREAD CLASS ###############
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
mwindow = QtWidgets.QMainWindow()
prog = AsgardGUI(mwindow)
mwindow.show()
sys.exit(app.exec_())