Calculate corner positions of a square workpiece

Overview

This example calculates corner positions of a square workpiece.

Specification of this example


Behavior
This example measures the approximate lines around a square workpiece by [Scan Edge Position], and calculate cross points of them.

Screenshot


How to try this example
1.Click the link below, then the folder containing zip file automatically opens.
refFile

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 the approximate lines around a square workpiece by [Scan Edge Position], displays them in Image Window, and calculate cross points of them.

How to implement

Scene data
Unit No.
Processing Item
0.
Camera Image Input
1.
Scan Edge Position
2.
Scan Edge Position
3.
Scan Edge Position
4.
Scan Edge Position
5.
Macro
The Macro Program below segment is to be set in '5.Macro'.
Macro Program
*MCRINIT
    'Initialize                                   '(1)
    FIRSTUNITNO& = 1
    INDEXCOEFFICIENTA& = 14
    INDEXCOEFFICIENTB& = 15
    INDEXCOEFFICIENTC& = 16
    LINEWIDTH& = 5

    Dim LINEARPARAM1#(2), LINEARPARAM2#(2), LINEARPARAM3#(2), LINEARPARAM4#(2)
    Dim CROSSX#(3), CROSSY#(3)

Return

*MEASUREPROC

    GetUnitData (FIRSTUNITNO&), INDEXCOEFFICIENTA&, LINEARPARAM1#(0)        '(2)
    GetUnitData (FIRSTUNITNO&), INDEXCOEFFICIENTB&, LINEARPARAM1#(1)
    GetUnitData (FIRSTUNITNO&), INDEXCOEFFICIENTC&, LINEARPARAM1#(2)
    GetUnitData (FIRSTUNITNO& + 1), INDEXCOEFFICIENTA&, LINEARPARAM2#(0)
    GetUnitData (FIRSTUNITNO& + 1), INDEXCOEFFICIENTB&, LINEARPARAM2#(1)
    GetUnitData (FIRSTUNITNO& + 1), INDEXCOEFFICIENTC&, LINEARPARAM2#(2)
    GetUnitData (FIRSTUNITNO& + 2), INDEXCOEFFICIENTA&, LINEARPARAM3#(0)
    GetUnitData (FIRSTUNITNO& + 2), INDEXCOEFFICIENTB&, LINEARPARAM3#(1)
    GetUnitData (FIRSTUNITNO& + 2), INDEXCOEFFICIENTC&, LINEARPARAM3#(2)
    GetUnitData (FIRSTUNITNO& + 3), INDEXCOEFFICIENTA&, LINEARPARAM4#(0)
    GetUnitData (FIRSTUNITNO& + 3), INDEXCOEFFICIENTB&, LINEARPARAM4#(1)
    GetUnitData (FIRSTUNITNO& + 3), INDEXCOEFFICIENTC&, LINEARPARAM4#(2)

    Crspoint LINEARPARAM1#(), LINEARPARAM2#(), CROSSX#(0), CROSSY#(0)       '(3)
    Crspoint LINEARPARAM2#(), LINEARPARAM3#(), CROSSX#(1), CROSSY#(1)
    Crspoint LINEARPARAM3#(), LINEARPARAM4#(), CROSSX#(2), CROSSY#(2)
    Crspoint LINEARPARAM4#(), LINEARPARAM1#(), CROSSX#(3), CROSSY#(3)

Return

*MEASUREDISPG

    SetDrawStyle PS_SOLID, LINEWIDTH&, JUDGE_OK         '(4)
    DrawLine CROSSX#(0), CROSSY#(0), CROSSX#(1), CROSSY#(1), 0
    DrawLine CROSSX#(1), CROSSY#(1), CROSSX#(2), CROSSY#(2), 0
    DrawLine CROSSX#(2), CROSSY#(2), CROSSX#(3), CROSSY#(3), 0
    DrawLine CROSSX#(3), CROSSY#(3), CROSSX#(0), CROSSY#(0), 0

Return

The macro program is in refthis link.
Explanation
(1)Initialize parameters(ex.external reference data No. of line coefficients ) when initialize measurement.
(2)Get the line coefficients of approximate lines around the work.
(3)Get the cross points of approximate lines.
(4)Draw lines which connect them in Image Window.