From c241adec5f732a6592f3899dbd8fc5c871dec426 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 16 Jul 2019 16:17:52 +0200 Subject: [PATCH 1/8] Ensure babystep_apply|undo always uses the planner The code around these calls _requires_ that the steps are immediately processed and/or added to the subsequent planner moves. The only part that doesn't care about immediate insertion is the direct user-insertion though the lcd encoder. --- Firmware/Marlin_main.cpp | 6 ++---- Firmware/mesh_bed_calibration.cpp | 10 ---------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d5b4ff106..fc470f604 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -2722,8 +2722,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon current_position[Z_AXIS] = st_get_position_mm(Z_AXIS); #endif - // Reset baby stepping to zero, if the babystepping has already been loaded before. The babystepsTodo value will be - // consumed during the first movements following this statement. + // Reset baby stepping to zero, if the babystepping has already been loaded before. if (home_z) babystep_undo(); @@ -5161,8 +5160,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) mbl.reset(); //reset mesh bed leveling - // Reset baby stepping to zero, if the babystepping has already been loaded before. The babystepsTodo value will be - // consumed during the first movements following this statement. + // Reset baby stepping to zero, if the babystepping has already been loaded before. babystep_undo(); // Cycle through all points and probe them diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index fb79022ff..b4490e93f 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -3030,8 +3030,6 @@ static void shift_z(float delta) plan_set_z_position(current_position[Z_AXIS]); } -#define BABYSTEP_LOADZ_BY_PLANNER - // Number of baby steps applied static int babystepLoadZ = 0; @@ -3062,20 +3060,12 @@ void babystep_load() void babystep_apply() { babystep_load(); -#ifdef BABYSTEP_LOADZ_BY_PLANNER shift_z(- float(babystepLoadZ) / float(cs.axis_steps_per_unit[Z_AXIS])); -#else - babystepsTodoZadd(babystepLoadZ); -#endif /* BABYSTEP_LOADZ_BY_PLANNER */ } void babystep_undo() { -#ifdef BABYSTEP_LOADZ_BY_PLANNER shift_z(float(babystepLoadZ) / float(cs.axis_steps_per_unit[Z_AXIS])); -#else - babystepsTodoZsubtract(babystepLoadZ); -#endif /* BABYSTEP_LOADZ_BY_PLANNER */ babystepLoadZ = 0; } From ff4e53d2d11a614045e111f10d8fcba900c311dc Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 16 Jul 2019 17:28:28 +0200 Subject: [PATCH 2/8] Prevent babysteps in more unsafe situations through homing_flag Further restrict babystep insertion when the lcd_update is enabled by toggling homing_flag when probing Z (where Z shouldn't be touched anyway as it would disrupt the measurement) Also reset the encoder value during mesh leveling. --- Firmware/Marlin_main.cpp | 7 ++++++- Firmware/ultralcd.cpp | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index fc470f604..23a734d77 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -4753,6 +4753,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) */ case 30: { + homing_flag = true; st_synchronize(); // TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly int l_feedmultiply = setup_for_endstop_move(); @@ -4764,6 +4765,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) printf_P(_N("%S X: %.5f Y: %.5f Z: %.5f\n"), _T(MSG_BED), _x, _y, _z); clean_up_after_endstop_move(l_feedmultiply); + homing_flag = false; } break; @@ -4854,6 +4856,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; } } + + homing_flag = true; // keep homing on to avoid babystepping while the LCD is enabled lcd_update_enable(true); KEEPALIVE_STATE(NOT_BUSY); //no need to print busy messages as we print current temperatures periodicaly SERIAL_ECHOLNPGM("PINDA probe calibration start"); @@ -4898,6 +4902,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) bool find_z_result = find_bed_induction_sensor_point_z(-1.f); if (find_z_result == false) { lcd_temp_cal_show_result(find_z_result); + homing_flag = false; break; } zero_z = current_position[Z_AXIS]; @@ -4948,9 +4953,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) printf_P(_N("\nPINDA temperature: %.1f Z shift (mm): %.3f"), current_temperature_pinda, current_position[Z_AXIS] - zero_z); EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); - } lcd_temp_cal_show_result(true); + homing_flag = false; #else //PINDA_THERMISTOR diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 7f4cfa648..684ec5178 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3108,7 +3108,7 @@ static void lcd_babystep_z() if (lcd_encoder != 0) { - if (homing_flag) lcd_encoder = 0; + if (homing_flag || mesh_bed_leveling_flag) lcd_encoder = 0; _md->babystepMemZ += (int)lcd_encoder; if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm From f5e419530b9bbce689eb2aa7320d85360eb019dd Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Tue, 16 Jul 2019 21:17:37 +0200 Subject: [PATCH 3/8] Inhibit LiveZ from the settings menu during mesh bed leveling --- Firmware/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 684ec5178..25cd55d93 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5789,7 +5789,7 @@ static void lcd_settings_menu() MENU_ITEM_TOGGLE_P(_T(MSG_RPI_PORT), (selectedSerialPort == 0) ? _T(MSG_OFF) : _T(MSG_ON), lcd_second_serial_set); #endif //HAS_SECOND_SERIAL - if (!isPrintPaused && !homing_flag) + if (!isPrintPaused && !homing_flag && !mesh_bed_leveling_flag) MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z); #if (LANG_MODE != 0) From 019c818c05466ea9d8ce66bbd5e1d8cc660cc650 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Sun, 2 Aug 2020 01:36:24 +0200 Subject: [PATCH 4/8] Insert babysteps using CRITICAL_SECTION instead of cli/sei --- Firmware/temperature.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 3a70da21a..35b05f0e8 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -2047,18 +2047,18 @@ FORCE_INLINE static void temperature_isr() if(curTodo>0) { - asm("cli"); + CRITICAL_SECTION_START; babystep(axis,/*fwd*/true); babystepsTodo[axis]--; //less to do next time - asm("sei"); + CRITICAL_SECTION_END; } else if(curTodo<0) { - asm("cli"); + CRITICAL_SECTION_START; babystep(axis,/*fwd*/false); babystepsTodo[axis]++; //less to do next time - asm("sei"); + CRITICAL_SECTION_END; } } #endif //BABYSTEPPING From 28e9c814fc4392a2a99a32ecd84e66b3c98f4656 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Fri, 29 Jan 2021 19:05:32 +0100 Subject: [PATCH 5/8] Remove code duplication for babystep insertion --- Firmware/temperature.h | 19 +++++-------------- Firmware/ultralcd.cpp | 7 +------ 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/Firmware/temperature.h b/Firmware/temperature.h index da88a53c0..0bf944724 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -99,13 +99,10 @@ extern bool bedPWMDisabled; float unscalePID_d(float d); #endif - - -#ifdef BABYSTEPPING - extern volatile int babystepsTodo[3]; -#endif -void resetPID(uint8_t extruder); + +#ifdef BABYSTEPPING +extern volatile int babystepsTodo[3]; inline void babystepsTodoZadd(int n) { @@ -115,15 +112,9 @@ inline void babystepsTodoZadd(int n) CRITICAL_SECTION_END } } +#endif -inline void babystepsTodoZsubtract(int n) -{ - if (n != 0) { - CRITICAL_SECTION_START - babystepsTodo[Z_AXIS] -= n; - CRITICAL_SECTION_END - } -} +void resetPID(uint8_t extruder); //high level conversion routines, for use outside of temperature.cpp //inline so that there is no performance decrease. diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 25cd55d93..d7c7a25d9 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3113,12 +3113,7 @@ static void lcd_babystep_z() if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0 - else - { - CRITICAL_SECTION_START - babystepsTodo[Z_AXIS] += (int)lcd_encoder; - CRITICAL_SECTION_END - } + else babystepsTodoZadd(lcd_encoder); _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS]; _delay(50); From 14a1a93bc84fcccf5aa7ee793f809b10c54006c5 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 24 Feb 2021 16:57:33 +0100 Subject: [PATCH 6/8] Include probing/MBL in the PRINTER_ACTIVE check This prevents to perform disruptive actions during homing or between MBL probes, which would result in a failure. --- Firmware/Marlin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index a1b6fe4eb..cc2766b44 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -377,7 +377,7 @@ extern uint16_t gcode_in_progress; extern LongTimer safetyTimer; #define PRINT_PERCENT_DONE_INIT 0xff -#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || mmu_print_saved) +#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || mmu_print_saved || homing_flag || mesh_bed_leveling_flag) //! Beware - mcode_in_progress is set as soon as the command gets really processed, //! which is not the same as posting the M600 command into the command queue From b4f5633bde4d73105bc9ad9dba746353afc81b59 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 24 Feb 2021 16:59:22 +0100 Subject: [PATCH 7/8] Enable "Move axis" and "Disable steppers" only when idle Move axis queues movements, which disrupts a normal print, homing (when XY is combined) or MBL. Likewise, "Disable steppers" only makes sense when the printer is fully idle. Only allow such actions when the printer is not active and/or in the paused state. --- Firmware/ultralcd.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index d7c7a25d9..833eddc39 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5747,10 +5747,12 @@ static void lcd_settings_menu() MENU_ITEM_BACK_P(_T(MSG_MAIN)); MENU_ITEM_SUBMENU_P(_i("Temperature"), lcd_control_temperature_menu);////MSG_TEMPERATURE - if (!homing_flag) + + if (!PRINTER_ACTIVE || isPrintPaused) + { MENU_ITEM_SUBMENU_P(_i("Move axis"), lcd_move_menu_1mm);////MSG_MOVE_AXIS - if (!isPrintPaused) MENU_ITEM_GCODE_P(_i("Disable steppers"), PSTR("M84"));////MSG_DISABLE_STEPPERS + } SETTINGS_FILAMENT_SENSOR; From e8f6c9fac91f0ad808ef8a8ee62f5b5466f5aeab Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 24 Feb 2021 17:01:45 +0100 Subject: [PATCH 8/8] Exit the _lcd_move* menus when homing/leveling Instead of resetting the encoder status when homing or leveling, simply exit the move/liveZ menu. When transitioning from idle->printing, axis move shouldn't be allowed as it would insert moves during a print. This is always wrong. The menu must be always dismissed. Instead of checking all places where the menu could be active, automatically dimiss the menu from within _lcd_move when homing/MBL is happening. The long-push function and the settings menu checks if "axis move" is possible, and thus prevent the user to re-enter the menu already. When doing the first layer calibration, the _lcd_babystep_z is automatically brought back after MBL has completed. Technically we should do the same when entering/exiting the paused state in _lcd_move. However, it's better to dismiss _any_ menu in stop_and_save_print_to_ram/restore_print_from_ram_and_continue instead. To be done later... --- Firmware/ultralcd.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 833eddc39..0117cca8a 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -2850,6 +2850,13 @@ void lcd_menu_statistics() static void _lcd_move(const char *name, int axis, int min, int max) { + if (homing_flag || mesh_bed_leveling_flag) + { + // printer entered a new state where axis move is forbidden + menu_back(); + return; + } + typedef struct { // 2bytes total bool initialized; // 1byte @@ -3071,6 +3078,13 @@ static void lcd_move_z() { */ static void lcd_babystep_z() { + if (homing_flag || mesh_bed_leveling_flag) + { + // printer changed to a new state where live Z is forbidden + menu_back(); + return; + } + typedef struct { int8_t status; @@ -3106,9 +3120,8 @@ static void lcd_babystep_z() lcd_timeoutToStatus.start(); } - if (lcd_encoder != 0) + if (lcd_encoder != 0) { - if (homing_flag || mesh_bed_leveling_flag) lcd_encoder = 0; _md->babystepMemZ += (int)lcd_encoder; if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm