Skip to content

Commit e4aba1b

Browse files
committed
lambda, conditional
1 parent ee0c9ff commit e4aba1b

File tree

5 files changed

+47
-38
lines changed

5 files changed

+47
-38
lines changed

Marlin/Configuration_adv.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,27 +1241,26 @@
12411241
/**
12421242
* TMC2208 Direction-Flip Delay
12431243
*
1244-
* Some TMC2208 / TMC2208_STANDALONE setups may require a short delay after a DIR change
1245-
* to avoid the driver to turn off, especially when using stealthChop (which is the default
1246-
* for standalone configuration).
1244+
* Some TMC2208 / TMC2208_STANDALONE drivers may require a short delay after a DIR change
1245+
* to prevent a standstill error, especially when using stealthChop (the standalone default).
12471246
*
1248-
* When enabled for an axis, FT Motion will "pause" that axis for > 750µs after a detected
1249-
* direction flip by holding its trajectory coordinate constant for a multiple of FTM_TS
1250-
* frames. For the default FTM_FS = 1000, it is a single 1ms frame.
1251-
* Other axes keep moving normally, and the wait is cancelled if the axis flips again.
1247+
* When enabled for an axis, FT Motion will hold that axis for > 750µs after a DIR change
1248+
* by holding its trajectory coordinate constant for a multiple of FTM_TS frames. For the
1249+
* default FTM_FS = 1000, it is a single 1ms frame.
12521250
*
1251+
* Other axes keep moving normally, and the wait is canceled if the axis flips again.
12531252
*/
12541253
#if AXIS_DRIVER_TYPE_X(TMC2208) || AXIS_DRIVER_TYPE_X(TMC2208_STANDALONE)
1255-
//#define APPLY_TIMING_HACK_ON_X
1254+
//#define FTM_DIR_CHANGE_HOLD_X
12561255
#endif
12571256
#if AXIS_DRIVER_TYPE_Y(TMC2208) || AXIS_DRIVER_TYPE_Y(TMC2208_STANDALONE)
1258-
//#define APPLY_TIMING_HACK_ON_Y
1257+
//#define FTM_DIR_CHANGE_HOLD_Y
12591258
#endif
12601259
#if AXIS_DRIVER_TYPE_Z(TMC2208) || AXIS_DRIVER_TYPE_Z(TMC2208_STANDALONE)
1261-
//#define APPLY_TIMING_HACK_ON_Z
1260+
//#define FTM_DIR_CHANGE_HOLD_Z
12621261
#endif
12631262
#if AXIS_DRIVER_TYPE_E0(TMC2208) || AXIS_DRIVER_TYPE_E0(TMC2208_STANDALONE)
1264-
//#define APPLY_TIMING_HACK_ON_E
1263+
//#define FTM_DIR_CHANGE_HOLD_E
12651264
#endif
12661265

12671266
#endif // FT_MOTION

Marlin/src/inc/Conditionals-4-adv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@
359359
#if ANY(FTM_SHAPER_EI, FTM_SHAPER_2HEI, FTM_SHAPER_3HEI)
360360
#define HAS_FTM_EI_SHAPING 1
361361
#endif
362+
#if ANY(FTM_DIR_CHANGE_HOLD_X, FTM_DIR_CHANGE_HOLD_Y, FTM_DIR_CHANGE_HOLD_Z, FTM_DIR_CHANGE_HOLD_E)
363+
#define HAS_FTM_DIR_CHANGE_HOLD 1
364+
#endif
362365
#endif
363366

364367
// Standard Motion

Marlin/src/module/ft_motion.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ xyze_pos_t FTMotion::startPos, // (mm) Start position of bl
7575
xyze_float_t FTMotion::ratio; // (ratio) Axis move ratio of block
7676
float FTMotion::tau = 0.0f; // (s) Time since start of block
7777
bool FTMotion::fastForwardUntilMotion = false; // Fast forward time if there is no motion
78-
#if ANY(APPLY_TIMING_HACK_ON_X, APPLY_TIMING_HACK_ON_Y, APPLY_TIMING_HACK_ON_Z, APPLY_TIMING_HACK_ON_E)
78+
#if HAS_FTM_DIR_CHANGE_HOLD
7979
xyze_uint_t FTMotion::hold_frames; // Briefly hold motion after direction changes to fix TMC2208 bug
8080
AxisBits FTMotion::last_traj_dir; // Direction of the last trajectory point after shaping, smoothing, ...
8181
#endif
@@ -250,7 +250,7 @@ void FTMotion::reset() {
250250

251251
moving_axis_flags.reset();
252252
last_target_traj.reset();
253-
#if ANY(APPLY_TIMING_HACK_ON_X, APPLY_TIMING_HACK_ON_Y, APPLY_TIMING_HACK_ON_Z, APPLY_TIMING_HACK_ON_E)
253+
#if HAS_FTM_DIR_CHANGE_HOLD
254254
last_traj_dir.reset();
255255
hold_frames.reset();
256256
#endif
@@ -620,32 +620,38 @@ void FTMotion::fill_stepper_plan_buffer() {
620620
// It eliminates idle time when changing smoothing time or shapers and speeds up homing and bed leveling.
621621
}
622622
else {
623-
#if ANY(APPLY_TIMING_HACK_ON_X, APPLY_TIMING_HACK_ON_Y, APPLY_TIMING_HACK_ON_Z, APPLY_TIMING_HACK_ON_E)
623+
624+
#if HAS_FTM_DIR_CHANGE_HOLD
625+
624626
// When a flip is detected (and the axis is in stealthChop or is standalone),
625627
// hold that axis' trajectory coordinate constant for at least 750µs.
626628

627629
#define DIR_FLIP_HOLD_S 0.000'750f
628-
static constexpr uint32_t DIR_FLIP_HOLD_FRAMES = DIR_FLIP_HOLD_S / FTM_TS + 1;
629-
630-
#define START_HOLD_IF_DIR_FLIP(A) \
631-
if (ENABLED(APPLY_TIMING_HACK_ON_##A)) { \
632-
const bool direction = traj_coords.A > last_target_traj.A; \
633-
const bool moved = traj_coords.A != last_target_traj.A; \
634-
const bool flipped = moved && (direction != last_traj_dir.A); \
635-
const bool hold = !moved || (flipped && hold_frames.A > 0); \
636-
if (hold) { \
637-
if (hold_frames.A) hold_frames.A--; \
638-
traj_coords.A = last_target_traj.A; \
639-
} else { \
640-
last_traj_dir.A = direction; \
641-
hold_frames.A = DIR_FLIP_HOLD_FRAMES; \
642-
} \
630+
static constexpr uint32_t dir_flip_hold_frames = DIR_FLIP_HOLD_S / (FTM_TS + 1);
631+
632+
auto start_hold_if_dir_flip = [](const AxisEnum a) {
633+
const bool dir = traj_coords[a] > last_target_traj[a],
634+
moved = traj_coords[a] != last_target_traj[a],
635+
flipped = moved && (dir != last_traj_dir[a]),
636+
hold = !moved || (flipped && hold_frames[a] > 0);
637+
if (hold) {
638+
if (hold_frames[a]) hold_frames[a]--;
639+
traj_coords[a] = last_target_traj[a];
643640
}
641+
else {
642+
last_traj_dir[a] = dir;
643+
hold_frames[a] = dir_flip_hold_frames;
644+
}
645+
};
646+
647+
#define START_HOLD_IF_DIR_FLIP(A) TERN_(FTM_DIR_CHANGE_HOLD_##A, start_hold_if_dir_flip(_AXIS(A)));
648+
644649
LOGICAL_AXIS_MAP(START_HOLD_IF_DIR_FLIP);
645650

646-
#undef START_HOLD_IF_DIR_FLIP
647-
#endif
651+
#endif // HAS_FTM_DIR_CHANGE_HOLD
652+
648653
fastForwardUntilMotion = false;
654+
649655
// Calculate and store stepper plan in buffer
650656
stepping_enqueue(traj_coords);
651657
}

Marlin/src/module/ft_motion.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,12 +332,11 @@ class FTMotion {
332332
static float tau; // (s) Time since start of block
333333
static bool fastForwardUntilMotion; // Fast forward time if there is no motion
334334

335-
#if ANY(APPLY_TIMING_HACK_ON_X, APPLY_TIMING_HACK_ON_Y, APPLY_TIMING_HACK_ON_Z, APPLY_TIMING_HACK_ON_E)
335+
#if HAS_FTM_DIR_CHANGE_HOLD
336336
static xyze_uint_t hold_frames; // Briefly hold motion after direction changes to fix TMC2208 bug
337337
static AxisBits last_traj_dir; // Direction of the last trajectory point after shaping, smoothing, ...
338338
#endif
339339

340-
341340
// Trajectory generators
342341
static TrapezoidalTrajectoryGenerator trapezoidalGenerator;
343342
#if ENABLED(FTM_POLYS)

buildroot/tests/STM32F103RC_btt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ set -e
1111
#
1212
restore_configs
1313
opt_set MOTHERBOARD BOARD_BTT_SKR_MINI_E3_V1_0 SERIAL_PORT 1 SERIAL_PORT_2 -1 \
14-
X_DRIVER_TYPE TMC2209 Y_DRIVER_TYPE TMC2209 Z_DRIVER_TYPE TMC2209 E0_DRIVER_TYPE TMC2209 \
14+
X_DRIVER_TYPE TMC2208 Y_DRIVER_TYPE TMC2208 Z_DRIVER_TYPE TMC2208 E0_DRIVER_TYPE TMC2208 \
1515
X_CURRENT_HOME X_CURRENT/2 Y_CURRENT_HOME Y_CURRENT/2 Z_CURRENT_HOME Y_CURRENT/2
16-
opt_enable CR10_STOCKDISPLAY PINS_DEBUGGING Z_IDLE_HEIGHT EDITABLE_HOMING_CURRENT \
17-
INPUT_SHAPING_X INPUT_SHAPING_Y FT_MOTION FT_MOTION_MENU FTM_RESONANCE_TEST EMERGENCY_PARSER \
16+
opt_enable CR10_STOCKDISPLAY EMERGENCY_PARSER Z_IDLE_HEIGHT EDITABLE_HOMING_CURRENT \
17+
INPUT_SHAPING_X INPUT_SHAPING_Y \
18+
FT_MOTION FT_MOTION_MENU FTM_RESONANCE_TEST FTM_DIR_CHANGE_HOLD_X FTM_DIR_CHANGE_HOLD_Y \
1819
BIQU_MICROPROBE_V1 PROBE_ENABLE_DISABLE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR \
19-
ADAPTIVE_STEP_SMOOTHING LIN_ADVANCE SMOOTH_LIN_ADVANCE NONLINEAR_EXTRUSION
20+
ADAPTIVE_STEP_SMOOTHING LIN_ADVANCE SMOOTH_LIN_ADVANCE NONLINEAR_EXTRUSION \
21+
PINS_DEBUGGING
2022
opt_disable FTM_POLYS
21-
exec_test $1 $2 "BigTreeTech SKR Mini E3 1.0 - TMC2209 HW Serial, FT_MOTION w/out FTM_POLYS" "$3"
23+
exec_test $1 $2 "BigTreeTech SKR Mini E3 1.0 - TMC2208 HW Serial, FT_MOTION w/out FTM_POLYS" "$3"

0 commit comments

Comments
 (0)