def robotic_work(): init() number_objects = len(coordinate) print(number_objects, coordinate) for rounds in range(number_objects): x = coordinate[rounds] color = COLOR_s[rounds] pun.Control('COM4', buarate, speed).Graper(40) time.sleep(1) pun.Control('COM4', buarate, speed).setReady() time.sleep(1) pun.Control('COM4', buarate, speed).gotoJoint(x[0], x[1], x[2], x[3], 45) time.sleep(2) pun.Control('COM4', buarate, speed).Graper(f_grap) time.sleep(2) pun.Control('COM4', buarate, speed).setReady() time.sleep(2) if (color == 'Green'): pun.Control('COM4', buarate, speed).gotoJoint(90, 5, -55, -90, 45) if (color == 'Red'): pun.Control('COM4', buarate, speed).gotoJoint(-90, 5, -55, -90, 45) time.sleep(2) pun.Control('COM4', buarate, speed).Graper(15) time.sleep(2) pun.Control('COM4', buarate, speed).setReady() time.sleep(1)
def actions_ready(self): buadrate = self.text_br.text() comport = self.text_port.text() speed = self.text_speed.text() speed = int((int(speed) / 100) * 255) if(speed >255):speed = 255 pun.Control(comport,buadrate,speed).setReady() print("Ready Start",buadrate,comport)
def actions_ungrap(self): buadrate = self.text_br.text() comport = self.text_port.text() speed = self.text_speed.text() speed = int((int(speed) / 100) * 255) if(speed >255):speed = 255 pun.Control(comport,buadrate,speed).Graper(20) print("grap Start",buadrate,comport)
def actions_home(self): buadrate = self.text_br.text() comport = self.text_port.text() speed = self.text_speed.text() speed = int((int(speed) / 100) * 255) if(speed >255):speed = 255 pun.Control(comport,buadrate,speed).gotoHome() print("Home Start",buadrate,comport)
def gotoHome(event): try: port = entry_port.get() bps = int(entry_bps.get()) speed = int(entry_speed.get()) pun.Control(port, bps, speed).gotoHome() except: print(" ")
def readyPosition(event): try: port = entry_port.get() bps = int(entry_bps.get()) speed = int(entry_speed.get()) pun.Control(port, bps, speed).setReady() except: print(" ")
def grapOff(event): try: port = entry_port.get() bps = int(entry_bps.get()) speed = int(entry_speed.get()) pun.Control(port, bps, speed).Graper(30) except: print(" ")
def actions_rotate_hand(self): angle = int(self.text_rt.text()) buadrate = self.text_br.text() comport = self.text_port.text() speed = self.text_speed.text() speed = int((int(speed) / 100) * 255) if(speed >255):speed = 255 pun.Control(comport,buadrate,speed).Rotate_hnad(angle) print("grap Start",buadrate,comport)
def run(self): #t1 = Thread (target=chang.getImage) t2 = Thread (target=self.robotic_work) result = False pun.Control(self.comport,self.buarate,self.speed).gotoHome() while(1): if(result == False): result = self.robotic_work() else: break
def actions_manual(self): angle = int(self.text_rt.text()) buadrate = self.text_br.text() comport = self.text_port.text() speed = self.text_speed.text() speed = int((int(speed) / 100) * 255) if(speed >255):speed = 255 pos_x = int(self.text_x.text()) pos_y = int(self.text_y.text()) pos_z = int(self.text_z.text()) x = readCSV.getPositons(pos_x,pos_y,pos_z) pun.Control(comport,buadrate,speed).gotoJoint(x[0],x[1],x[2],x[3],angle) print("Manual Start",buadrate,comport,pos_x,pos_y,pos_z)
def gotoPoint(event): try: port = entry_port.get() bps = int(entry_bps.get()) speed = int(entry_speed.get()) x_cor = int(entry_x.get()) y_cor = int(entry_y.get()) z_cor = int(entry_z.get()) q0, q1, q2, q3 = Arm.fw_kinematic(x_cor, y_cor, z_cor).findPositions() theta = Label(root, text=str(q0) + "\t" + str(q1) + "\t" + str(q2) + "\t" + str(q3) + " ").grid(row=2, column=4) pun.Control(port, bps, speed).gotoJoint(q0, q1, q2, q3, 45) except: theta = Label(root, text="Try agian ! I's out more range ").grid( row=2, column=4)
def init(): pun.Control('COM4', buarate, speed).gotoHome() objects = chang.getImage() number_objects = len(objects) print(number_objects) for i in range(number_objects): positions_x = objects[i][1] positions_y = objects[i][0] color = objects[i][2] x = (positions_x / 10) + 12 y = ((positions_y * -1) / 10) + 25.6 z = 2 y = y - 5 x = Arm.fw_kinemtic(x, y, z).findPositions() coordinate.append((x)) COLOR_s.append(color)
import cv2 import Arm import pun import time import chang chang.getImage() chang.processImage() x, y = chang.calculateDistance() x = x + 11 y = y - 3 pun.Control('COM15', 1000000, 100).setReady() pun.Control('COM15', 1000000, 100).Graper(27) time.sleep(1) Q0, Q1, Q2, Q3 = Arm.fw_kinematic(x, y, 2).findPositions() Q4, Q5, Q6, Q7 = Arm.fw_kinematic(0, 20, 3).findPositions() pun.Control('COM15', 1000000, 100).gotoJoint(Q0, Q1, Q2, Q3, 45) time.sleep(3) pun.Control('COM15', 1000000, 100).Graper(-15) time.sleep(1) pun.Control('COM15', 1000000, 100).setReady() time.sleep(2) pun.Control('COM15', 1000000, 100).gotoJoint(Q4, Q5, Q6, Q7, 45) time.sleep(3) pun.Control('COM15', 1000000, 100).Graper(20) time.sleep(1) pun.Control('COM15', 1000000, 100).setReady() time.sleep(3)
def robotic_work(self): self.find_oj() result_fb = True number_objects = len(self.coordinate) print(number_objects,self.coordinate) for rounds in range(number_objects): x = self.coordinate[rounds] color = self.COLOR_s[rounds] type_ob = self.fake[rounds] pun.Control(self.comport,self.buarate,self.speed).Graper(35) time.sleep(1) pun.Control(self.comport,self.buarate,self.speed).setReady() time.sleep(1) pun.Control(self.comport,self.buarate,self.speed).gotoJoint(x[0],x[1],x[2],x[3],45) time.sleep(2) pun.Control(self.comport,self.buarate,self.speed).Graper(self.f_grap) time.sleep(2) pun.Control(self.comport,self.buarate,self.speed).setReady() time.sleep(2) chang.get_image_feedback() feed_back_pic = cv2.imread("data/feed_back.jpg",0) feed_back_pic = feed_back_pic[10:62,61:78] y =[] for i in range(feed_back_pic.shape[0]): for j in range(feed_back_pic.shape[1]): y.append(feed_back_pic[i][j]) value_detect =sum(y) / (feed_back_pic.shape[0] * feed_back_pic.shape[1]) if(value_detect <= 150): print("Have" + str(value_detect)) result_fb = True # if( color == 'Green'):pun.Control(self.comport,self.buarate,self.speed).gotoJoint(90,5,-55,-90,45) #if( color == 'Red'):pun.Control(self.comport,self.buarate,self.speed).gotoJoint(-90,5,-55,-90,45) if( type_ob == 'Tester'):pun.Control(self.comport,self.buarate,self.speed).gotoJoint(90,5,-55,-90,45) if( type_ob == 'Termarind'):pun.Control(self.comport,self.buarate,self.speed).gotoJoint(-90,5,-55,-90,45) if( type_ob == 'Can'):pun.Control(self.comport,self.buarate,self.speed).gotoJoint(0,5,-55,-90,45) time.sleep(2) pun.Control(self.comport,self.buarate,self.speed).Graper(20) time.sleep(2) pun.Control(self.comport,self.buarate,self.speed).setReady() time.sleep(1) else: print("dont Have"+ str(value_detect)) result_fb = False pun.Control(self.comport,self.buarate,self.speed).gotoHome() break self.coordinate = [] self.COLOR_s = [] return result_fb