Skip to content

Commit

Permalink
Bring up to date, clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 12, 2024
1 parent f2c46a5 commit 7dc32cf
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 38 deletions.
24 changes: 10 additions & 14 deletions Marlin/src/gcode/feature/ft_motion/M493.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions Marlin/src/gcode/feature/ft_motion/M494.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/lcd/menu/menu_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -441,21 +441,21 @@ 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
#if HAS_Y_AXIS
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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/tft/ui_color_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/module/ft_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)),
Expand Down
12 changes: 7 additions & 5 deletions Marlin/src/module/ft_motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/module/ft_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, FTM_WINDOW_SIZE> xyze_trajectory_t;
typedef struct XYZEarray<float, FTM_BATCH_SIZE> xyze_trajectoryMod_t;
Expand Down

0 comments on commit 7dc32cf

Please sign in to comment.