浏览代码

Fix up fwretract handling

Scott Lahteine 7 年前
父节点
当前提交
62e7a9c671
共有 1 个文件被更改,包括 21 次插入24 次删除
  1. 21
    24
      Marlin/src/feature/fwretract.cpp

+ 21
- 24
Marlin/src/feature/fwretract.cpp 查看文件

108
     // G11 priority to recover the long retract if activated
108
     // G11 priority to recover the long retract if activated
109
     if (!retracting) swapping = retracted_swap[active_extruder];
109
     if (!retracting) swapping = retracted_swap[active_extruder];
110
   #else
110
   #else
111
-    const bool swapping = false;
111
+    constexpr bool swapping = false;
112
   #endif
112
   #endif
113
 
113
 
114
   /* // debugging
114
   /* // debugging
118
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
118
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
119
       SERIAL_ECHOPAIR("retracted[", i);
119
       SERIAL_ECHOPAIR("retracted[", i);
120
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
120
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
121
-      SERIAL_ECHOPAIR("retracted_swap[", i);
122
-      SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
121
+      #if EXTRUDERS > 1
122
+        SERIAL_ECHOPAIR("retracted_swap[", i);
123
+        SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
124
+      #endif
123
     }
125
     }
124
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
126
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
125
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);
127
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);
126
     SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
128
     SERIAL_ECHOLNPAIR("hop_amount ", hop_amount);
127
   //*/
129
   //*/
128
 
130
 
129
-  const float old_feedrate_mm_s = feedrate_mm_s;
131
+  const float old_feedrate_mm_s = feedrate_mm_s,
132
+              renormalize = RECIPROCAL(planner.e_factor[active_extruder]),
133
+              base_retract = swapping ? swap_retract_length : retract_length,
134
+              old_z = current_position[Z_AXIS],
135
+              old_e = current_position[E_AXIS];
130
 
136
 
131
   // The current position will be the destination for E and Z moves
137
   // The current position will be the destination for E and Z moves
132
   set_destination_from_current();
138
   set_destination_from_current();
133
-  stepper.synchronize();  // Wait for buffered moves to complete
134
-
135
-  const float renormalize = 1.0 / planner.e_factor[active_extruder];
136
 
139
 
137
   if (retracting) {
140
   if (retracting) {
138
     // Retract by moving from a faux E position back to the current E position
141
     // Retract by moving from a faux E position back to the current E position
139
     feedrate_mm_s = retract_feedrate_mm_s;
142
     feedrate_mm_s = retract_feedrate_mm_s;
140
-    current_position[E_AXIS] += (swapping ? swap_retract_length : retract_length) * renormalize;
141
-    sync_plan_position_e();
142
-    prepare_move_to_destination();  // set_current_to_destination
143
+    destination[E_AXIS] -= base_retract * renormalize;
144
+    prepare_move_to_destination();                        // set_current_to_destination
143
 
145
 
144
     // Is a Z hop set, and has the hop not yet been done?
146
     // Is a Z hop set, and has the hop not yet been done?
145
-    // No double zlifting
146
-    // Feedrate to the max
147
     if (retract_zlift > 0.01 && !hop_amount) {            // Apply hop only once
147
     if (retract_zlift > 0.01 && !hop_amount) {            // Apply hop only once
148
-      const float old_z = current_position[Z_AXIS];
149
       hop_amount += retract_zlift;                        // Add to the hop total (again, only once)
148
       hop_amount += retract_zlift;                        // Add to the hop total (again, only once)
150
       destination[Z_AXIS] += retract_zlift;               // Raise Z by the zlift (M207 Z) amount
149
       destination[Z_AXIS] += retract_zlift;               // Raise Z by the zlift (M207 Z) amount
151
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Maximum Z feedrate
150
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Maximum Z feedrate
152
       prepare_move_to_destination();                      // Raise up, set_current_to_destination
151
       prepare_move_to_destination();                      // Raise up, set_current_to_destination
153
-      current_position[Z_AXIS] = old_z;                   // Spoof the Z position in the planner
154
-      SYNC_PLAN_POSITION_KINEMATIC();
155
     }
152
     }
156
   }
153
   }
157
   else {
154
   else {
158
     // If a hop was done and Z hasn't changed, undo the Z hop
155
     // If a hop was done and Z hasn't changed, undo the Z hop
159
     if (hop_amount) {
156
     if (hop_amount) {
160
-      current_position[Z_AXIS] += hop_amount;             // Set actual Z (due to the prior hop)
161
-      SYNC_PLAN_POSITION_KINEMATIC();                     // Spoof the Z position in the planner
157
+      destination[Z_AXIS] -= hop_amount;                  // Move back down by the total hop amount
162
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Z feedrate to max
158
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Z feedrate to max
163
       prepare_move_to_destination();                      // Lower Z, set_current_to_destination
159
       prepare_move_to_destination();                      // Lower Z, set_current_to_destination
164
       hop_amount = 0.0;                                   // Clear the hop amount
160
       hop_amount = 0.0;                                   // Clear the hop amount
165
     }
161
     }
166
 
162
 
167
-    // A retract multiplier has been added here to get faster swap recovery
163
+    destination[E_AXIS] += (base_retract + (swapping ? swap_retract_recover_length : retract_recover_length)) * renormalize;
168
     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;
169
-
170
-    current_position[E_AXIS] -= (swapping ? swap_retract_length + swap_retract_recover_length
171
-                                          : retract_length + retract_recover_length) * renormalize;
172
-    sync_plan_position_e();
173
     prepare_move_to_destination();                        // Recover E, set_current_to_destination
165
     prepare_move_to_destination();                        // Recover E, set_current_to_destination
174
   }
166
   }
175
 
167
 
176
   feedrate_mm_s = old_feedrate_mm_s;                      // Restore original feedrate
168
   feedrate_mm_s = old_feedrate_mm_s;                      // Restore original feedrate
169
+  current_position[Z_AXIS] = old_z;                       // Restore Z and E positions
170
+  current_position[E_AXIS] = old_e;
171
+  SYNC_PLAN_POSITION_KINEMATIC();                         // As if the move never took place
177
 
172
 
178
   retracted[active_extruder] = retracting;                // Active extruder now retracted / recovered
173
   retracted[active_extruder] = retracting;                // Active extruder now retracted / recovered
179
 
174
 
189
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
184
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
190
       SERIAL_ECHOPAIR("retracted[", i);
185
       SERIAL_ECHOPAIR("retracted[", i);
191
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
186
       SERIAL_ECHOLNPAIR("] ", retracted[i]);
192
-      SERIAL_ECHOPAIR("retracted_swap[", i);
193
-      SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
187
+      #if EXTRUDERS > 1
188
+        SERIAL_ECHOPAIR("retracted_swap[", i);
189
+        SERIAL_ECHOLNPAIR("] ", retracted_swap[i]);
190
+      #endif
194
     }
191
     }
195
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
192
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
196
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);
193
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);

正在加载...
取消
保存