Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for dualx sudden layer shift (#19151) #19756

Merged
merged 4 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions Marlin/src/feature/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
const bool saved_ext_dup_mode = extruder_duplication_enabled;
active_extruder = DXC_ext;
extruder_duplication_enabled = false;
set_duplication_enabled(false, DXC_ext);
#endif

// Slow Load filament
Expand All @@ -243,9 +242,7 @@ bool load_filament(const float &slow_load_length/*=0*/, const float &fast_load_l
}

#if ENABLED(DUAL_X_CARRIAGE) // Tie the two extruders movement back together.
active_extruder = saved_ext;
extruder_duplication_enabled = saved_ext_dup_mode;
stepper.set_directions();
set_duplication_enabled(saved_ext_dup_mode, saved_ext);
#endif

#if ENABLED(ADVANCED_PAUSE_CONTINUOUS_PURGE)
Expand Down Expand Up @@ -437,17 +434,14 @@ bool pause_print(const float &retract, const xyz_pos_t &park_point, const float
#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
const bool saved_ext_dup_mode = extruder_duplication_enabled;
active_extruder = DXC_ext;
extruder_duplication_enabled = false;
set_duplication_enabled(false, DXC_ext);
#endif

if (unload_length) // Unload the filament
unload_filament(unload_length, show_lcd, PAUSE_MODE_CHANGE_FILAMENT);

#if ENABLED(DUAL_X_CARRIAGE)
active_extruder = saved_ext;
extruder_duplication_enabled = saved_ext_dup_mode;
stepper.set_directions();
set_duplication_enabled(saved_ext_dup_mode, saved_ext);
#endif

return true;
Expand Down Expand Up @@ -493,8 +487,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
const bool saved_ext_dup_mode = extruder_duplication_enabled;
active_extruder = DXC_ext;
extruder_duplication_enabled = false;
set_duplication_enabled(false, DXC_ext);
#endif

// Wait for filament insert by user and press button
Expand Down Expand Up @@ -548,9 +541,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
idle_no_sleep();
}
#if ENABLED(DUAL_X_CARRIAGE)
active_extruder = saved_ext;
extruder_duplication_enabled = saved_ext_dup_mode;
stepper.set_directions();
set_duplication_enabled(saved_ext_dup_mode, saved_ext);
#endif
}

Expand Down
5 changes: 2 additions & 3 deletions Marlin/src/gcode/bedlevel/G35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ void GcodeSuite::G35() {
tool_change(0, true);
#endif

#if HAS_DUPLICATION_MODE
extruder_duplication_enabled = false;
#endif
// Disable duplication mode on homing
TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));

// Home all before this procedure
home_all_axes();
Expand Down
7 changes: 3 additions & 4 deletions Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void GcodeSuite::G28() {
tool_change(0, true);
#endif

TERN_(HAS_DUPLICATION_MODE, extruder_duplication_enabled = false);
TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));

remember_feedrate_scaling_off();

Expand Down Expand Up @@ -411,9 +411,8 @@ void GcodeSuite::G28() {
raised_parked_position = current_position;
delayed_move_time = 0;
active_extruder_parked = true;
extruder_duplication_enabled = IDEX_saved_duplication_state;
dual_x_carriage_mode = IDEX_saved_mode;
stepper.set_directions();
dual_x_carriage_mode = IDEX_saved_mode;
set_duplication_enabled(IDEX_saved_duplication_state);

TERN_(IMPROVE_HOMING_RELIABILITY, end_slow_homing(slow_homing));
}
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ void GcodeSuite::G34() {
tool_change(0, true);
#endif

TERN_(HAS_DUPLICATION_MODE, extruder_duplication_enabled = false);
TERN_(HAS_DUPLICATION_MODE, set_duplication_enabled(false));

// In BLTOUCH HS mode, the probe travels in a deployed state.
// Users of G34 might have a badly misaligned bed, so raise Z by the
Expand Down
10 changes: 4 additions & 6 deletions Marlin/src/gcode/control/M605.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
const DualXMode previous_mode = dual_x_carriage_mode;

dual_x_carriage_mode = (DualXMode)parser.value_byte();
mirrored_duplication_mode = false;
idex_set_mirrored_mode(false);

if (dual_x_carriage_mode == DXC_MIRRORED_MODE) {
if (previous_mode != DXC_DUPLICATION_MODE) {
Expand All @@ -77,8 +77,7 @@
dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
return;
}
mirrored_duplication_mode = true;
stepper.set_directions();
idex_set_mirrored_mode(true);
float x_jog = current_position.x - .1;
for (uint8_t i = 2; --i;) {
planner.buffer_line(x_jog, current_position.y, current_position.z, current_position.e, feedrate_mm_s, 0);
Expand All @@ -103,8 +102,7 @@
break;
}
active_extruder_parked = false;
extruder_duplication_enabled = false;
stepper.set_directions();
set_duplication_enabled(false);
delayed_move_time = 0;
}
else if (!parser.seen('W')) // if no S or W parameter, the DXC mode gets reset to the user's default
Expand Down Expand Up @@ -166,7 +164,7 @@
if (parser.seenval('P')) duplication_e_mask = parser.value_int(); // Set the mask directly
else if (parser.seenval('E')) duplication_e_mask = pow(2, parser.value_int() + 1) - 1; // Set the mask by E index
ena = (2 == parser.intval('S', extruder_duplication_enabled ? 2 : 0));
extruder_duplication_enabled = ena && (duplication_e_mask >= 3);
set_duplication_enabled(ena && (duplication_e_mask >= 3));
}
SERIAL_ECHO_START();
SERIAL_ECHOPGM(STR_DUPLICATION_MODE);
Expand Down
72 changes: 48 additions & 24 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,7 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
#endif // !UBL_SEGMENTED

#if HAS_DUPLICATION_MODE
bool extruder_duplication_enabled,
mirrored_duplication_mode;
bool extruder_duplication_enabled;
#if ENABLED(MULTI_NOZZLE_DUPLICATION)
uint8_t duplication_e_mask; // = 0
#endif
Expand All @@ -942,13 +941,13 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
#if ENABLED(DUAL_X_CARRIAGE)

DualXMode dual_x_carriage_mode = DEFAULT_DUAL_X_CARRIAGE_MODE;
float inactive_extruder_x_pos = X2_MAX_POS, // used in mode 0 & 1
duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // used in mode 2
xyz_pos_t raised_parked_position; // used in mode 1
bool active_extruder_parked = false; // used in mode 1 & 2
millis_t delayed_move_time = 0; // used in mode 1
int16_t duplicate_extruder_temp_offset = 0; // used in mode 2

float inactive_extruder_x_pos = X2_MAX_POS, // Used in mode 0 & 1
duplicate_extruder_x_offset = DEFAULT_DUPLICATION_X_OFFSET; // Used in mode 2
xyz_pos_t raised_parked_position; // Used in mode 1
bool active_extruder_parked = false; // Used in mode 1 & 2
millis_t delayed_move_time = 0; // Used in mode 1
int16_t duplicate_extruder_temp_offset = 0; // Used in mode 2
bool idex_mirrored_mode = false; // Used in mode 3
float x_home_pos(const uint8_t extruder) {
if (extruder == 0)
return base_home_pos(X_AXIS);
Expand All @@ -962,6 +961,17 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
return hotend_offset[1].x > 0 ? hotend_offset[1].x : X2_HOME_POS;
}

void idex_set_mirrored_mode(const bool mirr) {
idex_mirrored_mode = mirr;
stepper.set_directions();
}

void set_duplication_enabled(const bool dupe, const int8_t tool_index/*=-1*/) {
extruder_duplication_enabled = dupe;
if (tool_index >= 0) active_extruder = tool_index;
stepper.set_directions();
}

/**
* Prepare a linear move in a dual X axis setup
*
Expand All @@ -984,23 +994,35 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
return true;
}
}
// unpark extruder: 1) raise, 2) move into starting XY position, 3) lower

#define CUR_X current_position.x
#define CUR_Y current_position.y
#define CUR_Z current_position.z
#define CUR_E current_position.e
#define RAISED_X raised_parked_position.x
#define RAISED_Y raised_parked_position.y
#define RAISED_Z raised_parked_position.z

if ( planner.buffer_line(RAISED_X, RAISED_Y, RAISED_Z, CUR_E, planner.settings.max_feedrate_mm_s[Z_AXIS], active_extruder))
if (planner.buffer_line( CUR_X, CUR_Y, RAISED_Z, CUR_E, PLANNER_XY_FEEDRATE(), active_extruder))
line_to_current_position(planner.settings.max_feedrate_mm_s[Z_AXIS]);
//
// Un-park the active extruder
//
#define CUR_X current_position.x
#define CUR_Y current_position.y
#define CUR_Z current_position.z
#define CUR_E current_position.e
#define RAISED_X raised_parked_position.x
#define RAISED_Y raised_parked_position.y
#define RAISED_Z raised_parked_position.z

const feedRate_t fr_zfast = planner.settings.max_feedrate_mm_s[Z_AXIS];

// 1. Raise
if (planner.buffer_line(RAISED_X, RAISED_Y, RAISED_Z, CUR_E, fr_zfast, active_extruder)) {
// 2. Move to starting XY
if (planner.buffer_line(CUR_X, CUR_Y, RAISED_Z, CUR_E, PLANNER_XY_FEEDRATE(), active_extruder)) {
// 3. Lower
line_to_current_position(fr_zfast);
}
}
planner.synchronize(); // paranoia
stepper.set_directions();

delayed_move_time = 0;
active_extruder_parked = false;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Clear active_extruder_parked");
break;

case DXC_MIRRORED_MODE:
case DXC_DUPLICATION_MODE:
if (active_extruder == 0) {
Expand All @@ -1013,17 +1035,19 @@ FORCE_INLINE void segment_idle(millis_t &next_idle_ms) {
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Set planner X", inactive_extruder_x_pos, " ... Line to X", new_pos.x);
planner.set_position_mm(inactive_extruder_x_pos, current_position.y, current_position.z, current_position.e);
if (!planner.buffer_line(new_pos, planner.settings.max_feedrate_mm_s[X_AXIS], 1)) break;

planner.synchronize();
sync_plan_position();
extruder_duplication_enabled = true;

set_duplication_enabled(true);

active_extruder_parked = false;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Set extruder_duplication_enabled\nClear active_extruder_parked");
}
else if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Active extruder not 0");
break;
}
}
stepper.set_directions();
return false;
}

Expand Down
8 changes: 6 additions & 2 deletions Marlin/src/module/motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ bool homing_needed_error(uint8_t axis_bits=0x07);
* Duplication mode
*/
#if HAS_DUPLICATION_MODE
extern bool extruder_duplication_enabled, // Used in Dual X mode 2
mirrored_duplication_mode; // Used in Dual X mode 3
extern bool extruder_duplication_enabled; // Used in Dual X mode 2
#if ENABLED(MULTI_NOZZLE_DUPLICATION)
extern uint8_t duplication_e_mask;
#endif
Expand All @@ -410,17 +409,22 @@ bool homing_needed_error(uint8_t axis_bits=0x07);
extern bool active_extruder_parked; // Used in mode 1, 2 & 3
extern millis_t delayed_move_time; // Used in mode 1
extern int16_t duplicate_extruder_temp_offset; // Used in mode 2 & 3
extern bool idex_mirrored_mode; // Used in mode 3

FORCE_INLINE bool dxc_is_duplicating() { return dual_x_carriage_mode >= DXC_DUPLICATION_MODE; }

float x_home_pos(const uint8_t extruder);

FORCE_INLINE int x_home_dir(const uint8_t extruder) { return extruder ? X2_HOME_DIR : X_HOME_DIR; }

void set_duplication_enabled(const bool dupe, const int8_t tool_index=-1);
void idex_set_mirrored_mode(const bool mirr);

#else

#if ENABLED(MULTI_NOZZLE_DUPLICATION)
enum DualXMode : char { DXC_DUPLICATION_MODE = 2 };
FORCE_INLINE void set_duplication_enabled(const bool dupe) { extruder_duplication_enabled = dupe; }
#endif

FORCE_INLINE int x_home_dir(const uint8_t) { return home_dir(X_AXIS); }
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ xyze_int8_t Stepper::count_direction{0};
#endif
#elif ENABLED(DUAL_X_CARRIAGE)
#define X_APPLY_DIR(v,ALWAYS) do{ \
if (extruder_duplication_enabled || ALWAYS) { X_DIR_WRITE(v); X2_DIR_WRITE(mirrored_duplication_mode ? !(v) : v); } \
if (extruder_duplication_enabled || ALWAYS) { X_DIR_WRITE(v); X2_DIR_WRITE(idex_mirrored_mode ? !(v) : v); } \
else if (last_moved_extruder) X2_DIR_WRITE(v); else X_DIR_WRITE(v); \
}while(0)
#define X_APPLY_STEP(v,ALWAYS) do{ \
Expand Down Expand Up @@ -2154,6 +2154,7 @@ uint32_t Stepper::block_phase_isr() {
if ( ENABLED(HAS_L64XX) // Always set direction for L64xx (Also enables the chips)
|| current_block->direction_bits != last_direction_bits
|| TERN(MIXING_EXTRUDER, false, stepper_extruder != last_moved_extruder)
|| ENABLED(DUAL_X_CARRIAGE) // For some reason, motion becomes jittery on small circles with dualx machines without this.
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
) {
last_direction_bits = current_block->direction_bits;
#if HAS_MULTI_EXTRUDER
Expand Down