Hello Guest it is January 28, 2020, 09:33:39 AM

Author Topic: Registration mark detection (print cut) macro  (Read 4496 times)

0 Members and 1 Guest are viewing this topic.

Registration mark detection (print cut) macro
« on: March 12, 2014, 07:46:33 PM »
Hi All,

I'm working on a registration mark sensing macro that will allow for print cut registration (setting the origin), coordinate system rotation to account for imprecise placement of the graphic and stretch adjustment (scaling).  I have already discussed this topic a bit in some posts in this thread http://www.machsupport.com/forum/index.php/topic,26268.msg188768.html#new.  

I have already completed an arduino based mark sensor setup that will output +5V upon detecting the edge of a mark.  This can be easily wired to an input for mach3.

I'm not a VB guy, but I do have some programming and scripting experience in C++, Java and Actionscript.  I'm looking for some help.  I'm going to outline what the program needs to do below and perhaps you gurus of Mach3 can help!

Graphics will be printed with registration marks (L shaped blocks) of a known size printed at the corners outside the bounding box.
A cut file will be created in advance which will be offset from the origin according to the size of the registration marks.
The operator will place the graphic on the machine and position the photocell in the interior angle of the registration mark.
The operator will start the macro.
The macro will move the machine X+ slowly until the edge is sensed.
Once the edge is sensed, the machine backs up on the axis 50% the length of the (known) reg mark size and advances more slowly, recording the X position when the photocell senses the edge again.  The slow down is to ensure precise detection.
The machine again backs up 50% of the reg mark size and moves in the Y+ direction.
When the sensor detects the edge, once again the machine backs up and moves more slowly in Y+ recording the Y value of the registration mark.
Now the X and Y coordinates of our origin corner are recorded.
The machine will center itself between the x and y leg of the aforementioned mark and proceed to travel rapidly in X+.
Upon detecting the edge the machine will stop, and backup (a greater distance due to speed, this will have to be experimented with) and advance forward slowly.
Upon detecting the mark while moving slowly, it will record the X coordinate.
The machine will move forward slowly past the registration mark edge by 50% the registration mark size on the X axis and then proceed to move Y+
Upon detecting the edge, the machine will back up and then proceed slowly on Y+ again until the edge is detected.  Upon detection the Y coordinate is recorded.
Now with 2 points recorded, the rotation can be calculated with an arc tangent (used later)
The machine will return to the first corner defined (the corner nearest the origin) and run a similar routine to detect a 3rd mark at either remaining corner.

These 3 points should be sufficient to calculate rotation and linear stretch on both axis.  Can someone help me get started with the VB?  I'll be sharing the simple arduino reg mark detector design once it is mounted to the machine and working reliably.  If we all work a little on this I think we can quickly add some incredibly valuable functionality to Mach3 that many of us could really benefit from!

Re: Registration mark detection (print cut) macro
« Reply #1 on: March 13, 2014, 09:22:49 AM »
I use this to align a block, you might adapt this to your needs.
Gives you an idea as to the logic of probing and computing alignment.
If I had the "arduino based mark sensor setup" I could help more.
I find no reference to where this hardware is available.

Code: [Select]
Angle = GetOemDro(118)


CurrentToolDiameter = GetOemDRO(43)
X = GetUserDro (1053)
Y = GetUserDro (1054)
Z = GetUserDro (1055)

CurrentFeed = GetOemDRO(818) 'Get the current feedrate to return to later
CurrentAbsInc = GetOemLED(48) 'Get the current G90/G91 state
CurrentGmode = GetOemDRO(819) 'Get the current G0/G1 state
CurrentToolDiameter = GetOemDRO(43) 'gets the current tool diameter
PlateThickness = GetUserDRO(1051)
ToolLength = GetOemDRO(42)

MoveXDistance = ((X * 1.1) + CurrentToolDiameter)
MoveYDistance = ((Y * 1.1) + CurrentToolDiameter)
MoveDistance = .5 + CurrentToolDiameter
MoveZDistance = .5

If GetOemLed (825) <> 0 Then 'Check to see if the probe is already grounded or faulty
    Call ProbeGrounded()
    Exit Sub

'Get top of part

'DoOEMButton (1010) 'zero the Z axis so the probe move will start from here
Code "G4 P4" ' this delay gives me time to get from computer to hold probe in place
Code "G91 G31Z-2.0 F4" 'probing move, can set the feed rate here as well as how far to move
While IsMoving() 'wait while it happens
'Call SetDro (2, PlateThickness)

ZProbePos = GetVar(2002) 'get the axact point the probe was hit
'Code "G0 Z" &PlateThickness
'While IsMoving ()
Code "G1 G91 F40 Z" &MoveZDistance 'put the Z retract height you want here
While IsMoving ()

'Code "(Z axis is now zeroed)" 'puts this message in the status bar
Code "F" &CurrentFeed 'Returns to prior feed rate

'Call SetDro (2,GetDro(2)-Z)

'Probe The X sides

    XCurrent = GetDro(0)
    YCurrent = GetDro(1)

    Code "G4 P1" 'Pause 1 second to give time to position probe plate
    While IsMoving ()
    Call SetDro (0,0.000)
    While IsMoving ()
    Call SetDro (1,0.000)
    Code "F4" 'slow feed rate to 4 ipm

Rem Probe Y Face Side

    Code "G90 G0 X" &-MoveDistance
    Code "G4 P0.25"
    Code "G91 G0 Z" &-MoveZDistance-.2
    Code "G4 P0.25"
    XNew = Xcurrent + 3
    Code "G31 X" &XNew 'Probe X1,Y1 (P1) location
    While IsMoving() 'wait for the move to finish
    X1 = GetVar(2000) 'get the probe touch location
    Y1=0 ' Should always be zero
    Y2 = Y-0.5 '1/2 inch back from end of block

    Code "G91 G0 X-.25"
    Code "G4 P0.25"
    Code "G91 G0 Y" &Y2
    Code "G4 P0.25"
    Code "G31 X" &XNew 'Probe X2,Y2 (P2) location
    While IsMoving() 'wait for the move to finish
    X2 = GetVar(2000) 'get the probe touch location
    'Y2= Block length - 1/2 inch

    Code "G91 G0 Z" &MoveZDistance+.2
    Code "G4 P0.25"
    Code "G91 G0 Y" &-Y2 'Go back to the first spot
    Code "G4 P0.25"
    Code "G91 G0 X" &CurrentToolDiameter+.1 'rapid move back to start point
    Code "G4 P0.25"

Rem Probe X Face Side

    Code "G90 G0 Y" &-MoveDistance
    Code "G4 P0.25"
    Code "G91 G0 Z" &-MoveZDistance-.2
    Code "G4 P0.25"
    YNew = YCurrent + 3
    Code "G31 Y" &YNew 'Probe X3,Y3 (P3) location
    While IsMoving()
    Y3 = GetVar(2001)   'get the probe location
    X4 = X-0.5 '1/2 inch back from end of block

    Code "G91 G0 Y-.25"
    Code "G4 P0.25"
    Code "G91 G0 X" &X4
    Code "G4 P0.25"
    Code "G31 Y" &YNew 'Probe X4,Y4 (P4) location
    While IsMoving() 'wait for the move to finish
    Y4 = GetVar(2001) 'get the probe touch location
    'X4= Block Width - 1/2 inch

    Code "G90 G0 Z" &MoveZDistance+1    'Back up and clear
    Code "G4 P0.25"

t1= (x4-x3)*(y1-y3)-(y4-y3)*(x1-x3)
b1= (y4-y3)*(x2-x1)-(x4-x3)*(y2-y1)

t2= (x2-x1)*(y1-y3)-(y2-y1)*(x1-x3)
b2= (y4-y3)*(x2-x1)-(x4-x3)*(y2-y1)

XH=x1+ua*(x2-x1) ' X Home  distance away
YH=y1+ua*(y2-y1) ' Y Home  distance away

If X>Y Then
   If NewAngle > 0 Then
   End If
End If

Rem move To the Block Lower Corner

    Code "G90 G0 Y" &YH + CurrentToolDiameter/2
    Code "G90 G0 X" &XH + CurrentToolDiameter/2
    While IsMoving ()
    Call SetDro (1,0.000)
    While IsMoving ()
    Code "G4 P0.25"
    Call SetDro (0,0.000)
    Call SetDro (1,0.000)

    Call SetOemDro (118,NewAngle) ' now you can rotate the block

'Call SetDro (2,Z + PlateThickness)

    Code "G4 P0.25"

    Code "F" &CurrentFeed 'restore starting feed rate
Call ReturnG90G91State()
Exit Sub
End If
Sub ProbeGrounded()
Code "(Probe plate is grounded, check connection and try again)"
Call ReturnG90G91State()
End Sub

Sub ReturnG90G91State()
If CurrentAbsInc = 0 Then 'if G91 was in effect before then return to it
Code "G91"
Code "G90"
End If
If CurrentGMode = 0 Then 'if G0 was in effect before then return to it
Code "G0"
Code "G1"
End If
End Sub                

Re: Registration mark detection (print cut) macro
« Reply #2 on: March 13, 2014, 09:59:57 AM »
That will definitely help.  Once I get the sensor setup dialed in, I'll post all the details.  It's about $40.00 of components.  Very simple.
Re: Registration mark detection (print cut) macro
« Reply #3 on: March 28, 2014, 08:07:52 PM »
Just a quick note to anyone who might be interested.  This sensor: http://www.amazon.com/gp/product/B00A6XKWR2/ref=oh_details_o01_s00_i01?ie=UTF8&psc=1 should do the trick for reg mark detection.  It will not require the use of an arduino or any other micro controller and if wired as a probe, should allow the use of a g31 command in a script to create the desired effect.

Offline jasko

  •  14 14
    • View Profile
Re: Registration mark detection (print cut) macro
« Reply #4 on: April 19, 2015, 02:08:28 PM »
what happens with this idea ?