From d796df3f1430cff91619fbb973c07f92ae718afe Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Mon, 3 Sep 2018 17:32:42 +0200 Subject: [PATCH 1/2] PFW-543 Add filament ramming when unloading filament with MMU. --- Firmware/mmu.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 78b9d93a..251fcde4 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -645,6 +645,61 @@ void extr_adj(int extruder) //loading filament for SNMM #endif } +//! @brief Unload sequence to optimize shape of the tip of the unloaded filament +//! +//! Ideas to minimize flash consumption of this code: +//! +//! Create const array of extrude and feed_rate on stack, call increment current_position, plan_buffer_line() and st_synchronize() +//! in loop iterating over array. +//! +//! Same as previous, but create array in PROGMEM and call PGM_read instructions in a loop. +//! +static void filament_ramming() +{ + current_position[E_AXIS] += 1; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] += 1; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1500 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] += 2; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] += 1.5; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] += 2.5; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 4000 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] -= 15; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 5000 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] -= 14; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1200 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] -= 6; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] += 10; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 700 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] -= 10; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 400 / 60, active_extruder); + st_synchronize(); + + current_position[E_AXIS] -= 50; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder); + st_synchronize(); +} void extr_unload() { //unload just current filament for multimaterial printers @@ -666,9 +721,7 @@ void extr_unload() lcd_print(" "); lcd_print(mmu_extruder + 1); - current_position[E_AXIS] -= 80; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder); - st_synchronize(); + filament_ramming(); mmu_command(MMU_CMD_U0); // get response @@ -989,4 +1042,4 @@ void mmu_eject_filament(uint8_t filament, bool recover) { puts_P(PSTR("Filament nr out of range!")); } -} \ No newline at end of file +} From 517fbb66bfc3a5460f02b1d24a7f49f2a0b0eecb Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Mon, 3 Sep 2018 20:00:46 +0200 Subject: [PATCH 2/2] Save 1K flash memory. --- Firmware/mmu.cpp | 79 +++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp index 251fcde4..7d2ef3c3 100644 --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -11,6 +11,7 @@ #include "cardreader.h" #include "ultralcd.h" #include "sound.h" +#include #define CHECK_FINDA ((IS_SD_PRINTING || is_usb_printing) && (mcode_in_progress != 600) && !saved_printing && e_active()) @@ -645,60 +646,36 @@ void extr_adj(int extruder) //loading filament for SNMM #endif } +struct E_step +{ + float extrude; //!< extrude distance in mm + float feed_rate; //!< feed rate in mm/s +}; +static const E_step ramming_sequence[] PROGMEM = +{ + {1.0, 1000.0/60}, + {1.0, 1500.0/60}, + {2.0, 2000.0/60}, + {1.5, 3000.0/60}, + {2.5, 4000.0/60}, + {-15.0, 5000.0/60}, + {-14.0, 1200.0/60}, + {-6.0, 600.0/60}, + {10.0, 700.0/60}, + {-10.0, 400.0/60}, + {-50.0, 2000.0/60}, +}; + //! @brief Unload sequence to optimize shape of the tip of the unloaded filament -//! -//! Ideas to minimize flash consumption of this code: -//! -//! Create const array of extrude and feed_rate on stack, call increment current_position, plan_buffer_line() and st_synchronize() -//! in loop iterating over array. -//! -//! Same as previous, but create array in PROGMEM and call PGM_read instructions in a loop. -//! static void filament_ramming() { - current_position[E_AXIS] += 1; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1000 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] += 1; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1500 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] += 2; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] += 1.5; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 3000 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] += 2.5; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 4000 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] -= 15; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 5000 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] -= 14; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 1200 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] -= 6; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 600 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] += 10; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 700 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] -= 10; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 400 / 60, active_extruder); - st_synchronize(); - - current_position[E_AXIS] -= 50; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2000 / 60, active_extruder); - st_synchronize(); + for(uint8_t i = 0; i < (sizeof(ramming_sequence)/sizeof(E_step));++i) + { + current_position[E_AXIS] += pgm_read_float(&(ramming_sequence[i].extrude)); + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], + current_position[E_AXIS], pgm_read_float(&(ramming_sequence[i].feed_rate)), active_extruder); + st_synchronize(); + } } void extr_unload()