From fe63324865356277315be969a67ba135e3ef9ef7 Mon Sep 17 00:00:00 2001 From: Sophist <3001893+Sophist-UK@users.noreply.github.com> Date: Sun, 17 Mar 2024 17:56:28 +0000 Subject: [PATCH 1/8] Fix minor INPUT_SHAPING config bugs 1. `Stepper::set_shaping_frequency` takes freq as a float, so SHAPING_FREQ_X/Y should be defined in `Configuration_adv.h` as floats. 2. SHAPING_FREQ_X/Y can be zero to indicate disabled. SanityChecks need to reflect this. --- Marlin/Configuration_adv.h | 8 ++++---- Marlin/src/inc/SanityCheck.h | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 302e459d863f..bf06c26f11a8 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1204,12 +1204,12 @@ //#define INPUT_SHAPING_Y #if ANY(INPUT_SHAPING_X, INPUT_SHAPING_Y) #if ENABLED(INPUT_SHAPING_X) - #define SHAPING_FREQ_X 40 // (Hz) The default dominant resonant frequency on the X axis. - #define SHAPING_ZETA_X 0.15f // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping). + #define SHAPING_FREQ_X 40.00f // (Hz) The default dominant resonant frequency on the X axis. + #define SHAPING_ZETA_X 0.15f // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping). #endif #if ENABLED(INPUT_SHAPING_Y) - #define SHAPING_FREQ_Y 40 // (Hz) The default dominant resonant frequency on the Y axis. - #define SHAPING_ZETA_Y 0.15f // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping). + #define SHAPING_FREQ_Y 40.00f // (Hz) The default dominant resonant frequency on the Y axis. + #define SHAPING_ZETA_Y 0.15f // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping). #endif //#define SHAPING_MIN_FREQ 20 // By default the minimum of the shaping frequencies. Override to affect SRAM usage. //#define SHAPING_MAX_STEPRATE 10000 // By default the maximum total step rate of the shaped axes. Override to affect SRAM usage. diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index c676c0aaa815..2a730d0afc7f 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -4199,9 +4199,11 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive." #ifdef SHAPING_MIN_FREQ static_assert((SHAPING_MIN_FREQ) > 0, "SHAPING_MIN_FREQ must be > 0."); + TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) == 0 || (SHAPING_FREQ_X) >= (SHAPING_MIN_FREQ), "SHAPING_FREQ_X must be >= SHAPING_MIN_FREQ.")); + TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) == 0 || (SHAPING_FREQ_Y) >= (SHAPING_MIN_FREQ), "SHAPING_FREQ_Y must be >= SHAPING_MIN_FREQ.")); #else - TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) > 0, "SHAPING_FREQ_X must be > 0 or SHAPING_MIN_FREQ must be set.")); - TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) > 0, "SHAPING_FREQ_Y must be > 0 or SHAPING_MIN_FREQ must be set.")); + TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) >= 0, "SHAPING_FREQ_X must be >= 0.")); + TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) >= 0, "SHAPING_FREQ_Y must be >= 0.")); #endif #ifdef __AVR__ #if ENABLED(INPUT_SHAPING_X) From 688c39c6285ae8e4ccbd58315106445246235275 Mon Sep 17 00:00:00 2001 From: Sophist <3001893+Sophist-UK@users.noreply.github.com> Date: Sun, 17 Mar 2024 21:39:28 +0000 Subject: [PATCH 2/8] Avoid division by zero if SHAPING_FREQ_* is zero for disabled. --- Marlin/src/module/stepper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 99fd2d293609..543d3e4576d9 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -159,7 +159,7 @@ constexpr ena_mask_t enable_overlap[] = { #endif #ifndef SHAPING_MIN_FREQ - #define SHAPING_MIN_FREQ _MIN(0x7FFFFFFFL OPTARG(INPUT_SHAPING_X, SHAPING_FREQ_X) OPTARG(INPUT_SHAPING_Y, SHAPING_FREQ_Y)) + #define SHAPING_MIN_FREQ _MIN(0x7FFFFFFFL OPTARG(INPUT_SHAPING_X, _MAX(SHAPING_FREQ_X, 1)) OPTARG(INPUT_SHAPING_Y, _MAX(SHAPING_FREQ_Y, 1))) #endif constexpr uint16_t shaping_min_freq = SHAPING_MIN_FREQ, shaping_echoes = max_step_rate / shaping_min_freq / 2 + 3; From 81b11d826fb1a22d7c5fa024537a7d3b0728baa9 Mon Sep 17 00:00:00 2001 From: Sophist <3001893+Sophist-UK@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:15:37 +0000 Subject: [PATCH 3/8] Revert "Avoid division by zero if SHAPING_FREQ_* is zero for disabled." This reverts commit 688c39c6285ae8e4ccbd58315106445246235275. --- Marlin/src/module/stepper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 543d3e4576d9..99fd2d293609 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -159,7 +159,7 @@ constexpr ena_mask_t enable_overlap[] = { #endif #ifndef SHAPING_MIN_FREQ - #define SHAPING_MIN_FREQ _MIN(0x7FFFFFFFL OPTARG(INPUT_SHAPING_X, _MAX(SHAPING_FREQ_X, 1)) OPTARG(INPUT_SHAPING_Y, _MAX(SHAPING_FREQ_Y, 1))) + #define SHAPING_MIN_FREQ _MIN(0x7FFFFFFFL OPTARG(INPUT_SHAPING_X, SHAPING_FREQ_X) OPTARG(INPUT_SHAPING_Y, SHAPING_FREQ_Y)) #endif constexpr uint16_t shaping_min_freq = SHAPING_MIN_FREQ, shaping_echoes = max_step_rate / shaping_min_freq / 2 + 3; From a13bc21c90cc3044d5382b102c2a4b6288b3ea53 Mon Sep 17 00:00:00 2001 From: Sophist <3001893+Sophist-UK@users.noreply.github.com> Date: Tue, 19 Mar 2024 10:23:36 +0000 Subject: [PATCH 4/8] Revert sanity checks for SHAPING_MIN_FREQ required for SHAPING_FREQ_X/Y=0 --- Marlin/src/inc/SanityCheck.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 2a730d0afc7f..c222b9951198 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -4202,8 +4202,8 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive." TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) == 0 || (SHAPING_FREQ_X) >= (SHAPING_MIN_FREQ), "SHAPING_FREQ_X must be >= SHAPING_MIN_FREQ.")); TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) == 0 || (SHAPING_FREQ_Y) >= (SHAPING_MIN_FREQ), "SHAPING_FREQ_Y must be >= SHAPING_MIN_FREQ.")); #else - TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) >= 0, "SHAPING_FREQ_X must be >= 0.")); - TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) >= 0, "SHAPING_FREQ_Y must be >= 0.")); + TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) > 0, "SHAPING_FREQ_X must be > 0 or SHAPING_MIN_FREQ must be set.")); + TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) > 0, "SHAPING_FREQ_Y must be > 0 or SHAPING_MIN_FREQ must be set.")); #endif #ifdef __AVR__ #if ENABLED(INPUT_SHAPING_X) From ae2f003d2f2718ade17006a4912d71ebfdd665a1 Mon Sep 17 00:00:00 2001 From: Sophist <3001893+Sophist-UK@users.noreply.github.com> Date: Tue, 19 Mar 2024 16:56:41 +0000 Subject: [PATCH 5/8] Revert remaining sanity checks to allow user to save RAM by setting a higher MIN-FREQ in the expectation that actual speeds will not be at the stated maximum feedrate. --- Marlin/src/inc/SanityCheck.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index c222b9951198..c676c0aaa815 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -4199,8 +4199,6 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive." #ifdef SHAPING_MIN_FREQ static_assert((SHAPING_MIN_FREQ) > 0, "SHAPING_MIN_FREQ must be > 0."); - TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) == 0 || (SHAPING_FREQ_X) >= (SHAPING_MIN_FREQ), "SHAPING_FREQ_X must be >= SHAPING_MIN_FREQ.")); - TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) == 0 || (SHAPING_FREQ_Y) >= (SHAPING_MIN_FREQ), "SHAPING_FREQ_Y must be >= SHAPING_MIN_FREQ.")); #else TERN_(INPUT_SHAPING_X, static_assert((SHAPING_FREQ_X) > 0, "SHAPING_FREQ_X must be > 0 or SHAPING_MIN_FREQ must be set.")); TERN_(INPUT_SHAPING_Y, static_assert((SHAPING_FREQ_Y) > 0, "SHAPING_FREQ_Y must be > 0 or SHAPING_MIN_FREQ must be set.")); From 3dedc40b466257b1b3fbb6c1675973d32f5446c4 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 22 Mar 2024 17:22:59 -0500 Subject: [PATCH 6/8] allow double --- Marlin/Configuration_adv.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index bf06c26f11a8..d54c7e86a0df 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1204,14 +1204,14 @@ //#define INPUT_SHAPING_Y #if ANY(INPUT_SHAPING_X, INPUT_SHAPING_Y) #if ENABLED(INPUT_SHAPING_X) - #define SHAPING_FREQ_X 40.00f // (Hz) The default dominant resonant frequency on the X axis. - #define SHAPING_ZETA_X 0.15f // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping). + #define SHAPING_FREQ_X 40.0 // (Hz) The default dominant resonant frequency on the X axis. + #define SHAPING_ZETA_X 0.15 // Damping ratio of the X axis (range: 0.0 = no damping to 1.0 = critical damping). #endif #if ENABLED(INPUT_SHAPING_Y) - #define SHAPING_FREQ_Y 40.00f // (Hz) The default dominant resonant frequency on the Y axis. - #define SHAPING_ZETA_Y 0.15f // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping). + #define SHAPING_FREQ_Y 40.0 // (Hz) The default dominant resonant frequency on the Y axis. + #define SHAPING_ZETA_Y 0.15 // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping). #endif - //#define SHAPING_MIN_FREQ 20 // By default the minimum of the shaping frequencies. Override to affect SRAM usage. + //#define SHAPING_MIN_FREQ 20.0 // By default the minimum of the shaping frequencies. Override to affect SRAM usage. //#define SHAPING_MAX_STEPRATE 10000 // By default the maximum total step rate of the shaped axes. Override to affect SRAM usage. //#define SHAPING_MENU // Add a menu to the LCD to set shaping parameters. #endif From 5359dd0d7d8f7b223ef4ace35cb6cf02ae217c9c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 22 Mar 2024 17:25:14 -0500 Subject: [PATCH 7/8] Hz --- 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 d54c7e86a0df..afec2c7528e2 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -1211,7 +1211,7 @@ #define SHAPING_FREQ_Y 40.0 // (Hz) The default dominant resonant frequency on the Y axis. #define SHAPING_ZETA_Y 0.15 // Damping ratio of the Y axis (range: 0.0 = no damping to 1.0 = critical damping). #endif - //#define SHAPING_MIN_FREQ 20.0 // By default the minimum of the shaping frequencies. Override to affect SRAM usage. + //#define SHAPING_MIN_FREQ 20.0 // (Hz) By default the minimum of the shaping frequencies. Override to affect SRAM usage. //#define SHAPING_MAX_STEPRATE 10000 // By default the maximum total step rate of the shaped axes. Override to affect SRAM usage. //#define SHAPING_MENU // Add a menu to the LCD to set shaping parameters. #endif From 4ce04e8b45098c31da57be44b29e9c3418ca2357 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 22 Mar 2024 17:30:37 -0500 Subject: [PATCH 8/8] Update SHAPING_MIN_FREQ code --- Marlin/src/module/stepper.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Marlin/src/module/stepper.h b/Marlin/src/module/stepper.h index 99fd2d293609..a11e16677eb8 100644 --- a/Marlin/src/module/stepper.h +++ b/Marlin/src/module/stepper.h @@ -159,10 +159,10 @@ constexpr ena_mask_t enable_overlap[] = { #endif #ifndef SHAPING_MIN_FREQ - #define SHAPING_MIN_FREQ _MIN(0x7FFFFFFFL OPTARG(INPUT_SHAPING_X, SHAPING_FREQ_X) OPTARG(INPUT_SHAPING_Y, SHAPING_FREQ_Y)) + #define SHAPING_MIN_FREQ _MIN(__FLT_MAX__ OPTARG(INPUT_SHAPING_X, SHAPING_FREQ_X) OPTARG(INPUT_SHAPING_Y, SHAPING_FREQ_Y)) #endif - constexpr uint16_t shaping_min_freq = SHAPING_MIN_FREQ, - shaping_echoes = max_step_rate / shaping_min_freq / 2 + 3; + constexpr float shaping_min_freq = SHAPING_MIN_FREQ; + constexpr uint16_t shaping_echoes = FLOOR(max_step_rate / shaping_min_freq / 2) + 3; typedef hal_timer_t shaping_time_t; enum shaping_echo_t { ECHO_NONE = 0, ECHO_FWD = 1, ECHO_BWD = 2 };