Hi Tom,

I am another member of the team that posted a bug question here:

Problem Bug found on SnampAmp

We are now having issues executing an M6 command while running gcode.

First let me begin by outlying our goal, we want the machine to move to Machine Coordinate 0 upon reaching M6 and to wait for a manual tool change. At this point the operator presses a button which initiates a program that checks the tool size on a plate, adjusts DROs, returns to Working Coordinate 0, and syncs.

Our M6 command runs on exec/wait/sync.
We've tried the M6 execution using variables 8, 86, and 87.

Here is our M6 program:
Code:
#include "CustomDef.h" //this is our def file that includes KMotionDef.h
 
enum {T_IDLE,T_START,T_WAIT_UNCLAMP,T_WAIT_MOVE,T_WAIT_CLAMP};
 
void main()
{
 while(!CheckDone(z_axis) && !CheckDone(y_axis) && !CheckDone(x_axis)); //CheckDoneXYZABC()
 
 *ChangerState = T_START;  //*ChangerState points to persist.UserData[87]
  
  printf("%d","Tool Change Initiated\n");
  gotoZero();
 
//our manually executed Tool Change Code sets *ChangerState to T_IDLE once completed
  while (*ChangerState != T_IDLE)  
  {
   WaitNextTimeSlice();
  }
}
Our gotoZero() function merely contains a Move(axis,0) with a while(!CheckDone(axis)) operation between each move.

The problem we are having seems to be with the 3 second Look Ahead buffering, it executes our M6 code 3 seconds too soon which causes follow errors and disables the axis.

This only happens during the first run:
Click image for larger version. 

Name:	m6 look ahead.jpg 
Views:	2 
Size:	20.0 KB 
ID:	257701

If we return the machine to Working Coordinate 0 and restart the cut it will successfuly run our M6 command with no issue the second time through:
Click image for larger version. 

Name:	m6 second run.jpg 
Views:	2 
Size:	21.0 KB 
ID:	257703

After running through the Gcode a second time we are able to complete the tool change, sync, and continue cutting.

We've tried placing the M6 code inside of an IF statement (see below) which does not allow it to execute unless a button is pushed, however kmotioncnc produces a generic gcode error during the Look Ahead Buffering when it reads the file under these conditions.

Code:
#include "CustomDef.h" //this is our def file that includes KMotionDef.h
 
enum {T_IDLE,T_START,T_WAIT_UNCLAMP,T_WAIT_MOVE,T_WAIT_CLAMP};
 
void main()
{
 while(!CheckDone(z_axis) && !CheckDone(y_axis) && !CheckDone(x_axis));
 
 if(CheckBit(137))
 {
  *ChangerState = T_START;  
  
   printf("%d","Tool Change Initiated\n");
   gotoZero();
 }
 while (*ChangerState != T_IDLE)  
 {
  WaitNextTimeSlice();
 }
}
We've tried placing a 3 second delay in the M6 code to allow the machine to catch up and this allows the M6 code to execute, the machine will go to 0, however kmotionCNC is unable to sync after the tool change.

Lastly we've tried running M6 as a blank file containing only a printf statement and we receive a generic Gcode error from kmotioncnc during the Look Ahead buffering which stops the execution of the code.

We’ve tried various gcode formats with similar results.

I'm assuming we have done something wrong and would appreciate any help to point us in the right direction.

Thanks in advance for you time,

David.