Re: UCcnc / UC300 with ATCs
here is my macro- with test bits left in but remmed out by //
it shows how i set box numbers etc
hope it helps anybody venturing into c# editing
//Tool positions definition
int headdownport = 3;
int headdownpin = 6;
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 = -1872; // Toolchange Y position // PERSKE
double ToolYchgpos = -1550; // Toolchange Y position // HSD
double probeheight = -146.0625;//use m312 to get exact position of probe with no tool
//double probeX = -1; //perske
//double probeY = -1872;
double probeX = 4; // HSD
double probeY = -1586;
double Zmin = -100;
double Zmin2 = -3;
double Feedrate = 600;
double Feedrate2 = 50;
double SafeZ2 = -50;
double retractheight = 10;
double retractheight2 = 2;
double SafeZ = -10;
int Newtool = exec.Getnewtool();
int Currenttool = exec.Getcurrenttool();
// ***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 numberout 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.GetLE D(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(" Change tool then press ok ");
//********probing************
//M31 probing macro
if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLE D(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 Z-5");// + SafeZ2); // Move Z up first
//while(exec.IsMoving()){}
exec.Code("G00 G53 X" + probeX +" Y" + probeY + "Z-5");// // Move to the probe sensor position in XY
while(exec.IsMoving()){}
exec.Code("G31 Z" + Zmin + "F" + Feedrate); // Move to the probe sensor position in z
while(exec.IsMoving()){}
exec.Wait(200);
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(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;
}
exec.Code("G31 Z" + Zmin2 + "F" + Feedrate2); // slow probe
while(exec.IsMoving()){}
exec.Wait(300);
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 z 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);
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()){}
if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
{
exec.Setcurrenttool(Newtool); //Set the current tool -> the new tool
exec.Wait(100);
//MessageBox.Show("Tool change done.");
}
else
{
exec.StopWithDeccel();
MessageBox.Show("Tool change was interrupted by user!");
}
}
so much to learn, so much to pass on.