Merge pull request #7802 from thinkyhead/bf2_fwretract_fixes

Fix G10/G11 with synchronize
This commit is contained in:
Scott Lahteine 2017-09-30 17:50:38 -05:00 committed by GitHub
commit 26d4c01660
6 changed files with 45 additions and 20 deletions

View File

@ -30,13 +30,22 @@
#include "fwretract.h" #include "fwretract.h"
FWRetract fwretract; // Single instance FWRetract fwretract; // Single instance - this calls the constructor
#include "../module/motion.h" #include "../module/motion.h"
#include "../module/planner.h" #include "../module/planner.h"
#include "../module/stepper.h"
// private:
#if EXTRUDERS > 1
bool FWRetract::retracted_swap[EXTRUDERS]; // Which extruders are swap-retracted
#endif
// public:
bool FWRetract::autoretract_enabled, // M209 S - Autoretract switch bool FWRetract::autoretract_enabled, // M209 S - Autoretract switch
FWRetract::retracted[EXTRUDERS] = { false }; // Which extruders are currently retracted FWRetract::retracted[EXTRUDERS]; // Which extruders are currently retracted
float FWRetract::retract_length, // M207 S - G10 Retract length float FWRetract::retract_length, // M207 S - G10 Retract length
FWRetract::retract_feedrate_mm_s, // M207 F - G10 Retract feedrate FWRetract::retract_feedrate_mm_s, // M207 F - G10 Retract feedrate
FWRetract::retract_zlift, // M207 Z - G10 Retract hop size FWRetract::retract_zlift, // M207 Z - G10 Retract hop size
@ -45,9 +54,6 @@ float FWRetract::retract_length, // M207 S - G10 Retract len
FWRetract::swap_retract_length, // M207 W - G10 Swap Retract length FWRetract::swap_retract_length, // M207 W - G10 Swap Retract length
FWRetract::swap_retract_recover_length, // M208 W - G11 Swap Recover length FWRetract::swap_retract_recover_length, // M208 W - G11 Swap Recover length
FWRetract::swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate FWRetract::swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
#if EXTRUDERS > 1
bool FWRetract::retracted_swap[EXTRUDERS] = { false }; // Which extruders are swap-retracted
#endif
void FWRetract::reset() { void FWRetract::reset() {
autoretract_enabled = false; autoretract_enabled = false;
@ -59,6 +65,13 @@ void FWRetract::reset() {
swap_retract_length = RETRACT_LENGTH_SWAP; swap_retract_length = RETRACT_LENGTH_SWAP;
swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP; swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP; swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
for (uint8_t i = 0; i < EXTRUDERS; ++i) {
retracted[i] = false;
#if EXTRUDERS > 1
retracted_swap[i] = false;
#endif
}
} }
/** /**
@ -87,10 +100,11 @@ void FWRetract::retract(const bool retracting
// Simply never allow two retracts or recovers in a row // Simply never allow two retracts or recovers in a row
if (retracted[active_extruder] == retracting) return; if (retracted[active_extruder] == retracting) return;
#if EXTRUDERS < 2 #if EXTRUDERS > 1
bool swapping = false; if (!retracting) swapping = retracted_swap[active_extruder];
#else
const bool swapping = false;
#endif #endif
if (!retracting) swapping = retracted_swap[active_extruder];
/* // debugging /* // debugging
SERIAL_ECHOLNPAIR("retracting ", retracting); SERIAL_ECHOLNPAIR("retracting ", retracting);
@ -117,6 +131,8 @@ void FWRetract::retract(const bool retracting
// The current position will be the destination for E and Z moves // The current position will be the destination for E and Z moves
set_destination_to_current(); set_destination_to_current();
stepper.synchronize(); // Wait for buffered moves to complete
if (retracting) { if (retracting) {
// Remember the Z height since G-code may include its own Z-hop // Remember the Z height since G-code may include its own Z-hop
// For best results turn off Z hop if G-code already includes it // For best results turn off Z hop if G-code already includes it

View File

@ -30,6 +30,11 @@
#include "../inc/MarlinConfig.h" #include "../inc/MarlinConfig.h"
class FWRetract { class FWRetract {
private:
#if EXTRUDERS > 1
static bool retracted_swap[EXTRUDERS]; // Which extruders are swap-retracted
#endif
public: public:
static bool autoretract_enabled, // M209 S - Autoretract switch static bool autoretract_enabled, // M209 S - Autoretract switch
retracted[EXTRUDERS]; // Which extruders are currently retracted retracted[EXTRUDERS]; // Which extruders are currently retracted
@ -42,22 +47,24 @@ public:
swap_retract_recover_length, // M208 W - G11 Swap Recover length swap_retract_recover_length, // M208 W - G11 Swap Recover length
swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
#if EXTRUDERS > 1 FWRetract() { reset(); }
static bool retracted_swap[EXTRUDERS]; // Which extruders are swap-retracted
#else
static bool constexpr retracted_swap[1] = { false };
#endif
FWRetract() {}
static void reset(); static void reset();
static void refresh_autoretract() {
for (uint8_t i = 0; i < EXTRUDERS; i++) retracted[i] = false;
}
static void enable_autoretract(const bool enable) {
autoretract_enabled = enable;
refresh_autoretract();
}
static void retract(const bool retracting static void retract(const bool retracting
#if EXTRUDERS > 1 #if EXTRUDERS > 1
, bool swapping = false , bool swapping = false
#endif #endif
); );
}; };
extern FWRetract fwretract; extern FWRetract fwretract;

View File

@ -34,7 +34,6 @@
void GcodeSuite::G10() { void GcodeSuite::G10() {
#if EXTRUDERS > 1 #if EXTRUDERS > 1
const bool rs = parser.boolval('S'); const bool rs = parser.boolval('S');
fwretract.retracted_swap[active_extruder] = rs; // Use 'S' for swap, default to false
#endif #endif
fwretract.retract(true fwretract.retract(true
#if EXTRUDERS > 1 #if EXTRUDERS > 1

View File

@ -65,8 +65,7 @@ void GcodeSuite::M208() {
void GcodeSuite::M209() { void GcodeSuite::M209() {
if (MIN_AUTORETRACT <= MAX_AUTORETRACT) { if (MIN_AUTORETRACT <= MAX_AUTORETRACT) {
if (parser.seen('S')) { if (parser.seen('S')) {
fwretract.autoretract_enabled = parser.value_bool(); fwretract.enable_autoretract(parser.value_bool());
for (uint8_t i = 0; i < EXTRUDERS; i++) fwretract.retracted[i] = false;
} }
} }
} }

View File

@ -3557,7 +3557,7 @@ void kill_screen(const char* lcd_msg) {
void lcd_control_retract_menu() { void lcd_control_retract_menu() {
START_MENU(); START_MENU();
MENU_BACK(MSG_CONTROL); MENU_BACK(MSG_CONTROL);
MENU_ITEM_EDIT(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled); MENU_ITEM_EDIT_CALLBACK(bool, MSG_AUTORETRACT, &fwretract.autoretract_enabled, fwretract.refresh_autoretract);
MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100); MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT, &fwretract.retract_length, 0, 100);
#if EXTRUDERS > 1 #if EXTRUDERS > 1
MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100); MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_SWAP, &fwretract.swap_retract_length, 0, 100);

View File

@ -247,6 +247,10 @@ void MarlinSettings::postprocess() {
#if HAS_MOTOR_CURRENT_PWM #if HAS_MOTOR_CURRENT_PWM
stepper.refresh_motor_power(); stepper.refresh_motor_power();
#endif #endif
#if ENABLED(FWRETRACT)
fwretract.refresh_autoretract();
#endif
} }
#if ENABLED(EEPROM_SETTINGS) #if ENABLED(EEPROM_SETTINGS)