Skip to content

Commit

Permalink
🎨 FT Motion, axis cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Aug 12, 2024
1 parent 89b0143 commit b062a3b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 38 deletions.
6 changes: 3 additions & 3 deletions Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
27 changes: 15 additions & 12 deletions Marlin/src/gcode/feature/ft_motion/M493.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
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)) {
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
#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)) {
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
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: 3 additions & 5 deletions Marlin/src/module/ft_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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;
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 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
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 @@ -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<float, FTM_WINDOW_SIZE> xyze_trajectory_t;
typedef struct XYZEarray<float, FTM_BATCH_SIZE> xyze_trajectoryMod_t;
Expand Down

0 comments on commit b062a3b

Please sign in to comment.