Optimize target_extruder, ignore T with mixing (#12432)

* Optimize target_extruder, ignore T with mixing
* Give G-code Tn parity with tool_change
This commit is contained in:
Scott Lahteine
2018-11-14 17:33:04 -06:00
committed by GitHub
parent 5e586a6b39
commit d2bb53702a
18 changed files with 150 additions and 138 deletions

View File

@@ -34,7 +34,8 @@
*/
void GcodeSuite::M200() {
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
if (parser.seen('D')) {
// setting any extruder filament size disables volumetric on the assumption that
@@ -55,11 +56,12 @@
*/
void GcodeSuite::M201() {
GET_TARGET_EXTRUDER();
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
LOOP_XYZE(i) {
if (parser.seen(axis_codes[i])) {
const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
planner.settings.max_acceleration_mm_per_s2[a] = parser.value_axis_units((AxisEnum)a);
}
}
@@ -74,11 +76,12 @@ void GcodeSuite::M201() {
*/
void GcodeSuite::M203() {
GET_TARGET_EXTRUDER();
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
LOOP_XYZE(i)
if (parser.seen(axis_codes[i])) {
const uint8_t a = i + (i == E_AXIS ? TARGET_EXTRUDER : 0);
const uint8_t a = (i == E_AXIS ? E_AXIS_N(target_extruder) : i);
planner.settings.max_feedrate_mm_s[a] = parser.value_axis_units((AxisEnum)a);
}
}

View File

@@ -40,7 +40,9 @@
* Z<zoffset>
*/
void GcodeSuite::M218() {
if (get_target_extruder_from_command() || target_extruder == 0) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
if (parser.seenval('X')) hotend_offset[X_AXIS][target_extruder] = parser.value_linear_units();
if (parser.seenval('Y')) hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units();

View File

@@ -27,7 +27,10 @@
* M221: Set extrusion percentage (M221 T0 S95)
*/
void GcodeSuite::M221() {
if (get_target_extruder_from_command()) return;
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);

View File

@@ -31,21 +31,22 @@
*/
void GcodeSuite::M92() {
GET_TARGET_EXTRUDER();
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
LOOP_XYZE(i) {
if (parser.seen(axis_codes[i])) {
if (i == E_AXIS) {
const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS + TARGET_EXTRUDER));
const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder)));
if (value < 20) {
float factor = planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] / value; // increase e constants if M92 E14 is given for netfab.
float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab.
#if HAS_CLASSIC_JERK && (DISABLED(JUNCTION_DEVIATION) || DISABLED(LIN_ADVANCE))
planner.max_jerk[E_AXIS] *= factor;
#endif
planner.settings.max_feedrate_mm_s[E_AXIS + TARGET_EXTRUDER] *= factor;
planner.max_acceleration_steps_per_s2[E_AXIS + TARGET_EXTRUDER] *= factor;
planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor;
planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor;
}
planner.settings.axis_steps_per_mm[E_AXIS + TARGET_EXTRUDER] = value;
planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value;
}
else {
planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);

View File

@@ -33,27 +33,27 @@
* F[units/min] Set the movement feedrate
* S1 Don't move the tool in XY after change
*/
void GcodeSuite::T(const uint8_t tmp_extruder) {
void GcodeSuite::T(const uint8_t tool_index) {
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR(">>> T(", tmp_extruder);
SERIAL_ECHOPAIR(">>> T(", tool_index);
SERIAL_CHAR(')');
SERIAL_EOL();
DEBUG_POS("BEFORE", current_position);
}
#endif
#if HOTENDS == 1 || (ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1)
#if EXTRUDERS < 2
tool_change(tmp_extruder);
tool_change(tool_index);
#elif HOTENDS > 1
#else
tool_change(
tmp_extruder,
tool_index,
MMM_TO_MMS(parser.linearval('F')),
(tmp_extruder == active_extruder) || parser.boolval('S')
(tool_index == active_extruder) || parser.boolval('S')
);
#endif

View File

@@ -54,7 +54,8 @@
void GcodeSuite::M600() {
point_t park_point = NOZZLE_PARK_POINT;
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
#if ENABLED(DUAL_X_CARRIAGE)
int8_t DXC_ext = target_extruder;

View File

@@ -43,7 +43,8 @@
*/
void GcodeSuite::M603() {
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
// Unload length
if (parser.seen('U')) {

View File

@@ -55,7 +55,9 @@ void GcodeSuite::M701() {
if (axis_unhomed_error()) park_point.z = 0;
#endif
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
// Z axis lift
if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
@@ -121,7 +123,8 @@ void GcodeSuite::M702() {
if (axis_unhomed_error()) park_point.z = 0;
#endif
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
// Z axis lift
if (parser.seenval('Z')) park_point.z = parser.linearval('Z');
@@ -154,8 +157,8 @@ void GcodeSuite::M702() {
#endif
{
// Unload length
const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
fc_settings[target_extruder].unload_length);
const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
: fc_settings[target_extruder].unload_length);
unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
}

View File

@@ -73,7 +73,8 @@ void GcodeSuite::M906() {
#endif
break;
case E_AXIS: {
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
switch (target_extruder) {
#if AXIS_IS_TMC(E0)
case 0: TMC_SET_CURRENT(E0); break;

View File

@@ -232,7 +232,8 @@
#endif
break;
case E_AXIS: {
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
switch (target_extruder) {
#if AXIS_HAS_STEALTHCHOP(E0)
case 0: TMC_SET_PWMTHRS_E(0); break;

View File

@@ -38,7 +38,6 @@ GcodeSuite gcode;
#include "../Marlin.h" // for idle() and suspend_auto_report
uint8_t GcodeSuite::target_extruder;
millis_t GcodeSuite::previous_move_ms;
bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
@@ -58,11 +57,10 @@ bool GcodeSuite::axis_relative_modes[] = AXIS_RELATIVE_MODES;
#endif
/**
* Set target_extruder from the T parameter or the active_extruder
*
* Returns TRUE if the target is invalid
* Get the target extruder from the T parameter or the active_extruder
* Return -1 if the T parameter is out of range
*/
bool GcodeSuite::get_target_extruder_from_command() {
int8_t GcodeSuite::get_target_extruder_from_command() {
if (parser.seenval('T')) {
const int8_t e = parser.value_byte();
if (e >= EXTRUDERS) {
@@ -70,14 +68,11 @@ bool GcodeSuite::get_target_extruder_from_command() {
SERIAL_CHAR('M');
SERIAL_ECHO(parser.codenum);
SERIAL_ECHOLNPAIR(" " MSG_INVALID_EXTRUDER " ", e);
return true;
return -1;
}
target_extruder = e;
return e;
}
else
target_extruder = active_extruder;
return false;
return active_extruder;
}
/**
@@ -539,7 +534,9 @@ void GcodeSuite::process_parsed_command(
case 302: M302(); break; // M302: Allow cold extrudes (set the minimum extrude temperature)
#endif
case 303: M303(); break; // M303: PID autotune
#if HAS_PID_HEATING
case 303: M303(); break; // M303: PID autotune
#endif
#if ENABLED(MORGAN_SCARA)
case 360: if (M360()) return; break; // M360: SCARA Theta pos1

View File

@@ -267,8 +267,6 @@ public:
GcodeSuite() {}
static uint8_t target_extruder;
static bool axis_relative_modes[];
#if ENABLED(CNC_WORKSPACE_PLANES)
@@ -290,8 +288,9 @@ public:
static millis_t previous_move_ms;
FORCE_INLINE static void reset_stepper_timeout() { previous_move_ms = millis(); }
static bool get_target_extruder_from_command();
static int8_t get_target_extruder_from_command();
static void get_destination_from_command();
static void process_parsed_command(
#if USE_EXECUTE_COMMANDS_IMMEDIATE
const bool no_ok = false
@@ -306,17 +305,6 @@ public:
FORCE_INLINE static void home_all_axes() { G28(true); }
/**
* Multi-stepper support for M92, M201, M203
*/
#if ENABLED(DISTINCT_E_FACTORS)
#define GET_TARGET_EXTRUDER() if (gcode.get_target_extruder_from_command()) return
#define TARGET_EXTRUDER gcode.target_extruder
#else
#define GET_TARGET_EXTRUDER() NOOP
#define TARGET_EXTRUDER 0
#endif
#if ENABLED(HOST_KEEPALIVE_FEATURE)
/**
* States for managing Marlin and host communication
@@ -669,7 +657,9 @@ private:
static void M302();
#endif
static void M303();
#if HAS_PID_HEATING
static void M303();
#endif
#if ENABLED(PIDTEMPBED)
static void M304();
@@ -832,7 +822,7 @@ private:
static void M999();
static void T(const uint8_t tmp_extruder);
static void T(const uint8_t tool_index);
};

View File

@@ -39,10 +39,15 @@
* M104: Set hot end temperature
*/
void GcodeSuite::M104() {
if (get_target_extruder_from_command()) return;
if (DEBUGGING(DRYRUN)) return;
const uint8_t e = target_extruder;
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
constexpr int8_t e = 0;
#else
const int8_t e = get_target_extruder_from_command();
if (e < 0) return;
#endif
if (parser.seenval('S')) {
const int16_t temp = parser.value_celsius();
@@ -82,9 +87,15 @@ void GcodeSuite::M104() {
*/
void GcodeSuite::M109() {
if (get_target_extruder_from_command()) return;
if (DEBUGGING(DRYRUN)) return;
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
constexpr int8_t target_extruder = 0;
#else
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
#endif
const bool no_wait_for_cooling = parser.seenval('S'),
set_temp = no_wait_for_cooling || parser.seenval('R');
if (set_temp) {

View File

@@ -31,7 +31,9 @@
* M105: Read hot end and bed temperature
*/
void GcodeSuite::M105() {
if (get_target_extruder_from_command()) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
#if NUM_SERIAL > 1
const int16_t port = command_queue_port[cmd_queue_index_r];
@@ -39,9 +41,9 @@ void GcodeSuite::M105() {
#if HAS_TEMP_SENSOR
SERIAL_PROTOCOLPGM_P(port, MSG_OK);
thermalManager.print_heaterstates(
thermalManager.print_heater_states(target_extruder
#if NUM_SERIAL > 1
port
, port
#endif
);
#else // !HAS_TEMP_SENSOR

View File

@@ -20,6 +20,10 @@
*
*/
#include "../../inc/MarlinConfig.h"
#if HAS_PID_HEATING
#include "../gcode.h"
#include "../../module/temperature.h"
@@ -32,26 +36,36 @@
* U<bool> with a non-zero value will apply the result to current settings
*/
void GcodeSuite::M303() {
#if HAS_PID_HEATING
const int e = parser.intval('E'), c = parser.intval('C', 5);
const bool u = parser.boolval('U');
int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150);
const int8_t e = parser.byteval('E');
if (WITHIN(e, 0, HOTENDS - 1))
target_extruder = e;
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(NOT_BUSY);
if (!WITHIN(e, 0
#if ENABLED(PIDTEMPBED)
-1
#endif
thermalManager.PID_autotune(temp, e, c, u);
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(IN_HANDLER);
,
#if ENABLED(PIDTEMP)
HOTENDS
#endif
#else
SERIAL_ERROR_START();
SERIAL_ERRORLNPGM(MSG_ERR_M303_DISABLED);
-1
)) {
SERIAL_ECHOLNPGM(MSG_PID_BAD_EXTRUDER_NUM);
return;
}
const int c = parser.intval('C', 5);
const bool u = parser.boolval('U');
const int16_t temp = parser.celsiusval('S', e < 0 ? 70 : 150);
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(NOT_BUSY);
#endif
thermalManager.PID_autotune(temp, e, c, u);
#if DISABLED(BUSY_WHILE_HEATING)
KEEPALIVE_STATE(IN_HANDLER);
#endif
}
#endif // HAS_PID_HEATING