Our GCode is strongly based on LinuxCNC (G and M codes). If you are thinking about suggesting a new command, look to see what LinuxCNC does. Saying "...like Marlin" will get you nowhere.
It is very close the the RS274NGC Interpreter definition of the codes.
Some gcode parameters and expressions are supported.
You can place comments in gcode using two methods.
Anything after a semicolon will be considered a comment and ignored by the gcode parser.
G0 G53 Z-1 ;move to top of Z
Anything within parentheses will be considered a comment and ignored by the gcode parser. This can be between gcode commands.,
M3 (Spindle CCW) S1000 (Speed 1000)
If the comment has 'MSG ' in it, it will echo the comment back to the console in the [MSG:INFO: GCode Comment...My Message]
format. It will strip the MSG
and the following character (typically a space) from your comment.
M3 (MSG Spindle CCW) S1000 (MSG Speed 1000)
Response
[MSG:INFO: GCode Comment...Spindle CCW]
[MSG:INFO: GCode Comment...Speed 1000]
The planner tries to maintain accurate, fast and smooth motion. It does this by loading multiple motion commands and combining them. It will not accelerate and decelerate between all motion commands. The simplest example is straight motion.
This snippet contains 2 separate move commands, but it will combine then into one smooth move to X200
G1 F100 X100
X200
If the motion commands create an angle, the planner will insert the minimum amount of decel/accel into the corner that it needs to maintain its accuracy (junction_deviation_mm:)
Unsynchronized commands are things like spindle commands or delays. The same code as above with a tiny delay will cause the machine to stop between the moves.
G1 F100 X100
G4 P0.5 ;delay 0.5 seconds
X200
This can affect when line comments are displayed by FluidNC. They are displayed when they are read into the planner. This means you will likely see comments displayed early when motion commands are being combined.
Machine axes XYZ are linear and affected by the G20/G21 unit mode. ABC are rotational and not affected by G20/21. You can use them as linear if you use millimeters.
Arc Parameters
Output pin number with M67
Parameter for G10
Line number. Optionally a line number can be used with each gcode line.
N100 G0 Z23.4
This is used with the M6 command. It is used to change the current tool number. With FluidNC it can also be used to change the spindle if multiple spindles are used.
Used to set spindle speed or laser power. It can be used by itself on a line or with other gcodes. The value is modal and remains in effect until changed. The unit is traditionally RPM, but is also used for laser power level in FluidNC.
S12000 ;set speed to 1000
M3 ;run spindle CW. It uses speed 12000
M5 ;turn of spindle
M3 S2000 ;turn on spindle CW with speed 2000
When speed is set to 0 you can optionally disable your spindle. See the spindle config documentation.
F1000 ; set feed rate to 1000
G1 X20 ;move to x20 at 1000
G1 X0 F3000 ;move to 0x0 at 3000
At startup feed rate is 0. You will get an error if you try to use a motion command like G1, G2, G3, etc. if you do not have a feed rate above 0.
Prepare to change to tool number. When the M6 command comes the actual tool will be changed. It can be used on its own line or with M6. Standard FluidNC uses tool numbers for multiple spindles. It is the way to change to another spindle.
Actual ATCs must be implemented by adding code to the firmware. This is a very advanced topic and only limited help can be given.
M6 T2 ;change to tool 2 now
T7 ;prepare to change to tool 7
M6 ; change to tool 7
Rapid motion. Move will occur at the maximum feed rate possible. Multiple axis motion is coordinated, so the actual rate in the resulting direction may be more or less than any specific axis.
Note: Some spindles, like lasers may disable during this move
Motion at current feed rate. It will use the current feed rate (F value). This can come from a previous value specified or on the same line that the G1 is on. If no F value has been received, you will get an error.
Example
F100 (set the feed rate)
G1 X5.5 (move to X5.5 at 100)
G1 X0 F500 (move to X0 at 500)
X1.5 (Move to X1.5 at 500. It uses the current modal G1 and F values)
This is the most common form. It uses a G2 or G3 <center...> <offsets...> <turns>
format.
It creates an arc move from the current location to the point determined by the offsets using the provided center. The x offset is I
and y offset is J
. If you provide a Z value it will create a helix move. Add a P
parameter for the number of turns.
G0 X0 Y0
F500
G02 X10 Y10 I0 J10
This would create a counter clockwise move from (0,0) to (0,10) with the center at X10, Y10.
If is impossible to fit an arc to the points provided, you will get an
error:33 [MSG:ERR: Gcode invalid target]
If you want to create an arc in XZ or YZ plane you must do a G18 or G19 plane select.
Hand coding arcs is complicated. If you want more infor do an internet search.
Pn.n
This is the delay in seconds.G4 Px.x
It is a synchronized command. This means all buffered gcode is completed before the dwell starts.
G10 Lx Px axes
L2
This sets the work coordinate offset to the value of axes
L20
This sets the work coordinate in the specified system number to the value of the axes
Pn
This specifies the coordinate system to change. P0 is used to change the current G54-G59 system. P1 through P6 selects G54 through G59
G10 L2 P0 X0 ; change the X offset in the curent coordinate system to 0
G10 L20 P1 X0 ; set the X work coordinate value in G54 to 0
You see all saved values with the $#
command.
Arcs only work on 2D planes. The default is the XY plane. If you want an arc on an alternate 2D plane, you must select that plane first.
G17
XY (default)G18
ZXG19
YZThis sets the units. The native units of FluidNC are millimeters. It will start in millimeters. If it sees a G20, it will start converting the axis and speed values into millimeters. It only does this for axes X, Y, and Z. The A, B, and C axes are considered rotary and unitless. No conversion will be used for these.
Config values are never converted.
G20
- Use inches for length and speed valuesG21
- Use millimeters for length and speed valuesG28 is a machine coordinate location stored in non volitile memory. It will go the the same location regardless of the coordinate system or G92 offsets. You can view the current setting via the $#
command.
G28
This does a rapid move to the location.G28 axes
If you specify axis values it will first do a rapid move to that location in your current work coordinate system. Then it will do a rapid to the stored G28 location. It will only move on axes specified.
G28 Z10
will move to work Z10 then move to the Z location stored in G28. No motion on X or Y.G28 X10 Y20
will move to work X10 Y20 then to the G28 location for X and Y. There will be no motion on Z or any other axes you have defined.G28 G91 X0
This is a way to move only to the X stored in G28. G91 X0 is relative move of 0 so there will be no move before the G28 move. Again, only the X axis will move. Note: You will remain in G91 after the move. If you were in G90 before the move, you may want to send a G90 to return to that mode.G28.1
Use this to set the G28 offset to the current location in machine coordinates.<Idle|MPos:0.000,-10.000,-30.000|FS:0,0|Ov:100,100,100>
G28.1
ok
$#
[G54:0.000,-150.000,0.000]
[G55:0.000,0.000,0.000]
[G56:0.000,0.000,-30.000]
[G57:0.000,0.000,0.000]
[G58:0.000,0.000,0.000]
[G59:0.000,0.000,0.000]
[G28:0.000,-10.000,-30.000]
[G30:5.000,-5.000,-1.000]
[G92:0.000,0.000,0.000]
[TLO:0.000]
ok
You should only use G28 after you have fully homed a machine. It needs an accurate machine position or it will move to inaccurate locations.
Many people set G28 to the home position. After homing send G28.1 to set G28 to the homed position. You can then send G28 to go to that position.
This is the same as G28, but use 30 instead of 28.
G38.n axes Pnn.nnn
G38.2
Probe towards workpiece. Stop on contact. Error on failure.G38.3
Same G38.2, but no error on failure.G38.4
Probe away from workpiece. Stop on loss of contact. Error on failure.G38.5
Same as G38.4, but no error on failure.G38.6
like G38.2G38.7
like G38.3G38.8
like G38.4G38.9
like G38.5The move will use the existing feed rate and distance mode (for G38.2-G38.5) if none is provided
The P parameter is optional. It is used to set the work location of the Z with the P parameter being the offset from a plate etc. Use this to set your touch plate thickness (ideally measured with a micrometer). The G43 tool length offsets and G92 system coordinate offsets are accounted for when using the P parameter.
You will get an error if the probe is touching before the probe command on G38.2 and G38.3. You will get an error if the probe is not touching before the command on G38.4 and G38.5
G91 G38.2 Z-20.0 F80.0 ;probe an absolute amount of -20 in Z with a feedrate of 80 until probe is triggered, then set the probe location to 0. (Maximum travel is 20.)
G53 G38.2 Z-40 F80 ;probe to a machine position of Z-40 with a feedrate of 80 until probe is triggered, then set the probe location to 0. (Maximum travel is 40.)
G38.2 Z-40 F80 P4.985 ;probe to a work position of Z-40 with a feedrate of 80 until probe is triggered, then set the probe location to 4.985 (the thickness of your touch plate). (Maximum travel is 40.)
G43.1 axes
This command is used to adjust for different length tools. It creates an offset from the current coordinate system. It does create any motion. If your work Z value is 1.00 and you send G43.1 Z0.250
, the work Z value will now be 1.25.
You can see the current value with the $#
command.
[G54:0.000,0.000,0.000]
...
[G92:0.000,0.000,0.000]
[TLO:0.000]
[PRB:0.000,0.000,0.000:0]
We do not support the
G43 H<tool number>
format. FluidNC does not store a table of tool offset values.
Resets the TLO to 0's.
G49
ok
$#
...
[TLO:0.000]
ok
Format
G53 axes
This moves to a specific point in machine coordinates. These are the coordinates reported as MPos with the ?
status command in $10=1
reporting mode. G53 mode is only active for the line it is on. Subsequent commands will return to moving in normal G0, G1, etc. mode.
Examples:
G0 G53 Z-1 (move to Z-1 in MPos)
G53 X20 (G0 move to Mpos X20)
This is used to set the current coordinate system. Coordinate systems store work coordinate system offsets. This allows you to set 6 different work offsets. The system always starts in G54. You set the value of the offsets with the G10 command. The offsets are stored in non volitile memory and are automatically restored at startup. You can read the offset values with the $#
command.
Examples:
G54
G10 L2 P1 Y5
$#
(response)
[G54:0.000,5.000,0.000]
[G55:0.000,0.000,0.000]
[G56:0.000,0.000,0.000]
[G57:0.000,0.000,0.000]
[G58:0.000,0.000,0.000]
[G59:0.000,0.000,0.000]
[G28:0.000,0.000,0.000]
[G30:0.000,0.000,0.000]
[G92:0.000,0.000,0.000]
[TLO:0.000]
G90 Example:
G90 ;(set absolute mode)
G0 X10.5 ;(move to X10.5 including any G54-G59 and G92 offsets)
G91 ;(set incremental mode)
G0 X-10.5 ;(move -10.5 in on the X axis)
G92 axes
G92 makes the current work position have the desired location specified. It creates an addtional offset from the current G54-G59 to achieve this. The value of the offset can be read with the $#
command. The offset is volitile and will be lost at reboot.
This should only be used by advanced users. Many newbies use it as a simple way to set a work 0. The desired affect is lost if system restarts, you change to a different G54-G59 system or the current G54-G59 offset is changed. Most people should use G10. Most gcode senders will use G10.
For example: If you are using G92 X0 Y0 Z0
the equivalent would be G10 L20 P0 X0 Y0 Z0
It is left over from the hand coding days. If you hand code a bunch of gcode for a part and want to cut a second part off to the side you can use the gcode to make the first part, then use G92 to offset over to the side and start a second part with the exact same gcode. You still need to use a G54 (etc) offset on the first part. Otherwise everything is lost after power off. If you are using G92 without using G10 before it you are suffering a bad case of RepRap poisoning.
Modern CAM does everything for you. If you want 2 parts, just copy the part in CAM.
G92 Does not affect soft limits. Soft limits work in machine space and are not affected by any offsets (G92, G54-G59)
G93 is Inverse Time Mode. In inverse time feed rate mode, an F word means the move should be completed in one divided by the F number minutes. For example, if the F number is 2.0, the move should be completed in half a minute.
When the inverse time feed rate mode is active, an F word must appear on every line which has a G1, G2, or G3 motion, and an F word on a line that does not have G1, G2, or G3 is ignored. Being in inverse time feed rate mode does not affect G0 (rapid move) motions.
G93
ok
G1 X50 F10 ;move will take 1/10=0.6 minutes
ok
G1 X0 ;missing feedrate
error:22
$e=22 ;get the error text
22: Gcode undefined feed rate
ok
G94 (Default) is Units per Minute Mode. In units per minute feed mode, an F word is interpreted to mean the controlled point should move at a certain number of inches per minute, millimeters per minute, or degrees per minute, depending upon what length units are being used and which axis or axes are moving.
This will put the machine into hold mode. You must send the resume (cycle start) command ~
or via a control input cycle_start_pin:
Turn on laser in clockwise mode. With a laser, this is constant power mode
Turn on laser in counter-clockwise mode. With a laser this is dynamic power mode
This disables the spindle. You can define what happens during disable via your spindle section of the config file.
M6 T1
T2 ; Tool #2 will be next
G0 X0 Y0
M6 ; now change to tool #2
This will change to tool T. You can specify the T number anywhere before the line with M6 or on the same line as M6.
With FluidNC: If you have multiple spindles, this command can be used to change spindles. See the spindles section.
Turn the mist coolant on. This is just a digital signal that can be used for any function (vacuum, etc).
M7.1 will turn mist coolant off.
Standard gcode uses M9 to turn off coolant. M7.1 will work in FluidNC to turn off mist coolant. No M commands in the standard have a .<number>. This could cause confusion to people reading your gcode or gcode senders streaming your code.
Turn the flood coolant on. This is just a digital signal that can be used for any function (vacuum, etc).
M8.1 will turn mist flood off. (See M7.1 note above)
This turns both M7 and M8 off. See M7.1 and M8.1 for a way to turn them off individually.
M61 Qn
Changes to the tool in Qn
without doing a tool change. This would be used if there is a tool installed without FluidNC knowing about it. It does not affect the TLO (G43). You would need to set that separately.M62 Pn
Turn on digital output synchronized with motion. The P word specifies the digital output number.M63 Pn
Turn off digital output synchronized with motion. The P word specifies the digital output number.M64 Pn
Turn on digital output immediately. The P word specifies the digital output number.M65 Pn
Turn off digital output immediately. The P word specifies the digital output number.M62 P0 ;turn on digital0_pin in your config file
M63 P0 ;turn it off.
We recommend you avoid M64 and M65. These unsychronized commands are unpredicable when they will occur.
This is a partial implementation of the M66 LinuxCNC gcode. Only immeiate mode 0 is supported. Immediate mode is useful for conditional tests in gcode programming .
Mode 0: IMMEDIATE - no waiting, returns immediately. The current value of the input is stored in parameter #5399
M66 P0 L0
ok
D#5399
[MSG:INFO: Value is 1.000]
This is used to set the PWM level of an output. It uses the following parameters. These are set up in the user output section of the config file.
E
The the number of the outputQ
The percentage of the duty cycle 0% - 100%M67 E0 Q23.76
You can put multiple commands on a single line of gcode as long as no two, or more, of the commands are in the same modal group. For example G20 (inch mode) and G21 (millimeter mode) both belong to the units group. You cannot put both G20 and G21 on the same line.
Once you set a value in a modal group it stays in effect.
G1 F100 X100
X200 ; we are still in G1 and F100
G0 ; switch to G0 mode
X100 ; move to X100 in G0 mode
G1 X200 ; switch to G1 mode and use existing speed of F100
You can see what modes are in effect with the $G
command.
$G
OK
[GC:G0 G54 G17 G21 G90 G94 M0 M5 M9 T0 S0.0 F500.0]
The first line of your gcode files should reset all of the modal values. You need to make sure things like G90/G91 are in the expected state or your gcode could behave unexpectedly. Here is an example line that returns several modal values to the FluidNC defaults.
G0 G54 G17 G21 G90 G94
If you create macros, you should also keep this in mind. You might want to return the modal values to defaults.