Page 1 of 1

Setting Current Coords from Tool Table information

PostPosted: Thu Sep 30, 2021 3:12 am
by DavidT
Hi,
I'm trying to set by macro the current coordinates using the tool length found in the tool table.
If I do it manually it works fine: entering "Tool Z Offset" in the "(Z) Work Offset" column will have the "(Z) Current coords" to update automatically and it keeps it up to date on homing.
If use a Setfield command in a macro, the Current coords are not updated automatically.

Please note: We work with a Z Zero at the machine bed surface and not on top of material. It's more convenient for us to work that way but I don't see it often so things might seem off from the start for some people.

So basically the idea is:
- we change tool with M6, and M6 calls for a M31 at the end
- M31 verify (among other things) if the tool already have a defined tool length in the tool table
> if no = measure the tool, update tool table & G54-G59 fixtures = life is good
> else (yes) = skip measurement, use tool length and input as "Tool Z Offset" + calculate and set "(Z) Work Offsets" because it was not done automatically = my script does not work as intended = life is okay but could be better

Here's the bloc that partially work. When I home the machine I would have to run this code block again to get the settings right.
Code: Select all
else //If tool is already measured, make sure machine offset matches the tool
{
   StringValue = AS3.Getfield(TLField);
   TOffset = Convert.ToDouble(StringValue);
   StringValue = AS3.Getfield(873); //Get Machine Coords Z
   ZOffset = Convert.ToDouble(StringValue);
   ZOffset = ZOffset - TOffset;   
     
   //UPDATE FIXTURE OFFSETS (Sets all fixture Z using Tool Length found in tool table)
   AS3.Setfield(ZOffset, 99); //Set Current Coords G54
   AS3.Setfield(TOffset, 135); //Set G54 Z Work Offset
   AS3.Setfield(ZOffset, 105); //Set Current Coords G55
   AS3.Setfield(TOffset, 141); //Set G55 Z Work Offset
   AS3.Setfield(ZOffset, 111); //Set Current Coords G56
   AS3.Setfield(TOffset, 147); //Set G56 Z Work Offset
   AS3.Setfield(ZOffset, 117); //Set Current Coords G57
   AS3.Setfield(TOffset, 153); //Set G57 Z Work Offset
   AS3.Setfield(ZOffset, 123); //Set Current Coords G58
   AS3.Setfield(TOffset, 159); //Set G58 Z Work Offset
   AS3.Setfield(ZOffset, 129); //Set Current Coords G59
   AS3.Setfield(TOffset, 165); //Set G59 Z Work Offset
}

If interested, here's the full Macro
Code: Select all
//Artefact Eyewear M31 probing macro

bool ReturnToOrigin = false; //True = move machine back to initial coordinates | False = stay over tool setter

//Tool Setter Settings
double TSX = 3;      //Tool Setter X position
double TSY = 503;   //Tool Setter Y position
double TSH = 47.14;    //Tool Setter Height

//Z-Axis Settings
double SafeZ = 98.5;   //Move to this Safe Z height before moving the machine
double PrbInitZ = 75;    //Height to go to before starting to probe
double Zmin = -30;      //Max probing travel distance
double FRFast = 300;   //Initial probing speed
double FRSlow = 100;   //Fine probing speed
double RetractH = 3;   //Retract distance after first touch on tool setter

//Tool Information
int Currenttool = exec.Getcurrenttool();
int TLField = 0;
if (Currenttool > 0 && Currenttool <= 21)
{
   TLField = (Currenttool + 195);
}
else if (Currenttool >= 22 && Currenttool <= 96)
{
   TLField = (Currenttool + 900);
}
else
{
MessageBox.Show("The (current) tool number is invalid.");
exec.Stop();
return;
}
double TOffset = 0;
double ToolLength;

//Utility variables
string StringValue;
double Xoriginalpos;
double Yoriginalpos;
double ZOffset;

//If machine was not homed then it is unsafe to move in machine coordinates, stop here...
if (!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58))
{
   MessageBox.Show("The machine was not yet homed, home the machine before probing!");
   exec.Stop();
   return;
}


//STORE THE CURRENT MACHINE COORDINATES
while(exec.IsMoving()){}
Xoriginalpos = exec.GetXmachpos();
Yoriginalpos = exec.GetYmachpos();


StringValue = AS3.Getfield(TLField);
ToolLength = Convert.ToDouble(StringValue);
if (ToolLength == 0) // Measure tool offset (Z) only if it's not already set
{
   //MessageBox.Show("Measuring Tool Length");
   //MOVE TO TOOL SETTER POSITION
   exec.Code("G00 G53 Z" + SafeZ); //Move Z up first
   while(exec.IsMoving()){}

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

   exec.Code("G00 G53 Z" + PrbInitZ); //Fast move to Probing Initial position
   while(exec.IsMoving()){}


   //PROBE ON TOOL SETTER
   exec.Code("G91");

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

   exec.Code("G0 Z" + RetractH);
   while(exec.IsMoving()){}

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

   exec.Code("G90");
   
   if (!exec.Ismacrostopped()) //If tool measure was not interrupted with a stop only then validate new tool number
   {
      //UPDATE FIXTURE OFFSETS (Sets all fixture to Z0 using Tool Setter Height)
      exec.mainform.sumoffsetcontrol1.G54.newCzinput(TSH); //Set G54 to new Zzero
      exec.mainform.sumoffsetcontrol1.G55.newCzinput(TSH); //Set G55 to new Zzero
      exec.mainform.sumoffsetcontrol1.G56.newCzinput(TSH); //Set G56 to new Zzero
      exec.mainform.sumoffsetcontrol1.G57.newCzinput(TSH); //Set G57 to new Zzero
      exec.mainform.sumoffsetcontrol1.G58.newCzinput(TSH); //Set G58 to new Zzero
      exec.mainform.sumoffsetcontrol1.G59.newCzinput(TSH); //Set G59 to new Zzero

      //STORE TOOL OFFSET IN TOOL TABLE
      StringValue = AS3.Getfield(135);
      TOffset = Convert.ToDouble(StringValue);
      AS3.Setfield(TOffset, TLField);
      while(exec.IsMoving()){}
      exec.Wait(200);
 
      //MOVE BACK TO ORIGINAL POSITION
      exec.Code("G00 G53 Z" + SafeZ); //Move Z up first
      while(exec.IsMoving()){}

      if (ReturnToOrigin)
      {
         exec.Code("G00 G53 X" + Xoriginalpos +" Y" + Yoriginalpos); //Move back to the original XY position
         while(exec.IsMoving()){}
      }
   }
}
else //If tool is already measured, make sure machine offset matches the tool
{
   StringValue = AS3.Getfield(TLField);
   TOffset = Convert.ToDouble(StringValue);
   StringValue = AS3.Getfield(873); //Get Machine Coords Z
   ZOffset = Convert.ToDouble(StringValue);
   ZOffset = ZOffset - TOffset;   
      
   //UPDATE FIXTURE OFFSETS (Sets all fixture Z using Tool Length found in tool table)
   AS3.Setfield(ZOffset, 99); //Set Current Coords G54
   AS3.Setfield(TOffset, 135); //Set G54 Z Work Offset
   AS3.Setfield(ZOffset, 105); //Set Current Coords G55
   AS3.Setfield(TOffset, 141); //Set G55 Z Work Offset
   AS3.Setfield(ZOffset, 111); //Set Current Coords G56
   AS3.Setfield(TOffset, 147); //Set G56 Z Work Offset
   AS3.Setfield(ZOffset, 117); //Set Current Coords G57
   AS3.Setfield(TOffset, 153); //Set G57 Z Work Offset
   AS3.Setfield(ZOffset, 123); //Set Current Coords G58
   AS3.Setfield(TOffset, 159); //Set G58 Z Work Offset
   AS3.Setfield(ZOffset, 129); //Set Current Coords G59
   AS3.Setfield(TOffset, 165); //Set G59 Z Work Offset
}


Maybe I could just calculate what to use instead of TSH in "exec.mainform.sumoffsetcontrol1.G54.newCzinput(TSH);" ... or use ZOffset!!?!? :!: :?: Hmmm

Re: Setting Current Coords from Tool Table information

PostPosted: Thu Sep 30, 2021 3:20 am
by DavidT
Well that seem to work! :oops:

Code: Select all
else //If tool is already measured, make sure machine offset matches the tool
{
   StringValue = AS3.Getfield(TLField);
   TOffset = Convert.ToDouble(StringValue);
   StringValue = AS3.Getfield(873); //Get Machine Coords Z
   ZOffset = Convert.ToDouble(StringValue);
   ZOffset = ZOffset - TOffset;   
      
   //UPDATE FIXTURE OFFSETS (Sets all fixture Z using Tool Length found in tool table)
   exec.mainform.sumoffsetcontrol1.G54.newCzinput(ZOffset); //Set G54 to new Zzero
   exec.mainform.sumoffsetcontrol1.G55.newCzinput(ZOffset); //Set G55 to new Zzero
   exec.mainform.sumoffsetcontrol1.G56.newCzinput(ZOffset); //Set G56 to new Zzero
   exec.mainform.sumoffsetcontrol1.G57.newCzinput(ZOffset); //Set G57 to new Zzero
   exec.mainform.sumoffsetcontrol1.G58.newCzinput(ZOffset); //Set G58 to new Zzero
   exec.mainform.sumoffsetcontrol1.G59.newCzinput(ZOffset); //Set G59 to new Zzero
}