Skip to content

Commit f7e31bd

Browse files
committed
apply review changes
1 parent 1fa21f5 commit f7e31bd

File tree

8 files changed

+63
-68
lines changed

8 files changed

+63
-68
lines changed

Marlin/Configuration_adv.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,10 +2267,9 @@
22672267
/**
22682268
* Nonlinear Extrusion Control
22692269
*
2270-
* Enables control over extrusion rate based on instantaneous extruder velocity. This can be used
2271-
* to correct for underextrusion at high extruder speeds that are otherwise well-behaved (e.g.
2272-
* not yet skipping).
2273-
*/
2270+
* Control extrusion rate based on instantaneous extruder velocity. Can be used to correct for
2271+
* underextrusion at high extruder speeds that are otherwise well-behaved (i.e., not skipping).
2272+
*/
22742273
//#define NONLINEAR_EXTRUSION
22752274

22762275
// @section leveling

Marlin/src/core/language.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
#define STR_CHAMBER_PID "Chamber PID"
300300
#define STR_STEPS_PER_UNIT "Steps per unit"
301301
#define STR_LINEAR_ADVANCE "Linear Advance"
302+
#define STR_NONLINEAR_EXTRUSION "Nonlinear Extrusion"
302303
#define STR_CONTROLLER_FAN "Controller Fan"
303304
#define STR_STEPPER_MOTOR_CURRENTS "Stepper motor currents"
304305
#define STR_RETRACT_S_F_Z "Retract (S<length> F<feedrate> Z<lift>)"

Marlin/src/gcode/feature/nonlinear/M592.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,25 @@
2727
#include "../../gcode.h"
2828
#include "../../../module/stepper.h"
2929

30+
void GcodeSuite::M592_report(const bool forReplay/*=true*/) {
31+
report_heading(forReplay, F(STR_NONLINEAR_EXTRUSION));
32+
SERIAL_ECHOLNPGM(" M593 A", stepper.ne.A, " B", stepper.ne.B, " C", stepper.ne.C);
33+
}
34+
3035
/**
3136
* M592: Get or set nonlinear extrusion parameters
3237
* A<factor> Linear coefficient (default 0.0)
3338
* B<factor> Quadratic coefficient (default 0.0)
3439
* C<factor> Constant coefficient (default 1.0)
3540
*
36-
* Adjusts the amount of extrusion based on the instantaneous velocity of extrusion, as a multiplier.
37-
* The amount of extrusion is multiplied by max(C, C + A*v + B*v^2) where v is extruder velocity in mm/s.
38-
* Only adjusts forward extrusions, since those are the ones affected by backpressure.
41+
* Adjusts the amount of extrusion based on the instantaneous velocity of extrusion, as a multiplier.
42+
* The amount of extrusion is multiplied by max(C, C + A*v + B*v^2) where v is extruder velocity in mm/s.
43+
* Only adjusts forward extrusions, since those are the ones affected by backpressure.
3944
*/
4045
void GcodeSuite::M592() {
41-
if (parser.seenval('A')) {
42-
stepper.ne_A = parser.value_float();
43-
}
44-
45-
if (parser.seenval('B')) {
46-
stepper.ne_B = parser.value_float();
47-
}
48-
49-
if (parser.seenval('C')) {
50-
stepper.ne_C = parser.value_float();
51-
}
46+
if (parser.seenval('A')) stepper.ne.A = parser.value_float();
47+
if (parser.seenval('B')) stepper.ne.B = parser.value_float();
48+
if (parser.seenval('C')) stepper.ne.C = parser.value_float();
5249
}
5350

5451
#endif // NONLINEAR_EXTRUSION

Marlin/src/gcode/gcode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,7 @@ class GcodeSuite {
11091109

11101110
#if ENABLED(NONLINEAR_EXTRUSION)
11111111
static void M592();
1112+
static void M592_report(const bool forReplay=true);
11121113
#endif
11131114

11141115
#if HAS_ZV_SHAPING

Marlin/src/inc/SanityCheck.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -853,19 +853,15 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
853853
#endif
854854

855855
/**
856-
* Nonlinear Extrusion requirements
856+
* Nonlinear Extrusion requirements
857857
*/
858858
#if ENABLED(NONLINEAR_EXTRUSION)
859859
#if DISABLED(ADAPTIVE_STEP_SMOOTHING)
860-
#error "ADAPTIVE_STEP_SMOOTHING is required for NONLINEAR_EXTRUSION"
861-
#endif
862-
863-
#if EXTRUDERS > 1
864-
#error "NONLINEAR_EXTRUSION doesn't currently support multi-extruder setups"
865-
#endif
866-
867-
#if DISABLED(CPU_32_BIT)
868-
#error "NONLINEAR_EXTRUSION requires 32-bit CPU"
860+
#error "ADAPTIVE_STEP_SMOOTHING is required for NONLINEAR_EXTRUSION."
861+
#elif HAS_MULTI_EXTRUDER
862+
#error "NONLINEAR_EXTRUSION doesn't currently support multi-extruder setups."
863+
#elif DISABLED(CPU_32_BIT)
864+
#error "NONLINEAR_EXTRUSION requires a 32-bit CPU."
869865
#endif
870866
#endif
871867

Marlin/src/module/settings.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,10 @@ typedef struct SettingsDataStruct {
635635
#endif
636636

637637
//
638-
// NONLINEAR_EXTRUSION
638+
// Nonlinear Extrusion
639639
//
640640
#if ENABLED(NONLINEAR_EXTRUSION)
641-
float ne_A, ne_B, ne_C; // M592 A B C
641+
ne_coeff_t stepper_ne; // M592 A B C
642642
#endif
643643

644644
} SettingsData;
@@ -1737,12 +1737,10 @@ void MarlinSettings::postprocess() {
17371737
#endif
17381738

17391739
//
1740-
// NONLINEAR_EXTRUSION
1740+
// Nonlinear Extrusion
17411741
//
17421742
#if ENABLED(NONLINEAR_EXTRUSION)
1743-
EEPROM_WRITE(stepper.ne_A);
1744-
EEPROM_WRITE(stepper.ne_B);
1745-
EEPROM_WRITE(stepper.ne_C);
1743+
EEPROM_WRITE(stepper.ne);
17461744
#endif
17471745

17481746
//
@@ -2820,12 +2818,10 @@ void MarlinSettings::postprocess() {
28202818
#endif
28212819

28222820
//
2823-
// NONLINEAR_EXTRUSION
2821+
// Nonlinear Extrusion
28242822
//
28252823
#if ENABLED(NONLINEAR_EXTRUSION)
2826-
EEPROM_READ(stepper.ne_A);
2827-
EEPROM_READ(stepper.ne_B);
2828-
EEPROM_READ(stepper.ne_C);
2824+
EEPROM_READ(stepper.ne);
28292825
#endif
28302826

28312827
//
@@ -3421,15 +3417,13 @@ void MarlinSettings::reset() {
34213417
//
34223418
// Heated Bed PID
34233419
//
3424-
34253420
#if ENABLED(PIDTEMPBED)
34263421
thermalManager.temp_bed.pid.set(DEFAULT_bedKp, DEFAULT_bedKi, DEFAULT_bedKd);
34273422
#endif
34283423

34293424
//
34303425
// Heated Chamber PID
34313426
//
3432-
34333427
#if ENABLED(PIDTEMPCHAMBER)
34343428
thermalManager.temp_chamber.pid.set(DEFAULT_chamberKp, DEFAULT_chamberKi, DEFAULT_chamberKd);
34353429
#endif
@@ -3481,7 +3475,6 @@ void MarlinSettings::reset() {
34813475
//
34823476
// Volumetric & Filament Size
34833477
//
3484-
34853478
#if DISABLED(NO_VOLUMETRICS)
34863479
parser.volumetric_enabled = ENABLED(VOLUMETRIC_DEFAULT_ON);
34873480
for (uint8_t q = 0; q < COUNT(planner.filament_size); ++q)
@@ -3623,6 +3616,11 @@ void MarlinSettings::reset() {
36233616
//
36243617
TERN_(FT_MOTION, fxdTiCtrl.set_defaults());
36253618

3619+
//
3620+
// Nonlinear Extrusion
3621+
//
3622+
TERN_(NONLINEAR_EXTRUSION, stepper.ne.reset());
3623+
36263624
//
36273625
// Input Shaping
36283626
//
@@ -3892,6 +3890,11 @@ void MarlinSettings::reset() {
38923890
//
38933891
TERN_(FT_MOTION, gcode.M493_report(forReplay));
38943892

3893+
//
3894+
// Nonlinear Extrusion
3895+
//
3896+
TERN_(NONLINEAR_EXTRUSION, gcode.M592_report(forReplay));
3897+
38953898
//
38963899
// Input Shaping
38973900
//

Marlin/src/module/stepper.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,9 @@ uint32_t Stepper::advance_divisor = 0,
246246
#endif
247247

248248
#if ENABLED(NONLINEAR_EXTRUSION)
249+
ne_coeff_t Stepper::ne;
250+
ne_fix_t Stepper::ne_fix;
249251
int32_t Stepper::ne_edividend;
250-
float Stepper::ne_A = 0;
251-
float Stepper::ne_B = 0;
252-
float Stepper::ne_C = 1;
253-
int32_t Stepper::ne_Afix;
254-
int32_t Stepper::ne_Bfix;
255-
int32_t Stepper::ne_Cfix;
256252
uint32_t Stepper::ne_scale;
257253
#endif
258254

@@ -2207,10 +2203,10 @@ hal_timer_t Stepper::calc_multistep_timer_interval(uint32_t step_rate) {
22072203

22082204
#if ENABLED(NONLINEAR_EXTRUSION)
22092205
uint32_t velocity = ne_scale * step_rate; // scale step_rate first so all intermediate values stay in range of 8.24 fixed point math
2210-
int32_t vd = (((int64_t)ne_Afix * velocity) >> 24) + (((((int64_t)ne_Bfix * velocity) >> 24) * velocity) >> 24);
2211-
if (vd < 0) vd = 0;
2206+
int32_t vd = (((int64_t)nefix.A * velocity) >> 24) + (((((int64_t)nefix.B * velocity) >> 24) * velocity) >> 24);
2207+
NOLESS(vd, 0);
22122208

2213-
advance_dividend.e = ((uint64_t)(ne_Cfix + vd) * ne_edividend) >> 24;
2209+
advance_dividend.e = (uint64_t(nefix.C + vd) * ne_edividend) >> 24;
22142210
#endif
22152211

22162212
#if ENABLED(OLD_ADAPTIVE_MULTISTEPPING)
@@ -2655,9 +2651,10 @@ hal_timer_t Stepper::block_phase_isr() {
26552651
acceleration_time = deceleration_time = 0;
26562652

26572653
#if ENABLED(ADAPTIVE_STEP_SMOOTHING)
2658-
oversampling_factor = 0; // Assume no axis smoothing (via oversampling)
26592654
#if ENABLED(NONLINEAR_EXTRUSION)
2660-
oversampling_factor = 1; // We need at least 2x oversampling to ensure we can increase extruder step rate
2655+
oversampling_factor = 1; // Need at least 2x oversampling to permit increase of E step rate
2656+
#else
2657+
oversampling_factor = 0; // Assume no axis smoothing (via oversampling)
26612658
#endif
26622659
// Decide if axis smoothing is possible
26632660
uint32_t max_rate = current_block->nominal_rate; // Get the step event rate
@@ -2777,16 +2774,16 @@ hal_timer_t Stepper::block_phase_isr() {
27772774

27782775
#if ENABLED(NONLINEAR_EXTRUSION)
27792776
ne_edividend = advance_dividend.e;
2780-
float scale = (float(ne_edividend) / advance_divisor) * planner.mm_per_step[E_AXIS_N(current_block->extruder)];
2777+
const float scale = (float(ne_edividend) / advance_divisor) * planner.mm_per_step[E_AXIS_N(current_block->extruder)];
27812778
ne_scale = (1L << 24) * scale;
27822779
if (current_block->direction_bits.e) {
2783-
ne_Afix = (1L << 24) * ne_A;
2784-
ne_Bfix = (1L << 24) * ne_B;
2785-
ne_Cfix = (1L << 24) * ne_C;
2786-
} else {
2787-
ne_Afix = 0;
2788-
ne_Bfix = 0;
2789-
ne_Cfix = (1L << 24);
2780+
ne_fix.A = (1L << 24) * ne.A;
2781+
ne_fix.B = (1L << 24) * ne.B;
2782+
ne_fix.C = (1L << 24) * ne.C;
2783+
}
2784+
else {
2785+
ne_fix.A = ne_fix.B = 0;
2786+
ne_fix.C = (1L << 24);
27902787
}
27912788
#endif
27922789

Marlin/src/module/stepper.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ constexpr ena_mask_t enable_overlap[] = {
284284

285285
#endif // HAS_ZV_SHAPING
286286

287+
#if ENABLED(NONLINEAR_EXTRUSION)
288+
typedef struct { float A, B, C; void reset() { A = B = 0.0f; C = 1.0f; } } ne_coeff_t;
289+
typedef struct { int32_t A, B, C; } ne_fix_t;
290+
#endif
291+
287292
//
288293
// Stepper class definition
289294
//
@@ -327,9 +332,7 @@ class Stepper {
327332
#endif
328333

329334
#if ENABLED(NONLINEAR_EXTRUSION)
330-
static float ne_A;
331-
static float ne_B;
332-
static float ne_C;
335+
static ne_coeff_t nla;
333336
#endif
334337

335338
private:
@@ -423,11 +426,9 @@ class Stepper {
423426
#endif
424427

425428
#if ENABLED(NONLINEAR_EXTRUSION)
426-
static int32_t ne_edividend;
427-
static int32_t ne_Afix;
428-
static int32_t ne_Bfix;
429-
static int32_t ne_Cfix;
430-
static uint32_t ne_scale;
429+
static int32_t ne_edividend;
430+
static uint32_t ne_scale;
431+
static ne_fix_t ne_fix;
431432
#endif
432433

433434
#if ENABLED(BABYSTEPPING)

0 commit comments

Comments
 (0)