24 #define LINE_FLAG_OVERFLOW bit(0)
25 #define LINE_FLAG_COMMENT_PARENTHESES bit(1)
26 #define LINE_FLAG_COMMENT_SEMICOLON bit(2)
31 static void protocol_exec_rt_suspend();
40 #ifdef CHECK_LIMITS_AT_INIT
71 uint8_t line_flags = 0;
72 uint8_t char_counter = 0;
79 if ((c ==
'\n') || (c ==
'\r')) {
84 line[char_counter] = 0;
85 #ifdef REPORT_ECHO_LINE_RECEIVED
93 }
else if (line[0] == 0) {
96 }
else if (line[0] ==
'$') {
122 }
else if (c ==
'/') {
126 }
else if (c ==
'(') {
133 }
else if (c ==
';') {
148 }
else if (c >=
'a' && c <=
'z') {
149 line[char_counter++] = c-
'a'+
'A';
151 line[char_counter++] = c;
216 if (
sys.
suspend) { protocol_exec_rt_suspend(); }
312 #ifdef PARKING_ENABLE
501 if (sys_rt_exec_debug) {
502 report_realtime_debug();
503 sys_rt_exec_debug = 0;
519 static void protocol_exec_rt_suspend()
521 #ifdef PARKING_ENABLE
523 float restore_target[
N_AXIS];
524 float parking_target[
N_AXIS];
534 uint8_t restore_condition;
535 float restore_spindle_speed;
543 #ifdef DISABLE_LASER_DURING_HOLD
566 #ifndef PARKING_ENABLE
576 memcpy(restore_target,parking_target,
sizeof(parking_target));
651 #ifdef PARKING_ENABLE
688 #ifdef PARKING_ENABLE
void protocol_main_loop()
Starts Grbl main loop. It handles all incoming characters from the serial port and executes...
plan_block_t * plan_get_current_block()
Returns address of first planner block, if available. Called by various main program functions...
#define DEFAULT_FEED_OVERRIDE
#define EXEC_RAPID_OVR_RESET
void plan_sync_position()
Reset the planner position vectors. Called by the system abort/initialization routine.
#define N_AXIS
Axis array index values. Must start with 0 and be continuous.
uint8_t system_check_safety_door_ajar()
Returns if safety door is ajar(T) or closed(F), based on pin state.
#define EXEC_FEED_OVR_COARSE_PLUS
void protocol_auto_cycle_start()
Auto-cycle start triggers when there is a motion ready to execute and if the main program is not...
#define SAFETY_DOOR_COOLANT_DELAY
Float (seconds)
uint8_t serial_read()
Fetches the first byte in the serial read buffer. Called by main program.
#define EXEC_RAPID_OVR_MEDIUM
#define STATE_HOLD
Active feed hold.
#define DEFAULT_RAPID_OVERRIDE
100%. Don't change this value.
void spindle_set_state(uint8_t state, float rpm)
Immediately sets spindle running state with direction and spindle rpm via PWM, if enabled...
void system_convert_array_steps_to_mpos(float *position, int32_t *steps)
Updates a machine 'position' array based on the 'step' array sent.
uint8_t spindle_speed_ovr
Spindle speed value in percent.
#define MESSAGE_SLEEP_MODE
void delay_sec(float seconds, uint8_t mode)
Non-blocking delay function used for general operation and suspend features.
#define SUSPEND_SAFETY_DOOR_AJAR
Tracks safety door state for resuming.
#define MIN_SPINDLE_SPEED_OVERRIDE
Percent of programmed spindle speed (1-100). Usually 10%.
void gc_sync_position()
Sets g-code parser position in mm. Input in steps. Called by the system abort and hard...
uint8_t gc_execute_line(char *line)
Executes one line of 0-terminated G-Code. The line is assumed to contain only uppercase.
void report_status_message(uint8_t status_code)
Handles the primary confirmation protocol response for streaming interfaces and human-feedback.
#define LINE_FLAG_OVERFLOW
Define line flags. Includes comment type tracking and line overflow detection.
#define bit_true(x, mask)
#define STEP_CONTROL_UPDATE_SPINDLE_PWM
uint8_t system_execute_line(char *line)
Directs and executes one line of formatted input from protocol_process. While mostly.
void report_alarm_message(uint8_t alarm_code)
Prints alarm messages.
void report_realtime_status()
Prints realtime status report.
#define SUSPEND_INITIATE_RESTORE
(Safety door only) Flag to initiate resume procedures from a cycle start.
#define PARKING_MOTION_LINE_NUMBER
void system_set_exec_state_flag(uint8_t mask)
Special handlers for setting and clearing Grbl's real-time execution flags.
void protocol_buffer_synchronize()
Block until all buffered steps are executed or in a cycle state. Works with feed hold.
uint8_t suspend
System suspend bitflag variable that manages holds, cancels, and safety door.
Planner data prototype. Must be used when passing new motions to the planner.
void system_clear_exec_accessory_overrides()
#define COOLANT_MIST_ENABLE
NOTE: Uses planner condition bit flag)
void report_feedback_message(uint8_t message_code)
Prints feedback messages. This serves as a centralized method to provide additional.
#define PARKING_TARGET
Parking axis target. In mm, as machine coordinate [-max_travel,0].
#define EXEC_CYCLE_STOP
bitmask 00000100
float spindle_speed
Desired spindle speed through line motion.
void plan_cycle_reinitialize()
Re-initialize buffer plan with a partially completed block, assumed to exist at the buffer tail...
void plan_update_velocity_profile_parameters()
Re-calculates buffered motions profile parameters upon a motion-based override change.
#define PL_COND_ACCESSORY_MASK
#define MESSAGE_ALARM_LOCK
#define PL_COND_FLAG_SPINDLE_CW
void sleep_check()
Checks running conditions for sleep. If satisfied, enables sleep countdown and executes.
volatile uint8_t sys_rt_exec_alarm
Global realtime executor bitflag variable for setting various alarms.
#define MAX_SPINDLE_SPEED_OVERRIDE
Percent of programmed spindle speed (100-255). Usually 200%.
uint8_t condition
Block bitflag variable defining block run conditions. Copied from pl_line_data.
#define SUSPEND_RESTART_RETRACT
Flag to indicate a retract from a restore parking motion.
uint8_t state
Tracks the current system state of Grbl.
#define EXEC_RESET
bitmask 00010000
#define PARKING_PULLOUT_RATE
Pull-out/plunge slow feed rate in mm/min.
#define STEP_CONTROL_EXECUTE_HOLD
#define PARKING_RATE
Parking fast rate after pull-out in mm/min.
#define DEFAULT_SPINDLE_SPEED_OVERRIDE
100%. Don't change this value.
#define EXEC_FEED_OVR_COARSE_MINUS
#define BITFLAG_LASER_MODE
#define SUSPEND_RETRACT_COMPLETE
(Safety door only) Indicates retraction and de-energizing is complete.
void plan_reset()
Initialize and reset the motion plan subsystem.
uint8_t f_override
Feed rate override value in percent.
#define EXEC_SPINDLE_OVR_STOP
#define EXEC_SAFETY_DOOR
bitmask 00100000
#define BITFLAG_HOMING_ENABLE
#define MESSAGE_CHECK_LIMITS
#define PL_COND_FLAG_SYSTEM_MOTION
Single motion. Circumvents planner state. Used by home/park.
float spindle_speed
Block spindle speed. Copied from pl_line_data.
#define LINE_BUFFER_SIZE
Line buffer size from the serial input stream to be executed.
#define SPINDLE_DISABLE
Modal Group M7: Spindle control.
#define MIN_FEED_RATE_OVERRIDE
Percent of programmed feed rate (1-100). Usually 50% or 1%.
uint8_t abort
System abort flag. Forces exit back to main loop for reset.
void mc_parking_motion(float *parking_target, plan_line_data_t *pl_data)
Plans and executes the single special motion case for parking. Independent of main planner buffer...
void system_clear_exec_alarm()
#define STATE_SLEEP
Sleep state.
#define SAFETY_DOOR_SPINDLE_DELAY
This option causes the feed hold input to act as a safety door switch. A safety door, when triggered,.
volatile uint8_t sys_rt_exec_motion_override
Global realtime executor bitflag variable for motion-based overrides.
#define EXEC_ALARM_SOFT_LIMIT
#define STATE_CYCLE
Cycle is running or motions are being executed.
uint8_t flags
Contains default boolean settings.
#define STATUS_SYSTEM_GC_LOCK
#define STATE_CHECK_MODE
G-code check mode. Locks out planner and motion only.
#define PL_COND_FLAG_COOLANT_FLOOD
#define RAPID_OVERRIDE_MEDIUM
Percent of rapid (1-99). Usually 50%.
#define STATE_ALARM
In alarm state. Locks out all g-code processes. Allows settings access.
#define EXEC_CYCLE_START
bitmask 00000010
void report_echo_line_received(char *line)
Prints the character string line Grbl has received from the user, which has been pre-parsed,.
system_t sys
Declare system global variable structure.
uint8_t soft_limit
Tracks soft limit errors for the state machine. (boolean)
#define EXEC_COOLANT_MIST_OVR_TOGGLE
int32_t sys_position[N_AXIS]
NOTE: These position variables may need to be declared as volatiles, if problems arise.
uint8_t report_ovr_counter
Tracks when to add override data to status reports.
#define MESSAGE_SAFETY_DOOR_AJAR
uint8_t coolant
{M7,M8,M9}
#define LINE_FLAG_COMMENT_SEMICOLON
void st_go_idle()
Stepper shutdown.
#define EXEC_SPINDLE_OVR_FINE_PLUS
#define EXEC_SPINDLE_OVR_RESET
#define EXEC_FEED_OVR_FINE_PLUS
void protocol_exec_rt_system()
Executes run-time commands, when required. This function primarily operates as Grbl's state...
void system_clear_exec_state_flag(uint8_t mask)
#define bit_isfalse(x, mask)
#define SPINDLE_STOP_OVR_ENABLED
#define EXEC_COOLANT_FLOOD_OVR_TOGGLE
uint8_t step_control
Governs the step segment generator depending on system state.
void st_prep_buffer()
Prepares step segment buffer. Continuously called from main program.
#define COOLANT_DISABLE
NOTE: Uses planner condition bit flag)
void st_wake_up()
BLOCK VELOCITY PROFILE DEFINITION.
int32_t line_number
Desired line number to report when executing.
#define EXEC_MOTION_CANCEL
bitmask 01000000
#define SUSPEND_MOTION_CANCEL
Indicates a canceled resume motion. Currently used by probing routine.
#define BITFLAG_HARD_LIMIT_ENABLE
#define EXEC_SPINDLE_OVR_COARSE_MINUS
#define EXEC_SLEEP
bitmask 10000000
#define EXEC_ALARM_HARD_LIMIT
Alarm executor codes. Valid values (1-255). Zero is reserved.
volatile uint8_t sys_rt_exec_state
Global realtime executor bitflag variable for state management. See EXEC bitmasks.
#define MAX_FEED_RATE_OVERRIDE
Percent of programmed feed rate (100-255). Usually 120% or 200%.
memset(pl_data, 0, sizeof(plan_line_data_t))
Zero pl_data struct.
uint8_t spindle
{M3,M4,M5}
#define EXEC_FEED_HOLD
bitmask 00001000
memcpy(block_coord_system, gc_state.coord_system, sizeof(gc_state.coord_system))
#define STEP_CONTROL_NORMAL_OP
Define step segment generator state flags.
#define SPINDLE_STOP_OVR_RESTORE
void system_set_exec_accessory_override_flag(uint8_t mask)
uint8_t r_override
Rapids override value in percent.
#define PL_COND_FLAG_NO_FEED_OVERRIDE
Motion does not honor feed override.
#define COOLANT_FLOOD_ENABLE
M8 (.
#define MESSAGE_CRITICAL_EVENT
Define Grbl feedback message codes. Valid values (0-255).
#define EXEC_SPINDLE_OVR_FINE_MINUS
#define SPINDLE_STOP_OVR_INITIATE
plan_line_data_t plan_data
STEP 4: EXECUTE!! Assumes that all error-checking has been completed and no failure modes exist...
#define FEED_OVERRIDE_COARSE_INCREMENT
(1-99). Usually 10%.
#define SPINDLE_OVERRIDE_FINE_INCREMENT
(1-99).
#define LINE_FLAG_COMMENT_PARENTHESES
#define MESSAGE_SPINDLE_RESTORE
#define SPINDLE_STOP_OVR_DISABLED
Define spindle stop override control states.
#define SPINDLE_OVERRIDE_COARSE_INCREMENT
(1-99). Usually 10%.
#define bit_false(x, mask)
#define EXEC_RAPID_OVR_LOW
#define SUSPEND_RESTORE_COMPLETE
(Safety door only) Indicates ready to resume normal operation.
#define STATE_JOG
Jogging mode.
#define STATE_HOMING
Performing homing cycle.
#define SPINDLE_STOP_OVR_RESTORE_CYCLE
void protocol_execute_realtime()
This function is the general interface to Grbl's real-time command execution system. It is called.
float feed_rate
Desired feed rate for line motion. Value is ignored, if rapid motion.
#define RAPID_OVERRIDE_LOW
Percent of rapid (1-99). Usually 25%.
#define SUSPEND_HOLD_COMPLETE
Indicates initial feed hold is complete.
#define SUSPEND_JOG_CANCEL
Indicates a jog cancel in process and to reset buffers when complete.
uint8_t spindle_stop_ovr
Tracks spindle stop override states.
uint8_t condition
Bitflag variable to indicate planner conditions. See defines above.
This struct stores a linear movement of a g-code block motion with its critical "nominal" values...
void st_update_plan_block_parameters()
Called by planner_recalculate() when the executing block is updated by the new plan.
volatile uint8_t sys_rt_exec_accessory_override
Global realtime executor bitflag variable for spindle/coolant overrides.
#define PARKING_AXIS
By default, Grbl disables feed rate overrides for all G38.x probe cycle commands. Although this...
#define STEP_CONTROL_EXECUTE_SYS_MOTION
#define EXEC_STATUS_REPORT
Define system executor bit map. Used internally by realtime protocol as realtime command flags...
#define EXEC_FEED_OVR_RESET
Override bit maps. Realtime bitflags to control feed, rapid, spindle, and coolant overrides...
#define PARKING_PULLOUT_INCREMENT
Spindle pull-out and plunge distance in mm. Incremental distance.
#define SUSPEND_DISABLE
Define system suspend flags. Used in various ways to manage suspend states and procedures.
parser_state_t gc_state
Declare gc extern struct.
#define PL_COND_FLAG_SPINDLE_CCW
void system_execute_startup(char *line)
Executes user startup script, if stored.
#define FEED_OVERRIDE_FINE_INCREMENT
(1-99). Usually 1%.
plan_line_data_t * pl_data
#define STATUS_OK
Define Grbl status codes. Valid values (0-255)
void st_reset()
Reset and clear stepper subsystem variables.
uint8_t limits_get_state()
Returns limit state as a bit-wise uint8 variable. Each bit indicates an axis limit, where.
void system_clear_exec_motion_overrides()
#define EXEC_FEED_OVR_FINE_MINUS
#define STATE_IDLE
Define system state bit map. The state variable primarily tracks the individual functions.
#define DELAY_MODE_SYS_SUSPEND
#define EXEC_SPINDLE_OVR_COARSE_PLUS
void coolant_set_state(uint8_t mode)
Main program only. Immediately sets flood coolant running state and also mist coolant,.
#define bit_istrue(x, mask)
#define STATE_SAFETY_DOOR
Safety door is ajar. Feed holds and de-energizes system.