Skip to content

Commit 6a871b2

Browse files
bmouritthinkyhead
andauthored
πŸ§‘β€πŸ’» Get E axis in FTMotion::loadBlockData (#27870)
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
1 parent bd9d7a3 commit 6a871b2

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

β€ŽMarlin/src/module/ft_motion.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ xyze_long_t FTMotion::steps = { 0 }; // Step count accumulator.
8989

9090
uint32_t FTMotion::interpIdx = 0; // Index of current data point being interpolated.
9191

92+
#if ENABLED(DISTINCT_E_FACTORS)
93+
uint8_t FTMotion::block_extruder_axis; // Cached E Axis from last-fetched block
94+
#else
95+
constexpr uint8_t FTMotion::block_extruder_axis;
96+
#endif
97+
9298
// Shaping variables.
9399
#if HAS_FTM_SHAPING
94100
FTMotion::shaping_t FTMotion::shaping = {
@@ -143,6 +149,12 @@ void FTMotion::loop() {
143149
continue;
144150
}
145151
loadBlockData(stepper.current_block);
152+
153+
// If the endstop is already pressed, endstop interrupts won't invoke
154+
// endstop_triggered and the move will grind. So check here for a
155+
// triggered endstop, which shortly marks the block for discard.
156+
endstops.update();
157+
146158
blockProcRdy = true;
147159
// Some kinematics track axis motion in HX, HY, HZ
148160
#if ANY(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY, MARKFORGED_YX)
@@ -389,6 +401,7 @@ void FTMotion::reset() {
389401
#endif
390402

391403
TERN_(HAS_EXTRUDERS, e_raw_z1 = e_advanced_z1 = 0.0f);
404+
TERN_(DISTINCT_E_FACTORS, block_extruder_axis = E_AXIS);
392405

393406
axis_move_end_ti.reset();
394407
}
@@ -453,13 +466,15 @@ void FTMotion::init() {
453466

454467
// Load / convert block data from planner to fixed-time control variables.
455468
void FTMotion::loadBlockData(block_t * const current_block) {
469+
// Cache the extruder index for this block
470+
TERN_(DISTINCT_E_FACTORS, block_extruder_axis = E_AXIS_N(current_block->extruder));
456471

457472
const float totalLength = current_block->millimeters,
458473
oneOverLength = 1.0f / totalLength;
459474

460475
startPosn = endPosn_prevBlock;
461476
const xyze_pos_t moveDist = LOGICAL_AXIS_ARRAY(
462-
current_block->steps.e * planner.mm_per_step[E_AXIS_N(current_block->extruder)] * (current_block->direction_bits.e ? 1 : -1),
477+
current_block->steps.e * planner.mm_per_step[block_extruder_axis] * (current_block->direction_bits.e ? 1 : -1),
463478
current_block->steps.x * planner.mm_per_step[X_AXIS] * (current_block->direction_bits.x ? 1 : -1),
464479
current_block->steps.y * planner.mm_per_step[Y_AXIS] * (current_block->direction_bits.y ? 1 : -1),
465480
current_block->steps.z * planner.mm_per_step[Z_AXIS] * (current_block->direction_bits.z ? 1 : -1),
@@ -568,12 +583,6 @@ void FTMotion::loadBlockData(block_t * const current_block) {
568583
#endif
569584
TERN_(HAS_Z_AXIS, _SET_MOVE_END(Z));
570585
SECONDARY_AXIS_MAP(_SET_MOVE_END);
571-
572-
// If the endstop is already pressed, endstop interrupts won't invoke
573-
// endstop_triggered and the move will grind. So check here for a
574-
// triggered endstop, which shortly marks the block for discard.
575-
endstops.update();
576-
577586
}
578587

579588
// Generate data points of the trajectory.
@@ -721,7 +730,7 @@ void FTMotion::convertToSteps(const uint32_t idx) {
721730
#if ENABLED(STEPS_ROUNDING)
722731
#define TOSTEPS(A,B) int32_t(trajMod.A[idx] * planner.settings.axis_steps_per_mm[B] + (trajMod.A[idx] < 0.0f ? -0.5f : 0.5f))
723732
const xyze_long_t steps_tar = LOGICAL_AXIS_ARRAY(
724-
TOSTEPS(e, E_AXIS_N(stepper.current_block->extruder)), // May be eliminated if guaranteed positive.
733+
TOSTEPS(e, block_extruder_axis), // May be eliminated if guaranteed positive.
725734
TOSTEPS(x, X_AXIS), TOSTEPS(y, Y_AXIS), TOSTEPS(z, Z_AXIS),
726735
TOSTEPS(i, I_AXIS), TOSTEPS(j, J_AXIS), TOSTEPS(k, K_AXIS),
727736
TOSTEPS(u, U_AXIS), TOSTEPS(v, V_AXIS), TOSTEPS(w, W_AXIS)
@@ -730,7 +739,7 @@ void FTMotion::convertToSteps(const uint32_t idx) {
730739
#else
731740
#define TOSTEPS(A,B) int32_t(trajMod.A[idx] * planner.settings.axis_steps_per_mm[B]) - steps.A
732741
xyze_long_t delta = LOGICAL_AXIS_ARRAY(
733-
TOSTEPS(e, E_AXIS_N(stepper.current_block->extruder)),
742+
TOSTEPS(e, block_extruder_axis),
734743
TOSTEPS(x, X_AXIS), TOSTEPS(y, Y_AXIS), TOSTEPS(z, Z_AXIS),
735744
TOSTEPS(i, I_AXIS), TOSTEPS(j, J_AXIS), TOSTEPS(k, K_AXIS),
736745
TOSTEPS(u, U_AXIS), TOSTEPS(v, V_AXIS), TOSTEPS(w, W_AXIS)

β€ŽMarlin/src/module/ft_motion.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ class FTMotion {
169169

170170
static xyze_long_t steps;
171171

172+
#if ENABLED(DISTINCT_E_FACTORS)
173+
static uint8_t block_extruder_axis; // Cached extruder axis index
174+
#else
175+
static constexpr uint8_t block_extruder_axis = E_AXIS;
176+
#endif
177+
172178
// Shaping variables.
173179
#if HAS_FTM_SHAPING
174180

0 commit comments

Comments
Β (0)