2. G-Code variables
Rosetta CNC supports Macro programming (following Fanuc Macro B style).
Your G-Code programs or sub-programs can include a few non-G-Code commands that use variables, arithmetic, logic statements, and looping are available.
Rosetta CNC supports 7000 variables that can be accessed from the G-code. These variables are divided into 5 groups as described in the following table.
Variable Number | Type of Variable | Function |
---|---|---|
#0 | Null | #0 is read-only and its value is always “null” that means “no value”. |
#1-#33 | Local Variables | Local variables are used to pass arguments to macros and as temporary scratch storage. |
#100-#499 | Input Variables | The value of these variables can be set by the user through the GUI and the value in the table will never be changed by the controller. |
#500-#3999 | Program Variables | The value of these variables can be read/write by G-code programs and are initialized with #0 before executing a program. |
#4000-#4999 | Shared Variables | The value of these variables is shared between the GUI interface and the controller. The result is that if during a program one of these variables is changed the user can see the updated final value in the table. |
#5000-#5999 | System Variables | Updated run time by the compiler |
#6000-#6999 | Protected Variables | Variables that can be modified by the user only before compilation and that are password protected. A G-code program can only read these variables and not write them. |
2.1 System variables description
System Variable | Meaning |
---|---|
Current Position Variables | Current Position variables Meaning |
5001-5006 | Current TCP position X – C See position information table |
5081-5086 | Current TCP position when restarting X - C |
5091-5093 | Last stop position X, Y, Z [inches or mm depending on parameter 5106] |
5094-5096 | Last stop position A, B, C |
Active G-codes Variables | Active G-codes Variables Meaning |
5100 | Sequence number of lines executed |
5101 | Group 01: G0, G1, G2, G3, G38.X, G73, G80, G81, G82, G83, G84, G85, G86, G87, G88, G89 |
5102 | Group 02: G17, G18, G19 |
5103 | Group 03: G90, G91 |
5104 | Group 04: G90.1, G91.1 |
5105 | Group 05: G93, G94 |
5106 | Group 06: G20, G21 |
5107 | Group 07: G40, G41, G41.1, G42, G42.1 |
5108 | Group 08: G43, G43.1, G43.2, G43.4, G43.7, G49 |
5110 | Group 10: G98, G99 |
5111 | Group 11: G50, G51 |
5112 | Group 12: G54, G55, G56, G57, G58, G59, G59.1, G59.2, G59.3 |
5113 | Group 13: G61, G61.1, G64 |
5116 | Group 16: G68, G69 |
5117 | Group 17: G15, G16 |
Other codes | Other codes meaning |
5120 | Interpolated-Grouprd axes mask. Value is a bitmask where bit 1 represents X axis, bit 2 Y axis, .. |
5127 | Active jerk [%] |
5128 | Active max acceleration [mm/s^2 or inches/s^2] (0 means use the maximum acceleration) |
5129 | Active max deceleration [mm/s^2 or inches/s^2] (0 means use the maximum deceleration) |
5130 | Active feed rate (F) |
5131 | Active spindle speed (S) |
5132 | Selected tool (T) |
5133 | Selected slot |
5134 | Current tool |
5135 | Current slot |
5136 | Active feed rate override mode, P argument of M50 |
5137 | Active spindle speed override mode, P argument of M51 |
5138 | Active traverse rate: target speed during G0 commands. 0 means use the maximum possible speed. [mm/s^2 or inches/s^2] |
5139 | Active user tool change procedure: 1 means procedure active (Between M107 and M108) |
5140 | Tolerance set with G64 P |
5141 | Points removal threshold set with G64 Q |
5148 | While a modal macro is active it stores how many times a modal macro (G66) has been called. |
5149 | Executing sub-program. Flag set to 1 while G-code is executing a sub-program called from the main program. |
Active M-codes | Active M-codes meaning |
5150 | M0, M2, M30, M47, M60 |
5151 | M3, M4, M5 |
5152 | M6, M106 |
5153 | M7, M9 |
5154 | M8, M9 |
5155 | M48, M49, M51 |
5156 | M48, M49, M51 |
G28, G28.1 Variables | G28, G28.1 Variables Meaning |
5161 | G28.1 position X |
5162 | G28.1 position Y |
5163 | G28.1 position Z |
5164 | G28.1 position A |
5165 | G28.1 position B |
5166 | G28.1 position C |
G30, G30.1 Variables | G30, G30.1 Variables Meaning |
5181 | G30.1 position X |
5182 | G30.1 position Y |
5183 | G30.1 position Z |
5184 | G30.1 position A |
5185 | G30.1 position B |
5186 | G30.1 position C |
WCS Offsets Variables | WCS Offsets Variables Meaning |
5201 - 5206 | G52 offset X - C |
5210 | G92 enabled (0 ÷ 1) |
5211 - 5216 | G92 offset X - C |
WCS Variables | WCS Variables Meaning |
5220 | Coord. System number |
5221 - 5226 | Coord. System 1 X – C |
5241 - 5246 | Coord. System 2 X – C |
5261 - 5266 | Coord. System 3 X – C |
5281 - 5286 | Coord. System 4 X – C |
5301 - 5306 | Coord. System 5 X – C |
5321 - 5326 | Coord. System 6 X – C |
5341 - 5346 | Coord. System 7 X – C |
5361 - 5366 | Coord. System 8 X – C |
5381 - 5386 | Coord. System 9 X – C |
Tool Variables | Tool Variables Meaning |
5400 | Current tool id |
5401 | Current tool offset X |
5402 | Current tool offset Y |
5403 | Current tool offset Z / Current tool length |
5410 | Current tool diameter |
5411 | Current tool type |
5412 | Current tool parameter 1 |
5413 | Current tool parameter 2 |
5414 | Current tool parameter 3 |
5420 | Tool compensation offset X (Set using G43, G43.1, G43.2, G43.4, G43.7, G49) |
5421 | Tool compensation offset Y (Set using G43, G43.1, G43.2, G43.4, G43.7, G49) |
5422 | Tool compensation offset Z (Set using G43, G43.1, G43.2, G43.4, G43.7, G49) |
5423 | Tool compensation offset A (Set using G43, G43.1, G43.2, G43.4, G43.7, G49) |
5424 | Tool compensation offset B (Set using G43, G43.1, G43.2, G43.4, G43.7, G49) |
5425 | Tool compensation offset C (Set using G43, G43.1, G43.2, G43.4, G43.7, G49) |
5426 | The id of the tool used for tool compensation, both normal(G43, G43.1, G43.2) and RTCP (G43.4, G43.7) |
5427 | The type of the tool used for tool compensation |
Scaling & Rotation Variables | Scaling and Rotation Variables Meaning |
5501 | G51 scaling factor X |
5502 | G51 scaling factor Y |
5503 | G51 scaling factor Z |
5504 | G51 offset X |
5505 | G51 offset Y |
5506 | G51 offset Z |
5510 | G68 rotation plane |
5511 | G68 rotation XY |
5512 | G68 rotation XZ |
5513 | G68 rotation YZ |
5514 | G68 offset X |
5515 | G68 offset Y |
5516 | G68 offset Z |
Runtime External Variables | Runtime External Variables Meaning |
5700 | Probe state at the end of a G38.X. Values: 1 probing procedure succeeded, -1 failed: sensor not tripped before reaching the target position, -2 failed: sensor already tripped |
5701 - 5706 | Probed position loaded at the end of a G38.X with respect to the active WCS See position information table |
5711 - 5716 | Probed position X - C loaded at the end of a G38.X with respect to machine coordinates See position information table |
5720 | Return value for M66 |
5721 | Return value for M109 and M120 |
5722 | Status of the last M66 (0 → Success, 1 → Failure) |
5730-5734 | User input values from M109 or M120 |
5735-5739 | User input values from M109 or M120 |
5740-5744 | Input values for M166 and M167 |
5745-5749 | Input values for M166 and M167 |
5750-5754 | Input values for M166 and M167 |
5755-5759 | Input values for M166 and M167 |
Parameters Related Variables | Parameters Related Variables (Set using G10 L100 P<param> V<value>) |
5800 | The motion mode used when G66 is enabled (0 → G0; 1 → G1) |
5801 | Rotary axis modulus used for the rollover |
5802 | Axis A rotary mode (see Rotary axis options) |
5803 | Axis B rotary mode (see Rotary axis options) |
5804 | Axis C rotary mode (see Rotary axis options) |
Restart related position variables | Meaning |
5091-5096 | Last stop positions. X,Y and Z in inches or mm depending on parameter 5106 and A,B,C in deg |
2.2 Named variables
Named variables work like normal numbered variables but are easier to read.
Syntax:
- Named variables must be enclosed between
<
>
marks. - All variable names are converted to lower case and have spaces and tabs removed, so
<named variable>
and< Nam ed Var i Able>
represent to the very same variable. - A named variable starts to exist when it is assigned a value for the first time.
- You can check if a named parameter already exists with the unary operation
EXISTS[arg]
.
Example:IF [EXISTS[#<_args.c>] EQ 0] THEN GOTO 10
- When a macro is called the passed arguments can be read using the correspondent named variable preceded by
_args
. Example: to get the value of thex
argument you can use#<_args.x>
.
2.2.1 Global and local scopes
A named parameter whose name starts with _
is local to the scope in which it is created. A local named variable vanishes when its scope is left. Indeed, when a local variable is declared in a subroutine and the subroutine returns, the variable is deleted and cannot be referred to anymore.
#<named_variable>
is a global named variable.#<_named_variable>
is a local named variable.
2.2.2 Indexing support
Both global and local variables support indexing with a syntax similar to C style arrays.
Every expression between brackets ([
,]
) in a variable name is evaluated by the G-code interpreter.
Examples:
#<named_variable[#<index>]>
is evaluated as#<named_variable[10]>
if#<index>
has been previously set to 10.#<named_variable[#<index1> + 1][#<index2>]>
is evaluated depending on the variables#<index1>
and#<index2>
2.2.3 Pre-defined Named Parameters
The G-Code compiler has a pre-defined set of read-only named parameters which can be useful in the Program/Macro/MDI editing.
There are nine groups:
#<sys.xxx>
which contains info about the system.
#<math.xxx>
which contains usefull math constants.
#<cnc.xxx>
which contains some of CNC setup settings.
#<compile.xxx>
which contains the compile enums.
#<kinematics.xxx>
which contains the kinematics enums.
#<axis.xxx>
which contains the axis enums.
#<tool.xxx>
which contains the tool enums.
#<probe.xxx>
which contains the probe enums.
#<wait_input>
which contains theM66
wait enums.
#<pick_place.xxx>
which contains the ATCM enums.
Named Variable | Description |
---|---|
#<sys.version.major> | The major version of CNC Core System (e.g. returns 0 of 0.3.7.167 version) |
#<sys.version.minor> | The minor version of CNC Core System (e.g. returns 3 of 0.3.7.167 version) |
#<sys.version.release> | The release version of CNC Core System (e.g. returns 7 of 0.3.7.167 version) |
#<sys.version.build> | The build version of CNC Core System (e.g. returns 167 of 0.3.7.167 version) |
#<sys.customer_id> | The customer ID (usually values 0) |
#<sys.interface_level> | Interface Level (for Control Software 1.9.2 will be 9 ) |
#<sys.ui.units_mode> | User Interface units mode:20 = Imperial (in)21 = Metric (mm) |
|
|
|
|
#<math.max> | Max value (1.7e+308) |
#<math.min> | Min value (5e-324) |
#<math.nan> | NaN value (-NAN) |
#<math.infinity> | Infinity value (+INF) |
#<math.neg_infinity> | Negative infinity value (-NAN) |
#<math.e> | Euler's number (2.7182818284590452354) |
#<math.pi> | Archimedes constant (3.14159274101257324218) |
#<math.ln_2> | Natural Log of 2 (0.69314718055994530942) |
#<math.ln_10> | Natural Log of 10 (2.30258509299404568402) |
#<math.ln_pi> | Natural Log of pi (1.14472988584940017414) |
#<math.to_mm> | Factor to convert inches to mm (25.4) |
#<math.to_in> | Factor to convert mm to inches (1/25.4) |
#<math.to_rad> | Factor to convert deg to rad (PI/180) |
#<math.to_deg> | Factor to convert rad to deg (180/PI) |
|
|
|
|
#<cnc.compile.mode> | Describes the modality of G-Code compilation (see #<compile.xxx> section for a detailed description) |
#<cnc.compile.line> | Contains the staring G-Code line for the compile modes #<compile.mode_program_from_line> and #<compile.mode_program_for_resume_from_line> |
|
|
|
|
#<cnc.machine_type> | Machine Type: 0 = Mill |
#<cnc.kinematics_model> | Describes the Kinematics Model in use (see #<kinematics.xxx> section for a detailed description) |
|
|
#<cnc.x.type> | X Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.x.max_vel> | X Axis Max Velocity [mm/min] |
#<cnc.x.acc> | X Axis Acceleration [mm/s²] |
#<cnc.x.min_lim> | X Axis Min Limit [mm] |
#<cnc.x.max_lim> | X Axis Max Limit [mm] |
|
|
#<cnc.y.type> | Y Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.y.max_vel> | Y Axis Max Velocity [mm/min] |
#<cnc.y.acc> | Y Axis Acceleration [mm/s²] |
#<cnc.y.min_lim> | Y Axis Min Limit [mm] |
#<cnc.y.max_lim> | Y Axis Max Limit [mm] |
|
|
#<cnc.z.type> | Z Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.z.max_vel> | Z Axis Max Velocity [mm/min] |
#<cnc.z.acc> | Z Axis Acceleration [mm/s²] |
#<cnc.z.min_lim> | Z Axis Min Limit [mm] |
#<cnc.z.max_lim> | Z Axis Max Limit [mm] |
|
|
#<cnc.a.type> | A Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.a.max_vel> | A Axis Max Velocity [mm/min] |
#<cnc.a.acc> | A Axis Acceleration [mm/s²] |
#<cnc.a.min_lim> | A Axis Min Limit [mm] |
#<cnc.a.max_lim> | A Axis Max Limit [mm] |
#<cnc.a.motion_mode> | A Axis Motion Mode: 0 = Continuous 1 = Indexing |
#<cnc.a.convention> | A Axis Convention: 0 = Normal 1 = Inverse |
#<cnc.a.wrapped_rotary> | A Axis Wrapped Rotary State: 0 = Disabled 1 = Enabled |
#<cnc.a.parallel_to> | A Axis Parallet to: 0 = X 1 = Y 2 = Z |
#<cnc.a.origin_mode> | A Axis Origin Mode: 0 = Custom 1 = WCS 1 - G54 2 = WCS 2 - G55 3 = WCS 3 - G56 4 = WCS 4 - G57 5 = WCS 5 - G58 6 = WCS 6 - G59 7 = WCS 7 - G59.1 8 = WCS 8 - G59.2 9 = WCS 9 - G59.3 |
#<cnc.a.origin_x> | A Axis Origin X [mm] |
#<cnc.a.origin_y> | A Axis Origin Y [mm] |
#<cnc.a.origin_z> | A Axis Origin Z [mm] |
|
|
#<cnc.b.type> | B Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.b.max_vel> | B Axis Max Velocity [mm/min] |
#<cnc.b.acc> | B Axis Acceleration [mm/s²] |
#<cnc.b.min_lim> | B Axis Min Limit [mm] |
#<cnc.b.max_lim> | B Axis Max Limit [mm] |
#<cnc.b.motion_mode> | B Axis Motion Mode: 0 = Continuous 1 = Indexing |
#<cnc.b.convention> | B Axis Convention: 0 = Normal 1 = Inverse |
#<cnc.b.wrapped_rotary> | B Axis Wrapped Rotary State: 0 = Disabled 1 = Enabled |
#<cnc.b.parallel_to> | B Axis Parallet to: 0 = X 1 = Y 2 = Z |
#<cnc.b.origin_mode> | B Axis Origin Mode: 0 = Custom 1 = WCS 1 - G54 2 = WCS 2 - G55 3 = WCS 3 - G56 4 = WCS 4 - G57 5 = WCS 5 - G58 6 = WCS 6 - G59 7 = WCS 7 - G59.1 8 = WCS 8 - G59.2 9 = WCS 9 - G59.3 |
#<cnc.b.origin_x> | B Axis Origin X [mm] |
#<cnc.b.origin_y> | B Axis Origin Y [mm] |
#<cnc.b.origin_z> | B Axis Origin Z [mm] |
|
|
#<cnc.c.type> | C Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.c.max_vel> | C Axis Max Velocity [mm/min] |
#<cnc.c.acc> | C Axis Acceleration [mm/s²] |
#<cnc.c.min_lim> | C Axis Min Limit [mm] |
#<cnc.c.max_lim> | C Axis Max Limit [mm] |
#<cnc.c.motion_mode> | C Axis Motion Mode: 0 = Continuous 1 = Indexing |
#<cnc.c.convention> | C Axis Convention: 0 = Normal 1 = Inverse |
#<cnc.c.wrapped_rotary> | C Axis Wrapped Rotary State: 0 = Disabled 1 = Enabled |
#<cnc.c.parallel_to> | C Axis Parallet to: 0 = X 1 = Y 2 = Z |
#<cnc.c.origin_mode> | C Axis Origin Mode: 0 = Custom 1 = WCS 1 - G54 2 = WCS 2 - G55 3 = WCS 3 - G56 4 = WCS 4 - G57 5 = WCS 5 - G58 6 = WCS 6 - G59 7 = WCS 7 - G59.1 8 = WCS 8 - G59.2 9 = WCS 9 - G59.3 |
#<cnc.c.origin_x> | C Axis Origin X [mm] |
#<cnc.c.origin_y> | C Axis Origin Y [mm] |
#<cnc.c.origin_z> | C Axis Origin Z [mm] |
|
|
#<cnc.u.type> | U Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.u.max_vel> | U Axis Max Velocity [mm/min] |
#<cnc.u.acc> | U Axis Acceleration [mm/s²] |
#<cnc.u.min_lim> | U Axis Min Limit [mm] |
#<cnc.u.max_lim> | U Axis Max Limit [mm] |
|
|
#<cnc.v.type> | V Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.v.max_vel> | V Axis Max Velocity [mm/min] |
#<cnc.v.acc> | V Axis Acceleration [mm/s²] |
#<cnc.v.min_lim> | V Axis Min Limit [mm] |
#<cnc.v.max_lim> | V Axis Max Limit [mm] |
|
|
#<cnc.w.type> | W Axis Type (see #<axis.type.xxx> section for a detailed description) |
#<cnc.w.max_vel> | W Axis Max Velocity [mm/min] |
#<cnc.w.acc> | W Axis Acceleration [mm/s²] |
#<cnc.w.min_lim> | W Axis Min Limit [mm] |
#<cnc.w.max_lim> | W Axis Max Limit [mm] |
|
|
|
|
#<cnc.spindle.max_speed> | Spindle Max Speed [rpm] |
|
|
#<cnc.rotary_table.d_x> | Rotary Table D:X [mm] |
#<cnc.rotary_table.d_y> | Rotary Table D:Y [mm] |
#<cnc.rotary_table.d_z> | Rotary Table D:Z [mm] |
|
|
#<cnc.tilting_spindle.h_x> | Tilting Spindle H:X [mm] |
#<cnc.tilting_spindle.h_y> | Tilting Spindle H:Y [mm] |
#<cnc.tilting_spindle.h_z> | Tilting Spindle H:Z [mm] |
#<cnc.tilting_spindle.j_x> | Tilting Spindle J:X [mm] |
#<cnc.tilting_spindle.j_y> | Tilting Spindle J:Y [mm] |
#<cnc.tilting_spindle.j_z> | Tilting Spindle J:Z [mm] |
|
|
|
|
#<compile.mode_mdi> | The G-Code compiler is compiling an MDI command |
#<compile.mode_macro> | The G-Code compiler is compiling a Macro (from User Input or a Top Toolbar Button) |
#<compile.mode_program> | The G-Code compiler is compiling the main Program |
#<compile.mode_program_from_line> | The G-Code compiler is compiling the main Program starting from a specified line of code |
#<compile.mode_program_for_resume> | The G-Code compiler is compiling the main Program for a RESUME command after a STOP command |
#<compile.mode_program_for_resume_from_line> | The G-Code compiler is compiling the main Program for a RESUME from specific line after a STOP command |
#<compile.mode_program_for_analysis'> | The G-Code compiler is compiling the main Program for analysis |
|
|
|
|
#<kinematics.model.trivial> | Kinematics Model: Trivial (0) |
#<kinematics.model.independent_rot_axes> | Kinematics Model: Independent Rotational Axes (1) |
#<kinematics.model.rotary_table_ac> | Kinematics Model: Rotary Table AC (2) |
#<kinematics.model.rotary_table_bc> | Kinematics Model: Rotary Table BC (3) |
#<kinematics.model.tilting_spindle_ca> | Kinematics Model: Tilting Spindle CA (4) |
#<kinematics.model.tilting_spindle_ab> | Kinematics Model: Tilting Spindle AB (5) |
|
|
|
|
#<axis.type.disabled> | Axis Type: Disabled (0) |
#<axis.type.linear> | Axis Type: Linear (1) |
#<axis.type.rotary_free> | Axis Type: Rotary Free (2) |
#<axis.type.rotary_head> | Axis Type: Rotary Head (3) |
#<axis.type.rotary_table> | Axis Type: Rotary Table (4) |
#<axis.type.gantry_1> | Axis Type: Gantry 1 (5) |
#<axis.type.gantry_2> | Axis Type: Gantry 2 (6) |
|
|
|
|
#<tool.type.generic> | Tool Type: Generic (0) |
#<tool.type.flat_end_mill> | Tool Type: Flat End Mill (1) |
#<tool.type.ball_nose_end_mill> | Tool Type: Ball Nose End Mill (2) |
#<tool.type.drill> | Tool Type: Drill (3) |
#<tool.type.probe> | Tool Type: Probe (4) |
#<tool.type.saw> | Tool Type: Saw (5) |
#<tool.type.plasma> | Tool Type: Plasma (6) |
#<tool.type.drag_knife> | Tool Type: Drag Knife (7) |
#<tool.type.lathe> | Tool Type: Lathe (8) |
|
|
|
|
#<probe.state.succeed> | Probe State: Succeeded (0). Probe state is available at #5700 . |
#<probe.state.not_tripped> | Probe State: Not Tripped (-1). Probe state is available at #5700 . |
#<probe.state.already_tripped> | Probe State: Already Tripped (-2). Probe state is available at #5700 . |
#<probe.state.not_yet_executed> | Probe State: Not Yet Executed (#0 or <#<math.nan>). Probe state is available at #5700 . |
|
|
|
|
#<wait_input.low> | M66 L parameter: Waits for the selected input to reach the LOW state (0) |
#<wait_input.high> | M66 L parameter: Waits for the selected input to reach the HIGH state (1) |
#<wait_input.fall> | M66 L parameter: Waits for the selected input to perform a FALL event (2) |
#<wait_input.rise> | M66 L parameter: Waits for the selected input to perform a RISE event (3) |
#<wait_input.immediate> | M66 L parameter: Return immediately and the input value is stored in #5720 (4) |
#<wait_input.alarm_low> | M66 L parameter: Waits for the selected input to reach the LOW state and generate a CNC alarm if timeout elapses while waiting (10) |
#<wait_input.alarm_high> | M66 L parameter: Waits for the selected input to reach the HIGH state and generate a CNC alarm if timeout elapses while waiting (11) |
#<wait_input.alarm_fall> | M66 L parameter: Waits for the selected input to perform a FALL event and generate a CNC alarm if timeout elapses while waiting (12) |
#<wait_input.alarm_rise> | M66 L parameter: Waits for the selected input to perform a RISE event and generate a CNC alarm if timeout elapses while waiting (13) |
#<wait_input.succees> | Status of the last M66 in #5722 : “Wait Input” operation ended with success state (0) |
#<wait_input.failure> | Status of the last M66 in #5722 : “Wait Input” operation ended with failure state (1) |
|
|
|
|
#<pick_place.mode_pick> | ATCM panel called the macro atcm_pick_place_tool.ngc for a PICK action |
#<pick_place.mode_place> | ATCM panel called the macro atcm_pick_place_tool.ngc for a PLACE action |
#<pick_place.mode_place_pick> | ATCM panel called the macro atcm_pick_place_tool.ngc for a PLACE and PICK action |
2.2.4 Examples
G17 G21 G40 G49 G80 G90 F1000 ; Create a global variable named "variable1". #<variable1> = 123 ; Create a local variable named "_variable2". #<_variable2> = 456 ; Use the global variable in a comparison. IF [#<variable1> EQ 123] THEN1 ; Use the global variable as target position. G1 X#<variable1> END1 ; Call the subroutine O1000 M98 P1000 ; Use the global variable whose value has been updated by the subroutine. G1 X#<variable1> ; Use the local variable as the target position. ; Since it is a local variable its value has remained 456 and it has not been changed by the subroutine. G1 Y#<_variable2> ; You can check for the existence of a named parameter IF [EXISTS[#<_variable2>]] THEN2 M109 P"Named parameter _variable2 exists and its value is #<_variable2>." END2 ; Call the subroutine O1002 as a macro to pass the arguments A and B G65 P1002 A0 B0 ; Named variables indexing support. #1 = 0 #<_index> = 1 ; Every expression between brackets is evaluated by the G-code interpreter. #<array[#<_index>]> = 12 #<array[#1+2]>= 34 ; Multiple brackets groups can be used to mimic tables. #<array[#1][2]>= 78 ; Indexed named variables value can be printed using messages. M109 P"array[1]=#<array[#<_index>]> array[2]=#<array[#1+2]> array[0][2]=#<array[#1][2]>" M2 ; Define the subroutine O1000 O1000 ; Update the global variable #<variable1> = 987 ; Create a local variable named "_variable2". ; The scope of this variable is local: ; It does not refer to the variable "_variable2" created outside of this subroutine #<_variable2> = 789 ; Use the global variable as target position. G1 Y#<_variable2> M99 ; Define the subroutine O1002. ; This subroutine expects to be called as a macro (using G65) because it expects 2 arguments. O1002 IF [EXISTS[#<_args.c>] EQ 0] THEN4 ; The argument C is not defined therefore we can initialise it to a default value. ; This way we can handle optional arguments. #<_args.c> = 10 G1 X10 END4 IF [#<_args.a> EQ 0] THEN1 IF [#<_args.b> EQ 0] THEN2 M5 ELSE2 M3 END2 ELSE1 IF [#<_args.b> EQ 0] THEN3 M99 ELSE3 M9 END3 END1 M99