MAGNETIC_PARKING_EXTRUDER (#12351)

This commit is contained in:
Rolf Werum
2019-02-06 13:30:53 +01:00
committed by Scott Lahteine
parent 1bd9a63049
commit 524c6c10bf
98 changed files with 3641 additions and 546 deletions

View File

@ -2078,6 +2078,10 @@ void MarlinSettings::reset(PORTARG_SOLO) {
toolchange_settings.z_raise = TOOLCHANGE_ZRAISE;
#endif
#if ENABLED(MAGNETIC_PARKING_EXTRUDER)
mpe_settings_init();
#endif
//
// Global Leveling
//

View File

@ -42,7 +42,7 @@
#endif
#endif
#if ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0
#if ENABLED(MAGNETIC_PARKING_EXTRUDER) || (ENABLED(PARKING_EXTRUDER) && PARKING_EXTRUDER_SOLENOIDS_DELAY > 0)
#include "../gcode/gcode.h" // for dwell()
#endif
@ -126,18 +126,143 @@
#endif // SWITCHING_NOZZLE
#if ENABLED(PARKING_EXTRUDER)
#if ENABLED(MAGNETIC_PARKING_EXTRUDER)
void pe_magnet_init() {
float parkingposx[2] , // M951 R L
parkinggrabdistance , // M951 I
parkingslowspeed, // M951 J
parkinghighspeed , // M951 H
parkingtraveldistance, // M951 D
compensationmultiplier;
inline void magnetic_parking_extruder_tool_change(const uint8_t tmp_extruder) {
const float oldx = current_position[X_AXIS],
grabpos = mpe_settings.parking_xpos[tmp_extruder] + (tmp_extruder ? mpe_settings.grab_distance : -mpe_settings.grab_distance),
offsetcompensation =
#if HAS_HOTEND_OFFSET
hotend_offset[X_AXIS][active_extruder] * mpe_settings.compensation_factor
#else
0
#endif
;
if (axis_unhomed_error(true, false, false)) return;
/**
* Z Lift and Nozzle Offset shift ar defined in caller method to work equal with any Multi Hotend realization
*
* Steps:
* 1. Move high speed to park position of new extruder
* 2. Move to couple position of new extruder (this also discouple the old extruder)
* 3. Move to park position of new extruder
* 4. Move high speed to approach park position of old extruder
* 5. Move to park position of old extruder
* 6. Move to starting position
*/
// STEP 1
current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("(1) Move extruder ", int(tmp_extruder));
DEBUG_POS(" to new extruder ParkPos", current_position);
}
#endif
planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
planner.synchronize();
// STEP 2
current_position[X_AXIS] = grabpos + offsetcompensation;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("(2) Couple extruder ", int(tmp_extruder));
DEBUG_POS(" to new extruder GrabPos", current_position);
}
#endif
planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
planner.synchronize();
// Delay before moving tool, to allow magnetic coupling
gcode.dwell(150);
// STEP 3
current_position[X_AXIS] = mpe_settings.parking_xpos[tmp_extruder] + offsetcompensation;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("(3) Move extruder ", int(tmp_extruder));
DEBUG_POS(" back to new extruder ParkPos", current_position);
}
#endif
planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
planner.synchronize();
// STEP 4
current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + (active_extruder == 0 ? MPE_TRAVEL_DISTANCE : -MPE_TRAVEL_DISTANCE) + offsetcompensation;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("(4) Move extruder ", int(tmp_extruder));
DEBUG_POS(" close to old extruder ParkPos", current_position);
}
#endif
planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
planner.synchronize();
// STEP 5
current_position[X_AXIS] = mpe_settings.parking_xpos[active_extruder] + offsetcompensation;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("(5) Park extruder ", int(tmp_extruder));
DEBUG_POS(" at old extruder ParkPos", current_position);
}
#endif
planner.buffer_line(current_position, mpe_settings.slow_feedrate, tmp_extruder);
planner.synchronize();
// STEP 6
current_position[X_AXIS] = oldx;
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) {
SERIAL_ECHOPAIR("(6) Move extruder ", int(tmp_extruder));
DEBUG_POS(" to starting position", current_position);
}
#endif
planner.buffer_line(current_position, mpe_settings.fast_feedrate, tmp_extruder);
planner.synchronize();
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("Autopark done.");
#endif
}
#elif ENABLED(PARKING_EXTRUDER)
void pe_solenoid_init() {
for (uint8_t n = 0; n <= 1; ++n)
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_magnet(n);
pe_activate_solenoid(n);
#else
pe_deactivate_magnet(n);
pe_deactivate_solenoid(n);
#endif
}
void pe_set_magnet(const uint8_t extruder_num, const uint8_t state) {
void pe_set_solenoid(const uint8_t extruder_num, const uint8_t state) {
switch (extruder_num) {
case 1: OUT_WRITE(SOL1_PIN, state); break;
default: OUT_WRITE(SOL0_PIN, state); break;
@ -206,7 +331,7 @@
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPGM("(3) Disengage magnet ");
#endif
pe_deactivate_magnet(active_extruder);
pe_deactivate_solenoid(active_extruder);
// STEP 4
@ -229,10 +354,10 @@
#endif
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_magnet(active_extruder); //just save power for inverted magnets
pe_activate_solenoid(active_extruder); //just save power for inverted magnets
#endif
pe_activate_magnet(tmp_extruder);
pe_activate_solenoid(tmp_extruder);
// STEP 6
@ -266,9 +391,9 @@
}
else { // nomove == true
// Only engage magnetic field for new extruder
pe_activate_magnet(tmp_extruder);
pe_activate_solenoid(tmp_extruder);
#if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT)
pe_activate_magnet(active_extruder); // Just save power for inverted magnets
pe_activate_solenoid(active_extruder); // Just save power for inverted magnets
#endif
}
@ -661,6 +786,8 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
dualx_tool_change(tmp_extruder, no_move);
#elif ENABLED(PARKING_EXTRUDER) // Dual Parking extruder
parking_extruder_tool_change(tmp_extruder, no_move);
#elif ENABLED(MAGNETIC_PARKING_EXTRUDER) // Magnetic Parking extruder
magnetic_parking_extruder_tool_change(tmp_extruder);
#elif ENABLED(SWITCHING_TOOLHEAD) // Switching Toolhead
switching_toolhead_tool_change(tmp_extruder, fr_mm_s, no_move);
#elif ENABLED(SWITCHING_NOZZLE) && !SWITCHING_NOZZLE_TWO_SERVOS

View File

@ -61,14 +61,29 @@
#define PE_MAGNET_ON_STATE PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE
#endif
void pe_set_magnet(const uint8_t extruder_num, const uint8_t state);
void pe_set_solenoid(const uint8_t extruder_num, const uint8_t state);
inline void pe_activate_magnet(const uint8_t extruder_num) { pe_set_magnet(extruder_num, PE_MAGNET_ON_STATE); }
inline void pe_deactivate_magnet(const uint8_t extruder_num) { pe_set_magnet(extruder_num, !PE_MAGNET_ON_STATE); }
inline void pe_activate_solenoid(const uint8_t extruder_num) { pe_set_solenoid(extruder_num, PE_MAGNET_ON_STATE); }
inline void pe_deactivate_solenoid(const uint8_t extruder_num) { pe_set_solenoid(extruder_num, !PE_MAGNET_ON_STATE); }
void pe_magnet_init();
void pe_solenoid_init();
#endif // PARKING_EXTRUDER
#elif ENABLED(MAGNETIC_PARKING_EXTRUDER)
typedef struct MPESettings {
float parking_xpos[2], // M951 L R
grab_distance, // M951 I
slow_feedrate, // M951 J
fast_feedrate, // M951 H
travel_distance, // M951 D
compensation_factor; // M951 C
} mpe_settings_t;
extern mpe_settings_t mpe_settings;
void mpe_settings_init();
#endif
#if ENABLED(SINGLENOZZLE)
extern uint16_t singlenozzle_temp[EXTRUDERS];