From 53d2e26aedc9438220b1cb9ad78f7d1fdf2d6c5f Mon Sep 17 00:00:00 2001 From: Marcio Teixeira Date: Wed, 18 Apr 2018 13:49:01 -0600 Subject: [PATCH] Fix for Cura pausing after probe on Hibiscus (T2381) - Added ability in Marlin to execute GCODE macros immediately. - Reimplemented the G29 functionality for Hibiscus. - Should no longer cause out-of-order execution of start GCODE lines. - Properly issues an "ok" so that Cura does not get hung up. - Added status messages during a probe fail recovery. --- Marlin/Conditionals_LulzBot.h | 79 ++++++++++++++++++++--------------- Marlin/Marlin_main.cpp | 35 ++++++++++++---- 2 files changed, 72 insertions(+), 42 deletions(-) diff --git a/Marlin/Conditionals_LulzBot.h b/Marlin/Conditionals_LulzBot.h index cac8e8c83..f299c9e05 100644 --- a/Marlin/Conditionals_LulzBot.h +++ b/Marlin/Conditionals_LulzBot.h @@ -13,7 +13,7 @@ * got disabled. */ -#define LULZBOT_FW_VERSION ".29" // Change this with each update +#define LULZBOT_FW_VERSION ".30" // Change this with each update #if ( \ !defined(LULZBOT_Gladiola_Mini) && \ @@ -625,7 +625,7 @@ } #if defined(LULZBOT_USE_Z_BELT) - #define LULZBOT_MENU_AXIS_LEVELING_GCODE "G28\nG0 Z5 F6000\nG91\nM211 S0\nM400\nM906 Z600\nG0 Z-15 F500\nG90\nM400\nM906 Z960\nM211 S1\nG28\nM117 Leveling done." + #define LULZBOT_MENU_AXIS_LEVELING_GCODE "M117 Leveling X Axis\nG28\nG0 Z5 F6000\nG91\nM211 S0\nM400\nM906 Z600\nG0 Z-15 F500\nG90\nM400\nM906 Z960\nM211 S1\nG28\nM117 Leveling done." #endif /*************************** COMMON TOOLHEADS PARAMETERS ***********************/ @@ -1542,46 +1542,57 @@ complex recovery sequence */ #if defined(LULZBOT_USE_Z_BELT) - #define LULZBOT_REWIPE_GCODE LULZBOT_MENU_AXIS_LEVELING_GCODE "\nG12 P0 S12 T0" + #define LULZBOT_REWIPE_GCODE LULZBOT_MENU_AXIS_LEVELING_GCODE "\nM117 Rewiping nozzle\nG12 P0 S12 T0\nM117 Probing bed" #else #define LULZBOT_REWIPE_GCODE "G0 Z10\nG12 P0 S12 T0" #endif #define LULZBOT_DO_PROBE_MOVE(speed) if (do_probe_move(LULZBOT_BED_PROBE_MIN, speed)) return NAN; - #define LULZBOT_PROBE_RETRY_COUNTER_DECL int reprobe_retries_left = LULZBOT_NUM_REWIPES; - - #define LULZBOT_G29_WITH_RETRY \ - { \ - LULZBOT_ENABLE_PROBE_PINS(true); \ + #define LULZBOT_EXECUTE_IMMEDIATE_DECL \ + void execute_commands_immediate_P(const char *pgcode); + + #define LULZBOT_EXECUTE_IMMEDIATE_IMPL \ + void execute_commands_immediate_P(const char *pgcode) { \ + char cmd[30]; \ + while(pgm_read_byte_near(pgcode) != '\0') { \ + const char *delim = strchr_P(pgcode, '\n'); \ + size_t len = delim ? delim - pgcode : strlen_P(pgcode); \ + strncpy_P(cmd, pgcode, len); \ + cmd[len] = '\0'; \ + pgcode += len; \ + if(delim) { \ + pgcode++; \ + } \ + parser.parse(cmd); \ + process_parsed_command(false); \ + } \ + } + + #define LULZBOT_G29_WITH_RETRY_DECL \ + void gcode_G29_with_retry(); + + #define LULZBOT_G29_WITH_RETRY_IMPL \ + void gcode_G29_with_retry() { \ set_bed_leveling_enabled(false); \ - gcode_G29(); \ + for(uint8_t i = 0; i < LULZBOT_NUM_REWIPES; i++) { \ + LULZBOT_ENABLE_PROBE_PINS(true); \ + gcode_G29(); \ + LULZBOT_ENABLE_PROBE_PINS(false); \ + if(planner.leveling_active) break; \ + execute_commands_immediate_P(PSTR(LULZBOT_REWIPE_GCODE)); \ + } \ if(planner.leveling_active) { \ - /* Probe succeeded */ \ - reprobe_retries_left = LULZBOT_NUM_REWIPES; \ - } else if(reprobe_retries_left > 0) { \ - /* Probe failed, but we still have retries left */ \ - reprobe_retries_left--; \ - SERIAL_ERRORLNPGM(MSG_REWIPE); \ - LCD_MESSAGEPGM(MSG_REWIPE); \ - enqueue_and_echo_commands_P(PSTR(LULZBOT_REWIPE_GCODE "\nG29")); \ + execute_commands_immediate_P(PSTR("M117 Probe successful")); \ } else { \ - /* Probe failed; no retries left */ \ - SERIAL_ERRORLNPGM("PROBE FAIL CLEAN NOZZLE"); /* cura listens for this message specifically */ \ - LCD_MESSAGEPGM(MSG_ERR_PROBING_FAILED); /* use a more friendly message on the LCD */ \ - BUZZ(25, 880); BUZZ(50, 0); /* play tone */ \ - BUZZ(25, 880); BUZZ(50, 0); \ - BUZZ(25, 880); BUZZ(50, 0); \ - do_blocking_move_to_z(100, MMM_TO_MMS(Z_PROBE_SPEED_FAST)); /* raise head */ \ - current_position[E_AXIS] = 0; /* prime nozzle at 75 mm/sec */ \ - planner.buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 75./60, active_extruder); \ - sync_plan_position_e(); \ - stepper.synchronize(); \ - kill(PSTR(MSG_ERR_PROBING_FAILED)); /* stop print job */ \ + SERIAL_ERRORLNPGM("PROBE FAIL CLEAN NOZZLE"); \ + execute_commands_immediate_P(PSTR("M117 Bed leveling failed.\nG0 Z10\nG0 E0\nM300 P25 S880\nM300 P50 S0\nM300 P25 S880\nM300 P50 S0\nM300 P25 S880\nM300 P50 S0\nG4 S1")); \ + kill(PSTR(MSG_ERR_PROBING_FAILED)); \ } \ - LULZBOT_ENABLE_PROBE_PINS(false); \ } + #define LULZBOT_G29_COMMAND gcode_G29_with_retry(); + #else /* Old style rewipe recovery that repeats only the failed probe point after a simple nozzle wipe. */ @@ -1611,17 +1622,19 @@ Nozzle::clean(0, 12, 0, 0); /* wipe nozzle */ \ } - #define LULZBOT_G29_WITH_RETRY \ + #define LULZBOT_G29_COMMAND \ { \ LULZBOT_ENABLE_PROBE_PINS(true); \ gcode_G29(); \ LULZBOT_ENABLE_PROBE_PINS(false); \ } - #define LULZBOT_PROBE_RETRY_COUNTER_DECL + #define LULZBOT_EXECUTE_IMMEDIATE_DECL + #define LULZBOT_EXECUTE_IMMEDIATE_IMPL + #define LULZBOT_G29_WITH_RETRY_DECL + #define LULZBOT_G29_WITH_RETRY_IMPL #endif - /******************************** MOTOR CURRENTS *******************************/ // Values for XYZ vary by printer model, values for E vary by toolhead. diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4edca0a07..50f8f3827 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -360,7 +360,8 @@ #include "AO_FT810_UI_Screens.h" #endif -LULZBOT_PROBE_RETRY_COUNTER_DECL +LULZBOT_EXECUTE_IMMEDIATE_DECL +LULZBOT_G29_WITH_RETRY_DECL bool Running = true; @@ -737,7 +738,11 @@ void stop(); void get_available_commands(); void process_next_command(); +#if defined(LULZBOT_EXECUTE_IMMEDIATE_IMPL) +void process_parsed_command(bool printok = true); +#else void process_parsed_command(); +#endif void get_cartesian_from_steppers(); void set_current_from_steppers_for_axis(const AxisEnum axis); @@ -2384,11 +2389,13 @@ static void clean_up_after_endstop_or_probe_move() { feedrate_mm_s = old_feedrate_mm_s; - if (isnan(measured_z)) { - LCD_MESSAGEPGM(MSG_ERR_PROBING_FAILED); - SERIAL_ERROR_START(); - SERIAL_ERRORLNPGM(MSG_ERR_PROBING_FAILED); - } + #if !defined(LULZBOT_G29_WITH_RETRY) + if (isnan(measured_z)) { + LCD_MESSAGEPGM(MSG_ERR_PROBING_FAILED); + SERIAL_ERROR_START(); + SERIAL_ERRORLNPGM(MSG_ERR_PROBING_FAILED); + } + #endif return measured_z; } @@ -11712,7 +11719,11 @@ inline void gcode_T(const uint8_t tmp_extruder) { /** * Process the parsed command and dispatch it to its handler */ -void process_parsed_command() { +void process_parsed_command( +#if defined(LULZBOT_EXECUTE_IMMEDIATE_IMPL) + bool printok +#endif +) { KEEPALIVE_STATE(IN_HANDLER); // Handle a known G, M, or T @@ -11808,8 +11819,8 @@ void process_parsed_command() { #if HAS_LEVELING case 29: // G29 Detailed Z probe, probes the bed at 3 or more points, // or provides access to the UBL System if enabled. - #if defined(LULZBOT_G29_WITH_RETRY) - LULZBOT_G29_WITH_RETRY + #if defined(LULZBOT_G29_COMMAND) + LULZBOT_G29_COMMAND #else gcode_G29(); #endif @@ -12576,6 +12587,9 @@ void process_parsed_command() { KEEPALIVE_STATE(NOT_BUSY); + #if defined(LULZBOT_EXECUTE_IMMEDIATE_IMPL) + if(printok) + #endif ok_to_send(); } @@ -14748,3 +14762,6 @@ void loop() { endstops.report_state(); idle(); } + +LULZBOT_G29_WITH_RETRY_IMPL +LULZBOT_EXECUTE_IMMEDIATE_IMPL