VPLC Series Machine Vision Motion Control All-in-One Quick Start (Part 3)

Publisher:DazzlingSpiritLatest update time:2024-09-29 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

ZV_REGION(copy_subImg, modRe, 1, 0) 'Draw the invalid area of ​​modRe image on the template image, the drawing color is black, used as mask

ZV_LATCH(copy_subImg, 1) 'Show the copied template image

end sub

'Update the eraser area

GLOBAL SUB draw_eraser()

if d_edit_m = 0 then 'If the template is edited

return 'Return to the sub-function and do not continue to execute

endif

DRAWRECT(c_rect(0), c_rect(1), c_rect(2), c_rect(3))'Draw the eraser area

END SUB

15

In the main.bas file, add a function that responds to the [Create Template] button on the edit template interface and associate it with the action function.



Motion Control

'The function that responds when the create template button is pressed on the edit template interface

GLOBAL SUB btn_loc_creModel()

d_is_creModel = 1

ZV_SHAPECREATERE(subImg, modRe,s_mod, d_mod_param(0), d_mod_param(1), d_mod_param(2), d_mod_param(3), d_mod_param(4), d_mod_param(5), d_mod_param(6), d_mod_param(7), d_mod_param( 8))

'Create a template

ZV_SHAPECONTOURS(s_mod, contlist1, 0) 'Get the template contour on the 0th pyramid

ZV_GRAYTORGB(subImg, colorSubImg) 'Convert grayscale image to RGB image

ZV_IMGINFO(colorSubImg, 0) 'Get colorSubImg image information and store it in table0

ZV_GETRIGIDVECTOR(mat_rigid1, 0, 0, 0, TABLE(0)/2, TABLE(1)/2, 0)' Calculate the rigid transformation matrix

ZV_CONTAFFINE(contlist1, mat_rigid1, tsContlist1)'Affine transformation of contour or contour sequence

ZV_CONTLIST(colorSubImg, tsContlist1, ZV_COLOR(0, 255, 0), 0) 'Draw a green contour sequence on the colorSubImg image

ZV_LATCHCLEAR(2)

ZV_LATCH(colorSubImg, 2)

end sub



Motion Control


16

In the draw.bas file, add a function that responds to the [OK] button in the editing template interface and associate it with the action function.



Motion Control

'The function executed when the OK button is pressed on the editing template interface

GLOBAL SUB btn_erase_cfm()

ZV_LATCHCLEAR(0)

ZV_LATCH(grabImg, 0) 'Display image on latch

HMI_CLOSEWINDOW(12) 'Close the template editing window

END SUB


Motion Control


17

In the main.bas file, add a function to create a response to the [Test] button in the template interface and associate it with the action function.



Motion Control

'Create a function that responds when the test button is pressed on the template interface

GLOBAL SUB btn_loc_test()

if (d_is_creModel = 0) then

?"Template not created!"

return

endif

'Start matching

TICKS = 0

ZVOBJECT match_rst, sIm g, colorImg

ZV_GAUSSBLUR(grabImg, sImg, 3)

ZV_SHAPEFIND(s_mod, sImg, match_rst, d_match_param(0), d_match_param(1), d_match_param(2), d_match_param(3), d_match_param(4), d_match_param(5), d_match_param(6))

ZV_MATINFO(match_rst, 0)

ZV_GRAYTORGB(sImg, colorImg)

if TABLE(0) > 0 then

local rowr

for rowr = 0 to TABLE(0) -1

ZV_MATGETROW(match_rst, rowr, 5, 3) 'Get the data of rowr in the match_rst matrix into table. The maximum length of table is 5

if(rowr = 0) then

d_match_rst(0) = TABLE(3)

d_match_rst(1) = TABLE(4)

d_match_rst(2) = TABLE(5)

d_match_rst(3) = TABLE(6)

d_match_rst(4) = TABLE(7)

ZV_GETRIGIDVECTOR(mat_rigid1, 0, 0, 0, TABLE(4), TABLE(5), TABLE(6))'Calculate the rigid transformation matrix

ZV_CONTAFFINE(contlist1, mat_rigid1, tsContlist1)'Affine transformation of contour or contour sequence

ZV_CONTLIST(colorImg, tsContlist1, ZV_COLOR(0, 255, 0), 0) 'Draw a green contour sequence on the colorSubImg image

endif

next

else

d_match_rst(0) = -1

d_match_rst(1) = -1

d_match_rst(2) = -1

d_match_rst(3) = -1

d_match_rst(4) = -1

endif

d_match_time = abs(TICKS) 'match time

ZV_LATCH(colorImg, 0)

end sub



Motion Control


18

In the draw.bas file, add a function to create a template interface [OK] button response and associate it with the action function.



Motion Control

'Create a function that responds when the OK button is pressed on the template interface

GLOBAL SUB btn_loc_cfm()

grab_switch = 0 'Turn off continuous acquisition of correction source

d_is_rtn_loc = 1

ZV_LATCHCLEAR(0)

ZV_LATCH(grabImg, 0) 'Display image on latch

ZV_LATCH(grabImg, 1) 'Display image on latch

HMI_CLOSEWINDOW(11)

END SUB



Motion Control


19

In the main.bas file, add a function that responds to the [Single Execution] button on the main interface and associate it with the action function.



Motion Control

'The function that responds when the single execution button is pressed on the main interface

GLOBAL SUB btn_test()

btn_grab()' Single acquisition image

btn_loc_test() 'matching test function

END SUB



Motion Control


20

In the main.bas file, add a function that responds to the [Continuous Run] button on the main interface and associate it with the action function.



Motion Control

'The function that responds when the continuous run button is clicked on the main interface

GLOBAL SUB btn_run()

if(run_switch = 1) then

"Continuous operation has been started, please do not repeat the operation!"

return

endif

run_switch = 1

if (1 = run_switch) then

if (0 = PROC_STATUS(main_task_id)) then

RUNTASK main_task_id, main_task

endif

endif

END SUB

'Continuously run the main task content

main_task:

while(1)

if (0 = run_switch) then

exit while

endif

'The following performs related positioning operations

btn_grab()

btn_loc_test()

wend

END


Motion Control


twenty one

In the main.bas file, add a function that responds to the [Stop Running] button on the main interface and associate it with the action function.



Motion Control



'The function that responds when the stop execution button is clicked on the main interface

GLOBAL SUB btn_stop()

if(run_switch = 0) then

?"Continuous operation is not enabled!"

return

endif

run_switch = 0

END SUB



Motion Control


Simulation Demonstration effect



Motion Control


This time, the VPLC series machine vision motion control all-in-one machine quick start (Part 3) - visual positioning based on shape matching is shared here.


[1] [2] [3]
Reference address:VPLC Series Machine Vision Motion Control All-in-One Quick Start (Part 3)

Previous article:What is the output voltage of the torque motor controller?
Next article:ZMC Motion Controller SCARA Robot Application Quick Start

Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号