Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

Choice of spindle start/stop codes


dmaier
 Share

Recommended Posts

We have two KIAs that have two different spindle start codes. 
1. M03 - Spindle start forward.
2. M13 - Spindle start forward with coolant flood on.

Same goes for spindle stop.
1. M05 - Spindle stop
2. M15 - Spindle stop with coolant off.

I was thinking of having two coolant options for Flood to choose from the coolant parameters. The regular flood on-off M08/M09, which wouldn't mess with the spindle on-off code. Then  another flood mode with M13/M15 for the spindle and coolant combined on-off that would ignore the command to post out the M03/M05 when M13/M15 are used. I am looking for some direction on the  simplest way to accomplish this. Any thoughts, ideas, or advice?

Link to comment
Share on other sites

Probably making it more complicated than it needs to be. What's the problem with keeping spindle and coolant commands separate ?

My lathes use M03 for lathe spindle and M13 for live tooling spindle. So you might be doing a lot of post editing to support this on only one machine.....and then you have to remember which post does what......there is a lot to be said for keeping the posts as similar as possible.

Link to comment
Share on other sites

If you wanted to do this, you could probably pull it off by triggering it through Canned Text. Canned Text is the mechanism that controls X Style Coolant. At some point in the Generic Fanuc Post, they also created a separate 'pcool1' (or something like that, I can't remember the exact spelling), Post Block.

All of the Canned Text mechanisms (pcan, pcan1, pcan2) end up calling 'pcant_out'. That is the block where you can "capture" the value.

I would setup a "cool_with_spindle" as a separate X-Style coolant option.

I would "trigger" it as a "before" option (pcan), so you can get the setting "before" the tool change takes place. In 'pcant_out', I would "detect" that you've turned on the option, but instead of "building an M-code string", (which is normally what "canned text" does...), I would set a "flag" variable. (Something like 'spin_w_cool')

Then, in the Tool Change (psof$, ptlchg$, ptlchg0$), I would setup some logic to test 'spin_w_cool', and "if true", I would use the "slin" and "slout" functions to "swap" the strings in the String List. This is a fairly advanced use of the tools in MP. Basically, you are "reading through the list of Strings" in MP's memory stack, and when you find the "Index" string, you go + or - from that location to find the string you are searching for. You can either "pull" a string out of the list, or "write" a new String in it's place.

I would set the logic to always update the Strings, with an If/Else. That way the strings are M03/M04 if the variable is zero, and M13/M14 if the variable is one. Pretty simple to build that bit of logic into a user-defined Post Block, and just call it at the start of each Tool Change event. Just make sure you call it after the call to 'pcan', but before the output line where the Spindle comes out...

 

 

  • Like 1
Link to comment
Share on other sites

I am having some issues understanding the slin/slout function. I found an example with slin on https://www.emastercam.com/forums/topic/72321-help-modifying-my-mill-post/ but do not see any example of slout being used to pull information. I found the formula example in the reference guide s=slout(n, base_string).  I have X style coolant commands turned on with the fifth coolant line down containing spindle w/ coolant options M13/M15 (on/off). I created a string spin_with_cool  and am using that as the "s" variable. I have pcant_out set as the base_string variable. Not sure what to put in for the "n" variable. spin_with_cool=slout(pcant_out). The slout definition says base_string is a string in array. Should I be using scoolantx instead of pcant_out for a base string? From what I am understanding this formula as, if using scoolantx for a base string then 9 is the number for the "n' variable because smcool58 is ninth down in the list  for coolant 5 on that would contain my M13 code. 

Link to comment
Share on other sites

You're on the right track, but need to update some areas of understanding about what is going on.

'pcant_out' is not a variable. It is a Post Block. Like a Subroutine on a CNC control. You "jump" to the block of code by putting the name of the Post Block as a single 'post line', or as part of an output statement.

'pcant_out' will get called as part of the jump (call) to 'pcan', 'pcan1', and 'pcan2'.

You aren't outputting a coolant mode, you are setting a 'flag' variable to track if coolant and spindle should be output tovether. So in the Post Lines, of the 'pcant_out' Post Block, you would add logic to test if the 5th coolant command has been activated.

There, inside 'pcant_out', you could use 'slin' to essentially "replace" the M03 and M04 strings. This doesn't output anything yet. It just changes the internal strings inside the String Select table.

All of the Variables in MP, both String Variables and Numeric Variables are held in Memory as a List of Variables.

There is a List of Strings, and a List of Numeric Variables. Each list is a 1 dimensional array of variables.

The name of a variable in both the 'slin' and 'slout' functions is the Index, or "entry point" into that list.

So you don't want to mess with the X Coolant strings at all. You want to swap out the Spindle Forward, and Spindle Reverse strings. Search for "M03" in your Post. It should be part of a String Select table.

Basically the Canned Text mechanism is being used to "swap out" strings in the String List, and the normal "spindle on" mechanism will now output M13, instead of M03.

The key with what we are doing is to use the existing structure of the Post to leave all the existing logic in place, and operational, instead of "brute forcing" the output.

Link to comment
Share on other sites

I thought I had this down but it looks like I am still not doing this correctly. One of my mistakes came by defining the string value with "M13" (my desired output)  instead of a blank "". This forced my statement to be true triggering the code swap(that part works great). So what I can tell I am not pulling a value into the string from my slin line.  Here is what I have.

spinwithcool : ""
spinwithcool = slin(9, scoolantx)

I am not getting the coolant code to save into the spinwithcool string. So I'm guessing 9, scoolantx is not what outputs my M13 code. I see cant_pos and cantext$ within the pcant lists 1-20, and cantext$ is referenced in the pcant_out block. Should I be using these with a vlin instead of slin? I tried that as well with no luck pulling anything into the spinwithcool string.  There is a line in the pcant_out block turning cantext$ into a string.

strtextno = no2str(cantext$)

I tried playing with strtextno instead of scoolantx in my slin line. I am running out of ideas. I'm not sure if I'm using the wrong string which has my value, if I am using slin incorrectly or both.

 

 

 

Link to comment
Share on other sites

You should not be using 'scoolantx' with 'slin'. You want to swap out the 'spindle' codes, not the 'coolant codes'.

This means you need to define "4 unique Strings", and inside 'pcant_out', you either load 'M03' and 'M04' or 'M13' and 'M14' into the Spindle Strings, based on the Coolant Setting.

Your logic isn't going to "output" any codes. It just "swaps the strings". The regular logic that outputs M03/M04 will now output the new strings, or the normal strings auto-magically for you.

Once I work out the correct logic, I'll post the solution in this thread...

  • Like 1
Link to comment
Share on other sites
Well I gave up on trying to understand the slin/slout functions for now. Gonna wait to see what Colin comes up with. I just could not figure them out without seeing an example of working code. I haven't found an issue yet while testing this out and it might not be the correct way to go about this, but I was able to accomplish what I was trying to do with the spindle code swap.  I created the following strings.
 
# Spindle with coolant strings
sm03_1    : "M03"      #Spindle forward
sm05_1    : "M05"      #Spindle off    
sm13_1    : "M13"      #Spindle forward
sm15_1    : "M15"      #Spindle off
spincoolcheck : ""     #Holds active coolant code
 
At the end of the pcant_out post block I added a statement to capture the coolant code.
 
pcant_out       #Canned text - build the string for output
   #Assign string select type outputs
      if cant_pos < three, #cant_pos indicates canned text output
        [
        if cantext$ = three, bld = one
        if cantext$ = four, bld = zero
        #Build the cantext string
        if cantext$ = one, strcantext = strcantext + sm00
        if cantext$ = two, strcantext = strcantext + sm01
        if cantext$ = five, strcantext = strcantext + scant5
        if cantext$ > five,
          [
          strtextno = no2str(cantext$)
          strcantext = strcantext + strm + strtextno
          ]
        ]
      else, #cant_pos indicates coolant output
        [
        coolant_bin = flook (two, cantext$) #Create binary value for each coolant using lookup table
        if frac(cantext$/two),
          [
          if all_cool_off,
            [
            if coolant_on, pbld, n$, *sall_cool_off, e$
            coolant_on = zero
            suppress = 1               #WBT added this for null toolchange with "First command shuts all off"
                                       #and turn off selected in the second op, post outputs M9 twice            
            ]
          else, coolant_on = coolant_on - coolant_bin/2 #Odd = off command, subtract appropriate binary value.
          ]
        else,                                         #Even = on command
          [   #Determine if this coolant is already on
          local_int = zero
          coolantx = zero
          while local_int < 20,
            [
            result2 = and(2^local_int, coolant_on)
            local_int = local_int + one
            if result2 = coolant_bin, suppress = one
            ]
          ]
        if suppress <> 1, #Don't output an on code for a coolant that is already on
          [
          if not(frac(cantext$/two)), coolant_on = coolant_on + coolant_bin #Maintain binary sum of all coolants currently on
          coolantx = cantext$ - 50                                          #Create a coolantx value for string select
          pbld, n$, *scoolantx, spincoolcheck = scoolantx, e$
          ]
        suppress = zero
        ]
 
 
I created a post block to define the new spindle codes when the M13 coolant code is activated.

pspinwcool 
      if  spincoolcheck = scool58,
           [
           sm03 = sm13_1
           sm05 = sm15_1
           ]
     else,
           [
           sm03 = sm03_1
          sm05 = sm05_1
           ]

  
Then finally I inserted my post block into the spindle out post blocks.
 
pspindleout     #Spindle speed and M code output 
 
      if not((opcode$ = 3 | opcode$ = 16) & nextdc$ = 3 & rigid_tap), speed, pspinwcool, spindle
pfspindleout     #Spindle speed and M code output forced   
      if not((opcode$ = 3 | opcode$ = 16) & nextdc$ = 3 & rigid_tap), *speed, pspinwcool, *spindle
 
Now I that I have the x style coolant codes replacing the spindle codes I just need to suppress the on/off (M13/M15) coolant codes themselves from posting when M13 is used as a spindle code so they do not post twice.  I might be able to use slin/slout for this. Most of my attempts at using this function gave me blank or unwanted results. But what do you expect from a guy that doen't understand the proper use of those functions. LOL. Joking aside it will still be nice to understand the slin/slout functions to scratch my itch of curiosity and create cleaner code.
 
 
 
 
 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...