Browse Source

Merge pull request #7802 from thinkyhead/bf2_fwretract_fixes

Fix G10/G11 with synchronize
Scott Lahteine 7 years ago
parent
commit
26d4c01660

+ 24
- 8
Marlin/src/feature/fwretract.cpp View File

@@ -30,13 +30,22 @@
30 30
 
31 31
 #include "fwretract.h"
32 32
 
33
-FWRetract fwretract; // Single instance
33
+FWRetract fwretract; // Single instance - this calls the constructor
34 34
 
35 35
 #include "../module/motion.h"
36 36
 #include "../module/planner.h"
37
+#include "../module/stepper.h"
38
+
39
+// private:
40
+
41
+#if EXTRUDERS > 1
42
+  bool FWRetract::retracted_swap[EXTRUDERS];         // Which extruders are swap-retracted
43
+#endif
44
+
45
+// public:
37 46
 
38 47
 bool FWRetract::autoretract_enabled,                 // M209 S - Autoretract switch
39
-     FWRetract::retracted[EXTRUDERS] = { false };    // Which extruders are currently retracted
48
+     FWRetract::retracted[EXTRUDERS];                // Which extruders are currently retracted
40 49
 float FWRetract::retract_length,                     // M207 S - G10 Retract length
41 50
       FWRetract::retract_feedrate_mm_s,              // M207 F - G10 Retract feedrate
42 51
       FWRetract::retract_zlift,                      // M207 Z - G10 Retract hop size
@@ -45,9 +54,6 @@ float FWRetract::retract_length,                     // M207 S - G10 Retract len
45 54
       FWRetract::swap_retract_length,                // M207 W - G10 Swap Retract length
46 55
       FWRetract::swap_retract_recover_length,        // M208 W - G11 Swap Recover length
47 56
       FWRetract::swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
48
-#if EXTRUDERS > 1
49
-  bool FWRetract::retracted_swap[EXTRUDERS] = { false }; // Which extruders are swap-retracted
50
-#endif
51 57
 
52 58
 void FWRetract::reset() {
53 59
   autoretract_enabled = false;
@@ -59,6 +65,13 @@ void FWRetract::reset() {
59 65
   swap_retract_length = RETRACT_LENGTH_SWAP;
60 66
   swap_retract_recover_length = RETRACT_RECOVER_LENGTH_SWAP;
61 67
   swap_retract_recover_feedrate_mm_s = RETRACT_RECOVER_FEEDRATE_SWAP;
68
+
69
+  for (uint8_t i = 0; i < EXTRUDERS; ++i) {
70
+    retracted[i] = false;
71
+    #if EXTRUDERS > 1
72
+      retracted_swap[i] = false;
73
+    #endif
74
+  }
62 75
 }
63 76
 
64 77
 /**
@@ -87,10 +100,11 @@ void FWRetract::retract(const bool retracting
87 100
   // Simply never allow two retracts or recovers in a row
88 101
   if (retracted[active_extruder] == retracting) return;
89 102
 
90
-  #if EXTRUDERS < 2
91
-    bool swapping = false;
103
+  #if EXTRUDERS > 1
104
+    if (!retracting) swapping = retracted_swap[active_extruder];
105
+  #else
106
+    const bool swapping = false;
92 107
   #endif
93
-  if (!retracting) swapping = retracted_swap[active_extruder];
94 108
 
95 109
   /* // debugging
96 110
     SERIAL_ECHOLNPAIR("retracting ", retracting);
@@ -117,6 +131,8 @@ void FWRetract::retract(const bool retracting
117 131
   // The current position will be the destination for E and Z moves
118 132
   set_destination_to_current();
119 133
 
134
+  stepper.synchronize();  // Wait for buffered moves to complete
135
+
120 136
   if (retracting) {
121 137
     // Remember the Z height since G-code may include its own Z-hop
122 138
     // For best results turn off Z hop if G-code already includes it

+ 15
- 8
Marlin/src/feature/fwretract.h View File

@@ -30,6 +30,11 @@
30 30
 #include "../inc/MarlinConfig.h"
31 31
 
32 32
 class FWRetract {
33
+private:
34
+  #if EXTRUDERS > 1
35
+    static bool retracted_swap[EXTRUDERS];         // Which extruders are swap-retracted
36
+  #endif
37
+
33 38
 public:
34 39
   static bool autoretract_enabled,                 // M209 S - Autoretract switch
35 40
               retracted[EXTRUDERS];                // Which extruders are currently retracted
@@ -42,22 +47,24 @@ public:
42 47
                swap_retract_recover_length,        // M208 W - G11 Swap Recover length
43 48
                swap_retract_recover_feedrate_mm_s; // M208 R - G11 Swap Recover feedrate
44 49
 
45
-  #if EXTRUDERS > 1
46
-    static bool retracted_swap[EXTRUDERS];         // Which extruders are swap-retracted
47
-  #else
48
-    static bool constexpr retracted_swap[1] = { false };
49
-  #endif
50
-
51
-  FWRetract() {}
50
+  FWRetract() { reset(); }
52 51
 
53 52
   static void reset();
54 53
 
54
+  static void refresh_autoretract() {
55
+    for (uint8_t i = 0; i < EXTRUDERS; i++) retracted[i] = false;
56
+  }
57
+
58
+  static void enable_autoretract(const bool enable) {
59
+    autoretract_enabled = enable;
60
+    refresh_autoretract();
61
+  }
62
+
55 63
   static void retract(const bool retracting
56 64
     #if EXTRUDERS > 1
57 65
       , bool swapping = false
58 66
     #endif
59 67
   );
60
-
61 68
 };
62 69
 
63 70
 extern FWRetract fwretract;

+ 0
- 1
Marlin/src/gcode/feature/fwretract/G10_G11.cpp View File

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

+ 1
- 2
Marlin/src/gcode/feature/fwretract/M207-M209.cpp View File

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

+ 1
- 1
Marlin/src/lcd/ultralcd.cpp View File

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

+ 4
- 0
Marlin/src/module/configuration_store.cpp View File

@@ -247,6 +247,10 @@ void MarlinSettings::postprocess() {
247 247
   #if HAS_MOTOR_CURRENT_PWM
248 248
     stepper.refresh_motor_power();
249 249
   #endif
250
+
251
+  #if ENABLED(FWRETRACT)
252
+    fwretract.refresh_autoretract();
253
+  #endif
250 254
 }
251 255
 
252 256
 #if ENABLED(EEPROM_SETTINGS)

Loading…
Cancel
Save