by Battwell » Fri Nov 04, 2016 5:19 pm
pasted whole m6 code below- ive added this by ****probing section.
{ and } are indented so you can see where im trying to skip the code
// Battwells m6 and probing
//Tool positions definition
int headdownport = 3; //hsd
int headdownpin = 6; //hsd
int headnumber = 1; //hsd
int Newtool = exec.Getnewtool();
int Currenttool = exec.Getcurrenttool();
//iVars[1]=1;
double probeyes = exec.Getvar (1);
double[] ToolX = new double[11];
double[] ToolY = new double[11];
//ToolX[1] = -150; // Tool1 X position
//ToolY[1] = -1858; // Tool1 Y position
double ToolXchgpos = -200; // Toolchange X position
double ToolYchgpos = -1550; // Toolchange Y position // HSD
double probeheight = -208.7625;// hsd // use m312 to get exact position of probe with no tool
double probeX = 4; // HSD
double probeY = -1586;
// change settings for perske head ********(tool numbers above 80)
if (Newtool >79)
{
headnumber = 2; // perske
probeX = -1; //perske
probeY = -1872; //perske
ToolYchgpos = -1872; // Toolchange Y position // PERSKE
probeheight = -146.0625;// perske // use m312 to get exact position of probe with no tool
headdownport = 3;// perske
headdownpin = 7;// perske
}
// ***end of set head 2 perske ***
// Probing settings//
double Zmin = -200;
double Zmin2 = -3;
double Feedrate = 600;
double Feedrate2 = 50;
double SafeZ2 = -50;
double retractheight = 10;
double retractheight2 = 2;
double SafeZ = -10;
// ***set tool field number***
int Boxnumber = 195;// fieldnumber for tools 1-20 (field 196)
if (Newtool >20)
{
Boxnumber = 921-21;// fieldnumber for tools 21-96. minus 21 so tool increment is correct
}
// ***end of set tool field number***
if(Newtool == -1) // If new tool number is -1 means a missing T code, so we need to stop here...
{
MessageBox.Show("no tool number!");
exec.Stop();
return;
}
if(Newtool <1 || Newtool >96) // Tool number is out of range, so we need to stop here...
{
MessageBox.Show(" tool number out of range !");
exec.Stop();
return;
}
if(Newtool == Currenttool) // Same tool was selected, so do nothing, stop here...
{
// MessageBox.Show(" same tool !");
return;
}
//return;
if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is unsafe to move in machine coordinates, stop here...
{
MessageBox.Show("The machine was not yet homed, do homeing before executing a tool change!");
exec.Stop();
return;
}
while(exec.IsMoving()){}
// Stop spindle if running and Move Z up
exec.Stopspin();
exec.Code("G00 G53 Z"+ SafeZ); // Move Z up
while(exec.IsMoving()){}
// Move to old tool position on XY plane
exec.Code("G00 G53 X" + ToolXchgpos + " Y" + ToolYchgpos);
while(exec.IsMoving()){}
MessageBox.Show(" Insert tool " +Newtool + " then press ok ");
//********probing************
//M31 probing macro
if (probeyes >0)
{ // skip probe if #1=0 *********************
if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is unsafe to move in machine coordinates, stop here...
{
MessageBox.Show("MACHINE NOT HOMED, home the machine before tool change!");
exec.Stop();
return;
}
while(exec.IsMoving()){}
exec.Wait(200);
if(exec.GetLED(37)) // if probe signal is on - probe stuck! stop here...
{
MessageBox.Show("The probe signal isnt ready-check probe!");
exec.Stop();
return;
}
//HEAD DOWN
exec.Setoutpin(headdownport,headdownpin);
double Xoriginalpos = exec.GetXmachpos(); // Get the current X machine coordinates
double Yoriginalpos = exec.GetYmachpos(); // Get the current Y machine coordinates
double Zoriginalpos = exec.GetZmachpos(); // Get the current Z machine coordinates
exec.Code("G00 G53 X" + probeX +" Y" + probeY + "Z-5");// // Move to the probe sensor position in XY
while(exec.IsMoving()){}
//********switch to incremental *********
exec.Code("G91");
exec.Code("G31 Z" + Zmin + "F" + Feedrate); // Move to the probe sensor position in z
while(exec.IsMoving()){}
exec.Wait(400);
Console.Beep();
double Zoriginalposprobed = exec.GetZmachpos(); // Get the current Z machine coordinates
//MessageBox.Show ("position is now " + Zoriginalposprobed);
double probedpos= Zoriginalposprobed - Zoriginalpos;
//MessageBox.Show ("Length difference is" + probedpos);
double backoff = exec.GetZmachpos() + retractheight2;
exec.Code("G00 G53 Z" + backoff); // Move few mm?? above probe plate
while(exec.IsMoving()){}
exec.Wait(100);
if(exec.GetLED(37)) // if probe signal is on- probe stuck! stop here...
{
MessageBox.Show("The probe signal isnt ready-check probe!");
exec.Stop();
return;
}
exec.Code("G31 Z" + Zmin2 + "F" + Feedrate2); // slow probe
while(exec.IsMoving()){}
exec.Wait(100);
Console.Beep();
//********switch to absolute *********
exec.Code("G90");
if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate
{
Zoriginalposprobed = exec.GetZmachpos(); // Get the current Z machine coordinates
//MessageBox.Show ("position is now " + Zoriginalposprobed);
probedpos= Zoriginalposprobed - Zoriginalpos;
//MessageBox.Show ("Length difference is " + probedpos);
double tooloffset= Zoriginalposprobed - probeheight;
//MessageBox.Show ("tool length is " + tooloffset);
//exec.Code("G44 H1"); // Load tool offset one, note the tool length is defined in the tools menu
//while(exec.IsMoving()){}
//exec.Wait(500);
double Zup = exec.GetZmachpos() + retractheight;
if(Zup > SafeZ)
{
Zup = SafeZ;
}
//HEAD UP
//exec.Clroutpin(headdownport,headdownpin);
//exec.Wait(100);
// end of head up
exec.Code("G00 G53 Z-5");// // Move z to -5 from home switch
while(exec.IsMoving()){}
exec.Wait(100);
exec.Code("G00 G53 x-200");// // Move x to -5 from home switch
while(exec.IsMoving()){}
exec.Wait(100);
// **** Set tool table ****
int fieldtoset= (Boxnumber + Newtool);// different field numbers now with extra tools added in this version
AS3.Setfield(tooloffset, fieldtoset);
while(exec.IsMoving()){}
exec.Callbutton(167);// save all settings
exec.Wait(100);
//exec.Code("G43 H"+ Newtool); // Load new tool offset
AS3.Setfield(tooloffset, 169);//set tooloffset z
exec.Wait(200);
AS3.Validatefield(169); // this updates all settings with new z offset.
exec.Wait(100);
while(exec.IsMoving()){}
} //end of no probe loop *****************
if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
{
exec.Code("G43 H"+ Newtool); // Load new tool offset
exec.Wait(100);
exec.Setcurrenttool(Newtool); //Set the current tool -> the new tool
exec.Wait(100);
// MessageBox.Show("Tool change done.");
exec.AddStatusmessage("Tool change OK - Now Tool "+ Newtool);
}
else
{
exec.StopWithDeccel();
MessageBox.Show("Tool change was interrupted by user!");
}
}