Wednesday, April 5, 2023

G Code & M Code

What is a G code

G codes are a programming language used in CNC machining to define various movements of axes and other functions of a CNC machine. They play a crucial role in understanding coordinate systems and measurements. G codes are categorized into different groups, allowing only one G code from a specific group to be used in a single program line. However, multiple G codes from different groups can be used in a single program block. Some G codes are defined as modal codes, meaning they remain active in a program until another G code within the same group is activated. While most G codes are common across all CNC controllers, there may be slight variations between milling and turning operations. The following are common and essential G codes frequently used with CNC milling and turning machines:

 

G00 – Rapid move - This code is used for rapid movement of the axes to move from one point to another in free space without cutting the material. It does not require a feed rate and usually occurs at the maximum velocity of the machine axes.

G01 – Linear feed movement - This code directs the axes to move in a straight path or linear interpolation with a programmed feed. It involves interpolating all the axes in motion to reach the endpoint at the same time.

G02 - Circular movement Clockwise - This code instructs the axes to move in a circular path or circular interpolation in a clockwise direction with a programmed feed. The circular path is defined by its start and endpoints, radius, or center point.

G03 – Circular movement Anti-clockwise - This code moves the axes in a circular path or circular interpolation in an anti-clockwise direction with a programmed feed. The circular path is defined by its start and endpoints, radius, or center point.

G04 – Dwell time - A dwell time is a pause in program execution. The duration of the dwell is specified by the F value in seconds. No axis movements occur during the dwell time, and other functions such as spindles and coolant remain on.

G17 / G18 / G19 - Plane Selection – These codes are used for selecting a plane during circular interpolation of axis movements. G17 is used for the XY plane, G18 for the ZX plane, and G19 for the YZ plane. The default plane selection for milling operations is G17.

G20 / G21 - Unit Selection – These codes define the measurement unit for axis movements during programming. G20 is used for inch units, and G21 is used for the metric system.

G28 - Zero Return - This function brings one or more axes back to the home position from the last cutting position, usually through an intermediate point.

G40 – Cutter compensation cancel – This code cancels the cutter compensation mode.

G41 / G42 - Cutter composition left / right – These codes enable cutter compensation mode. G41 allows compensation in the right direction, while G42 allows compensation in the left direction.

G43 / G44 - Tool length offset - During axis positioning, the actual movement of the axis is adjusted based on the tool length offset value. G43 is used for a positive tool offset, and G44 is used for a negative tool offset.

G49 - Tool length offset cancel – This code cancels the tool length offset value.

G53 - Machine Coordinate system – While machine positioning is typically done using a user-created coordinate system, it can sometimes be beneficial to program with the machine coordinate system. The G53 code in a program defines the machine coordinate system.

G54 to G59 – Fixture offset – These codes are used to select different fixture offsets in a program. It is possible to use multiple fixture offsets within the same program.

G73 to G89 – Canned cycles – These codes are reserved for canned cycles, which streamline program writing. For example, G81 is used for drilling and G84 is used for tapping.

G90 - Absolute position mode – With absolute position mode, the machine moves to the commanded position based on the user coordinate system.

G91 - Incremental position mode – With incremental position mode, the commanded position and movement are based on the distance and direction from the current location.

G94 - Feed per minute - This code specifies the feed rate of an axis movement in a program in units such as mm/min.

G95 - Feed per revolution - This code is used in tapping cycles in milling operations. The axis feed rate is programmed based on the spindle RPM.

G96 - Constant surface speed ​​– During turning operations, the machining or surface area of the workpiece continually changes. By applying this code, the machine maintains a constant surface speed based on the cutting diameter and specified surface speed in surface units per minute.


G97 - Constant RPM - The G97 code is used for spindle rotation at a constant RPM in milling operations. It cancels the constant surface speed in turning processes.

G98 - Return to an initial point – With drilling and boring canned cycle operations, it is necessary to return the cutting tool to the initial point before a rapid move to the next position. The G98 code is used for this operation.

G99 - Return to R point – With canned cycle operations, the G99 code is used to bring the cutting tool back to the R point, eliminating extra axis movement and reducing cycle time.

 


What is M code 

M codes are used in CNC (Computer Numerical Control) programming to activate or deactivate various miscellaneous functions of a CNC machine. They are used to perform different actions such as tool changes, coolant activation, and palette changes. The specific M code functions can vary depending on the type of machine and CNC controller being used. Here is a list of some commonly used M codes that are typically standard for all types of CNC machines.

M00 - Mandatory program stop - The M00 code is used to pause a running program at any point. When this code is encountered, all axes and spindle motion will come to a stop. To resume the operation, the cycle start button needs to be pressed again.

M01 - Optional program stop - The M01 code is similar to M00. It allows for an optional stop in the program. To enable this feature, the optional stop switch on the operator panel should be kept in the ON condition.

M02 - End of program – The M02 command marks the end of program execution. After encountering this code, all programming operations will cease, and the program will not rewind. If the cycle start button is pressed again, the programming operations will continue with the following program block.

M03 – Spindle forward or clockwise – The M03 code activates the spindle rotation in a clockwise or forward direction at a specified speed. The M03 command is typically accompanied by the 'S' word, which specifies the desired speed. For example, M03 S100 signifies the rotation of the spindle in a clockwise direction at 100 RPM.

M04 - Spindle reverse or counter-clockwise – The M04 code activates the spindle rotation in a counter-clockwise or reverse direction at a specified speed. Similar to M03, the M04 command is also accompanied by the 'S' word to represent the desired speed. For example, M04 S100 denotes the rotation of the spindle in a counter-clockwise direction at 100 RPM.

M05 - Spindle stop –  The M05 code stops the rotation of the spindle, whether it is rotating clockwise or counterclockwise.

M06 - Tool Change – The M06 code indicates a tool change on the machine, with the tool number specified by T. For instance, M06 T05 represents the change to tool number five.

M07 – Through coolant on – The M07 code activates the through-tool coolant output, allowing coolant to flow through the tool during machining.

M08 – Flood coolant on – The M08 code activates the flood coolant output, which provides a continuous flow of coolant during machining.

M09 – Coolant off – The M09 code deactivates all coolant outputs, stopping the flow of coolant.

M10 – Spindle chuck clamp – Spindle Chuck Clamp: The M10 command is used to clamp the spindle chuck on turning machines.

M11 - Spindle chuck Un-clamp – The M11 command unclamps the spindle chuck on turning machines.

M19 - Spindle orientation - This code enables the spindle to stop or orientate itself at a specific position. Spindle orientation is essential for tool-changing operations and can also be used in specific machining cycles such as G76 and G87.

M30 – Program end and rewind – The M30 command marks the end of the current program execution and rewinds it to the beginning. By pressing the cycle start button again, the program will restart from the first program block.

M60 - Palette Change – In some CNC machining centers, the M60 code is used to change the pallet and the workpieces attached to it.

M98 - Subprogram call - The M98 command is used to call separate subprograms, which helps reduce program length and complexity. The subprogram number is specified along with the M98 command.

M99 – Return to the main program – The M99 code is used to return to the main program from a subprogram.

Note: The above list provides a general overview of some commonly used M codes, but it's important to consult the specific machine documentation and CNC controller manual for accurate and detailed information about M codes supported by your machine.

No comments:

Post a Comment

Popular Posts