From 5a0923ed2846affca10cb378cf8ff40042cfbba3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 1 Nov 2025 16:05:20 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Unified=20Linear=20Advance=20K?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Part of #21827 --- Marlin/Configuration_adv.h | 15 +++++---- Marlin/src/gcode/feature/advance/M900.cpp | 4 +-- Marlin/src/gcode/feature/ft_motion/M493.cpp | 33 ------------------ Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/gcode/gcode.h | 4 +-- Marlin/src/inc/Changes.h | 4 +++ Marlin/src/inc/Conditionals-4-adv.h | 7 ++-- Marlin/src/inc/SanityCheck.h | 33 +++++++++--------- Marlin/src/lcd/e3v2/proui/dwin.cpp | 6 ++-- Marlin/src/lcd/e3v2/proui/dwin_defines.h | 4 +-- Marlin/src/lcd/menu/menu_motion.cpp | 12 ------- Marlin/src/module/ft_motion.cpp | 5 +-- Marlin/src/module/ft_motion.h | 10 ------ Marlin/src/module/planner.cpp | 37 ++++++++++----------- Marlin/src/module/planner.h | 17 +++++----- Marlin/src/module/settings.cpp | 10 +++--- ini/features.ini | 2 +- 17 files changed, 79 insertions(+), 126 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index f1feb94688..6184e5df93 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1154,9 +1154,6 @@ #define FTM_DEFAULT_DYNFREQ_MODE dynFreqMode_DISABLED // Default mode of dynamic frequency calculation. (DISABLED, Z_BASED, MASS_BASED) - #define FTM_LINEAR_ADV_DEFAULT_ENA false // Default linear advance enable (true) or disable (false) - #define FTM_LINEAR_ADV_DEFAULT_K 0.0f // Default linear advance gain. (Acceleration-based scaling factor.) - #define FTM_DEFAULT_SHAPER_X ftMotionShaper_NONE // Default shaper mode on X axis (NONE, ZV, ZVD, ZVDD, ZVDDD, EI, 2HEI, 3HEI, MZV) #define FTM_SHAPING_DEFAULT_FREQ_X 37.0f // (Hz) Default peak frequency used by input shapers #define FTM_SHAPING_ZETA_X 0.1f // Zeta used by input shapers for X axis @@ -2388,13 +2385,17 @@ * See https://marlinfw.org/docs/features/lin_advance.html for full instructions. */ //#define LIN_ADVANCE -#if ENABLED(LIN_ADVANCE) + +#if ANY(LIN_ADVANCE, FT_MOTION) #if ENABLED(DISTINCT_E_FACTORS) - #define ADVANCE_K { 0.22 } // (mm) Compression length per 1mm/s extruder speed, per extruder + #define ADVANCE_K { 0.22 } // (mm) Compression length per 1mm/s extruder speed, per extruder. Override with 'M900 T K'. #else - #define ADVANCE_K 0.22 // (mm) Compression length applying to all extruders + #define ADVANCE_K 0.22 // (mm) Compression length for all extruders. Override with 'M900 K'. #endif - //#define ADVANCE_K_EXTRA // Add a second linear advance constant, configurable with M900 L. + //#define ADVANCE_K_EXTRA // Add a second linear advance constant, configurable with 'M900 L'. +#endif + +#if ENABLED(LIN_ADVANCE) //#define LA_DEBUG // Print debug information to serial during operation. Disable for production use. //#define EXPERIMENTAL_I2S_LA // Allow I2S_STEPPER_STREAM to be used with LA. Performance degrades as the LA step rate reaches ~20kHz. diff --git a/Marlin/src/gcode/feature/advance/M900.cpp b/Marlin/src/gcode/feature/advance/M900.cpp index ac6a5246aa..7631cd0e8c 100644 --- a/Marlin/src/gcode/feature/advance/M900.cpp +++ b/Marlin/src/gcode/feature/advance/M900.cpp @@ -22,7 +22,7 @@ #include "../../../inc/MarlinConfig.h" -#if ENABLED(LIN_ADVANCE) +#if HAS_LIN_ADVANCE_K #include "../../gcode.h" #include "../../../module/planner.h" @@ -194,4 +194,4 @@ void GcodeSuite::M900_report(const bool forReplay/*=true*/) { } } -#endif // LIN_ADVANCE +#endif // HAS_LIN_ADVANCE_K diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 796676bf57..6f021c1a0f 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -114,13 +114,6 @@ void say_shaping() { SERIAL_EOL(); #endif } - - #if HAS_EXTRUDERS - if (c.active) { - SERIAL_ECHO_TERNARY(c.linearAdvEna, "Linear Advance ", "en", "dis", "abled"); - SERIAL_ECHOLNPGM(". Gain: ", c.linearAdvK); - } - #endif } void GcodeSuite::M493_report(const bool forReplay/*=true*/) { @@ -134,9 +127,6 @@ void GcodeSuite::M493_report(const bool forReplay/*=true*/) { #if HAS_DYNAMIC_FREQ , " D", c.dynFreqMode #endif - #if HAS_EXTRUDERS - , " P", c.linearAdvEna, " K", c.linearAdvK - #endif // Axis Synchronization , " H", c.axis_sync_enabled ); @@ -172,7 +162,6 @@ void GcodeSuite::M493_report(const bool forReplay/*=true*/) { * Linear / Pressure Advance: * * P Enable (1) or Disable (0) Linear Advance pressure control - * K Set Linear Advance gain * * Specifying Axes (for A,C,F,I,Q): * @@ -251,28 +240,6 @@ void GcodeSuite::M493() { #endif // NUM_AXES_SHAPED > 0 - #if HAS_EXTRUDERS - - // Pressure control (linear advance) parameter. - if (parser.seen('P')) { - const bool val = parser.value_bool(); - ftMotion.cfg.linearAdvEna = val; - flag.report = true; - } - - // Pressure control (linear advance) gain parameter. - if (parser.seenval('K')) { - const float val = parser.value_float(); - if (WITHIN(val, 0.0f, 10.0f)) { - ftMotion.cfg.linearAdvK = val; - flag.report = true; - } - else // Value out of range. - SERIAL_ECHOLNPGM("Linear Advance gain out of range."); - } - - #endif // HAS_EXTRUDERS - // Parse 'H' Axis Synchronization parameter. if (parser.seenval('H')) { const bool enabled = parser.value_bool(); diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index b3dae56849..20b268256e 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -1038,7 +1038,7 @@ void GcodeSuite::process_parsed_command(bool no_ok/*=false*/) { case 871: M871(); break; // M871: Print/reset/clear first layer temperature offset values #endif - #if ENABLED(LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K case 900: M900(); break; // M900: Set advance K factor. #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 87d626effc..effbd85449 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -309,7 +309,7 @@ * * M871 - Print/Reset/Clear first layer temperature offset values. (Requires PTC_PROBE, PTC_BED, or PTC_HOTEND) * M876 - Handle Prompt Response. (Requires HOST_PROMPT_SUPPORT and not EMERGENCY_PARSER) - * M900 - Set / Report Linear Advance K-factor. (Requires LIN_ADVANCE) + * M900 - Set / Report Linear Advance K-factor (Requires LIN_ADVANCE or FT_MOTION) and Smoothing Tau factor (Requires SMOOTH_LIN_ADVANCE). * M906 - Set / Report motor current in milliamps using axis codes XYZE, etc. Report values if no axis codes given. (Requires *_DRIVER_TYPE TMC(2130|2160|5130|5160|2208|2209|2240|2660)) * M907 - Set digital trimpot motor current using axis codes. (Requires a board with digital trimpots) * M908 - Control digital trimpot directly. (Requires HAS_MOTOR_CURRENT_DAC or DIGIPOTSS_PIN) @@ -1249,7 +1249,7 @@ private: static void M871(); #endif - #if ENABLED(LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K static void M900(); static void M900_report(const bool forReplay=true); #endif diff --git a/Marlin/src/inc/Changes.h b/Marlin/src/inc/Changes.h index cbfdcfc47f..2d8fe87863 100644 --- a/Marlin/src/inc/Changes.h +++ b/Marlin/src/inc/Changes.h @@ -745,6 +745,10 @@ #error "FTM_SHAPING_DEFAULT_[XY]_FREQ is now FTM_SHAPING_DEFAULT_FREQ_[XY]." #elif defined(SDSS) #error "SDSS is now SD_SS_PIN." +#elif defined(FTM_LINEAR_ADV_DEFAULT_ENA) + #error "FTM_LINEAR_ADV_DEFAULT_ENA is obsolete and should be removed." +#elif defined(FTM_LINEAR_ADV_DEFAULT_K) + #error "FTM_LINEAR_ADV_DEFAULT_K is now set with ADVANCE_K and should be removed." #endif // SDSS renamed to SD_SS_PIN diff --git a/Marlin/src/inc/Conditionals-4-adv.h b/Marlin/src/inc/Conditionals-4-adv.h index d72f2e4582..8bec3c1dd3 100644 --- a/Marlin/src/inc/Conditionals-4-adv.h +++ b/Marlin/src/inc/Conditionals-4-adv.h @@ -346,11 +346,12 @@ #if ALL(FT_MOTION, HAS_EXTRUDERS) #define FTM_HAS_LIN_ADVANCE 1 #endif - -#if HAS_JUNCTION_DEVIATION && ANY(LIN_ADVANCE, FTM_HAS_LIN_ADVANCE) +#if ANY(FTM_HAS_LIN_ADVANCE, LIN_ADVANCE) + #define HAS_LIN_ADVANCE_K 1 +#endif +#if HAS_JUNCTION_DEVIATION && ENABLED(LIN_ADVANCE) #define HAS_LINEAR_E_JERK 1 #endif - #if ENABLED(LIN_ADVANCE) && DISABLED(SMOOTH_LIN_ADVANCE) #define HAS_ROUGH_LIN_ADVANCE 1 #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index a8467ac606..aadb3aea9d 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -848,26 +848,15 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L #endif /** - * Linear Advance 1.5 - Check K value range + * Linear Advance requirements */ #if ENABLED(LIN_ADVANCE) - #if ENABLED(DISTINCT_E_FACTORS) - constexpr float lak[] = ADVANCE_K; - static_assert(COUNT(lak) <= DISTINCT_E, "The ADVANCE_K array has too many elements (i.e., more than " STRINGIFY(DISTINCT_E) ")."); - #define _LIN_ASSERT(N) static_assert(N >= COUNT(lak) || WITHIN(lak[N], 0, 10), "ADVANCE_K values must be from 0 to 10 (Changed in LIN_ADVANCE v1.5, Marlin 1.1.9)."); - REPEAT(DISTINCT_E, _LIN_ASSERT) - #undef _LIN_ASSERT - #else - static_assert(WITHIN(ADVANCE_K, 0, 10), "ADVANCE_K must be from 0 to 10 (Changed in LIN_ADVANCE v1.5, Marlin 1.1.9)."); - #endif - + // Incompatible with Direct Stepping #if ENABLED(DIRECT_STEPPING) #error "DIRECT_STEPPING is incompatible with LIN_ADVANCE. (Extrusion is controlled externally by the Step Daemon.)" #endif - /** - * Smooth Linear Advance - */ + // Smooth Linear Advance #if ENABLED(SMOOTH_LIN_ADVANCE) #ifndef CPU_32_BIT #error "SMOOTH_LIN_ADVANCE requires a 32-bit CPU." @@ -875,9 +864,23 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L #error "INPUT_SHAPING_E_SYNC requires INPUT_SHAPING_X or INPUT_SHAPING_Y." #endif #endif - #endif // LIN_ADVANCE +/** + * Linear Advance and FT Motion - Check K value range + */ +#if HAS_LIN_ADVANCE_K + #if ENABLED(DISTINCT_E_FACTORS) + constexpr float lak[] = ADVANCE_K; + static_assert(COUNT(lak) <= DISTINCT_E, "The ADVANCE_K array has too many elements (i.e., more than " STRINGIFY(DISTINCT_E) ")."); + #define _LIN_ASSERT(N) static_assert(N >= COUNT(lak) || WITHIN(lak[N], 0, 10), "ADVANCE_K values must be from 0 to 10."); + REPEAT(DISTINCT_E, _LIN_ASSERT) + #undef _LIN_ASSERT + #else + static_assert(WITHIN(ADVANCE_K, 0, 10), "ADVANCE_K must be from 0 to 10."); + #endif +#endif + /** * Nonlinear Extrusion requirements */ diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index a8d8e277db..8ff1fe6412 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -2686,7 +2686,7 @@ void applyMaxAccel() { planner.set_max_acceleration(hmiValue.axis, menuData.valu void setJDmm() { setPFloatOnClick(MIN_JD_MM, MAX_JD_MM, 3, applyJDmm); } #endif -#if ENABLED(LIN_ADVANCE) +#if HAS_LIN_ADVANCE_K #define LA_FDIGITS 3 void applyLA_K() { planner.set_advance_k(menuData.value / POW(10, LA_FDIGITS)); } void setLA_K() { setFloatOnClick(0, 10, LA_FDIGITS, planner.get_advance_k(), applyLA_K); } @@ -3677,7 +3677,7 @@ void drawTuneMenu() { void drawMotionMenu() { constexpr uint8_t items = (4 - + COUNT_ENABLED(EDITABLE_STEPS_PER_UNIT, EDITABLE_HOMING_FEEDRATE, LIN_ADVANCE, SHAPING_MENU, ADAPTIVE_STEP_SMOOTHING_TOGGLE) + + COUNT_ENABLED(EDITABLE_STEPS_PER_UNIT, EDITABLE_HOMING_FEEDRATE, HAS_LIN_ADVANCE_K, SMOOTH_LIN_ADVANCE, SHAPING_MENU, ADAPTIVE_STEP_SMOOTHING_TOGGLE) + 2 ); checkkey = ID_Menu; @@ -3696,7 +3696,7 @@ void drawMotionMenu() { #if ENABLED(EDITABLE_HOMING_FEEDRATE) MENU_ITEM(ICON_Homing, MSG_HOMING_FEEDRATE, onDrawSubMenu, drawHomingFRMenu); #endif - #if ENABLED(LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K static float editable_k; editable_k = planner.get_advance_k(); EDIT_ITEM(ICON_MaxAccelerated, MSG_ADVANCE_K, onDrawLA_K, setLA_K, &editable_k); diff --git a/Marlin/src/lcd/e3v2/proui/dwin_defines.h b/Marlin/src/lcd/e3v2/proui/dwin_defines.h index 52ad604296..42645be0f4 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin_defines.h +++ b/Marlin/src/lcd/e3v2/proui/dwin_defines.h @@ -121,10 +121,10 @@ #if ENABLED(POWER_LOSS_RECOVERY) #define PROUI_ITEM_PLR // Tune > Power-loss Recovery #endif -#if ENABLED(HAS_JUNCTION_DEVIATION) +#if HAS_JUNCTION_DEVIATION #define PROUI_ITEM_JD // Tune > Junction Deviation #endif -#if ENABLED(LIN_ADVANCE) +#if HAS_LIN_ADVANCE_K #define PROUI_ITEM_ADVK 1 // Tune > Linear Advance #endif #if ANY(HAS_PID_HEATING, MPC_AUTOTUNE) && DISABLED(DISABLE_TUNING_GRAPH) diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 305b77688c..0d23484f3f 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -499,12 +499,6 @@ void menu_move() { } #endif - #if HAS_EXTRUDERS - EDIT_ITEM(bool, MSG_LINEAR_ADVANCE, &c.linearAdvEna); - if (c.linearAdvEna || ENABLED(FT_MOTION_NO_MENU_TOGGLE)) - EDIT_ITEM(float42_52, MSG_ADVANCE_K, &c.linearAdvK, 0.0f, 10.0f); - #endif - EDIT_ITEM(bool, MSG_FTM_AXIS_SYNC, &c.axis_sync_enabled); #if ENABLED(FTM_SMOOTHING) @@ -578,12 +572,6 @@ void menu_move() { SUBMENU_S(_dmode(), MSG_FTM_DYN_MODE, menu_ftm_dyn_mode); #endif - #if HAS_EXTRUDERS - EDIT_ITEM(bool, MSG_LINEAR_ADVANCE, &c.linearAdvEna); - if (c.linearAdvEna || ENABLED(FT_MOTION_NO_MENU_TOGGLE)) - EDIT_ITEM(float42_52, MSG_ADVANCE_K, &c.linearAdvK, 0.0f, 10.0f); - #endif - #if ENABLED(FTM_SMOOTHING) CARTES_MAP(_SMOO_MENU_ITEM); #endif diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index cd0c162668..239badc23b 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -612,12 +612,13 @@ void FTMotion::generateTrajectoryPointsFromBlock() { LOGICAL_AXIS_MAP_LC(_SET_TRAJ); #if FTM_HAS_LIN_ADVANCE - if (cfg.linearAdvEna) { + const float advK = planner.get_advance_k(); + if (advK) { float traj_e = traj.e[traj_idx_set]; if (use_advance_lead) { // Don't apply LA to retract/unretract blocks float e_rate = (traj_e - prev_traj_e) * (FTM_FS); - traj.e[traj_idx_set] += e_rate * cfg.linearAdvK; + traj.e[traj_idx_set] += e_rate * advK; } prev_traj_e = traj_e; } diff --git a/Marlin/src/module/ft_motion.h b/Marlin/src/module/ft_motion.h index 4254680fbf..a24f3271cf 100644 --- a/Marlin/src/module/ft_motion.h +++ b/Marlin/src/module/ft_motion.h @@ -73,11 +73,6 @@ typedef struct FTConfig { #endif // HAS_FTM_SHAPING - #if HAS_EXTRUDERS - bool linearAdvEna = FTM_LINEAR_ADV_DEFAULT_ENA; // Linear advance enable configuration. - float linearAdvK = FTM_LINEAR_ADV_DEFAULT_K; // Linear advance gain. - #endif - TrajectoryType trajectory_type = TrajectoryType::FTM_TRAJECTORY_TYPE; // Trajectory generator type float poly6_acceleration_overshoot; // Overshoot factor for Poly6 (1.25 to 2.0) } ft_config_t; @@ -126,11 +121,6 @@ class FTMotion { #undef _SET_SMOOTH #endif - #if HAS_EXTRUDERS - cfg.linearAdvEna = FTM_LINEAR_ADV_DEFAULT_ENA; - cfg.linearAdvK = FTM_LINEAR_ADV_DEFAULT_K; - #endif - cfg.poly6_acceleration_overshoot = FTM_POLY6_ACCELERATION_OVERSHOOT; setTrajectoryType(TrajectoryType::FTM_TRAJECTORY_TYPE); diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 404d1fc5a7..b4c53fab6b 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -234,7 +234,7 @@ float Planner::previous_nominal_speed; int32_t Planner::xy_freq_min_interval_us = LROUND(1000000.0f / (XY_FREQUENCY_LIMIT)); #endif -#if ENABLED(LIN_ADVANCE) +#if HAS_LIN_ADVANCE_K float Planner::extruder_advance_K[DISTINCT_E]; // Initialized by settings.load #if ENABLED(SMOOTH_LIN_ADVANCE) uint32_t Planner::extruder_advance_K_q27[DISTINCT_E]; @@ -881,11 +881,9 @@ void Planner::calculate_trapezoid_for_block(block_t * const block, const float e #if ENABLED(SMOOTH_LIN_ADVANCE) block->cruise_time = plateau_steps > 0 ? float(plateau_steps) * float(STEPPER_TIMER_RATE) / float(cruise_rate) : 0; - #endif - - #if HAS_ROUGH_LIN_ADVANCE + #elif HAS_ROUGH_LIN_ADVANCE if (block->la_advance_rate) { - const float comp = extruder_advance_K[E_INDEX_N(block->extruder)] * block->steps.e / block->step_event_count; + const float comp = get_advance_k(block->extruder) * block->steps.e / block->step_event_count; block->max_adv_steps = cruise_rate * comp; block->final_adv_steps = final_rate * comp; } @@ -2403,7 +2401,7 @@ bool Planner::_populate_block( // Start with print or travel acceleration accel = CEIL((esteps ? settings.acceleration : settings.travel_acceleration) * steps_per_mm); - #if ANY(LIN_ADVANCE, FTM_HAS_LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K // Linear advance is currently not ready for HAS_I_AXIS #define MAX_E_JERK(N) TERN(HAS_LINEAR_E_JERK, max_e_jerk[E_INDEX_N(N)], max_jerk.e) @@ -2416,11 +2414,7 @@ bool Planner::_populate_block( * Check the appropriate K value for Standard or Fixed-Time Motion. */ if (esteps && dm.e) { - const bool ftm_active = TERN0(FTM_HAS_LIN_ADVANCE, ftMotion.cfg.active), - ftm_la_active = TERN0(FTM_HAS_LIN_ADVANCE, ftm_active && ftMotion.cfg.linearAdvEna); - const float advK = ftm_active - ? (ftm_la_active ? TERN0(FTM_HAS_LIN_ADVANCE, ftMotion.cfg.linearAdvK) : 0) - : TERN0(HAS_ROUGH_LIN_ADVANCE, extruder_advance_K[E_INDEX_N(extruder)]); + const float advK = get_advance_k(extruder); if (advK) { float e_D_ratio = (target_float.e - position_float.e) / TERN(IS_KINEMATIC, block->millimeters, @@ -2434,17 +2428,20 @@ bool Planner::_populate_block( // This assumes no one will use a retract length of 0mm < retr_length < ~0.2mm // and no one will print 100mm wide lines using 3mm filament or 35mm wide lines using 1.75mm filament. use_adv_lead = e_D_ratio <= 3.0f; - if (use_adv_lead && TERN0(HAS_ROUGH_LIN_ADVANCE, !ftm_active)) { - // For Standard Motion LA: Scale E acceleration so it'll be possible to jump to the advance speed - const uint32_t max_accel_steps_per_s2 = (MAX_E_JERK(extruder) / (advK * e_D_ratio)) * steps_per_mm; - if (accel > max_accel_steps_per_s2) { - accel = max_accel_steps_per_s2; - if (TERN0(LA_DEBUG, DEBUGGING(INFO))) SERIAL_ECHOLNPGM("Acceleration limited to max_accel_steps_per_s2 (", max_accel_steps_per_s2, ")"); + + #if HAS_ROUGH_LIN_ADVANCE + if (use_adv_lead && TERN1(FT_MOTION, !ftMotion.cfg.active)) { + // For Standard Motion LA: Scale E acceleration so it'll be possible to jump to the advance speed + const uint32_t max_accel_steps_per_s2 = (MAX_E_JERK(extruder) / (advK * e_D_ratio)) * steps_per_mm; + if (accel > max_accel_steps_per_s2) { + accel = max_accel_steps_per_s2; + if (TERN0(LA_DEBUG, DEBUGGING(INFO))) SERIAL_ECHOLNPGM("Acceleration limited to max_accel_steps_per_s2 (", max_accel_steps_per_s2, ")"); + } } - } + #endif } } - #endif // LIN_ADVANCE || FTM_HAS_LIN_ADVANCE + #endif // HAS_LIN_ADVANCE_K // Limit acceleration per axis if (block->step_event_count <= acceleration_long_cutoff) { @@ -2475,7 +2472,7 @@ bool Planner::_populate_block( block->la_scaling = 0; if (use_adv_lead) { // The Bresenham algorithm will convert this step rate into extruder steps - block->la_advance_rate = extruder_advance_K[E_INDEX_N(extruder)] * block->acceleration_steps_per_s2; + block->la_advance_rate = get_advance_k(extruder) * block->acceleration_steps_per_s2; // Reduce LA ISR frequency by calling it only often enough to ensure that there will // never be more than four extruder steps per call diff --git a/Marlin/src/module/planner.h b/Marlin/src/module/planner.h index 21b6fd660b..c001dadd66 100644 --- a/Marlin/src/module/planner.h +++ b/Marlin/src/module/planner.h @@ -530,7 +530,7 @@ class Planner { static constexpr bool leveling_active = false; #endif - #if ENABLED(LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K static float extruder_advance_K[DISTINCT_E]; static void set_advance_k(const float k, const uint8_t e=active_extruder) { UNUSED(e); @@ -541,13 +541,14 @@ class Planner { UNUSED(e); return extruder_advance_K[E_INDEX_N(e)]; } - #if ENABLED(SMOOTH_LIN_ADVANCE) - static uint32_t get_advance_k_q27(const uint8_t e=active_extruder) { - UNUSED(e); - return extruder_advance_K_q27[E_INDEX_N(e)]; - } - #endif - #endif // LIN_ADVANCE + #endif + + #if ENABLED(SMOOTH_LIN_ADVANCE) + static uint32_t get_advance_k_q27(const uint8_t e=active_extruder) { + UNUSED(e); + return extruder_advance_K_q27[E_INDEX_N(e)]; + } + #endif /** * The current position of the tool in absolute steps diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 63f69d13c2..3414d322da 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -498,7 +498,7 @@ typedef struct SettingsDataStruct { // // LIN_ADVANCE // - #if ENABLED(LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K float planner_extruder_advance_K[DISTINCT_E]; // M900 K planner.extruder_advance_K #if ENABLED(SMOOTH_LIN_ADVANCE) float stepper_extruder_advance_tau[DISTINCT_E]; // M900 U stepper.extruder_advance_tau @@ -1564,7 +1564,7 @@ void MarlinSettings::postprocess() { // Linear Advance // { - #if ENABLED(LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K _FIELD_TEST(planner_extruder_advance_K); EEPROM_WRITE(planner.extruder_advance_K); #if ENABLED(SMOOTH_LIN_ADVANCE) @@ -2649,7 +2649,7 @@ void MarlinSettings::postprocess() { // // Linear Advance // - #if ENABLED(LIN_ADVANCE) + #if HAS_LIN_ADVANCE_K { float extruder_advance_K[DISTINCT_E]; _FIELD_TEST(planner_extruder_advance_K); @@ -2665,7 +2665,7 @@ void MarlinSettings::postprocess() { DISTINCT_E_LOOP() stepper.set_advance_tau(tau[e], e); #endif } - #endif + #endif // HAS_LIN_ADVANCE_K // // Motor Current PWM @@ -4098,7 +4098,7 @@ void MarlinSettings::reset() { // // Linear Advance // - TERN_(LIN_ADVANCE, gcode.M900_report(forReplay)); + TERN_(HAS_LIN_ADVANCE_K, gcode.M900_report(forReplay)); // // Motor Current (SPI or PWM) diff --git a/ini/features.ini b/ini/features.ini index bd45dd02c1..d1b02bb4d4 100644 --- a/ini/features.ini +++ b/ini/features.ini @@ -312,7 +312,7 @@ SPI_FLASH_BACKUP = build_src_filter=+ HAS_TOOLCHANGE = build_src_filter=+ FT_MOTION = build_src_filter=+ + + -LIN_ADVANCE = build_src_filter=+ +HAS_LIN_ADVANCE_K = build_src_filter=+ PHOTO_GCODE = build_src_filter=+ CONTROLLER_FAN_EDITABLE = build_src_filter=+ HAS_ZV_SHAPING = build_src_filter=+