Browse Source

Fix position sync in M600 pause/resume

studiodyne 7 years ago
parent
commit
8181220bfd
1 changed files with 20 additions and 31 deletions
  1. 20
    31
      Marlin/src/feature/pause.cpp

+ 20
- 31
Marlin/src/feature/pause.cpp View File

@@ -93,16 +93,21 @@ static void ensure_safe_temperature() {
93 93
   }
94 94
 }
95 95
 
96
+void do_pause_e_move(const float &length, const float fr) {
97
+  current_position[E_AXIS] += length;
98
+  set_destination_from_current();
99
+  #if IS_KINEMATIC
100
+    planner.buffer_line_kinematic(destination, fr, active_extruder);
101
+  #else
102
+    line_to_destination(fr);
103
+  #endif
104
+  stepper.synchronize();
105
+}
106
+
96 107
 // public:
97 108
 
98 109
 bool move_away_flag = false;
99 110
 
100
-#if IS_KINEMATIC
101
-  #define RUNPLAN(RATE_MM_S) planner.buffer_line_kinematic(destination, RATE_MM_S, active_extruder)
102
-#else
103
-  #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S)
104
-#endif
105
-
106 111
 bool pause_print(const float &retract, const float &z_lift, const float &x_pos, const float &y_pos,
107 112
                         const float &unload_length/*=0*/ , const int8_t max_beep_count/*=0*/, const bool show_lcd/*=false*/
108 113
 ) {
@@ -140,17 +145,11 @@ bool pause_print(const float &retract, const float &z_lift, const float &x_pos,
140 145
     #endif
141 146
   }
142 147
 
143
-  // Save current position
144 148
   stepper.synchronize();
145
-  COPY(resume_position, current_position);
146
-
147
-  if (retract) {
148
-    // Initial retract before move to filament change position
149
-    set_destination_from_current();
150
-    destination[E_AXIS] += retract;
151
-    RUNPLAN(PAUSE_PARK_RETRACT_FEEDRATE);
152
-    stepper.synchronize();
153
-  }
149
+  COPY(resume_position, current_position); // Save current position for later
150
+
151
+  // Initial retract before move to filament change position
152
+  if (retract) do_pause_e_move(retract, PAUSE_PARK_RETRACT_FEEDRATE);
154 153
 
155 154
   // Lift Z axis
156 155
   if (z_lift > 0)
@@ -168,10 +167,7 @@ bool pause_print(const float &retract, const float &z_lift, const float &x_pos,
168 167
     }
169 168
 
170 169
     // Unload filament
171
-    set_destination_from_current();
172
-    destination[E_AXIS] += unload_length;
173
-    RUNPLAN(FILAMENT_CHANGE_UNLOAD_FEEDRATE);
174
-    stepper.synchronize();
170
+    do_pause_e_move(unload_length, FILAMENT_CHANGE_UNLOAD_FEEDRATE);
175 171
   }
176 172
 
177 173
   if (show_lcd) {
@@ -272,8 +268,6 @@ void resume_print(const float &load_length/*=0*/, const float &initial_extrude_l
272 268
     filament_change_beep(max_beep_count, true);
273 269
   #endif
274 270
 
275
-  set_destination_from_current();
276
-
277 271
   if (load_length != 0) {
278 272
     #if ENABLED(ULTIPANEL)
279 273
       // Show "insert filament"
@@ -297,9 +291,7 @@ void resume_print(const float &load_length/*=0*/, const float &initial_extrude_l
297 291
     #endif
298 292
 
299 293
     // Load filament
300
-    destination[E_AXIS] += load_length;
301
-    RUNPLAN(FILAMENT_CHANGE_LOAD_FEEDRATE);
302
-    stepper.synchronize();
294
+    do_pause_e_move(load_length, FILAMENT_CHANGE_LOAD_FEEDRATE);
303 295
   }
304 296
 
305 297
   #if ENABLED(ULTIPANEL) && ADVANCED_PAUSE_EXTRUDE_LENGTH > 0
@@ -312,9 +304,7 @@ void resume_print(const float &load_length/*=0*/, const float &initial_extrude_l
312 304
         lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_EXTRUDE);
313 305
 
314 306
         // Extrude filament to get into hotend
315
-        destination[E_AXIS] += extrude_length;
316
-        RUNPLAN(ADVANCED_PAUSE_EXTRUDE_FEEDRATE);
317
-        stepper.synchronize();
307
+        do_pause_e_move(extrude_length, ADVANCED_PAUSE_EXTRUDE_FEEDRATE);
318 308
       }
319 309
 
320 310
       // Show "Extrude More" / "Resume" menu and wait for reply
@@ -337,8 +327,7 @@ void resume_print(const float &load_length/*=0*/, const float &initial_extrude_l
337 327
   #endif
338 328
 
339 329
   // Set extruder to saved position
340
-  destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS];
341
-  planner.set_e_position_mm(current_position[E_AXIS]);
330
+  planner.set_e_position_mm((current_position[E_AXIS] = resume_position[E_AXIS]));
342 331
 
343 332
   // Move XY to starting position, then Z
344 333
   do_blocking_move_to_xy(resume_position[X_AXIS], resume_position[Y_AXIS], PAUSE_PARK_XY_FEEDRATE);
@@ -349,7 +338,7 @@ void resume_print(const float &load_length/*=0*/, const float &initial_extrude_l
349 338
   #endif
350 339
 
351 340
   #if ENABLED(ULTIPANEL)
352
-    // Show status screen
341
+    // Show pause status screen
353 342
     lcd_advanced_pause_show_message(ADVANCED_PAUSE_MESSAGE_STATUS);
354 343
   #endif
355 344
 

Loading…
Cancel
Save