diff --git a/gcode.c b/gcode.c index 8a64a91..281a0ee 100644 --- a/gcode.c +++ b/gcode.c @@ -795,10 +795,11 @@ uint8_t gc_execute_line(char *line) break; case MOTION_MODE_PROBE: // [G38 Errors]: Target is same current. No axis words. Cutter compensation is enabled. Feed rate - // is undefined. Probe is triggered. + // is undefined. Probe is triggered. NOTE: Probe check moved to probe cycle. Instead of returning + // an error, it issues an alarm to prevent further motion to the probe. It's also done there to + // allow the planner buffer to empty and move off the probe trigger before another probing cycle. if (!axis_words) { FAIL(STATUS_GCODE_NO_AXIS_WORDS); } // [No axis words] if (gc_check_same_position(gc_state.position, gc_block.values.xyz)) { FAIL(STATUS_GCODE_INVALID_TARGET); } // [Invalid target] - if (probe_get_state()) { FAIL(STATUS_GCODE_PROBE_TRIGGERED); } // [Probe triggered] break; } } diff --git a/motion_control.c b/motion_control.c index 98956f7..a07af59 100644 --- a/motion_control.c +++ b/motion_control.c @@ -276,7 +276,14 @@ void mc_homing_cycle() void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate) #endif { - protocol_buffer_synchronize(); // Finish all queued commands and empty planner buffer. + // Finish all queued commands and empty planner buffer before starting probe cycle. + protocol_buffer_synchronize(); + + // After syncing, check if probe is already triggered. If so, halt and issue alarm. + if (probe_get_state()) { + bit_true_atomic(sys.execute, EXEC_CRIT_EVENT); + protocol_execute_runtime(); + } if (sys.abort) { return; } // Return if system reset has been issued. // Setup and queue probing motion. Auto cycle-start should not start the cycle. diff --git a/nuts_bolts.h b/nuts_bolts.h index 1acaf16..073ed3d 100644 --- a/nuts_bolts.h +++ b/nuts_bolts.h @@ -29,6 +29,7 @@ #define X_AXIS 0 // Axis indexing value. Must start with 0 and be continuous. #define Y_AXIS 1 #define Z_AXIS 2 +// #define A_AXIS 3 #define MM_PER_INCH (25.40) #define INCH_PER_MM (0.0393701) diff --git a/report.h b/report.h index 4f1d768..71e636e 100644 --- a/report.h +++ b/report.h @@ -50,9 +50,8 @@ #define STATUS_GCODE_INVALID_TARGET 33 #define STATUS_GCODE_ARC_RADIUS_ERROR 34 #define STATUS_GCODE_NO_OFFSETS_IN_PLANE 35 -#define STATUS_GCODE_PROBE_TRIGGERED 36 -#define STATUS_GCODE_UNUSED_WORDS 37 -#define STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR 38 +#define STATUS_GCODE_UNUSED_WORDS 36 +#define STATUS_GCODE_G43_DYNAMIC_AXIS_ERROR 37 // Define Grbl alarm codes. Less than zero to distinguish alarm error from status error. #define ALARM_LIMIT_ERROR -1 diff --git a/settings.c b/settings.c index c64b0a4..451c8d3 100644 --- a/settings.c +++ b/settings.c @@ -25,6 +25,7 @@ #include "protocol.h" #include "report.h" #include "limits.h" +#include "stepper.h" settings_t settings; @@ -194,8 +195,14 @@ uint8_t settings_store_global_setting(uint8_t parameter, float value) { if (int_value < 3) { return(STATUS_SETTING_STEP_PULSE_MIN); } settings.pulse_microseconds = int_value; break; case 1: settings.stepper_idle_lock_time = int_value; break; - case 2: settings.step_invert_mask = int_value; break; - case 3: settings.dir_invert_mask = int_value; break; + case 2: + settings.step_invert_mask = int_value; + st_generate_step_dir_invert_masks(); // Regenerate step and direction port invert masks. + break; + case 3: + settings.dir_invert_mask = int_value; + st_generate_step_dir_invert_masks(); // Regenerate step and direction port invert masks. + break; case 4: // Reset to ensure change. Immediate re-init may cause problems. if (int_value) { settings.flags |= BITFLAG_INVERT_ST_ENABLE; } else { settings.flags &= ~BITFLAG_INVERT_ST_ENABLE; } diff --git a/settings.h b/settings.h index 0d6b671..f741771 100644 --- a/settings.h +++ b/settings.h @@ -24,7 +24,7 @@ #define GRBL_VERSION "0.9g" -#define GRBL_VERSION_BUILD "20140725" +#define GRBL_VERSION_BUILD "20140801" // Version of the EEPROM data. Will be used to migrate existing data from older versions of Grbl // when firmware is upgraded. Always stored in byte 0 of eeprom diff --git a/stepper.c b/stepper.c index 60a71ed..0ca2850 100644 --- a/stepper.c +++ b/stepper.c @@ -439,6 +439,19 @@ ISR(TIMER0_OVF_vect) #endif +// Generates the step and direction port invert masks used in the Stepper Interrupt Driver. +void st_generate_step_dir_invert_masks() +{ + uint8_t idx; + step_port_invert_mask = 0; + dir_port_invert_mask = 0; + for (idx=0; idx