def btnHomeBe(self): g2.send('g90g0x0') #lay text tu text edit a = self.edit_Program.toPlainText() x = a.split() print(a) print(x)
def ScrollBarJerk(self): self.Jerk = self.ScrollBar_Jerk.value() * 10 jerk = str(self.Jerk) g2.send('$xjm=' + jerk) g2.send('$yjm=' + jerk) g2.send('$zjm=' + jerk) g2.send('$ajm=' + jerk) g2.send('$bjm=' + jerk)
def JogReleased(self, joint): jerk = self.ScrollBar_Jerk.value() * 10 if joint == "X1" or joint == "X2": self.jogthread.STT = 0 g2.send("$xjm=" + str(jerk)) if joint == "Y1" or joint == "Y2": self.jogthread.STT = 0 g2.send("$yjm=" + str(jerk)) if joint == "Z1" or joint == "Z2": self.jogthread.STT = 0 g2.send("$zjm=" + str(jerk)) if joint == "A1" or joint == "A2": self.jogthread.STT = 0 g2.send("$ajm=" + str(jerk)) if joint == "B1" or joint == "B2": self.jogthread.STT = 0 g2.send("$bjm=" + str(jerk))
def P_program(self, p): px = float(self.lb_px.text()) py = float(self.lb_py.text()) pz = float(self.lb_pz.text()) rad = pi / 180 x = float(self.lb_x.text()) * rad y = float(self.lb_y.text()) * rad z = float(self.lb_z.text()) * rad a = float(self.lb_a.text()) * rad b = float(self.lb_b.text()) * rad - 90 * rad + a step = self.SpinBox_Step.value() if self.rb_Left.isChecked(): otp = [1, 1, 0] else: otp = [0, 0, 0] if p == 'PX1': px = px + step if p == 'PX2': px = px - step if p == 'PY1': py = py + step if p == 'PY2': py = py - step if p == 'PZ1': pz = pz + step if p == 'PZ2': pz = pz - step j, limit = R.ikine([px, py, pz], [x, y, z, a, b], otp) if limit and self.cb_ApplyLimit.isChecked(): QMessageBox.about(self, "Error", "Joint is limit!") else: vel = str(self.Speed) cmd = 'g90g01x' + str(round(j[0], 4)) \ + 'y' + str(round(j[1], 4)) \ + 'z' + str(round(j[2], 4)) \ + 'a' + str(round(j[3], 4)) \ + 'b' + str(round(j[4] + 90 - j[3], 4)) \ + 'f' + vel g2.send(cmd)
def run(self): if len(w.gcode) > 4: for n in range(0, 4): cmd = w.gcode[n] g2.send(cmd) else: self.i = 0 print(w.OK) while self.sttRun: time.sleep(0.001) if w.OK: w.OK = 0 if self.i == len(w.gcode): print('#' * 50) w.lb_Line.setText("Done*********") self.i = 3 break w.lb_Line.setText(str(self.i)) cmd = w.gcode[self.i] g2.send(cmd) self.i += 1
def btn_Chup(self): mauphathien = "None" ret, img = self.cam.read() ret, img = self.cam.read() name = self.cbb_Mauthu1.currentText() data = pg.read_from_db(name) _, phathien = BoLoc(data, img) if phathien: mauphathien = name g2.send("A") else: name = self.cbb_Mauthu2.currentText() data = pg.read_from_db(name) _, phathien = BoLoc(data, img) if phathien: mauphathien = name g2.send("B") else: name = self.cbb_Mauthu3.currentText() data = pg.read_from_db(name) _, phathien = BoLoc(data, img) if phathien: mauphathien = name g2.send("C") else: mauphathien = "None" frame = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # get frame infos height, width, channel = frame.shape step = channel * width # create QImage from RGB frame qImg = QImage(frame.data, width, height, step, QImage.Format_RGB888) self.lb_Img.setPixmap(QPixmap.fromImage(qImg)) self.lb_Mauphathien.setText(mauphathien)
def btnServoON(self): if self.cb_ServoON.isChecked(): g2.send('$out1=1') else: g2.send('$out1=0')
def btnOutput8(self): if self.cb_Output8.isChecked(): g2.send('$out8=1') else: g2.send('$out8=0')
def btnOutput9(self): if self.cb_Output9.isChecked(): g2.send('$out9=1') else: g2.send('$out9=0')
def btnSendMDI(self): cmd = self.ld_stt.text() if cmd != '': g2.send(cmd) self.ld_stt.setText('')
def run(self): while self.STT: dataJog = w.dataJog g2.send(dataJog) time.sleep(0.02)
def btnHomeDay(self): g2.send('g90g0z0')
def btnPause(self): g2.send('!') print('pause')
def btnOutput2(self): if self.cb_Output2.isChecked(): g2.send('$out2=1') else: g2.send('$out2=0')
def btnOutput3(self): if self.cb_Output3.isChecked(): g2.send('$out3=1') else: g2.send('$out3=0')
def btnHomeAll(self): g2.send('g28.2x0y0z0') g2.send('g28.3x0y90z0a90b0')
def btnOutput1(self): if self.cb_Output1.isChecked(): g2.send('$out1=1') else: g2.send('$out1=0')
def run(self): try: g2.open() w.lb_stt_com.setText(g2.s.port + " connect OK") g2.send('$sv=2') g2.send('$ej=1') g2.send('g54') time.sleep(1) g2.send('$sv=1') g2.send('$si=100') # setting g2.send('$2po=1') g2.send('$3po=0') g2.send('$4po=0') g2.send('$yhd=1') g2.send('$zhd=1') g2.send('$xtn=-115') g2.send('$xtm=115') g2.send('$ytn=-30') g2.send('$ytm=225') g2.send('$ztn=-135') g2.send('$ztm=135') g2.send('$atn=-45') g2.send('$atm=225') g2.send('$btn=-180') g2.send('$btm=180') g2.send('$sl=1') g2.send('$xzb=35') g2.send('$yzb=5') g2.send('$zzb=21') except: error = g2.s.port + " connect ERROR" w.lb_stt_com.setText(error) self.STT = 0 while self.STT: if g2.s.in_waiting: # Or: while ser.inWaiting(): data = g2.read() data = data.decode() self.data.emit(data)
def btnReady(self): g2.send('g90g0x0y120z120a120b-30')
def run(self): print('Run') # ct = w.program a = w.edit_Program.toPlainText() a = a.upper() ct = a.split() print(ct) SL_Dat = w.Step_SL.value() SL = int(w.edit_SL.text()) try: for i in range(SL, SL_Dat): if self.sttRun == 0: break for n in range(0, len(ct)): if n == len(ct) - 1: w.edit_SL.setText(str(i + 1)) g2.send('g90g0x0y0u0') g2.send('G10 L20 P2 Z0') if self.sttRun == 0: break line = ct[n] if line == 'K1': print('Nâng khuôn ') w.lb_Stt.setText('Nâng khuôn') ecd.send('A1B0*') if line == 'K0': print('Hạ khuôn ') w.lb_Stt.setText('Hạ khuôn') ecd.send('A1B1*') if line[0] == 'A': goc = line.lstrip('A') print('Bẻ trước ' + goc) w.lb_Stt.setText('Bẻ trước ' + goc) g2.send('g90g01x' + goc + 'f10000') while w.lb_stt.text() != 'Next': time.sleep(0.1) pass if line[0] == 'B': goc = line.lstrip('B') print('Bẻ sau ' + goc) w.lb_Stt.setText('Bẻ sau ' + goc) g2.send('g90g01x' + goc + 'f10000') while w.lb_stt.text() != 'Next': time.sleep(0.1) pass if line[0] == 'X': goc = line.lstrip('X') print('Xoay ' + goc) w.lb_Stt.setText('Xoay ' + goc) g2.send('g90g01Y' + goc + 'f1000') while w.lb_stt.text() != 'Next': time.sleep(0.1) pass if line[0] == 'D': feed = line.lstrip('D') print('Đẩy dây ' + feed) w.lb_Stt.setText('Đẩy dây ' + feed) g2.send('g91g01Z' + feed + 'f1000') while w.lb_stt.text() != 'Next': time.sleep(0.1) pass time.sleep(0.1) except: print("END") self.n = 0 self.sttRun = 0 print('Stop....') w.lb_Stt.setText('Stop ')
def btnHomeAll(self): g2.send('g90g0x0y0u0') g2.send('G10 L20 P2 Z0')
def btnSendMDI(self): cmd = self.ld_stt.text() print(cmd) g2.send(cmd)
def btnZeroAll(self): g2.send('g90g0x0y90z0a90b0c0')
def btnOutput5(self): if self.cb_Output5.isChecked(): g2.send('$out5=1') else: g2.send('$out5=0')
def btnStop(self): g2.send('!') time.sleep(0.1) g2.send('%') print('Stop')
def btnOutput6(self): if self.cb_Output6.isChecked(): g2.send('$out6=1') else: g2.send('$out6=0')
def btnResume(self): g2.send('~') print('resume')
def btnOutput7(self): if self.cb_Output7.isChecked(): g2.send('$out7=1') else: g2.send('$out7=0')
def btnOutput4(self): if self.cb_Output4.isChecked(): g2.send('$out4=1') else: g2.send('$out4=0')
def JogPressed(self, joint): vel = str(self.Speed) if joint == "X1": g2.send("$xjm=2000") self.dataJog = "g91g1x0.1f" + vel if joint == "X2": g2.send("$xjm=2000") self.dataJog = "g91g1x-0.1f" + vel if joint == "Y1": g2.send("$yjm=1000") self.dataJog = "g91g1y0.1f" + vel if joint == "Y2": g2.send("$yjm=1000") self.dataJog = "g91g1y-0.1f" + vel if joint == "Z1": g2.send("$zjm=1000") self.dataJog = "g91g1z0.1f" + vel if joint == "Z2": g2.send("$zjm=1000") self.dataJog = "g91g1z-0.1f" + vel if joint == "A1": g2.send("$ajm=10000") g2.send("$bjm=10000") self.dataJog = "g91g1a0.5b-0.5f" + vel if joint == "A2": g2.send("$ajm=10000") g2.send("$bjm=10000") self.dataJog = "g91g1a-0.5b0.5f" + vel if joint == "B1": g2.send("$bjm=10000") self.dataJog = "g91g1b0.5f" + vel if joint == "B2": g2.send("$bjm=10000") self.dataJog = "g91g1b-0.5f" + vel self.jogthread.STT = 1 self.jogthread.start()