This repository contains comprehensive documentation of G-Code and M-Code commands used in CNC programming. G-Code is primarily used to control CNC machines, while M-Code is used for miscellaneous functions. This documentation aims to provide clear explanations and examples of each command, helping users understand and use them effectively.
Warning: This documentation is valid only for CNC lathes. Verify compatibility with your specific CNC machine before use. Commands and their behavior may vary depending on the machine's configuration and capabilities.
| Gcode | Function | Explanation | Example | Modal |
|---|---|---|---|---|
| G00 | Rapid positioning | Fast axis movement for positioning (18 m/min X, 24 m/min Z) | G00 X50 Z80; | Yes |
| G01 | Linear interpolation | Straight-line movement with programmed feed rate | G01 X50 Z30 F0.2; | Yes |
| G02 | Circular interpolation | Clockwise circular arc (use R or I/K) | G02 X60 Z20 R10 F0.1; | Yes |
| G03 | Circular interpolation | Counterclockwise circular arc (use R or I/K) | G03 X60 Z20 I10 K0 F0.1; | Yes |
| G04 | Dwell time | Programmed pause (X/U in seconds, P in milliseconds) | G04 X1.5; (1.5 seconds) | No |
| G20 | Inch units | Program in inches | G20; | Yes |
| G21 | Metric units | Program in millimeters | G21; | Yes |
| G28 | Return to reference | Returns axes to machine reference point | G28; | No |
| G33 | Threading | Step-by-step threading cycle | G33 Z50 F1.5; (1.5mm pitch) | Yes |
| G40 | Radius cancellation | Cancels tool radius compensation | G40; | Yes |
| G41 | Left compensation | Activates left-side radius compensation | G41; | Yes |
| G42 | Right compensation | Activates right-side radius compensation | G42; | Yes |
| G54 | Work coordinate system | Selects workpiece coordinate system 1 | G54; | Yes |
| G55 | Work coordinate system | Selects workpiece coordinate system 2 | G55; | Yes |
| G63 | Tool zeroing | Semi-automatic zeroing with position sensor (Tool Eye) | G63 T01 A03; | No |
| G70 | Finishing cycle | Finishing cycle after roughing | G70 P100 Q200; | No |
| G71 | Longitudinal roughing | Automatic roughing cycle along the Z-axis | G71 U2.5 R1; G71 P100 Q200 U0.5 W0.2 F0.3; | Yes |
| G72 | Facing roughing | Automatic roughing cycle along the X-axis | G72 W2.5 R1; G72 P100 Q200 U0.5 W0.2 F0.3; | Yes |
| G73 | Pattern repeating | Roughing cycle parallel to final profile | G73 U5 W5 R3; G73 P100 Q200 U0.5 W0.2 F0.3; | Yes |
| G74 | Peck drilling/Turning | Peck drilling cycle (G74 R_; G74 Z_ Q_ F_) or turning | G74 Z-20 Q5000 F0.1; | Yes |
| G75 | Grooving/Facing | Grooving cycle (G75 R_; G75 X_ Z_ P_ Q_ F_) or facing | G75 X50 Z-10 P2000 Q10000 F0.1; | Yes |
| G76 | Threading cycle | Complete threading cycle | G76 P010060 Q100 R0.05; G76 X28.05 Z-30 P974 Q500 F1.5; | Yes |
| G90 | Absolute coordinates | Absolute coordinate system | G90; | Yes |
| G91 | Incremental coordinates | Incremental coordinate system | G91; | Yes |
| G92 | RPM limit | Sets maximum RPM limit | G92 S2000; | Yes |
| G94 | Feed per minute | Feed rate in mm/minute | G94 F100; | Yes |
| G95 | Feed per revolution | Feed rate in mm/revolution (default for lathes) | G95 F0.2; | Yes |
| G96 | Constant surface speed | Activates constant cutting speed (S in m/min) | G96 S200; | Yes |
| G97 | Fixed RPM | Cancels constant speed, returns to fixed RPM | G97 S1000; | Yes |
| Mcode | Function | Explanation | Example |
|---|---|---|---|
| M00 | Program stop | Immediate program interruption | M00; |
| M01 | Optional stop | Conditional interruption (activated by operator) | M01; |
| M02 | Program end | Ends program without returning to start | M02; |
| M03 | Spindle CW | Spindle rotation clockwise | M03 S1000; |
| M04 | Spindle CCW | Spindle rotation counterclockwise | M04 S800; |
| M05 | Spindle stop | Stops spindle rotation | M05; |
| M08 | Coolant on | Activates coolant system | M08; |
| M09 | Coolant off | Deactivates coolant system | M09; |
| M18 | Spindle orientation off | Cancels spindle orientation mode | M18; |
| M19 | Spindle orientation | Positions spindle at a specific angle | M19; |
| M20 | Bar feeder | Activates automatic bar feeder | M20; |
| M30 | Program end | Ends program and returns to start (ISO standard) | M30; |
| M50 | Retract Tool Eye | Retracts tool measurement sensor | M50; |
| M51 | Advance Tool Eye | Advances tool measurement sensor | M51; |
| M98 | Subprogram call | Calls a subprogram | M98 P1000; |
| M99 | Subprogram return | Returns from subprogram | M99; |
Contributions to this documentation are welcome! If you have additional commands, corrections, or improvements, feel free to submit a pull request.
This documentation was developed based on the book Processos de Programação, Preparação e Operação de Torno CNC.
Special thanks to SENAI and Sidnei Domingues da Silva for their support, references, and valuable contributions that helped structure this material.