Link to us from your website and promote the community!... Then email us to receive a Free CNC cheat sheet from the CNC Specialty Store!

Facebook Group

Share your CNC information?
...Macro programs
...and more

Suggestions or comments?
Please Email Us

Thank you for all your contributions and supporting the CNC community.

Beginning your Fanuc NC program with safety code. How do you begin writing all your machine tool programs?

The greatest majority of crashes are a result of improper programming or programming that could eliminate the chance of operators making mistakes. CNC programmers often forget about Modal M-codes. They are often left active and are not canceled within the program. What happens if an operator punches a wrong code into MDI like G18 and then starts up the program? If there was no G17 in their program then they are in trouble. I have seen this happen many times.
Often times it is difficult to determine reasoning behind a crash. One reason is when a crash happens the machine is powered down until someone inspects and troubleshoots what has happened. If powered down however; all the modal M-codes are reset back to default settings on power up and is not easily traceable to the operator. I can not tell you how many times I have heard it just take off running a normal proven program. This safety code is likely the answer as long as your operator was not lying to you.

Here is an example safety code that is used on Fanuc controls. Machine tool builder and various machine models will differ. So check with the OEM or distributer for proper format, if you need to figure them out yourself. The state at which you generally want to attain is when the machine is initially powered up. What you need to do is figure out which ones are modal and put them in your first few lines. Here is an example of a program. Lathes and machining centers may vary.

Important note:Many machine tools have limitations as to how many G or M-codes you may have in one line.
One way to eliminate putting in all of these lines is to write a macro program and place the beginning code in the macro. That way only one Code will need to be placed in each program to call all the functions.

Example Program with safety code

  1. O1000
  2. (Start of safety code)
  3. G20 G17 G40 (G20 inch/G21 Metric, XY plane, cancel cutter compensation)
  4. G49 G64 G80 (Cancel tool length compensation, normal cutting mode, cancel canned cycles)
  5. G90 G94 G98 (absolute mode, feed per minute, initial plane for canned cycles)
  6. (end of safety code)

Program safe postion

  1. G91G30X0.Y0.Z0. (Start at home position)
  2. N1 (describe tool)
  3. T1 M6
  4. G0 G90 G54 X-position Y-Position
  5. M3S1000T2
  6. (Rest of NC Program)

M30 (End program)

CNC programming safety code and causes for crashes. How to avoid improper G-code and NC programming mistakes.