Z probing problems

If you have a question about the software please ask it here.

Z probing problems

Postby 4.2A » Tue Sep 26, 2017 1:34 am

Hello,

I just build a z probing tool for my machine. It works with a PNP NC proximity sensor. Additionally, the LED on the proximity sensor also tells me when the milling tool has triggered the sensor. In general, this tool works fine. The tool heigth when triggered is 36.80, so I edited the tool z Offset #1 to 36.80. Correct?

Now, when I press the probe button, it does the probe job fine, but returns a z value of -48.77 or similar.
36.80 + 10 should be 46.80 displayed as z value, I think.

What did I wrong?

This is my M31 probing code, I am using UCCNC 1.2039:

Code: Select all
//M31 probing macro

double probeX = 200;
double probeY = 300;
double Zmin = -100;
double FeedrateFast = 300;
double FeedrateSlow = 100;
double SafeZ = 100;
double retractheight = 10;
double retractforsecondmeasurement = 1;

bool domoveXY = false; //Enable XY movement
bool dodualcycle = true; //Do probing from 2 cycles, first with Fast and second with Slow feedrates

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, home the machine before run to parking position!");
  exec.Stop();
  return;
}

while(exec.IsMoving()){}

double Xoriginalpos = exec.GetXmachpos(); // Get the current machine coordinates
double Yoriginalpos = exec.GetYmachpos(); // Get the current machine coordinates

if(domoveXY) // Make XY movement only if enabled
{
  exec.Code("G00 G53 Z" + SafeZ); // Move Z up first
  while(exec.IsMoving()){}

  exec.Code("G00 G53 X" + probeX +" Y" + probeY); // Move to the probe sensor position in XY
  while(exec.IsMoving()){}
}

if(dodualcycle)
{
  exec.Code("G31 Z" + Zmin + "F" + FeedrateFast); // Do the Z probing with Fast feedrate first
  while(exec.IsMoving()){}

  exec.Code("G91 G0 Z" + retractforsecondmeasurement);
  exec.Code("G90");
}

while(exec.IsMoving()){}
exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow); // Do the Z probing again with Slow Feedrate to get a more accurate reading
while(exec.IsMoving()){}

if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
{
 exec.Code("G44 H1"); // Load tool offset one, note the tool lenght is defined in the tools menu
 while(exec.IsMoving()){}
 exec.Wait(200);

 double Zup = exec.GetZmachpos() + retractheight;

 if(Zup > SafeZ)
 {
   Zup = SafeZ;
 }
 
 exec.Code("G00 G53 Z" + Zup); // Move 10mm above probe plate
 while(exec.IsMoving()){}

if(domoveXY) // Make XY movement back to start position only if XY movement is enabled
{
  exec.Code("G00 G53 X" + Xoriginalpos +" Y" + Yoriginalpos); // Move back to the original XY position
  while(exec.IsMoving()){}
}

}

With kind regards - and 4.2A
User avatar
4.2A
 
Posts: 21
Joined: Fri Mar 31, 2017 6:55 pm

Re: Z probing problems

Postby dezsoe » Tue Sep 26, 2017 10:30 am

After you run G31, you do nothing with the probe result. The easiest steps are (if you want to set the probe point to zero): run G31 to find probe point then set axis to zero. If you need other calculations, or you have a fixed probe then you need the coordinate for the probe to calculate for your needs. You can get it from the actual position, but it is better to read variables #5061 to #5066 (X to C, #5063 for Z) as they are the exact values written while probing. (The actual coords will a bit differ because the axis slow-down, but these variables are written on the probe trigger.)
dezsoe
 
Posts: 972
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Z probing problems

Postby 4.2A » Tue Sep 26, 2017 10:39 am

dezsoe wrote:You can get it from the actual position, but it is better to read variables #5061 to #5066 (X to C, #5063 for Z) as they are the exact values written while probing. (The actual coords will a bit differ because the axis slow-down, but these variables are written on the probe trigger.)

Sorry. I did not understand what you replied and I do not know how to program anything.

So I ask simple: is there a proper M31.txt or some code fragments which can do what I need?
With kind regards - and 4.2A
User avatar
4.2A
 
Posts: 21
Joined: Fri Mar 31, 2017 6:55 pm

Re: Z probing problems

Postby dezsoe » Tue Sep 26, 2017 10:50 am

OK, let's start it from the beginning. I have to know how you want to use it to be able to help you. :)

Is your probe fixed to somewhere on the machine or you put it on the top of the workpiece and measure there? This is the most important question as the two versions require whole different technique.

As you write you have a proximity sensor. Do you know the exact distance from the sensor where it turns on?

Maybe, better than lot of words, post a photo of your machine where the sensor is also visible.
dezsoe
 
Posts: 972
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Z probing problems

Postby 4.2A » Tue Sep 26, 2017 11:51 am

dezsoe wrote:Is your probe fixed to somewhere on the machine or you put it on the top of the workpiece and measure there? This is the most important question as the two versions require whole different technique.

My probe is to put on the top of the workpiece.


dezsoe wrote:As you write you have a proximity sensor. Do you know the exact distance from the sensor where it turns on?

36.80. That is the heigth of the sensor when it had been triggered.


dezsoe wrote:Maybe, better than lot of words, post a photo of your machine where the sensor is also visible.

It looks similar to this one.
With kind regards - and 4.2A
User avatar
4.2A
 
Posts: 21
Joined: Fri Mar 31, 2017 6:55 pm

Re: Z probing problems

Postby dezsoe » Tue Sep 26, 2017 1:26 pm

OK, give me some time, I'll be back later today with your macro. :)

(I have to modify mine which makes everything you want, but lot of other things that you don't need.)
dezsoe
 
Posts: 972
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Z probing problems

Postby 4.2A » Tue Sep 26, 2017 10:38 pm

dezsoe wrote:OK, give me some time, I'll be back later today with your macro.

Thank you in advance. :D
With kind regards - and 4.2A
User avatar
4.2A
 
Posts: 21
Joined: Fri Mar 31, 2017 6:55 pm

Re: Z probing problems

Postby dezsoe » Wed Sep 27, 2017 2:42 pm

Sorry, I had no time to finish until now. :)

Code: Select all
// ================================================================================================
// M31 probing macro
// ================================================================================================

// ------ Set globals -----------------------------------------------------------------------------

DepthCorrection = 0.0;                                                          // Set negative value to go deeper in workpiece

SafeZ = 10.0;

FastFeedrate = 50.0;                                                            // First probe
ZFastmin = exec.GetZpos() - SafeZ - 2.0;
RetractZ = 5.0;

FineFeedrate = 25.0;                                                            // Fine probe
FineZ = 0.5;

IsSafeProbeMode = exec.GetLED(_SafeProbeModeLED);                               // SafeProbeMode

Feed = exec.getcurrentfeedrate();

Zmachpos = exec.GetZmachpos();                                                  // Original Z pos to return to

// ------ Setup parameters ------------------------------------------------------------------------

MeasureWithGage = true;                                                         // Is there a gage?
GageHeight = 36.80;

// ------ Initialize ------------------------------------------------------------------------------

if(!exec.GetLED(_XHomedLED) || !exec.GetLED(_YHomedLED) || !exec.GetLED(_ZHomedLED)) // Machine was not homed
{
  MessageBox.Show("The machine was not yet homed, home the machine before measuring!");
  return;
}

if (AS3.Getbuttonstate(_G54Button))
  FixtureNo = 1;
else if (AS3.Getbuttonstate(_G55Button))
  FixtureNo = 2;
else if (AS3.Getbuttonstate(_G56Button))
  FixtureNo = 3;
else if (AS3.Getbuttonstate(_G57Button))
  FixtureNo = 4;
else if (AS3.Getbuttonstate(_G58Button))
  FixtureNo = 5;
else if (AS3.Getbuttonstate(_G59Button))
  FixtureNo = 6;

if (FixtureNo == 0)
{
  MessageBox.Show("Problems with fixture number.");
  return;
}

G92OffsetZ = AS3.Getfielddouble(_G92OffsetZField);
ToolOffsetZ = AS3.Getfielddouble(_ToolOffsetZField);

// ------ Run -------------------------------------------------------------------------------------

if (IsSafeProbeMode)
{
  exec.Callbutton(_SafeProbeModeOffButton);                                     // Turn off SafeProbeMode
}

while(exec.IsMoving()){}

if (!DoMeasurement())
  return;

return;

// ====== EVENTS ==================================================================================

#Events

// ====== GLOBALS =================================================================================

const int _SafeProbeModeLED = 243;                                              // SafeProbeMode LED
const int _XHomedLED = 56;                                                      // X..C Homed: LED 56..61
const int _YHomedLED = 57;
const int _ZHomedLED = 58;

const int _G92OffsetZField = 502;                                               // 500..505 XYZABC
const int _ToolOffsetZField = 169;                                              // Tool length offset

const int _G54Button = 118;                                                     // G54..G59: LED 118..123
const int _G55Button = 119;
const int _G56Button = 120;
const int _G57Button = 121;
const int _G58Button = 122;
const int _G59Button = 123;
const int _SafeProbeModeOnButton = 545;                                         // Turn on SafeProbeMode
const int _SafeProbeModeOffButton = 546;                                        // Turn off SafeProbeMode

double DepthCorrection = 0.0;
double ProbeX = 0.0;
double ProbeY = 0.0;
double SafeZ = 0.0;
double FastFeedrate = 0.0;
double ZFastmin = 0.0;
double RetractZ = 0.0;
double FineFeedrate = 0.0;
double FineZ = 0.0;
double G92OffsetZ = 0.0;
double ToolOffsetZ = 0.0;

bool MeasureWithGage = false;
double GageHeight = 0.0;
bool IsSafeProbeMode = false;

int FixtureNo = 0;

double Feed = 0.0;

double Zmachpos = 0.0;

// ------------------------------------------------------------------------------------------------

bool DoMeasurement()
{
  if (MeasureWithGage)
  {
    AS3.Additemtolistbeginning("Using gage: " + GageHeight, 2);
  }
  else
  {
    GageHeight = 0.0;
  }
  // Do first probe
  exec.Code("G31 Z" + ZFastmin + "F" + FastFeedrate);
  while(exec.IsMoving()){}
  AS3.Additemtolistbeginning("1st probe: " + exec.ivars[5063], 2);
  // Zero Z
  exec.Code("G10 L2 P" + FixtureNo + " Z" + (MachFromProbeZ() - G92OffsetZ - ToolOffsetZ));
  while(exec.IsMoving()){}
  if(!exec.Ismacrostopped())
  {
    // Pull up
    exec.Code("G00 Z" + RetractZ);
    while(exec.IsMoving()){}
    // Go back for fine probe
    exec.Code("G00 Z" + FineZ);
    while(exec.IsMoving()){}
    // Fine probe (-1 must be enough)
    exec.Code("G31 Z-1.0000 F" + FineFeedrate);
    while(exec.IsMoving()){}
    AS3.Additemtolistbeginning("2nd probe: " + exec.ivars[5063], 2);
    // Set work offset with GageHeight and DepthCorrection
    exec.Code("G10 L2 P" + FixtureNo + " Z" + (MachFromProbeZ() - G92OffsetZ - ToolOffsetZ - GageHeight + DepthCorrection));
    while(exec.IsMoving()){}
    // Send Z back to original position
    exec.Code("G00 G53 Z" + Zmachpos);
    while(exec.IsMoving()){}
    // Set original feed rate
    exec.Code("F" + Feed);
    while(exec.IsMoving()){}
  }

  if (IsSafeProbeMode)
  {
    exec.Callbutton(_SafeProbeModeOnButton); // SafeProbeMode bekapcs
  }

  return true;
}

// ------------------------------------------------------------------------------------------------

double MachFromProbeZ()
{
  double WorkOffsetZ = AS3.Getfielddouble(135 + 6 * (FixtureNo - 1));
  return (exec.ivars[5063] + WorkOffsetZ + G92OffsetZ + ToolOffsetZ);
}

// ------------------------------------------------------------------------------------------------

Set FastFeedRate and FineFeedRate as you need (and your machine needs), GageHeight is as you wrote. First it makes a fast probe, zeroes Z, then makes a fine probe with lower feed rate. Then it sets the current work offset for Z modified by the height of the probing gage.

If anyone wants to use it with a contact probe, where no gage height is, just set MeasureWithGage to false.
dezsoe
 
Posts: 972
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Z probing problems

Postby 4.2A » Wed Sep 27, 2017 3:32 pm

Thank you!

I noticed that it stops if the z axis has to travel down for a larger amount. Why does it stops then?
What is the purpose of ZFastmin?
With kind regards - and 4.2A
User avatar
4.2A
 
Posts: 21
Joined: Fri Mar 31, 2017 6:55 pm

Re: Z probing problems

Postby dezsoe » Wed Sep 27, 2017 4:06 pm

I use it because normally I jog near above the test point and start it. Fast probe is very slow to wait for it, so I jog as near as it is safe. Then it has to probe only 2-5mm, so ZFastMin is far enough.
dezsoe
 
Posts: 972
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 5 guests