Skip to content

Commit 4ddf626

Browse files
authored
🐛 FT Motion trajectory fixes (#28101)
1 parent 991fc9c commit 4ddf626

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Marlin/src/module/ft_motion.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ float FTMotion::tau = 0.0f; // (s) Time since start of b
7575
TrapezoidalTrajectoryGenerator FTMotion::trapezoidalGenerator;
7676
Poly5TrajectoryGenerator FTMotion::poly5Generator;
7777
Poly6TrajectoryGenerator FTMotion::poly6Generator;
78-
TrajectoryGenerator& FTMotion::currentGenerator = FTMotion::trapezoidalGenerator;
78+
TrajectoryGenerator* FTMotion::currentGenerator = &FTMotion::trapezoidalGenerator;
7979
TrajectoryType FTMotion::trajectoryType = TrajectoryType::FTM_TRAJECTORY_TYPE;
8080

8181
// Make vector variables.
@@ -496,7 +496,7 @@ void FTMotion::runoutBlock() {
496496
const float total_duration = max_intervals * FTM_TS + reminder_from_last_block;
497497

498498
// Plan a zero-motion trajectory for runout
499-
currentGenerator.planRunout(total_duration);
499+
currentGenerator->planRunout(total_duration);
500500

501501
blockProcRdy = true; // since ratio is 0, the trajectory positions won't advance in any axis
502502
}
@@ -511,7 +511,7 @@ int32_t FTMotion::stepperCmdBuffItems() {
511511
void FTMotion::init() {
512512
update_shaping_params();
513513
TERN_(FTM_SMOOTHING, update_smoothing_params());
514-
setTrajectoryType(TrajectoryType::FTM_TRAJECTORY_TYPE);
514+
setTrajectoryType(cfg.trajectory_type);
515515
reset(); // Precautionary.
516516
}
517517

@@ -520,11 +520,11 @@ void FTMotion::setTrajectoryType(const TrajectoryType type) {
520520
cfg.trajectory_type = trajectoryType = type;
521521
switch (type) {
522522
default: cfg.trajectory_type = trajectoryType = TrajectoryType::FTM_TRAJECTORY_TYPE;
523-
case TrajectoryType::TRAPEZOIDAL: currentGenerator = trapezoidalGenerator; break;
524-
case TrajectoryType::POLY5: currentGenerator = poly5Generator; break;
525-
case TrajectoryType::POLY6: currentGenerator = poly6Generator; break;
523+
case TrajectoryType::TRAPEZOIDAL: currentGenerator = &trapezoidalGenerator; break;
524+
case TrajectoryType::POLY5: currentGenerator = &poly5Generator; break;
525+
case TrajectoryType::POLY6: currentGenerator = &poly6Generator; break;
526526
}
527-
currentGenerator.reset(); // Reset the selected generator
527+
currentGenerator->reset(); // Reset the selected generator
528528
}
529529

530530
// Load / convert block data from planner to fixed-time control variables.
@@ -545,7 +545,7 @@ void FTMotion::loadBlockData(block_t * const current_block) {
545545
const float final_speed = mmps * current_block->final_rate; // (mm/s) End feedrate
546546

547547
// Plan the trajectory using the trajectory generator
548-
currentGenerator.plan(initial_speed, final_speed, current_block->acceleration, current_block->nominal_speed, totalLength);
548+
currentGenerator->plan(initial_speed, final_speed, current_block->acceleration, current_block->nominal_speed, totalLength);
549549

550550
// Accel + Coasting + Decel + datapoints
551551
const float reminder_from_last_block = - tau;
@@ -555,7 +555,7 @@ void FTMotion::loadBlockData(block_t * const current_block) {
555555
TERN_(FTM_HAS_LIN_ADVANCE, use_advance_lead = current_block->use_advance_lead);
556556

557557
// Watch endstops until the move ends
558-
const float total_duration = currentGenerator.getTotalDuration();
558+
const float total_duration = currentGenerator->getTotalDuration();
559559
uint32_t max_intervals = ceil((total_duration + reminder_from_last_block) * FTM_FS);
560560
const millis_t move_end_ti = millis() + SEC_TO_MS((FTM_TS) * float(max_intervals + num_samples_shaper_settle() + ((PROP_BATCHES) + 1) * (FTM_BATCH_SIZE)) + (float(FTM_STEPPERCMD_BUFF_SIZE) / float(FTM_STEPPER_FS)));
561561

@@ -572,7 +572,7 @@ void FTMotion::loadBlockData(block_t * const current_block) {
572572
// Generate data points of the trajectory.
573573
// Called from FTMotion::loop() at the fetch of a new planner block, after loadBlockData.
574574
void FTMotion::generateTrajectoryPointsFromBlock() {
575-
const float total_duration = currentGenerator.getTotalDuration();
575+
const float total_duration = currentGenerator->getTotalDuration();
576576
if (tau + FTM_TS > total_duration) {
577577
// TODO: refactor code so this thing is not twice.
578578
// the reason of it being in the beginning, is that a block can be so short that it has
@@ -589,7 +589,7 @@ void FTMotion::generateTrajectoryPointsFromBlock() {
589589
// tau can start negative, but it always holds that `tau > -FTM_TS`
590590

591591
// Get distance from trajectory generator
592-
const float dist = currentGenerator.getDistanceAtTime(tau);
592+
const float dist = currentGenerator->getDistanceAtTime(tau);
593593

594594
#define _SET_TRAJ(q) traj.q[traj_idx_set] = startPos.q + ratio.q * dist;
595595
LOGICAL_AXIS_MAP_LC(_SET_TRAJ);

Marlin/src/module/ft_motion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ typedef struct FTConfig {
7373
float linearAdvK = FTM_LINEAR_ADV_DEFAULT_K; // Linear advance gain.
7474
#endif
7575

76-
TrajectoryType trajectory_type = TrajectoryType::TRAPEZOIDAL; // Trajectory generator type
76+
TrajectoryType trajectory_type = TrajectoryType::FTM_TRAJECTORY_TYPE; // Trajectory generator type
7777
float poly6_acceleration_overshoot; // Overshoot factor for Poly6 (1.25 to 2.0)
7878
} ft_config_t;
7979

@@ -186,7 +186,7 @@ class FTMotion {
186186
static TrapezoidalTrajectoryGenerator trapezoidalGenerator;
187187
static Poly5TrajectoryGenerator poly5Generator;
188188
static Poly6TrajectoryGenerator poly6Generator;
189-
static TrajectoryGenerator& currentGenerator;
189+
static TrajectoryGenerator* currentGenerator;
190190
static TrajectoryType trajectoryType;
191191

192192
// Number of batches needed to propagate the current trajectory to the stepper.

0 commit comments

Comments
 (0)