Z-offset after tool change wrong

Post anything you want to discuss with others about the software.

Re: Z-offset after tool change wrong

Postby dezsoe » Mon Jan 30, 2023 12:59 pm

No, Frank, it should not be. In the line before the G31 the finishing Z coordinate is calculated. You can use relative coords, but then you first need to apply G91. (And don't forget to switch back to absolute.)

However, the calculation is bad, because it uses machine coords and probes in work coords.
dezsoe
 
Posts: 2049
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Z-offset after tool change wrong

Postby Parkgrr » Mon Jan 30, 2023 9:01 pm

Thanks for the help guys

I think I'm going to stick with something closer to the default M31 and implement the coarse and fine probing.

I saw in the default M31 that the probe lines are:
exec.Code("G31 Z" + Zmin + "F" + FeedrateFast);
exec.Code("G91 G0 Z" + retractforsecondmeasurement);
exec.Code("G90");
exec.Code("G31 Z" + Zmin + "F" + FeedrateSlow);

Am I having issues because I'm not calling G91, retracting, then switching back to G90?

Or must these moves include G53 like
exec.Code("G31 G53 Z" + Zmin + "F" + FeedrateSlow);
Parkgrr
 
Posts: 98
Joined: Mon Dec 07, 2020 9:12 am

Re: Z-offset after tool change wrong

Postby fsli » Tue Jan 31, 2023 12:43 am

dezsoe wrote:No, Frank, it should not be. In the line before the G31 the finishing Z coordinate is calculated. You can use relative coords, but then you first need to apply G91. (And don't forget to switch back to absolute.) However, the calculation is bad, because it uses machine coords and probes in work coords.

Had he used the relative distance instead of an absolute position, the mixture of machine .vs. work coordinates wouldn't even arise as an issue. So, in the context of the macro he's posted, "The axis value should be a relative distance to travel, not an absolute end point".
Frank
fsli
 
Posts: 93
Joined: Mon Jul 11, 2022 12:36 am

Re: Z-offset after tool change wrong

Postby Parkgrr » Tue Jan 31, 2023 3:46 am

In that case would adding G53 to the G31 command solve the issue?

exec.Code("G31 G53 Z" + Zmin + "F" + FeedrateSlow);
Parkgrr
 
Posts: 98
Joined: Mon Dec 07, 2020 9:12 am

Re: Z-offset after tool change wrong

Postby fsli » Tue Jan 31, 2023 12:01 pm

Parkgrr wrote:In that case would adding G53 to the G31 command solve the issue?
exec.Code("G31 G53 Z" + Zmin + "F" + FeedrateSlow);

Two choices:

Code: Select all
// Probe in absolute machine coordinates
ZPos = exec.GetZmachpos();
ZPos = ZPos - ZMove; //Set Zpos to Zpos minus distance to probe
exec.Code("G53 G31 Z" + ZPos + " F5.0" ); // Probes the tool length

Code: Select all
// Probe using relative distance (not dependent on coordinate system)
exec.Code("G91");
exec.Code("G31 Z-" + ZMove + " F5.0" ); // Probes the tool length

It's not clear from the snippet you posted whether the distance mode is G90 or G91 when reaching the G31. So, if it's G90 entering the macro and you choose the relative probe method, then you'll need to switch it back before the next movement command.

The other thing you should do is pick up the probe contact position using variable 5603 instead of GetZmachpos(). That is, instead of:

Code: Select all
while(exec.IsMoving()){}
ZPos = exec.GetZmachpos();

... use something like:

Code: Select all
while(exec.IsMoving()){}

if (!AS3.GetLED(244) || exec.Ismacrostopped())
{
   MessageBox.Show(exec.mainform, "Probe failed!");
   return;
}

ZPos = exec.Getvar(5063);

Where the IF is checking that the probe actually completed before retrieving the final machine position. When (if) the machine sees the probe trigger, it slows down using deceleration. Theoretically, the final machine position can be different than where the probe actually made contact.
Frank
fsli
 
Posts: 93
Joined: Mon Jul 11, 2022 12:36 am

Re: Z-offset after tool change wrong

Postby Parkgrr » Wed Feb 01, 2023 12:43 am

I really appreciate the help Frank. The entire macro is in G90, I'm never calling G91.

Sounds like going incremental is the way to go. Would it be ok to look something like this? Including the latter half of the macro to make sure I'm writing these values into fields correctly

Code: Select all
double OldZpos = ZPos;                             // Set Old z position to current z position
ZPos = ZPos - ZMove;                                //Set Zpos to Zpos minus distance to probe

exec.Code("G91");
exec.Code("G31 Z" + ZPos + " F5.0" );       // Probes the tool length.
exec.Code("G90");
while(exec.IsMoving()){}
if (!AS3.GetLED(244) || exec.Ismacrostopped())
{
   MessageBox.Show(exec.mainform, "Probe failed!");
   return;
}
ZPos = exec.Getvar(5063);

if(ZPos == OldZpos)                                       // Check if the the tool positon was found.
{
  MessageBox.Show("ERROR! The tool did not hit the probe and DRO was not set");
  exec.Stop();
  return;
}

 double Zoffset = AS3.Getfielddouble(873);  //Set Zoffset to the current Z Mach coord
 double Toffset = (Zoffset - ZShift);               //Set Toffset to be current Z minus Zshift
exec.Code("G49");                                        // Cancel/delete tool offset
exec.Wait(100);
AS3.Setfieldtext("Removed Tool Offset ",2000);
AS3.Setfield(Toffset , (195+Tool));
exec.Callbutton(780);                                 // Save tooltable
AS3.Setfieldtext("The Tool Table Is Updated ",2000);
AS3.Setfieldtext(" ",2000);
AS3.Setfieldtext("Applying G43 ",2000);
exec.Wait(1000);
exec.Code("G43 H" +Tool );   
AS3.Setfieldtext("          G43 H" +Tool +"  Applied ",2000);
AS3.Setfieldtext(" ",2000);
exec.AddStatusmessage("G43 Applied");
Parkgrr
 
Posts: 98
Joined: Mon Dec 07, 2020 9:12 am

Re: Z-offset after tool change wrong

Postby fsli » Wed Feb 01, 2023 2:33 am

This is incorrect:
Code: Select all
exec.Code("G91");
exec.Code("G31 Z" + ZPos + " F5.0" );       // Probes the tool length.

Since it's a relative move, the Z value needs to be the distance (and direction) to travel, not the absolute position. In my example, I showed it this way:
Code: Select all
// Probe using relative distance (not dependent on coordinate system)
exec.Code("G91");
exec.Code("G31 Z-" + ZMove + " F5.0" ); // Probes the tool length

I used Zmove, which in your macro is the distance you want to travel. I placed a minus just before it, in the "G31 Z-", based on your example subtracting it from the starting Z position.

You're checking:
Code: Select all
if(ZPos == OldZpos)                                       // Check if the the tool positon was found.
{
  MessageBox.Show("ERROR! The tool did not hit the probe and DRO was not set");
  exec.Stop();
  return;
}

... and (Zpos == OldZpos) is not likely to ever happen. That is, if the probe fails it doesn't retract to the starting position: it dies where it dies. I included a test for probe failure in my example.

As for the rest of the macro, I'm not sure what you're trying to accomplish. It looks like you're wanting to save the tool length into the tool table, but I don't see where Zshift is being defined. I don't think the calculation you're doing for Toffset will necessarily result in the length of the tool.
Frank
fsli
 
Posts: 93
Joined: Mon Jul 11, 2022 12:36 am

Re: Z-offset after tool change wrong

Postby Parkgrr » Wed Feb 01, 2023 9:37 pm

The if(ZPos == OldZpos) is a holdover error check from issues that existed with the UCR201 pendant plugin that would mess with probing until very recently. Removed that safely (I think)

Thanks for the help. G31 is a bit mysterious to me. Basic question, How should I be using the 5063 coord? Is that a G53 coord? I assume I probe, then before moving get 5063, do exec.GetZmachpos(), and subtract one from the other to get tool offset, and load that value into the necessary fields line by line?

Also, would you be open to shooting over your M31? This macro was adapted from a Terry Parker macro, just want to make sure I'm writing these fields correctly.
Parkgrr
 
Posts: 98
Joined: Mon Dec 07, 2020 9:12 am

Re: Z-offset after tool change wrong

Postby Parkgrr » Thu Feb 02, 2023 12:26 am

Thank you for helping. I guess I'm not sure what to do with 5063, you've recommended it though so I'd like to make this thing as bulletproof as I can.
Code: Select all
//DO FINE PROBE (Already in G91)----------
exec.Code("G0 Z" + SecondMeasRetract);
exec.Code("G31 Z-" + ZMove + FeedrateSlow);               //Fine Probe
exec.Code("G90");
while(exec.IsMoving()){}
if (!AS3.GetLED(244) || exec.Ismacrostopped())
{
   MessageBox.Show(exec.mainform, "Probe failed!");
   exec.Code("G1 G53 F75 Z"+(SafeZ));                          // Move to safe Z
   return;
}
while(exec.IsMoving()){}

// APPLY OFFSET
exec.Code("G44 H" +Tool );                                        //Set tool length offset
exec.Callbutton(780);                                               // Save tooltable
Parkgrr
 
Posts: 98
Joined: Mon Dec 07, 2020 9:12 am

Re: Z-offset after tool change wrong

Postby Parkgrr » Thu Feb 02, 2023 7:12 am

(I'm open to help from anyone just trying to get this macro working. The macro posted above functions perfectly except that new tool offsets are not being written to the tool table or the WCS tool offset. I checked the default M31 and it looks just like this, a tip from anyone?)
Parkgrr
 
Posts: 98
Joined: Mon Dec 07, 2020 9:12 am

PreviousNext

Return to General discussion about the UCCNC software

Who is online

Users browsing this forum: No registered users and 10 guests