Skip to content

Commit

Permalink
🩹 Fix FT Motion toggle in active job (MarlinFirmware#27335)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
narno2202 and thinkyhead authored Aug 17, 2024
1 parent 4a36520 commit 381aeb9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 54 deletions.
42 changes: 14 additions & 28 deletions Marlin/src/gcode/feature/ft_motion/M493.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,18 @@ void GcodeSuite::M493_report(const bool forReplay/*=true*/) {
* R 0.00 Set the vibration tolerance for the Y axis
*/
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())
flag.report_h = true;
flag.report = true;

// Parse 'S' mode parameter.
if (parser.seen('S')) {
const bool active = parser.value_bool();

if (active != ftMotion.cfg.active) {
switch (active) {
case false:
flag.reset_ft = true;
// fall-thru
case true:
flag.report_h = true;
ftMotion.cfg.active = active;
break;
}
stepper.ftMotion_syncPosition();
ftMotion.cfg.active = active;
flag.report = true;
}
}

Expand All @@ -228,7 +221,7 @@ void GcodeSuite::M493() {
case ftMotionShaper_3HEI:
case ftMotionShaper_MZV:
ftMotion.cfg.shaper[axis] = newsh;
flag.update = flag.report_h = true;
flag.update = flag.report = true;
break;
}
}
Expand All @@ -249,7 +242,7 @@ void GcodeSuite::M493() {
if (parser.seen('P')) {
const bool val = parser.value_bool();
ftMotion.cfg.linearAdvEna = val;
flag.report_h = true;
flag.report = true;
SERIAL_ECHO_TERNARY(val, "Linear Advance ", "en", "dis", "abled.\n");
}

Expand All @@ -258,7 +251,7 @@ void GcodeSuite::M493() {
const float val = parser.value_float();
if (val >= 0.0f) {
ftMotion.cfg.linearAdvK = val;
flag.report_h = true;
flag.report = true;
}
else // Value out of range.
SERIAL_ECHOLNPGM("Linear Advance gain out of range.");
Expand All @@ -281,7 +274,7 @@ void GcodeSuite::M493() {
#endif
case dynFreqMode_DISABLED:
ftMotion.cfg.dynFreqMode = val;
flag.report_h = true;
flag.report = true;
break;
default:
SERIAL_ECHOLNPGM("?Invalid Dynamic Frequency Mode [D] value.");
Expand Down Expand Up @@ -309,7 +302,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)) {
ftMotion.cfg.baseFreq.x = val;
flag.update = flag.reset_ft = flag.report_h = true;
flag.update = flag.report = true;
}
else // Frequency out of range.
SERIAL_ECHOLNPGM("Invalid [", C('A'), "] frequency value.");
Expand All @@ -323,7 +316,7 @@ void GcodeSuite::M493() {
if (parser.seenval('F')) {
if (modeUsesDynFreq) {
ftMotion.cfg.dynFreqK.x = parser.value_float();
flag.report_h = true;
flag.report = true;
}
else
SERIAL_ECHOLNPGM("Wrong mode for [", C('F'), "] frequency scaling.");
Expand Down Expand Up @@ -370,7 +363,7 @@ void GcodeSuite::M493() {
const float val = parser.value_float();
if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) {
ftMotion.cfg.baseFreq.y = val;
flag.update = flag.reset_ft = flag.report_h = true;
flag.update = flag.report = true;
}
else // Frequency out of range.
SERIAL_ECHOLNPGM("Invalid frequency [", C('B'), "] value.");
Expand All @@ -384,7 +377,7 @@ void GcodeSuite::M493() {
if (parser.seenval('H')) {
if (modeUsesDynFreq) {
ftMotion.cfg.dynFreqK.y = parser.value_float();
flag.report_h = true;
flag.report = true;
}
else
SERIAL_ECHOLNPGM("Wrong mode for [", C('H'), "] frequency scaling.");
Expand Down Expand Up @@ -423,16 +416,9 @@ void GcodeSuite::M493() {

#endif // HAS_Y_AXIS

planner.synchronize();

if (flag.update) ftMotion.update_shaping_params();

if (flag.reset_ft) {
stepper.ftMotion_syncPosition();
ftMotion.reset();
}

if (flag.report_h) say_shaping();
if (flag.report) say_shaping();
}

#endif // FT_MOTION
50 changes: 25 additions & 25 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,44 +351,44 @@ void menu_move() {
}
#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.update_shaping_params();
ui.go_back();
}

inline void menu_ftm_cmpn_x() {
inline void menu_ftm_shaper_x() {
const ftMotionShaper_t shaper = ftMotion.cfg.shaper.x;
START_MENU();
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_ZV) ACTION_ITEM(MSG_FTM_ZV, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZV); });
if (shaper != ftMotionShaper_ZVD) ACTION_ITEM(MSG_FTM_ZVD, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZVD); });
if (shaper != ftMotionShaper_ZVDD) ACTION_ITEM(MSG_FTM_ZVDD, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZVDD); });
if (shaper != ftMotionShaper_ZVDDD) ACTION_ITEM(MSG_FTM_ZVDDD,[]{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_ZVDDD); });
if (shaper != ftMotionShaper_EI) ACTION_ITEM(MSG_FTM_EI, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_EI); });
if (shaper != ftMotionShaper_2HEI) ACTION_ITEM(MSG_FTM_2HEI, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_2HEI); });
if (shaper != ftMotionShaper_3HEI) ACTION_ITEM(MSG_FTM_3HEI, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_3HEI); });
if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_cmpn(X_AXIS, ftMotionShaper_MZV); });
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_shaper(X_AXIS, ftMotionShaper_ZV); });
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_shaper(X_AXIS, ftMotionShaper_ZVDD); });
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_shaper(X_AXIS, ftMotionShaper_EI); });
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_shaper(X_AXIS, ftMotionShaper_3HEI); });
if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_shaper(X_AXIS, ftMotionShaper_MZV); });

END_MENU();
}

inline void menu_ftm_cmpn_y() {
inline void menu_ftm_shaper_y() {
const ftMotionShaper_t shaper = ftMotion.cfg.shaper.y;
START_MENU();
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_ZV) ACTION_ITEM(MSG_FTM_ZV, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZV); });
if (shaper != ftMotionShaper_ZVD) ACTION_ITEM(MSG_FTM_ZVD, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZVD); });
if (shaper != ftMotionShaper_ZVDD) ACTION_ITEM(MSG_FTM_ZVDD, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZVDD); });
if (shaper != ftMotionShaper_ZVDDD) ACTION_ITEM(MSG_FTM_ZVDDD,[]{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_ZVDDD); });
if (shaper != ftMotionShaper_EI) ACTION_ITEM(MSG_FTM_EI, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_EI); });
if (shaper != ftMotionShaper_2HEI) ACTION_ITEM(MSG_FTM_2HEI, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_2HEI); });
if (shaper != ftMotionShaper_3HEI) ACTION_ITEM(MSG_FTM_3HEI, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_3HEI); });
if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_cmpn(Y_AXIS, ftMotionShaper_MZV); });
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_shaper(Y_AXIS, ftMotionShaper_ZV); });
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_shaper(Y_AXIS, ftMotionShaper_ZVDD); });
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_shaper(Y_AXIS, ftMotionShaper_EI); });
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_shaper(Y_AXIS, ftMotionShaper_3HEI); });
if (shaper != ftMotionShaper_MZV) ACTION_ITEM(MSG_FTM_MZV, []{ ftm_menu_set_shaper(Y_AXIS, ftMotionShaper_MZV); });

END_MENU();
}
Expand Down Expand Up @@ -438,7 +438,7 @@ void menu_move() {

if (c.active) {
#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();

if (AXIS_HAS_SHAPER(X)) {
Expand All @@ -449,7 +449,7 @@ void menu_move() {
}
#endif
#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();

if (AXIS_HAS_SHAPER(Y)) {
Expand Down Expand Up @@ -495,11 +495,11 @@ void menu_move() {
START_MENU();

#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();
#endif
#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();
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3422,7 +3422,7 @@ void Stepper::set_axis_position(const AxisEnum a, const int32_t &v) {
#if ENABLED(FT_MOTION)

void Stepper::ftMotion_syncPosition() {
//planner.synchronize(); planner already synchronized in M493
planner.synchronize();

// Update stepper positions from the planner
AVR_ATOMIC_SECTION_START();
Expand Down

0 comments on commit 381aeb9

Please sign in to comment.