Skip to content

Commit

Permalink
apply DISTINCT_E_FACTORS
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 1, 2022
1 parent 56c32f5 commit d921fdb
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 57 deletions.
10 changes: 7 additions & 3 deletions Marlin/Configuration_adv.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/**
* Marlin 3D Printer Firmware
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
Expand Down Expand Up @@ -2064,8 +2064,12 @@
*/
//#define LIN_ADVANCE
#if ENABLED(LIN_ADVANCE)
//#define EXTRA_LIN_ADVANCE_K // Add a second linear advance constant, configurable with M900.
#define LIN_ADVANCE_K { 0.22 } // Unit: mm compression per 1mm/s extruder speed
#if ENABLED(DISTINCT_E_FACTORS)
#define ADVANCE_K { 0.22 } // (mm) Compression length per 1mm/s extruder speed
#else
#define ADVANCE_K 0.22 // (mm) Compression length per 1mm/s extruder speed
#endif
//#define ADVANCE_K_EXTRA // Add a second linear advance constant, configurable with M900.
//#define LA_DEBUG // Print debug information to serial during operation. Disable for production use.
//#define EXPERIMENTAL_SCURVE // Allow S-Curve Acceleration to be used with LA.
//#define ALLOW_LOW_EJERK // Allow a DEFAULT_EJERK value of <10. Recommended for direct drive hotends.
Expand Down
22 changes: 11 additions & 11 deletions Marlin/src/gcode/feature/advance/M900.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
#include "../../gcode.h"
#include "../../../module/planner.h"

#if ENABLED(EXTRA_LIN_ADVANCE_K)
float other_extruder_advance_K[EXTRUDERS];
#if ENABLED(ADVANCE_K_EXTRA)
float other_extruder_advance_K[DISTINCT_E];
uint8_t lin_adv_slot = 0;
#endif

/**
* M900: Get or Set Linear Advance K-factor
* T<tool> Which tool to address
* K<factor> Set current advance K factor (Slot 0).
* L<factor> Set secondary advance K factor (Slot 1). Requires EXTRA_LIN_ADVANCE_K.
* S<0/1> Activate slot 0 or 1. Requires EXTRA_LIN_ADVANCE_K.
* L<factor> Set secondary advance K factor (Slot 1). Requires ADVANCE_K_EXTRA.
* S<0/1> Activate slot 0 or 1. Requires ADVANCE_K_EXTRA.
*/
void GcodeSuite::M900() {

Expand All @@ -58,12 +58,12 @@ void GcodeSuite::M900() {
}
#endif

float &kref = planner.extruder_advance_K[tool_index], newK = kref;
float &kref = planner.extruder_advance_K[E_INDEX_N(tool_index)], newK = kref;
const float oldK = newK;

#if ENABLED(EXTRA_LIN_ADVANCE_K)
#if ENABLED(ADVANCE_K_EXTRA)

float &lref = other_extruder_advance_K[tool_index];
float &lref = other_extruder_advance_K[E_INDEX_N(tool_index)];

const bool old_slot = TEST(lin_adv_slot, tool_index), // The tool's current slot (0 or 1)
new_slot = parser.boolval('S', old_slot); // The passed slot (default = current)
Expand Down Expand Up @@ -111,9 +111,9 @@ void GcodeSuite::M900() {

if (!parser.seen_any()) {

#if ENABLED(EXTRA_LIN_ADVANCE_K)
#if ENABLED(ADVANCE_K_EXTRA)

#if EXTRUDERS < 2
#if DISTINCT_E < 2
SERIAL_ECHOLNPGM("Advance S", new_slot, " K", kref, "(S", !new_slot, " K", lref, ")");
#else
EXTRUDER_LOOP() {
Expand All @@ -127,7 +127,7 @@ void GcodeSuite::M900() {
#else

SERIAL_ECHO_START();
#if EXTRUDERS < 2
#if DISTINCT_E < 2
SERIAL_ECHOLNPGM("Advance K=", planner.extruder_advance_K[0]);
#else
SERIAL_ECHOPGM("Advance K");
Expand All @@ -145,7 +145,7 @@ void GcodeSuite::M900() {

void GcodeSuite::M900_report(const bool forReplay/*=true*/) {
report_heading(forReplay, F(STR_LINEAR_ADVANCE));
#if EXTRUDERS < 2
#if DISTINCT_E < 2
report_echo_start(forReplay);
SERIAL_ECHOLNPGM(" M900 K", planner.extruder_advance_K[0]);
#else
Expand Down
12 changes: 12 additions & 0 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,3 +1067,15 @@
#if ANY(DISABLE_INACTIVE_X, DISABLE_INACTIVE_Y, DISABLE_INACTIVE_Z, DISABLE_INACTIVE_I, DISABLE_INACTIVE_J, DISABLE_INACTIVE_K, DISABLE_INACTIVE_U, DISABLE_INACTIVE_V, DISABLE_INACTIVE_W, DISABLE_INACTIVE_E)
#define HAS_DISABLE_INACTIVE_AXIS 1
#endif

// *** Temporary compatibility for CI ***
#ifdef LIN_ADVANCE_K
#if ENABLED(DISTINCT_E_FACTORS)
#define ADVANCE_K { LIN_ADVANCE_K }
#else
#define ADVANCE_K LIN_ADVANCE_K
#endif
#endif
#if ENABLED(EXTRA_LIN_ADVANCE_K)
#define ADVANCE_K_EXTRA
#endif
19 changes: 8 additions & 11 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1328,17 +1328,14 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
* Linear Advance 1.5 - Check K value range
*/
#if ENABLED(LIN_ADVANCE)
constexpr float lak[] = LIN_ADVANCE_K;
static_assert(COUNT(lak) == EXTRUDERS, "LIN_ADVANCE_K must be an array EXTRUDERS long.");
static_assert(
WITHIN(lak[0], 0, 10),
"LIN_ADVANCE_K must be values from 0 to 10 (Changed in LIN_ADVANCE v1.5, Marlin 1.1.9)."
);
#if EXTRUDERS > 1
static_assert(
WITHIN(lak[1], 0, 10),
"LIN_ADVANCE_K must be values from 0 to 10 (Changed in LIN_ADVANCE v1.5, Marlin 1.1.9)."
);
#if DISTINCT_E > 1
constexpr float lak[] = ADVANCE_K;
static_assert(COUNT(lak) < DISTINCT_E, "The ADVANCE_K array has too many elements (i.e., more than " STRINGIFY(DISTINCT_E) ").");
#define _LIN_ASSERT(N) static_assert(WITHIN(lak[N], 0, 10), "ADVANCE_K values must be from 0 to 10 (Changed in LIN_ADVANCE v1.5, Marlin 1.1.9).");
REPEAT(DISTINCT_E, _LIN_ASSERT)
#undef _LIN_ASSERT
#else
static_assert(WITHIN(ADVANCE_K, 0, 10), "ADVANCE_K must be from 0 to 10 (Changed in LIN_ADVANCE v1.5, Marlin 1.1.9).");
#endif
#if ENABLED(S_CURVE_ACCELERATION) && DISABLED(EXPERIMENTAL_SCURVE)
#error "LIN_ADVANCE and S_CURVE_ACCELERATION may not play well together! Enable EXPERIMENTAL_SCURVE to continue."
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2772,7 +2772,7 @@ void CrealityDWINClass::Menu_Item_Handler(uint8_t menu, uint8_t item, bool draw/
#if ENABLED(LIN_ADVANCE)
case ADVANCED_LA:
if (draw) {
Draw_Menu_Item(row, ICON_MaxAccelerated, F("Lin Advance Kp"));
Draw_Menu_Item(row, ICON_MaxAccelerated, F("Lin Advance K"));
Draw_Float(planner.extruder_advance_K[0], row, false, 100);
}
else
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/lcd/extui/ui_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,17 +712,17 @@ namespace ExtUI {

#if ENABLED(POWER_LOSS_RECOVERY)
bool getPowerLossRecoveryEnabled() { return recovery.enabled; }
void setPowerLossRecoveryEnabled(const bool value) { recovery.enable(value); }
void setPowerLossRecoveryEnabled(const bool value) { recovery.enable(value); }
#endif

#if ENABLED(LIN_ADVANCE)
float getLinearAdvance_mm_mm_s(const extruder_t extruder) {
return (extruder < EXTRUDERS) ? planner.extruder_advance_K[extruder - E0] : 0;
return (extruder < EXTRUDERS) ? planner.extruder_advance_K[E_INDEX_N(extruder - E0)] : 0;
}

void setLinearAdvance_mm_mm_s(const_float_t value, const extruder_t extruder) {
if (extruder < EXTRUDERS)
planner.extruder_advance_K[extruder - E0] = constrain(value, 0, 10);
planner.extruder_advance_K[E_INDEX_N(extruder - E0)] = constrain(value, 0, 10);
}
#endif

Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ void menu_backlash();
BACK_ITEM(MSG_ADVANCED_SETTINGS);

#if ENABLED(LIN_ADVANCE)
#if EXTRUDERS == 1
#if DISTINCT_E < 2
EDIT_ITEM(float42_52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 10);
#elif HAS_MULTI_EXTRUDER
#else
EXTRUDER_LOOP()
EDIT_ITEM_N(float42_52, e, MSG_ADVANCE_K_E, &planner.extruder_advance_K[e], 0, 10);
#endif
Expand Down Expand Up @@ -687,11 +687,11 @@ void menu_advanced_settings() {
#if DISABLED(NO_VOLUMETRICS) || ENABLED(ADVANCED_PAUSE_FEATURE)
SUBMENU(MSG_FILAMENT, menu_advanced_filament);
#elif ENABLED(LIN_ADVANCE)
#if EXTRUDERS == 1
#if DISTINCT_E < 2
EDIT_ITEM(float42_52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 10);
#elif HAS_MULTI_EXTRUDER
LOOP_L_N(n, E_STEPPERS)
EDIT_ITEM_N(float42_52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[n], 0, 10);
#else
EXTRUDER_LOOP()
EDIT_ITEM_N(float42_52, n, MSG_ADVANCE_K_E, &planner.extruder_advance_K[e], 0, 10);
#endif
#endif

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/menu/menu_tune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ void menu_tune() {
// Advance K:
//
#if ENABLED(LIN_ADVANCE) && DISABLED(SLIM_LCD_MENUS)
#if EXTRUDERS == 1
#if DISTINCT_E < 2
EDIT_ITEM(float42_52, MSG_ADVANCE_K, &planner.extruder_advance_K[0], 0, 10);
#elif HAS_MULTI_EXTRUDER
#else
EXTRUDER_LOOP()
EDIT_ITEM_N(float42_52, e, MSG_ADVANCE_K_E, &planner.extruder_advance_K[e], 0, 10);
#endif
Expand Down
10 changes: 5 additions & 5 deletions Marlin/src/module/planner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ float Planner::previous_nominal_speed;
#endif

#if ENABLED(LIN_ADVANCE)
float Planner::extruder_advance_K[EXTRUDERS]; // Initialized by settings.load()
float Planner::extruder_advance_K[DISTINCT_E]; // Initialized by settings.load()
#endif

#if HAS_POSITION_FLOAT
Expand Down Expand Up @@ -854,7 +854,7 @@ void Planner::calculate_trapezoid_for_block(block_t * const block, const_float_t

#if ENABLED(LIN_ADVANCE)
if (block->la_advance_rate) {
const float comp = extruder_advance_K[block->extruder] * block->steps.e / block->step_event_count;
const float comp = extruder_advance_K[E_INDEX_N(block->extruder)] * block->steps.e / block->step_event_count;
block->max_adv_steps = cruise_rate * comp;
block->final_adv_steps = final_rate * comp;
}
Expand Down Expand Up @@ -2541,7 +2541,7 @@ bool Planner::_populate_block(
*
* de > 0 : Extruder is running forward (e.g., for "Wipe while retracting" (Slic3r) or "Combing" (Cura) moves)
*/
use_advance_lead = esteps && extruder_advance_K[extruder] && de > 0;
use_advance_lead = esteps && extruder_advance_K[E_INDEX_N(extruder)] && de > 0;

if (use_advance_lead) {
float e_D_ratio = (target_float.e - position_float.e) /
Expand All @@ -2557,7 +2557,7 @@ bool Planner::_populate_block(
use_advance_lead = false;
else {
// Scale E acceleration so that it will be possible to jump to the advance speed.
const uint32_t max_accel_steps_per_s2 = MAX_E_JERK(extruder) / (extruder_advance_K[extruder] * e_D_ratio) * steps_per_mm;
const uint32_t max_accel_steps_per_s2 = MAX_E_JERK(extruder) / (extruder_advance_K[E_INDEX_N(extruder)] * e_D_ratio) * steps_per_mm;
if (TERN0(LA_DEBUG, accel > max_accel_steps_per_s2))
SERIAL_ECHOLNPGM("Acceleration limited.");
NOMORE(accel, max_accel_steps_per_s2);
Expand Down Expand Up @@ -2594,7 +2594,7 @@ bool Planner::_populate_block(

if (use_advance_lead) {
// the Bresenham algorithm will convert this step rate into extruder steps
block->la_advance_rate = extruder_advance_K[extruder] * block->acceleration_steps_per_s2;
block->la_advance_rate = extruder_advance_K[E_INDEX_N(extruder)] * block->acceleration_steps_per_s2;

// reduce LA ISR frequency by calling it only often enough to ensure that there will
// never be more than four extruder steps per call
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class Planner {
#endif

#if ENABLED(LIN_ADVANCE)
static float extruder_advance_K[EXTRUDERS];
static float extruder_advance_K[DISTINCT_E];
#endif

/**
Expand Down
24 changes: 14 additions & 10 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@
#endif
#endif

#if ENABLED(EXTRA_LIN_ADVANCE_K)
extern float other_extruder_advance_K[EXTRUDERS];
#if ENABLED(ADVANCE_K_EXTRA)
extern float other_extruder_advance_K[DISTINCT_E];
#endif

#if HAS_MULTI_EXTRUDER
Expand Down Expand Up @@ -442,7 +442,7 @@ typedef struct SettingsDataStruct {
//
// LIN_ADVANCE
//
float planner_extruder_advance_K[_MAX(EXTRUDERS, 1)]; // M900 K planner.extruder_advance_K
float planner_extruder_advance_K[_MAX(DISTINCT_E, 1)]; // M900 K planner.extruder_advance_K

//
// HAS_MOTOR_CURRENT_PWM
Expand Down Expand Up @@ -2334,7 +2334,7 @@ void MarlinSettings::postprocess() {
// Linear Advance
//
{
float extruder_advance_K[_MAX(EXTRUDERS, 1)];
float extruder_advance_K[_MAX(DISTINCT_E, 1)];
_FIELD_TEST(planner_extruder_advance_K);
EEPROM_READ(extruder_advance_K);
#if ENABLED(LIN_ADVANCE)
Expand Down Expand Up @@ -3206,13 +3206,17 @@ void MarlinSettings::reset() {
//
// Linear Advance
//

#if ENABLED(LIN_ADVANCE)
constexpr float linAdvanceK[] = LIN_ADVANCE_K;
EXTRUDER_LOOP() {
planner.extruder_advance_K[e] = linAdvanceK[e];
TERN_(EXTRA_LIN_ADVANCE_K, other_extruder_advance_K[e] = linAdvanceK[e]);
}
#if ENABLED(DISTINCT_E_FACTORS)
constexpr float linAdvanceK[] = ADVANCE_K;
EXTRUDER_LOOP() {
const float a = linAdvanceK[_MAX(e, COUNT(linAdvanceK) - 1)];
planner.extruder_advance_K[e] = a;
TERN_(ADVANCE_K_EXTRA, other_extruder_advance_K[e] = a);
}
#else
planner.extruder_advance_K[0] = ADVANCE_K;
#endif
#endif

//
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
#endif

// Migrate Linear Advance K factor to the new extruder
TERN_(LIN_ADVANCE, planner.extruder_advance_K[active_extruder] = planner.extruder_advance_K[migration_extruder]);
TERN_(LIN_ADVANCE, planner.extruder_advance_K[E_INDEX_N(active_extruder)] = planner.extruder_advance_K[E_INDEX_N(migration_extruder)]);

// Perform the tool change
tool_change(migration_extruder);
Expand Down
2 changes: 1 addition & 1 deletion buildroot/tests/mega2560
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ opt_enable AUTO_BED_LEVELING_UBL RESTORE_LEVELING_AFTER_G28 DEBUG_LEVELING_FEATU
REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER LIGHTWEIGHT_UI STATUS_MESSAGE_SCROLLING SHOW_CUSTOM_BOOTSCREEN BOOT_MARLIN_LOGO_SMALL \
SDSUPPORT SDCARD_SORT_ALPHA USB_FLASH_DRIVE_SUPPORT AUTO_REPORT_SD_STATUS SCROLL_LONG_FILENAMES MEDIA_MENU_AT_TOP \
EEPROM_SETTINGS EEPROM_CHITCHAT GCODE_MACROS CUSTOM_MENU_MAIN FREEZE_FEATURE CANCEL_OBJECTS SOUND_MENU_ITEM \
MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE EXTRA_LIN_ADVANCE_K QUICK_HOME \
MULTI_NOZZLE_DUPLICATION CLASSIC_JERK LIN_ADVANCE ADVANCE_K_EXTRA QUICK_HOME \
LCD_SET_PROGRESS_MANUALLY PRINT_PROGRESS_SHOW_DECIMALS SHOW_REMAINING_TIME \
ENCODER_NOISE_FILTER BABYSTEPPING BABYSTEP_XY NANODLP_Z_SYNC I2C_POSITION_ENCODERS M114_DETAIL
exec_test $1 $2 "Azteeg X3 Pro | EXTRUDERS 5 | RRDFGSC | UBL | LIN_ADVANCE ..." "$3"
Expand Down
4 changes: 2 additions & 2 deletions buildroot/tests/rambo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ opt_enable USE_ZMAX_PLUG REPRAP_DISCOUNT_SMART_CONTROLLER LCD_PROGRESS_BAR LCD_P
FWRETRACT ARC_P_CIRCLES CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS \
PSU_CONTROL PS_OFF_CONFIRM PS_OFF_SOUND POWER_OFF_WAIT_FOR_COOLDOWN \
POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE POWER_LOSS_RECOVER_ZHOME POWER_LOSS_ZHOME_POS \
SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER LIN_ADVANCE EXTRA_LIN_ADVANCE_K \
SLOW_PWM_HEATERS THERMAL_PROTECTION_CHAMBER LIN_ADVANCE ADVANCE_K_EXTRA \
HOST_ACTION_COMMANDS HOST_PROMPT_SUPPORT PINS_DEBUGGING MAX7219_DEBUG M114_DETAIL
opt_add DEBUG_POWER_LOSS_RECOVERY
exec_test $1 $2 "RAMBO | EXTRUDERS 2 | CHAR LCD + SD | FIX Probe | ABL-Linear | Advanced Pause | PLR | LEDs ..." "$3"
Expand Down Expand Up @@ -93,7 +93,7 @@ opt_set MOTHERBOARD BOARD_MINIRAMBO \
opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER \
SDSUPPORT PCA9632 SOUND_MENU_ITEM GCODE_REPEAT_MARKERS \
AUTO_BED_LEVELING_LINEAR PROBE_MANUALLY LCD_BED_LEVELING \
LIN_ADVANCE EXTRA_LIN_ADVANCE_K \
LIN_ADVANCE ADVANCE_K_EXTRA \
INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT EXPERIMENTAL_I2CBUS M100_FREE_MEMORY_WATCHER \
NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE \
ADVANCED_PAUSE_FEATURE PARK_HEAD_ON_PAUSE ADVANCED_PAUSE_CONTINUOUS_PURGE FILAMENT_LOAD_UNLOAD_GCODES \
Expand Down

0 comments on commit d921fdb

Please sign in to comment.