Skip to content

Commit dd8febc

Browse files
committed
Revert "Merge pull request MarlinFirmware#8611 from thinkyhead/bf2_planner_split_first"
This reverts commit 824980e, reversing changes made to aa7efb9.
1 parent fb44f8e commit dd8febc

File tree

2 files changed

+64
-111
lines changed

2 files changed

+64
-111
lines changed

Marlin/src/module/planner.cpp

Lines changed: 62 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -698,35 +698,69 @@ void Planner::calculate_volumetric_multipliers() {
698698
#endif // PLANNER_LEVELING
699699

700700
/**
701-
* Planner::_buffer_steps
701+
* Planner::_buffer_line
702702
*
703-
* Add a new linear movement to the buffer (in terms of steps).
703+
* Add a new linear movement to the buffer in axis units.
704704
*
705-
* target - target position in steps units
705+
* Leveling and kinematics should be applied ahead of calling this.
706+
*
707+
* a,b,c,e - target positions in mm and/or degrees
706708
* fr_mm_s - (target) speed of the move
707709
* extruder - target extruder
708710
*/
709-
void Planner::_buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uint8_t extruder) {
711+
void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder) {
712+
713+
// The target position of the tool in absolute steps
714+
// Calculate target position in absolute steps
715+
//this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
716+
const long target[XYZE] = {
717+
LROUND(a * axis_steps_per_mm[X_AXIS]),
718+
LROUND(b * axis_steps_per_mm[Y_AXIS]),
719+
LROUND(c * axis_steps_per_mm[Z_AXIS]),
720+
LROUND(e * axis_steps_per_mm[E_AXIS_N])
721+
};
722+
723+
// When changing extruders recalculate steps corresponding to the E position
724+
#if ENABLED(DISTINCT_E_FACTORS)
725+
if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
726+
position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
727+
last_extruder = extruder;
728+
}
729+
#endif
710730

711731
const int32_t da = target[X_AXIS] - position[X_AXIS],
712732
db = target[Y_AXIS] - position[Y_AXIS],
713733
dc = target[Z_AXIS] - position[Z_AXIS];
714734

715-
int32_t de = target[E_AXIS] - position[E_AXIS];
716-
717-
/* <-- add a slash to enable
718-
SERIAL_ECHOPAIR(" _buffer_steps FR:", fr_mm_s);
719-
SERIAL_ECHOPAIR(" A:", target[A_AXIS]);
735+
/*
736+
SERIAL_ECHOPAIR(" Planner FR:", fr_mm_s);
737+
SERIAL_CHAR(' ');
738+
#if IS_KINEMATIC
739+
SERIAL_ECHOPAIR("A:", a);
740+
SERIAL_ECHOPAIR(" (", da);
741+
SERIAL_ECHOPAIR(") B:", b);
742+
#else
743+
SERIAL_ECHOPAIR("X:", a);
720744
SERIAL_ECHOPAIR(" (", da);
721-
SERIAL_ECHOPAIR(" steps) B:", target[B_AXIS]);
722-
SERIAL_ECHOPAIR(" (", db);
723-
SERIAL_ECHOLNPGM(" steps) C:", target[C_AXIS]);
724-
SERIAL_ECHOPAIR(" (", dc);
725-
SERIAL_ECHOLNPGM(" steps) E:", target[E_AXIS]);
726-
SERIAL_ECHOPAIR(" (", de);
727-
SERIAL_ECHOLNPGM(" steps)");
745+
SERIAL_ECHOPAIR(") Y:", b);
746+
#endif
747+
SERIAL_ECHOPAIR(" (", db);
748+
#if ENABLED(DELTA)
749+
SERIAL_ECHOPAIR(") C:", c);
750+
#else
751+
SERIAL_ECHOPAIR(") Z:", c);
752+
#endif
753+
SERIAL_ECHOPAIR(" (", dc);
754+
SERIAL_CHAR(')');
755+
SERIAL_EOL();
728756
//*/
729757

758+
// DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
759+
if (DEBUGGING(DRYRUN))
760+
position[E_AXIS] = target[E_AXIS];
761+
762+
int32_t de = target[E_AXIS] - position[E_AXIS];
763+
730764
#if ENABLED(PREVENT_COLD_EXTRUSION) || ENABLED(PREVENT_LENGTHY_EXTRUDE)
731765
if (de) {
732766
#if ENABLED(PREVENT_COLD_EXTRUSION)
@@ -1033,7 +1067,6 @@ void Planner::_buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uin
10331067
// Segment time im micro seconds
10341068
uint32_t segment_time_us = LROUND(1000000.0 / inverse_secs);
10351069
#endif
1036-
10371070
#if ENABLED(SLOWDOWN)
10381071
if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
10391072
if (segment_time_us < min_segment_time_us) {
@@ -1227,12 +1260,12 @@ void Planner::_buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uin
12271260
vmax_junction = MINIMUM_PLANNER_SPEED; // Set default max junction speed
12281261

12291262
// Skip first block or when previous_nominal_speed is used as a flag for homing and offset cycles.
1230-
if (block_buffer_head != block_buffer_tail && previous_nominal_speed > 0.0) {
1263+
if (moves_queued() && !UNEAR_ZERO(previous_nominal_speed)) {
12311264
// Compute cosine of angle between previous and current path. (prev_unit_vec is negative)
12321265
// NOTE: Max junction velocity is computed without sin() or acos() by trig half angle identity.
1233-
float cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
1234-
- previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
1235-
- previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS] ;
1266+
const float cos_theta = - previous_unit_vec[X_AXIS] * unit_vec[X_AXIS]
1267+
- previous_unit_vec[Y_AXIS] * unit_vec[Y_AXIS]
1268+
- previous_unit_vec[Z_AXIS] * unit_vec[Z_AXIS];
12361269
// Skip and use default max junction speed for 0 degree acute junction.
12371270
if (cos_theta < 0.95) {
12381271
vmax_junction = min(previous_nominal_speed, block->nominal_speed);
@@ -1272,24 +1305,25 @@ void Planner::_buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uin
12721305
}
12731306
}
12741307

1275-
if (moves_queued && !UNEAR_ZERO(previous_nominal_speed)) {
1308+
if (moves_queued > 1 && !UNEAR_ZERO(previous_nominal_speed)) {
12761309
// Estimate a maximum velocity allowed at a joint of two successive segments.
12771310
// If this maximum velocity allowed is lower than the minimum of the entry / exit safe velocities,
12781311
// then the machine is not coasting anymore and the safe entry / exit velocities shall be used.
12791312

12801313
// The junction velocity will be shared between successive segments. Limit the junction velocity to their minimum.
1281-
const bool prev_speed_larger = previous_nominal_speed > block->nominal_speed;
1282-
const float smaller_speed_factor = prev_speed_larger ? (block->nominal_speed / previous_nominal_speed) : (previous_nominal_speed / block->nominal_speed);
12831314
// Pick the smaller of the nominal speeds. Higher speed shall not be achieved at the junction during coasting.
1284-
vmax_junction = prev_speed_larger ? block->nominal_speed : previous_nominal_speed;
1315+
vmax_junction = min(block->nominal_speed, previous_nominal_speed);
1316+
1317+
const float smaller_speed_factor = vmax_junction / previous_nominal_speed;
1318+
12851319
// Factor to multiply the previous / current nominal velocities to get componentwise limited velocities.
12861320
float v_factor = 1;
12871321
limited = 0;
12881322
// Now limit the jerk in all axes.
12891323
LOOP_XYZE(axis) {
12901324
// Limit an axis. We have to differentiate: coasting, reversal of an axis, full stop.
1291-
float v_exit = previous_speed[axis], v_entry = current_speed[axis];
1292-
if (prev_speed_larger) v_exit *= smaller_speed_factor;
1325+
float v_exit = previous_speed[axis] * smaller_speed_factor,
1326+
v_entry = current_speed[axis];
12931327
if (limited) {
12941328
v_exit *= v_factor;
12951329
v_entry *= v_factor;
@@ -1384,79 +1418,9 @@ void Planner::_buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uin
13841418

13851419
recalculate();
13861420

1387-
} // _buffer_steps()
1388-
1389-
/**
1390-
* Planner::_buffer_line
1391-
*
1392-
* Add a new linear movement to the buffer in axis units.
1393-
*
1394-
* Leveling and kinematics should be applied ahead of calling this.
1395-
*
1396-
* a,b,c,e - target positions in mm and/or degrees
1397-
* fr_mm_s - (target) speed of the move
1398-
* extruder - target extruder
1399-
*/
1400-
void Planner::_buffer_line(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder) {
1401-
// When changing extruders recalculate steps corresponding to the E position
1402-
#if ENABLED(DISTINCT_E_FACTORS)
1403-
if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
1404-
position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
1405-
last_extruder = extruder;
1406-
}
1407-
#endif
1408-
1409-
// The target position of the tool in absolute steps
1410-
// Calculate target position in absolute steps
1411-
const int32_t target[XYZE] = {
1412-
LROUND(a * axis_steps_per_mm[X_AXIS]),
1413-
LROUND(b * axis_steps_per_mm[Y_AXIS]),
1414-
LROUND(c * axis_steps_per_mm[Z_AXIS]),
1415-
LROUND(e * axis_steps_per_mm[E_AXIS_N])
1416-
};
1417-
1418-
/* <-- add a slash to enable
1419-
SERIAL_ECHOPAIR(" _buffer_line FR:", fr_mm_s);
1420-
#if IS_KINEMATIC
1421-
SERIAL_ECHOPAIR(" A:", a);
1422-
SERIAL_ECHOPAIR(" (", target[A_AXIS]);
1423-
SERIAL_ECHOPAIR(" steps) B:", b);
1424-
#else
1425-
SERIAL_ECHOPAIR(" X:", a);
1426-
SERIAL_ECHOPAIR(" (", target[X_AXIS]);
1427-
SERIAL_ECHOPAIR(" steps) Y:", b);
1428-
#endif
1429-
SERIAL_ECHOPAIR(" (", target[Y_AXIS]);
1430-
#if ENABLED(DELTA)
1431-
SERIAL_ECHOPAIR(" steps) C:", c);
1432-
#else
1433-
SERIAL_ECHOPAIR(" steps) Z:", c);
1434-
#endif
1435-
SERIAL_ECHOPAIR(" (", target[Z_AXIS]);
1436-
SERIAL_ECHOPAIR(" steps) E:", e);
1437-
SERIAL_ECHOPAIR(" (", target[E_AXIS]);
1438-
SERIAL_ECHOLNPGM(" steps)");
1439-
//*/
1440-
1441-
// DRYRUN ignores all temperature constraints and assures that the extruder is instantly satisfied
1442-
if (DEBUGGING(DRYRUN))
1443-
position[E_AXIS] = target[E_AXIS];
1444-
1445-
// Always split the first move in two so it can chain
1446-
if (!blocks_queued()) {
1447-
DISABLE_STEPPER_DRIVER_INTERRUPT();
1448-
#define _BETWEEN(A) (position[A##_AXIS] + target[A##_AXIS]) >> 1
1449-
const int32_t between[XYZE] = { _BETWEEN(X), _BETWEEN(Y), _BETWEEN(Z), _BETWEEN(E) };
1450-
_buffer_steps(between, fr_mm_s, extruder);
1451-
_buffer_steps(target, fr_mm_s, extruder);
1452-
ENABLE_STEPPER_DRIVER_INTERRUPT();
1453-
}
1454-
else
1455-
_buffer_steps(target, fr_mm_s, extruder);
1456-
14571421
stepper.wake_up();
14581422

1459-
} // _buffer_line()
1423+
} // buffer_line()
14601424

14611425
/**
14621426
* Directly set the planner XYZ position (and stepper positions)

Marlin/src/module/planner.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class Planner {
144144
static uint8_t last_extruder; // Respond to extruder change
145145
#endif
146146

147-
static int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
147+
static int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
148148

149149
static float e_factor[EXTRUDERS], // The flow percentage and volumetric multiplier combine to scale E movement
150150
filament_size[EXTRUDERS], // diameter of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder
@@ -352,17 +352,6 @@ class Planner {
352352

353353
#endif
354354

355-
/**
356-
* Planner::_buffer_steps
357-
*
358-
* Add a new linear movement to the buffer (in terms of steps).
359-
*
360-
* target - target position in steps units
361-
* fr_mm_s - (target) speed of the move
362-
* extruder - target extruder
363-
*/
364-
static void _buffer_steps(const int32_t target[XYZE], float fr_mm_s, const uint8_t extruder);
365-
366355
/**
367356
* Planner::_buffer_line
368357
*
@@ -374,7 +363,7 @@ class Planner {
374363
* fr_mm_s - (target) speed of the move
375364
* extruder - target extruder
376365
*/
377-
static void _buffer_line(const float &a, const float &b, const float &c, const float &e, const float &fr_mm_s, const uint8_t extruder);
366+
static void _buffer_line(const float &a, const float &b, const float &c, const float &e, float fr_mm_s, const uint8_t extruder);
378367

379368
static void _set_position_mm(const float &a, const float &b, const float &c, const float &e);
380369

0 commit comments

Comments
 (0)