M6

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

M6

Postby tracar » Mon Dec 03, 2018 6:48 am

here is the problem
i start a file , it calls M6, Z raises , the spindle stops, it moves to the tool change area, ( manually change tool and hit ok)the tool is now probing for new tool length. IT RAISES Z, STARTS SPINNING then it GOES TO WHERE IT LEFT OFF AND starts cutting as normal, at this point when a second M6 is called Z raises , the spindle stops, it moves to the tool change area, ( manually change tool and hit ok)the tool is now probing for new tool length, lifts , STARTS THE SPINDLE, AND DOES NOT RAISE AND GO TO WHERE IT LEFT OFF IN THE cut.... does a strange 90degree travel, CANT FINGER THIS OUT...

attached the M6 file below.

this is manual tool change

on the latest version of uccnc
Attachments
M6.txt
(2.93 KiB) Downloaded 1015 times
tracar
 
Posts: 39
Joined: Sun Jun 18, 2017 6:37 pm

Re: M6

Postby Robertspark » Mon Dec 03, 2018 1:26 pm

Looking at your macro:

You dont record the position where the cut stopped / the M6 was called from.

I'd suggest recording that before you (line 18):

Code: Select all
exec.Code("G00 G53 Z"+ parkZ); // Move Z up first to park2 Z position


Then after line 78 (last line)

I'd suggest moving the machine back to where the M6 called it from, and then end the M6 macro at that point, given the tool will now be in the same location X, Y and then drop down to Z. and then return from the macro,.

I would suggest that you may want to reset you feedrate or spindle speed to match you manually installed tool, so you may want a prompt before you send the machine off to carry on cutting where you left off (although this may be in the gcode already).

---------------------------------------------------

I'd suggest getting rid of the second:

Code: Select all
if(!exec.GetLED(56)||!exec.GetLED(57)||!exec.GetLED(58)) // If machine was not homed then it is not smart to do this, stop here...
{
  MessageBox.Show("The machine was not yet homed, home the machine before setting Z-zero");
  exec.Stop();
  return;
}


given you already tested for it on lines 7 >12
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M6

Postby Robertspark » Mon Dec 03, 2018 3:40 pm

This one may work better for you:

(Obviously TRY it WITHOUT BREAKING A TOOL + material first..!!!)

Code: Select all
// "automatic"  tool change

double parkZ = 0;
double parkX = 1.7;
double parkY = -23;

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()){}

int originalmodalmode = exec.actualmodal; // remember the modal mode
int originaldistancemode = exec.actualdistmode; // remember the distance (G90/G91) mode
double Xmachposvariable = exec.GetXmachpos(); // remember X Axis
double Ymachposvariable = exec.GetYmachpos(); // remember Y Axis
double Zmachposvariable = exec.GetZmachpos(); // remember Z Axis

string Activemodal = AS3.Getfield(877); // Field 877: Activemodal
string[] WordSeparator = new string[] {"|"};
string[] ParamSeparator = new string[] {","};
string[] Modals = Activemodal.Split(WordSeparator, StringSplitOptions.None);
string WorkOffset = Modals[4]; // G54-G59 save current work offset
exec.Wait(200);

// begin toolchange macro movement.....
exec.Code("G90"); // set machine to absloute distance mode
exec.Code("G00 G53 Z"+ parkZ); // Move Z up first to park2 Z position
while(exec.IsMoving()){}

exec.Code ("M5");  // ***** added this to stop the spindle after it raises from the cut *****

exec.Code("G00 G53 X" + parkX +" Y" + parkY); // Move to XY park2 position
while(exec.IsMoving()){}

{
  MessageBox.Show("Manually Change Tool NOW, Then Press OK To Continue");
}


//Simple Probe for Zero
//This routine probes in negative Z at the current XY location
//Z offsets for G54 to G59 are then re-written to the new Z0

double ZRetractHeight = 3;  //Height above Z0 to which probe will retract
double CoarseRate = 50; //Feedrate for initial probing
double FineRate = 1;  //Feedrate for fine probing
double Zmin = -6; //maximum probing distance

double PlateThickness = .244;  //thickness of the probing plate
double MaterialOffset = 0; //compensation for part thickness

double CombinedOffset = PlateThickness - MaterialOffset;  //really for use later when PlateThickness and MaterialOffset are DROs

exec.Code( "G91 " ); //switch machine to incremental distance mode
exec.Code( "G31 Z" + Zmin + "F" + CoarseRate); // Probe Z quickly to get rough height
while(exec.IsMoving()){}
exec.Wait(200);

exec.Code ("G00 Z" + .050); // Retract .05" above the plate
while(exec.IsMoving()){}
exec.Wait(100);

exec.Code("G31 Z" + Zmin + "F" + FineRate); // Probe Z slowly for better resolution
while(exec.IsMoving()){}
exec.Wait(200);

exec.mainform.sumoffsetcontrol1.G54.newCzinput(CombinedOffset);  // Set G54 to new Zzero
exec.mainform.sumoffsetcontrol1.G55.newCzinput(CombinedOffset);  // Set G55 to new Zzero   
exec.mainform.sumoffsetcontrol1.G56.newCzinput(CombinedOffset);  // Set G56 to new Zzero
exec.mainform.sumoffsetcontrol1.G57.newCzinput(CombinedOffset);  // Set G57 to new Zzero
exec.mainform.sumoffsetcontrol1.G58.newCzinput(CombinedOffset);  // Set G58 to new Zzero
exec.mainform.sumoffsetcontrol1.G59.newCzinput(CombinedOffset);  // Set G59 to new Zzero
//probing routine & tool offset complete

//move back & restart motion
exec.Code("G00 G53 Z"+ parkZ); // Move Z up first to park Z position
while(exec.IsMoving()){}
exec.Wait(200);
exec.Code ("M3");  //  restart start
exec.Wait(200);
exec.Code("G00 G53 X"+ Xmachposvariable + " Y"+ Ymachposvariable); // move cutter back to X&Y toolchange position
while(exec.IsMoving()){}
exec.Wait(200);
exec.Code("G00 G53 Z"+ Zmachposvariable); // move cutter back to Z toolchange position
while(exec.IsMoving()){}
exec.Wait(200);
//reset machine modal, distance mode and work offsets.

exec.Code (" G"+ WorkOffset );// restore G54-G59 work offset
exec.Code (" G"+ originaldistancemode );// restore the distance (G90/G91) mode
exec.Code (" G"+ originalmodalmode );// restore the modal before the toolchange {G0, G1, G2, G3 etc}
exec.Wait(200);
//return to where we left off at the start of the toolchange
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M6

Postby tracar » Mon Dec 03, 2018 8:22 pm

YES YES. works great if nothing goes wrong. .....But i thought i would pretend i had a tool break, so i stopped it. goto park 1 position change tool, probe new tool length with probe button, rewind code a few, run from here... and it goes back and burries the tool.. hahaha so close.
tracar
 
Posts: 39
Joined: Sun Jun 18, 2017 6:37 pm

Re: M6

Postby Robertspark » Mon Dec 03, 2018 8:27 pm

Sorry

I know what the problem is
exec.Code("G00 G53 Z"+ Zmachposvariable)
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M6

Postby Robertspark » Mon Dec 03, 2018 9:45 pm

hmmm.... sorry ......

Try this one, I've tested it as far as I can and it seems like it will work.

Code: Select all
// "automatic"  tool change

double parkZ = 0;
double parkX = 1.7;
double parkY = -23;

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()){}

int originalmodalmode = exec.actualmodal; // remember the modal mode
int originaldistancemode = exec.actualdistmode; // remember the distance (G90/G91) mode
double Xmachposvariable = exec.GetXmachpos(); // remember X Axis
double Ymachposvariable = exec.GetYmachpos(); // remember Y Axis
double Zposvariable = exec.GetZpos(); // remember Z Axis

string Activemodal = AS3.Getfield(877); // Field 877: Activemodal
string[] WordSeparator = new string[] {"|"};
string[] ParamSeparator = new string[] {","};
string[] Modals = Activemodal.Split(WordSeparator, StringSplitOptions.None);
string WorkOffset = Modals[4]; // G54-G59 save current work offset
exec.Wait(200);

// begin toolchange macro movement.....
exec.Code("G90"); // set machine to absloute distance mode
exec.Code("G00 G53 Z"+ parkZ); // Move Z up first to park2 Z position
while(exec.IsMoving()){}

exec.Code ("M5");  // ***** added this to stop the spindle after it raises from the cut *****

exec.Code("G00 G53 X" + parkX +" Y" + parkY); // Move to XY park2 position
while(exec.IsMoving()){}

{
  MessageBox.Show("Manually Change Tool NOW, Then Press OK To Continue");
}


//Simple Probe for Zero
//This routine probes in negative Z at the current XY location
//Z offsets for G54 to G59 are then re-written to the new Z0

double ZRetractHeight = 3;  //Height above Z0 to which probe will retract
double CoarseRate = 50; //Feedrate for initial probing
double FineRate = 1;  //Feedrate for fine probing
double Zmin = -6; //maximum probing distance

double PlateThickness = .244;  //thickness of the probing plate
double MaterialOffset = 0; //compensation for part thickness

double CombinedOffset = PlateThickness - MaterialOffset;  //really for use later when PlateThickness and MaterialOffset are DROs

exec.Code( "G91 " ); //switch machine to incremental distance mode
exec.Code( "G31 Z" + Zmin + "F" + CoarseRate); // Probe Z quickly to get rough height
while(exec.IsMoving()){}
exec.Wait(200);

exec.Code ("G00 Z" + .050); // Retract .05" above the plate
while(exec.IsMoving()){}
exec.Wait(100);

exec.Code("G31 Z" + Zmin + "F" + FineRate); // Probe Z slowly for better resolution
while(exec.IsMoving()){}
exec.Wait(200);

exec.mainform.sumoffsetcontrol1.G54.newCzinput(CombinedOffset);  // Set G54 to new Zzero
exec.mainform.sumoffsetcontrol1.G55.newCzinput(CombinedOffset);  // Set G55 to new Zzero   
exec.mainform.sumoffsetcontrol1.G56.newCzinput(CombinedOffset);  // Set G56 to new Zzero
exec.mainform.sumoffsetcontrol1.G57.newCzinput(CombinedOffset);  // Set G57 to new Zzero
exec.mainform.sumoffsetcontrol1.G58.newCzinput(CombinedOffset);  // Set G58 to new Zzero
exec.mainform.sumoffsetcontrol1.G59.newCzinput(CombinedOffset);  // Set G59 to new Zzero
//probing routine & tool offset complete

//move back & restart motion
exec.Code("G00 G53 Z"+ parkZ); // Move Z up first to park Z position
while(exec.IsMoving()){}
exec.Wait(200);
exec.Code ("M3");  //  restart start
exec.Wait(200);
exec.Code("G00 G53 X"+ Xmachposvariable + " Y"+ Ymachposvariable); // move cutter back to X&Y toolchange position
while(exec.IsMoving()){}
exec.Wait(200);

//reset machine modal, distance mode and work offsets.

exec.Code (" G"+ WorkOffset );// restore G54-G59 work offset
exec.Code (" G"+ originaldistancemode );// restore the distance (G90/G91) mode
exec.Code (" G"+ originalmodalmode );// restore the modal before the toolchange {G0, G1, G2, G3 etc}
exec.Wait(200);
//return to where we left off at the start of the toolchange

exec.Code("G00 Z"+ Zposvariable); // move cutter back to Z toolchange position
while(exec.IsMoving()){}
exec.Wait(200);
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M6

Postby tracar » Tue Dec 04, 2018 12:53 am

File works great with stock tool probe script. Thankyou

What causes the x and y. To turn red like this?
Attachments
1543884747350520301248.jpg
tracar
 
Posts: 39
Joined: Sun Jun 18, 2017 6:37 pm

Re: M6

Postby tracar » Tue Dec 04, 2018 5:31 am

so how can this file be changed to put it back to the original NoN G68 non red dro on return from tool change probe.

i have included my last working file M6 i added this : exec.Code( "G69 " );
is there a better way to rewrite or add this change ?

i mean the dro's still change red, but go back to normal color just before the cut
Attachments
M6.txt
(4.04 KiB) Downloaded 865 times
tracar
 
Posts: 39
Joined: Sun Jun 18, 2017 6:37 pm

Re: M6

Postby Robertspark » Tue Dec 04, 2018 10:15 am

here you go

Seems to work ok (please test it first though with and without G68)....

Code: Select all
// "automatic"  tool change

double parkZ = 0;
double parkX = 1.7;
double parkY = -23;

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()){}

int originalmodalmode = exec.actualmodal; // remember the modal mode
int originaldistancemode = exec.actualdistmode; // remember the distance (G90/G91) mode
double Xmachposvariable = exec.GetXmachpos(); // remember X Axis
double Ymachposvariable = exec.GetYmachpos(); // remember Y Axis
double Zposvariable = exec.GetZpos(); // remember Z Axis

string Activemodal = AS3.Getfield(877); // Field 877: Activemodal
string[] WordSeparator = new string[] {"|"};
string[] ParamSeparator = new string[] {","};
string[] Modals = Activemodal.Split(WordSeparator, StringSplitOptions.None);
string WorkOffset = Modals[4]; // G54-G59 save current work offset
exec.Wait(200);

int G68active = 0;
double Rx = 0;
double Ry = 0;
double Angle = 0;
if (AS3.GetLED(254) == true){  // check if G68 active, if so store current settings to reset later.

exec.GetRotate(out Rx, out Ry, out Angle); // returns values  into the defined variables Rx, Ry and Angle
G68active = 128; // set flag
exec.Code("G69"); // clear rotation
}

// begin toolchange macro movement.....
exec.Code("G90"); // set machine to absloute distance mode
exec.Code("G00 G53 Z"+ parkZ); // Move Z up first to park2 Z position
while(exec.IsMoving()){}

exec.Code ("M5");  // ***** added this to stop the spindle after it raises from the cut *****

exec.Code("G00 G53 X" + parkX +" Y" + parkY); // Move to XY park2 position
while(exec.IsMoving()){}

{
  MessageBox.Show("Manually Change Tool NOW, Then Press OK To Continue");
}


//Simple Probe for Zero
//This routine probes in negative Z at the current XY location
//Z offsets for G54 to G59 are then re-written to the new Z0

double ZRetractHeight = 1;  //Height above Z0 to which probe will retract
double CoarseRate = 30; //Feedrate for initial probing
double FineRate = 2;  //Feedrate for fine probing
double Zmin = -5.5; //maximum probing distance

double PlateThickness = .244;  //thickness of the probing plate
double MaterialOffset = 0; //compensation for part thickness

double CombinedOffset = PlateThickness - MaterialOffset;  //really for use later when PlateThickness and MaterialOffset are DROs

exec.Code( "G91" ); //switch machine to incremental distance mode
exec.Code( "G31 Z" + Zmin + "F" + CoarseRate); // Probe Z quickly to get rough height
while(exec.IsMoving()){}
exec.Wait(200);

exec.Code ("G00 Z" + .1); // Retract .1" above the plate
while(exec.IsMoving()){}
exec.Wait(100);

exec.Code("G31 Z" + Zmin + "F" + FineRate); // Probe Z slowly for better resolution
while(exec.IsMoving()){}
exec.Wait(200);

exec.mainform.sumoffsetcontrol1.G54.newCzinput(CombinedOffset);  // Set G54 to new Zzero
//exec.mainform.sumoffsetcontrol1.G55.newCzinput(CombinedOffset);  // Set G55 to new Zzero   
//exec.mainform.sumoffsetcontrol1.G56.newCzinput(CombinedOffset);  // Set G56 to new Zzero
//exec.mainform.sumoffsetcontrol1.G57.newCzinput(CombinedOffset);  // Set G57 to new Zzero
//exec.mainform.sumoffsetcontrol1.G58.newCzinput(CombinedOffset);  // Set G58 to new Zzero
//exec.mainform.sumoffsetcontrol1.G59.newCzinput(CombinedOffset);  // Set G59 to new Zzero
//probing routine & tool offset complete

//move back & restart motion
exec.Code("G00 G53 Z"+ parkZ); // Move Z up first to park Z position
while(exec.IsMoving()){}
exec.Wait(200);
exec.Code ("M3");  //  restart start
exec.Wait(200);
exec.Code("G00 G53 X"+ Xmachposvariable + " Y"+ Ymachposvariable); // move cutter back to X&Y toolchange position
while(exec.IsMoving()){}
exec.Wait(200);

//reset machine modal, distance mode and work offsets.

exec.Code (" G"+ WorkOffset );// restore G54-G59 work offset
exec.Code (" G"+ originaldistancemode );// restore the distance (G90/G91) mode
exec.Code (" G"+ originalmodalmode );// restore the modal before the toolchange {G0, G1, G2, G3 etc}
if (G68active == 128){  //  check if G68 flag set, if so, restore G68
exec.Code ( "G68 A" + Rx + " B" + Ry + " R" + Angle );
G68active = 0; // clear flag
}
exec.Wait(200);

exec.Code("G00 Z"+ Zposvariable); // move cutter back to Z toolchange position
while(exec.IsMoving()){}
exec.Wait(200);
//return to where we left off at the start of the toolchange


I only changed it from line 29-38 and then from 105-108 and I removed the line you had for exec.Code(G69);
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M6

Postby Robertspark » Tue Dec 04, 2018 11:44 am

One thing you probably want to be aware of......

That macro depends upon AS3.Getfield(877) to obtain the current active work offset (G54-G59).

This part of the macro depends upon splitting Activemodal (field 877) into an array.

At this time the array looks as follows:
G0|G17|G40|G50|G54|G64|G69|G90|G98
which translates to:
motion modal|workplane|tool compensation|scale|velocity mode|rotation|distance mode|canned cycle return.

The array puts each of these values into a location, starting at [0] = motion modal (G0, G1, G2, G3 etc)

If the stack changes in the future..... and something is added then this "may" affect your macro.

(I have recommended defining these as individual fields in the past but its been muted given the data can be extracted by other means from field 877)

Such as for instance if G93 is added, then G95 will probably appear in the string too.... making the string a little longer.

Longer is not a problem, just if the stack is changed / increased above (before)array position [4] which is where we check and reset the work co-ordinates back to where they were before the toolchange.

Eg, to create your macro, I used the following thread as the basis of how to parse the 877 field.....
The catch is if you run this code now you find that G68/69 for which this script was created {not required any more as we have a defined function} was in array postition [3] which is now [5] because tool compensation has been added (G40/G41/G42) and also something else was probably added (scale factors?? I can't remember)..... the thing is the stack got longer.
viewtopic.php?f=11&t=644&p=4596&hilit=activemodal#p4596
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 5 guests