Calculate the approximate outer circumference of a circular workpiece
Overview
This example calculates the approximate outer circumference of a circular workpiece.
Specification of this example
Behavior
This example measures outer edges of a circular workpiece by [Edge Position], calculates the approximate outer circumference of it, and displays the result in Image Window.
Screenshot
How to try this example
1.Click the link below, then the folder containing zip file automatically opens.
File
2.Right-click and hold on the zip file, and drop it on working window of FJ system. The images and scene data in zip file are loaded on the program automatically.
3.Re-measure the image. Then System automatically measures outer edges of a circular workpiece by [Edge Position], calculates the approximate outer circumference of it, and displays the result in Image Window.
How to implement
Scene data
Unit No.
|
Processing Item
|
0.
|
Camera Image Input
|
1.
|
Edge Position
|
2.
|
Edge Position
|
3.
|
Edge Position
|
4.
|
Edge Position
|
5.
|
Edge Position
|
6.
|
Edge Position
|
7.
|
Edge Position
|
8.
|
Edge Position
|
9.
|
Macro
|
The Macro Program below segment is to be set in '9.Macro'.
Macro Program
*MCRINIT
UNITNO& = 1 '(1)
LOOPCOUNT& = 8
FONTSIZE& = 24
Dim POSX#(7), POSY#(7)
Return
*MEASUREPROC
'(2)
For COUNT& = 0 To (LOOPCOUNT& - 1)
GetUnitData (UNITNO& + COUNT&), "X", POSX#(COUNT&)
GetUnitData (UNITNO& + COUNT&), "Y", POSY#(COUNT&)
Next
ApproximationCircle LOOPCOUNT&, POSX#(), POSY#(), CENTERX#, CENTERY#, RADIUS# '(3)
Return
*MEASUREDISPG
'(4)
SetDrawStyle PS_SOLID, 5, JUDGE_OK
DrawCircle CENTERX#, CENTERY#, RADIUS#, 0
'(5)
SetTextStyle FONTSIZE&, TA_TOP, JUDGE_OK, 0, FONTSTYLE_BOLD + FONTSTYLE_UNDERLINE
DrawTextG "Center X: " + Str2$(CENTERX#, 3, 2, 0, 0) + ", Center Y: " + Str2$(CENTERY#, 3, 2, 0, 0) + ", Radius: " + Str2$(RADIUS#, 3, 2, 0, 0), 10, 10, 0 '(6)
Return
The macro program is in
this link.
Explanation
(1)Initialize parameters(ex.measurement times of [Edge Position] ) when initialize measurement.
(2)Get the outer edges of a circular workpiece.
(3)Calculate the approximate outer circumference of it.
(4)Display the center position and radius of the circumference in Image Window.
(5)Draw the circumference in Image Window.