From 7dc32cfd8f645fec6e5e6787bc308b37115fb64c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 12 Aug 2024 17:15:17 -0500 Subject: [PATCH] Bring up to date, clean up --- Marlin/src/gcode/feature/ft_motion/M493.cpp | 24 +++++++++------------ Marlin/src/gcode/feature/ft_motion/M494.cpp | 10 +++++++-- 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, 42 insertions(+), 38 deletions(-) diff --git a/Marlin/src/gcode/feature/ft_motion/M493.cpp b/Marlin/src/gcode/feature/ft_motion/M493.cpp index db0ee75a0af46..e66b7c6e08f86 100644 --- a/Marlin/src/gcode/feature/ft_motion/M493.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M493.cpp @@ -55,23 +55,19 @@ void say_shaper_type(const AxisEnum a) { #define AXIS_1_NAME "Y" #endif -#define CMPNSTR_IS_SHAPER(A) WITHIN(ftMotion.cfg.cmpnstr[A], ftMotionCmpnstr_ZV, ftMotionCmpnstr_MZV) -#define CMPNSTR_IS_EISHAPER(A) WITHIN(ftMotion.cfg.cmpnstr[A], ftMotionCmpnstr_EI, ftMotionCmpnstr_3HEI) - - void say_shaping() { // FT Enabled SERIAL_ECHO_TERNARY(ftMotion.cfg.active, "Fixed-Time Motion ", "en", "dis", "abled"); // FT Shaping #if HAS_X_AXIS - if (CMPNSTR_HAS_SHAPER(X_AXIS)) { + if (AXIS_HAS_SHAPER(X_AXIS)) { 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_AXIS)) { SERIAL_ECHOPGM(" and with " AXIS_1_NAME); say_shaper_type(Y_AXIS); } @@ -84,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) || AXIS_HAS_SHAPER(Y_AXIS)) { #if HAS_DYNAMIC_FREQ SERIAL_ECHOPGM("Dynamic Frequency Mode "); switch (ftMotion.cfg.dynFreqMode) { @@ -274,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) || AXIS_HAS_SHAPER(Y_AXIS)) { const dynFreqMode_t val = dynFreqMode_t(parser.value_byte()); switch (val) { #if HAS_DYNAMIC_FREQ_MM @@ -308,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_AXIS)) { 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)) { @@ -337,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_AXIS)) { if (WITHIN(val, 0.01f, 1.0f)) { ftMotion.cfg.zeta[0] = val; flag.update = true; @@ -352,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_AXIS)) { if (WITHIN(val, 0.00f, 1.0f)) { ftMotion.cfg.vtol[0] = val; flag.update = true; @@ -370,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_AXIS)) { const float val = parser.value_float(); if (WITHIN(val, FTM_MIN_SHAPE_FREQ, (FTM_FS) / 2)) { ftMotion.cfg.baseFreq[Y_AXIS] = val; @@ -398,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_AXIS)) { if (WITHIN(val, 0.01f, 1.0f)) { ftMotion.cfg.zeta[1] = val; flag.update = true; @@ -413,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_AXIS)) { if (WITHIN(val, 0.00f, 1.0f)) { ftMotion.cfg.vtol[1] = val; flag.update = true; diff --git a/Marlin/src/gcode/feature/ft_motion/M494.cpp b/Marlin/src/gcode/feature/ft_motion/M494.cpp index aa083173fdb43..83d14adc47c1e 100644 --- a/Marlin/src/gcode/feature/ft_motion/M494.cpp +++ b/Marlin/src/gcode/feature/ft_motion/M494.cpp @@ -74,9 +74,15 @@ void say_ftm_cfg() { */ void GcodeSuite::M494() { - if (!parser.seen_any()) { say_ftm_cfg(); return; } + if (!parser.seen_any()) { + say_ftm_cfg(); + return; + } - if (!ftMotion.cfg.mode) { SERIAL_ECHOLN("M494 echo: rejected! FTM is not enabled."); return; } + if (!ftMotion.cfg.active) { + SERIAL_ECHOLN("M494 echo: rejected! FTM is not enabled."); + return; + } ftMotionTrajGenMode_t mode_val_seen = trajGenMode_NONE; bool good_cfg_received = true; diff --git a/Marlin/src/lcd/menu/menu_motion.cpp b/Marlin/src/lcd/menu/menu_motion.cpp index 08676ce50e5e5..e90b9d337d3dd 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_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, 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_AXIS)) 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_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, 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_AXIS)) 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 9861cbc1f6ffa..846aa868620f1 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 6521df5c2131a..55084988e1e99 100644 --- a/Marlin/src/module/ft_motion.cpp +++ b/Marlin/src/module/ft_motion.cpp @@ -352,14 +352,14 @@ void FTMotion::loop() { void FTMotion::update_shaping_params() { #if HAS_X_AXIS - shaping.x.ena = CMPNSTR_HAS_SHAPER(X_AXIS); + shaping.x.ena = AXIS_HAS_SHAPER(X_AXIS); if (shaping.x.ena) { 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); + shaping.y.ena = AXIS_HAS_SHAPER(Y_AXIS); if (shaping.y.ena) { 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]); @@ -766,7 +766,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; @@ -827,7 +827,7 @@ void FTMotion::convertToSteps(const uint32_t idx) { // Set up step/dir bits for all axes LOGICAL_AXIS_CODE( - command_set[E_AXIS_N(current_block->extruder)](err_P.e, steps.e, stepperCmdBuff[stepperCmdBuff_produceIdx], _BV(FT_BIT_DIR_E), _BV(FT_BIT_STEP_E)), + command_set[E_AXIS](err_P.e, steps.e, stepperCmdBuff[stepperCmdBuff_produceIdx], _BV(FT_BIT_DIR_E), _BV(FT_BIT_STEP_E)), command_set[X_AXIS](err_P.x, steps.x, stepperCmdBuff[stepperCmdBuff_produceIdx], _BV(FT_BIT_DIR_X), _BV(FT_BIT_STEP_X)), command_set[Y_AXIS](err_P.y, steps.y, stepperCmdBuff[stepperCmdBuff_produceIdx], _BV(FT_BIT_DIR_Y), _BV(FT_BIT_STEP_Y)), command_set[Z_AXIS](err_P.z, steps.z, stepperCmdBuff[stepperCmdBuff_produceIdx], _BV(FT_BIT_DIR_Z), _BV(FT_BIT_STEP_Z)), diff --git a/Marlin/src/module/ft_motion.h b/Marlin/src/module/ft_motion.h index 7695ad0189ef7..3a632121a0d09 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 (1 + ENABLED(HAS_Y_AXIS)) + 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 810649b9888f5..14f85a2cdb9a5 100644 --- a/Marlin/src/module/ft_types.h +++ b/Marlin/src/module/ft_types.h @@ -71,8 +71,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[A] != ftMotionShaper_NONE) +#define AXIS_HAS_EISHAPER(A) WITHIN(ftMotion.cfg.shaper[A], ftMotionShaper_EI, ftMotionShaper_3HEI) typedef struct XYZEarray xyze_trajectory_t; typedef struct XYZEarray xyze_trajectoryMod_t;