Browse Source

PARK_HEAD_ON_PAUSE implementation

Scott Lahteine 7 years ago
parent
commit
ff0dd162b7
2 changed files with 179 additions and 20 deletions
  1. 169
    17
      Marlin/Marlin_main.cpp
  2. 10
    3
      Marlin/ultralcd.cpp

+ 169
- 17
Marlin/Marlin_main.cpp View File

@@ -122,6 +122,7 @@
122 122
  * M119 - Report endstops status.
123 123
  * M120 - Enable endstops detection.
124 124
  * M121 - Disable endstops detection.
125
+ * M125 - Save current position and move to filament change position. (Requires PARK_HEAD_ON_PAUSE)
125 126
  * M126 - Solenoid Air Valve Open. (Requires BARICUDA)
126 127
  * M127 - Solenoid Air Valve Closed. (Requires BARICUDA)
127 128
  * M128 - EtoP Open. (Requires BARICUDA)
@@ -150,7 +151,7 @@
150 151
  * M208 - Set Recover (unretract) Additional (!) Length: S<length> and Feedrate: F<units/min>. (Requires FWRETRACT)
151 152
  * M209 - Turn Automatic Retract Detection on/off: S<0|1> (For slicers that don't support G10/11). (Requires FWRETRACT)
152 153
           Every normal extrude-only move will be classified as retract depending on the direction.
153
- * M211 - Enable, Disable, and/or Report software endstops: S<0|1>
154
+ * M211 - Enable, Disable, and/or Report software endstops: S<0|1> (Requires MIN_SOFTWARE_ENDSTOPS or MAX_SOFTWARE_ENDSTOPS)
154 155
  * M218 - Set a tool offset: "M218 T<index> X<offset> Y<offset>". (Requires 2 or more extruders)
155 156
  * M220 - Set Feedrate Percentage: "M220 S<percent>" (i.e., "FR" on the LCD)
156 157
  * M221 - Set Flow Percentage: "M221 S<percent>"
@@ -199,13 +200,11 @@
199 200
  * M350 - Set microstepping mode. (Requires digital microstepping pins.)
200 201
  * M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.)
201 202
  *
202
- * ************ SCARA Specific - This can change to suit future G-code regulations
203 203
  * M360 - SCARA calibration: Move to cal-position ThetaA (0 deg calibration)
204 204
  * M361 - SCARA calibration: Move to cal-position ThetaB (90 deg calibration - steps per degree)
205 205
  * M362 - SCARA calibration: Move to cal-position PsiA (0 deg calibration)
206 206
  * M363 - SCARA calibration: Move to cal-position PsiB (90 deg calibration - steps per degree)
207 207
  * M364 - SCARA calibration: Move to cal-position PSIC (90 deg to Theta calibration position)
208
- * ************* SCARA End ***************
209 208
  *
210 209
  * ************ Custom codes - This can change to suit future G-code regulations
211 210
  * M100 - Watch Free Memory (For Debugging). (Requires M100_FREE_MEMORY_WATCHER)
@@ -4667,6 +4666,45 @@ inline void gcode_M17() {
4667 4666
   enable_all_steppers();
4668 4667
 }
4669 4668
 
4669
+#if IS_KINEMATIC
4670
+  #define RUNPLAN(RATE_MM_S) planner.buffer_line_kinematic(destination, RATE_MM_S, active_extruder)
4671
+#else
4672
+  #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S)
4673
+#endif
4674
+
4675
+#if ENABLED(PARK_HEAD_ON_PAUSE)
4676
+  float resume_position[XYZE];
4677
+  bool move_away_flag = false;
4678
+
4679
+  inline void move_back_on_resume() {
4680
+    if (!move_away_flag) return;
4681
+    move_away_flag = false;
4682
+
4683
+    // Set extruder to saved position
4684
+    destination[E_AXIS] = current_position[E_AXIS] = resume_position[E_AXIS];
4685
+    planner.set_e_position_mm(current_position[E_AXIS]);
4686
+
4687
+    #if IS_KINEMATIC
4688
+      // Move XYZ to starting position
4689
+      planner.buffer_line_kinematic(lastpos, FILAMENT_CHANGE_XY_FEEDRATE, active_extruder);
4690
+    #else
4691
+      // Move XY to starting position, then Z
4692
+      destination[X_AXIS] = resume_position[X_AXIS];
4693
+      destination[Y_AXIS] = resume_position[Y_AXIS];
4694
+      RUNPLAN(FILAMENT_CHANGE_XY_FEEDRATE);
4695
+      destination[Z_AXIS] = resume_position[Z_AXIS];
4696
+      RUNPLAN(FILAMENT_CHANGE_Z_FEEDRATE);
4697
+    #endif
4698
+    stepper.synchronize();
4699
+
4700
+    #if ENABLED(FILAMENT_RUNOUT_SENSOR)
4701
+      filament_ran_out = false;
4702
+    #endif
4703
+    set_current_to_destination();
4704
+  }
4705
+
4706
+#endif // PARK_HEAD_ON_PAUSE
4707
+
4670 4708
 #if ENABLED(SDSUPPORT)
4671 4709
 
4672 4710
   /**
@@ -4694,9 +4732,13 @@ inline void gcode_M17() {
4694 4732
   inline void gcode_M23() { card.openFile(current_command_args, true); }
4695 4733
 
4696 4734
   /**
4697
-   * M24: Start SD Print
4735
+   * M24: Start or Resume SD Print
4698 4736
    */
4699 4737
   inline void gcode_M24() {
4738
+    #if ENABLED(PARK_HEAD_ON_PAUSE)
4739
+      move_back_on_resume();
4740
+    #endif
4741
+
4700 4742
     card.startFileprint();
4701 4743
     print_job_timer.start();
4702 4744
   }
@@ -4704,7 +4746,14 @@ inline void gcode_M17() {
4704 4746
   /**
4705 4747
    * M25: Pause SD Print
4706 4748
    */
4707
-  inline void gcode_M25() { card.pauseSDPrint(); }
4749
+  inline void gcode_M25() {
4750
+    card.pauseSDPrint();
4751
+    print_job_timer.pause();
4752
+
4753
+    #if ENABLED(PARK_HEAD_ON_PAUSE)
4754
+      enqueue_and_echo_commands_P(PSTR("M125")); // Must be enqueued with pauseSDPrint set to be last in the buffer
4755
+    #endif
4756
+  }
4708 4757
 
4709 4758
   /**
4710 4759
    * M26: Set SD Card file index
@@ -6084,6 +6133,111 @@ inline void gcode_M120() { endstops.enable_globally(true); }
6084 6133
  */
6085 6134
 inline void gcode_M121() { endstops.enable_globally(false); }
6086 6135
 
6136
+#if ENABLED(PARK_HEAD_ON_PAUSE)
6137
+
6138
+  /**
6139
+   * M125: Store current position and move to filament change position.
6140
+   *       Called on pause (by M25) to prevent material leaking onto the
6141
+   *       object. On resume (M24) the head will be moved back and the
6142
+   *       print will resume.
6143
+   *
6144
+   *       If Marlin is compiled without SD Card support, M125 can be
6145
+   *       used directly to pause the print and move to park position,
6146
+   *       resuming with a button click or M108.
6147
+   *
6148
+   *    L = override retract length
6149
+   *    X = override X
6150
+   *    Y = override Y
6151
+   *    Z = override Z raise
6152
+   */
6153
+  inline void gcode_M125() {
6154
+    if (move_away_flag) return; // already paused
6155
+
6156
+    const bool job_running = print_job_timer.isRunning();
6157
+
6158
+    // there are blocks after this one, or sd printing
6159
+    move_away_flag = job_running || planner.blocks_queued()
6160
+      #if ENABLED(SDSUPPORT)
6161
+        || card.sdprinting
6162
+      #endif
6163
+    ;
6164
+
6165
+    if (!move_away_flag) return; // nothing to pause
6166
+
6167
+    // M125 can be used to pause a print too
6168
+    #if ENABLED(SDSUPPORT)
6169
+      card.pauseSDPrint();
6170
+    #endif
6171
+    print_job_timer.pause();
6172
+
6173
+    // Save current position
6174
+    COPY(resume_position, current_position);
6175
+
6176
+    set_destination_to_current();
6177
+
6178
+    // Initial retract before move to filament change position
6179
+    destination[E_AXIS] += code_seen('L') ? code_value_axis_units(E_AXIS) : 0
6180
+      #if defined(FILAMENT_CHANGE_RETRACT_LENGTH) && FILAMENT_CHANGE_RETRACT_LENGTH > 0
6181
+        - (FILAMENT_CHANGE_RETRACT_LENGTH)
6182
+      #endif
6183
+    ;
6184
+    RUNPLAN(FILAMENT_CHANGE_RETRACT_FEEDRATE);
6185
+
6186
+    // Lift Z axis
6187
+    const float z_lift = code_seen('Z') ? code_value_axis_units(Z_AXIS) :
6188
+      #if defined(FILAMENT_CHANGE_Z_ADD) && FILAMENT_CHANGE_Z_ADD > 0
6189
+        FILAMENT_CHANGE_Z_ADD
6190
+      #else
6191
+        0
6192
+      #endif
6193
+    ;
6194
+    if (z_lift > 0) {
6195
+      destination[Z_AXIS] += z_lift;
6196
+      NOMORE(destination[Z_AXIS], Z_MAX_POS);
6197
+      RUNPLAN(FILAMENT_CHANGE_Z_FEEDRATE);
6198
+    }
6199
+
6200
+    // Move XY axes to filament change position or given position
6201
+    destination[X_AXIS] = code_seen('X') ? code_value_axis_units(X_AXIS) : 0
6202
+      #ifdef FILAMENT_CHANGE_X_POS
6203
+        + FILAMENT_CHANGE_X_POS
6204
+      #endif
6205
+    ;
6206
+    destination[Y_AXIS] = code_seen('Y') ? code_value_axis_units(Y_AXIS) : 0
6207
+      #ifdef FILAMENT_CHANGE_Y_POS
6208
+        + FILAMENT_CHANGE_Y_POS
6209
+      #endif
6210
+    ;
6211
+
6212
+    #if HOTENDS > 1 && DISABLED(DUAL_X_CARRIAGE)
6213
+      if (active_extruder > 0) {
6214
+        if (!code_seen('X')) destination[X_AXIS] += hotend_offset[X_AXIS][active_extruder];
6215
+        if (!code_seen('Y')) destination[Y_AXIS] += hotend_offset[Y_AXIS][active_extruder];
6216
+      }
6217
+    #endif
6218
+
6219
+    clamp_to_software_endstops(destination);
6220
+    RUNPLAN(FILAMENT_CHANGE_XY_FEEDRATE);
6221
+    set_current_to_destination();
6222
+    stepper.synchronize();
6223
+    disable_e_steppers();
6224
+
6225
+    #if DISABLED(SDSUPPORT)
6226
+      // Wait for lcd click or M108
6227
+      wait_for_user = true;
6228
+      KEEPALIVE_STATE(PAUSED_FOR_USER);
6229
+      while (wait_for_user) idle();
6230
+      KEEPALIVE_STATE(IN_HANDLER);
6231
+
6232
+      // Return to print position and continue
6233
+      move_back_on_resume();
6234
+      if (job_running) print_job_timer.start();
6235
+      move_away_flag = false;
6236
+    #endif
6237
+  }
6238
+
6239
+#endif // PARK_HEAD_ON_PAUSE
6240
+
6087 6241
 #if ENABLED(BLINKM) || ENABLED(RGB_LED)
6088 6242
 
6089 6243
   void set_led_color(const uint8_t r, const uint8_t g, const uint8_t b) {
@@ -7253,25 +7407,18 @@ inline void gcode_M503() {
7253 7407
     busy_doing_M600 = true;  // Stepper Motors can't timeout when this is set
7254 7408
 
7255 7409
     // Pause the print job timer
7256
-    bool job_running = print_job_timer.isRunning();
7410
+    const bool job_running = print_job_timer.isRunning();
7411
+
7257 7412
     print_job_timer.pause();
7258 7413
 
7259 7414
     // Show initial message and wait for synchronize steppers
7260 7415
     lcd_filament_change_show_message(FILAMENT_CHANGE_MESSAGE_INIT);
7261 7416
     stepper.synchronize();
7262 7417
 
7263
-    float lastpos[NUM_AXIS];
7264
-
7265 7418
     // Save current position of all axes
7266
-    LOOP_XYZE(i)
7267
-      lastpos[i] = destination[i] = current_position[i];
7268
-
7269
-    // Define runplan for move axes
7270
-    #if IS_KINEMATIC
7271
-      #define RUNPLAN(RATE_MM_S) planner.buffer_line_kinematic(destination, RATE_MM_S, active_extruder);
7272
-    #else
7273
-      #define RUNPLAN(RATE_MM_S) line_to_destination(RATE_MM_S);
7274
-    #endif
7419
+    float lastpos[XYZE];
7420
+    COPY(lastpos, current_position);
7421
+    set_destination_to_current();
7275 7422
 
7276 7423
     // Initial retract before move to filament change position
7277 7424
     destination[E_AXIS] += code_seen('E') ? code_value_axis_units(E_AXIS) : 0
@@ -8555,6 +8702,11 @@ void process_next_command() {
8555 8702
           break;
8556 8703
       #endif // FAN_COUNT > 0
8557 8704
 
8705
+      #if ENABLED(PARK_HEAD_ON_PAUSE)
8706
+        case 125: // M125: Store current position and move to filament change position
8707
+          gcode_M125(); break;
8708
+      #endif
8709
+
8558 8710
       #if ENABLED(BARICUDA)
8559 8711
         // PWM for HEATER_1_PIN
8560 8712
         #if HAS_HEATER_1

+ 10
- 3
Marlin/ultralcd.cpp View File

@@ -615,11 +615,18 @@ void kill_screen(const char* lcd_msg) {
615 615
     void lcd_sdcard_pause() {
616 616
       card.pauseSDPrint();
617 617
       print_job_timer.pause();
618
+      #if ENABLED(PARK_HEAD_ON_PAUSE)
619
+        enqueue_and_echo_commands_P(PSTR("M125"))
620
+      #endif
618 621
     }
619 622
 
620 623
     void lcd_sdcard_resume() {
621
-      card.startFileprint();
622
-      print_job_timer.start();
624
+      #if ENABLED(PARK_HEAD_ON_PAUSE)
625
+        enqueue_and_echo_commands_P(PSTR("M24"))
626
+      #else
627
+        card.startFileprint();
628
+        print_job_timer.start();
629
+      #endif
623 630
     }
624 631
 
625 632
     void lcd_sdcard_stop() {
@@ -634,7 +641,7 @@ void kill_screen(const char* lcd_msg) {
634 641
       lcd_setstatus(MSG_PRINT_ABORTED, true);
635 642
     }
636 643
 
637
-  #endif //SDSUPPORT
644
+  #endif // SDSUPPORT
638 645
 
639 646
   #if ENABLED(MENU_ITEM_CASE_LIGHT)
640 647
 

Loading…
Cancel
Save