Automatic Tool Migration feature (#17248)

This commit is contained in:
studiodyne
2020-04-23 04:03:28 +02:00
committed by GitHub
parent 4dce03fa42
commit 2f6262c27b
27 changed files with 575 additions and 151 deletions

View File

@ -27,6 +27,10 @@
#include "../gcode.h"
#include "../../module/tool_change.h"
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
#include "../../module/motion.h"
#endif
#include "../../MarlinCore.h" // for SP_X_STR, etc.
extern const char SP_X_STR[], SP_Y_STR[], SP_Z_STR[];
@ -35,16 +39,30 @@ void M217_report(const bool eeprom=false) {
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
serialprintPGM(eeprom ? PSTR(" M217") : PSTR("Toolchange:"));
SERIAL_ECHOPAIR(" S", LINEAR_UNIT(toolchange_settings.swap_length));
SERIAL_ECHOPAIR_P(SP_E_STR, LINEAR_UNIT(toolchange_settings.extra_prime));
SERIAL_ECHOPAIR_P(SP_P_STR, LINEAR_UNIT(toolchange_settings.prime_speed));
SERIAL_ECHOPAIR(" R", LINEAR_UNIT(toolchange_settings.retract_speed));
SERIAL_ECHOPAIR(" S", LINEAR_UNIT(toolchange_settings.swap_length),
" B", LINEAR_UNIT(toolchange_settings.extra_resume));
SERIAL_ECHOPAIR_P(SP_E_STR, LINEAR_UNIT(toolchange_settings.extra_prime),
SP_P_STR, LINEAR_UNIT(toolchange_settings.prime_speed));
SERIAL_ECHOPAIR(" R", LINEAR_UNIT(toolchange_settings.retract_speed),
" U", LINEAR_UNIT(toolchange_settings.unretract_speed),
" F", toolchange_settings.fan_speed,
" G", toolchange_settings.fan_time);
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
SERIAL_ECHOPAIR(" N", int(migration.automode));
SERIAL_ECHOPAIR(" L", LINEAR_UNIT(migration.last));
#endif
#if ENABLED(TOOLCHANGE_PARK)
SERIAL_ECHOPAIR(" W", LINEAR_UNIT(toolchange_settings.enable_park));
SERIAL_ECHOPAIR_P(SP_X_STR, LINEAR_UNIT(toolchange_settings.change_point.x));
SERIAL_ECHOPAIR_P(SP_Y_STR, LINEAR_UNIT(toolchange_settings.change_point.y));
#endif
#if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
SERIAL_ECHOPAIR(" V", LINEAR_UNIT(enable_first_prime));
#endif
#else
UNUSED(eeprom);
@ -58,48 +76,98 @@ void M217_report(const bool eeprom=false) {
/**
* M217 - Set SINGLENOZZLE toolchange parameters
*
* // Tool change command
* Q Prime active tool and exit
*
* // Tool change settings
* S[linear] Swap length
* E[linear] Purge length
* B[linear] Extra Swap length
* E[linear] Prime length
* P[linear/m] Prime speed
* R[linear/m] Retract speed
* U[linear/m] UnRetract speed
* V[linear] 0/1 Enable auto prime first extruder used
* W[linear] 0/1 Enable park & Z Raise
* X[linear] Park X (Requires TOOLCHANGE_PARK)
* Y[linear] Park Y (Requires TOOLCHANGE_PARK)
* Z[linear] Z Raise
* F[linear] Fan Speed 0-255
* G[linear/s] Fan time
*
* Tool migration settings
* A[0|1] Enable auto-migration on runout
* L[index] Last extruder to use for auto-migration
*
* Tool migration command
* T[index] Migrate to next extruder or the given extruder
*/
void GcodeSuite::M217() {
#define SPR_PARAM
#define XY_PARAM
#if ENABLED(TOOLCHANGE_FILAMENT_SWAP)
#undef SPR_PARAM
#define SPR_PARAM "SPRE"
static constexpr float max_extrude = TERN(PREVENT_LENGTHY_EXTRUDE, EXTRUDE_MAXLENGTH, 500);
static constexpr float max_extrude =
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
EXTRUDE_MAXLENGTH
#else
500
#endif
;
if (parser.seen('Q')) { tool_change_prime(); return; }
if (parser.seenval('S')) { const float v = parser.value_linear_units(); toolchange_settings.swap_length = constrain(v, 0, max_extrude); }
if (parser.seenval('B')) { const float v = parser.value_linear_units(); toolchange_settings.extra_resume = constrain(v, -10, 10); }
if (parser.seenval('E')) { const float v = parser.value_linear_units(); toolchange_settings.extra_prime = constrain(v, 0, max_extrude); }
if (parser.seenval('P')) { const int16_t v = parser.value_linear_units(); toolchange_settings.prime_speed = constrain(v, 10, 5400); }
if (parser.seenval('R')) { const int16_t v = parser.value_linear_units(); toolchange_settings.retract_speed = constrain(v, 10, 5400); }
if (parser.seenval('U')) { const int16_t v = parser.value_linear_units(); toolchange_settings.unretract_speed = constrain(v, 10, 5400); }
#if TOOLCHANGE_FS_FAN >= 0 && FAN_COUNT > 0
if (parser.seenval('F')) { const int16_t v = parser.value_linear_units(); toolchange_settings.fan_speed = constrain(v, 0, 255); }
if (parser.seenval('G')) { const int16_t v = parser.value_linear_units(); toolchange_settings.fan_time = constrain(v, 1, 30); }
#endif
#endif
#if ENABLED(TOOLCHANGE_FS_PRIME_FIRST_USED)
if (parser.seenval('V')) { enable_first_prime = parser.value_linear_units(); }
#endif
#if ENABLED(TOOLCHANGE_PARK)
#undef XY_PARAM
#define XY_PARAM "XY"
if (parser.seenval('X')) { toolchange_settings.change_point.x = parser.value_linear_units(); }
if (parser.seenval('Y')) { toolchange_settings.change_point.y = parser.value_linear_units(); }
if (parser.seenval('W')) { toolchange_settings.enable_park = parser.value_linear_units(); }
if (parser.seenval('X')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.x = constrain(v, X_MIN_POS, X_MAX_POS); }
if (parser.seenval('Y')) { const int16_t v = parser.value_linear_units(); toolchange_settings.change_point.y = constrain(v, Y_MIN_POS, Y_MAX_POS); }
#endif
if (parser.seenval('Z')) { toolchange_settings.z_raise = parser.value_linear_units(); }
if (!parser.seen(SPR_PARAM XY_PARAM "Z")) M217_report();
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
migration.target = 0; // 0 = disabled
if (parser.seenval('L')) { // Last
const int16_t lval = parser.value_int();
if (WITHIN(lval, 0, EXTRUDERS - 1)) {
migration.last = lval;
migration.automode = (active_extruder < migration.last);
}
}
if (parser.seen('A')) // Auto on/off
migration.automode = parser.value_bool();
if (parser.seen('T')) { // Migrate now
if (parser.has_value()) {
const int16_t tval = parser.value_int();
if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != active_extruder) {
migration.target = tval + 1;
extruder_migration();
migration.target = 0; // disable
return;
}
else
migration.target = 0; // disable
}
else {
extruder_migration();
return;
}
}
#endif
M217_report();
}
#endif // EXTRUDERS > 1

View File

@ -33,10 +33,8 @@ void GcodeSuite::M221() {
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
if (parser.seenval('S')) {
planner.flow_percentage[target_extruder] = parser.value_int();
planner.refresh_e_factor(target_extruder);
}
if (parser.seenval('S'))
planner.set_flow(target_extruder, parser.value_int());
else {
SERIAL_ECHO_START();
SERIAL_CHAR('E', '0' + target_extruder);

View File

@ -31,10 +31,6 @@
#include "../queue.h"
#endif
#if HAS_LEDS_OFF_FLAG
#include "../../MarlinCore.h"
#endif
#if EITHER(LCD_SET_PROGRESS_MANUALLY, SD_REPRINT_LAST_SELECTED_FILE)
#include "../../lcd/ultralcd.h"
#endif
@ -44,6 +40,7 @@
#endif
#if HAS_LEDS_OFF_FLAG
#include "../../MarlinCore.h" // for wait_for_user_response
#include "../../feature/leds/printer_event_leds.h"
#endif