Переглянути джерело

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,7 +108,7 @@ void FWRetract::retract(const bool retracting
108 108
     // G11 priority to recover the long retract if activated
109 109
     if (!retracting) swapping = retracted_swap[active_extruder];
110 110
   #else
111
-    const bool swapping = false;
111
+    constexpr bool swapping = false;
112 112
   #endif
113 113
 
114 114
   /* // debugging
@@ -118,62 +118,57 @@ void FWRetract::retract(const bool retracting
118 118
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
119 119
       SERIAL_ECHOPAIR("retracted[", i);
120 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 126
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
125 127
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);
126 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 137
   // The current position will be the destination for E and Z moves
132 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 140
   if (retracting) {
138 141
     // Retract by moving from a faux E position back to the current E position
139 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 146
     // Is a Z hop set, and has the hop not yet been done?
145
-    // No double zlifting
146
-    // Feedrate to the max
147 147
     if (retract_zlift > 0.01 && !hop_amount) {            // Apply hop only once
148
-      const float old_z = current_position[Z_AXIS];
149 148
       hop_amount += retract_zlift;                        // Add to the hop total (again, only once)
150 149
       destination[Z_AXIS] += retract_zlift;               // Raise Z by the zlift (M207 Z) amount
151 150
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Maximum Z feedrate
152 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 154
   else {
158 155
     // If a hop was done and Z hasn't changed, undo the Z hop
159 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 158
       feedrate_mm_s = planner.max_feedrate_mm_s[Z_AXIS];  // Z feedrate to max
163 159
       prepare_move_to_destination();                      // Lower Z, set_current_to_destination
164 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 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 165
     prepare_move_to_destination();                        // Recover E, set_current_to_destination
174 166
   }
175 167
 
176 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 173
   retracted[active_extruder] = retracting;                // Active extruder now retracted / recovered
179 174
 
@@ -189,8 +184,10 @@ void FWRetract::retract(const bool retracting
189 184
     for (uint8_t i = 0; i < EXTRUDERS; ++i) {
190 185
       SERIAL_ECHOPAIR("retracted[", i);
191 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 192
     SERIAL_ECHOLNPAIR("current_position[z] ", current_position[Z_AXIS]);
196 193
     SERIAL_ECHOLNPAIR("current_position[e] ", current_position[E_AXIS]);

Завантаження…
Відмінити
Зберегти