Skip to content

Commit

Permalink
Do not extrude during unload in a filament runout
Browse files Browse the repository at this point in the history
Introduce a new internal code 'R' to cleanly differentiate between
regular filament swap or runout.
  • Loading branch information
wavexx committed Jun 28, 2021
1 parent 31a00c3 commit a5135af
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 21 deletions.
25 changes: 20 additions & 5 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3735,7 +3735,7 @@ static T gcode_M600_filament_change_z_shift()
#endif
}

static void gcode_M600(bool automatic, float x_position, float y_position, float z_shift, float e_shift, float /*e_shift_late*/)
static void gcode_M600(bool automatic, bool runout, float x_position, float y_position, float z_shift, float e_shift, float /*e_shift_late*/)
{
st_synchronize();
float lastpos[4];
Expand Down Expand Up @@ -3777,8 +3777,17 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
lcd_change_fil_state = 0;

// Unload filament
if (mmu_enabled) extr_unload(); //unload just current filament for multimaterial printers (used also in M702)
else unload_filament(true); //unload filament for single material (used also in M702)
if (mmu_enabled)
{
// unload just current filament for multimaterial printers (used also in M702)
extr_unload();
}
else
{
// unload filament for single material (used also in M702)
unload_filament(runout? UnloadType::Runout: UnloadType::Swap);
}

//finish moves
st_synchronize();

Expand Down Expand Up @@ -8184,7 +8193,8 @@ SERIAL_PROTOCOLPGM("\n\n");
float e_shift_init = 0;
float e_shift_late = 0;
bool automatic = false;

bool runout = false;

//Retract extruder
if(code_seen('E'))
{
Expand Down Expand Up @@ -8242,8 +8252,13 @@ SERIAL_PROTOCOLPGM("\n\n");

if (mmu_enabled && code_seen_P(PSTR("AUTO")))
automatic = true;
if (code_seen('R'))
{
// Code 'R' is supported internally to indicate filament change due to a runout condition
runout = true;
}

gcode_M600(automatic, x_position, y_position, z_shift, e_shift_init, e_shift_late);
gcode_M600(automatic, runout, x_position, y_position, z_shift, e_shift_init, e_shift_late);

}
break;
Expand Down
2 changes: 1 addition & 1 deletion Firmware/fsensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void fsensor_enque_M600(){
puts_P(PSTR("fsensor_update - M600"));
eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1);
eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1);
enquecommand_front_P((PSTR("M600")));
enquecommand_front_P((PSTR("M600 R")));
}

//! @brief filament sensor update (perform M600 on filament runout)
Expand Down
29 changes: 15 additions & 14 deletions Firmware/ultralcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4966,7 +4966,7 @@ void lcd_wizard(WizState state)
lcd_display_message_fullscreen_P(_i("Now I will preheat nozzle for PLA."));
wait_preheat();
//unload current filament
unload_filament(true);
unload_filament();
//load filament
lcd_wizard_load();
setTargetHotend(0, 0); //we are finished, cooldown nozzle
Expand Down Expand Up @@ -6282,23 +6282,24 @@ static void change_extr_menu(){
#endif //SNMM

// unload filament for single material printer (used in M702 gcode)
// @param automatic: If true, unload_filament is part of a unload+load sequence (M600)
void unload_filament(bool automatic)
void unload_filament(UnloadType unload)
{
custom_message_type = CustomMsg::FilamentLoading;
lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT));

raise_z_above(automatic? MIN_Z_FOR_SWAP: MIN_Z_FOR_UNLOAD);

// extrude slowly
current_position[E_AXIS] += FILAMENTCHANGE_UNLOADFEED;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_EFEED_PRIME);
st_synchronize();

// relieve leftover pressure
current_position[E_AXIS] += 0.1;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_EFEED_PRIME / 2);
st_synchronize();
raise_z_above(unload == UnloadType::Swap? MIN_Z_FOR_SWAP: MIN_Z_FOR_UNLOAD);
if (unload != UnloadType::Runout)
{
// extrude slowly
current_position[E_AXIS] += FILAMENTCHANGE_UNLOADFEED;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_EFEED_PRIME);
st_synchronize();

// relieve leftover pressure
current_position[E_AXIS] += 0.1;
plan_buffer_line_curposXYZE(FILAMENTCHANGE_EFEED_PRIME / 2);
st_synchronize();
}

// retract & eject
current_position[E_AXIS] += FILAMENTCHANGE_FIRSTRETRACT;
Expand Down
12 changes: 11 additions & 1 deletion Firmware/ultralcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,17 @@ extern bool bFilamentAction;
void mFilamentItem(uint16_t nTemp,uint16_t nTempBed);
void mFilamentItemForce();
void lcd_generic_preheat_menu();
void unload_filament(bool automatic = false);


enum class UnloadType : uint8_t
{
User, // user-triggered unload
Swap, // part of a M600 sequence
Runout, // triggered by runout
};

void unload_filament(UnloadType unload=UnloadType::User);


void lcd_printer_connected();
void lcd_ping();
Expand Down

0 comments on commit a5135af

Please sign in to comment.