From 7e4415c9dbb024838924cab7a970baa5cd3d86d2 Mon Sep 17 00:00:00 2001 From: narno2202 Date: Sun, 11 Feb 2024 18:22:09 +0100 Subject: [PATCH 1/6] Store FT_MOTION linearadvance as int and convert to the real value during processing. Clearer than 10E-6 value --- Marlin/Configuration_adv.h | 2 +- Marlin/src/gcode/feature/ft_motion/M493.cpp | 4 ++-- Marlin/src/lcd/menu/menu_motion.cpp | 2 +- Marlin/src/module/ft_motion.cpp | 2 +- Marlin/src/module/ft_motion.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index df532ae6f310..44ff4ead3be4 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1124,7 +1124,7 @@ #define FTM_SHAPING_DEFAULT_X_FREQ 37.0f // (Hz) Default peak frequency used by input shapers #define FTM_SHAPING_DEFAULT_Y_FREQ 37.0f // (Hz) Default peak frequency used by input shapers #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 + #define FTM_LINEAR_ADV_DEFAULT_K 0 // Default linear advance gain, integer value, internally converted to the real value (FTM_LINEAR_ADV_DEFAULT_K* 0.000001) #define FTM_SHAPING_ZETA_X 0.1f // Zeta used by input shapers for X axis #define FTM_SHAPING_ZETA_Y 0.1f // Zeta used by input shapers for Y axis diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 2da92b8582d6..9eea29f62034 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -212,8 +212,8 @@ void GcodeSuite::M493() { // Pressure control (linear advance) gain parameter. if (parser.seenval('K')) { - const float val = parser.value_float(); - if (val >= 0.0f) { + const int val = parser.value_int(); + if (val >= 0) { ftMotion.cfg.linearAdvK = val; flag.report_h = true; } diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 239d03d9777a..9ef4ada9a2ea 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -452,7 +452,7 @@ void menu_move() { #if HAS_EXTRUDERS EDIT_ITEM(bool, MSG_LINEAR_ADVANCE, &c.linearAdvEna); - if (c.linearAdvEna) EDIT_ITEM(float42_52, MSG_ADVANCE_K, &c.linearAdvK, 0, 10); + if (c.linearAdvEna) EDIT_ITEM(uint16_3, MSG_ADVANCE_K, &c.linearAdvK, 0, 1000); #endif END_MENU(); diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index e912255561f1..34e534848604 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -632,7 +632,7 @@ void FTMotion::makeVector() { #if HAS_EXTRUDERS if (cfg.linearAdvEna) { float dedt_adj = (traj.e[makeVector_batchIdx] - e_raw_z1) * (FTM_FS); - if (ratio.e > 0.0f) dedt_adj += accel_k * cfg.linearAdvK; + if (ratio.e > 0.0f) dedt_adj += accel_k * cfg.linearAdvK * 0.000001; e_raw_z1 = traj.e[makeVector_batchIdx]; e_advanced_z1 += dedt_adj * (FTM_TS); diff --git a/Marlin/src/module/ft_motion.h b/Marlin/src/module/ft_motion.h index 884a18347903..e822b3c94696 100644 --- a/Marlin/src/module/ft_motion.h +++ b/Marlin/src/module/ft_motion.h @@ -59,7 +59,7 @@ typedef struct FTConfig { #if HAS_EXTRUDERS bool linearAdvEna = FTM_LINEAR_ADV_DEFAULT_ENA; // Linear advance enable configuration. - float linearAdvK = FTM_LINEAR_ADV_DEFAULT_K; // Linear advance gain. + uint16_t linearAdvK = FTM_LINEAR_ADV_DEFAULT_K; // Linear advance gain. #endif } ft_config_t; From 426dfa4e86c01e1cbaa5e5b8cf7f1309f9278e1c Mon Sep 17 00:00:00 2001 From: narno2202 Date: Sat, 17 Feb 2024 10:53:37 +0100 Subject: [PATCH 2/6] Change K factor range between 0.1 and 1 10e-6 --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 4 ++-- Marlin/src/lcd/menu/menu_motion.cpp | 2 +- Marlin/src/module/ft_motion.cpp | 2 +- Marlin/src/module/ft_motion.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 9eea29f62034..b644811547d5 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -212,8 +212,8 @@ void GcodeSuite::M493() { // Pressure control (linear advance) gain parameter. if (parser.seenval('K')) { - const int val = parser.value_int(); - if (val >= 0) { + const float val = parser.value_float(); + if (val >= 0.00) { ftMotion.cfg.linearAdvK = val; flag.report_h = true; } diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 9ef4ada9a2ea..032cf191f787 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -452,7 +452,7 @@ void menu_move() { #if HAS_EXTRUDERS EDIT_ITEM(bool, MSG_LINEAR_ADVANCE, &c.linearAdvEna); - if (c.linearAdvEna) EDIT_ITEM(uint16_3, MSG_ADVANCE_K, &c.linearAdvK, 0, 1000); + if (c.linearAdvEna) EDIT_ITEM(float62, MSG_ADVANCE_K, &c.linearAdvK, 0.0f, 1000.0f); #endif END_MENU(); diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index 34e534848604..3b466d097408 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -632,7 +632,7 @@ void FTMotion::makeVector() { #if HAS_EXTRUDERS if (cfg.linearAdvEna) { float dedt_adj = (traj.e[makeVector_batchIdx] - e_raw_z1) * (FTM_FS); - if (ratio.e > 0.0f) dedt_adj += accel_k * cfg.linearAdvK * 0.000001; + if (ratio.e > 0.0f) dedt_adj += accel_k * cfg.linearAdvK * 0.0001; e_raw_z1 = traj.e[makeVector_batchIdx]; e_advanced_z1 += dedt_adj * (FTM_TS); diff --git a/Marlin/src/module/ft_motion.h b/Marlin/src/module/ft_motion.h index e822b3c94696..884a18347903 100644 --- a/Marlin/src/module/ft_motion.h +++ b/Marlin/src/module/ft_motion.h @@ -59,7 +59,7 @@ typedef struct FTConfig { #if HAS_EXTRUDERS bool linearAdvEna = FTM_LINEAR_ADV_DEFAULT_ENA; // Linear advance enable configuration. - uint16_t linearAdvK = FTM_LINEAR_ADV_DEFAULT_K; // Linear advance gain. + float linearAdvK = FTM_LINEAR_ADV_DEFAULT_K; // Linear advance gain. #endif } ft_config_t; From 32e72468ac884b3d08c11bfc4c2011293b733920 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 15 Jul 2024 13:20:07 -0500 Subject: [PATCH 3/6] this --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index b644811547d5..2da92b8582d6 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -213,7 +213,7 @@ void GcodeSuite::M493() { // Pressure control (linear advance) gain parameter. if (parser.seenval('K')) { const float val = parser.value_float(); - if (val >= 0.00) { + if (val >= 0.0f) { ftMotion.cfg.linearAdvK = val; flag.report_h = true; } From 4567f46ec1fbc2a9d7f1da7f9fb0c4c1f4d1fb63 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 15 Jul 2024 13:21:26 -0500 Subject: [PATCH 4/6] divide by a million? --- Marlin/Configuration_adv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index fe803d11b841..949d2970d1b5 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1126,7 +1126,7 @@ #define FTM_SHAPING_DEFAULT_X_FREQ 37.0f // (Hz) Default peak frequency used by input shapers #define FTM_SHAPING_DEFAULT_Y_FREQ 37.0f // (Hz) Default peak frequency used by input shapers #define FTM_LINEAR_ADV_DEFAULT_ENA false // Default linear advance enable (true) or disable (false) - #define FTM_LINEAR_ADV_DEFAULT_K 0 // Default linear advance gain, integer value, internally converted to the real value (FTM_LINEAR_ADV_DEFAULT_K* 0.000001) + #define FTM_LINEAR_ADV_DEFAULT_K 0 // Default linear advance gain, integer value (internally divided by 1 million) #define FTM_SHAPING_ZETA_X 0.1f // Zeta used by input shapers for X axis #define FTM_SHAPING_ZETA_Y 0.1f // Zeta used by input shapers for Y axis From 2e1e1aa6a813cb2f6e36d1ea37ce1b0174a32c1d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 15 Jul 2024 13:22:34 -0500 Subject: [PATCH 5/6] f --- Marlin/src/module/ft_motion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index 27f60ef543ce..486889294d2f 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -664,7 +664,7 @@ void FTMotion::makeVector() { #if HAS_EXTRUDERS if (cfg.linearAdvEna) { float dedt_adj = (traj.e[makeVector_batchIdx] - e_raw_z1) * (FTM_FS); - if (ratio.e > 0.0f) dedt_adj += accel_k * cfg.linearAdvK * 0.0001; + if (ratio.e > 0.0f) dedt_adj += accel_k * cfg.linearAdvK * 0.0001f; e_raw_z1 = traj.e[makeVector_batchIdx]; e_advanced_z1 += dedt_adj * (FTM_TS); From 7d9f168f4fb4e2df4618b635b960846468e7bc66 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 15 Jul 2024 13:25:56 -0500 Subject: [PATCH 6/6] decript --- Marlin/Configuration_adv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 949d2970d1b5..fb0d1a94a73b 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1126,7 +1126,7 @@ #define FTM_SHAPING_DEFAULT_X_FREQ 37.0f // (Hz) Default peak frequency used by input shapers #define FTM_SHAPING_DEFAULT_Y_FREQ 37.0f // (Hz) Default peak frequency used by input shapers #define FTM_LINEAR_ADV_DEFAULT_ENA false // Default linear advance enable (true) or disable (false) - #define FTM_LINEAR_ADV_DEFAULT_K 0 // Default linear advance gain, integer value (internally divided by 1 million) + #define FTM_LINEAR_ADV_DEFAULT_K 0 // Default linear advance gain, integer value. (Acceleration-based scaling factor.) #define FTM_SHAPING_ZETA_X 0.1f // Zeta used by input shapers for X axis #define FTM_SHAPING_ZETA_Y 0.1f // Zeta used by input shapers for Y axis