int headnumber = 1; //hsd
int headdownport = 3;
int headdownpin = 6;
int head1downport = 3;
int head1downpin = 6;
int head2downport = 3;
int head2downpin = 7;// dont worry about above- not used in this machine.
// Probing settings//
double Zmin = -200;
double Zmin2 = -3;
double Feedrate = 500;
double Feedrate2 = 30;
double SafeZ2 = -50;
double retractheight = 10;
double retractheight2 = 2.5;
int Newtool = exec.Getnewtool();
int stoppedled=11;
// ***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***
double probeyes = exec.Getvar (1);
double ToolXchgpos = -200; // Toolchange X position
double ToolYchgpos = -36.5; // Toolchange Y position // HSD
double probeheight = -150.71;// hsd // use m312 to get exact position of probe with no tool
double probeX = 4; // these are machine co ordinates of probe position
double probeY = -36.5;
//M31 probing macro
if (AS3.GetLED(18) && !AS3.GetLED(stoppedled)); // check idle (18)-then check spindle stopped: relay on vfd
//if (probeyes <1)
{ // 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(exec.mainform,"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(exec.mainform,"The probe signal isnt ready-check probe!");
exec.Setvar(0, 100);//stops manual change macroloop blocking the output for eject
exec.Stop();
return;
}
//HEAD DOWN
//exec.Setoutpin(headdownport,headdownpin);
double Zoriginalpos = exec.GetZmachpos(); // Get the current Z machine coordinates
exec.Setvar(5063,0);
exec.Code("G00 G53 Z-0.5");// // Move above the probe sensor position in z
exec.Code("G00 G53 Y" + probeY + "Z-0.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(100);
Console.Beep();
if(!exec.GetLED(244)) // if didnt hit probe stop here...
{
MessageBox.Show(exec.mainform,"The probe didnt hit!");
exec.Stop();
return;
}
double probed1 = exec.Getvar(5063); // Get the current Z coordinates//*****using vars
//exec.AddStatusmessage("probe at "+ probed1);
exec.Code("G90");
exec.Code("G01 f200 Z" + probed1 );
while(exec.IsMoving()){}
exec.Wait(100);
Console.Beep();
double Zoriginalposprobed = exec.GetZmachpos(); // Get the current Z machine coordinates
double Zoriginalposprobed2 = exec.GetZmachpos(); // Get the current Z machine coordinates
double probedpos= Zoriginalposprobed - Zoriginalpos;
double probedpos2= Zoriginalposprobed2 - Zoriginalpos;// *****using vars
//exec.AddStatusmessage("Tool length old method1 "+ probedpos);
exec.Code("G91");
//double backoff = exec.GetZmachpos() + retractheight2;
//exec.Code("G00 G53 Z" + backoff); // Move few mm?? above probe plate
exec.Code("G00 Z"+ retractheight2 ); // Move 2 mm?? above probe plate
while(exec.IsMoving()){}
exec.Wait(100);
exec.Setvar(5063,0);
//Console.Beep();
if(exec.GetLED(37)) // if probe signal is on- probe stuck! stop here...
{
MessageBox.Show(exec.mainform,"The probe signal isnt ready-check probe!");
exec.Setvar(0, 100);//stops manual change macroloop blocking the output for eject
exec.Stop();
return;
}
exec.Code("G31 Z" + Zmin2 + "F" + Feedrate2); // slow probe
while(exec.IsMoving()){}
exec.Wait(100);
Console.Beep();
if(!exec.GetLED(244)) // if didnt hit probe stop here...
{
MessageBox.Show(exec.mainform,"The probe didnt hit!");
exec.Setvar(0, 100);//stops manual change macroloop blocking the output for eject
exec.Stop();
return;
}
double probed2 = exec.Getvar(5063); // Get the current Z coordinates//*****using vars
//exec.AddStatusmessage("probed position "+ probed2);
exec.Code("G90");
exec.Code("G01 f200 Z" + probed2 );
while(exec.IsMoving()){}
exec.Wait(100);
Console.Beep();
//Zoriginalposprobed2= exec.GetZmachpos(); // Get the current Z machine coordinates
//********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
double goodprobed = exec.Getvar(5060); // ****using vars
//exec.AddStatusmessage("probe good? "+ goodprobed);
probedpos= Zoriginalposprobed - Zoriginalpos;
exec.Wait(100);
//probedpos2= Zoriginalposprobed2 - Zoriginalpos;//*****using vars
double tooloffset= Zoriginalposprobed - probeheight;
exec.AddStatusmessage("Tool length now "+ tooloffset);
exec.Code("G00 G53 Z-0.5");// // Move z to -0.5 from home switch
while(exec.IsMoving()){}
exec.Wait(100);
exec.Code("G00 G53 y200");// // Move y to +200mm 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);
exec.Wait(100);
AS3.Validatefield(fieldtoset);
//exec.AddStatusmessage("field # "+ fieldtoset);
exec.Callbutton(168);// apply all settings
exec.Wait(100);
exec.Callbutton(167);// save all settings
exec.Wait(100);
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(Newtool <96)
{
if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
{
exec.Code("G0 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 PROBED OK Tool # "+ Newtool);
}
else
{
exec.StopWithDeccel();
exec.Setvar(0, 100);//stops manual change macroloop blocking the output for eject
MessageBox.Show("Tool change was interrupted by user!");
}
}
}
} //end of no probe loop *****************
Return to General discussion about the UCCNC software
Users browsing this forum: Bing [Bot] and 2 guests