Browse Source

Improved solution to tool-change bug

pull/1/head
Scott Lahteine 8 years ago
parent
commit
672e45652e
  1. 30
      Marlin/Marlin_main.cpp

30
Marlin/Marlin_main.cpp

@ -7883,6 +7883,7 @@ inline void gcode_M999() {
inline void move_extruder_servo(uint8_t e) { inline void move_extruder_servo(uint8_t e) {
const int angles[2] = SWITCHING_EXTRUDER_SERVO_ANGLES; const int angles[2] = SWITCHING_EXTRUDER_SERVO_ANGLES;
MOVE_SERVO(SWITCHING_EXTRUDER_SERVO_NR, angles[e]); MOVE_SERVO(SWITCHING_EXTRUDER_SERVO_NR, angles[e]);
delay(500);
} }
#endif #endif
@ -8029,25 +8030,15 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#if ENABLED(SWITCHING_EXTRUDER) #if ENABLED(SWITCHING_EXTRUDER)
// <0 if the new nozzle is higher, >0 if lower. A bigger raise when lower. // <0 if the new nozzle is higher, >0 if lower. A bigger raise when lower.
float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder], const float z_diff = hotend_offset[Z_AXIS][active_extruder] - hotend_offset[Z_AXIS][tmp_extruder],
z_raise = 0.3 + (z_diff > 0.0 ? z_diff : 0.0); z_raise = 0.3 + (z_diff > 0.0 ? z_diff : 0.0);
// Always raise by some amount (destination copied from current_position earlier) // Always raise by some amount (destination copied from current_position earlier)
float save_Z = destination[Z_AXIS]; // save Z for later on current_position[Z_AXIS] += z_raise;
destination[Z_AXIS] += z_raise; planner.buffer_line_kinematic(current_position, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
planner.buffer_line_kinematic(destination, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
stepper.synchronize(); stepper.synchronize();
move_extruder_servo(active_extruder); move_extruder_servo(active_extruder);
delay(500);
// Move back down, if needed
if (z_raise != z_diff) {
destination[Z_AXIS] = current_position[Z_AXIS] + z_diff;
planner.buffer_line_kinematic(destination, planner.max_feedrate_mm_s[Z_AXIS], active_extruder);
stepper.synchronize();
}
destination[Z_AXIS] = save_Z; // restore original Z position so the 'Move to the "old position"' is correct
#endif #endif
/** /**
@ -8098,12 +8089,12 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
#endif #endif
// Adjustments to the current position // Adjustments to the current position
float xydiff[2] = { offset_vec.x, offset_vec.y }; const float xydiff[2] = { offset_vec.x, offset_vec.y };
current_position[Z_AXIS] += offset_vec.z; current_position[Z_AXIS] += offset_vec.z;
#else // !ABL_PLANAR #else // !ABL_PLANAR
float xydiff[2] = { const float xydiff[2] = {
hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder], hotend_offset[X_AXIS][tmp_extruder] - hotend_offset[X_AXIS][active_extruder],
hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder] hotend_offset[Y_AXIS][tmp_extruder] - hotend_offset[Y_AXIS][active_extruder]
}; };
@ -8170,6 +8161,15 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
prepare_move_to_destination(); prepare_move_to_destination();
} }
#if ENABLED(SWITCHING_EXTRUDER)
// Move back down, if needed. (Including when the new tool is higher.)
if (z_raise != z_diff) {
destination[Z_AXIS] += z_diff;
feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];
prepare_move_to_destination();
}
#endif
} // (tmp_extruder != active_extruder) } // (tmp_extruder != active_extruder)
stepper.synchronize(); stepper.synchronize();

Loading…
Cancel
Save