Go to the source code of this file.
Data Structures | |
| struct | gc_modal_t |
| NOTE: When this struct is zeroed, the above defines set the defaults for the system. More... | |
| struct | gc_values_t |
| struct | parser_state_t |
| struct | parser_block_t |
Macros | |
| #define | MODAL_GROUP_G0 0 |
| Define modal group internal numbers for checking multiple command violations and tracking the. More... | |
| #define | MODAL_GROUP_G1 1 |
| [G0,G1,G2,G3,G38.2,G38.3,G38.4,G38.5,G80] Motion More... | |
| #define | MODAL_GROUP_G2 2 |
| [G17,G18,G19] Plane selection More... | |
| #define | MODAL_GROUP_G3 3 |
| [G90,G91] Distance mode More... | |
| #define | MODAL_GROUP_G4 4 |
| [G91.1] Arc IJK distance mode More... | |
| #define | MODAL_GROUP_G5 5 |
| [G93,G94] Feed rate mode More... | |
| #define | MODAL_GROUP_G6 6 |
| [G20,G21] Units More... | |
| #define | MODAL_GROUP_G7 7 |
| [G40] Cutter radius compensation mode. G41/42 NOT SUPPORTED. More... | |
| #define | MODAL_GROUP_G8 8 |
| [G43.1,G49] Tool length offset More... | |
| #define | MODAL_GROUP_G12 9 |
| [G54,G55,G56,G57,G58,G59] Coordinate system selection More... | |
| #define | MODAL_GROUP_G13 10 |
| [G61] Control mode More... | |
| #define | MODAL_GROUP_M4 11 |
| [M0,M1,M2,M30] Stopping More... | |
| #define | MODAL_GROUP_M7 12 |
| [M3,M4,M5] Spindle turning More... | |
| #define | MODAL_GROUP_M8 13 |
| [M7,M8,M9] Coolant control More... | |
| #define | NON_MODAL_NO_ACTION 0 |
| #define OTHER_INPUT_F 14 More... | |
| #define | NON_MODAL_DWELL 4 |
| G4 (Do not alter value) More... | |
| #define | NON_MODAL_SET_COORDINATE_DATA 10 |
| G10 (Do not alter value) More... | |
| #define | NON_MODAL_GO_HOME_0 28 |
| G28 (Do not alter value) More... | |
| #define | NON_MODAL_SET_HOME_0 38 |
| G28.1 (Do not alter value) More... | |
| #define | NON_MODAL_GO_HOME_1 30 |
| G30 (Do not alter value) More... | |
| #define | NON_MODAL_SET_HOME_1 40 |
| G30.1 (Do not alter value) More... | |
| #define | NON_MODAL_ABSOLUTE_OVERRIDE 53 |
| G53 (Do not alter value) More... | |
| #define | NON_MODAL_SET_COORDINATE_OFFSET 92 |
| G92 (Do not alter value) More... | |
| #define | NON_MODAL_RESET_COORDINATE_OFFSET 102 |
| #define | MOTION_MODE_SEEK 0 |
| Modal Group G1: Motion modes. More... | |
| #define | MOTION_MODE_LINEAR 1 |
| G1 (Do not alter value) More... | |
| #define | MOTION_MODE_CW_ARC 2 |
| G2 (Do not alter value) More... | |
| #define | MOTION_MODE_CCW_ARC 3 |
| G3 (Do not alter value) More... | |
| #define | MOTION_MODE_PROBE_TOWARD 140 |
| G38.2 (Do not alter value) More... | |
| #define | MOTION_MODE_PROBE_TOWARD_NO_ERROR 141 |
| G38.3 (Do not alter value) More... | |
| #define | MOTION_MODE_PROBE_AWAY 142 |
| G38.4 (Do not alter value) More... | |
| #define | MOTION_MODE_PROBE_AWAY_NO_ERROR 143 |
| G38.5 (Do not alter value) More... | |
| #define | MOTION_MODE_NONE 80 |
| G80 (Do not alter value) More... | |
| #define | PLANE_SELECT_XY 0 |
| Modal Group G2: Plane select. More... | |
| #define | PLANE_SELECT_ZX 1 |
| G18 (Do not alter value) More... | |
| #define | PLANE_SELECT_YZ 2 |
| G19 (Do not alter value) More... | |
| #define | DISTANCE_MODE_ABSOLUTE 0 |
| Modal Group G3: Distance mode. More... | |
| #define | DISTANCE_MODE_INCREMENTAL 1 |
| G91 (Do not alter value) More... | |
| #define | DISTANCE_ARC_MODE_INCREMENTAL 0 |
| Modal Group G4: Arc IJK distance mode. More... | |
| #define | PROGRAM_FLOW_RUNNING 0 |
| Modal Group M4: Program flow. More... | |
| #define | PROGRAM_FLOW_PAUSED 3 |
| M0. More... | |
| #define | PROGRAM_FLOW_OPTIONAL_STOP 1 |
| M1. More... | |
| #define | PROGRAM_FLOW_COMPLETED_M2 2 |
| NOTE: Not supported, but valid and ignored. More... | |
| #define | PROGRAM_FLOW_COMPLETED_M30 30 |
| M30 (Do not alter value) More... | |
| #define | FEED_RATE_MODE_UNITS_PER_MIN 0 |
| Modal Group G5: Feed rate mode. More... | |
| #define | FEED_RATE_MODE_INVERSE_TIME 1 |
| G93 (Do not alter value) More... | |
| #define | UNITS_MODE_MM 0 |
| Modal Group G6: Units mode. More... | |
| #define | UNITS_MODE_INCHES 1 |
| G20 (Do not alter value) More... | |
| #define | CUTTER_COMP_DISABLE 0 |
| Modal Group G7: Cutter radius compensation mode. More... | |
| #define | CONTROL_MODE_EXACT_PATH 0 |
| Modal Group G13: Control mode. More... | |
| #define | SPINDLE_DISABLE 0 |
| Modal Group M7: Spindle control. More... | |
| #define | SPINDLE_ENABLE_CW PL_COND_FLAG_SPINDLE_CW |
| M3 (. More... | |
| #define | SPINDLE_ENABLE_CCW PL_COND_FLAG_SPINDLE_CCW |
| NOTE: Uses planner condition bit flag) More... | |
| #define | COOLANT_DISABLE 0 |
| NOTE: Uses planner condition bit flag) More... | |
| #define | COOLANT_FLOOD_ENABLE PL_COND_FLAG_COOLANT_FLOOD |
| M8 (. More... | |
| #define | COOLANT_MIST_ENABLE PL_COND_FLAG_COOLANT_MIST |
| NOTE: Uses planner condition bit flag) More... | |
| #define | TOOL_LENGTH_OFFSET_CANCEL 0 |
| NOTE: Uses planner condition bit flag) More... | |
| #define | TOOL_LENGTH_OFFSET_ENABLE_DYNAMIC 1 |
| G43.1. More... | |
| #define | WORD_F 0 |
| Modal Group G12: Active work coordinate system. More... | |
| #define | WORD_I 1 |
| #define | WORD_J 2 |
| #define | WORD_K 3 |
| #define | WORD_L 4 |
| #define | WORD_N 5 |
| #define | WORD_P 6 |
| #define | WORD_R 7 |
| #define | WORD_S 8 |
| #define | WORD_T 9 |
| #define | WORD_X 10 |
| #define | WORD_Y 11 |
| #define | WORD_Z 12 |
| #define | GC_UPDATE_POS_TARGET 0 |
| Define g-code parser position updating flags. More... | |
| #define | GC_UPDATE_POS_SYSTEM 1 |
| #define | GC_UPDATE_POS_NONE 2 |
| #define | GC_PROBE_FOUND GC_UPDATE_POS_SYSTEM |
| Define probe cycle exit states and assign proper position updating. More... | |
| #define | GC_PROBE_ABORT GC_UPDATE_POS_NONE |
| #define | GC_PROBE_FAIL_INIT GC_UPDATE_POS_NONE |
| #define | GC_PROBE_FAIL_END GC_UPDATE_POS_TARGET |
| #define | GC_PROBE_CHECK_MODE GC_UPDATE_POS_TARGET |
| #define | GC_PARSER_NONE 0 |
| Define gcode parser flags for handling special cases. More... | |
| #define | GC_PARSER_JOG_MOTION bit(0) |
| #define | GC_PARSER_CHECK_MANTISSA bit(1) |
| #define | GC_PARSER_ARC_IS_CLOCKWISE bit(2) |
| #define | GC_PARSER_PROBE_IS_AWAY bit(3) |
| #define | GC_PARSER_PROBE_IS_NO_ERROR bit(4) |
| #define | GC_PARSER_LASER_FORCE_SYNC bit(5) |
| #define | GC_PARSER_LASER_DISABLE bit(6) |
| #define | GC_PARSER_LASER_ISMOTION bit(7) |
Functions | |
| void | gc_init () |
| Initialize the parser. More... | |
| uint8_t | gc_execute_line (char *line) |
| Execute one block of rs275/ngc/g-code. More... | |
| void | gc_sync_position () |
| Set g-code parser position. Input in steps. More... | |
Variables | |
| parser_state_t | gc_state |
| Declare gc extern struct. More... | |
| struct gc_modal_t |
NOTE: When this struct is zeroed, the above defines set the defaults for the system.
| struct gc_values_t |
| struct parser_state_t |
| Data Fields | ||
|---|---|---|
| float | coord_offset[N_AXIS] | Retains the G92 coordinate offset (work coordinates) relative to. |
| float | coord_system[N_AXIS] | Current work coordinate system (G54+). Stores offset from absolute machine. |
| float | feed_rate | Millimeters/min. |
| int32_t | line_number | Last line number sent. |
| gc_modal_t | modal | |
| float | position[N_AXIS] | Where the interpreter considers the tool to be at this point in the code. |
| float | spindle_speed | RPM. |
| uint8_t | tool | Tracks tool number. NOT USED. |
| float | tool_length_offset | Tracks tool length offset value when enabled. |
| struct parser_block_t |
| Data Fields | ||
|---|---|---|
| gc_modal_t | modal | |
| uint8_t | non_modal_command | |
| gc_values_t | values | |
| #define CONTROL_MODE_EXACT_PATH 0 |
| #define COOLANT_DISABLE 0 |
| #define COOLANT_FLOOD_ENABLE PL_COND_FLAG_COOLANT_FLOOD |
| #define COOLANT_MIST_ENABLE PL_COND_FLAG_COOLANT_MIST |
| #define CUTTER_COMP_DISABLE 0 |
| #define DISTANCE_ARC_MODE_INCREMENTAL 0 |
| #define DISTANCE_MODE_ABSOLUTE 0 |
| #define FEED_RATE_MODE_INVERSE_TIME 1 |
| #define FEED_RATE_MODE_UNITS_PER_MIN 0 |
| #define GC_PARSER_NONE 0 |
| #define GC_PROBE_ABORT GC_UPDATE_POS_NONE |
| #define GC_PROBE_CHECK_MODE GC_UPDATE_POS_TARGET |
| #define GC_PROBE_FAIL_END GC_UPDATE_POS_TARGET |
| #define GC_PROBE_FAIL_INIT GC_UPDATE_POS_NONE |
| #define GC_PROBE_FOUND GC_UPDATE_POS_SYSTEM |
| #define GC_UPDATE_POS_TARGET 0 |
| #define MODAL_GROUP_G0 0 |
| #define MODAL_GROUP_G1 1 |
| #define MODAL_GROUP_G12 9 |
| #define MODAL_GROUP_G7 7 |
| #define MOTION_MODE_PROBE_AWAY 142 |
| #define MOTION_MODE_PROBE_AWAY_NO_ERROR 143 |
| #define MOTION_MODE_PROBE_TOWARD 140 |
| #define MOTION_MODE_PROBE_TOWARD_NO_ERROR 141 |
| #define MOTION_MODE_SEEK 0 |
| #define NON_MODAL_ABSOLUTE_OVERRIDE 53 |
| #define NON_MODAL_NO_ACTION 0 |
#define OTHER_INPUT_F 14
Define command actions for within execution-type modal groups (motion, stopping, non-modal). Used NOTE: Some macro values are assigned specific values to make g-code state reporting and parsing Modal Group G0: Non-modal actions (Default: Must be zero)
| #define NON_MODAL_SET_COORDINATE_DATA 10 |
| #define NON_MODAL_SET_COORDINATE_OFFSET 92 |
| #define PLANE_SELECT_XY 0 |
| #define PROGRAM_FLOW_COMPLETED_M2 2 |
| #define PROGRAM_FLOW_COMPLETED_M30 30 |
| #define PROGRAM_FLOW_RUNNING 0 |
| #define SPINDLE_DISABLE 0 |
| #define SPINDLE_ENABLE_CCW PL_COND_FLAG_SPINDLE_CCW |
| #define SPINDLE_ENABLE_CW PL_COND_FLAG_SPINDLE_CW |
| #define TOOL_LENGTH_OFFSET_CANCEL 0 |
| #define UNITS_MODE_MM 0 |
| #define WORD_F 0 |
| uint8_t gc_execute_line | ( | char * | line | ) |
Execute one block of rs275/ngc/g-code.
Execute one block of rs275/ngc/g-code.
STEP 1: Initialize parser block struct and copy current g-code state modes. The parser updates these modes and commands as the block line is parser and will only be used and executed after successful error-checking. The parser block struct also contains a block values struct, word tracking variables, and a non-modal commands tracker for the new block. This struct contains all of the necessary information to execute the block.
< Initialize the parser block struct.
< Copy current modes
< Tracks G10 P coordinate selection for execution
< XYZ tracking
< IJK tracking
< Tracks G and M command words. Also used for modal group violations.
< Tracks value words.
<
NOTE: $J= already parsed when passed to this function.
< Initialize default line number reported during jog.
STEP 2: Import all g-code words in the block line. A g-code word is a letter followed by a number, which can either be a 'G'/'M' command or sets/assigns a command value. Also, perform initial error-checks for command word modal group violations, for any repeated words, and for negative values set for the value words F, N, P, T, and S.
< Bit-value for assigning tracking variables
< Loop until no more g-code words in line.
NOTE: Mantissa is multiplied by 100 to catch non-integer command values. This is more
< Compute mantissa for Gxx.x commands.
NOTE: Rounding must be used to catch small floating point errors.
'G' and 'M' Command Words: Parse commands and check for modal group violations.
/ NOTE: Modal group numbers are defined in Table 4 of NIST RS274-NGC v3, pg.20
< Ignore G28.1, G30.1, and G92.1
< Set to zero to indicate valid non-integer G command.
< [Unsupported G38.x command]
< Set to zero to indicate valid non-integer G command.
< Set to zero to indicate valid non-integer G command.
NOTE: Not required since cutter radius compensation is always disabled. Only here
NOTE: The NIST g-code standard vaguely states that when a tool length offset is changed,
< G49
< G43.1
< Set to zero to indicate valid non-integer G command.
NOTE: G59.x are not supported. (But their int_values would be 60, 61, and 62.)
< Shift to array indexing.
< [Unsupported G command]
NOTE: Variable 'word_bit' is always assigned, if the command is valid.
< Program pause
< Optional stop not supported. Ignore.
< Program end and reset
< [Unsupported M command]
NOTE: Variable 'word_bit' is always assigned, if the command is valid.
NOTE: All remaining letters assign values.
Non-Command Words: This initial parsing phase only checks for repeats of the remaining legal g-code words and stores their value. Error-checking is performed later since some words (I,J,K,L,P,R) have multiple connotations and/or depend on the issued commands.
NOTE: For certain commands, P value must be an integer, but none of these commands are supported.
NOTE: Variable 'word_bit' is always assigned, if the non-command letter is valid.
NOTE: Negative value check is done here simply for code-efficiency.
< Flag to indicate parameter assigned.
| void gc_sync_position | ( | ) |
| parser_state_t gc_state |