Skip to content

Commit bbbf6e0

Browse files
authored
Merge pull request #9 from elephantrobotics/riscv-opt
Riscv opt
2 parents 316db8a + d4afce1 commit bbbf6e0

File tree

8 files changed

+76
-33
lines changed

8 files changed

+76
-33
lines changed

__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""
2+
__init__.py
3+
This module controls the robotic arm movements.
4+
5+
Author: Wang Weijian
6+
Date: 2025-05-07
7+
"""
8+
9+
__version__ = "2.0.2"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
['165', '10', '103']
1+
['170', '25', '100']
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
['170', '20', '65']
1+
['165', '45', '64']
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
['165', '5', '65']
1+
['165', '15', '64']
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
['165', '10', '65']
1+
['165', '20', '64']
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
['170', '15', '65']
1+
['165', '25', '64']

libraries/yolov8File/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ pyqt5==5.15.11
3434
gpiozero==2.0.4
3535
pyserial==3.5
3636
pymycobot==3.9.3
37-
matplotlib==3.10.1
37+
matplotlib==3.10.0

main.py

Lines changed: 61 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ def _init_variable(self):
175175
self.cooldown_counter = 0 # 新增冷却计数器(单位:帧)- yolov8
176176
self.detect_history = deque(maxlen=5) # 存放最近5帧识别结果 - yolov8
177177

178-
self.pump = None
179178
self.valve =None
180179

181180

@@ -202,6 +201,8 @@ def _init_variable(self):
202201
self.BLUE = (255, 178, 50)
203202
self.YELLOW = (0, 255, 255)
204203

204+
self.init_point_done = False # 标志位:是否点击过初始点按钮
205+
205206
# initialization status
206207
def _init_status(self):
207208
self.camera_status = False # camera open state
@@ -487,12 +488,8 @@ def buad_choose(self):
487488
from gpiozero import Device, LED
488489
Device.pin_factory = LGPIOFactory(chip=0) # 显式指定/dev/gpiochip0
489490
# 初始化 GPIO 控制的设备
490-
self.pump = LED(71) # 气泵
491491
self.valve = LED(72) # 阀门
492-
self.pump.on() # 关闭泵
493-
time.sleep(0.05)
494-
self.valve.on() # 打开阀门
495-
time.sleep(1)
492+
self.valve.on()
496493

497494
else:
498495
self.camera_edit.setText('0')
@@ -1438,11 +1435,11 @@ def show_camera(self):
14381435
self.is_picking = True
14391436

14401437
def pick_task():
1441-
if self.crawl_status:
1442-
self.decide_move(self.real_x, self.real_y, self.color)
1443-
# global is_picking, cooldown_counter
1444-
self.is_picking = False
1445-
self.cooldown_counter = 20 # 设置冷却帧数,防止连续触发
1438+
# if self.crawl_status:
1439+
self.decide_move(self.real_x, self.real_y, self.color)
1440+
# global is_picking, cooldown_counter
1441+
self.is_picking = False
1442+
self.cooldown_counter = 20 # 设置冷却帧数,防止连续触发
14461443

14471444
threading.Thread(target=pick_task).start()
14481445
else:
@@ -1601,6 +1598,12 @@ def discern_func(self):
16011598

16021599
def crawl_func(self):
16031600
"""Turn crawling on/off"""
1601+
if not self.init_point_done:
1602+
if self.language == 1:
1603+
QMessageBox.warning(self, 'prompt', 'Please return to the initial point first!')
1604+
else:
1605+
QMessageBox.warning(self, '警告', '请先回到初始点!')
1606+
return
16041607
if self.crawl_status:
16051608
self.crawl_status = False
16061609
self.btn_color(self.crawl_btn, 'blue')
@@ -1639,7 +1642,7 @@ def check_position(self, data, ids, max_same_data_count=50):
16391642
start_time = time.time()
16401643
while True:
16411644
# 超时检测
1642-
if (time.time() - start_time) >= 3:
1645+
if (time.time() - start_time) >= 5:
16431646
break
16441647
res = self.myCobot.is_in_position(data, ids)
16451648
# print('res', res, data)
@@ -1662,6 +1665,7 @@ def to_origin_func(self):
16621665
try:
16631666
"""back to initial position"""
16641667
self.is_pick = False
1668+
self.controls_disable_place_offset(True)
16651669
self.pump_off()
16661670
if self.comboBox_device.currentText() == 'ultraArm P340':
16671671
self.myCobot.set_angles(self.move_angles[0], 30)
@@ -1673,6 +1677,12 @@ def to_origin_func(self):
16731677
if self.comboBox_function.currentText() == 'yolov5':
16741678
self.yolov5_is_not_pick = False
16751679
self.is_yolov5_cut_btn_clicked = False
1680+
self.init_point_done = True
1681+
if self.language == 1:
1682+
msg_box = QMessageBox(QMessageBox.Information, 'prompt', 'Returned to initial point successfully!')
1683+
else:
1684+
msg_box = QMessageBox(QMessageBox.Information, '提示', '成功返回初始点!')
1685+
msg_box.exec_()
16761686
except Exception as e:
16771687
e = traceback.format_exc()
16781688
self.loger.error(str(e))
@@ -2025,6 +2035,16 @@ def shape_detect(self, img):
20252035
else:
20262036
return None
20272037

2038+
def controls_disable_place_offset(self, status):
2039+
"""禁用/打开 ABCD四个放置点按钮、XYZ坐标偏移量修改"""
2040+
controls_list = [self.radioButton_A, self.radioButton_B, self.radioButton_C, self.radioButton_D, self.xoffset_edit, self.yoffset_edit, self.zoffset_edit]
2041+
if status:
2042+
for b in controls_list:
2043+
b.setEnabled(True)
2044+
else:
2045+
for b in controls_list:
2046+
b.setEnabled(False)
2047+
20282048
def decide_move(self, x, y, color):
20292049
device = self.comboBox_device.currentText()
20302050
if self.comboBox_function.currentText() == 'yolov5':
@@ -2067,6 +2087,8 @@ def decide_move(self, x, y, color):
20672087
def moved(self, x, y):
20682088
try:
20692089
# print('xy',x, y)
2090+
# 机械臂执行过程中,禁用某些控件编辑
2091+
self.controls_disable_place_offset(False)
20702092
self.is_crawl = True
20712093
while self.is_pick:
20722094
QApplication.processEvents()
@@ -2092,6 +2114,7 @@ def moved(self, x, y):
20922114
self.prompts(f'X:{self.pos_x} Y:{self.pos_y} Z:{self.pos_z}')
20932115
self.pos_x, self.pos_y, self.pos_z = round(x, 2), round(y, 2), self.camera_z
20942116
self.prompts(f'X:{self.pos_x} Y:{self.pos_y} Z:{self.pos_z}')
2117+
20952118
if self.is_crawl:
20962119
if self.crawl_status:
20972120
self.is_crawl = False
@@ -2100,7 +2123,7 @@ def moved(self, x, y):
21002123
self.stop_wait(3)
21012124
else:
21022125
self.myCobot.send_angles(self.move_angles[1], 50)
2103-
# self.check_position(self.move_angles[1], 0)
2126+
self.check_position(self.move_angles[1], 0)
21042127
# send coordinates to move mycobot
21052128
if func == 'QR code recognition' or func == '二维码识别':
21062129
if device == 'myPalletizer 260 for M5' or device == 'myPalletizer 260 for Pi':
@@ -2113,11 +2136,11 @@ def moved(self, x, y):
21132136
self.stop_wait(2.5)
21142137
elif device == 'mechArm 270 for Pi' or device == 'mechArm 270 for M5':
21152138
self.myCobot.send_coords(
2116-
[self.home_coords[0] + x, self.home_coords[1] + y, 150, 172.36, 5.36, 125.58], 30,
2139+
[self.home_coords[0] + x, self.home_coords[1] + y, 150, 172.36, 5.36, 125.58], 70,
21172140
1)
21182141
self.myCobot.send_coords(
21192142
[self.home_coords[0] + x, self.home_coords[1] + y, self.camera_z, 172.36, 5.36,
2120-
125.58], 30, 1)
2143+
125.58], 70, 1)
21212144
data = [self.home_coords[0] + x, self.home_coords[1] + y, self.camera_z, 172.36, 5.36,
21222145
125.58]
21232146
self.check_position(data, 1)
@@ -2142,7 +2165,7 @@ def moved(self, x, y):
21422165
time.sleep(3)
21432166

21442167
elif device == 'myCobot 280 for RISCV':
2145-
self.myCobot.send_coords([x, y, self.camera_z, 178.99, -3.78, -62.9], 70, 1)
2168+
self.myCobot.send_coords([x, y, self.camera_z, 178.99, -3.78, -62.9], 90, 1)
21462169
data = [x, y, self.camera_z, 178.99, -3.78, 62.9]
21472170
self.check_position(data, 1)
21482171

@@ -2153,10 +2176,10 @@ def moved(self, x, y):
21532176
self.myCobot.send_coords([x, y, self.camera_z, 0], 20, 0)
21542177
self.stop_wait(1.5)
21552178
elif device in ['mechArm 270 for Pi', 'mechArm 270 for M5']:
2156-
self.myCobot.send_coords([x, y, 110, -176.1, 2.4, -125.1], 60,
2179+
self.myCobot.send_coords([x, y, 110, -176.1, 2.4, -125.1], 70,
21572180
1) # usb :rx,ry,rz -173.3, -5.48, -57.9
21582181
# self.stop_wait(3)
2159-
self.myCobot.send_coords([x, y, self.camera_z, -176.1, 2.4, -125.1], 60, 1)
2182+
self.myCobot.send_coords([x, y, self.camera_z, -176.1, 2.4, -125.1], 70, 1)
21602183
# self.stop_wait(3)
21612184
self.check_position([x, y, self.camera_z, -176.1, 2.4, -125.1], 1)
21622185

@@ -2178,7 +2201,7 @@ def moved(self, x, y):
21782201
time.sleep(2)
21792202

21802203
elif device in ['myCobot 280 for RISCV']:
2181-
self.myCobot.send_coords([x, y, self.camera_z, 179.87, -3.78, -62.75], 60, 1)
2204+
self.myCobot.send_coords([x, y, self.camera_z, 179.87, -3.78, -62.75], 90, 1)
21822205
self.check_position([x, y, self.camera_z, 179.87, -3.78, -62.75], 1)
21832206

21842207
else:
@@ -2189,8 +2212,8 @@ def moved(self, x, y):
21892212
self.stop_wait(1.5)
21902213

21912214
elif device in ['mechArm 270 for Pi', 'mechArm 270 for M5']:
2192-
self.myCobot.send_coords([x, y, 150, -176.1, 2.4, -125.1], 60, 1)
2193-
self.myCobot.send_coords([x, y, self.camera_z, -176.1, 2.4, -125.1], 60, 1)
2215+
self.myCobot.send_coords([x, y, 150, -176.1, 2.4, -125.1], 70, 1)
2216+
self.myCobot.send_coords([x, y, self.camera_z, -176.1, 2.4, -125.1], 70, 1)
21942217
self.check_position([x, y, self.camera_z, -176.1, 2.4, -125.1], 1)
21952218

21962219
elif device in ['myCobot 280 for Pi', 'myCobot 280 for M5']:
@@ -2211,7 +2234,7 @@ def moved(self, x, y):
22112234
time.sleep(2)
22122235

22132236
elif device in ['myCobot 280 for RISCV']:
2214-
self.myCobot.send_coords([x, y, self.camera_z, 179.87, -3.78, -62.75], 70, 1)
2237+
self.myCobot.send_coords([x, y, self.camera_z, 179.87, -3.78, -62.75], 90, 1)
22152238
self.check_position([x, y, self.camera_z, 179.87, -3.78, -62.75], 1)
22162239

22172240
# open pump
@@ -2270,11 +2293,12 @@ def moved(self, x, y):
22702293
self.myCobot.send_angles(self.new_move_coords_to_angles[color], 50)
22712294
self.check_position(self.new_move_coords_to_angles[color], 0)
22722295
else:
2273-
self.myCobot.send_coords(self.move_coords[color], 40, 0)
2296+
self.myCobot.send_coords(self.move_coords[color], 50, 0)
22742297
self.stop_wait(4)
22752298

22762299
# close pump
22772300
self.pump_off()
2301+
self.stop_wait(2)
22782302

22792303
# self.stop_wait(4)
22802304
if device == 'ultraArm P340':
@@ -2287,6 +2311,8 @@ def moved(self, x, y):
22872311
self.btn_color(self.place_btn, 'blue')
22882312
self.num = 0
22892313
self.real_sx = self.real_sy = 0
2314+
# 运动结束后启用某些控件编辑
2315+
self.controls_disable_place_offset(True)
22902316
time.sleep(0.1)
22912317
if self.auto_mode_status:
22922318
self.is_pick = True
@@ -2303,7 +2329,6 @@ def pump_on(self):
23032329
self.myCobot.set_basic_output(5, 0)
23042330
time.sleep(0.05)
23052331
elif self.comboBox_device.currentText() in self.RISCV:
2306-
self.pump.on()
23072332
self.valve.off() # 关闭阀门
23082333
time.sleep(0.05)
23092334
else:
@@ -2332,7 +2357,6 @@ def pump_off(self):
23322357
time.sleep(0.05)
23332358

23342359
elif self.comboBox_device.currentText() in self.RISCV:
2335-
self.pump.off()
23362360
self.valve.on()
23372361
time.sleep(0.05)
23382362
else:
@@ -2395,6 +2419,10 @@ def add_img(self):
23952419
return
23962420
if not self.camera_status:
23972421
self.open_camera()
2422+
if self.language == 1:
2423+
self.prompts('Put the image you want to recognize into the camera area, and click the Cut button.')
2424+
else:
2425+
self.prompts('将要识别的图像放入相机区域,然后单击剪切按钮。')
23982426
while self.camera_status:
23992427
while self.camera_status:
24002428
QApplication.processEvents()
@@ -2529,10 +2557,10 @@ def prompts(self, msg=None):
25292557
if msg is not None:
25302558
if self.language == 1:
25312559
self.prompts_lab.setText('Prmpt:\n' + msg)
2532-
QApplication.processEvents()
2560+
# QApplication.processEvents()
25332561
else:
25342562
self.prompts_lab.setText('提示:\n' + msg)
2535-
QApplication.processEvents()
2563+
QApplication.processEvents()
25362564

25372565
def combox_func_checked(self):
25382566
try:
@@ -2575,6 +2603,12 @@ def combox_func_checked(self):
25752603
def auto_mode(self):
25762604
"""automated operation"""
25772605
btn = [self.discern_btn, self.crawl_btn, self.place_btn]
2606+
if not self.init_point_done:
2607+
if self.language == 1:
2608+
QMessageBox.warning(self, 'prompt', 'Please return to the initial point first!')
2609+
else:
2610+
QMessageBox.warning(self, '警告', '请先回到初始点!')
2611+
return
25782612
if self.auto_mode_status:
25792613
self.auto_mode_status = False
25802614
self.discern_status = False

0 commit comments

Comments
 (0)