Skip to content

Commit

Permalink
Tool Change Migration fixes and debugging (MarlinFirmware#18448)
Browse files Browse the repository at this point in the history
  • Loading branch information
InsanityAutomation authored and HairingX committed Jun 16, 2021
1 parent adc5fbb commit 049a65a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
15 changes: 13 additions & 2 deletions Marlin/src/feature/runout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bool FilamentMonitorBase::enabled = true,
#endif

#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
//#define DEBUG_TOOLCHANGE_MIGRATION_FEATURE
#include "../module/tool_change.h"
#endif

Expand Down Expand Up @@ -80,8 +81,18 @@ void event_filament_runout() {
if (TERN0(ADVANCED_PAUSE_FEATURE, did_pause_print)) return; // Action already in progress. Purge triggered repeated runout.

#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
if (migration.in_progress) return; // Action already in progress. Purge triggered repeated runout.
if (migration.automode) { extruder_migration(); return; }
if (migration.in_progress) {
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOLN("Migration Already In Progress");
#endif
return; // Action already in progress. Purge triggered repeated runout.
}
if (migration.automode) {
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOLN("Migration Starting");
#endif
if (extruder_migration()) return;
}
#endif

TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getActiveTool()));
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/config/M217.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void M217_report(const bool eeprom=false) {
" G", toolchange_settings.fan_time);

#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOPAIR(" N", int(migration.automode));
SERIAL_ECHOPAIR(" A", int(migration.automode));
SERIAL_ECHOPAIR(" L", LINEAR_UNIT(migration.last));
#endif

Expand Down
34 changes: 30 additions & 4 deletions Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,33 +1222,55 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {

#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)

void extruder_migration() {
bool extruder_migration() {

#if ENABLED(PREVENT_COLD_EXTRUSION)
if (thermalManager.targetTooColdToExtrude(active_extruder)) return;
if (thermalManager.targetTooColdToExtrude(active_extruder)) {
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOLN("Migration Source Too Cold");
#endif
return false;
}
#endif

// No auto-migration or specified target?
if (!migration.target && active_extruder >= migration.last) {
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHO_MSG("No Migration Target");
SERIAL_ECHO_MSG("Target: ", migration.target,
" Last: ", migration.last,
" Active: ", active_extruder);
#endif
migration.automode = false;
return;
return false;
}

// Migrate to a target or the next extruder

uint8_t migration_extruder = active_extruder;

if (migration.target) {
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOLN("Migration using fixed target");
#endif
// Specified target ok?
const int16_t t = migration.target - 1;
if (t != active_extruder) migration_extruder = t;
}
else if (migration.automode && migration_extruder < migration.last && migration_extruder < EXTRUDERS - 1)
migration_extruder++;

if (migration_extruder == active_extruder) return;
if (migration_extruder == active_extruder) {
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOLN("Migration source matches active");
#endif
return false;
}

// Migration begins
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOLN("Beginning migration");
#endif

migration.in_progress = true; // Prevent runout script
planner.synchronize();
Expand Down Expand Up @@ -1294,6 +1316,10 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {

planner.synchronize();
planner.set_e_position_mm(current_position.e); // New extruder primed and ready
#if ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOLN("Migration Complete");
#endif
return true;
}

#endif // TOOLCHANGE_MIGRATION_FEATURE
2 changes: 1 addition & 1 deletion Marlin/src/module/tool_change.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
} migration_settings_t;
constexpr migration_settings_t migration_defaults = { 0, 0, false, false };
extern migration_settings_t migration;
void extruder_migration();
bool extruder_migration();
#endif
#endif

Expand Down

0 comments on commit 049a65a

Please sign in to comment.