// XY Center Pocket Probing Macro int originalmodalmode = exec.actualmodal; // Modal mode (G0, G1, ...) int originaldistancemode = exec.actualdistmode; // Distance mode (G90, G91) double CurrentFeed = AS3.Getfielddouble(867); // Current Feedrate string FeedOR = AS3.Getfield(232); // Current Feedrate Override double CurrentFeedOR = Convert.ToDouble(FeedOR.Replace("%", String.Empty)); double FeedFactor = 100/CurrentFeedOR; // Feedrate scale factor is Feedrate Overide is not 100% bool ZeroYN = AS3jog.Getbuttonstate(20540); // Auto Zero double Frate1 = AS3jog.Getfielddouble(20333); // First Probe Feedrate double Frate2 = AS3jog.Getfielddouble(20334); // Slow Probe Feedrate double X1; //X axis Probe Point double X2; //X axis Probe Point double Xhit; //X axis Probe Point double XCenter; // X Center Location double XLength; // X axis Pocket Length double XStart; // X axis Start Position double Y1; //Y axis Probe Point double Y2; //Y axis Probe Point double Yhit; //Y axis Probe Point double YCenter; // Y Center Location double YLength; // Y axis Pocket Length double YStart; // Y axis Start Position double Dmax = AS3jog.Getfielddouble(20335); // Probing Distance double ProbeL ; // Probe Distance double ZStart = AS3.Getfielddouble(228); // Current Z axis Work Coordinate double XYClear = AS3jog.Getfielddouble(20337); // XY Clearance double ProbeD = AS3jog.Getfielddouble(20338); // Probe Diameter double Retract = AS3jog.Getfielddouble(20340); // Pullback Distance double PlateOff = AS3jog.Getfielddouble(20341); // Plate Offset string XC; // X Center String Value string XL; // X Length String Value string YC; // Y Center String Value string YL; // Y Length String Value int StrLength; // String Length int Precision = AS3.Getfieldint(195) + 1;// Number of decimal places string Dotstr = "."; // Decimal Separator int DotLoc; // Location of decimal place int DecLength; // # of decimals if (Frate1 == 0) // Check Initial Feedrate { MessageBox.Show (exec.mainform, "Initial Feedrate is currently set to 0." + "\n" + "Set Initial Feedrate value and try again.", "Invalid Feedrate!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); exec.AddStatusmessage("Macro aborted - Initial Feedrate = 0"); exec.Stop(); return; } if (Dmax == 0) // Check Probing Distance { MessageBox.Show (exec.mainform, "Probe Distance is currently set to 0." + "\n" + "Set Probe Distance value and try again.", "Invalid Probing Distance!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); exec.AddStatusmessage("Macro aborted - Probe Distance = 0"); exec.Stop(); return; } if (XYClear == 0) // Check Probing Distance { MessageBox.Show (exec.mainform, "X-Y Clearance is currently set to 0." + "\n" + "Set X-Y Clearance value and try again.", "Invalid X-Y Clearance!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); exec.AddStatusmessage("Macro aborted - X-Y Clearance = 0"); exec.Stop(); return; } if (ProbeD == 0) // Check Probing Diameter { MessageBox.Show (exec.mainform, "Probe Diameter is currently set to 0." + "\n" + "Set Probe Diameter value and try again.", "Invalid Probe Diameter!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); exec.AddStatusmessage("Macro aborted - Probe Diameter = 0"); exec.Stop(); return; } if (Retract == 0) // Check Retract Distance { MessageBox.Show (exec.mainform, "Pullback Distance is currently set to 0." + "\n" + "Set Pullback Distance value and try again.", "Invalid Pullback Distance!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); exec.AddStatusmessage("Macro aborted - Pullback Distance = 0"); exec.Stop(); return; } Frate1 = Frate1 * FeedFactor; // Scale Feedrate if FRO is not 100% Frate2 = Frate2 * FeedFactor; // Scale Feedrate if FRO is not 100% exec.Code("G90"); while(exec.IsMoving()){} if (AS3.GetLED(37)) // Check Probe Input { MessageBox.Show (exec.mainform, "Probe Input is currently active." + "\n" + "Check connections and try again.", "Probe Active!!!", MessageBoxButtons.OK, MessageBoxIcon.Error); exec.AddStatusmessage("Macro aborted - Probe Active"); exec.Stop(); return; } exec.AddStatusmessage(" "); exec.AddStatusmessage(" "); // Probe X+ axis XStart = AS3.Getfielddouble(226); // Current X axis Work Coordinate ProbeL = XStart + Dmax; // Probe Length //exec.Code("F" + Frate1); // Set First Probe Feedrate exec.AddStatusmessage(" "); exec.AddStatusmessage("Probing for X+ Position..."); exec.Code("G31 X" + ProbeL + " F" + Frate1); // Do First Probe move while(exec.IsMoving()){} Xhit = exec.Getvar(5061); // Read the touch point X1 = Xhit + ProbeD/2 + PlateOff; // Tool Center Position at X=0 if (Frate2 != 0) { exec.Code("G0 X" + (Xhit - Retract)); // Back away from edge while(exec.IsMoving()){} exec.AddStatusmessage("Slow Probing for X+ Position..."); //exec.Code("F" + Frate2); // Set Slow Probe Feedrate exec.Code("G31 X" + ProbeL + " F" + Frate2); // Do Slow Probe move while(exec.IsMoving()){} Xhit = exec.Getvar(5061); // Read the touch point X1 = Xhit + ProbeD/2 + PlateOff; // Tool Center Position at X=0 } // End Slow Probing exec.Code("G0 X" + (Xhit - Retract)); // Back away from edge while(exec.IsMoving()){} exec.Code("G0 X" + XStart); // Rapid back to Start Position while(exec.IsMoving()){} // Probe X- axis XStart = AS3.Getfielddouble(226); // Current X axis Work Coordinate ProbeL = XStart - Dmax; // Probe Length //exec.Code("F" + Frate1); // Set First Probe Feedrate exec.AddStatusmessage(" "); exec.AddStatusmessage("Probing for X- Position..."); exec.Code("G31 X" + ProbeL + " F" + Frate1); // Do First Probe move while(exec.IsMoving()){} Xhit = exec.Getvar(5061); // Read the touch point X2 = Xhit - ProbeD/2 - PlateOff; // Tool Center Position at X=0 if (Frate2 != 0) { exec.Code("G0 X" + (Xhit + Retract)); // Back away from edge while(exec.IsMoving()){} exec.AddStatusmessage("Slow Probing for X- Position..."); //exec.Code("F" + Frate2); // Set Slow Probe Feedrate exec.Code("G31 X" + ProbeL + " F" + Frate2); // Do Slow Probe move while(exec.IsMoving()){} Xhit = exec.Getvar(5061); // Read the touch point X2 = Xhit - ProbeD/2 - PlateOff; // Tool Center Position at X=0 } // End Slow Probing exec.Code("G0 X" + (Xhit + Retract)); // Back away from edge while(exec.IsMoving()){} // Calculate X Center and Pocket Length XCenter = (X1 + X2) / 2; XLength = X1 - X2; // Convert X Center Position to String and reduce # of decimal places XC = XCenter.ToString(); // Convert to String StrLength = XC.Length; // Find String Length DotLoc = XC.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { XC = XC.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } // Convert X Length Position to String and reduce # of decimal places XL = XLength.ToString(); // Convert to String StrLength = XL.Length; // Find String Length DotLoc = XL.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { XL = XL.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } if (ZeroYN) // Zero X axis if enabled { exec.Code("G0 X" + XCenter); // Move to X Center while(exec.IsMoving()){} AS3.Setfield(0, 226); // Set X axis DRO to new zeroed position AS3.Validatefield(226); exec.AddStatusmessage(" "); exec.AddStatusmessage("X axis is now Zeroed at Pocket Center"); } else { exec.Code("G0 X" + XStart); // Rapid back to Start Position while(exec.IsMoving()){} } // Probe Y+ axis YStart = AS3.Getfielddouble(227); // Current Y axis Work Coordinate ProbeL = YStart + Dmax; // Probe Length //exec.Code("F" + Frate1); // Set First Probe Feedrate exec.AddStatusmessage(" "); exec.AddStatusmessage("Probing for Y+ Position..."); exec.Code("G31 Y" + ProbeL + " F" + Frate1); // Do First Probe move while(exec.IsMoving()){} Yhit = exec.Getvar(5062); // Read the touch point Y1 = Yhit + ProbeD/2 + PlateOff; // Tool Center Position at Y=0 if (Frate2 != 0) { exec.Code("G0 Y" + (Yhit - Retract)); // Back away from edge while(exec.IsMoving()){} exec.AddStatusmessage("Slow Probing for Y+ Position..."); //exec.Code("F" + Frate2); // Set Slow Probe Feedrate exec.Code("G31 Y" + ProbeL + " F" + Frate2); // Do Slow Probe move while(exec.IsMoving()){} Yhit = exec.Getvar(5062); // Read the touch point Y1 = Yhit + ProbeD/2 + PlateOff; // Tool Center Position at Y=0 } // End Slow Probing exec.Code("G0 Y" + (Yhit - Retract)); // Back away from edge while(exec.IsMoving()){} exec.Code("G0 Y" + YStart); // Rapid back to Start Position while(exec.IsMoving()){} // Probe Y- axis ProbeL = YStart - Dmax; // Probe Length //exec.Code("F" + Frate1); // Set First Probe Feedrate exec.AddStatusmessage(" "); exec.AddStatusmessage("Probing for Y- Position..."); exec.Code("G31 Y" + ProbeL + " F" + Frate1); // Do First Probe move while(exec.IsMoving()){} Yhit = exec.Getvar(5062); // Read the touch point Y2 = Yhit - ProbeD/2 - PlateOff; // Tool Center Position at Y=0 if (Frate2 != 0) { exec.Code("G0 Y" + (Yhit + Retract)); // Back away from edge while(exec.IsMoving()){} exec.AddStatusmessage("Slow Probing for Y- Position..."); //exec.Code("F" + Frate2); // Set Slow Probe Feedrate exec.Code("G31 Y" + ProbeL + " F" + Frate2); // Do Slow Probe move while(exec.IsMoving()){} Yhit = exec.Getvar(5062); // Read the touch point Y2 = Yhit - ProbeD/2 - PlateOff; // Tool Center Position at Y=0 } // End Slow Probing exec.Code("G0 Y" + (Yhit + Retract)); // Back away from edge while(exec.IsMoving()){} // Calculate Y Center and Pocket Length YCenter = (Y1 + Y2) / 2; YLength = Y1 - Y2; // Convert Y Center Position to String and reduce # of decimal places YC = YCenter.ToString(); // Convert to String StrLength = YC.Length; // Find String Length DotLoc = YC.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { YC = YC.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } // Convert Y Length Position to String and reduce # of decimal places YL = YLength.ToString(); // Convert to String StrLength = YL.Length; // Find String Length DotLoc = YL.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { YL = YL.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } if (ZeroYN) // Zero Y axis if enabled { exec.Code("G0 Y" + YCenter); // Move to Y Center while(exec.IsMoving()){} AS3.Setfield(0, 227); // Set Y axis DRO to new zeroed position AS3.Validatefield(227); exec.AddStatusmessage(" "); exec.AddStatusmessage("Y axis is now Zeroed at Pocket Center"); } else { exec.Code("G0 Y" + YStart); // Rapid back to Start Position while(exec.IsMoving()){} } AS3jog.Setfieldtext(XC, 20347); // Write X Center Position to DRO AS3jog.Setfieldtext(XL, 20345); // Write X Length Position to DRO AS3jog.Setfieldtext(YC, 20348); // Write Y Center Position to DRO AS3jog.Setfieldtext(YL, 20346); // Write Y Length Position to DRO exec.AddStatusmessage(" "); exec.AddStatusmessage("Pocket Y Length = " + YL); exec.AddStatusmessage("Pocket X Length = " + XL); exec.AddStatusmessage("Pocket Center located at " + XC + ", " + YC); exec.Code("F" + CurrentFeed); // Set Feedrate back to previous exec.Wait(200); if (originaldistancemode == 91) { exec.Code("G91"); } if (originalmodalmode == 1) { exec.Code("G1"); }