by spumco » Sun Jan 07, 2018 5:42 am
Thanks Gerry. I really don't know if the macro is at fault or something else.
Here's the inside pocket X-only macro. The X/Y pocket is basically the same, only longer, so I added it as an attachment.
// X Axis 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 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
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()){}
}
AS3jog.Setfieldtext(XC, 20347); // Write X Center Position to DRO
AS3jog.Setfieldtext(XL, 20345); // Write X Length Position to DRO
exec.AddStatusmessage(" ");
exec.AddStatusmessage("Pocket Length = " + XL);
exec.AddStatusmessage("Pocket Center located at X = " + XC);
exec.Code("F" + CurrentFeed); // Set Feedrate back to previous
exec.Wait(200);
if (originaldistancemode == 91)
{
exec.Code("G91");
}
if (originalmodalmode == 1)
{
exec.Code("G1");
}
- Attachments
-
- M20537.txt
- (11.73 KiB) Downloaded 845 times