M6 to update multiple WCS (M54, M55..)

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

M6 to update multiple WCS (M54, M55..)

Postby sternman318 » Fri Apr 24, 2020 9:02 pm

Hello,
I am using an M6 macro that has been floating around. For work in on WCS, it works beautifully. It is attached in the code format below.

Is it possible to modify it to update both G54 and G55? For example, if you have two of the same piece in the vice and want to do both in a single setup. The probe as it is seems to operate under whichever WCS it is initiated under.

Thank you.

Code: Select all
if (!exec.GetLED(308))                                                          // Mobile wp referenced
{
  exec.AddStatusmessage("The workpiece was not referenced.");
  return;
}

bool wasCycleRunning = exec.GetLED(54);

if (wasCycleRunning)
{
  exec.Stop();
  while(exec.IsMoving()){}
  exec.Code("");
}

int CurrTool = exec.Getcurrenttool();
int NewTool = exec.Getnewtool();

if (NewTool == -1)                                                              // -1 -> there was no T word
{
  exec.AddStatusmessage("There was no T word for the M6.");
  return;
}

string NewToolName = "T" + NewTool;

if (NewTool == CurrTool)
{
  if (wasCycleRunning) exec.Callbutton(128);                                    // Cycle start if it was started
  return;
}

double cpX = exec.GetXmachpos();
double cpY = exec.GetYmachpos();
double cpZ = exec.GetZmachpos();

double cpwZ = exec.GetZpos();

if (!GotoMachPos(tcpX, tcpY, tcpZ)) return;

MessageBox.Show(exec.mainform, "Insert new tool " + NewToolName, "Change tool");
if (exec.Ismacrostopped()) return;

exec.Setcurrenttool(NewTool);
while (exec.IsMoving());

exec.Callbutton(801);                                                           // Tool probe
exec.Callbutton(841);                                                           // Mobile probe
exec.Callbutton(800);                                                           // Quick jump to probe screen

if (!AS3.Getbuttonstate(851)) exec.Callbutton(851);                             // Zero probed axes

exec.Callbutton(848);                                                           // Goto probe pos

exec.Wait(100);
while (exec.IsMoving());
if (exec.Ismacrostopped()) return;

exec.Miston();                                                                  // Turn Mist On

exec.Callbutton(821);                                                           // Start probe
while (!AS3.Getbuttonstate(821) && !exec.Ismacrostopped()) Thread.Sleep(10);
while (AS3.Getbuttonstate(821) && !exec.Ismacrostopped()) Thread.Sleep(10);
exec.Wait(500);
if (exec.Ismacrostopped()) return;

exec.Stopcoolant();                                                             // Turn Mist Off

if (exec.GetLED(300)) return;                                                   // If probe failed then exit (g-code is stopped!)

AS3.selectlayer(2);

if (!GotoMachPos(cpX, cpY, GetMachFromWorkZ(cpwZ))) return;

if (wasCycleRunning) exec.Callbutton(128);                                      // Cycle start if it was started

return;

#Events

const double tcpX = -10.7404;                                                        // Tool change position
const double tcpY = -0.9035;
const double tcpZ = 0;

bool GotoMachPos(double x, double y, double z)
{
  List<string> codelist = new List<string>();                                   // Create a new List of strings.

  double limitPlus = AS3.Getfielddouble(42);                                    // Z axis softlimit +
  bool limitValid = (AS3.Getfielddouble(41) != limitPlus);                      // Softlimit valid if limit+ <> limit-

  double cZ = exec.GetZmachpos();
  double safeZ = AS3.Getfielddouble(2734);                                      // SafeZ
  double moveZ = cZ;

  if (limitValid && (z > limitPlus))                                            // Check for Z overtravel
  {
    if (MessageBox.Show(exec.mainform, "Destination Z is higher than Z soft limit.\nAllow move on Z soft limit?", "Z height warning!", MessageBoxButtons.YesNo) == DialogResult.Yes)
      z = limitPlus;                                                            // Set destination Z to limit+
    else
    {
      exec.Callbutton(130);                                                     // Stop!
      return false;
    }
  }

  if (moveZ < safeZ) moveZ = safeZ;
  if (moveZ < z) moveZ = z;
  if (cZ < moveZ)
    codelist.Add("G0 G53 Z" + moveZ.ToString("F6"));
  codelist.Add("G0 G53 X" + x.ToString("F6") + " Y" + y.ToString("F6"));
  codelist.Add("G0 G53 Z" + z.ToString("F6"));

  exec.Codelist(codelist);                                                      //Execute the List of g-codes.
  while (exec.IsMoving());

  return !exec.Ismacrostopped();
}

double GetMachFromWorkZ(double wz)
{
  double g92offset = AS3.Getfielddouble(502);
  double tooloffset = AS3.Getfielddouble(169);
  double workoffset = AS3.Getfielddouble(133 + 6 * (int)(exec.Getactualmodalcode(12) - 54) + 2);
  return (wz + workoffset + g92offset + tooloffset);
}
Attachments
M6.txt
(4.48 KiB) Downloaded 417 times
sternman318
 
Posts: 5
Joined: Sat Mar 07, 2020 5:35 am

Re: M6 to update multiple WCS (M54, M55..)

Postby sternman318 » Fri Apr 24, 2020 9:43 pm

Looks like selecting "Zero All Offsets" should achieve this. Apologies for the post.
sternman318
 
Posts: 5
Joined: Sat Mar 07, 2020 5:35 am


Return to General discussion about the UCCNC software

Who is online

Users browsing this forum: Bing [Bot] and 12 guests