Skip to content

Commit 2f522ab

Browse files
narno2202Andy-Big
authored andcommitted
🐛 Fix FT Motion runout in progress (MarlinFirmware#26020)
1 parent 930e2db commit 2f522ab

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

Marlin/Configuration_adv.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@
11271127
* Advanced configuration
11281128
*/
11291129
#define FTM_BATCH_SIZE 100 // Batch size for trajectory generation;
1130-
// half the window size for Ulendo FBS.
1130+
#define FTM_WINDOW_SIZE 200 // Window size for trajectory generation.
11311131
#define FTM_FS 1000 // (Hz) Frequency for trajectory generation. (1 / FTM_TS)
11321132
#define FTM_TS 0.001f // (s) Time step for trajectory generation. (1 / FTM_FS)
11331133
#define FTM_STEPPER_FS 20000 // (Hz) Frequency for stepper I/O update.

Marlin/src/module/ft_motion.cpp

+33-6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ bool FxdTiCtrl::batchRdy = false; // Indicates a batch of the fi
7575
bool FxdTiCtrl::batchRdyForInterp = false; // Indicates the batch is done being post processed,
7676
// if applicable, and is ready to be converted to step commands.
7777
bool FxdTiCtrl::runoutEna = false; // True if runout of the block hasn't been done and is allowed.
78+
bool FxdTiCtrl::runout = false; // Indicates if runout is in progress.
7879

7980
// Trapezoid data variables.
8081
xyze_pos_t FxdTiCtrl::startPosn, // (mm) Start position of block
@@ -123,6 +124,8 @@ hal_timer_t FxdTiCtrl::nextStepTicks = FTM_MIN_TICKS; // Accumulator for the nex
123124
float FxdTiCtrl::e_advanced_z1 = 0.0f; // (ms) Unit delay of advanced extruder position.
124125
#endif
125126

127+
constexpr uint32_t last_batchIdx = (FTM_WINDOW_SIZE) - (FTM_BATCH_SIZE);
128+
126129
//-----------------------------------------------------------------//
127130
// Function definitions.
128131
//-----------------------------------------------------------------//
@@ -143,8 +146,8 @@ void FxdTiCtrl::runoutBlock() {
143146
if (runoutEna && !batchRdy) { // If the window is full already (block intervals was a multiple of
144147
// the batch size), or runout is not enabled, no runout is needed.
145148
// Fill out the trajectory window with the last position calculated.
146-
if (makeVector_batchIdx > FTM_BATCH_SIZE)
147-
for (uint32_t i = makeVector_batchIdx; i < 2 * (FTM_BATCH_SIZE); i++) {
149+
if (makeVector_batchIdx > last_batchIdx)
150+
for (uint32_t i = makeVector_batchIdx; i < (FTM_WINDOW_SIZE); i++) {
148151
LOGICAL_AXIS_CODE(
149152
traj.e[i] = traj.e[makeVector_batchIdx - 1],
150153
traj.x[i] = traj.x[makeVector_batchIdx - 1],
@@ -159,8 +162,9 @@ void FxdTiCtrl::runoutBlock() {
159162
);
160163
}
161164

162-
makeVector_batchIdx = FTM_BATCH_SIZE;
165+
makeVector_batchIdx = last_batchIdx;
163166
batchRdy = true;
167+
runout = true;
164168
}
165169
runoutEna = false;
166170
}
@@ -184,14 +188,35 @@ void FxdTiCtrl::loop() {
184188
}
185189

186190
// Planner processing and block conversion.
187-
if (!blockProcRdy) stepper.fxdTiCtrl_BlockQueueUpdate();
191+
if (!blockProcRdy && !runout) stepper.fxdTiCtrl_BlockQueueUpdate();
188192

189193
if (blockProcRdy) {
190194
if (!blockProcRdy_z1) loadBlockData(current_block_cpy); // One-shot.
191195
while (!blockProcDn && !batchRdy && (makeVector_idx - makeVector_idx_z1 < (FTM_POINTS_PER_LOOP)))
192196
makeVector();
193197
}
194198

199+
if (runout && !batchRdy) { // The lower half of the window has been runout.
200+
// Runout the upper half of the window: the upper half has been shifted into the lower
201+
// half. Fill out the upper half so another batch can be processed.
202+
for (uint32_t i = last_batchIdx; i < (FTM_WINDOW_SIZE) - 1; i++) {
203+
LOGICAL_AXIS_CODE(
204+
traj.e[i] = traj.e[(FTM_WINDOW_SIZE) - 1],
205+
traj.x[i] = traj.x[(FTM_WINDOW_SIZE) - 1],
206+
traj.y[i] = traj.y[(FTM_WINDOW_SIZE) - 1],
207+
traj.z[i] = traj.z[(FTM_WINDOW_SIZE) - 1],
208+
traj.i[i] = traj.i[(FTM_WINDOW_SIZE) - 1],
209+
traj.j[i] = traj.j[(FTM_WINDOW_SIZE) - 1],
210+
traj.k[i] = traj.k[(FTM_WINDOW_SIZE) - 1],
211+
traj.u[i] = traj.u[(FTM_WINDOW_SIZE) - 1],
212+
traj.v[i] = traj.v[(FTM_WINDOW_SIZE) - 1],
213+
traj.w[i] = traj.w[(FTM_WINDOW_SIZE) - 1]
214+
);
215+
}
216+
batchRdy = true;
217+
runout = false;
218+
}
219+
195220
// FBS / post processing.
196221
if (batchRdy && !batchRdyForInterp) {
197222

@@ -371,10 +396,12 @@ void FxdTiCtrl::reset() {
371396
stepperCmdBuff_produceIdx = stepperCmdBuff_consumeIdx = 0;
372397

373398
traj.reset(); // Reset trajectory history
399+
trajMod.reset(); // Reset modified trajectory history
374400

375401
blockProcRdy = blockProcRdy_z1 = blockProcDn = false;
376402
batchRdy = batchRdyForInterp = false;
377403
runoutEna = false;
404+
runout = false;
378405

379406
endPosn_prevBlock.reset();
380407

@@ -611,8 +638,8 @@ void FxdTiCtrl::makeVector() {
611638
#endif
612639

613640
// Filled up the queue with regular and shaped steps
614-
if (++makeVector_batchIdx == 2 * (FTM_BATCH_SIZE)) {
615-
makeVector_batchIdx = FTM_BATCH_SIZE;
641+
if (++makeVector_batchIdx == (FTM_WINDOW_SIZE)) {
642+
makeVector_batchIdx = last_batchIdx;
616643
batchRdy = true;
617644
}
618645

Marlin/src/module/ft_motion.h

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class FxdTiCtrl {
133133
static bool blockProcRdy, blockProcRdy_z1, blockProcDn;
134134
static bool batchRdy, batchRdyForInterp;
135135
static bool runoutEna;
136+
static bool runout;
136137

137138
// Trapezoid data variables.
138139
static xyze_pos_t startPosn, // (mm) Start position of block

Marlin/src/module/ft_types.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum stepDirState_t : uint8_t {
4848
stepDirState_NEG = 2U
4949
};
5050

51-
typedef struct XYZEarray<float, 2 * (FTM_BATCH_SIZE)> xyze_trajectory_t;
51+
typedef struct XYZEarray<float, FTM_WINDOW_SIZE> xyze_trajectory_t;
5252
typedef struct XYZEarray<float, FTM_BATCH_SIZE> xyze_trajectoryMod_t;
5353

5454
typedef struct XYZEval<stepDirState_t> xyze_stepDir_t;

0 commit comments

Comments
 (0)