I recently added a camera to set X and Y on my CNC router. Helps index the rotary as well.
I wrote this simple macro to move the spindle to the camera position and then set the X and Y to zero. My plan is to create a button on the Camera page to call the macro. If I understand correctly all I need to do is to name the button the same as the macro number for the two to be associated, if this is not correct please let me know.
My intentions.... move to Z-.100 in machine coordinates to insure clearance no matter what tool I have in the spindle. Then move X and Y relatively to the camera position, then set x and y to zero in the current work coordinates. To finish up I set the modals to my most common usage.
I know it's simple but my first one and just wanted to get another set of eyes in case I missed something. Thanks in advance for any input!
- Code: Select all
//Just in case......
exec.Stopspin(); // Stop Spindle
exec.Code("G53 G0 Z-0.100"); // Move Z to .100 under machine home
while(exec.IsMoving()){}
exec.Code("G91 G0 X-2.677 Y2.106"); // Move spindle to camera position
while(exec.IsMoving()){}
// Get Current Offset and set X and Y to zero in that offset
bool G54YN = AS3.Getbuttonstate(118); //G54
bool G55YN = AS3.Getbuttonstate(119); //G55
bool G56YN = AS3.Getbuttonstate(120); //G56
bool G57YN = AS3.Getbuttonstate(121); //G57
bool G58YN = AS3.Getbuttonstate(122); //G58
bool G59YN = AS3.Getbuttonstate(123); //G59
if (G54YN)
{
AS3.Setfield(0, 133); // Set G54 X axis new zeroed position
AS3.Validatefield(133);
AS3.Setfield(0, 134); // Set G54 Y axis new zeroed position
AS3.Validatefield(134);
}
if (G55YN)
{
AS3.Setfield(0, 139); // Set G55 X axis new zeroed position
AS3.Validatefield(139);
AS3.Setfield(0, 140); // Set G55 Y axis new zeroed position
AS3.Validatefield(140);
}
if (G56YN)
{
AS3.Setfield(0, 145); // Set G56 X axis new zeroed position
AS3.Validatefield(145);
AS3.Setfield(0, 146); // Set G56 Y axis new zeroed position
AS3.Validatefield(146);
}
if (G57YN)
{
AS3.Setfield(0, 151); // Set G57 X axis new zeroed position
AS3.Validatefield(151);
AS3.Setfield(0, 152); // Set G57 Y axis new zeroed position
AS3.Validatefield(152);
}
if (G58YN)
{
AS3.Setfield(0, 157); // Set G58 X axis new zeroed position
AS3.Validatefield(157);
AS3.Setfield(0, 158); // Set G58 Y axis new zeroed position
AS3.Validatefield(158);
}
if (G59YN)
{
AS3.Setfield(0, 163); // Set G59 X axis new zeroed position
AS3.Validatefield(163);
AS3.Setfield(0, 164); // Set G59 Y axis new zeroed position
AS3.Validatefield(164);
}
//Leave modals in safe settings
exec.Code("G90");
exec.Code("G1");