m31 tool leght offset not saved

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

m31 tool leght offset not saved

Postby Ukendt » Mon Nov 25, 2024 12:54 pm

Hi folks :-)

Im curently tryng to set up a tool probing , i have the m31 doing its job more or less . Problem is that tool offsets dont populate the tool library ! in the m31 macro there is a line with G44 Hx , but it dosnt seem to store anything . The probing is done in negative direction from G53 Z home , perhaps one of you can see what im missing
Code: Select all
//

M31 probing macro

double probeX = 120;
double probeY = 588;
double Zmin = -200;
double FeedrateFast = 200;
double FeedrateSlow = 100;
double SafeZ = -60;
double retractheight = 150;
double retractforsecondmeasurement = 1;

bool domoveXY = true; //Enable XY movement false
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 probing!");
  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()){}
}

}

Ukendt
 
Posts: 6
Joined: Thu Jul 20, 2023 8:49 pm

Re: m31 tool leght offset not saved

Postby sebba » Mon Nov 25, 2024 2:34 pm

Hi,

I did this like this:
I defined a TCP (Tool Change Position) in machine coordinates. In that position I have a fixed probe, only for measuring tools.
First, I had to find out where (on Z axis) is the touch plate.
For this, I use a tool with known length, declared as Master Tool, or Reference Tool in Probe page.
To find out the Z position of the TP (Touch Plate) I made a macro. This is used for "calibrating" the TCP-TP mcZ position.
You can find the macro here: https://github.com/Haimana/HTM_ATC/blob ... M20330.txt
This macro, corelated with the known length of the Master Tool, will get and save in the profile file the mcZpos of the touch plate. This is the TCP-TP calibrating part.
The mcZpos remain untouched in profile file until the next run of M20330.

For measuring tools and save their length in TT (ToolTable), i made another macro, M20331. https://github.com/Haimana/HTM_ATC/blob ... M20331.txt
This macro will measure the actual loaded tool and the measured length is saved in the TT with this line of code:
Code: Select all
exec.Writetooltablecell(currentTool, varLength, Convert.ToString(currenToolOffset));


Unfortunately the code is dirty and more comments are in Romanian language. Otherwise, for me, this way works like a charm. Same principle was running for more than 6 years on Mach3 and now it was "translated" and is running on UCCNC.
Of course, my macros are made for my ATC system but can be easily modified for your needs.

Best regards,
Seb
- YQWQ
User avatar
sebba
 
Posts: 62
Joined: Mon Dec 21, 2020 9:56 am
Location: Bucharest, ROMANIA

Re: m31 tool leght offset not saved

Postby Ukendt » Wed Nov 27, 2024 4:27 pm

Hi Seb !

Ill have a look at it here in the weekend , sound like just the thing i need :-) hopefully google translate can help a bit with the comments . I am not able yet to discern wether code is good or bad so that absolutly not a problem :-D
Ukendt
 
Posts: 6
Joined: Thu Jul 20, 2023 8:49 pm

Re: m31 tool leght offset not saved

Postby sebba » Wed Nov 27, 2024 7:36 pm

hello,
unfortunately I have no time to clean the code and make the translations. I still have some updates to do (spindle sensors) and some graphics
even the github say "not ready", what is there is running for almost 2 weeks but not very often (lack of time). I personally consider this stage as RC version.
If you have time, you can give a try. I'll be happy to answer your questions, if any. just use my topic for this.
best regards,
Seb
- YQWQ
User avatar
sebba
 
Posts: 62
Joined: Mon Dec 21, 2020 9:56 am
Location: Bucharest, ROMANIA

Re: m31 tool leght offset not saved

Postby valhallaCNC » Fri Nov 29, 2024 1:58 pm

Sebba...
I checked your GitHub where you included my M20002 macro for VFD. I didn't see the M3 and M4 macro in the GitHub, you really need those for up to speed to work correctly. I never thought to add the dwell to M20002, my speed doesn't vary once set. Are you using the dwell in place of my M3 and M4 ? I haven't ran your version yet , just curious as to how the dwell is used .
Thanks Joe
valhallaCNC
 
Posts: 83
Joined: Wed Jun 30, 2021 8:04 pm

Re: m31 tool leght offset not saved

Postby sebba » Fri Nov 29, 2024 2:34 pm

I'm outside right now but as far as I remember (huh, old guy here) M3 and M4 are the default macros, what I did there should be applied over a default install/profile
I hope I'm remember correctly :D
- YQWQ
User avatar
sebba
 
Posts: 62
Joined: Mon Dec 21, 2020 9:56 am
Location: Bucharest, ROMANIA

Re: m31 tool leght offset not saved

Postby valhallaCNC » Fri Nov 29, 2024 2:43 pm

M3 and M4 are default, I used modified versions, for the up to speed to work. This topic viewtopic.php?f=2&t=3366 has the modified ones. Stop using old as an excuse....makes me wanna nap early...
valhallaCNC
 
Posts: 83
Joined: Wed Jun 30, 2021 8:04 pm

Re: m31 tool leght offset not saved

Postby Ukendt » Sun Dec 01, 2024 2:00 pm

Hello again :-)

Am looking this atm , but cant find the option to declare an Master tool at the probe section in software . Could you point me in the right direction perhaps ?

I translated your 20330 and 20331 macro's

Code: Select all
// macro for calibrating TCP sensor, the mcZ position
// will be need a "Master Tool" with known length
// have to be done once per setup or re-done if the sensor is repositioned

   //define error sound message
   System.Media.SoundPlayer errorSound = new System.Media.SoundPlayer(Application.StartupPath + @"\Flashscreen\SOUND\error.wav");
   
   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...
   {
      exec.AddStatusmessage("Measure TCP Z measuring cannot start! One or more axis are NOT REFERENCED");
      errorSound.Play();
      exec.Stop();
      return;
   }
   
      DialogResult confirmMeasure = MessageBox.Show(
      "Are you sure you want to measure the TCP TP position?\n\nYou need the Reference Tool!\nYou also have to know the Reference Tool length!\n\nPress OK to continue or Cancel to abort",
      "Measure Tool!",
      MessageBoxButtons.OKCancel,
      MessageBoxIcon.Warning,
      MessageBoxDefaultButton.Button2,
      MessageBoxOptions.ServiceNotification
      );
               
      if (confirmMeasure == DialogResult.Cancel) {         
         exec.Stop();
         return;
      // } else if (confirmMeasure == DialogResult.OK) {
         // exec.AddStatusmessage("Moving to TCP");
         // exec.Code("M200");
         // exec.Code("M20331");
      } // end code for OK response


   // check for master tool
   if (exec.Getcurrenttool() != AS3.Getfieldint(2747)) {
      exec.AddStatusmessage("Master Tool not loaded! Master tool " + AS3.Getfieldint(2747));
      errorSound.Play();
      exec.Stop();
      return;
   }
      
// we take the TCP (Tool Change Position) coordinates from the ATC setup
double tcpXpos = AS3.Getfielddouble(30020);
double tcpYpos = AS3.Getfielddouble(30021);
double tcpZpos = AS3.Getfielddouble(30022);

double minZlimit = AS3.Getfielddouble(41);
double FeedrateSlow = AS3.Getfielddouble(2710);
double FeedrateFast = AS3.Getfielddouble(2709);
double FeedRate = AS3.Getfielddouble(30017);


// define feed for tool measurement
double retractforsecondmeasurement = AS3.Getfielddouble(2706);

// master tool length
double masterLength = AS3.Getfielddouble(30024);
// exec.AddStatusmessage("Reference Tool Length = " + masterLength);

bool dodualcycle =  AS3.Getbuttonstate(853); //Do probing from 2 cycles, first with Fast and second with Slow feedrates
// exec.AddStatusmessage(Convert.ToString(dodualcycle));


//we are moving to tcpZpos
exec.Code("G53 G01 F" + FeedRate + " Z" + tcpZpos);
exec.Code("G53 G01 F" + FeedRate + " X" + tcpXpos);
exec.Code("G53 G01 F" + FeedRate + " Y" + tcpYpos);
while(exec.IsMoving()){}

if(!dodualcycle)
{
  exec.Code("G31 Z" + minZlimit + "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()){}

//we descend to touch, maximum on the minimum Z coordinate defined in the axes
exec.Code("G31 F" + FeedrateSlow + " Z" + minZlimit);
while(exec.IsMoving()){}

   double mcZpos = exec.GetZmachpos();
   exec.AddStatusmessage("mcZpos = " + mcZpos);
   mcZpos = exec.GetZmachpos() - masterLength;
   exec.AddStatusmessage("mcZpos + masterLength = " + mcZpos);
   AS3.Setfield(mcZpos, 20330);
   AS3.Validatefield(20330);
   
   //save mcZpos in profile file   
   exec.Writekey("UserTextfields", "20330", Convert.ToString(mcZpos)); //   
   exec.Wait(500); // Wait 500msec
   
exec.Code("G53 G01 F" + FeedRate + " Z" + tcpZpos);

//


Code: Select all
// macro for measuring tools in TCP. M20330 have to be run first (once)
// M20330 will provide the mcZpos of TCP sensor

// defining error sound file
System.Media.SoundPlayer errorSound = new System.Media.SoundPlayer(Application.StartupPath + @"\Flashscreen\SOUND\error.wav");
   
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...
{
   exec.AddStatusmessage("Measure TCP Z measuring cannot start! One or more axis are NOT REFERENCED");
   errorSound.Play();
   exec.Stop();
   return;
}
   
// TCP (Tool Change Position) from ATC setup
double tcpXpos = AS3.Getfielddouble(30020);
double tcpYpos = AS3.Getfielddouble(30021);
double tcpZpos = AS3.Getfielddouble(30022);

double minZlimit = AS3.Getfielddouble(41);
double FeedrateSlow = AS3.Getfielddouble(2710);
double FeedrateFast = AS3.Getfielddouble(2709);
double FeedRate = AS3.Getfielddouble(30017);

double retractforsecondmeasurement = AS3.Getfielddouble(2706);

// mcZpos position - saved by M20330 macro with Master Tool with known length
double mcZpos = Convert.ToDouble(exec.Readkey("UserTextfields", "20330", "0"));

// getting current tool number, for measuring
int currentTool = exec.Getcurrenttool(); // We take the current tool - oldtool in records Mach

bool dodualcycle =  AS3.Getbuttonstate(853); //Do probing from 2 cycles, first with Fast and second with Slow feedrates
// exec.AddStatusmessage(Convert.ToString(dodualcycle));

var varLength = Plugininterface.Datatypes.Tooltablecolumnname.Length;

// moving to TCP
   exec.Code("G53 G01 F" + FeedRate + " Z" + tcpZpos);
   exec.Code("G53 G01 F" + FeedRate + " Y" + tcpYpos);
   exec.Code("G53 G01 F" + FeedRate + " X" + tcpXpos);
   while(exec.IsMoving()){}

if(!dodualcycle)
{
  exec.Code("G31 Z" + minZlimit + "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()){}

//we descend to touch, maximum on the minimum Z coordinate defined in the axes
exec.Code("G31 F" + FeedrateSlow + " Z" + minZlimit);
while(exec.IsMoving()){}

double currentZpos = exec.GetZmachpos();

   double currenToolOffset = Math.Abs(mcZpos) + exec.GetZmachpos();
   exec.AddStatusmessage("toolLength = " + currenToolOffset);

    exec.Writetooltablecell(currentTool, varLength, Convert.ToString(currenToolOffset)); //
    exec.Callbutton(780); // Calling the button to save the tooltable
   exec.Code("G43 H" + currentTool);

   // search for the currentTool in slots. Update fields if found.
   for (int i = 1; i <= 10; i++) {
        if (currentTool == AS3.Getfieldint(20500 + i)) {
            AS3.Setfieldtext(Convert.ToString(currenToolOffset), i+20520); // display the length of the tool in the slot
            AS3.Validatefield(i+20520); // strong input                   
        }
   }
   
   // updating tool edit fields
   exec.Code("M20400");
   
   // returning to tcpZpos
   exec.Code("G53 G01 F" + FeedRate + " Z" + tcpZpos);


I also se a reference to macro 20400 do i need to have that also to make this work ? if i can make it to bend to my will :-D
Last edited by Ukendt on Sun Dec 01, 2024 2:03 pm, edited 1 time in total.
Ukendt
 
Posts: 6
Joined: Thu Jul 20, 2023 8:49 pm

Re: m31 tool leght offset not saved

Postby sebba » Sun Dec 01, 2024 4:24 pm

not mandatory, you can comment it
M20400 si updating the textfields values on this screen.
atc1.PNG


Master Tool is teh same thing with Reference Tool in Probe -> Setup screen
atc2.PNG
- YQWQ
User avatar
sebba
 
Posts: 62
Joined: Mon Dec 21, 2020 9:56 am
Location: Bucharest, ROMANIA

Re: m31 tool leght offset not saved

Postby Ukendt » Sun Dec 01, 2024 4:34 pm

sebba wrote:not mandatory, you can comment it
M20400 si updating the textfields values on this screen.
atc1.PNG


Master Tool is teh same thing with Reference Tool in Probe -> Setup screen
atc2.PNG


Ok how do i add this tool screen you have there , i just now reaized you have made a whole ATC screen(plugin) :geek: think i might have do update Uccnc software because i dont have that option , ive been running the 1.2113 and think i read you have tested with 1.2117 . Anyways im gonna reinstall when i find that new version installer and have a new look at it .
Ukendt
 
Posts: 6
Joined: Thu Jul 20, 2023 8:49 pm

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 6 guests

cron