Programming Basics
The Ready Motion Controller uses the G CODE language. G-code is relatively easy to read. It consists of commands (which start with G, and some with M) followed by parameters. G0 moves as fast as the machine can go and is called “traverse”, G1 moves at the speed given by the F parameter and is called “feed rate”, G2 and G3 draw arcs, clockwise and counterclockwise. The expectation is that when the laser or spindle occurs during G1, G2 and G3, but not G0, which is why there’s no speed (“feed rate”) control for G0. Of the parameters, X, Y, A, B, C, D, E and Z are the coordinates to move to (usually absolute, but there’s a relative mode too), and, for arcs, I, J and K are the coordinates of the center. If a coordinate does not change during a move, it can be omitted (which is why you see almost no Z parameters). With some commands (G0 to G3 included), you don’t need to repeat the command on a new line if it’s the same as before: you can supply just the new set of parameters (coordinates, and maybe feed rate), which is why most of your lines are just X, Y, I, J and F. Linear moves would be just X and Y (and/or Z if moving vertically too, and/or F if speed has to change). Coordinates in various forms (“0”, “0.” and “0.0000” are all ok), But has line length limits of 70 characters.
G-CODE Overview
G-code | Meaning | Notes |
---|---|---|
F | Defines feed rate. | Example: G1 X10 F100 |
G | Address for preparatory commands | G commands often tell the control what kind of motion is wanted |
I | Defines arc center in X axis for G02 or G03 arc commands. | Also used as a parameter within some fixed cycles. |
J | Defines arc center in Y axis for G02 or G03 arc commands. | Also used as a parameter within some fixed cycles. |
K | Defines arc center in Z axis for G02 or G03 arc commands. | Also used as a parameter within some fixed cycles, equal to L address. |
M | Miscellaneous function | Many M-codes call for machine functions |
P | Serves as parameter address for various G and M codes | With G04, defines dwell time value |
S | Defines speed, either spindle speed laser frequency | Example: M3 S300 |
X | Absolute or incremental position of X axis. | Example: G00 X1 F400 |
Y | Absolute or incremental position of Y axis | Example: G00 Y1 F400 |
Z | Absolute or incremental position of Z axis | Example: G00 Z1 F400 |
A | Absolute or incremental position of A axis | Example: G00 A1 F400 |
B | Absolute or incremental position of B axis | Example: G00 B1 F400 |
C | Absolute or incremental position of C axis | Example: G00 C1 F400 |
D | Absolute or incremental position of D axis | Example: G00 D1 F400 |
E | Absolute or incremental position of E axis | Example: G00 E1 F400 |
Motion (G)
G-code | Meaning | Notes |
---|---|---|
G0/G00 | Rapid positioning | Switch to rapid linear motion mode (seek). Used to get the tool somewhere quickly without cutting — moves the machine as quickly as possible along each axis — an axis which needs less movement will finish before the others, so one cannot count on the movement being a straight line. |
G1/G01 | Linear interpolation | Switch to linear motion at the current feed rate. Used to cut a straight line — the interpreter will determine the acceleration needed along each axis to ensure direct movement from the original to the destination point at no more than the current Feed rate (F see below). |
G2/G02 | Circular interpolation, clockwise | Switch to clockwise arc mode. The interpreter will cut an arc or circle from the current position to the destination using the specified radius (R) or center (IJK location) at the current Feed rate (F see below) in the plane selected by G17/18/19 (see below). |
G3/G03 | Circular interpolation, counterclockwise | Switch to anti-clockwise arc mode. Corollary to G02 above. |
G4/G04 | Dwell (pause) | This should probably be calculated to be only one or two spindle rotations for best efficiency. Dwell time is expressed using a parameter (may be X, U, or P) which determines the time unit (seconds, milliseconds, &c.) P, for seconds, is supported and used by Ready Motion’s UI typically X and U express the duration in milliseconds. |
G10 | Set Work Coordinate Origin (and resultant Offsets) | Coordinate system origin setting. This setting is persistent and expects the user to follow good practices and not manually move the machine, instead only using jogging commands via the interface or a pendant which works through the control system, or to have and use homing switches. Examples:
See Re: Move after Homing to a position for a discussion of this. |
G17 | Select the XY plane (for arcs) | |
G18 | Select the XZ plane (for arcs) | |
G19 | Select the YZ plane (for arcs) | |
G20 | After this, units will be in inches | Best practice: do this at the start of a program and nowhere else. The usual minimum increment in G20 is one ten-thousandth of an inch (0.0001″). |
G21 | After this, units will be in mm | Best practice: do this at the start of a program and nowhere else. The usual minimum increment in G21 (one thousandth of a millimeter, .001 mm, that is, one micrometre). |
G28 | Go to Pre-Defined Position | Takes an argument of an X Y Z coordinate for the intermediate point that the tool tip will pass through on its way home to machine zero. v0.7 “Incorrectly performed the homing cycle”[11]Usually used to park the machine.[12]
http://www.cnccookbook.com/CCCNCGCodeG28ReturntoReference.htm |
G30 | Go to Pre-Defined Position (Return to secondary home position) | Takes a P address specifying which machine zero point is desired, if the machine has several secondary points (P1 to P4). Takes X Y Z addresses which define the intermediate point that the tool tip will pass through on its way home to machine zero. v0.7 “Incorrectly performed the homing cycle”[13]Usually used to park the machine.[14] c.f., G28 above. |
G30.1 | Set Pre-Defined Position | Stores the current absolute position. |
G38.1 | Probe cycle | Using a Touch Plate |
G38.2 | Straight Probe | Probe toward workpiece, stop on contact, signal error if failure |
G38.3 | Probe | Probe toward workpiece, stop on contact |
G38.4 | Probe | Probe away from workpiece, stop on loss of contact, signal error if failure |
G38.5 | Probe | Probe away from workpiece, stop on loss of contact |
G43.1 | Dynamic tool length offset | Change subsequent motions by offsetting the Z and/or X offsets stored in the tool table. Does not cause any motion, but will be applied the next time a compensated axis is moved, that axis’s endpoint will be the compensated location. See G38.1 above for a link which discusses using this.[15] |
G49 | Cancel tool offset. | Cancels tool offset set by G43 or G44 |
G53 | Absolute mode override | Move in Machine Coordinates. Preface to a movement command on the same line which causes the machine to disregard any coordinate system which is in effect. G53 G0 X0 Y0 Z0 will return to the machine home / origin. Useful to move the tool relative to the machine, e.g., for tool changes. |
G54–G59 | Work Coordinate Systems | Fixture offset 1–6. |
G61 | Exact path control mode | This is the default path mode Ready Motion run in. |
G80 | Motion mode cancel | Canned cycle |
G90 | Switch to absolute distance mode | Coordinates are now relative to the origin of the currently active coordinate system, as opposed to the current position. G0 X-10 Y5 will move to the position 10 units to the left and 5 above the origin X0,Y0. cf. G91 below. |
G91 | Switch to incremental distance mode | Coordinates are now relative to the current position, with no consideration for machine origin. G0 X-10 Y5 will move to the position 10 units to the left and 5 above the current position. cf. G90 above. |
G92 | Coordinate offset. Change the current coordinates without moving | e.g. “G92 x0 y0 z0” makes the current position a temporary home position. The intent is to allow one to re-use code (say for a part when doing multiples) which has a given origin. The temporary origin can then be cleared and the actual machine origin, set via G10 restored by the command below.[21] |
G92.1 | Clear (temporary) Coordinate System Offsets | Previously set by G92 (see above). |
G93 | Set inverse time feed rate mode | An F word is interpreted to mean that the move should be completed in (one divided by the F number) minutes. For example, if F is 2, the move should be completed in half a minute |
G94 | Set units per minute feed rate mode | An F Word is interpreted to mean the controlled point should move at a certain number of units (or degrees) per minute |
Feed Rate (F)
F-code | Meaning | Notes |
---|---|---|
F | Defines feed rate | Unit used is that set by G20 or G21 (see above). The Feed setting in the G-Code determines the maximum rate at which the motor can rotate when moving a given distance so as to get up to (but not exceed) the Feed rate and the maximum acceleration limit which is set in Ready Motion’s UI. It can be on a separate line or on the same line as a G1/G2/G3 command. |
Machine Options (M)
M-code | Meaning | Notes |
---|---|---|
M0 | Program Pause and End | Stops the machine so you can change the tool |
M2 | Program Pause and End | Reset Program Flow |
Spindle and Laser Control | ||
M16 | Turn on Output 0 | Spindle and Laser Control |
M17 | Turn off Output 0 | Spindle and Laser Control |
M18 / M7 | Turn on Output 1 | Spindle and Laser Control / Mist Coolant |
M19 / M9 | Turn off Output 1 | Spindle and Laser Control / Mist Off |
M20 | Turn on Output 2 | Spindle and Laser Control |
M21 | Turn off Output 2 | Spindle and Laser Control |
M22 / M8 | Turn on Output 3 | Spindle and Laser Control / Coolant On |
M23 / M9 | Turn off Output 3 | Spindle and Laser Control / Coolant Off |
M24 | Turn on Output 4 | Spindle and Laser Control |
M25 | Turn off Output 4 | Spindle and Laser Control |
M26 / M4 | Turn on Output 5 | Spindle and Laser Control / Spindle On (counterclockwise rotation) |
M2 / M3 | Turn off Output 5 | Spindle and Laser Control / Spindle On (clockwise rotation) |
M28 | Turn on Output 6 | Spindle and Laser Control |
M29 | Turn off Output 6 | Spindle and Laser Control |
M30 | Turn on Output 7 | Spindle and Laser Control |
M31 | Turn off Output 7 | Spindle and Laser Control |
Output Block 2 | ||
M32 | Turn on Output 0 | Output Block 2 |
M33 | Turn off Output 0 | Output Block 2 |
M34 | Turn on Output 1 | Output Block 2 |
M35 | Turn off Output 1 | Output Block 2 |
M36 | Turn on Output 2 | Output Block 2 |
M37 | Turn off Output 2 | Output Block 2 |
M38 | Turn on Output 3 | Output Block 2 |
M39 | Turn off Output 3 | Output Block 2 |
M40 | Turn on Output 4 | Output Block 2 |
M41 | Turn off Output 4 | Output Block 2 |
M42 | Turn on Output 5 | Output Block 2 |
M43 | Turn off Output 5 | Output Block 2 |
M44 | Turn on Output 6 | Output Block 2 |
M45 | Turn off Output 6 | Output Block 2 |
M46 | Turn on Output 7 | Output Block 2 |
M47 | Turn off Output 7 | Output Block 2 |
Output Block 3 | ||
M48 | Turn on Output 0 | Output Block 3 |
M49 | Turn off Output 0 | Output Block 3 |
M50 | Turn on Output 1 | Output Block 3 |
M51 | Turn off Output 1 | Output Block 3 |
M52 | Turn on Output 2 | Output Block 3 |
M53 | Turn off Output 2 | Output Block 3 |
M54 | Turn on Output 3 | Output Block 3 |
M55 | Turn off Output 3 | Output Block 3 |
M56 | Turn on Output 4 | Output Block 3 |
M57 | Turn off Output 4 | Output Block 3 |
M58 | Turn on Output 5 | Output Block 3 |
M59 | Turn off Output 5 | Output Block 3 |
M60 | Turn on Output 6 | Output Block 3 |
M61 | Turn off Output 6 | Output Block 3 |
M62 | Turn on Output 7 | Output Block 3 |
M63 | Turn off Output 7 | Output Block 3 |
Output Block 5 | ||
M64 | Turn on Output 0 | Output Block 5 |
M65 | Turn off Output 0 | Output Block 5 |
M66 | Turn on Output 1 | Output Block 5 |
M67 | Turn off Output 1 | Output Block 5 |
M68 | Turn on Output 2 | Output Block 5 |
M69 | Turn off Output 2 | Output Block 5 |
M70 | Turn on Output 3 | Output Block 5 |
M71 | Turn off Output 3 | Output Block 5 |
M72 | Turn on Output 4 | Output Block 5 |
M73 | Turn off Output 4 | Output Block 5 |
M74 | Turn on Output 5 | Output Block 5 |
M75 | Turn off Output 5 | Output Block 5 |
M76 | Turn on Output 6 | Output Block 5 |
M77 | Turn off Output 6 | Output Block 5 |
M78 | Turn on Output 7 | Output Block 5 |
M79 | Turn off Output 7 | Output Block 5 |
Program Commands
Code | Meaning | Notes |
---|---|---|
() | Comments | (Here is a comment) |
$$ | Configuration | View Machine Configuration |
$# | Configuration | View # Parameter |
$G | Configuration | View Parser State |
$I | Configuration | View Build Info |
$N | Configuration | View Startup Blocks |
$x=value | Configuration | Save Machine Setting |
$Nx=line | Configuration | Save Startup Block |
$C | Configuration | Check Gcode Mode |
$X | Configuration | Kill Alarm Lock |
$H | Configuration | Run Homing Cycle |
~ | Configuration | Cycle Start |
! | Configuration | Feed Hold |
? | Configuration | Current Status |
ctrl-x | Configuration | Reset |
$ | Configuring | For better detail of configuring commands please check out Configuring-Grbl-v0.9 |
$0 | Configuration | step pulse, usec |
$1 | Configuration | step idle delay, msec |
$2 | Configuration | step port invert mask:00000000 |
$3 | Configuration | dir port invert mask:0000000 |
$4 | Configuration | step enable invert, bool |
$5 | Configuration | limit pins invert, bool |
$6 | Configuration | probe pin invert, bool (TESTING STILL) |
$10 | Configuration | status report mask:00000011 |
$11 | Configuration | junction deviation, mm |
$12 | Configuration | arc tolerance, mm |
$13 | Configuration | report inches, bool |
$20 | Configuration | soft limits, bool |
$21 | Configuration | hard limits, bool |
$22 | Configuration | homing cycle, bool |
$23 | Configuration | homing dir invert mask:00000000 |
$24 | Configuration | homing feed, mm/min |
$25 | Configuration | homing seek, mm/min |
$26 | Configuration | homing debounce, msec |
$27 | Configuration | homing pull-off, mm |
$100 | Configuration | x, step/mm |
$101 | Configuration | y, step/mm |
$102 | Configuration | z, step/mm |
$103 | Configuration | a, step/mm |
$104 | Configuration | b, step/mm |
$105 | Configuration | c, step/mm |
$106 | Configuration | d, step/mm |
$107 | Configuration | e, step/mm |
$110 | Configuration | x max rate, mm/min |
$111 | Configuration | y max rate, mm/min |
$112 | Configuration | z max rate, mm/min |
$113 | Configuration | a max rate, mm/min |
$114 | Configuration | b max rate, mm/min |
$115 | Configuration | c max rate, mm/min |
$116 | Configuration | d max rate, mm/min |
$117 | Configuration | e max rate, mm/min |
$120 | Configuration | x accel, mm/sec^2 |
$121 | Configuration | y accel, mm/sec^2 |
$122 | Configuration | z accel, mm/sec^2 |
$123 | Configuration | a accel, mm/sec^2 |
$124 | Configuration | b accel, mm/sec^2 |
$125 | Configuration | c accel, mm/sec^2 |
$126 | Configuration | d accel, mm/sec^2 |
$127 | Configuration | e accel, mm/sec^2 |
$130 | Configuration | x max travel, mm |
$131 | Configuration | y max travel, mm |
$132 | Configuration | z max travel, mm |
$133 | Configuration | a max travel, mm |
$134 | Configuration | b max travel, mm |
$135 | Configuration | c max travel, mm |
$136 | Configuration | d max travel, mm |
$137 | Configuration | e max travel, mm |
Example Code
(HEADER)
(BACKSTOP 127.876 FROM START )
(READY MOTION)
(This program as developed as an example and not intended for any particular)
(application. Ready Motion does not except any responsibility for how this program is used in applications.)
(STEPPER SETTINGS)
($100=76.7400)
($101=125.984)
$100=386.025
$101=629.921
$102=314.960
$103=125.984
$120=200
$121=200
$122=200
$123=200
(END)
G92 X0 Y0 Z0 A0 B0 C0 D0 E0
(LASER NOT ENABLED)
M5
(MAKE SURE NO POWER)
M25
(MAKE SURE NO FREQ)
S0
(HOUSEKEEPING)
M28
(HEADER END)
G21 (All units in mm)
(Start cutting path id: path3108-0-3)
(Change tool to Default tool)
G00 Z 0.000
G00 X -0.008 Y 133.883
M22 (AIR ON)
M24
M3 S1000
G01 Z 0.000 F 250.000(Penetrate)
G01 X 0.041 Y 134.950 Z 0.000
G03 X -0.019 Y 134.959 Z 0.000 I -0.053 J -0.157 F 300
G03 X -0.074 Y 134.948 Z 0.000 I 0.007 J -0.178
G03 X 0.090 Y 134.931 Z 0.000 I -0.224 J -0.194
G00 Z 0.000
M5
M25 (U CONTROL OFF)
M23 (AIR OFF)
(End cutting path id: path3108-0-3)
(FOOTER)
(LASER NOT ENABLED)
M5
M23 (AIR OFF)
M25 (U CONTROL OFF)
G4 P1
M31 (REDLIGHT OFF)
M29 (HOIUSEKEEPING OFF)
G00 X0 Y0 Z0 A0 B0 C0 D0 E0
M2
(END