From b062a3b2260e62570b83692298cfb1bb7c80bdaf Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 12 Aug 2024 17:28:55 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20FT=20Motion,=20axis=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/core/types.h | 6 ++--- Marlin/src/gcode/feature/ft_motion/M493.cpp | 27 ++++++++++++--------- Marlin/src/lcd/menu/menu_motion.cpp | 16 ++++++------ Marlin/src/lcd/tft/ui_color_ui.cpp | 6 ++--- Marlin/src/module/ft_motion.cpp | 8 +++--- Marlin/src/module/ft_motion.h | 12 +++++---- Marlin/src/module/ft_types.h | 4 +-- 7 files changed, 41 insertions(+), 38 deletions(-) diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index 4bc50b56c70b..6fcff84ee135 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -297,7 +297,7 @@ enum AxisEnum : uint8_t { #endif // Distinct axes, including all E and Core - NUM_AXIS_ENUMS, + NUM_AXIS_HEADS, // Most of the time we refer only to the single E_AXIS #if HAS_EXTRUDERS @@ -995,7 +995,7 @@ class AxisBits; class AxisBits { public: - typedef bits_t(NUM_AXIS_ENUMS) el; + typedef bits_t(NUM_AXIS_HEADS) el; union { el bits; // Axes x, y, z ... e0, e1, e2 ... hx, hy, hz @@ -1056,7 +1056,7 @@ class AxisBits { FI AxisBits& operator=(const el p) { set(p); return *this; } FI void reset() { set(0); } - FI void fill() { set(_BV(NUM_AXIS_ENUMS) - 1); } + FI void fill() { set(_BV(NUM_AXIS_HEADS) - 1); } #define MSET(pE,pX,pY,pZ,pI,pJ,pK,pU,pV,pW) LOGICAL_AXIS_CODE(e=pE, x=pX, y=pY, z=pZ, i=pI, j=pJ, k=pK, u=pU, v=pV, w=pW) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index 993b4b203572..a9dab22852f1 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -61,13 +61,13 @@ void say_shaping() { // FT Shaping #if HAS_X_AXIS - if (CMPNSTR_HAS_SHAPER(X_AXIS)) { + if (AXIS_HAS_SHAPER(X)) { SERIAL_ECHOPGM(" with " AXIS_0_NAME); say_shaper_type(X_AXIS); } #endif #if HAS_Y_AXIS - if (CMPNSTR_HAS_SHAPER(Y_AXIS)) { + if (AXIS_HAS_SHAPER(Y)) { SERIAL_ECHOPGM(" and with " AXIS_1_NAME); say_shaper_type(Y_AXIS); } @@ -80,7 +80,7 @@ void say_shaping() { dynamic = z_based || g_based; // FT Dynamic Frequency Mode - if (CMPNSTR_HAS_SHAPER(X_AXIS) || CMPNSTR_HAS_SHAPER(Y_AXIS)) { + if (AXIS_HAS_SHAPER(X) || AXIS_HAS_SHAPER(Y)) { #if HAS_DYNAMIC_FREQ SERIAL_ECHOPGM("Dynamic Frequency Mode "); switch (ftMotion.cfg.dynFreqMode) { @@ -201,8 +201,11 @@ void GcodeSuite::M493() { if (active != ftMotion.cfg.active) { switch (active) { - case false: flag.reset_ft = true; - case true: flag.report_h = true; + case false: + flag.reset_ft = true; + // fall-thru + case true: + flag.report_h = true; ftMotion.cfg.active = active; break; } @@ -267,7 +270,7 @@ void GcodeSuite::M493() { // Dynamic frequency mode parameter. if (parser.seenval('D')) { - if (CMPNSTR_HAS_SHAPER(X_AXIS) || CMPNSTR_HAS_SHAPER(Y_AXIS)) { + if (AXIS_HAS_SHAPER(X) || AXIS_HAS_SHAPER(Y)) { const dynFreqMode_t val = dynFreqMode_t(parser.value_byte()); switch (val) { #if HAS_DYNAMIC_FREQ_MM @@ -301,7 +304,7 @@ void GcodeSuite::M493() { // Parse frequency parameter (X axis). if (parser.seenval('A')) { - if (CMPNSTR_HAS_SHAPER(X_AXIS)) { + if (AXIS_HAS_SHAPER(X)) { 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)) { @@ -330,7 +333,7 @@ void GcodeSuite::M493() { // Parse zeta parameter (X axis). if (parser.seenval('I')) { const float val = parser.value_float(); - if (CMPNSTR_HAS_SHAPER(X_AXIS)) { + if (AXIS_HAS_SHAPER(X)) { if (WITHIN(val, 0.01f, 1.0f)) { ftMotion.cfg.zeta[0] = val; flag.update = true; @@ -345,7 +348,7 @@ void GcodeSuite::M493() { // Parse vtol parameter (X axis). if (parser.seenval('Q')) { const float val = parser.value_float(); - if (CMPNSTR_IS_EISHAPER(X_AXIS)) { + if (AXIS_HAS_EISHAPER(X)) { if (WITHIN(val, 0.00f, 1.0f)) { ftMotion.cfg.vtol[0] = val; flag.update = true; @@ -363,7 +366,7 @@ void GcodeSuite::M493() { // Parse frequency parameter (Y axis). if (parser.seenval('B')) { - if (CMPNSTR_HAS_SHAPER(Y_AXIS)) { + if (AXIS_HAS_SHAPER(Y)) { const float val = parser.value_float(); if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) { ftMotion.cfg.baseFreq[Y_AXIS] = val; @@ -391,7 +394,7 @@ void GcodeSuite::M493() { // Parse zeta parameter (Y axis). if (parser.seenval('J')) { const float val = parser.value_float(); - if (CMPNSTR_HAS_SHAPER(Y_AXIS)) { + if (AXIS_HAS_SHAPER(Y)) { if (WITHIN(val, 0.01f, 1.0f)) { ftMotion.cfg.zeta[1] = val; flag.update = true; @@ -406,7 +409,7 @@ void GcodeSuite::M493() { // Parse vtol parameter (Y axis). if (parser.seenval('R')) { const float val = parser.value_float(); - if (CMPNSTR_IS_EISHAPER(Y_AXIS)) { + if (AXIS_HAS_EISHAPER(Y)) { if (WITHIN(val, 0.00f, 1.0f)) { ftMotion.cfg.vtol[1] = val; flag.update = true; diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 08676ce50e5e..5ec2948129f6 100644 --- a/Marlin/src/lcd/menu/menu_motion.cpp +++ b/Marlin/src/lcd/menu/menu_motion.cpp @@ -416,9 +416,9 @@ void menu_move() { void menu_ft_motion() { // Define stuff ahead of the menu loop - MString<20> shaper_name[1 + ENABLED(HAS_Y_AXIS)] {}; + MString<20> shaper_name[NUM_AXES_SHAPED] {}; #if HAS_X_AXIS - for (uint_fast8_t a = X_AXIS; a <= TERN(HAS_Y_AXIS, Y_AXIS, X_AXIS); ++a) + for (uint_fast8_t a = X_AXIS; a < NUM_AXES_SHAPED; ++a) shaper_name[a] = get_shaper_name(AxisEnum(a)); #endif #if HAS_DYNAMIC_FREQ @@ -441,10 +441,10 @@ void menu_move() { SUBMENU_N(X_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_cmpn_x); MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[X_AXIS]); MENU_ITEM_ADDON_END(); - if (CMPNSTR_HAS_SHAPER(X_AXIS)) { + if (AXIS_HAS_SHAPER(X)) { 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.update_shaping_params); EDIT_ITEM_FAST_N(float42_52, X_AXIS, MSG_FTM_ZETA_N, &c.zeta[0], 0.0f, 1.0f, ftMotion.update_shaping_params); - if (CMPNSTR_IS_EISHAPER(X_AXIS)) + if (AXIS_HAS_EISHAPER(X)) EDIT_ITEM_FAST_N(float42_52, X_AXIS, MSG_FTM_VTOL_N, &c.vtol[0], 0.0f, 1.0f, ftMotion.update_shaping_params); } #endif @@ -452,10 +452,10 @@ void menu_move() { SUBMENU_N(Y_AXIS, MSG_FTM_CMPN_MODE, menu_ftm_cmpn_y); MENU_ITEM_ADDON_START_RJ(5); lcd_put_u8str(shaper_name[Y_AXIS]); MENU_ITEM_ADDON_END(); - if (CMPNSTR_HAS_SHAPER(Y_AXIS)) { + if (AXIS_HAS_SHAPER(Y)) { 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.update_shaping_params); EDIT_ITEM_FAST_N(float42_52, Y_AXIS, MSG_FTM_ZETA_N, &c.zeta[1], 0.0f, 1.0f, ftMotion.update_shaping_params); - if (CMPNSTR_IS_EISHAPER(Y_AXIS)) + if (AXIS_HAS_EISHAPER(Y)) EDIT_ITEM_FAST_N(float42_52, Y_AXIS, MSG_FTM_VTOL_N, &c.vtol[1], 0.0f, 1.0f, ftMotion.update_shaping_params); } #endif @@ -483,9 +483,9 @@ void menu_move() { void menu_tune_ft_motion() { // Define stuff ahead of the menu loop - MString<20> shaper_name[1 + ENABLED(HAS_Y_AXIS)] {}; + MString<20> shaper_name[NUM_AXES_SHAPED] {}; #if HAS_X_AXIS - for (uint_fast8_t a = X_AXIS; a <= TERN(HAS_Y_AXIS, Y_AXIS, X_AXIS); ++a) + for (uint_fast8_t a = X_AXIS; a < NUM_AXES_SHAPED; ++a) shaper_name[a] = get_shaper_name(AxisEnum(a)); #endif #if HAS_DYNAMIC_FREQ diff --git a/Marlin/src/lcd/tft/ui_color_ui.cpp b/Marlin/src/lcd/tft/ui_color_ui.cpp index 9861cbc1f6ff..846aa868620f 100644 --- a/Marlin/src/lcd/tft/ui_color_ui.cpp +++ b/Marlin/src/lcd/tft/ui_color_ui.cpp @@ -247,21 +247,21 @@ void MarlinUI::draw_status_screen() { tft.set_background(COLOR_BACKGROUND); tft.add_rectangle(0, 0, COORDINATES_W, COORDINATES_H, COLOR_AXIS_HOMED); - #if ENABLED(HAS_X_AXIS) && defined(X_MARK_X) && defined(X_MARK_Y) && defined(X_VALUE_X) && defined(X_VALUE_Y) + #if HAS_X_AXIS && defined(X_MARK_X) && defined(X_MARK_Y) && defined(X_VALUE_X) && defined(X_VALUE_Y) tft.add_text(X_MARK_X, X_MARK_Y, COLOR_AXIS_HOMED , "X"); const bool nhx = axis_should_home(X_AXIS); tft_string.set(blink && nhx ? "?" : ftostr4sign(LOGICAL_X_POSITION(current_position.x))); tft.add_text(X_VALUE_X, X_VALUE_Y, nhx ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string); #endif - #if ENABLED(HAS_Y_AXIS) && defined(Y_MARK_X) && defined(Y_MARK_Y) && defined(Y_VALUE_X) && defined(Y_VALUE_Y) + #if HAS_Y_AXIS && defined(Y_MARK_X) && defined(Y_MARK_Y) && defined(Y_VALUE_X) && defined(Y_VALUE_Y) tft.add_text(Y_MARK_X, Y_MARK_Y, COLOR_AXIS_HOMED , "Y"); const bool nhy = axis_should_home(Y_AXIS); tft_string.set(blink && nhy ? "?" : ftostr4sign(LOGICAL_Y_POSITION(current_position.y))); tft.add_text(Y_VALUE_X, Y_VALUE_Y, nhy ? COLOR_AXIS_NOT_HOMED : COLOR_AXIS_HOMED, tft_string); #endif - #if ENABLED(HAS_Z_AXIS) && defined(Z_MARK_X) && defined(Z_MARK_Y) && defined(Z_VALUE_X) && defined(Z_VALUE_Y) && defined(Z_VALUE_OFFSET) + #if HAS_Z_AXIS && defined(Z_MARK_X) && defined(Z_MARK_Y) && defined(Z_VALUE_X) && defined(Z_VALUE_Y) && defined(Z_VALUE_OFFSET) tft.add_text(Z_MARK_X, Z_MARK_Y, COLOR_AXIS_HOMED , "Z"); uint16_t offset = Z_VALUE_OFFSET; const bool nhz = axis_should_home(Z_AXIS); diff --git a/Marlin/src/module/ft_motion.cpp b/Marlin/src/module/ft_motion.cpp index b19cd8600a61..a3f308bc5f57 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -349,15 +349,13 @@ void FTMotion::loop() { void FTMotion::update_shaping_params() { #if HAS_X_AXIS - shaping.x.ena = CMPNSTR_HAS_SHAPER(X_AXIS); - if (shaping.x.ena) { + if ((shaping.x.ena = AXIS_HAS_SHAPER(X))) { shaping.x.set_axis_shaping_A(cfg.shaper[X_AXIS], cfg.zeta[X_AXIS], cfg.vtol[X_AXIS]); shaping.x.set_axis_shaping_N(cfg.shaper[X_AXIS], cfg.baseFreq[X_AXIS], cfg.zeta[X_AXIS]); } #endif #if HAS_Y_AXIS - shaping.y.ena = CMPNSTR_HAS_SHAPER(Y_AXIS); - if (shaping.y.ena) { + if ((shaping.y.ena = AXIS_HAS_SHAPER(Y))) { shaping.y.set_axis_shaping_A(cfg.shaper[Y_AXIS], cfg.zeta[Y_AXIS], cfg.vtol[Y_AXIS]); shaping.y.set_axis_shaping_N(cfg.shaper[Y_AXIS], cfg.baseFreq[Y_AXIS], cfg.zeta[Y_AXIS]); } @@ -664,7 +662,7 @@ void FTMotion::makeVector() { * - Tests for delta are moved outside the loop. * - Two functions are used for command computation with an array of function pointers. */ -static void (*command_set[SUM_TERN(HAS_EXTRUDERS, NUM_AXES, 1)])(int32_t&, int32_t&, ft_command_t&, int32_t, int32_t); +static void (*command_set[LOGICAL_AXES])(int32_t&, int32_t&, ft_command_t&, int32_t, int32_t); static void command_set_pos(int32_t &e, int32_t &s, ft_command_t &b, int32_t bd, int32_t bs) { if (e < FTM_CTS_COMPARE_VAL) return; diff --git a/Marlin/src/module/ft_motion.h b/Marlin/src/module/ft_motion.h index 4851a8cc7dbc..eb717a91db9b 100644 --- a/Marlin/src/module/ft_motion.h +++ b/Marlin/src/module/ft_motion.h @@ -36,23 +36,25 @@ #endif #endif +#define NUM_AXES_SHAPED TERN(HAS_Y_AXIS, 2, 1) + typedef struct FTConfig { bool active = ENABLED(FTM_IS_DEFAULT_MOTION); // Active (else standard motion) #if HAS_X_AXIS - ftMotionShaper_t shaper[1 + ENABLED(HAS_Y_AXIS)] = // Shaper type + ftMotionShaper_t shaper[NUM_AXES_SHAPED] = // Shaper type { FTM_DEFAULT_SHAPER_X OPTARG(HAS_Y_AXIS, FTM_DEFAULT_SHAPER_Y) }; - float baseFreq[1 + ENABLED(HAS_Y_AXIS)] = // Base frequency. [Hz] + float baseFreq[NUM_AXES_SHAPED] = // Base frequency. [Hz] { FTM_SHAPING_DEFAULT_X_FREQ OPTARG(HAS_Y_AXIS, FTM_SHAPING_DEFAULT_Y_FREQ) }; - float zeta[1 + ENABLED(HAS_Y_AXIS)] = // Damping factor + float zeta[NUM_AXES_SHAPED] = // Damping factor { FTM_SHAPING_ZETA_X OPTARG(HAS_Y_AXIS, FTM_SHAPING_ZETA_Y) }; - float vtol[1 + ENABLED(HAS_Y_AXIS)] = // Vibration Level + float vtol[NUM_AXES_SHAPED] = // Vibration Level { FTM_SHAPING_V_TOL_X OPTARG(HAS_Y_AXIS, FTM_SHAPING_V_TOL_Y) }; #endif #if HAS_DYNAMIC_FREQ dynFreqMode_t dynFreqMode = FTM_DEFAULT_DYNFREQ_MODE; // Dynamic frequency mode configuration. - float dynFreqK[1 + ENABLED(HAS_Y_AXIS)] = { 0.0f }; // Scaling / gain for dynamic frequency. [Hz/mm] or [Hz/g] + float dynFreqK[NUM_AXES_SHAPED] = { 0.0f }; // Scaling / gain for dynamic frequency. [Hz/mm] or [Hz/g] #else static constexpr dynFreqMode_t dynFreqMode = dynFreqMode_DISABLED; #endif diff --git a/Marlin/src/module/ft_types.h b/Marlin/src/module/ft_types.h index 51cd548a03f5..d43340b73b81 100644 --- a/Marlin/src/module/ft_types.h +++ b/Marlin/src/module/ft_types.h @@ -41,8 +41,8 @@ enum dynFreqMode_t : uint8_t { dynFreqMode_MASS_BASED = 2 }; -#define CMPNSTR_HAS_SHAPER(A) (ftMotion.cfg.shaper[A] != ftMotionShaper_NONE) -#define CMPNSTR_IS_EISHAPER(A) WITHIN(ftMotion.cfg.shaper[A], ftMotionShaper_EI, ftMotionShaper_3HEI) +#define AXIS_HAS_SHAPER(A) (ftMotion.cfg.shaper[_AXIS(A)] != ftMotionShaper_NONE) +#define AXIS_HAS_EISHAPER(A) WITHIN(ftMotion.cfg.shaper[_AXIS(A)], ftMotionShaper_EI, ftMotionShaper_3HEI) typedef struct XYZEarray xyze_trajectory_t; typedef struct XYZEarray xyze_trajectoryMod_t;