M6

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

Re: M6

Postby tracar » Tue Dec 04, 2018 2:41 pm

i don't think i will be needing to rotate anything like the big mills, mine is a older wood/soft metal cnc retrofitted with new electronics.
i will test the new M6 out when i get back later today, Thankyou for all the help on this, i have been scouring thru the uccnc documents folder and can see how each line of code does what, but to use it in context , i just dont have anything to reference it to until someone does it for me, Learning is fun :)

Thankoy for all your time on this Rob !!!!
tracar
 
Posts: 39
Joined: Sun Jun 18, 2017 6:37 pm

Re: M6

Postby tracar » Tue Dec 04, 2018 4:23 pm

G68
i dont use or im unaware of how G68 gets active i dont believe i will ever need to use this rotation for probing using G68 in this machine ever. can it be disabled? and the script simplified ?
tracar
 
Posts: 39
Joined: Sun Jun 18, 2017 6:37 pm

Re: M6

Postby Robertspark » Tue Dec 04, 2018 4:42 pm

No G68 code in this one:

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 = 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}
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


G68 is not used for probing, it is just used to rotate the workplane, very useful for repeat operations.

https://www.cnccookbook.com/g68-g69-rot ... nc-g-code/
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M6

Postby tracar » Wed Dec 05, 2018 7:56 am

so what part of the code enables g68?
tracar
 
Posts: 39
Joined: Sun Jun 18, 2017 6:37 pm

Re: M6

Postby Robertspark » Wed Dec 05, 2018 10:28 am

Check if G68 is active and store the current rotation co-ordinates + rotation angle

Code: Select all
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
}


Restore G68 9if it was active {it checks a variable / flag (G68active) to see if it was set with a random integer "128" (I could have set it to anything)}
It then clears the G68active variable.

Code: Select all
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
}
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: M6

Postby thesleepydog » Sun Mar 03, 2019 11:46 am

Robertspark wrote:here you go

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

[code]// "automatic" tool change

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


Sorry for the dumb question... Is this in metric?
thesleepydog
 
Posts: 15
Joined: Sun Mar 03, 2019 11:10 am

Re: M6

Postby cncdrive » Sun Mar 03, 2019 4:29 pm

UCCNC is unitless which means that your profile file settings (steps per units value) define if everything is metric or imperial.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: M6

Postby thesleepydog » Fri Mar 15, 2019 10:17 am

cncdrive wrote:UCCNC is unitless which means that your profile file settings (steps per units value) define if everything is metric or imperial.


So the values in the file are Steps? I am trying to work out if ParkX value in the example file is 1.7 inches / mm or steps? and likewise for parkY = -23 inches/mm/steps?

"double parkZ = 0;
double parkX = 1.7;
double parkY = -23;"
thesleepydog
 
Posts: 15
Joined: Sun Mar 03, 2019 11:10 am

Re: M6

Postby cncdrive » Fri Mar 15, 2019 10:30 am

They are in Units. If your unit is inches then they are inched if your units are millimeters then they are millimeters and if your units are kilometers then kilometers or whatever you defined with the steps per values for Units.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Previous

Return to Macros

Who is online

Users browsing this forum: No registered users and 3 guests