Browse Source

Improve FWRETRACT logic, add common sense

studiodyne 6 years ago
parent
commit
eb02f8c719

+ 28
- 33
Marlin/src/feature/fwretract.cpp View File

94
   #endif
94
   #endif
95
 ) {
95
 ) {
96
 
96
 
97
-  static float hop_height,        // Remember where the Z height started
98
-               hop_amount = 0.0;  // Total amount lifted, for use in recover
97
+  static float hop_amount = 0.0;  // Total amount lifted, for use in recover
99
 
98
 
100
-  // Simply never allow two retracts or recovers in a row
99
+  // Prevent two retracts or recovers in a row
101
   if (retracted[active_extruder] == retracting) return;
100
   if (retracted[active_extruder] == retracting) return;
102
 
101
 
102
+  // Prevent two swap-retract or recovers in a row
103
   #if EXTRUDERS > 1
103
   #if EXTRUDERS > 1
104
+    // Allow G10 S1 only after G10
105
+    if (swapping && retracted_swap[active_extruder] == retracting) return;
106
+    // G11 priority to recover the long retract if activated
104
     if (!retracting) swapping = retracted_swap[active_extruder];
107
     if (!retracting) swapping = retracted_swap[active_extruder];
105
   #else
108
   #else
106
     const bool swapping = false;
109
     const bool swapping = false;
121
   //*/
124
   //*/
122
 
125
 
123
   const bool has_zhop = retract_zlift > 0.01;     // Is there a hop set?
126
   const bool has_zhop = retract_zlift > 0.01;     // Is there a hop set?
124
-
125
   const float old_feedrate_mm_s = feedrate_mm_s;
127
   const float old_feedrate_mm_s = feedrate_mm_s;
126
-  const int16_t old_flow = planner.flow_percentage[active_extruder];
127
-
128
-  // Don't apply flow multiplication to retract/recover
129
-  planner.flow_percentage[active_extruder] = 100;
130
 
128
 
131
   // The current position will be the destination for E and Z moves
129
   // The current position will be the destination for E and Z moves
132
   set_destination_from_current();
130
   set_destination_from_current();
133
-
134
   stepper.synchronize();  // Wait for buffered moves to complete
131
   stepper.synchronize();  // Wait for buffered moves to complete
135
 
132
 
136
-  if (retracting) {
137
-    // Remember the Z height since G-code may include its own Z-hop
138
-    // For best results turn off Z hop if G-code already includes it
139
-    hop_height = destination[Z_AXIS];
133
+  const float renormalize = 100.0 / planner.flow_percentage[active_extruder] / planner.volumetric_multiplier[active_extruder];
140
 
134
 
135
+  if (retracting) {
141
     // Retract by moving from a faux E position back to the current E position
136
     // Retract by moving from a faux E position back to the current E position
142
     feedrate_mm_s = retract_feedrate_mm_s;
137
     feedrate_mm_s = retract_feedrate_mm_s;
143
-    current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) / planner.volumetric_multiplier[active_extruder];
138
+    current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) * renormalize;
144
     sync_plan_position_e();
139
     sync_plan_position_e();
145
     prepare_move_to_destination();
140
     prepare_move_to_destination();
146
 
141
 
147
     // Is a Z hop set, and has the hop not yet been done?
142
     // Is a Z hop set, and has the hop not yet been done?
148
-    if (has_zhop) {
149
-      hop_amount += retract_zlift;                // Carriage is raised for retraction hop
150
-      current_position[Z_AXIS] -= retract_zlift;  // Pretend current pos is lower. Next move raises Z.
151
-      SYNC_PLAN_POSITION_KINEMATIC();             // Set the planner to the new position
152
-      prepare_move_to_destination();              // Raise up to the old current pos
143
+    // No double zlifting
144
+    // Feedrate to the max
145
+    if (has_zhop && !hop_amount) {
146
+      hop_amount += retract_zlift;                        // Carriage is raised for retraction hop
147
+      feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Z feedrate to max
148
+      current_position[Z_AXIS] -= retract_zlift;          // Pretend current pos is lower. Next move raises Z.
149
+      SYNC_PLAN_POSITION_KINEMATIC();                     // Set the planner to the new position
150
+      prepare_move_to_destination();                      // Raise up to the old current pos
153
     }
151
     }
154
   }
152
   }
155
   else {
153
   else {
156
     // If a hop was done and Z hasn't changed, undo the Z hop
154
     // If a hop was done and Z hasn't changed, undo the Z hop
157
-    if (hop_amount && NEAR(hop_height, destination[Z_AXIS])) {
158
-      current_position[Z_AXIS] += hop_amount;     // Pretend current pos is higher. Next move lowers Z.
159
-      SYNC_PLAN_POSITION_KINEMATIC();             // Set the planner to the new position
160
-      prepare_move_to_destination();              // Lower to the old current pos
161
-      hop_amount = 0.0;
155
+    if (hop_amount) {
156
+      current_position[Z_AXIS] -= retract_zlift;          // Pretend current pos is lower. Next move raises Z.
157
+      SYNC_PLAN_POSITION_KINEMATIC();                     // Set the planner to the new position
158
+      feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Z feedrate to max
159
+      prepare_move_to_destination();                      // Raise up to the old current pos
160
+      hop_amount = 0.0;                                   // Clear hop
162
     }
161
     }
163
 
162
 
164
     // A retract multiplier has been added here to get faster swap recovery
163
     // A retract multiplier has been added here to get faster swap recovery
165
     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
164
     feedrate_mm_s = swapping ? swap_retract_recover_feedrate_mm_s : retract_recover_feedrate_mm_s;
166
 
165
 
167
     const float move_e = swapping ? swap_retract_length + swap_retract_recover_length : retract_length + retract_recover_length;
166
     const float move_e = swapping ? swap_retract_length + swap_retract_recover_length : retract_length + retract_recover_length;
168
-    current_position[E_AXIS] -= move_e / planner.volumetric_multiplier[active_extruder];
167
+    current_position[E_AXIS] -= move_e * renormalize;
169
     sync_plan_position_e();
168
     sync_plan_position_e();
170
-
171
     prepare_move_to_destination();  // Recover E
169
     prepare_move_to_destination();  // Recover E
172
   }
170
   }
173
 
171
 
174
-  // Restore flow and feedrate
175
-  planner.flow_percentage[active_extruder] = old_flow;
176
-  feedrate_mm_s = old_feedrate_mm_s;
172
+  feedrate_mm_s = old_feedrate_mm_s;                      // Restore original feedrate
177
 
173
 
178
-  // The active extruder is now retracted or recovered
179
-  retracted[active_extruder] = retracting;
174
+  retracted[active_extruder] = retracting;                // Active extruder now retracted / recovered
180
 
175
 
181
-  // If swap retract/recover then update the retracted_swap flag too
176
+  // If swap retract/recover update the retracted_swap flag too
182
   #if EXTRUDERS > 1
177
   #if EXTRUDERS > 1
183
     if (swapping) retracted_swap[active_extruder] = retracting;
178
     if (swapping) retracted_swap[active_extruder] = retracting;
184
   #endif
179
   #endif
197
     SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
192
     SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
198
   //*/
193
   //*/
199
 
194
 
200
-} // retract()
195
+}
201
 
196
 
202
 #endif // FWRETRACT
197
 #endif // FWRETRACT

+ 4
- 1
Marlin/src/lcd/language/language_en.h View File

615
   #define MSG_CONTROL_RETRACT_RECOVER_SWAP    _UxGT("S UnRet mm")
615
   #define MSG_CONTROL_RETRACT_RECOVER_SWAP    _UxGT("S UnRet mm")
616
 #endif
616
 #endif
617
 #ifndef MSG_CONTROL_RETRACT_RECOVERF
617
 #ifndef MSG_CONTROL_RETRACT_RECOVERF
618
-  #define MSG_CONTROL_RETRACT_RECOVERF        _UxGT("UnRet  V")
618
+  #define MSG_CONTROL_RETRACT_RECOVERF        _UxGT("UnRet V")
619
+#endif
620
+#ifndef MSG_CONTROL_RETRACT_RECOVER_SWAPF
621
+  #define MSG_CONTROL_RETRACT_RECOVER_SWAPF   _UxGT("S UnRet V")
619
 #endif
622
 #endif
620
 #ifndef MSG_AUTORETRACT
623
 #ifndef MSG_AUTORETRACT
621
   #define MSG_AUTORETRACT                     _UxGT("AutoRetr.")
624
   #define MSG_AUTORETRACT                     _UxGT("AutoRetr.")

+ 1
- 0
Marlin/src/lcd/language/language_fr.h View File

222
 #define MSG_CONTROL_RETRACT_RECOVER         _UxGT("UnRet mm")
222
 #define MSG_CONTROL_RETRACT_RECOVER         _UxGT("UnRet mm")
223
 #define MSG_CONTROL_RETRACT_RECOVER_SWAP    _UxGT("Ech. UnRet mm")
223
 #define MSG_CONTROL_RETRACT_RECOVER_SWAP    _UxGT("Ech. UnRet mm")
224
 #define MSG_CONTROL_RETRACT_RECOVERF        _UxGT("UnRet V")
224
 #define MSG_CONTROL_RETRACT_RECOVERF        _UxGT("UnRet V")
225
+#define MSG_CONTROL_RETRACT_RECOVER_SWAPF   _UxGT("Ech. Retr. V")
225
 #define MSG_AUTORETRACT                     _UxGT("Retract. Auto.")
226
 #define MSG_AUTORETRACT                     _UxGT("Retract. Auto.")
226
 #define MSG_FILAMENTCHANGE                  _UxGT("Changer filament")
227
 #define MSG_FILAMENTCHANGE                  _UxGT("Changer filament")
227
 #define MSG_INIT_SDCARD                     _UxGT("Init. la carte SD")
228
 #define MSG_INIT_SDCARD                     _UxGT("Init. la carte SD")

+ 3
- 0
Marlin/src/lcd/ultralcd.cpp View File

3716
         MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &fwretract.swap_retract_recover_length, -100, 100);
3716
         MENU_ITEM_EDIT(float52, MSG_CONTROL_RETRACT_RECOVER_SWAP, &fwretract.swap_retract_recover_length, -100, 100);
3717
       #endif
3717
       #endif
3718
       MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &fwretract.retract_recover_feedrate_mm_s, 1, 999);
3718
       MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVERF, &fwretract.retract_recover_feedrate_mm_s, 1, 999);
3719
+      #if EXTRUDERS > 1
3720
+        MENU_ITEM_EDIT(float3, MSG_CONTROL_RETRACT_RECOVER_SWAPF, &fwretract.swap_retract_recover_feedrate_mm_s, 1, 999);
3721
+      #endif
3719
       END_MENU();
3722
       END_MENU();
3720
     }
3723
     }
3721
 
3724
 

Loading…
Cancel
Save