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:

Changing M Codes


Recommended Posts

OK, here is what I am running into. I have 2 brands of machines, Matsuura's and Mori's. Both are horizontals. Both use an almost identical post. I am working on combining them into one post. I have everything worked out except for the clamp codes on the 4th axis.

The Mori uses M10 & M11. The Matsuura uses M21 & M22

I am capturing the machine description from the machine definition, so the post knows if it is running the Matsuura or the Mori. Is there an easy way to get the post to swap out the M codes?

 

 

Link to comment
Share on other sites

Yes.

the String Function 'slin' stands for "String List In". It uses an "index variable" (the variable in your "ordered list of numeric and string variables created by MP), and an "offset" from that index variable, to determine "which string variable" we are editing.

There are some decent examples of how to use the function in the documentation.

smtap   : "G84"
smrigid : "G84.2"


# Canned drill cycle string select
sg81    : "G81"      #drill      - no dwell 
sg81d   : "G82"      #drill      - with dwell 
sg83    : "G83"      #peck drill - no dwell 
sg83d   : "G83"      #peck drill - with dwell 
sg73    : "G73"      #chip break - no dwell 
sg73d   : "G73"      #chip break - with dwell 
sg84    : "G84"      #tap        - right hand
sg84d   : "G74"      #tap        - left hand
sg85    : "G85"      #bore #1    - no dwell 
sg85d   : "G89"      #bore #1    - with dwell 
sg86    : "G86"      #bore #2    - no dwell 
sg86d   : "G86"      #bore #2    - with dwell 
sgm1    : "G76"      #misc #1    - no dwell
sgm1d   : "G76"      #misc #1    - with dwell
sgm2    : "G81"      #misc #2    - no dwell
sgm2d   : "G82"      #misc #2    - with dwell
sgc9    : "G81"      #custom #9  - no dwell
sgc9d   : "G82"      #custom #9  - with dwell
sgdrill : ""         #Target for string

fstrsel sg81 drlgsel sgdrill 18 -1


# --------------------------------------------------------------------------
# Drilling
# --------------------------------------------------------------------------
pdrill0$         #Pre-process before drill call
      sav_dgcode = gcode$ #Capture gcode for 5 axis drill
      #Set correct Tap Code, based on tapping mode
      if rigid_tap, smrigid = slin(sg81, 6)
      else, smtap = slin(sg81, 6)

 

Here is a quick sample I whipped up.

The "slin" function uses that "index" variable (1st parameter), as the starting string, in the Variable List.

The 2nd parameter (6), is the "offset" from the 1st string. This is a "zero-based" index, so an offset of "0", means, replace the string that is listed as the "index" variable.

An offset of "1", means replace the next string, 1 space below the index string.

In our case, "sg84" is 6 variables below "sg81".

I could have also used the following to accomplish the same thing:

smrigid = slin (sg84, 0)

 

 

 

  • Like 2
Link to comment
Share on other sites

Similarly, the function "slout", is used to "retrieve" a string value, from a String Variable, in the ordered list of MP variables.

As an example, if you had enough "temporary string variables" setup in a user-defined (list) array, you could "copy out" all of the string values, in a String Select Table (list), (save them for future use), with "slout". Then you could use "slin" to overwrite all of the existing strings, with new string values. If needed, we could then "restore" all of the original strings, in the string list, using "slin", and writing the "saved" values back to the String Select Table Array.

  • Like 1
Link to comment
Share on other sites

Awesome Colin! That should work nicely.

As far as why I like to keep things in one post....There are a few reasons. Mainly when updating or adding a new feature I only have to do it once, rather than remembering to do it a few times. And since I've been pretty meticulous about documenting what I've done and the changes I've made, it would be reasonably easy for someone else to follow.

  • Like 1
Link to comment
Share on other sites

Colin, just a curiosity here.  Can't you identify the machine in the mach def?  Would it be better, worse or indifferent to do something like:

plock

     if mach = mori, "M70", else "M80"

punlock

     if mach = mori, "M71", else "M80"

Link to comment
Share on other sites

There are some technical differences. In your example, you are just outputting 'String Literals'. This has the effect of divorcing the output of the codes.

What I mean by that, is you should be using a String Select Function for String output; if that output is a "mode" that you need to track the 'state of'.

The beauty of the String Select Function (and the part that amateur post hackers miss), is the SSF "ties" the string output to the Modality of a Numeric variable? 

So what?

Why is that important? Because the magic in the Post is the ability to make decisions based on Boolean Logic.

You can't track a 'M80' String. You can't test it for true/false.

The thing is, if these machine modes were all completely independent, then your method would be just fine.

But by tying the strings to a number, we can now build complex comparisons, to check for multiple conditions.

A good example is High Speed Codes, and Tool Lenth Offsets. Some modes must be turned on before G43, and must remain on until after the G49. Others must be done while TLO is active. We can track the modes through the "current" value of the variable, compared to the "previous" value. Modality is a beautiful thing. 

  • Like 3
Link to comment
Share on other sites

And that is why I asked the master.  I was only thinking in simple lock/unlock codes.  Not as far as any other string value.  Now the "why" here is crystal clear.  You have no idea how much I appreciate the resource you are!

  • Thanks 1
Link to comment
Share on other sites

Also, 'yes', we can get the Machine Name string, along with basically anything in the Machine Definition. Each Tool Change event in the NCI File is preceded by 'preparatory NCI line', that set the values of predefined variables before the tool change. We get the machine and information about the Axis Combination. Axis combos don't do much for us, on a 3X, 4X, or even 5X milling machine. But a Multi-turret or multi-spindle lathe is a good example of where the Axis Combos actually provide some value to us.

  • Like 1
Link to comment
Share on other sites

Just throwing this out there, but If it was me I would not tackle this as a post problem but a machine problem.  I would add M10/M11 to that matsuraas or vice versa.  That way you can use the same exact program for each machine.

If M10 is already taken up then create a new Mcode M110/M111 and Mcode alias it. 

 

I am assuming fanuc control here but, Put 110 in paramter #6021 and make a new program in the library folder O9021

O9021(Universal 4th lock)

M10

M99

 

etc etc etc.  This way everything is automated and you don't have to keep track of machine descriptions.  But whatever floats your boat.

  • Like 1
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...