// X+ Y+ Probing Macro (Plate) 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 = AS3.Getbuttonstate(20540); // Auto Zero double Frate1 = AS3.Getfielddouble(2709); // First Probe Feedrate double Frate2 = AS3.Getfielddouble(2710); // Slow Probe Feedrate // y Axis - Coordinates double Y1 = 0; // Y axis Probe Point double Y2 = 0; // Y axis Probe Point double X1b = 0; //Xb axis Probe Point double X2b = 0; //Xb axis Probe Point double Yhit; // Y axis Probe Point double YZero; // Y Zero Location double YStart; // Y axis Start Position // x Axis - Coordinates double X1 = 0; //X axis Probe Point double X2 = 0; //X axis Probe Point double Y1b = 0; // Yb axis Probe Point double Y2b = 0; // Yb axis Probe Point double Xhit; //X axis Probe Point double XZero; // X Zero Location double XStart; // X axis Start Position // probing settings double Dmax = AS3.Getfielddouble(20335); // Probing Distance double ProbeL; // Probe Distance double ZClear = AS3.Getfielddouble(2734); // Z Clearance double XYClear = AS3.Getfielddouble(2732); // XY Clearance double ProbeD = AS3.Getfielddouble(2705); // Probe Diameter bool EdgeYN = AS3.Getbuttonstate(20541); // Probe Edge Checkbox. bool Edge1 = AS3.Getbuttonstate(853); // One Time Edge bool Aglcorr = AS3.Getbuttonstate(20556); // Angle_Correction bool TPlate = AS3.Getbuttonstate(20560); // Touchplate double EdgeL = AS3.Getfielddouble(20339); // Edge Length double CornerD = AS3.Getfielddouble(20342); // Corner Distance double Retract = AS3.Getfielddouble(2706); // Pullback Distance double Platedx = AS3.Getfielddouble(20558); // Edge LengthX (X-Axis Probing) double Platedy = AS3.Getfielddouble(20559); // Edge LengthY (y-Axis Probing) double PlateOffx = AS3.Getfielddouble(20560); // Plate Offset X double PlateOffy = AS3.Getfielddouble(20561); // Plate Offset Y double PlateOffz = AS3.Getfielddouble(20562); // Plate Offset Z double GDbl; // G Code Value string Ypos; // Y Position String Value string Xpos; // X Position 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 double EdgeDelta; // Difference between points along edge string EdgeDeltaStr; // String version double angle_y = 0; // Part_coord angle y double angle_x = 0; // Part_coord angle x double angle_pcs = 0; // Part xy angle string anglestr; // String version string degree = ((char)0x00B0).ToString(); double Hyp; // Hypotenuse of triangle double m1; // line 1 m double m2; // line 2 m double t1; // line 1 t double t2; // line 2 t double sx; // intersection x double sy; // intersection y if (TPlate == false) // Check whether plate is attached, set plate thickness zero { exec.AddStatusmessage("No Touchplate used"); PlateOffx = 0; PlateOffy = 0; PlateOffz = 0; } 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("G69"); // Reset Coordinate Rotation AS3.SetLED(false, 260); // Reset G68 LED exec.AddStatusmessage("Coordinate System Rotation is Set to 0°"); AS3.Setfield(0,20556); // Reset Coord Angle // Probing y-Part // 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(" "); exec.AddStatusmessage("Probing for Y Position..."); exec.Wait(10); // Pause to allow user to position plate YStart = AS3.Getfielddouble(227); // Current Y axis Work Coordinate ProbeL = YStart + Dmax; // Probe Length exec.Code("G31 Y" + Dbl2Str(ProbeL) + " F" + Frate1); // Do First Probe move while (exec.IsMoving()) {} AS3jog.Setfieldtext(Dbl2Str(ProbeL), 20576); // Write sy Position to DRO Yhit = exec.Getvar(5062); // Read the touch point Y1 = Yhit + ProbeD / 2 + PlateOffy; // Tool Center Position at Y=0 X1b = AS3.Getfielddouble(226); // x1b coordinate for first y-touch point YZero = Y1; if (Frate2 == 0) { GDbl = Yhit - XYClear; // Retract Position exec.Code("G0 Y" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} } else // Slow Probe { GDbl = Yhit - Retract; // Retract Position exec.Code("G0 Y" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} exec.AddStatusmessage("Slow Probing for Y Position..."); exec.Code("G31 Y" + Dbl2Str(ProbeL) + " F" + Frate2); // Do Slow Probe move while (exec.IsMoving()) {} Yhit = exec.Getvar(5062); // Read the touch point Y1 = Yhit + ProbeD / 2 + PlateOffy; // Tool Center Position at Y=0 YZero = Y1; } if (!EdgeYN) { GDbl = Yhit - XYClear; // Retract Position exec.Code("G0 Y" + Dbl2Str(GDbl)); // Back away from edge if not Edge Probing while (exec.IsMoving()) {} } else { exec.Code("G0 Y" + YStart); // Back away to Start Position for Edge Probing while (exec.IsMoving()) {} } // Convert Y Position to String and reduce # of decimal places Ypos = Dbl2Str(Y1); // Convert to String StrLength = Ypos.Length; // Find String Length DotLoc = Ypos.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { Ypos = Ypos.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } // Edge Probing // modified with x-plate length (Platedx) if (EdgeYN) { exec.Code("G91"); // Change to Incremental Mode while (exec.IsMoving()) {} exec.Code("G0 X" + Platedx); // Move along edge while (exec.IsMoving()) {} exec.Code("G90"); // Change to Absolute Mode while (exec.IsMoving()) {} exec.AddStatusmessage("Probing for Edge Location..."); exec.Code("G31 Y" + Dbl2Str(ProbeL) + " F" + Frate1); // Do First Probe move while (exec.IsMoving()) {} Yhit = exec.Getvar(5062); // Read the touch point Y2 = Yhit + ProbeD / 2 + PlateOffy; // Tool Center Position at Y=0 X2b = AS3.Getfielddouble(226); // x2b coordinate for first y-touch point if (Frate2 == 0) { GDbl = Yhit - XYClear; // Retract Position exec.Code("G0 Y" + YStart); // Back away from edge while (exec.IsMoving()) {} } else // Slow Probe { GDbl = Yhit - Retract; // Retract Position exec.Code("G0 Y" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} exec.AddStatusmessage("Slow Probing for Edge Location..."); exec.Code("G31 Y" + Dbl2Str(ProbeL) + " F" + Frate2); // Do Slow Probe move while (exec.IsMoving()) {} Yhit = exec.Getvar(5062); // Read the touch point Y2 = Yhit + ProbeD / 2 + PlateOffy; // Tool Center Position at Y=0 GDbl = Yhit - XYClear; // Retract Position exec.Code("G0 Y" + YStart); // Back away from edge while (exec.IsMoving()) {} exec.AddStatusmessage("Edge Found..."); } // End Slow Probing // calculation of y-Edge EdgeDelta = (Y2 - Y1); // Get Difference EdgeDeltaStr = Dbl2Str(EdgeDelta); // Convert to string and change sign StrLength = EdgeDeltaStr.Length; // Find String Length DotLoc = EdgeDeltaStr.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { EdgeDeltaStr = EdgeDeltaStr.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } angle_y = Math.Atan(EdgeDelta / Platedx) * 180 / Math.PI; // Get angle in Degrees anglestr = Dbl2Str(angle_y); // Convert angle to string StrLength = anglestr.Length; // Find String Length DotLoc = anglestr.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { anglestr = anglestr.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } AS3jog.Setfieldtext(anglestr + degree, 20349); // Write angle to DRO AS3jog.Setfieldtext(EdgeDeltaStr, 20350); // Write delta Y to DRO // Write to Status Window //exec.AddStatusmessage(" "); exec.AddStatusmessage("dy = " + EdgeDeltaStr); exec.AddStatusmessage("Angle = " + anglestr); if (Edge1) // If One Time Edge { AS3jog.Switchbutton(false, 20541); // Uncheck Probe Edge Checkbox on Jog Screen AS3.Setcheckboxstate(false, 20310); // Uncheck Probe Edge Checkbox on Checkbox Screen AS3jog.Switchbutton(false, 20542); // Uncheck One Time Edge Checkbox on Jog Screen AS3.Setcheckboxstate(false, 20311); // Uncheck One Time Edge Checkbox on Checkbox Screen } } // End Edge Probing AS3jog.Setfieldtext(Ypos, 20344); // Write Y Position to DRO //exec.AddStatusmessage(" "); exec.AddStatusmessage("Y Probe Position = " + Ypos); if (ZeroYN && !EdgeYN) // If Zero DRO and Not Edge Probing - Then Zero DRO { AS3.Setfield(0 - XYClear - ProbeD / 2 - PlateOffy, 227); // Set Y axis DRO to new zeroed position AS3.Validatefield(227); //exec.AddStatusmessage(" "); exec.AddStatusmessage("Y axis is now Zeroed"); } // x edge Probing // retract to X1b- Corner distance GDbl = X1b - CornerD; // Retract Position exec.Code("G0 X" + GDbl); // Move to inital position for x-probing while (exec.IsMoving()) {} exec.Code("G91"); // Change to Incremental Mode while (exec.IsMoving()) {} exec.Code("G0 Y" + CornerD); // Move y to first x Probe position while (exec.IsMoving()) {} exec.Code("G90"); // Change to Absolute Mode while (exec.IsMoving()) {} if (AS3.GetLED(37)) // Check Probe Input { MessageBox.Show("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; } // Start with x Probe movement //exec.AddStatusmessage(" "); //exec.AddStatusmessage(" "); exec.AddStatusmessage("Probing for X Position..."); exec.Wait(10); // Pause to allow user to position plate XStart = AS3.Getfielddouble(226); // Current X axis Work Coordinate ProbeL = XStart + Dmax; // Probe Length exec.Code("G31 X" + Dbl2Str(ProbeL) + " F" + Frate1); // Do First Probe move while (exec.IsMoving()) {} Xhit = exec.Getvar(5061); // Read the touch point X1 = Xhit + ProbeD / 2 + PlateOffx; // Tool Center Position at X=0 Y1b = AS3.Getfielddouble(227); // x1b coordinate for first x-touch point XZero = X1; if (Frate2 == 0) { GDbl = Xhit - XYClear; // Retract Position exec.Code("G0 X" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} } else // Slow Probe { GDbl = Xhit - Retract; // Retract Position exec.Code("G0 X" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} exec.AddStatusmessage("Slow Probing for X Position..."); exec.Code("G31 X" + Dbl2Str(ProbeL) + " F" + Frate2); // Do Slow Probe move while (exec.IsMoving()) {} Xhit = exec.Getvar(5061); // Read the touch point X1 = Xhit + ProbeD / 2 + PlateOffx; // Tool Center Position at X=0 XZero = X1; } if (!EdgeYN) { GDbl = Xhit - XYClear; // Retract Position exec.Code("G0 X" + Dbl2Str(GDbl)); // Back away from edge if not Edge Probing while (exec.IsMoving()) {} } else { exec.Code("G0 X" + XStart); // Back away to Start Position for Edge Probing while (exec.IsMoving()) {} } // Convert X Position to String and reduce # of decimal places Xpos = Dbl2Str(X1); // Convert to String StrLength = Xpos.Length; // Find String Length DotLoc = Xpos.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { Xpos = Xpos.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } // Edge Probing if (EdgeYN) { exec.Code("G91"); // Change to Incremental Mode while (exec.IsMoving()) {} exec.Code("G0 Y" + Platedy); // Move along edge while (exec.IsMoving()) {} exec.Code("G90"); // Change to Absolute Mode while (exec.IsMoving()) {} exec.AddStatusmessage("Probing for Edge Location..."); exec.Code("G31 X" + Dbl2Str(ProbeL) + " F" + Frate1); // Do First Probe move while (exec.IsMoving()) {} Xhit = exec.Getvar(5061); // Read the touch point X2 = Xhit + ProbeD / 2 + PlateOffx; // Tool Center Position at X=0 Y2b = AS3.Getfielddouble(227); // y2b coordinate for second x-touch point if (Frate2 == 0) { GDbl = Xhit - XYClear; // Retract Position exec.Code("G0 X" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} } else // Slow Probe { GDbl = Xhit - Retract; // Retract Position exec.Code("G0 X" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} exec.AddStatusmessage("Slow Probing for Edge Location..."); exec.Code("G31 X" + Dbl2Str(ProbeL) + " F" + Frate2); // Do Slow Probe move while (exec.IsMoving()) {} Xhit = exec.Getvar(5061); // Read the touch point X2 = Xhit + ProbeD / 2 + PlateOffx; // Tool Center Position at X=0 GDbl = Xhit - XYClear; // Retract Position exec.Code("G0 X" + Dbl2Str(GDbl)); // Back away from edge while (exec.IsMoving()) {} exec.AddStatusmessage("Edge Found..."); } // End Slow Probing EdgeDelta = (X1 - X2); // Get Difference EdgeDeltaStr = Dbl2Str(0 - EdgeDelta); // Convert to string and change sign StrLength = EdgeDeltaStr.Length; // Find String Length DotLoc = EdgeDeltaStr.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { EdgeDeltaStr = EdgeDeltaStr.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } angle_x = Math.Atan(EdgeDelta / Platedy) * 180 / Math.PI; // Get angle in Degrees anglestr = Dbl2Str(angle_x); // Convert angle to string StrLength = anglestr.Length; // Find String Length DotLoc = anglestr.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { anglestr = anglestr.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } if (Platedy > Platedx) { AS3jog.Setfieldtext(anglestr + degree, 20349); // Write angle to DRO AS3jog.Setfieldtext(EdgeDeltaStr, 20350); // Write delta X to DRO } angle_pcs = angle_x - angle_y; anglestr = Dbl2Str(angle_pcs); // Convert angle to string StrLength = anglestr.Length; // Find String Length DotLoc = anglestr.IndexOf(Dotstr); // Find location of decimal place DecLength = StrLength - (DotLoc + 1); // # of decimal digits if (DecLength > (Precision - 1)) { anglestr = anglestr.Remove(DotLoc + Precision); // Trim extra digits from end, only if needed } AS3jog.Setfieldtext(anglestr + degree, 20557); // Write angle to DRO Wrks Angle // Write to Status Window //exec.AddStatusmessage(" "); exec.AddStatusmessage("dx = " + EdgeDeltaStr); exec.AddStatusmessage("Angle = " + anglestr); if (Edge1) // If One Time Edge { AS3jog.Switchbutton(false, 20541); // Uncheck Probe Edge Checkbox on Jog Screen AS3.Setcheckboxstate(false, 20310); // Uncheck Probe Edge Checkbox on Checkbox Screen AS3jog.Switchbutton(false, 20542); // Uncheck One Time Edge Checkbox on Jog Screen AS3.Setcheckboxstate(false, 20311); // Uncheck One Time Edge Checkbox on Checkbox Screen } } // End Edge Probing AS3jog.Setfieldtext(Xpos, 20343); // Write X Position to DRO //exec.AddStatusmessage(" "); exec.AddStatusmessage("X Probe Position = " + Xpos); if (ZeroYN && !EdgeYN) // If Zero DRO and Not Edge Probing - Then Zero DRO { AS3.Setfield(0 - XYClear - ProbeD / 2 - PlateOffx, 226); // Set x axis DRO to new zeroed position AS3.Validatefield(226); //exec.AddStatusmessage(" "); exec.AddStatusmessage("X axis is now Zeroed"); } if (ZeroYN && EdgeYN) // If Zero DRO and Edge Probing - Then Zero DRO using intersection of 2 lines { // calculation of intersection point if (X2==X1) // correction of infinity slope { X2=X1+0.000001; } m1 = (Y2 - Y1) / (X2b - X1b); m2 = (Y2b - Y1b) / (X2 - X1); t1 = Y2 - X2b * m1; t2 = Y2b - X2 * m2; sx = (t2 - t1) / (m1 - m2); sy = (m1*t2 - m2 * t1) / (m1 - m2); AS3jog.Setfieldtext(Dbl2Str(m1), 20570); // Write m1 Position to DRO AS3jog.Setfieldtext(Dbl2Str(m2), 20571); // Write m1 Position to DRO AS3jog.Setfieldtext(Dbl2Str(t1), 20572); // Write t1 Position to DRO AS3jog.Setfieldtext(Dbl2Str(t2), 20573); // Write t2 Position to DRO AS3jog.Setfieldtext(Dbl2Str(sx), 20574); // Write sx Position to DRO AS3jog.Setfieldtext(Dbl2Str(sy), 20575); // Write sy Position to DRO YStart = AS3.Getfielddouble(227); // Current Y axis Work Coordinate XStart = AS3.Getfielddouble(226); // Current X axis Work Coordinate AS3.Setfield(XStart - sx, 226); // Set x axis DRO to new zeroed position AS3.Validatefield(226); //exec.AddStatusmessage(" "); exec.AddStatusmessage("X axis is now Zeroed"); AS3.Setfield(YStart - sy, 227); // Set x axis DRO to new zeroed position AS3.Validatefield(227); //exec.AddStatusmessage(" "); exec.AddStatusmessage("Y axis is now Zeroed"); } if (Aglcorr && ZeroYN && EdgeYN) { anglestr = AS3jog.Getfield(20349); //anglestr = "45"; exec.Code("G68 A0.000 B0.000 R" + anglestr); // Rotation arround Zero X,Y AS3.SetLED(true, 260); AS3jog.Setfieldtext(anglestr, 20556); // Write coor angle into } // change settings to initial exec.Code("F" + CurrentFeed); // Set Feedrate back to previous exec.Wait(200); if (originaldistancemode == 91) { exec.Code("G91"); } if (originalmodalmode == 1) { exec.Code("G1"); } #Events string Dbl2Str(double val) { return String.Format("{0:F6}", val); }