What order is the M6 read? Also a paid job...

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

What order is the M6 read? Also a paid job...

Postby dimmaz88 » Fri Dec 16, 2022 2:04 pm

Can anyone please explain how a M6 is read please. I'm using a modified stock M6 and if the job calls for the tool that's already in the spindle it doesn't work properly. To get around this I'll request a manual change before starting the job, this way the M6 works properly.


If anyone is willing to help me set this up with safety features I'm willing to pay. I don't have the time to dedicate to learning C# at the moment and I'd like to add air pressure sensors, tool in/out recognition etc...


Here is my code
Code: Select all
//Example linear toolchanger code

//Tool positions definition
int Chuckopenport = 1;
int Chuckopenpin = 14;

double[] ToolX = new double[11];
double[] ToolY = new double[11];
ToolX[0] = 0; // Tool0 X position
ToolY[0] = 0; // Tool0 Y position

ToolX[1] = 1447.14; // Tool1 X position
ToolY[1] = 192; // Tool1 Y position
ToolX[2] = 1447.14; // Tool2 X position
ToolY[2] = 342; // Tool2 Y position
ToolX[3] = 1447.14; // Tool3 X position
ToolY[3] = 492; // Tool3 Y position
ToolX[4] = 1447.14; // Tool4 X position
ToolY[4] = 642; // Tool4 Y position
ToolX[5] = 1447.14; // Tool5 X position
ToolY[5] = 792; // Tool5 Y position
ToolX[6] = 1447.14; // Tool6 X position
ToolY[6] = 942; // Tool6 Y position
ToolX[7] = 1447.14; // Tool7 X position
ToolY[7] = 1092; // Tool7 Y position
ToolX[8] = 1447.14; // Tool8 X position
ToolY[8] = 1242; // Tool8 Y position
ToolX[9] = 1447.14; // Tool9 X position
ToolY[9] = 1392; // Tool9 Y position
ToolX[10] = 1447.14; // Tool10 X position
ToolY[10] = 1542; // Tool10 Y position

double SafeZ = 145;
double pickupSafeZ = 75;
double Ztoolrelease = -61;
double Ztoolpickup = -61;

int Newtool = exec.Getnewtool();
int Currenttool = exec.Getcurrenttool();

if(Newtool == -1) // If new tool number is -1 means a missing T code, so we need to stop here...
return;

if(Newtool <1 || Newtool >10) // Tool number is out of range, so we need to stop here...
return;

if(Newtool == Currenttool) // Same tool was selected, so do nothing, stop here...
return;

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, do homing before executing a tool change!");
  exec.Stop();
  return;
}

while(exec.IsMoving()){}

// Get current XY machine coordinates to return to this position at the end of the macro

double Xoriginalpos = exec.GetXmachpos();
double Yoriginalpos = exec.GetYmachpos();

// Stop spindle if running and Move Z up

exec.Stopspin();
exec.Code("G00 G53 Z"+ SafeZ);          // Move Z up safe
while(exec.IsMoving()){}

if(Currenttool!=0) // No need to drop down tool if current tool number is zero
{
  // Move to old tool position on XY plane

  exec.Code("G00 G53 Y" + ToolY[Currenttool]);
  exec.Code("G00 G53 X" + ToolX[Currenttool]);
  while(exec.IsMoving()){}

  // Drop current tool
 
  exec.Code("G00 G53 Z"+ Ztoolrelease); // Move Z axis down to tool holder position
  while(exec.IsMoving()){}
  exec.Setoutpin(Chuckopenport, Chuckopenpin); // Open the chuck with pneumatic valve
  exec.Wait(1000); // Wait one 1000msec
  exec.Code("G00 G53 Z"+ pickupSafeZ); // Move Z up
  exec.Clroutpin(Chuckopenport, Chuckopenpin);      // added solenoid close
  while(exec.IsMoving()){}
}

// Move to new tool position on XY plane    
exec.Code("G00 G53 X" + ToolX[Newtool] + " Y" + ToolY[Newtool]);
while(exec.IsMoving()){}


// Pick new tool

exec.Setoutpin(Chuckopenport, Chuckopenpin);    //added solenoid open
exec.Code("G00 G53 Z"+ Ztoolpickup); // Move Z axis down to tool holder position
while(exec.IsMoving()){}
exec.Clroutpin(Chuckopenport, Chuckopenpin); // Close the chuck with pneumatic valve
exec.Wait(1000); // Wait one 1000msec
exec.Code("G00 G53 Z"+ SafeZ); // Move Z up
while(exec.IsMoving()){}


// Move back to start point

//exec.Code("G00 G53 X" + Xoriginalpos + " Y" + Yoriginalpos);
while(exec.IsMoving()){}

// Measure new tool will go here....

exec.Code("G43 H"+Newtool); // Load new tool offset

exec.Wait(200);
while(exec.IsMoving()){}
if(!exec.Ismacrostopped()) // If tool change was not interrupted with a stop only then validate new tool number
{
 
exec.Setcurrenttool(Newtool); //Set the current tool -> the new tool
exec.Writekey("LastTool", "ToolNumber", Newtool.ToString()); // Save tool number
 
  //MessageBox.Show("Tool change done.");
}
else
{
  exec.StopWithDeccel();
  MessageBox.Show("Tool change was interrupted by user!");
}


dimmaz88
 
Posts: 27
Joined: Mon Jun 13, 2022 9:22 am

Re: What order is the M6 read? Also a paid job...

Postby ger21 » Fri Dec 16, 2022 3:22 pm

Code: Select all
if(Newtool == Currenttool) // Same tool was selected, so do nothing, stop here...
{
exec.Stop();
return;
}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: What order is the M6 read? Also a paid job...

Postby dimmaz88 » Fri Dec 16, 2022 8:00 pm

Hi Gerry, I was aware of this line but I'm not sure why it doesn't behave properly.

If I run it with the tool already in it will add the offset again doubling it up.
dimmaz88
 
Posts: 27
Joined: Mon Jun 13, 2022 9:22 am

Re: What order is the M6 read? Also a paid job...

Postby dimmaz88 » Fri Dec 16, 2022 8:10 pm

Sorry Gerry I missed that you'd added an extra line, my friend just pointed out out. I'll give it a try on Monday.

How does that command change things?
dimmaz88
 
Posts: 27
Joined: Mon Jun 13, 2022 9:22 am

Re: What order is the M6 read? Also a paid job...

Postby ger21 » Sat Dec 17, 2022 1:39 am

Deleted due to wrong information.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: What order is the M6 read? Also a paid job...

Postby fsli » Sat Dec 17, 2022 12:53 pm

ger21 wrote:It stops the macro. You have comments saying "stop here", but nothing to actually stop anything. You need to add that line in all your if...then;s that check for errors.

Since the return exits from the macro, and the exec.Stop is documented as stopping motion (not for stopping a macro), I don't understand how adding exec.Stop would change anything.

I also don't see anything in the macro that would create the condition which dimmaz reported: the offset being doubled when the tool hasn't changed. My suspicion would be that there's another macro that gets executed after the M6, or the M6 is being called from within some other macro.

I'll add, though, that I'm not clear on whether the only problem being reported is that the offset is doubled, or if there's some other reason to suspect this M6 is creating some other issue.
Frank
fsli
 
Posts: 97
Joined: Mon Jul 11, 2022 12:36 am

Re: What order is the M6 read? Also a paid job...

Postby dimmaz88 » Sun Dec 18, 2022 4:29 pm

Thank you both.

Could this potentially be a conflict with my G-code and the M6? I don't have any code with me, but I'll post some tomorrow.

It's been a while since we edited this M6 so we're unsure of what we did. Initially the offsets didn't work at all, each tool change would result in the tool lengths being added up. We added something that first cleared the offset, and once it changed to tool it added on the new offset. I just can't remember what we did, and can't find anything in there that does this, albeit I have very little programming knowledge.
dimmaz88
 
Posts: 27
Joined: Mon Jun 13, 2022 9:22 am

Re: What order is the M6 read? Also a paid job...

Postby dimmaz88 » Mon Dec 19, 2022 8:54 am

I've just tested the machine, and if I load a job that calls for the tool that's already in the spindle it adds on the tool offset. Which would result in the tool being plunged into the work.

I added an exec.stop like Gerry said but all that does is stop the job all together. I'll upload my G-code to see if that's a potential issue..

Code: Select all
( bezels )
( File created: Sunday October 23 2022 - 05:44 PM)
( for Mach2/3 from Vectric )
( Material Size)
( X= 1220.000, Y= 2440.000 ,Z= 12.000)
()
(Toolpaths used in this file:)
(Profile 2)
(Profile 3)
(Profile 3 [1])
(Profile 3 [2])
(Tools used in this file: )
(1 = End Mill {3.175 mm} Foamex)
N130G00G21G17G90G40G49G80
N140G71G91.1
N150T1M06
N160 (End Mill {3.175 mm} Foamex)
N170G00G43Z37.010H1
N180S12000M03
N190(Toolpath:- Profile 2)
N200()
N210G94
N220X0.000Y0.000F2000.0
N230G00X50.088Y197.632Z37.000
N240G1X50.088Y197.632Z12.000F2000.0
N250G1X50.088Y247.632Z0.000
N260G1X50.088Y340.288Z0.000
N270G1X50.088Y340.288Z3.000
N280G1X50.088Y358.463Z3.000
N290G1X50.088Y358.463Z0.000
N300G1X50.088Y494.457Z0.000
N310G1X571.912Y494.457Z0.000
N320G1X571.912Y358.463Z0.000
N330G1X571.912Y358.463Z3.000
N340G1X571.912Y340.288Z3.000
N350G1X571.912Y340.288Z0.000
N360G1X571.912Y197.632Z0.000
N370G1X50.088Y197.632Z0.000
N380G1X50.088Y247.632Z0.000
N390G00X50.088Y247.632Z37.000
N400G00X648.088Y197.632Z37.000
N410G1X648.088Y197.632Z12.000F2000.0
N420G1X648.088Y247.632Z0.000
N430G1X648.088Y340.288Z0.000
N440G1X648.088Y340.288Z3.000
N450G1X648.088Y358.463Z3.000
N460G1X648.088Y358.463Z0.000
N470G1X648.088Y494.457Z0.000
N480G1X1169.912Y494.457Z0.000
N490G1X1169.912Y349.914Z0.000
N500G1X1169.912Y349.914Z3.000
N510G1X1169.912Y331.739Z3.000
N520G1X1169.912Y331.739Z0.000
N530G1X1169.912Y197.632Z0.000
N540G1X648.088Y197.632Z0.000
N550G1X648.088Y247.632Z0.000
N560G00X648.088Y247.632Z37.000
N570G00X648.088Y798.632Z37.000
N580G1X648.088Y798.632Z12.000F2000.0
N590G1X648.088Y848.632Z0.000
N600G1X648.088Y915.955Z0.000
N610G1X648.088Y915.955Z3.000
N620G1X648.088Y934.130Z3.000
N630G1X648.088Y934.130Z0.000
N640G1X648.088Y1095.457Z0.000
N650G1X1169.912Y1095.457Z0.000
N660G1X1169.912Y934.130Z0.000
N670G1X1169.912Y934.130Z3.000
N680G1X1169.912Y915.955Z3.000
N690G1X1169.912Y915.955Z0.000
N700G1X1169.912Y798.632Z0.000
N710G1X648.088Y798.632Z0.000
N720G1X648.088Y848.632Z0.000
N730G00X648.088Y848.632Z37.000
N740G00X571.912Y798.632Z37.000
N750G1X571.912Y798.632Z12.000F2000.0
N760G1X521.912Y798.632Z0.000
N770G1X50.088Y798.632Z0.000
N780G1X50.088Y913.105Z0.000
N790G1X50.088Y913.105Z3.000
N800G1X50.088Y931.280Z3.000
N810G1X50.088Y931.280Z0.000
N820G1X50.088Y1095.457Z0.000
N830G1X571.912Y1095.457Z0.000
N840G1X571.912Y936.980Z0.000
N850G1X571.912Y936.980Z3.000
N860G1X571.912Y918.805Z3.000
N870G1X571.912Y918.805Z0.000
N880G1X571.912Y798.632Z0.000
N890G1X521.912Y798.632Z0.000
N900G00X521.912Y798.632Z37.000
N910G00X571.912Y1399.632Z37.000
N920G1X571.912Y1399.632Z12.000F2000.0
N930G1X521.912Y1399.632Z0.000
N940G1X50.088Y1399.632Z0.000
N950G1X50.088Y1494.471Z0.000
N960G1X50.088Y1494.471Z3.000
N970G1X50.088Y1512.646Z3.000
N980G1X50.088Y1512.646Z0.000
N990G1X50.088Y1696.457Z0.000
N1000G1X571.912Y1696.457Z0.000
N1010G1X571.912Y1529.745Z0.000
N1020G1X571.912Y1529.745Z3.000
N1030G1X571.912Y1511.570Z3.000
N1040G1X571.912Y1511.570Z0.000
N1050G1X571.912Y1399.632Z0.000
N1060G1X521.912Y1399.632Z0.000
N1070G00X521.912Y1399.632Z37.000
N1080G00X648.088Y1399.632Z37.000
N1090G1X648.088Y1399.632Z12.000F2000.0
N1100G1X648.088Y1449.632Z0.000
N1110G1X648.088Y1511.570Z0.000
N1120G1X648.088Y1511.570Z3.000
N1130G1X648.088Y1529.745Z3.000
N1140G1X648.088Y1529.745Z0.000
N1150G1X648.088Y1696.457Z0.000
N1160G1X1169.912Y1696.457Z0.000
N1170G1X1169.912Y1518.346Z0.000
N1180G1X1169.912Y1518.346Z3.000
N1190G1X1169.912Y1500.171Z3.000
N1200G1X1169.912Y1500.171Z0.000
N1210G1X1169.912Y1399.632Z0.000
N1220G1X648.088Y1399.632Z0.000
N1230G1X648.088Y1449.632Z0.000
N1240G00X648.088Y1449.632Z37.000
N1250G00X648.088Y2000.632Z37.000
N1260G1X648.088Y2000.632Z12.000F2000.0
N1270G1X648.088Y2050.632Z0.000
N1280G1X648.088Y2235.427Z0.000
N1290G1X648.088Y2235.427Z3.000
N1300G1X648.088Y2253.603Z3.000
N1310G1X648.088Y2253.603Z0.000
N1320G1X648.088Y2297.457Z0.000
N1330G1X1169.912Y2297.457Z0.000
N1340G1X1169.912Y2239.353Z0.000
N1350G1X1169.912Y2239.353Z3.000
N1360G1X1169.912Y2221.178Z3.000
N1370G1X1169.912Y2221.178Z0.000
N1380G1X1169.912Y2000.632Z0.000
N1390G1X648.088Y2000.632Z0.000
N1400G1X648.088Y2050.632Z0.000
N1410G00X648.088Y2050.632Z37.000
N1420G00X571.912Y2000.632Z37.000
N1430G1X571.912Y2000.632Z12.000F2000.0
N1440G1X521.912Y2000.632Z0.000
N1450G1X50.088Y2000.632Z0.000
N1460G1X50.088Y2241.127Z0.000
N1470G1X50.088Y2241.127Z3.000
N1480G1X50.088Y2259.302Z3.000
N1490G1X50.088Y2259.302Z0.000
N1500G1X50.088Y2297.457Z0.000
N1510G1X571.912Y2297.457Z0.000
N1520G1X571.912Y2253.603Z0.000
N1530G1X571.912Y2253.603Z3.000
N1540G1X571.912Y2235.427Z3.000
N1550G1X571.912Y2235.427Z0.000
N1560G1X571.912Y2000.632Z0.000
N1570G1X521.912Y2000.632Z0.000
N1580G00X521.912Y2000.632Z37.000
N1590S12000M03
(Profile 3)
()
N1620G00X12.000Y14.544Z37.000
N1630G1X12.000Y14.544Z0.000F2000.0
N1640G1X1208.000Y14.544Z0.000
N1650G1X1208.000Y2418.544Z0.000
N1660G1X12.000Y2418.544Z0.000
N1670G1X12.000Y14.544Z0.000
N1680G00X12.000Y14.544Z37.000
N1690S12000M03
(Profile 3 [1])
()
N1720G00X610.000Y2427.322Z37.000
N1730G1X610.000Y2427.322Z0.000F2000.0
N1740G1X610.000Y12.522Z0.000
N1750G00X610.000Y12.522Z37.000
N1760S12000M03
(Profile 3 [2])
()
N1790G00X9.507Y615.544Z37.000
N1800G1X9.507Y615.544Z0.000F2000.0
N1810G1X1210.507Y615.544Z0.000
N1820G00X1210.507Y615.544Z37.000
N1830G00X1209.238Y1216.544Z37.000
N1840G1X1209.238Y1216.544Z0.000F2000.0
N1850G1X10.738Y1216.544Z0.000
N1860G00X10.738Y1216.544Z37.000
N1870G00X10.059Y1817.544Z37.000
N1880G1X10.059Y1817.544Z0.000F2000.0
N1890G1X1210.059Y1817.544Z0.000
N1900G00X1210.059Y1817.544Z37.000
N1910G00Z37.010
N1920G00X0.000Y0.000
N1930M09
N1940M30
%
dimmaz88
 
Posts: 27
Joined: Mon Jun 13, 2022 9:22 am

Re: What order is the M6 read? Also a paid job...

Postby dimmaz88 » Mon Dec 19, 2022 9:31 am

I think I've figured it out, after the M6 line in the g-code there's a G43. I've deleted that and it now works, although I had one attempt that added on the offset again but I can't replicate it now.

I'll use it today and see how it performs.

Am I right in thinking that there should be no tool offset commands in the g-code if using a M6 macro?
dimmaz88
 
Posts: 27
Joined: Mon Jun 13, 2022 9:22 am

Re: What order is the M6 read? Also a paid job...

Postby dimmaz88 » Mon Dec 19, 2022 11:51 am

Please ignore that last reply, I was using an old post processor, I've actually deleted the G43 command out of it since.

Still having the same issue ☹
dimmaz88
 
Posts: 27
Joined: Mon Jun 13, 2022 9:22 am

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 17 guests