After some experimentation, this is what I have finally ended up with…
The camera can be used for X - Y tool positioning as follows;
By adding two new VB buttons to the Mach3 screen labeled Camera and Home;
Clicking the Camera button opens the video window, sets a slow jog rate and prompts for the Datum to be located.
Clicking the Home button closes the video window, resets the slow jog rate and moves both the X and Y axis (applying the offset) so that the spindle / tool is centered at the datum point.
The VB (Cypress Enable) scripts I have used to achieve this are as follows;
Camera button script;
Call SetUserLed(1102,1) 'open Klaus's video window
Call SetOemDRO(3,1) 'set slow jog rate to 1%
Code "(Locate Datum then click HOME)" 'message for status bar
Home button script;
SetUserLED(1103,1) 'close Klause’s video window
Call SetOemDRO(3,80) 'reset jog rate to 80%
Xs=GetOemDRO(59) 'read Xscale DRO
Ys=GetOemDRO(60) 'read Yscale DRO
Xmove = 70.850 * 1/Xs 'enter your camera offset here
Ymove = 1.070 * 1/Ys 'enter your camera offset here
Code "G91 G0 X" &Xmove & "Y" &Ymove 'make incremental move
While IsMoving () 'wait while that happens
Wend
Code "G90" 'go back to absolute moves
DoOEMButton (1008) 'zero X axis DRO
DoOEMButton (1009) 'zero Y axis DRO
Code "(Homing to Datum Complete)" 'message for status bar
To take advantage of the Local System Rotate function I have added 3 new VB buttons labeled A, B & C.
Button A opens the video window, sets a slow jog rate and prompts for the Datum to be located.
Button B resets the X an Y axis DRO’s to zero and prompts for the reference to be located.
Button C closes the video window, resets the slow jog rate, performs the calculations and moves the X an Y axis so the spindle / tool position is centered on the Datum location then sets the Local System Rotated DRO to the calculated value. The scripts I have used are as follows;
Button A script;
Call SetUserLed(1102,1) 'open Klaus's video window
Call SetOemDRO(118,0) 'reset system rotate DRO
Code "(Locate Datum then click Button B)" 'message for status bar
Call SetOemDRO(3,1) 'set slow jog rate to 1%
Button B script;
DoOEMButton (1008) 'zero X axis DRO
DoOEMButton (1009) 'zero Y axis DRO
Code "(Locate Reference then click Button C)" 'message for status bar
Button C script;
Sub Main()
Call SetUserLed(1103,1) 'close Klaus's video window
X1pos = GetOemDRO(800) 'read x axis DRO
Y1pos = GetOemDRO(801) 'read y axis DRO
If (Y1pos=0) Then GoTo Label1 'avoid divide by zero error
b = Atn(X1pos/Y1pos)*(180/(4*Atn(1))) 'calculate angle
b = b - (b*2) 'change sign (+/-)
Code "G0 X0 Y0" 'move to datum
While IsMoving () ‘wait for task to be completed
Wend
Xmove = 70.850 'enter your camera offset here
Ymove = 1.070 'enter your camera offset here
Code "G91 G0 X" &Xmove & "Y" &Ymove 'make incremental move
While IsMoving () ‘wait while that happens
Wend
Code "G90" 'go back to absolute moves
Call SetOemDRO(118,b) 'set system rotate DRO
Label1:
DoOEMButton (1008) 'zero X axis DRO
DoOEMButton (1009) 'zero Y axis DRO
Call SetOemDRO(3,80) 'reset jog rate to 80%
Code "(Process complete)" 'message for status bar
End Sub
(With both the Home button and the C button scripts my camera offset should be changed to suit your particular machine).
Obviously, everything is ‘work in progress’ and there will always be room for improvement so please feel free to change these scripts, as necessary, to suit your own particular application. My solution is presented here just as a guide for future development.
One further thought…
If, for example, a round circuit board was made and a datum and a reference had been established and the angle calculated (as mentioned above). This angle (angle1) could be stored as a VAR. If the round circuit board was removed from the work table then replaced (at a different angle) then by locating the same datum and reference and again calculating the angle (angle2) by subtracting one from the other the resultant angle when entered into the Local System Rotated DRO would be correct for work to be re-commenced on the circuit board as if it had never been removed and replaced.
It would perhaps be quite complicated to perform all the necessary math’s using a calculator but by using a VB script it could not be made more easy.
Tweakie.