0
0
Fork 0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2025-02-27 19:36:58 +00:00

🩹 Fix FT Motion toggle in active job (#27335)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
This commit is contained in:
narno2202 2024-08-17 20:02:05 +02:00 committed by GitHub
parent 4a36520820
commit 381aeb94c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 40 additions and 54 deletions

View file

@ -190,25 +190,18 @@ void GcodeSuite::M493_report(const bool forReplay/*=true*/) {
* R 0.00 Set the vibration tolerance for the Y axis * R 0.00 Set the vibration tolerance for the Y axis
*/ */
void GcodeSuite::M493() { void GcodeSuite::M493() {
struct { bool update:1, reset_ft:1, report_h:1; } flag = { false }; struct { bool update:1, report:1; } flag = { false };
if (!parser.seen_any()) if (!parser.seen_any())
flag.report_h = true; flag.report = true;
// Parse 'S' mode parameter. // Parse 'S' mode parameter.
if (parser.seen('S')) { if (parser.seen('S')) {
const bool active = parser.value_bool(); const bool active = parser.value_bool();
if (active != ftMotion.cfg.active) { if (active != ftMotion.cfg.active) {
switch (active) { stepper.ftMotion_syncPosition();
case false: ftMotion.cfg.active = active;
flag.reset_ft = true; flag.report = true;
// fall-thru
case true:
flag.report_h = true;
ftMotion.cfg.active = active;
break;
}
} }
} }
@ -228,7 +221,7 @@ void GcodeSuite::M493() {
case ftMotionShaper_3HEI: case ftMotionShaper_3HEI:
case ftMotionShaper_MZV: case ftMotionShaper_MZV:
ftMotion.cfg.shaper[axis] = newsh; ftMotion.cfg.shaper[axis] = newsh;
flag.update = flag.report_h = true; flag.update = flag.report = true;
break; break;
} }
} }
@ -249,7 +242,7 @@ void GcodeSuite::M493() {
if (parser.seen('P')) { if (parser.seen('P')) {
const bool val = parser.value_bool(); const bool val = parser.value_bool();
ftMotion.cfg.linearAdvEna = val; ftMotion.cfg.linearAdvEna = val;
flag.report_h = true; flag.report = true;
SERIAL_ECHO_TERNARY(val, "Linear Advance ", "en", "dis", "abled.\n"); SERIAL_ECHO_TERNARY(val, "Linear Advance ", "en", "dis", "abled.\n");
} }
@ -258,7 +251,7 @@ void GcodeSuite::M493() {
const float val = parser.value_float(); const float val = parser.value_float();
if (val >= 0.0f) { if (val >= 0.0f) {
ftMotion.cfg.linearAdvK = val; ftMotion.cfg.linearAdvK = val;
flag.report_h = true; flag.report = true;
} }
else // Value out of range. else // Value out of range.
SERIAL_ECHOLNPGM("Linear Advance gain out of range."); SERIAL_ECHOLNPGM("Linear Advance gain out of range.");
@ -281,7 +274,7 @@ void GcodeSuite::M493() {
#endif #endif
case dynFreqMode_DISABLED: case dynFreqMode_DISABLED:
ftMotion.cfg.dynFreqMode = val; ftMotion.cfg.dynFreqMode = val;
flag.report_h = true; flag.report = true;
break; break;
default: default:
SERIAL_ECHOLNPGM("?Invalid Dynamic Frequency Mode [D] value."); SERIAL_ECHOLNPGM("?Invalid Dynamic Frequency Mode [D] value.");
@ -309,7 +302,7 @@ void GcodeSuite::M493() {
// TODO: Frequency minimum is dependent on the shaper used; the above check isn't always correct. // 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)) { if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) {
ftMotion.cfg.baseFreq.x = val; ftMotion.cfg.baseFreq.x = val;
flag.update = flag.reset_ft = flag.report_h = true; flag.update = flag.report = true;
} }
else // Frequency out of range. else // Frequency out of range.
SERIAL_ECHOLNPGM("Invalid [", C('A'), "] frequency value."); SERIAL_ECHOLNPGM("Invalid [", C('A'), "] frequency value.");
@ -323,7 +316,7 @@ void GcodeSuite::M493() {
if (parser.seenval('F')) { if (parser.seenval('F')) {
if (modeUsesDynFreq) { if (modeUsesDynFreq) {
ftMotion.cfg.dynFreqK.x = parser.value_float(); ftMotion.cfg.dynFreqK.x = parser.value_float();
flag.report_h = true; flag.report = true;
} }
else else
SERIAL_ECHOLNPGM("Wrong mode for [", C('F'), "] frequency scaling."); SERIAL_ECHOLNPGM("Wrong mode for [", C('F'), "] frequency scaling.");
@ -370,7 +363,7 @@ void GcodeSuite::M493() {
const float val = parser.value_float(); const float val = parser.value_float();
if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) { if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) {
ftMotion.cfg.baseFreq.y = val; ftMotion.cfg.baseFreq.y = val;
flag.update = flag.reset_ft = flag.report_h = true; flag.update = flag.report = true;
} }
else // Frequency out of range. else // Frequency out of range.
SERIAL_ECHOLNPGM("Invalid frequency [", C('B'), "] value."); SERIAL_ECHOLNPGM("Invalid frequency [", C('B'), "] value.");
@ -384,7 +377,7 @@ void GcodeSuite::M493() {
if (parser.seenval('H')) { if (parser.seenval('H')) {
if (modeUsesDynFreq) { if (modeUsesDynFreq) {
ftMotion.cfg.dynFreqK.y = parser.value_float(); ftMotion.cfg.dynFreqK.y = parser.value_float();
flag.report_h = true; flag.report = true;
} }
else else
SERIAL_ECHOLNPGM("Wrong mode for [", C('H'), "] frequency scaling."); SERIAL_ECHOLNPGM("Wrong mode for [", C('H'), "] frequency scaling.");
@ -423,16 +416,9 @@ void GcodeSuite::M493() {
#endif // HAS_Y_AXIS #endif // HAS_Y_AXIS
planner.synchronize();
if (flag.update) ftMotion.update_shaping_params(); if (flag.update) ftMotion.update_shaping_params();
if (flag.reset_ft) { if (flag.report) say_shaping();
stepper.ftMotion_syncPosition();
ftMotion.reset();
}
if (flag.report_h) say_shaping();
} }
#endif // FT_MOTION #endif // FT_MOTION

View file

@ -351,44 +351,44 @@ void menu_move() {
} }
#endif #endif
void ftm_menu_set_cmpn(const AxisEnum axis, const ftMotionShaper_t s) { void ftm_menu_set_shaper(const AxisEnum axis, const ftMotionShaper_t s) {
ftMotion.cfg.shaper[axis] = s; ftMotion.cfg.shaper[axis] = s;
ftMotion.update_shaping_params(); ftMotion.update_shaping_params();
ui.go_back(); ui.go_back();
} }
inline void menu_ftm_cmpn_x() { inline void menu_ftm_shaper_x() {
const ftMotionShaper_t shaper = ftMotion.cfg.shaper.x; const ftMotionShaper_t shaper = ftMotion.cfg.shaper.x;
START_MENU(); START_MENU();
BACK_ITEM(MSG_FIXED_TIME_MOTION); BACK_ITEM(MSG_FIXED_TIME_MOTION);
if (shaper != ftMotionShaper_NONE) ACTION_ITEM(MSG_LCD_OFF, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_NONE); }); if (shaper != ftMotionShaper_NONE) ACTION_ITEM(MSG_LCD_OFF, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_NONE); });
if (shaper != ftMotionShaper_ZV) ACTION_ITEM(MSG_FTM_ZV, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZV); }); if (shaper != ftMotionShaper_ZV) ACTION_ITEM(MSG_FTM_ZV, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_ZV); });
if (shaper != ftMotionShaper_ZVD) ACTION_ITEM(MSG_FTM_ZVD, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZVD); }); if (shaper != ftMotionShaper_ZVD) ACTION_ITEM(MSG_FTM_ZVD, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_ZVD); });
if (shaper != ftMotionShaper_ZVDD) ACTION_ITEM(MSG_FTM_ZVDD, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZVDD); }); if (shaper != ftMotionShaper_ZVDD) ACTION_ITEM(MSG_FTM_ZVDD, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_ZVDD); });
if (shaper != ftMotionShaper_ZVDDD) ACTION_ITEM(MSG_FTM_ZVDDD,[]{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZVDDD); }); if (shaper != ftMotionShaper_ZVDDD) ACTION_ITEM(MSG_FTM_ZVDDD,[]{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_ZVDDD); });
if (shaper != ftMotionShaper_EI) ACTION_ITEM(MSG_FTM_EI, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_EI); }); if (shaper != ftMotionShaper_EI) ACTION_ITEM(MSG_FTM_EI, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_EI); });
if (shaper != ftMotionShaper_2HEI) ACTION_ITEM(MSG_FTM_2HEI, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_2HEI); }); if (shaper != ftMotionShaper_2HEI) ACTION_ITEM(MSG_FTM_2HEI, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_2HEI); });
if (shaper != ftMotionShaper_3HEI) ACTION_ITEM(MSG_FTM_3HEI, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_3HEI); }); if (shaper != ftMotionShaper_3HEI) ACTION_ITEM(MSG_FTM_3HEI, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_3HEI); });
if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_MZV); }); if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_MZV); });
END_MENU(); END_MENU();
} }
inline void menu_ftm_cmpn_y() { inline void menu_ftm_shaper_y() {
const ftMotionShaper_t shaper = ftMotion.cfg.shaper.y; const ftMotionShaper_t shaper = ftMotion.cfg.shaper.y;
START_MENU(); START_MENU();
BACK_ITEM(MSG_FIXED_TIME_MOTION); BACK_ITEM(MSG_FIXED_TIME_MOTION);
if (shaper != ftMotionShaper_NONE) ACTION_ITEM(MSG_LCD_OFF, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_NONE); }); if (shaper != ftMotionShaper_NONE) ACTION_ITEM(MSG_LCD_OFF, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_NONE); });
if (shaper != ftMotionShaper_ZV) ACTION_ITEM(MSG_FTM_ZV, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZV); }); if (shaper != ftMotionShaper_ZV) ACTION_ITEM(MSG_FTM_ZV, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_ZV); });
if (shaper != ftMotionShaper_ZVD) ACTION_ITEM(MSG_FTM_ZVD, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZVD); }); if (shaper != ftMotionShaper_ZVD) ACTION_ITEM(MSG_FTM_ZVD, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_ZVD); });
if (shaper != ftMotionShaper_ZVDD) ACTION_ITEM(MSG_FTM_ZVDD, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZVDD); }); if (shaper != ftMotionShaper_ZVDD) ACTION_ITEM(MSG_FTM_ZVDD, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_ZVDD); });
if (shaper != ftMotionShaper_ZVDDD) ACTION_ITEM(MSG_FTM_ZVDDD,[]{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZVDDD); }); if (shaper != ftMotionShaper_ZVDDD) ACTION_ITEM(MSG_FTM_ZVDDD,[]{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_ZVDDD); });
if (shaper != ftMotionShaper_EI) ACTION_ITEM(MSG_FTM_EI, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_EI); }); if (shaper != ftMotionShaper_EI) ACTION_ITEM(MSG_FTM_EI, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_EI); });
if (shaper != ftMotionShaper_2HEI) ACTION_ITEM(MSG_FTM_2HEI, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_2HEI); }); if (shaper != ftMotionShaper_2HEI) ACTION_ITEM(MSG_FTM_2HEI, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_2HEI); });
if (shaper != ftMotionShaper_3HEI) ACTION_ITEM(MSG_FTM_3HEI, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_3HEI); }); if (shaper != ftMotionShaper_3HEI) ACTION_ITEM(MSG_FTM_3HEI, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_3HEI); });
if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_MZV); }); if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_MZV); });
END_MENU(); END_MENU();
} }
@ -438,7 +438,7 @@ void menu_move() {
if (c.active) { if (c.active) {
#if HAS_X_AXIS #if HAS_X_AXIS
SUBMENU_N(X_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_cmpn_x); SUBMENU_N(X_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_shaper_x);
MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[X_AXIS]); MENU_ITEM_ADDON_END(); MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[X_AXIS]); MENU_ITEM_ADDON_END();
if (AXIS_HAS_SHAPER(X)) { if (AXIS_HAS_SHAPER(X)) {
@ -449,7 +449,7 @@ void menu_move() {
} }
#endif #endif
#if HAS_Y_AXIS #if HAS_Y_AXIS
SUBMENU_N(Y_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_cmpn_y); SUBMENU_N(Y_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_shaper_y);
MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[Y_AXIS]); MENU_ITEM_ADDON_END(); MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[Y_AXIS]); MENU_ITEM_ADDON_END();
if (AXIS_HAS_SHAPER(Y)) { if (AXIS_HAS_SHAPER(Y)) {
@ -495,11 +495,11 @@ void menu_move() {
START_MENU(); START_MENU();
#if HAS_X_AXIS #if HAS_X_AXIS
SUBMENU_N(X_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_cmpn_x); SUBMENU_N(X_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_shaper_x);
MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[X_AXIS]); MENU_ITEM_ADDON_END(); MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[X_AXIS]); MENU_ITEM_ADDON_END();
#endif #endif
#if HAS_Y_AXIS #if HAS_Y_AXIS
SUBMENU_N(Y_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_cmpn_y); SUBMENU_N(Y_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_shaper_y);
MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[Y_AXIS]); MENU_ITEM_ADDON_END(); MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[Y_AXIS]); MENU_ITEM_ADDON_END();
#endif #endif

View file

@ -3422,7 +3422,7 @@ void Stepper::set_axis_position(const AxisEnum a, const int32_t &v) {
#if ENABLED(FT_MOTION) #if ENABLED(FT_MOTION)
void Stepper::ftMotion_syncPosition() { void Stepper::ftMotion_syncPosition() {
//planner.synchronize(); planner already synchronized in M493 planner.synchronize();
// Update stepper positions from the planner // Update stepper positions from the planner
AVR_ATOMIC_SECTION_START(); AVR_ATOMIC_SECTION_START();