From e27fdd1300b3c5c096926698018647b74de5893f Mon Sep 17 00:00:00 2001 From: narno2202 Date: Thu, 22 Jun 2023 21:09:59 +0200 Subject: [PATCH 1/8] FT_MOTION : it's impossible to enble EI shaping mode with M493 S12, this PR correct this issue --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 413c63dfca08..e3231480f330 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -169,6 +169,7 @@ void GcodeSuite::M493() { #if HAS_X_AXIS case ftMotionMode_ZV: case ftMotionMode_ZVD: + case ftMotionMode_EI: case ftMotionMode_2HEI: case ftMotionMode_3HEI: case ftMotionMode_MZV: From 18cbb41bc88a037f694d250f5731a9da0230494c Mon Sep 17 00:00:00 2001 From: narno2202 Date: Thu, 22 Jun 2023 23:37:36 +0200 Subject: [PATCH 2/8] FT_MOTION : Disable M493 S0 during an ongoig print as it causes layer shifting --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index e3231480f330..3b952a30184c 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -179,6 +179,7 @@ void GcodeSuite::M493() { #endif case ftMotionMode_DISABLED: case ftMotionMode_ENABLED: + if(printJobOngoing() && ftMotionMode_DISABLED) {SERIAL_ECHOLNPGM("Ongoing Job, control mode [S] forbidden"); return;} fxdTiCtrl.cfg.mode = newmm; flag.report_h = true; if (oldmm == ftMotionMode_DISABLED) flag.reset_ft = true; From 06b2275d1cf81be9c647e576e453554ed21e3ac9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 23 Jun 2023 04:40:42 -0500 Subject: [PATCH 3/8] forbid 'M493 S' during print job --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 3b952a30184c..7dbefd97a9a4 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -164,6 +164,12 @@ void GcodeSuite::M493() { newmm = (ftMotionMode_t)parser.value_byte(); if (newmm != oldmm) { + + if (printJobOngoing()) { + SERIAL_ECHOLNPGM("Ongoing Job, control mode [S] forbidden."); + return; + } + switch (newmm) { default: SERIAL_ECHOLNPGM("?Invalid control mode [S] value."); return; #if HAS_X_AXIS @@ -179,7 +185,6 @@ void GcodeSuite::M493() { #endif case ftMotionMode_DISABLED: case ftMotionMode_ENABLED: - if(printJobOngoing() && ftMotionMode_DISABLED) {SERIAL_ECHOLNPGM("Ongoing Job, control mode [S] forbidden"); return;} fxdTiCtrl.cfg.mode = newmm; flag.report_h = true; if (oldmm == ftMotionMode_DISABLED) flag.reset_ft = true; From 83ebb75abc2b2d6aa9e3a9d21ea4723a0ff27511 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 23 Jun 2023 04:44:39 -0500 Subject: [PATCH 4/8] Allow M493 S in G-code files --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 7dbefd97a9a4..e3231480f330 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -164,12 +164,6 @@ void GcodeSuite::M493() { newmm = (ftMotionMode_t)parser.value_byte(); if (newmm != oldmm) { - - if (printJobOngoing()) { - SERIAL_ECHOLNPGM("Ongoing Job, control mode [S] forbidden."); - return; - } - switch (newmm) { default: SERIAL_ECHOLNPGM("?Invalid control mode [S] value."); return; #if HAS_X_AXIS From b9cfea33700ef95f015bf4c034af3c8e48069042 Mon Sep 17 00:00:00 2001 From: narno2202 Date: Fri, 23 Jun 2023 23:17:41 +0200 Subject: [PATCH 5/8] flag.reset_ft causes layer shift when changing the frequencies of the shaping mode while printing. So Remove it --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index e3231480f330..5d2bb9984fb8 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -258,7 +258,7 @@ void GcodeSuite::M493() { // TODO: Frequency minimum is dependent on the shaper used; the above check isn't always correct. if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) { fxdTiCtrl.cfg.baseFreq[X_AXIS] = val; - flag.update_n = flag.reset_ft = flag.report_h = true; + flag.update_n = flag.report_h = true; } else // Frequency out of range. SERIAL_ECHOLNPGM("Invalid [", AS_CHAR('A'), "] frequency value."); @@ -289,7 +289,7 @@ void GcodeSuite::M493() { const float val = parser.value_float(); if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) { fxdTiCtrl.cfg.baseFreq[Y_AXIS] = val; - flag.update_n = flag.reset_ft = flag.report_h = true; + flag.update_n = flag.report_h = true; } else // Frequency out of range. SERIAL_ECHOLNPGM("Invalid frequency [", AS_CHAR('B'), "] value."); From 03c0d83c797bd4977498169d0c81d19913d5f889 Mon Sep 17 00:00:00 2001 From: Ulendo Alex Date: Thu, 29 Jun 2023 16:21:44 -0400 Subject: [PATCH 6/8] Further runout updates: resolves layer shift on mode or frequency change. --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 5 +- Marlin/src/module/ft_motion.cpp | 76 +++++++-------------- Marlin/src/module/ft_motion.h | 2 +- 3 files changed, 28 insertions(+), 55 deletions(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 5d2bb9984fb8..ed131434dfad 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -316,7 +316,10 @@ void GcodeSuite::M493() { if (flag.update_n) fxdTiCtrl.refreshShapingN(); if (flag.update_a) fxdTiCtrl.updateShapingA(); #endif - if (flag.reset_ft) fxdTiCtrl.reset(); + if (flag.reset_ft) { + planner.synchronize(); + fxdTiCtrl.reset(); + } if (flag.report_h) say_shaping(); } diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index 6fe8e936e0e5..01d961b98bd3 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -26,6 +26,7 @@ #include "ft_motion.h" #include "stepper.h" // Access stepper block queue function and abort status. + // Access planner singleton for settings, busy flag, etc.. FxdTiCtrl fxdTiCtrl; @@ -75,7 +76,7 @@ bool FxdTiCtrl::batchRdy = false; // Indicates a batch of the fi bool FxdTiCtrl::batchRdyForInterp = false; // Indicates the batch is done being post processed, // if applicable, and is ready to be converted to step commands. bool FxdTiCtrl::runoutEna = false; // True if runout of the block hasn't been done and is allowed. -bool FxdTiCtrl::runout = false; // Indicates if runout is in progress. +bool FxdTiCtrl::blockDataIsRunout = false; // Indicates the last loaded block variables are for a runout. // Trapezoid data variables. xyze_pos_t FxdTiCtrl::startPosn, // (mm) Start position of block @@ -142,31 +143,21 @@ void FxdTiCtrl::startBlockProc(block_t * const current_block) { // Moves any free data points to the stepper buffer even if a full batch isn't ready. void FxdTiCtrl::runoutBlock() { + if (!runoutEna) return; - if (runoutEna && !batchRdy) { // If the window is full already (block intervals was a multiple of - // the batch size), or runout is not enabled, no runout is needed. - // Fill out the trajectory window with the last position calculated. - if (makeVector_batchIdx > last_batchIdx) - for (uint32_t i = makeVector_batchIdx; i < (FTM_WINDOW_SIZE); i++) { - LOGICAL_AXIS_CODE( - traj.e[i] = traj.e[makeVector_batchIdx - 1], - traj.x[i] = traj.x[makeVector_batchIdx - 1], - traj.y[i] = traj.y[makeVector_batchIdx - 1], - traj.z[i] = traj.z[makeVector_batchIdx - 1], - traj.i[i] = traj.i[makeVector_batchIdx - 1], - traj.j[i] = traj.j[makeVector_batchIdx - 1], - traj.k[i] = traj.k[makeVector_batchIdx - 1], - traj.u[i] = traj.u[makeVector_batchIdx - 1], - traj.v[i] = traj.v[makeVector_batchIdx - 1], - traj.w[i] = traj.w[makeVector_batchIdx - 1] - ); - } + startPosn = endPosn_prevBlock; + ratio.reset(); - makeVector_batchIdx = last_batchIdx; - batchRdy = true; - runout = true; - } - runoutEna = false; + accel_P = decel_P = 0.0f; + + max_intervals = WITHIN(cfg.mode, 10U, 19U) ? (FTM_BATCH_SIZE) * ceil((FTM_ZMAX) / (FTM_BATCH_SIZE)) : 0; + + static constexpr uint32_t nr_windows = ceil((FTM_WINDOW_SIZE) / (FTM_BATCH_SIZE)); + if (max_intervals <= (FTM_BATCH_SIZE) * (nr_windows - 1)) max_intervals = (FTM_BATCH_SIZE) * nr_windows; + max_intervals += (FTM_WINDOW_SIZE) - makeVector_batchIdx; + + blockProcRdy = blockDataIsRunout = true; + runoutEna = blockProcDn = false; } // Controller main, to be invoked from non-isr task. @@ -183,40 +174,22 @@ void FxdTiCtrl::loop() { if (sts_stepperBusy) return; // Wait until motion buffers are emptied reset(); blockProcDn = true; // Set queueing to look for next block. - runoutEna = false; // Disabling running out this block, since we want to halt the motion. + runoutEna = false; // Disabling running out this block, since we want to halt the motion. stepper.abort_current_block = false; // Abort finished. } // Planner processing and block conversion. - if (!blockProcRdy && !runout) stepper.fxdTiCtrl_BlockQueueUpdate(); + if (!blockProcRdy) stepper.fxdTiCtrl_BlockQueueUpdate(); if (blockProcRdy) { - if (!blockProcRdy_z1) loadBlockData(current_block_cpy); // One-shot. + if (!blockProcRdy_z1) { // One-shot. + if (!blockDataIsRunout) loadBlockData(current_block_cpy); + else blockDataIsRunout = false; + } while (!blockProcDn && !batchRdy && (makeVector_idx - makeVector_idx_z1 < (FTM_POINTS_PER_LOOP))) makeVector(); } - if (runout && !batchRdy) { // The lower half of the window has been runout. - // Runout the upper half of the window: the upper half has been shifted into the lower - // half. Fill out the upper half so another batch can be processed. - for (uint32_t i = last_batchIdx; i < (FTM_WINDOW_SIZE) - 1; i++) { - LOGICAL_AXIS_CODE( - traj.e[i] = traj.e[(FTM_WINDOW_SIZE) - 1], - traj.x[i] = traj.x[(FTM_WINDOW_SIZE) - 1], - traj.y[i] = traj.y[(FTM_WINDOW_SIZE) - 1], - traj.z[i] = traj.z[(FTM_WINDOW_SIZE) - 1], - traj.i[i] = traj.i[(FTM_WINDOW_SIZE) - 1], - traj.j[i] = traj.j[(FTM_WINDOW_SIZE) - 1], - traj.k[i] = traj.k[(FTM_WINDOW_SIZE) - 1], - traj.u[i] = traj.u[(FTM_WINDOW_SIZE) - 1], - traj.v[i] = traj.v[(FTM_WINDOW_SIZE) - 1], - traj.w[i] = traj.w[(FTM_WINDOW_SIZE) - 1] - ); - } - batchRdy = true; - runout = false; - } - // FBS / post processing. if (batchRdy && !batchRdyForInterp) { @@ -401,7 +374,6 @@ void FxdTiCtrl::reset() { blockProcRdy = blockProcRdy_z1 = blockProcDn = false; batchRdy = batchRdyForInterp = false; runoutEna = false; - runout = false; endPosn_prevBlock.reset(); @@ -530,7 +502,7 @@ void FxdTiCtrl::loadBlockData(block_t * const current_block) { s_2e = s_1e + F_P * T2_P; // One less than (Accel + Coasting + Decel) datapoints - max_intervals = N1 + N2 + N3 - 1U; + max_intervals = N1 + N2 + N3; endPosn_prevBlock += moveDist; } @@ -643,13 +615,11 @@ void FxdTiCtrl::makeVector() { batchRdy = true; } - if (makeVector_idx == max_intervals) { + if (++makeVector_idx == max_intervals) { blockProcDn = true; blockProcRdy = false; makeVector_idx = 0; } - else - makeVector_idx++; } // Interpolates single data point to stepper commands. diff --git a/Marlin/src/module/ft_motion.h b/Marlin/src/module/ft_motion.h index 2186ecb710a8..36b1411462f1 100644 --- a/Marlin/src/module/ft_motion.h +++ b/Marlin/src/module/ft_motion.h @@ -133,7 +133,7 @@ class FxdTiCtrl { static bool blockProcRdy, blockProcRdy_z1, blockProcDn; static bool batchRdy, batchRdyForInterp; static bool runoutEna; - static bool runout; + static bool blockDataIsRunout; // Trapezoid data variables. static xyze_pos_t startPosn, // (mm) Start position of block From 47fc1613c93bd6cd568913f9925dab6345727041 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 29 Jun 2023 17:55:03 -0500 Subject: [PATCH 7/8] Already synchronized --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 5 +---- Marlin/src/module/ft_motion.cpp | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index ed131434dfad..5d2bb9984fb8 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -316,10 +316,7 @@ void GcodeSuite::M493() { if (flag.update_n) fxdTiCtrl.refreshShapingN(); if (flag.update_a) fxdTiCtrl.updateShapingA(); #endif - if (flag.reset_ft) { - planner.synchronize(); - fxdTiCtrl.reset(); - } + if (flag.reset_ft) fxdTiCtrl.reset(); if (flag.report_h) say_shaping(); } diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index 01d961b98bd3..85507f77849c 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -174,7 +174,7 @@ void FxdTiCtrl::loop() { if (sts_stepperBusy) return; // Wait until motion buffers are emptied reset(); blockProcDn = true; // Set queueing to look for next block. - runoutEna = false; // Disabling running out this block, since we want to halt the motion. + runoutEna = false; // Disabling running out this block, since we want to halt the motion. stepper.abort_current_block = false; // Abort finished. } From 3f1fb8eed25c61c6ca65b728ad70234ac3d37916 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 29 Jun 2023 18:17:54 -0500 Subject: [PATCH 8/8] more predef --- Marlin/src/module/ft_motion.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index 85507f77849c..581849703cdc 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -150,10 +150,11 @@ void FxdTiCtrl::runoutBlock() { accel_P = decel_P = 0.0f; - max_intervals = WITHIN(cfg.mode, 10U, 19U) ? (FTM_BATCH_SIZE) * ceil((FTM_ZMAX) / (FTM_BATCH_SIZE)) : 0; + static constexpr uint32_t shaper_intervals = (FTM_BATCH_SIZE) * ceil((FTM_ZMAX) / (FTM_BATCH_SIZE)), + min_max_intervals = (FTM_BATCH_SIZE) * ceil((FTM_WINDOW_SIZE) / (FTM_BATCH_SIZE)); - static constexpr uint32_t nr_windows = ceil((FTM_WINDOW_SIZE) / (FTM_BATCH_SIZE)); - if (max_intervals <= (FTM_BATCH_SIZE) * (nr_windows - 1)) max_intervals = (FTM_BATCH_SIZE) * nr_windows; + max_intervals = cfg.modeHasShaper() ? shaper_intervals : 0; + if (max_intervals <= min_max_intervals - (FTM_BATCH_SIZE)) max_intervals = min_max_intervals; max_intervals += (FTM_WINDOW_SIZE) - makeVector_batchIdx; blockProcRdy = blockDataIsRunout = true;