Improved handling of Manual NC commands

Improved handling of Manual NC commands

bob.schultz
Alumni Alumni
2,399 Views
10 Replies
Message 1 of 11

Improved handling of Manual NC commands

bob.schultz
Alumni
Alumni

The new entry function onManualNC has been added to the post processor kernel in the latest version of Fusion, allowing for a single point of entry for handling Manual NC commands.  When the onManualNC function is defined in your post processor, this function will be called for all Manual NC commands, rather than the method of calling different entry functions (onCommand, onPassthrough, onParameter, etc.).  If this function is not defined, then the standard method will be used, as it currently is in all generic post processors, so existing post processors do not have to be updated.

 

A helper function, expandManualNC, has also been added.  This function is not defined in the post processor, but rather is called to process a Manual NC command using the standard methods as described above.  Both of these functions are passed the command and value for the Manual NC command.

function onManualNC(command, value)
expandManualNC(command, value)

The following example shows how the Display message Manual NC command can be processed in the onManualNC function and all other commands in their normal functions.

function onManualNC(command, value) {
  switch (command) {
  case COMMAND_DISPLAY_MESSAGE: // prepend ‘MSG,’ to operator messages
    writeComment("MSG, " + value);
    break;
  default:
    expandManualNC(command, value);  // normal processing of Manual NC command
  }
}

Another benefit of these functions is the ability to buffer the Manual NC commands and output them wherever you desire in the program, rather than always prior to the onSection call.  You do this by adding the following code to your post processor.

/**
  Buffer Manual NC commands for processing later
*/
var manualNC = [];
function onManualNC(command, value) {
  manualNC.push({command:command, value:value});
}

/**
  Processes the Manual NC commands
  Pass the desired command to process or leave argument list blank to process all buffered commands
*/
function executeManualNC(command) {
  for (var i = 0; i < manualNC.length; ++i) {
    if (!command || (command == manualNC[i].command)) {
      switch(manualNC[i].command) {
     /* case COMMAND_DISPLAY_MESSAGE: // sample on explicit execution of Manual NC command
        writeComment("MSG, " + manualNC[i].value);
        break;*/
      default:
        expandManualNC(manualNC[i].command, manualNC[i].value);
      }
    }
  }
  for (var i = 0; i < manualNC.length; ++i) {
    if (!command || (command == manualNC[i].command)) {
      manualNC.splice(i, 1);
    }
  }
}

You can now call the executeManualNC command wherever you want the Manual NC commands to be output, simply by calling it with a parameter to specify which command you want processed at this time, or with a blank argument to process all buffered Manual NC commands.  The following example will output the Display message command prior to the tool change block and all other commands after the tool change block.

    executeManualNC(COMMAND_DISPLAY_MESSAGE);  // display Manual NC messages
    writeBlock("T" + toolFormat.format(tool.number), mFormat.format(6));
    if (tool.comment) {
      writeComment(tool.comment);
    }
    executeManualNC(); // process remaining Manual NC commands


Bob Schultz
Sr. Post Processor Developer

2,400 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable

a good solution.

Can You also make an example with a few "Action" commands with values?

My JS is not very well.

 

Best regards

0 Likes
Message 3 of 11

bob.schultz
Alumni
Alumni

You can find a good example of parsing Action commands, some with values, some without, in the Doosan Mill/Turn post.  Take a look at the onParameter function (all existing posts use the old method of parsing Manual NC commands).

 

You will see a list of supported commands in the comments at the top of the post processor.  Let me know if you have any questions.



Bob Schultz
Sr. Post Processor Developer

0 Likes
Message 4 of 11

Dave_Moxham1
Contributor
Contributor

I'm having trouble getting this to work in the Doosan Mill turn post.

 

I'd like manual NC to post after the machine homes and the M1 at the very end of each section, but also at the beginning if isFirstsection.

 

I have read the other threads on this subject, but I'm still struggling. Can someone help me out please?

 

 

0 Likes
Message 5 of 11

bob.schultz
Alumni
Alumni

You can start with copying the following code into your post.  You can place it between any functions, for example just above the onParameter function.

/**
  Buffer Manual NC commands for processing later
*/
var manualNC = [];
function onManualNC(command, value) {
  manualNC.push({command:command, value:value});
}

/**
  Processes the Manual NC commands
  Pass the desired command to process or leave argument list blank to process all buffered commands
*/
function executeManualNC(command) {
  for (var i = 0; i < manualNC.length; ++i) {
    if (!command || (command == manualNC[i].command)) {
      switch(manualNC[i].command) {
     /* case COMMAND_DISPLAY_MESSAGE: // sample on explicit execution of Manual NC command
        writeComment("MSG, " + manualNC[i].value);
        break;*/
      default:
        expandManualNC(manualNC[i].command, manualNC[i].value);
      }
    }
  }
  for (var i = 0; i < manualNC.length; ++i) {
    if (!command || (command == manualNC[i].command)) {
      manualNC.splice(i, 1);
    }
  }
}

 

Now you will want to add a call to executeManualNC where you want the commands processed.  For example, if you want the commands output after the home position move in the Doosan Mill/Turn post you would place it here.

  // Process Manual NC commands
  executeManualNC();

  // Consider part cutoff as stockTransfer operation
  if (!(machineState.stockTransferIsActive && partCutoff)) {
    machineState.stockTransferIsActive = false;
  }

 The Manual NC commands  will be processed where ever you place this call.



Bob Schultz
Sr. Post Processor Developer

0 Likes
Message 6 of 11

Dave_Moxham1
Contributor
Contributor

Hi Bob,

 

Thank you for your swift reply and I do apologise for making you post that section of code in these forums for what must be the 50th time!

 

I have issues with the pass through text jumbling up.

 

I can't post the part that I'm working on, but I'll model up a test part a bit later to try and demonstrate the issue.

0 Likes
Message 7 of 11

bob.schultz
Alumni
Alumni

No worries, it is easier to post the code again than try to point someone to the correct block of code to include.  For the Pass Through text, here is a sample function that will output multiple lines of text separated by commas.  See if this solves your issue.

function onPassThrough(text) {
  var commands = String(text).split(",");
  for (text in commands) {
    writeBlock(commands[text]);
  }
}


Bob Schultz
Sr. Post Processor Developer

0 Likes
Message 8 of 11

Dave_Moxham1
Contributor
Contributor

Bob, you are the man!

 

Thank you very much.

0 Likes
Message 9 of 11

Dave_Moxham1
Contributor
Contributor
%
O1001
G21
M110
M24
TEST START  *Pass through code as written*
M1          
M2
M3
M4
M5
M6
TEST END    *******************

N1(FACE2)
G0 G28 G53 B0. (SUB SPINDLE RETURN)
G28 U0. V0.
G28 W0.
M90
G54
G99 G18 M34
G50 S2500
T0101
M8
G97 S2465 M3 P11
G0 Z5.5
X90.4 Y0.
G96 S700 M3 P11
Z1.514
X70.4
G1 X63.228 F0.2
X60.4 Z0.1
X-1.8
X1.028 Z1.514
G0 X90.4
Z5.5
G97 S2465 M3 P11
M1  *Some of the Pass Through code has randomly made its way here*
M3  *********
M5  *********
TEST END **********

It seems I'm still having trouble with erratic behaviour.

 

I've attached the post, but I can't share the file that produced this code publicly.

 

I can pm you with the file if you would like to take a look?

 

 

 

 

0 Likes
Message 10 of 11

bob.schultz
Alumni
Alumni

It seems you found an issue with the logic that we need to correct.  You can make the following change in the executeManualNC function to resolve this issue.

  for (var i = manualNC.length -1; i >= 0; --i) { // CHANGE THIS LINE
    if (!command || (command == manualNC[i].command)) {
      manualNC.splice(i, 1);
    }
  }

Walking forward through the array skips every other Manual NC command when removing them from the stack.



Bob Schultz
Sr. Post Processor Developer

Message 11 of 11

Dave_Moxham1
Contributor
Contributor

Thanks Bob.

0 Likes