Skip to content

Commit

Permalink
πŸ§‘β€πŸ’» FxdTiCtrl => FTMotion
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 12, 2023
1 parent a7a3abb commit e7e77d9
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 208 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ void idle(const bool no_stepper_sleep/*=false*/) {
TERN_(HAS_TFT_LVGL_UI, LV_TASK_HANDLER());

// Manage Fixed-time Motion Control
TERN_(FT_MOTION, fxdTiCtrl.loop());
TERN_(FT_MOTION, ftMotion.loop());

IDLE_DONE:
TERN_(MARLIN_DEV_MODE, idle_depth--);
Expand Down Expand Up @@ -1632,7 +1632,7 @@ void setup() {
#endif

#if ENABLED(FT_MOTION)
SETUP_RUN(fxdTiCtrl.init());
SETUP_RUN(ftMotion.init());
#endif

marlin_state = MF_RUNNING;
Expand Down
66 changes: 33 additions & 33 deletions Marlin/src/gcode/feature/ft_motion/M493.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@

void say_shaping() {
// FT Enabled
SERIAL_ECHO_TERNARY(fxdTiCtrl.cfg.mode, "Fixed-Time Motion ", "en", "dis", "abled");
SERIAL_ECHO_TERNARY(ftMotion.cfg.mode, "Fixed-Time Motion ", "en", "dis", "abled");

// FT Shaping
#if HAS_X_AXIS
if (fxdTiCtrl.cfg.mode > ftMotionMode_ENABLED) {
if (ftMotion.cfg.mode > ftMotionMode_ENABLED) {
SERIAL_ECHOPGM(" with ");
switch (fxdTiCtrl.cfg.mode) {
switch (ftMotion.cfg.mode) {
default: break;
case ftMotionMode_ZV: SERIAL_ECHOPGM("ZV"); break;
case ftMotionMode_ZVD: SERIAL_ECHOPGM("ZVD"); break;
Expand All @@ -51,15 +51,15 @@ void say_shaping() {
#endif
SERIAL_ECHOLNPGM(".");

const bool z_based = TERN0(HAS_DYNAMIC_FREQ_MM, fxdTiCtrl.cfg.dynFreqMode == dynFreqMode_Z_BASED),
g_based = TERN0(HAS_DYNAMIC_FREQ_G, fxdTiCtrl.cfg.dynFreqMode == dynFreqMode_MASS_BASED),
const bool z_based = TERN0(HAS_DYNAMIC_FREQ_MM, ftMotion.cfg.dynFreqMode == dynFreqMode_Z_BASED),
g_based = TERN0(HAS_DYNAMIC_FREQ_G, ftMotion.cfg.dynFreqMode == dynFreqMode_MASS_BASED),
dynamic = z_based || g_based;

// FT Dynamic Frequency Mode
if (fxdTiCtrl.cfg.modeHasShaper()) {
if (ftMotion.cfg.modeHasShaper()) {
#if HAS_DYNAMIC_FREQ
SERIAL_ECHOPGM("Dynamic Frequency Mode ");
switch (fxdTiCtrl.cfg.dynFreqMode) {
switch (ftMotion.cfg.dynFreqMode) {
default:
case dynFreqMode_DISABLED: SERIAL_ECHOPGM("disabled"); break;
#if HAS_DYNAMIC_FREQ_MM
Expand All @@ -74,32 +74,32 @@ void say_shaping() {

#if HAS_X_AXIS
SERIAL_ECHO_TERNARY(dynamic, "X/A ", "base dynamic", "static", " compensator frequency: ");
SERIAL_ECHO(p_float_t(fxdTiCtrl.cfg.baseFreq[X_AXIS], 2), F("Hz"));
SERIAL_ECHO(p_float_t(ftMotion.cfg.baseFreq[X_AXIS], 2), F("Hz"));
#if HAS_DYNAMIC_FREQ
if (dynamic) SERIAL_ECHO(" scaling: ", p_float_t(fxdTiCtrl.cfg.dynFreqK[X_AXIS], 8), F("Hz/"), z_based ? F("mm") : F("g"));
if (dynamic) SERIAL_ECHO(" scaling: ", p_float_t(ftMotion.cfg.dynFreqK[X_AXIS], 8), F("Hz/"), z_based ? F("mm") : F("g"));
#endif
SERIAL_EOL();
#endif

#if HAS_Y_AXIS
SERIAL_ECHO_TERNARY(dynamic, "Y/B ", "base dynamic", "static", " compensator frequency: ");
SERIAL_ECHO(p_float_t(fxdTiCtrl.cfg.baseFreq[Y_AXIS], 2), F(" Hz"));
SERIAL_ECHO(p_float_t(ftMotion.cfg.baseFreq[Y_AXIS], 2), F(" Hz"));
#if HAS_DYNAMIC_FREQ
if (dynamic) SERIAL_ECHO(F(" scaling: "), p_float_t(fxdTiCtrl.cfg.dynFreqK[Y_AXIS], 8), F("Hz/"), z_based ? F("mm") : F("g"));
if (dynamic) SERIAL_ECHO(F(" scaling: "), p_float_t(ftMotion.cfg.dynFreqK[Y_AXIS], 8), F("Hz/"), z_based ? F("mm") : F("g"));
#endif
SERIAL_EOL();
#endif
}

#if HAS_EXTRUDERS
SERIAL_ECHO_TERNARY(fxdTiCtrl.cfg.linearAdvEna, "Linear Advance ", "en", "dis", "abled");
SERIAL_ECHOLN(F(". Gain: "), p_float_t(fxdTiCtrl.cfg.linearAdvK, 5));
SERIAL_ECHO_TERNARY(ftMotion.cfg.linearAdvEna, "Linear Advance ", "en", "dis", "abled");
SERIAL_ECHOLN(F(". Gain: "), p_float_t(ftMotion.cfg.linearAdvK, 5));
#endif
}

void GcodeSuite::M493_report(const bool forReplay/*=true*/) {
report_heading_etc(forReplay, F(STR_FT_MOTION));
const ft_config_t &c = fxdTiCtrl.cfg;
const ft_config_t &c = ftMotion.cfg;
SERIAL_ECHOPGM(" M493 S", c.mode);
#if HAS_X_AXIS
SERIAL_ECHOPGM(" A", c.baseFreq[X_AXIS]);
Expand Down Expand Up @@ -160,7 +160,7 @@ void GcodeSuite::M493() {

// Parse 'S' mode parameter.
if (parser.seenval('S')) {
const ftMotionMode_t oldmm = fxdTiCtrl.cfg.mode,
const ftMotionMode_t oldmm = ftMotion.cfg.mode,
newmm = (ftMotionMode_t)parser.value_byte();

if (newmm != oldmm) {
Expand All @@ -179,7 +179,7 @@ void GcodeSuite::M493() {
#endif
case ftMotionMode_DISABLED:
case ftMotionMode_ENABLED:
fxdTiCtrl.cfg.mode = newmm;
ftMotion.cfg.mode = newmm;
flag.report_h = true;
if (oldmm == ftMotionMode_DISABLED) flag.reset_ft = true;
break;
Expand All @@ -192,15 +192,15 @@ void GcodeSuite::M493() {
// Pressure control (linear advance) parameter.
if (parser.seen('P')) {
const bool val = parser.value_bool();
fxdTiCtrl.cfg.linearAdvEna = val;
ftMotion.cfg.linearAdvEna = val;
SERIAL_ECHO_TERNARY(val, "Linear Advance ", "en", "dis", "abled.\n");
}

// Pressure control (linear advance) gain parameter.
if (parser.seenval('K')) {
const float val = parser.value_float();
if (val >= 0.0f) {
fxdTiCtrl.cfg.linearAdvK = val;
ftMotion.cfg.linearAdvK = val;
flag.report_h = true;
}
else // Value out of range.
Expand All @@ -213,22 +213,22 @@ void GcodeSuite::M493() {

// Dynamic frequency mode parameter.
if (parser.seenval('D')) {
if (fxdTiCtrl.cfg.modeHasShaper()) {
if (ftMotion.cfg.modeHasShaper()) {
const dynFreqMode_t val = dynFreqMode_t(parser.value_byte());
switch (val) {
case dynFreqMode_DISABLED:
fxdTiCtrl.cfg.dynFreqMode = val;
ftMotion.cfg.dynFreqMode = val;
flag.report_h = true;
break;
#if HAS_DYNAMIC_FREQ_MM
case dynFreqMode_Z_BASED:
fxdTiCtrl.cfg.dynFreqMode = val;
ftMotion.cfg.dynFreqMode = val;
flag.report_h = true;
break;
#endif
#if HAS_DYNAMIC_FREQ_G
case dynFreqMode_MASS_BASED:
fxdTiCtrl.cfg.dynFreqMode = val;
ftMotion.cfg.dynFreqMode = val;
flag.report_h = true;
break;
#endif
Expand All @@ -243,8 +243,8 @@ void GcodeSuite::M493() {
}

const bool modeUsesDynFreq = (
TERN0(HAS_DYNAMIC_FREQ_MM, fxdTiCtrl.cfg.dynFreqMode == dynFreqMode_Z_BASED)
|| TERN0(HAS_DYNAMIC_FREQ_G, fxdTiCtrl.cfg.dynFreqMode == dynFreqMode_MASS_BASED)
TERN0(HAS_DYNAMIC_FREQ_MM, ftMotion.cfg.dynFreqMode == dynFreqMode_Z_BASED)
|| TERN0(HAS_DYNAMIC_FREQ_G, ftMotion.cfg.dynFreqMode == dynFreqMode_MASS_BASED)
);

#endif // HAS_DYNAMIC_FREQ
Expand All @@ -253,11 +253,11 @@ void GcodeSuite::M493() {

// Parse frequency parameter (X axis).
if (parser.seenval('A')) {
if (fxdTiCtrl.cfg.modeHasShaper()) {
if (ftMotion.cfg.modeHasShaper()) {
const float val = parser.value_float();
// 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;
ftMotion.cfg.baseFreq[X_AXIS] = val;
flag.update_n = flag.reset_ft = flag.report_h = true;
}
else // Frequency out of range.
Expand All @@ -271,7 +271,7 @@ void GcodeSuite::M493() {
// Parse frequency scaling parameter (X axis).
if (parser.seenval('F')) {
if (modeUsesDynFreq) {
fxdTiCtrl.cfg.dynFreqK[X_AXIS] = parser.value_float();
ftMotion.cfg.dynFreqK[X_AXIS] = parser.value_float();
flag.report_h = true;
}
else
Expand All @@ -285,10 +285,10 @@ void GcodeSuite::M493() {

// Parse frequency parameter (Y axis).
if (parser.seenval('B')) {
if (fxdTiCtrl.cfg.modeHasShaper()) {
if (ftMotion.cfg.modeHasShaper()) {
const float val = parser.value_float();
if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) {
fxdTiCtrl.cfg.baseFreq[Y_AXIS] = val;
ftMotion.cfg.baseFreq[Y_AXIS] = val;
flag.update_n = flag.reset_ft = flag.report_h = true;
}
else // Frequency out of range.
Expand All @@ -302,7 +302,7 @@ void GcodeSuite::M493() {
// Parse frequency scaling parameter (Y axis).
if (parser.seenval('H')) {
if (modeUsesDynFreq) {
fxdTiCtrl.cfg.dynFreqK[Y_AXIS] = parser.value_float();
ftMotion.cfg.dynFreqK[Y_AXIS] = parser.value_float();
flag.report_h = true;
}
else
Expand All @@ -313,10 +313,10 @@ void GcodeSuite::M493() {
#endif // HAS_Y_AXIS

#if HAS_X_AXIS
if (flag.update_n) fxdTiCtrl.refreshShapingN();
if (flag.update_a) fxdTiCtrl.updateShapingA();
if (flag.update_n) ftMotion.refreshShapingN();
if (flag.update_a) ftMotion.updateShapingA();
#endif
if (flag.reset_ft) fxdTiCtrl.reset();
if (flag.reset_ft) ftMotion.reset();
if (flag.report_h) say_shaping();

}
Expand Down
24 changes: 12 additions & 12 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,13 @@ void menu_move() {
#include "../../gcode/gcode.h"

void ftm_menu_setShaping(const ftMotionMode_t s) {
fxdTiCtrl.cfg.mode = s;
fxdTiCtrl.refreshShapingN();
ftMotion.cfg.mode = s;
ftMotion.refreshShapingN();
ui.go_back();
}

inline void menu_ftm_mode() {
const ftMotionMode_t mode = fxdTiCtrl.cfg.mode;
const ftMotionMode_t mode = ftMotion.cfg.mode;

START_MENU();
BACK_ITEM(MSG_FIXED_TIME_MOTION);
Expand All @@ -349,17 +349,17 @@ void menu_move() {
#if HAS_DYNAMIC_FREQ

inline void menu_ftm_dyn_mode() {
const dynFreqMode_t dmode = fxdTiCtrl.cfg.dynFreqMode;
const dynFreqMode_t dmode = ftMotion.cfg.dynFreqMode;

START_MENU();
BACK_ITEM(MSG_FIXED_TIME_MOTION);

if (dmode != dynFreqMode_DISABLED) ACTION_ITEM(MSG_LCD_OFF, []{ fxdTiCtrl.cfg.dynFreqMode = dynFreqMode_DISABLED; ui.go_back(); });
if (dmode != dynFreqMode_DISABLED) ACTION_ITEM(MSG_LCD_OFF, []{ ftMotion.cfg.dynFreqMode = dynFreqMode_DISABLED; ui.go_back(); });
#if HAS_DYNAMIC_FREQ_MM
if (dmode != dynFreqMode_Z_BASED) ACTION_ITEM(MSG_FTM_Z_BASED, []{ fxdTiCtrl.cfg.dynFreqMode = dynFreqMode_Z_BASED; ui.go_back(); });
if (dmode != dynFreqMode_Z_BASED) ACTION_ITEM(MSG_FTM_Z_BASED, []{ ftMotion.cfg.dynFreqMode = dynFreqMode_Z_BASED; ui.go_back(); });
#endif
#if HAS_DYNAMIC_FREQ_G
if (dmode != dynFreqMode_MASS_BASED) ACTION_ITEM(MSG_FTM_MASS_BASED, []{ fxdTiCtrl.cfg.dynFreqMode = dynFreqMode_MASS_BASED; ui.go_back(); });
if (dmode != dynFreqMode_MASS_BASED) ACTION_ITEM(MSG_FTM_MASS_BASED, []{ ftMotion.cfg.dynFreqMode = dynFreqMode_MASS_BASED; ui.go_back(); });
#endif

END_MENU();
Expand All @@ -368,7 +368,7 @@ void menu_move() {
#endif // HAS_DYNAMIC_FREQ

void menu_ft_motion() {
ft_config_t &c = fxdTiCtrl.cfg;
ft_config_t &c = ftMotion.cfg;

FSTR_P ftmode;
switch (c.mode) {
Expand Down Expand Up @@ -403,16 +403,16 @@ void menu_move() {

if (c.modeHasShaper()) {
#if HAS_X_AXIS
EDIT_ITEM_FAST_N(float42_52, X_AXIS, MSG_FTM_BASE_FREQ_N, &c.baseFreq[X_AXIS], FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2, fxdTiCtrl.refreshShapingN);
EDIT_ITEM_FAST_N(float42_52, X_AXIS, MSG_FTM_BASE_FREQ_N, &c.baseFreq[X_AXIS], FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2, ftMotion.refreshShapingN);
#endif
#if HAS_Y_AXIS
EDIT_ITEM_FAST_N(float42_52, Y_AXIS, MSG_FTM_BASE_FREQ_N, &c.baseFreq[Y_AXIS], FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2, fxdTiCtrl.refreshShapingN);
EDIT_ITEM_FAST_N(float42_52, Y_AXIS, MSG_FTM_BASE_FREQ_N, &c.baseFreq[Y_AXIS], FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2, ftMotion.refreshShapingN);
#endif

EDIT_ITEM_FAST(float42_52, MSG_FTM_ZETA, &c.zeta, 0.0f, 1.0f, fxdTiCtrl.refreshShapingN);
EDIT_ITEM_FAST(float42_52, MSG_FTM_ZETA, &c.zeta, 0.0f, 1.0f, ftMotion.refreshShapingN);

if (WITHIN(c.mode, ftMotionMode_EI, ftMotionMode_3HEI))
EDIT_ITEM_FAST(float42_52, MSG_FTM_VTOL, &c.vtol, 0.0f, 1.0f, fxdTiCtrl.refreshShapingN);
EDIT_ITEM_FAST(float42_52, MSG_FTM_VTOL, &c.vtol, 0.0f, 1.0f, ftMotion.refreshShapingN);

#if HAS_DYNAMIC_FREQ
SUBMENU(MSG_FTM_DYN_MODE, menu_ftm_dyn_mode);
Expand Down
Loading

0 comments on commit e7e77d9

Please sign in to comment.