Did a little research on this and some experimenting. Haven't cut anything on rotated material yet, but according to the display window in Mach3, it appears to work. Add a button to your screen and insert the vb code in the button. I also inserted an LED "OEMLED(108)" to show when rotation was in effect, but the X,Y DRO's also change red to note rotated coordinates.Les Newell wrote: ↑Thu Apr 08, 2021 2:39 pm I have attached the files. A lot of it is LinuxCNC specific, reading probe parameters and doing the probing etc. The subroutines of most interest would be find_xedge.ngc and find_yedge.ngc
Basically here is how it works:
First zero X and Y on the corner. Now find the X,Y coordinates of a point along the edge. This wants to be a decent distance from the corner. Find the arc tangent of those coordinates (the atan function) to get the rotation angle. Now use coordinate rotation with that angle (I think it's G68 in Mach3)
To use, zero X & Y on the corner, then jog down the edge to another point. Click the button. The rotation angle is displayed in a message box. Click yes to rotate. To cancel rotation, click the button again. One note, jogging doesn't follow the rotated coordinate system.
Code: Select all
If GetOEMLED(108) Then 'coordinates rotated
If MsgBox ("Cancel rotation?", 4 + 32, "Rotation") = 6 Then
Code("G69")
DoOEMButton(160) 'regen toolpath
Message "Rotation cancelled. (G69)"
End If
Else
If Format(GetDRO(0),"0.0000") <> 0 And Format(GetDRO(1),"0.0000") <> 0 Then 'can't calculate angle if one axis is zero
dx = GetDRO(0)
dy = GetDRO(1)
Pi = Atn( 1 ) * 4
If Abs( dx ) > Abs( dy ) Then ' horizontal, near X axis
angle = Atn( dy / dx ) / Pi * 180
Else ' vertical, near Y axis
angle = Atn( - dx / dy ) / Pi * 180
End If
If MsgBox ("Rotate coordinates " & Format(angle, "0.0000") & "° ?", 4 + 32, "Rotation") = 6 Then
SetOEMDRO(118, angle)
Code("G68X0Y0R" & angle)
DoOEMButton(160) 'regen toolpath
Message "Coordinates rotated. (G68)"
End If
End If
End If