G Code Quick Reference

G Codes
G0 X3.5 Y5.0 Z1.0 A2.0 (Rapid move)

G1 X3.5 Y5.0 Z1.0 A2.0(linear move)

G2 X0.0 Y0.5 I0 J0.25 (CW Arc move)

G3 X0.0 Y0.5 I0 J0.25 (CCW Arc move)

G4 P0.25

(Dwell seconds)

 

G10L2Pn G10L2P1X0Y0Z0

(Set Fixture Offset #n)

 

G20 Inch units

G21 mm units

 

G28 Move to Reference Position #1

G30 Move to Reference Position #2

 

G40 Tool Comp Off

G41 Tool Comp On

Left of Contour)

G42 Tool Comp On (Right of Contour)

 

G43 Hn (Tool #n length comp On)

 

G49 (Tool length comp off)

 

G53 Absolute Coord

G54 Fixture Offset 1

G55 Fixture Offset 2

G56 Fixture Offset 3

G57 Fixture Offset 4

G58 Fixture Offset 5

G59 Fixture Offset 6

G59.1 Fixture Offset 7

G59.2 Fixture Offset 8

G59.3 Fixture Offset 9

 

G90 Absolute Coordinates

G91 Relative Coordinates

 

G92 Set Global Offset Coordinates G92 X0Y0 Z0

 

M Codes:
M0 (Program Stop)

M2 (Program End)

M3 Spindle CW

M4 Spindle CCW

M5 Spindle Stop

M6 Tool Change

M7 Mist On

M8 Flood On

M9 Mist/Flood Off

M98 Pxxx Call Subroutine

M99 Return from Subroutine

 

 

Other Codes:
F (Set Feed rate in/min or mm/min)

S (Spindle Speed)

D (Tool)

O Subroutine Label

 

Comments:

(Simple Comment)

(MSG,OK toContinue?)
(CMD,EnableAxis0)
(BUF,SetBitBuf29)

Other KMotionCNC Screens             see also KMotion OnLine Help

G Code Viewer Screen

G Code Viewer Setup Screen

Tool Setup Screen

 

Axis Display Help Custom Button Help Units and Coordinate System Help Fixture Offset Help Tool Selection/Display Help File Load Save Help Control Execution Help Show Tool Viewer / G Code Viewer Help File Selector Help Simulate Help Jog and Gamepad Button Help Feed Rate Override Help G Code Editor Help Emergency Stop Help Manual Data Entry Help

(Click on Image to Jump to related help)

 

 

KMotionCNC allows the user to edit, execute, and view G Code Programs.  GCode is a historical language for defining Linear/Circular/Helical Interpolated Motions often used to program numerically controlled machines (CNC Machines).

 

 

 

 

 

See the Quick Reference at left for commonly used G Code commands.

 

 

Display

The 4 axis Display along the top of the screen indicated the current position of each axis.  The units of the display are in either mm or inches depending on the current mode of the interpreter (see Coordinate System Units)

The displayed position will match the g -code programmed position (i.e. last G1 commanded position) which is not necessarily the actual machine tool position if global or fixture offsets are in use.

The color of the display gives an indication of current status. 

Green - indicates normal status, hardware is connected, axis is enabled, and the displayed position is the current tool position in GCode coordinates. 

Orange - indicates normal status, hardware is connected, axis is enabled, and the displayed position is the current tool position in Raw Machine Coordinates (G53 without any Global offset (G92) or Fixture Offset (G54+). 

White - indicates simulation mode is selected.  The displayed position is the current position after the last line of interpreted G code.

Yellow - indicates hardware disconnected or axis disabled.  The displayed position is invalid

 

Coordinate System Origin

 

When checked, the displayed position is the current tool position in Raw Machine Coordinates (G53 without any Global offset (G92) or Fixture Offset (G54+).  Machine coodinates are relative to the fixed machine home position.

Unchecked displays the normal GCode Coordinate relative to the "floating" origin which may be moved by changing either the global offset (G92) and/or a Fixture Offset.

 

Coordinate System Units / Mode

Displays the current mode of the G code interpreter. 

 

 

G20 selects English Inch units

G21 selects Metric mm units

 

G90 selects Absolute Coordinates

G91 selects Relative Coordinates

 

 

Fixture Offset

Displays and allows changing of the current Fixture Offset.  KMotionCNC supports 9 Fixture offsets.  Each Fixture may be programmed to introduce an arbitrary x,y,z,a offset.  Use the G10L2Pn command to set the offset associated with the fixture #n.  An example might be:

G10 L2 P3 X10.0 Y20.0 Z30.0   which sets Fixture Offset #3 to (10,20,30)

Executing the command G56 (or by selecting 3 - G56 in the drop down list) will cause Fixture offset #3 to be in use in subsequent commands until a different Fixture is selected.  (See also - G Code Offsets).

 

Tool

Displays and allows changing of the currently selected Tool.  KMotionCNC supports up to 99 tool definitions.  The tool definitions are specified in a text file that is selected on the ToolSetup Screen.

A tool definition consists of the tool number (FMS), the pocket where it is located if there is a tool changer available (POC), the length of the tool (LEN), the diameter of the tool (DIAM), and an optional comment.

Executing the command D3 (or by selecting 3 in the drop down list) will cause Tool #3 to be in use in subsequent commands until a different Tool is selected.

See below for an example Tool Table

 

 

POC FMS  LEN   DIAM  COMMENT

1    1   0.0   0.0   first tool

2    2   0.0   0.0

3    3   1.0   0.5

4    4   2.0   1.0

32  32   0.0   0.0   last tool

 

 

File New / Open/ Save

This group of pushbuttons allow a G Code file to be loaded or saved to or from the edit window.  The edit window allows the user to quickly switch between 7 loaded G Code files.   Once a file is loaded into one of the edit windows, the name of that file will persist between sessions.

 

Execute Controls

This group of pushbuttons allow the control of G Code execution.  Restart will reset the instruction pointer to the first line of the file.  Execute will begin continuous execution from where the current instruction pointer is located on the left of the edit window.  Single Step will execute one single line of G code  where the current instruction pointer is currently pointing.  Note that the instruction pointer may be moved to any line by right clicking on the line within the edit window and selecting Set Next Statement.

 

Show Tool Setup / G Code Viewer Screens

This group of buttons bring additional screens into view.  The Tool Setup Screen is used to configure the system's parameters.  Machine Axis distance/velocity/accelerations.  M Code and User Button Actions Actions, Tool and Setup definition files, and Jog Button and Joystick rates. The G Code Viewer Screen allows real-time, 3D viewing of the machine tool paths either during actual machine operation or during simulation.

 

G Code Edit Window

 

 

 

 

 

 

 

 

 

 

 

 

 

The Edit Window displays the loaded G-Code and allows editing.  G-Code color syntax highlighting makes the code more readable.  A right mouse click will bring up the context menu shown.  Note that Transform Sel will bring up a utility dialog (shown below) that allows the selected G-Code to be scaled or offset.

 

 

 

File Selector

The file selector shows which of the 7 loaded G Code files is currently active for editing.  The Main Window Title also displays the loaded filename for the selected file.  The file number is highlighted in green when that file is currently executing G Code.  Only one G Code file is allowed to execute at a particular time.

 

 

 

 

 

Simulate

Enables Simulation Mode which allows viewing and verification of a G Code Program with or without any actual hardware connected.  When Simulation mode is enabled no actual machine motion will be made.  Executing or Single Stepping through a G Code program will change the Displayed Position and Plot the machine tool path on the G Code Viewer Screen.  In Simulation Mode the Numeric Display Color changes to white to indicate the display is not showing the actual machine tool position.  While in Simulation mode the Jog Buttons and Gamepad buttons will also change the displayed position and tool position on the G Code Viewer Screen without causing any actual machine tool motion.

 

Emergency Stop

Emergency Stop may be used to immediately stop all motion.  Any commands in motion will be aborted and all axes will be disabled.  After depressing Emergency Stop the system must be re-initialized and the G Code Interpreter state will be lost.   Use Halt to stop in a controlled manner after the next line of GCode has been completed.

The ESC key may also be use to initiate an Emergency Stop whenever the KMotionCNC Screen has the focus.

 

Manual Entry

The Manual Entry cell allows the user to quickly enter a single line of G Code and Send it to the interpreter for execution.  The last 10 entered commands are saved in a drop down list for quick re-entry.

 

 

 

 

 

Jog Buttons

The Jog buttons may be used to move any of the axes.  Pushing and holding any of the arrow buttons will cause continuous motion.  There are 2 buttons in each direction for each axis.  The second button moves at twice the rate as the first.  The speeds for each axis may be specified in the Tool Setup Screen.

There is also a Step button (square dot) for each axis and direction that will move an exact step size (as specified in the step size selection).  The center button will stop a step in progress (useful for aborting large steps).

A USB Gamepad such as the one shown below may also be used to Jog the System.  Simply connect the Gamepad and it should become immediately active.  The left Joystick controls x and y and the right joystick controls z and a.  The same speed parameters in the Tool Setup Screen control both the Jog pushbuttons on the screen and the Gamepad.

The Jog buttons and Gamepad are also active in simulation mode

  

Feed Rate Override

Feed Rate Override provides a means to adjust the feedrate while the machine is in operation without having to modify the G Code.  The Feed Rate is specified within the G Code using the F command and the Feed Rate Override is a multiplicative factor that is applied to that value.  For example F100 would specify a Feed rate of 100 inches/minute (or 100 mm/minute if the interpreter is in metric mm mode), with a feed rate override of 1.5 the actual attempted feed rate would be 150 inches/minute (or 150 mm/minute in mm mode). 

Note that this speed will only be used if all the axes involved will remain below the maximum allowed speeds set on the Tool Setup Screen.   Additionally, short vectors with sharp corners (greater than the specified break angle) that require stopping may be limited due to acceleration limits.   KMotionCNC uses complex algorithms to ensure that velocities and accelerations remain below user specified limits.  So if the Feed Rate Override or (Specified Feed rate itself) doesn't seem to be having the expected result, check if the maximum velocities and accelerations are limiting.

The Feed Rate Override may be changed either by using the slider or by typing a value and pressing the apply button.

Note that because motions are planned ahead and downloaded to the Motion Controller ahead of time, that the feed rate override will take a short amount of time to have an effect.  The amount of time that the trajectory planner looks ahead is specified on the Tool Setup Screen and is normally set at from 1 to 3 seconds.  The main limitation to making this value very short is the worst case response time of Microsoft Windows™ and the PC hardware being used.  

 

Custom Buttons

KMotionCNC allows up to 5 Custom Buttons to be displayed and defined for special operations.  Which of these buttons are visible, what they display as a title, and what action they perform are all definable on the Tool Setup Screen.

The area shown within the red rectangle is where the Custom Buttons will appear if defined.  The actions that the buttons perform are defined in the same manner as the actions that M Codes perform.  These may be simple actions such as setting an Output to turn something on or may be a complex operation that involves invoking a program.  Normally one or more buttons will be used to initialize and configure the motion controller and/or home the machine.

 

 

 

Other GCode Commands

KMotion's G Code interpreter was derived from the Open Source EMC G Code Interpreter. Click here for the EMC User Manual (Only the G Code portions of the manual, Chapters 10-14 pertain to KMotion G Code)

Specially coded comments embedded within a GCode program may be used to issue KMotion Console Script commands directly to KMotion

A comment in the form: (CMD,xxxxxx) will issue the command xxxxxx immediately to KMotion as soon as it is encountered by the Interpreter.  Any KMotion command that does not generate a response may be used in this manner.

A comment in the form: (BUF,xxxxxx) will place the command xxxxxx into KMotion's coordinated motion buffer.  Coordinated motion sequences are download to a motion buffer within KMotion before they are executed.  This guarantees smooth uninterrupted motion. The BUF command form allows a command to be inserted within the buffer so they are executed at an exact time within the motion sequence.  Only the following KMotion Script commands  may be used in this manner. 

SetBitBuf, ClearBitBuf, SetStateBitBuf.

Additionally, a comment in the form: (MSG,xxxxxx) will pause GCode Execution and display a pop-up message window displaying the message xxxxxxx.