Biên dạng mô phỏng từ G-Code

Một phần của tài liệu Thiết kế và chế tạo hệ thống nhận diện mối hàn cho robot tự động (Trang 105)

97 Kết quả mô phỏng cho thấy, quỹ đạo được tạo ra bởi thuật tốn có hình dạng giống với quỹ đạo thực tế của mẫu.

4.3.2. Thực nghiệm toàn bộ hệ thống

Thực nghiệm toàn bộ hệ thống nhằm kiểm chứng lại tồn bộ hệ thống có hoạt động đúng với yêu cầu đề ra ban đầu. Thực nghiệm toàn bộ hệ thống sẽ được thực hiện bằng cách vận hành toàn bộ hệ thống theo đúng quy trình. Kết quả của quá trình này được đánh giá dựa theo ghi nhận về độ lệch biên dạng giữa thuật toán và mẫu.

Điều kiện và cách thức tiến hành thực nghiệm

Nhóm tiếp tục sử dụng mẫu thử là một tấm thép có kích thước 40x20 cm được cắt và hàn đính giống như khi thực nghiệm xử lý ảnh. Hệ thống được được thiết lập với các tham số như sau:

Bảng 4.2: Các thông số thiết lập

Tên tham số Giá trị

ppm 44.06237571 pixel/mm

xoffset 33.6848 mm

(yoffset + j/ppm) 105.6454 mm

v 300 mm/phút

Do giới hạn về hành trình của bàn máy, nhóm khơng thể thực nghiệm với tồn bộ đường hàn, quá trình thực nghiệm được tiến hành với một đoạn của mẫu có độ dài 130 mm theo phương Y. Nhóm sẽ tiến hành thực thi tồn bộ chương trình và kiểm tra các giá trị được ghi nhận trong tập tin G-Code được lưu trữ.

Kết quả thực nghiệm

Sau khi tiến hành 5 lần thực nghiệm, nhóm ghi nhận được quỹ đạo điều khiển bởi hệ thống bám sát với đường hàn thực tế. Độ lệch lớn nhất ghi nhận được nằm trong khoảng 0,5 mm theo phương X.

98

99

100

Nhận xét

Sau khi thực nghiệm riêng lẻ xử lý ảnh cũng như thực nghiệm vận hành toàn hệ thống, kết quả cho thấy giải thuật xử lý ảnh hoạt động tốt, có khả năng nhận diện và xác định đường hàn với độ chính xác cao. Tuy nhiên việc kết hợp giữa xử lý ảnh và điều khiển chưa thực sự đồng bộ, dẫn đến có sự sai lệch.

101

Chương 5: KẾT LUẬN 5.1. Kết quả đạt được

Sau thời gian thực hiện đồ án tốt nghiệp, các mục tiêu đề ra đối với đề tài đã được hoàn thành. Một số kết quả đạt được như sau:

- Xây dựng được thuật toán nhận diện đường hàn. - Thiết kế và hồn thiện mơ hình kiểm chứng.

- Xây dựng chương trình điều khiển dựa trên dữ liệu từ xử lý ảnh cho mơ hình. So với mục tiêu ban đầu đề ra, nhóm đã hồn thành đúng như kế hoạch đặt ra. Thuật tốn xử lý ảnh có khả năng nhận diện và trích xuất dữ liệu tương đối hiệu quả, chính xác. Mơ hình phần cứng hoạt động tốt, đáp ứng đủ các tiêu chí đã đề ra trước. Ngồi ra, thơng qua q trình thực hiện đề tài, nhóm có cơ hội vận dụng các kiến thức đã học vào việc thiết kế và giải quyết các vấn đề được đặt ra.

5.2. Những mặt hạn chế

Ngồi những kết quả đạt được thì nhóm cũng ghi nhận một vài hạn chế của hệ thống như sau:

- Thuật tốn điều khiển cịn phụ thuộc nhiều vào phần mềm Mach 3, chưa tối ưu cho việc tích hợp vào một hệ thống hàn tự động hồn chỉnh.

- Chưa có giao diện tương tác và điều khiển.

5.3. Hướng phát triển

Từ những mặt hạn chế của đề tài, để đề tài hoạt động tốt hơn và có thể áp dụng vào thực tế, nhóm xin đề xuất những hướng phát triển như sau: Phát triển riêng hệ thống điều khiển, phát triển giao diện tương tác, điều khiển.

102

TÀI LIỆU THAM KHẢO Tiếng Việt

[1] Lương Mạnh Bá, Nguyễn Thanh Thủy (2006), “Nhập môn xử lý ảnh số”, Nhà

xuất bản khoa học và kỹ thuật.

[2] Trịnh Chất, Lê Văn Uyển (2006), “Tính tốn thiết kế hệ dẫn động cơ khí”, Nhà

xuất bản giáo dục, tập một và hai.

[3] Nguyễn Thúc Hà, Bùi Văn Hạnh, Võ Văn Phong (2006), “Giáo trình cơng nghệ hàn”, Nhà xuất bản giáo dục.

[4] Nguyễn Quang Hoan (2006), “Giáo trình Xử lý ảnh”, Học viện cơng nghệ bưu

chính viễn thơng.

[5] Trần Ngọc Nhuần (2006), “Đai răng – đặc điểm và cấu tạo”, Tạp chí Khoa học

– Cơng nghệ Thủy sản, số 03-04/2006.

[6] Nguyễn Hiền Minh, Phan Thanh Phong (2019), “Ứng dụng xử lý ảnh trong hệ thống phân loại sản phẩm”, Đại học Sư phạm kỹ thuật Thành phố Hồ Chí Minh. [7] Đỗ Năng Tồn, Phạm Việt Bình (2007), “Giáo trình Xử lý ảnh”, Đại học Thái

Nguyên.

[8] Động cơ bước (STEP), phân loại, ứng dụng và điều khiển. Internet: https://vietmachine.com.vn/cac-loai-dong-co-buoc-step-phan-loai-ung-dung-va- dieu-khien.html, 26/04/2021.

[9] Hướng dẫn cách tháo lắp trục vít me đai ốc bi - Cách sửa chữa vít me đai ốc bi. Internet: https://tayhostar.vn/huong-dan-cach-thao-lap-truc-vit-me-dai-oc-bi- cach-sua-chua-vit-me-dai-oc-bi-a41.html, 26/04/2021.

[10] Máy hàn tự động là gì? Các loại máy hàn tự động hiện nay. Internet: https://maydochuyendung.com/tin-tuc/tu-van-tieu-dung/may-han-tu-dong-la-gi-cac- loai-may-han-tu-dong-hien-nay, 24/04/2021.

103 [11] Python (ngơn ngữ lập trình).

Internet:https://vi.wikipedia.org/wiki/Python_(ngơn_ngữ_lập_trình), 11/08/2021. [12] Cơng tắc hành trình Limit Switch. Internet: https://thietbihienthi.com/cong- tac-hanh-trinh-limit-switch/, 01/07/2021.

[13] Cơ cấu truyền động (vít me, ray trượt, đai). Internet:

https://vietmachine.com.vn/co-cau-truyen-dong-vit-me-ray-truot-dai.html, 01/07/2021.

[14] Kiến thức dây đai (dây curoa) ai cũng phải biết. Internet:

https://cuahangvattu.com/blog/kien-thuc-day-dai-day-curoa-ai-cung-phai-biet, 01/07/2021.

[15] Hàn ma sát là gì? tìm hiểu tổng quan về phương pháp hàn ma sát. Internet: http://cokhithanhduy.com/han-ma-sat-la-gi-tim-hieu-tong-quan-ve-phuong-phap- han-ma-sat/, 01/07/2021.

[16] Thanh trượt con trượt QWW series HIWIN. Internet:

https://www.ngananhphat.com/vn/san-pham/2196/thanh-truot-con-truot-qww- series-hiwin.html, 01/07/2021.

Tiếng Anh

[17] Azhar Shaukharova, Yi Liang, Hutian Feng, Bin Xu (2016), “Study of Stiffness of Linear Guide Pairs by Experiment and FEA”, World Journal Engineering and Technology (April. 2016).

[18] Guangyuan Zhang, Zhengfang Zhu, Guannan Si (2014), “Welding line detection based on image for automatic welding machine”, IEEE, (20-21 Dec. 2014). [19] Oriental Motor USA Corp, “Technical Reference”.

[20] Oriental Motor USA Corp, “Motor Sizing Calculations”.

104 [22] Rafael C. Gonzalez, Richard E. Woods (2008), “Digital Image Processing”, Pearson Education Inc.

[23] Belt Actuator Sizing Tool. Internet: https://www.orientalmotor.com/motor- sizing/beltActuator-sizing.html, 02/05/2021.

[24] NEMA 23 Stepper motor 57x100mm 2.5Nm. Internet: https://mro.ecvv.com/product/4891239, 01/07/2021.

[25] NEMA 23 Closed loop stepper motor drive kit 2.2Nm LC57H280. Internet: https://vi.aliexpress.com/item/4000597353388.html, 01/07/2021.

[26] Laser Pressure Welding. Internet:

https://www.manufacturingguide.com/en/laser-pressure-welding, 01/07/2021 [27] 1605 ball screw set: SFU1605 ball screw with end machining + ball screw supporter + ball nut housing + coupling. Internet:

https://cpdxkcnc.com/products/1605-ball-screw-set-sfu1605-ball-screw-with-end- machining-ball-screw-supporter-ball-nut-housing-coupling-530, 01/07/2021.

105 PHỤ LỤC #==========================================================================# # WINDOWS VERSION #==========================================================================# #==========================================================================# # IMPORT MODULES ARE USED

#==========================================================================# import cv2 as cv import numpy as np import argparse import math import datetime import os import imutils import time import pywinauto

from pywinauto.application import Application # import pywinauto lib from pywinauto import Desktop

from pywinauto.keyboard import send_keys

#==========================================================================# # INITIALIZING GLOBAL VARIABLES WITH INITIAL VALUE

#==========================================================================# y_dis = 0 state = 0 alpha = 5 beta = 0 ppm = 44.06237571

# Image saved directory

directory = r'D:\\Welding_image_process\\img_saved'

# Set the name of output file timenow = datetime.datetime.now()

filename_output = "D:\Welding_image_process\data\gcode_" + \

timenow.strftime("%d%m%y")+"_"+timenow.strftime("%H%M%S")+".txt" file_output = open(filename_output, "w+")

file_output.close()

# Define the codec and create VideoWriter object

filename_video = "D:\\Welding_image_process\\img_saved\\video_" + \ timenow.strftime("%d%m%y")+"_"+timenow.strftime("%H%M%S")+".avi" fourcc = cv.VideoWriter_fourcc(*'XVID')

106

out = cv.VideoWriter(filename_video, fourcc, 20.0, (640, 480)) start_time = 0 FirstTO = 0 GlobalTO = 0 #==========================================================================# # IMPLEMENTATION #==========================================================================# #**

# @brief line_prepend - add a line to the beginning of current lines # @details #==========================================================================# def line_prepend(newContent): file_output = open(filename_output, "r+") currentContent = file_output.read() # print(currentContent) file_output.seek(0, 0) file_output.write(newContent + "\n") file_output.write(currentContent) file_output.close() #**

# @brief state_0 - send home & move command to Mach3 software # @details

#==========================================================================#

def state_0():

appMach3 = Application(backend='uia').connect( title="Mach3 CNC Controller ")

# First step - Load Recent File

loadRF = appMach3.Mach3CNCController.child_window(

title="Recent File", auto_id="8349", control_type="Button").wrapper_ object()

loadRF.click() time.sleep(0.1) # Click 'OK'

okBTN = appMach3.Mach3CNCController.child_window(

title="OK", auto_id="1", control_type="Button").wrapper_object() okBTN.click()

time.sleep(0.1) # Edit GCode

107

title="Edit G-

Code", auto_id="8586", control_type="Button").wrapper_object()

okBTN.click() time.sleep(0.1)

# Edit gcode by notepad

notepad = Application(backend='uia').connect(title="gcode.txt - Notepad" )

send_keys('^a') # send key "alt + a" to mach3 software time.sleep(0.05)

# Add "G0 Y5" into gcode file to control Mach3 Y Homing

notepad.gcodetxtNotepad.Edit.type_keys("G0 X30 Y5", with_spaces=True) time.sleep(0.05)

send_keys('{ENTER}') # send key "Enter" to mach3 software time.sleep(0.05) notepad.gcodetxtNotepad.menu_select("File -> Save") time.sleep(0.05) notepad.gcodetxtNotepad.menu_select("File -> Exit") time.sleep(0.2) send_keys('%r') send_keys('%r') time.sleep(30) ################################ loadRF.click() time.sleep(0.1) # Click 'OK' okBTN = appMach3.Mach3CNCController.child_window(

title="OK", auto_id="1", control_type="Button").wrapper_object() okBTN.click()

time.sleep(0.1) # Edit GCode

okBTN = appMach3.Mach3CNCController.child_window( title="Edit G-

Code", auto_id="8586", control_type="Button").wrapper_object()

okBTN.click() time.sleep(0.1)

# Edit gcode by notepad

notepad = Application(backend='uia').connect(title="gcode.txt - Notepad" )

send_keys('^a') time.sleep(0.05)

108

# Add "G1 Y180 F300" into gcode file to control Mach3 goto Y180 with Fee drate = 300 mm/p

notepad.gcodetxtNotepad.Edit.type_keys("G1 Y135 F300", with_spaces=True) time.sleep(0.05) send_keys('{ENTER}') time.sleep(0.05) notepad.gcodetxtNotepad.menu_select("File -> Save") time.sleep(0.05) notepad.gcodetxtNotepad.menu_select("File -> Exit") time.sleep(0.1) send_keys('%r') send_keys('%r') time.sleep(0.05)

# Set State_var = 1 to switch to state 1

#**

# @brief state_1 - detect, recognize and creat gcode # @details #==========================================================================# def state_1(): global y_dis global state global start_time # global FirstTO # global GlobalTO

img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

img_gray_ct = cv.addWeighted(img_gray, alpha, np.zeros( img_gray.shape, img_gray.dtype), 0, beta)

img_copy = np.copy(img)

# Set canny threshold and hough theshold canny_threshold = 100

hough_threshold = 120

blur_img = cv.blur(img_gray_ct, (9, 9)) binary_img = cv.adaptiveThreshold(

blur_img, 255, cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY_INV, 21,

2)

binary_img = cv.erode(binary_img, None, iterations=2) # Skeletonize the image

109

# HoughLine

lines = cv.HoughLines(skeleton_img, 1, np.pi / 180, hough_threshold, None, 0, 0) all_point_x_top = []

all_point_x_bottom = [] if lines is not None:

for i in range(0, len(lines)): rho = lines[i][0][0] theta = lines[i][0][1] a = math.cos(theta) b = math.sin(theta) pt1 = (int(rho/a), 0) pt2 = (int((rho/a)-640*(b/a)), 640)

if ((pt1[0] < 640 and pt1[0] > 0) and # pt1[0] (X_1) must be in range (0;640)

(pt2[0] < 640 and pt2[0] > 0) and # pt2[0] (X_2) must be in range (0;640) # pt1[0] (X_1) and pt2[0] (X_2) cannot be 0 (pt1[0] != 0 and pt2[0] != 0) and (pt1[0] != pt2[0])): # pt1[0] (X_1) and pt2[0] (X_2) mu st be different #y1 != y2 all_point_x_top.append(pt1) all_point_x_bottom.append(pt2) num_line = len(all_point_x_top) if (num_line != 0):

#Calculate the lines then take their average line ave_top_point = 0

ave_bottom_point = 0

for i in range(0, num_line):

ave_top_point += all_point_x_top[i][0] ave_bottom_point += all_point_x_bottom[i][0] ave_top_point = int(ave_top_point/num_line) ave_bottom_point = int(ave_bottom_point/num_line) cv.line(img_copy, (ave_top_point, 0), (ave_bottom_point, 640), (0, 0, 255), 1)

110 for j in range(0, 640): if ((img_copy[240, j][0] == 0) and (img_copy[240, j][1] == 0) and (img_copy[240, j][2] == 255)): # Distance of X x_dis = (j/ppm) + 33.6848 # delta_X = 33.6848

# Delta Time from the starting of state 3 to current DeltaTime = (end_time - start_time)

y_dis = round((DeltaTime*(300/60) + 105.6454), 4) # #visme 33mm from base

# #DATA SAMPLE G90 G1 F2000 X Y str_gcode = "G1 X" + \

str(round(x_dis, 4)) + " Y" + str(y_dis) + " F300" # Add the new str_gcode line above the previous one line_prepend(str_gcode) # cv.putText(img_copy,str(round(distance_line,4)),(50,50 ),fontFace=cv.FONT_HERSHEY_COMPLEX,fontScale=1,color=(150,100,200),thickness =2) # cv.arrowedLine(img_copy,(0,240),(j,240),(255,255,0),5) # cv.arrowedLine(img_copy,(j,240),(0,240),(255,255,0),5) # cv.line(img_copy,(0,240),(640,240),(0,255,0),1) break # else:

#print("LINE NOT FOUND")

cv.imshow("Detected Lines (in red) - Standard Hough Line Transform", img _copy) if (y_dis >= 240): cv.destroyAllWindows() state = 3 #==========================================================================# # MAIN CODE #==========================================================================#

print("State 0 - SETUP MACHINE. PLEASE WAIT 30 SECONDS...")

if(state == 0): state_0() state = 1

print("State 1. ANALYZE AND GENERATE GCODE")

111

start_time = time.monotonic() while(state == 1):

ret, img = cap_video.read() # read frame then timing end_time = time.monotonic() # end of time delta # if frame is read correctly ret is True

if not ret:

print("Can't receive frame (stream end?). Exiting ...") break img = cv.flip(img, 1) img = cv.flip(img, 0) state_1() # Check key key = cv.waitKey(1)

if key & 0xFF == ord('q'): # Press "q" to quit break

print("DONE")

print("THE GCODE IS SAVED IN "+str(filename_output))

cap_video.release() cv.destroyAllWindows()

Một phần của tài liệu Thiết kế và chế tạo hệ thống nhận diện mối hàn cho robot tự động (Trang 105)

Tải bản đầy đủ (PDF)

(120 trang)