Skip to content

Commit fedc095

Browse files
committed
update and fix myarm use
1 parent 0e3c532 commit fedc095

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

main.py

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@ def _init_variable(self):
135135
# Used to calculate the coordinates between the cube and myarm
136136
self.sum_x1 = self.sum_x2 = self.sum_y2 = self.sum_y1 = 0
137137
# Grab the coordinates of the center point relative to myarm
138-
self.camera_x, self.camera_y = 165, 5
138+
self.camera_x, self.camera_y = 165, 0
139139
self.camera_z = 110
140+
# display real img coord
141+
self.pos_x, self.pos_y, self.pos_z = 0, 0, 0
140142
# The coordinates of the cube relative to myarm
141143
self.c_x, self.c_y = 0, 0
142144
# The ratio of pixels to actual values
@@ -580,6 +582,7 @@ def open_camera(self):
580582
self.open_camera_btn.setText('关闭')
581583
self.btn_color(self.open_camera_btn, 'red')
582584
except Exception as e:
585+
e = traceback.format_exc()
583586
self.loger.error('Unable to open camera' + str(e))
584587
self.camera_status = False
585588
self.camera_edit.setEnabled(True)
@@ -612,6 +615,7 @@ def close_camera(self):
612615
self.buad_choose()
613616
self.prompts_lab.clear()
614617
except Exception as e:
618+
e = traceback.format_exc()
615619
self.loger.error('camera off exception' + str(e))
616620

617621
def camera_checked(self):
@@ -867,6 +871,7 @@ def show_camera(self):
867871
QtGui.QImage.Format_RGB888)
868872
self.show_camera_lab.setPixmap(QtGui.QPixmap.fromImage(showImage))
869873
except Exception as e:
874+
e = traceback.format_exc()
870875
self.loger.error('Abnormal image recognition:' + str(e))
871876
elif func == 'QR code recognition' or func == '二维码识别':
872877
try:
@@ -911,6 +916,7 @@ def show_camera(self):
911916
QtGui.QImage.Format_RGB888)
912917
self.show_camera_lab.setPixmap(QtGui.QPixmap.fromImage(showImage))
913918
except Exception as e:
919+
e = traceback.format_exc()
914920
self.loger.error('abnormal' + str(e))
915921
elif func == 'yolov5':
916922
try:
@@ -1088,9 +1094,11 @@ def show_camera(self):
10881094

10891095
self.num = self.real_sx = self.real_sy = 0
10901096
except Exception as e:
1097+
e = traceback.format_exc()
10911098
self.loger.error('yolov5 Exception:' + str(e))
10921099
# is_release = False
10931100
except Exception as e:
1101+
e = traceback.format_exc()
10941102
self.loger.error('yolov5 Exception:' + str(e))
10951103
else:
10961104
try:
@@ -1640,22 +1648,31 @@ def moved(self, x, y):
16401648
QApplication.processEvents()
16411649
# send Angle to move myarm
16421650
device = self.comboBox_device.currentText()
1651+
func = self.comboBox_function.currentText()
1652+
if func == 'QR code recognition' or func == '二维码识别':
1653+
self.pos_x, self.pos_y, self.pos_z = round(self.home_coords[0] + x, 2), round(
1654+
self.home_coords[1] + y, 2), self.camera_z
1655+
self.prompts(f'X:{self.pos_x} Y:{self.pos_y} Z:{self.pos_z}')
1656+
else:
1657+
self.pos_x, self.pos_y, self.pos_z = round(x, 2), round(y, 2), self.camera_z
1658+
self.prompts(f'X:{self.pos_x} Y:{self.pos_y} Z:{self.pos_z}')
16431659
if self.is_crawl:
16441660
if self.crawl_status:
16451661
self.is_crawl = False
16461662
if device == 'myArm 300 for Pi':
16471663
self.myCobot.send_angles(self.move_angles[1], 35)
16481664
self.stop_wait(3)
1649-
func = self.comboBox_function.currentText()
16501665
# send coordinates to move myarm
16511666
if func == 'QR code recognition' or func == '二维码识别':
1667+
self.prompts(f'X:{self.home_coords[0] + x} Y:{self.home_coords[1] + y} Z:{self.camera_z}')
16521668
if device == 'myArm 300 for Pi':
16531669
self.myCobot.send_coords(
16541670
[self.home_coords[0] + x, self.home_coords[1] + y, 190.5, -179.72, 6.5, -179.43],
16551671
40, 1)
16561672
self.stop_wait(2.5)
16571673
self.myCobot.send_coords(
1658-
[self.home_coords[0] + x, self.home_coords[1] + y, self.camera_z, -179.72, 6.5, -179.43], 40,
1674+
[self.home_coords[0] + x, self.home_coords[1] + y, self.camera_z, -179.72, 6.5,
1675+
-179.43], 40,
16591676
1)
16601677
self.stop_wait(2.5)
16611678
elif func == 'shape recognition' or func == 'Keypoints' or func == '形状识别' or func == '特征点识别' or func == 'yolov5':
@@ -1680,7 +1697,7 @@ def moved(self, x, y):
16801697
tmp = self.myCobot.get_angles()
16811698
else:
16821699
break
1683-
if device == 'mechArm 270 for Pi':
1700+
if device == 'myArm 300 for Pi':
16841701
self.myCobot.send_angles([tmp[0], 0, 0, -90, -0.79, -83, tmp[6]], 35)
16851702
self.stop_wait(3)
16861703

@@ -1761,6 +1778,7 @@ def parse_folder(self, folder):
17611778
restore.append(cv2.imread(path + '/{}'.format(l)))
17621779
return restore
17631780
except Exception as e:
1781+
e = traceback.format_exc()
17641782
self.loger.error(str(e))
17651783

17661784
def add_img(self):
@@ -1859,6 +1877,7 @@ def add_img(self):
18591877
showImage = showImage.scaled(new_width, new_height, Qt.KeepAspectRatio)
18601878
self.show_cutimg_lab.setPixmap(QtGui.QPixmap.fromImage(showImage))
18611879
except Exception as e:
1880+
e = traceback.format_exc()
18621881
self.loger.info(e)
18631882

18641883
x, y, w, h = roi
@@ -2009,7 +2028,7 @@ def offset_change(self):
20092028
offset = f.read().splitlines()
20102029
# self.loger.info(offset)
20112030
self.camera_x, self.camera_y, self.camera_z = int(eval(offset[0])[0]), int(eval(offset[0])[1]), int(
2012-
eval(offset[0][2]))
2031+
eval(offset[0])[2])
20132032

20142033
self.xoffset_edit.clear()
20152034
self.yoffset_edit.clear()
@@ -2067,12 +2086,13 @@ def open_file(self):
20672086
try:
20682087
value = self.comboBox_device.currentText()
20692088
if value in self.Pi:
2070-
# os.startfile(libraries_path)
2071-
# else:
2089+
# os.startfile(libraries_path)
2090+
# else:
20722091
os.system('xdg-open ' + libraries_path)
20732092
# self.file_window = fileWindow()
20742093
# self.file_window.show()
20752094
except Exception as e:
2095+
e = traceback.format_exc()
20762096
self.loger.info(str(e))
20772097

20782098
def get_img_coord(self):
@@ -2083,6 +2103,18 @@ def get_img_coord(self):
20832103
else:
20842104
self.img_coord_status = True
20852105
self.btn_color(self.image_coord_btn, 'red')
2106+
self.get_real_img_coord()
2107+
2108+
def get_real_img_coord(self):
2109+
try:
2110+
if self.auto_mode_status or self.crawl_status:
2111+
self.img_coord_lab.clear()
2112+
self.img_coord_lab.setText(f'X:{self.pos_x} Y:{self.pos_y} Z:{self.pos_z}')
2113+
else:
2114+
pass
2115+
except Exception as e:
2116+
e = traceback.format_exc()
2117+
self.loger.error(str(e))
20862118

20872119
def get_current_coord_btnClick(self):
20882120
if not self.has_mycobot():
@@ -2273,6 +2305,7 @@ def _init_language(self):
22732305
self.yolov5_cut_btn.setText(_translate("AiKit_UI", "剪切"))
22742306

22752307
'''绘制类别'''
2308+
22762309
def draw_label(self, img, label, x, y):
22772310
text_size = cv2.getTextSize(label, self.FONT_FACE, self.FONT_SCALE, self.THICKNESS)
22782311
dim, baseline = text_size[0], text_size[1]
@@ -2347,6 +2380,7 @@ def post_process(self, input_image):
23472380
# cv2.imshow("nput_frame",input_image)
23482381
# return input_image
23492382
except Exception as e:
2383+
e = traceback.format_exc()
23502384
self.loger.error(e)
23512385

23522386
if cx + cy > 0:
@@ -2390,7 +2424,7 @@ def resource_path(relative_path):
23902424
try:
23912425
libraries_path = resource_path('libraries')
23922426
libraries_path = libraries_path.replace("\\", "/")
2393-
print(libraries_path)
2427+
# print(libraries_path)
23942428
app = QApplication(sys.argv)
23952429
AiKit_window = AiKit_APP()
23962430
AiKit_window.show()

test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@
2121
if func in mapping:
2222
offset_file = f'/offset/{device}_{mapping[func]}.txt'
2323
print(offset_file)
24+
with open('./libraries' + offset_file, "r", encoding="utf-8") as f:
25+
offset = f.read().splitlines()
26+
# self.loger.info(offset)
27+
print(offset)
28+
camera_x, camera_y, camera_z = int(eval(offset[0])[0]), int(eval(offset[0])[1]), int(
29+
eval(offset[0])[2])
30+
print(camera_x, camera_y, camera_z)

0 commit comments

Comments
 (0)