@@ -201,6 +201,8 @@ def _init_variable(self):
201201 self .BLUE = (255 , 178 , 50 )
202202 self .YELLOW = (0 , 255 , 255 )
203203
204+ self .init_point_done = False # 标志位:是否点击过初始点按钮
205+
204206 # initialization status
205207 def _init_status (self ):
206208 self .camera_status = False # camera open state
@@ -487,6 +489,7 @@ def buad_choose(self):
487489 Device .pin_factory = LGPIOFactory (chip = 0 ) # 显式指定/dev/gpiochip0
488490 # 初始化 GPIO 控制的设备
489491 self .valve = LED (72 ) # 阀门
492+ self .valve .on ()
490493
491494 else :
492495 self .camera_edit .setText ('0' )
@@ -1595,6 +1598,12 @@ def discern_func(self):
15951598
15961599 def crawl_func (self ):
15971600 """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
15981607 if self .crawl_status :
15991608 self .crawl_status = False
16001609 self .btn_color (self .crawl_btn , 'blue' )
@@ -1633,7 +1642,7 @@ def check_position(self, data, ids, max_same_data_count=50):
16331642 start_time = time .time ()
16341643 while True :
16351644 # 超时检测
1636- if (time .time () - start_time ) >= 3 :
1645+ if (time .time () - start_time ) >= 5 :
16371646 break
16381647 res = self .myCobot .is_in_position (data , ids )
16391648 # print('res', res, data)
@@ -1667,6 +1676,12 @@ def to_origin_func(self):
16671676 if self .comboBox_function .currentText () == 'yolov5' :
16681677 self .yolov5_is_not_pick = False
16691678 self .is_yolov5_cut_btn_clicked = False
1679+ self .init_point_done = True
1680+ if self .language == 1 :
1681+ msg_box = QMessageBox (QMessageBox .Information , 'prompt' , 'Returned to initial point successfully!' )
1682+ else :
1683+ msg_box = QMessageBox (QMessageBox .Information , '提示' , '成功返回初始点!' )
1684+ msg_box .exec_ ()
16701685 except Exception as e :
16711686 e = traceback .format_exc ()
16721687 self .loger .error (str (e ))
@@ -2019,6 +2034,16 @@ def shape_detect(self, img):
20192034 else :
20202035 return None
20212036
2037+ def controls_disable_place_offset (self , status ):
2038+ """禁用/打开 ABCD四个放置点按钮、XYZ坐标偏移量修改"""
2039+ controls_list = [self .radioButton_A , self .radioButton_B , self .radioButton_C , self .radioButton_D , self .xoffset_edit , self .yoffset_edit , self .zoffset_edit ]
2040+ if status :
2041+ for b in controls_list :
2042+ b .setEnabled (True )
2043+ else :
2044+ for b in controls_list :
2045+ b .setEnabled (False )
2046+
20222047 def decide_move (self , x , y , color ):
20232048 device = self .comboBox_device .currentText ()
20242049 if self .comboBox_function .currentText () == 'yolov5' :
@@ -2086,15 +2111,18 @@ def moved(self, x, y):
20862111 self .prompts (f'X:{ self .pos_x } Y:{ self .pos_y } Z:{ self .pos_z } ' )
20872112 self .pos_x , self .pos_y , self .pos_z = round (x , 2 ), round (y , 2 ), self .camera_z
20882113 self .prompts (f'X:{ self .pos_x } Y:{ self .pos_y } Z:{ self .pos_z } ' )
2114+
20892115 if self .is_crawl :
20902116 if self .crawl_status :
20912117 self .is_crawl = False
2118+ # 机械臂执行过程中,禁用某些控件编辑
2119+ self .controls_disable_place_offset (False )
20922120 if device == 'ultraArm P340' :
20932121 self .myCobot .set_angles (self .move_angles [1 ], 20 )
20942122 self .stop_wait (3 )
20952123 else :
20962124 self .myCobot .send_angles (self .move_angles [1 ], 50 )
2097- # self.check_position(self.move_angles[1], 0)
2125+ self .check_position (self .move_angles [1 ], 0 )
20982126 # send coordinates to move mycobot
20992127 if func == 'QR code recognition' or func == '二维码识别' :
21002128 if device == 'myPalletizer 260 for M5' or device == 'myPalletizer 260 for Pi' :
@@ -2107,11 +2135,11 @@ def moved(self, x, y):
21072135 self .stop_wait (2.5 )
21082136 elif device == 'mechArm 270 for Pi' or device == 'mechArm 270 for M5' :
21092137 self .myCobot .send_coords (
2110- [self .home_coords [0 ] + x , self .home_coords [1 ] + y , 150 , 172.36 , 5.36 , 125.58 ], 30 ,
2138+ [self .home_coords [0 ] + x , self .home_coords [1 ] + y , 150 , 172.36 , 5.36 , 125.58 ], 70 ,
21112139 1 )
21122140 self .myCobot .send_coords (
21132141 [self .home_coords [0 ] + x , self .home_coords [1 ] + y , self .camera_z , 172.36 , 5.36 ,
2114- 125.58 ], 30 , 1 )
2142+ 125.58 ], 70 , 1 )
21152143 data = [self .home_coords [0 ] + x , self .home_coords [1 ] + y , self .camera_z , 172.36 , 5.36 ,
21162144 125.58 ]
21172145 self .check_position (data , 1 )
@@ -2136,7 +2164,7 @@ def moved(self, x, y):
21362164 time .sleep (3 )
21372165
21382166 elif device == 'myCobot 280 for RISCV' :
2139- self .myCobot .send_coords ([x , y , self .camera_z , 178.99 , - 3.78 , - 62.9 ], 70 , 1 )
2167+ self .myCobot .send_coords ([x , y , self .camera_z , 178.99 , - 3.78 , - 62.9 ], 90 , 1 )
21402168 data = [x , y , self .camera_z , 178.99 , - 3.78 , 62.9 ]
21412169 self .check_position (data , 1 )
21422170
@@ -2147,10 +2175,10 @@ def moved(self, x, y):
21472175 self .myCobot .send_coords ([x , y , self .camera_z , 0 ], 20 , 0 )
21482176 self .stop_wait (1.5 )
21492177 elif device in ['mechArm 270 for Pi' , 'mechArm 270 for M5' ]:
2150- self .myCobot .send_coords ([x , y , 110 , - 176.1 , 2.4 , - 125.1 ], 60 ,
2178+ self .myCobot .send_coords ([x , y , 110 , - 176.1 , 2.4 , - 125.1 ], 70 ,
21512179 1 ) # usb :rx,ry,rz -173.3, -5.48, -57.9
21522180 # self.stop_wait(3)
2153- self .myCobot .send_coords ([x , y , self .camera_z , - 176.1 , 2.4 , - 125.1 ], 60 , 1 )
2181+ self .myCobot .send_coords ([x , y , self .camera_z , - 176.1 , 2.4 , - 125.1 ], 70 , 1 )
21542182 # self.stop_wait(3)
21552183 self .check_position ([x , y , self .camera_z , - 176.1 , 2.4 , - 125.1 ], 1 )
21562184
@@ -2172,7 +2200,7 @@ def moved(self, x, y):
21722200 time .sleep (2 )
21732201
21742202 elif device in ['myCobot 280 for RISCV' ]:
2175- self .myCobot .send_coords ([x , y , self .camera_z , 179.87 , - 3.78 , - 62.75 ], 60 , 1 )
2203+ self .myCobot .send_coords ([x , y , self .camera_z , 179.87 , - 3.78 , - 62.75 ], 90 , 1 )
21762204 self .check_position ([x , y , self .camera_z , 179.87 , - 3.78 , - 62.75 ], 1 )
21772205
21782206 else :
@@ -2183,8 +2211,8 @@ def moved(self, x, y):
21832211 self .stop_wait (1.5 )
21842212
21852213 elif device in ['mechArm 270 for Pi' , 'mechArm 270 for M5' ]:
2186- self .myCobot .send_coords ([x , y , 150 , - 176.1 , 2.4 , - 125.1 ], 60 , 1 )
2187- self .myCobot .send_coords ([x , y , self .camera_z , - 176.1 , 2.4 , - 125.1 ], 60 , 1 )
2214+ self .myCobot .send_coords ([x , y , 150 , - 176.1 , 2.4 , - 125.1 ], 70 , 1 )
2215+ self .myCobot .send_coords ([x , y , self .camera_z , - 176.1 , 2.4 , - 125.1 ], 70 , 1 )
21882216 self .check_position ([x , y , self .camera_z , - 176.1 , 2.4 , - 125.1 ], 1 )
21892217
21902218 elif device in ['myCobot 280 for Pi' , 'myCobot 280 for M5' ]:
@@ -2205,7 +2233,7 @@ def moved(self, x, y):
22052233 time .sleep (2 )
22062234
22072235 elif device in ['myCobot 280 for RISCV' ]:
2208- self .myCobot .send_coords ([x , y , self .camera_z , 179.87 , - 3.78 , - 62.75 ], 70 , 1 )
2236+ self .myCobot .send_coords ([x , y , self .camera_z , 179.87 , - 3.78 , - 62.75 ], 90 , 1 )
22092237 self .check_position ([x , y , self .camera_z , 179.87 , - 3.78 , - 62.75 ], 1 )
22102238
22112239 # open pump
@@ -2264,7 +2292,7 @@ def moved(self, x, y):
22642292 self .myCobot .send_angles (self .new_move_coords_to_angles [color ], 50 )
22652293 self .check_position (self .new_move_coords_to_angles [color ], 0 )
22662294 else :
2267- self .myCobot .send_coords (self .move_coords [color ], 40 , 0 )
2295+ self .myCobot .send_coords (self .move_coords [color ], 50 , 0 )
22682296 self .stop_wait (4 )
22692297
22702298 # close pump
@@ -2281,6 +2309,8 @@ def moved(self, x, y):
22812309 self .btn_color (self .place_btn , 'blue' )
22822310 self .num = 0
22832311 self .real_sx = self .real_sy = 0
2312+ # 运动结束后启用某些控件编辑
2313+ self .controls_disable_place_offset (True )
22842314 time .sleep (0.1 )
22852315 if self .auto_mode_status :
22862316 self .is_pick = True
@@ -2567,6 +2597,12 @@ def combox_func_checked(self):
25672597 def auto_mode (self ):
25682598 """automated operation"""
25692599 btn = [self .discern_btn , self .crawl_btn , self .place_btn ]
2600+ if not self .init_point_done :
2601+ if self .language == 1 :
2602+ QMessageBox .warning (self , 'prompt' , 'Please return to the initial point first!' )
2603+ else :
2604+ QMessageBox .warning (self , '警告' , '请先回到初始点!' )
2605+ return
25702606 if self .auto_mode_status :
25712607 self .auto_mode_status = False
25722608 self .discern_status = False
0 commit comments