瀏覽代碼

Filament Runout handling for Mixing Extruder (#20327)

Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
Stephan 3 年之前
父節點
當前提交
713de872ce
沒有連結到貢獻者的電子郵件帳戶。

+ 5
- 2
Marlin/Configuration.h 查看文件

@@ -1278,6 +1278,8 @@
1278 1278
   #define FIL_RUNOUT_STATE     LOW        // Pin state indicating that filament is NOT present.
1279 1279
   #define FIL_RUNOUT_PULLUP               // Use internal pullup for filament runout pins.
1280 1280
   //#define FIL_RUNOUT_PULLDOWN           // Use internal pulldown for filament runout pins.
1281
+  //#define WATCH_ALL_RUNOUT_SENSORS      // Execute runout script on any triggering sensor, not only for the active extruder.
1282
+                                          // This is automatically enabled for MIXING_EXTRUDERs.
1281 1283
 
1282 1284
   // Override individually if the runout sensors vary
1283 1285
   //#define FIL_RUNOUT1_STATE LOW
@@ -1312,8 +1314,9 @@
1312 1314
   //#define FIL_RUNOUT8_PULLUP
1313 1315
   //#define FIL_RUNOUT8_PULLDOWN
1314 1316
 
1315
-  // Set one or more commands to execute on filament runout.
1316
-  // (After 'M412 H' Marlin will ask the host to handle the process.)
1317
+  // Commands to execute on filament runout.
1318
+  // With multiple runout sensors use the %c placeholder for the current tool in commands (e.g., "M600 T%c")
1319
+  // NOTE: After 'M412 H1' the host handles filament runout and this script does not apply.
1317 1320
   #define FILAMENT_RUNOUT_SCRIPT "M600"
1318 1321
 
1319 1322
   // After a runout is detected, continue printing this length of filament

+ 22
- 8
Marlin/src/feature/runout.cpp 查看文件

@@ -47,12 +47,12 @@ bool FilamentMonitorBase::enabled = true,
47 47
 
48 48
 #if HAS_FILAMENT_RUNOUT_DISTANCE
49 49
   float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
50
-  volatile float RunoutResponseDelayed::runout_mm_countdown[EXTRUDERS];
50
+  volatile float RunoutResponseDelayed::runout_mm_countdown[NUM_RUNOUT_SENSORS];
51 51
   #if ENABLED(FILAMENT_MOTION_SENSOR)
52 52
     uint8_t FilamentSensorEncoder::motion_detected;
53 53
   #endif
54 54
 #else
55
-  int8_t RunoutResponseDebounced::runout_count; // = 0
55
+  int8_t RunoutResponseDebounced::runout_count[NUM_RUNOUT_SENSORS]; // = 0
56 56
 #endif
57 57
 
58 58
 //
@@ -70,7 +70,7 @@ bool FilamentMonitorBase::enabled = true,
70 70
   #include "../lcd/extui/ui_api.h"
71 71
 #endif
72 72
 
73
-void event_filament_runout() {
73
+void event_filament_runout(const uint8_t extruder) {
74 74
 
75 75
   if (did_pause_print) return;  // Action already in progress. Purge triggered repeated runout.
76 76
 
@@ -85,10 +85,10 @@ void event_filament_runout() {
85 85
     }
86 86
   #endif
87 87
 
88
-  TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getActiveTool()));
88
+  TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getTool(extruder)));
89 89
 
90
-  #if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS)
91
-    const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, active_extruder);
90
+  #if ANY(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS, MULTI_FILAMENT_SENSOR)
91
+    const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, extruder);
92 92
   #endif
93 93
 
94 94
   //action:out_of_filament
@@ -124,8 +124,22 @@ void event_filament_runout() {
124 124
     SERIAL_EOL();
125 125
   #endif // HOST_ACTION_COMMANDS
126 126
 
127
-  if (run_runout_script)
128
-    queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
127
+  if (run_runout_script) {
128
+    #if MULTI_FILAMENT_SENSOR
129
+      char script[strlen(FILAMENT_RUNOUT_SCRIPT) + 1];
130
+      sprintf_P(script, PSTR(FILAMENT_RUNOUT_SCRIPT), tool);
131
+      #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
132
+        SERIAL_ECHOLNPAIR("Runout Command: ", script);
133
+      #endif
134
+      queue.inject(script);
135
+    #else
136
+      #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
137
+        SERIAL_ECHOPGM("Runout Command: ");
138
+        SERIAL_ECHOLNPGM(FILAMENT_RUNOUT_SCRIPT);
139
+      #endif
140
+      queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
141
+    #endif
142
+  }
129 143
 }
130 144
 
131 145
 #endif // HAS_FILAMENT_SENSOR

+ 72
- 24
Marlin/src/feature/runout.h 查看文件

@@ -43,7 +43,7 @@
43 43
   #define FILAMENT_RUNOUT_THRESHOLD 5
44 44
 #endif
45 45
 
46
-void event_filament_runout();
46
+void event_filament_runout(const uint8_t extruder);
47 47
 
48 48
 template<class RESPONSE_T, class SENSOR_T>
49 49
 class TFilamentMonitor;
@@ -119,11 +119,41 @@ class TFilamentMonitor : public FilamentMonitorBase {
119 119
         TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, cli()); // Prevent RunoutResponseDelayed::block_completed from accumulating here
120 120
         response.run();
121 121
         sensor.run();
122
-        const bool ran_out = response.has_run_out();
122
+        const uint8_t runout_flags = response.has_run_out();
123 123
         TERN_(HAS_FILAMENT_RUNOUT_DISTANCE, sei());
124
+        #if MULTI_FILAMENT_SENSOR
125
+          #if ENABLED(WATCH_ALL_RUNOUT_SENSORS)
126
+            const bool ran_out = !!runout_flags;  // any sensor triggers
127
+            uint8_t extruder = 0;
128
+            if (ran_out) {
129
+              uint8_t bitmask = runout_flags;
130
+              while (!(bitmask & 1)) {
131
+                bitmask >>= 1;
132
+                extruder++;
133
+              }
134
+            }
135
+          #else
136
+            const bool ran_out = TEST(runout_flags, active_extruder);  // suppress non active extruders
137
+            uint8_t extruder = active_extruder;
138
+          #endif
139
+        #else
140
+          const bool ran_out = !!runout_flags;
141
+          uint8_t extruder = active_extruder;
142
+        #endif
143
+
144
+        #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
145
+          if (runout_flags) {
146
+            SERIAL_ECHOPGM("Runout Sensors: ");
147
+            LOOP_L_N(i, 8) SERIAL_ECHO('0' + TEST(runout_flags, i));
148
+            SERIAL_ECHOPAIR(" -> ", extruder);
149
+            if (ran_out) SERIAL_ECHOPGM(" RUN OUT");
150
+            SERIAL_EOL();
151
+          }
152
+        #endif
153
+
124 154
         if (ran_out) {
125 155
           filament_ran_out = true;
126
-          event_filament_runout();
156
+          event_filament_runout(extruder);
127 157
           planner.synchronize();
128 158
         }
129 159
       }
@@ -280,16 +310,17 @@ class FilamentSensorBase {
280 310
       static inline void block_completed(const block_t* const) {}
281 311
 
282 312
       static inline void run() {
283
-        const bool out = poll_runout_state(active_extruder);
284
-        if (!out) filament_present(active_extruder);
285
-        #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
286
-          static bool was_out = false;
287
-          if (out != was_out) {
288
-            was_out = out;
289
-            SERIAL_ECHOPGM("Filament ");
290
-            SERIAL_ECHOPGM_P(out ? PSTR("OUT\n") : PSTR("IN\n"));
291
-          }
292
-        #endif
313
+        LOOP_L_N(s, NUM_RUNOUT_SENSORS) {
314
+          const bool out = poll_runout_state(s);
315
+          if (!out) filament_present(s);
316
+          #if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
317
+            static uint8_t was_out; // = 0
318
+            if (out != TEST(was_out, s)) {
319
+              TBI(was_out, s);
320
+              SERIAL_ECHOLNPAIR_P(PSTR("Filament Sensor "), '0' + s, out ? PSTR(" OUT") : PSTR(" IN"));
321
+            }
322
+          #endif
323
+        }
293 324
       }
294 325
   };
295 326
 
@@ -305,13 +336,13 @@ class FilamentSensorBase {
305 336
   // during a runout condition.
306 337
   class RunoutResponseDelayed {
307 338
     private:
308
-      static volatile float runout_mm_countdown[EXTRUDERS];
339
+      static volatile float runout_mm_countdown[NUM_RUNOUT_SENSORS];
309 340
 
310 341
     public:
311 342
       static float runout_distance_mm;
312 343
 
313 344
       static inline void reset() {
314
-        LOOP_L_N(i, EXTRUDERS) filament_present(i);
345
+        LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i);
315 346
       }
316 347
 
317 348
       static inline void run() {
@@ -320,15 +351,17 @@ class FilamentSensorBase {
320 351
           const millis_t ms = millis();
321 352
           if (ELAPSED(ms, t)) {
322 353
             t = millis() + 1000UL;
323
-            LOOP_L_N(i, EXTRUDERS)
354
+            LOOP_L_N(i, NUM_RUNOUT_SENSORS)
324 355
               SERIAL_ECHOPAIR_P(i ? PSTR(", ") : PSTR("Remaining mm: "), runout_mm_countdown[i]);
325 356
             SERIAL_EOL();
326 357
           }
327 358
         #endif
328 359
       }
329 360
 
330
-      static inline bool has_run_out() {
331
-        return runout_mm_countdown[active_extruder] < 0;
361
+      static inline uint8_t has_run_out() {
362
+        uint8_t runout_flags = 0;
363
+        LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_mm_countdown[i] < 0) SBI(runout_flags, i);
364
+        return runout_flags;
332 365
       }
333 366
 
334 367
       static inline void filament_present(const uint8_t extruder) {
@@ -353,13 +386,28 @@ class FilamentSensorBase {
353 386
   class RunoutResponseDebounced {
354 387
     private:
355 388
       static constexpr int8_t runout_threshold = FILAMENT_RUNOUT_THRESHOLD;
356
-      static int8_t runout_count;
389
+      static int8_t runout_count[NUM_RUNOUT_SENSORS];
390
+
357 391
     public:
358
-      static inline void reset()                                  { runout_count = runout_threshold; }
359
-      static inline void run()                                    { if (runout_count >= 0) runout_count--; }
360
-      static inline bool has_run_out()                            { return runout_count < 0; }
361
-      static inline void block_completed(const block_t* const)    { }
362
-      static inline void filament_present(const uint8_t)          { runout_count = runout_threshold; }
392
+      static inline void reset() {
393
+        LOOP_L_N(i, NUM_RUNOUT_SENSORS) filament_present(i);
394
+      }
395
+
396
+      static inline void run() {
397
+        LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] >= 0) runout_count[i]--;
398
+      }
399
+
400
+      static inline uint8_t has_run_out() {
401
+        uint8_t runout_flags = 0;
402
+        LOOP_L_N(i, NUM_RUNOUT_SENSORS) if (runout_count[i] < 0) SBI(runout_flags, i);
403
+        return runout_flags;
404
+      }
405
+
406
+      static inline void block_completed(const block_t* const) { }
407
+
408
+      static inline void filament_present(const uint8_t extruder) {
409
+        runout_count[extruder] = runout_threshold;
410
+      }
363 411
   };
364 412
 
365 413
 #endif // !HAS_FILAMENT_RUNOUT_DISTANCE

+ 3
- 0
Marlin/src/inc/Conditionals_adv.h 查看文件

@@ -134,6 +134,9 @@
134 134
   #ifdef FILAMENT_RUNOUT_DISTANCE_MM
135 135
     #define HAS_FILAMENT_RUNOUT_DISTANCE 1
136 136
   #endif
137
+  #if ENABLED(MIXING_EXTRUDER)
138
+    #define WATCH_ALL_RUNOUT_SENSORS
139
+  #endif
137 140
 #endif
138 141
 
139 142
 // Let SD_FINISHED_RELEASECOMMAND stand in for SD_FINISHED_STEPPERRELEASE

+ 15
- 17
Marlin/src/inc/SanityCheck.h 查看文件

@@ -823,26 +823,24 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
823 823
 #if HAS_FILAMENT_SENSOR
824 824
   #if !PIN_EXISTS(FIL_RUNOUT)
825 825
     #error "FILAMENT_RUNOUT_SENSOR requires FIL_RUNOUT_PIN."
826
-  #elif NUM_RUNOUT_SENSORS > E_STEPPERS
827
-    #if HAS_PRUSA_MMU2
826
+  #elif HAS_PRUSA_MMU2 && NUM_RUNOUT_SENSORS != 1
828 827
       #error "NUM_RUNOUT_SENSORS must be 1 with MMU2 / MMU2S."
829
-    #else
830
-      #error "NUM_RUNOUT_SENSORS cannot exceed the number of E steppers."
831
-    #endif
832
-  #elif NUM_RUNOUT_SENSORS >= 2 && !PIN_EXISTS(FIL_RUNOUT2)
833
-    #error "FIL_RUNOUT2_PIN is required with NUM_RUNOUT_SENSORS >= 2."
834
-  #elif NUM_RUNOUT_SENSORS >= 3 && !PIN_EXISTS(FIL_RUNOUT3)
835
-    #error "FIL_RUNOUT3_PIN is required with NUM_RUNOUT_SENSORS >= 3."
836
-  #elif NUM_RUNOUT_SENSORS >= 4 && !PIN_EXISTS(FIL_RUNOUT4)
837
-    #error "FIL_RUNOUT4_PIN is required with NUM_RUNOUT_SENSORS >= 4."
838
-  #elif NUM_RUNOUT_SENSORS >= 5 && !PIN_EXISTS(FIL_RUNOUT5)
839
-    #error "FIL_RUNOUT5_PIN is required with NUM_RUNOUT_SENSORS >= 5."
840
-  #elif NUM_RUNOUT_SENSORS >= 6 && !PIN_EXISTS(FIL_RUNOUT6)
841
-    #error "FIL_RUNOUT6_PIN is required with NUM_RUNOUT_SENSORS >= 6."
842
-  #elif NUM_RUNOUT_SENSORS >= 7 && !PIN_EXISTS(FIL_RUNOUT7)
843
-    #error "FIL_RUNOUT7_PIN is required with NUM_RUNOUT_SENSORS >= 7."
828
+  #elif NUM_RUNOUT_SENSORS != 1 && NUM_RUNOUT_SENSORS != E_STEPPERS
829
+    #error "NUM_RUNOUT_SENSORS must be either 1 or number of E steppers."
844 830
   #elif NUM_RUNOUT_SENSORS >= 8 && !PIN_EXISTS(FIL_RUNOUT8)
845 831
     #error "FIL_RUNOUT8_PIN is required with NUM_RUNOUT_SENSORS >= 8."
832
+  #elif NUM_RUNOUT_SENSORS >= 7 && !PIN_EXISTS(FIL_RUNOUT7)
833
+    #error "FIL_RUNOUT7_PIN is required with NUM_RUNOUT_SENSORS >= 7."
834
+  #elif NUM_RUNOUT_SENSORS >= 6 && !PIN_EXISTS(FIL_RUNOUT6)
835
+    #error "FIL_RUNOUT6_PIN is required with NUM_RUNOUT_SENSORS >= 6."
836
+  #elif NUM_RUNOUT_SENSORS >= 5 && !PIN_EXISTS(FIL_RUNOUT5)
837
+    #error "FIL_RUNOUT5_PIN is required with NUM_RUNOUT_SENSORS >= 5."
838
+  #elif NUM_RUNOUT_SENSORS >= 4 && !PIN_EXISTS(FIL_RUNOUT4)
839
+    #error "FIL_RUNOUT4_PIN is required with NUM_RUNOUT_SENSORS >= 4."
840
+  #elif NUM_RUNOUT_SENSORS >= 3 && !PIN_EXISTS(FIL_RUNOUT3)
841
+    #error "FIL_RUNOUT3_PIN is required with NUM_RUNOUT_SENSORS >= 3."
842
+  #elif NUM_RUNOUT_SENSORS >= 2 && !PIN_EXISTS(FIL_RUNOUT2)
843
+    #error "FIL_RUNOUT2_PIN is required with NUM_RUNOUT_SENSORS >= 2."
846 844
   #elif BOTH(FIL_RUNOUT1_PULLUP, FIL_RUNOUT1_PULLDOWN)
847 845
     #error "You can't enable FIL_RUNOUT1_PULLUP and FIL_RUNOUT1_PULLDOWN at the same time."
848 846
   #elif BOTH(FIL_RUNOUT2_PULLUP, FIL_RUNOUT2_PULLDOWN)

+ 15
- 17
Marlin/src/module/endstops.cpp 查看文件

@@ -468,24 +468,22 @@ void _O2 Endstops::report_states() {
468 468
   #if HAS_CUSTOM_PROBE_PIN
469 469
     print_es_state(PROBE_TRIGGERED(), PSTR(STR_Z_PROBE));
470 470
   #endif
471
-  #if HAS_FILAMENT_SENSOR
472
-    #if NUM_RUNOUT_SENSORS == 1
473
-      print_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
474
-    #else
475
-      #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; state = FIL_RUNOUT##N##_STATE; break;
476
-      LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) {
477
-        pin_t pin;
478
-        uint8_t state;
479
-        switch (i) {
480
-          default: continue;
481
-          REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _CASE_RUNOUT)
482
-        }
483
-        SERIAL_ECHOPGM(STR_FILAMENT_RUNOUT_SENSOR);
484
-        if (i > 1) SERIAL_CHAR(' ', '0' + i);
485
-        print_es_state(extDigitalRead(pin) != state);
471
+  #if MULTI_FILAMENT_SENSOR
472
+    #define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; state = FIL_RUNOUT##N##_STATE; break;
473
+    LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) {
474
+      pin_t pin;
475
+      uint8_t state;
476
+      switch (i) {
477
+        default: continue;
478
+        REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _CASE_RUNOUT)
486 479
       }
487
-      #undef _CASE_RUNOUT
488
-    #endif
480
+      SERIAL_ECHOPGM(STR_FILAMENT_RUNOUT_SENSOR);
481
+      if (i > 1) SERIAL_CHAR(' ', '0' + i);
482
+      print_es_state(extDigitalRead(pin) != state);
483
+    }
484
+    #undef _CASE_RUNOUT
485
+  #elif HAS_FILAMENT_SENSOR
486
+    print_es_state(READ(FIL_RUNOUT1_PIN) != FIL_RUNOUT1_STATE, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
489 487
   #endif
490 488
 
491 489
   TERN_(BLTOUCH, bltouch._reset_SW_mode());

+ 7
- 1
buildroot/tests/mega2560-tests 查看文件

@@ -94,8 +94,14 @@ restore_configs
94 94
 opt_set MOTHERBOARD BOARD_AZTEEG_X3_PRO
95 95
 opt_set LCD_LANGUAGE el_gr
96 96
 opt_enable MIXING_EXTRUDER GRADIENT_MIX GRADIENT_VTOOL CR10_STOCKDISPLAY \
97
-           USE_CONTROLLER_FAN CONTROLLER_FAN_EDITABLE CONTROLLER_FAN_IGNORE_Z
97
+           USE_CONTROLLER_FAN CONTROLLER_FAN_EDITABLE CONTROLLER_FAN_IGNORE_Z \
98
+           FILAMENT_RUNOUT_SENSOR ADVANCED_PAUSE_FEATURE NOZZLE_PARK_FEATURE
98 99
 opt_set MIXING_STEPPERS 5
100
+opt_set NUM_RUNOUT_SENSORS E_STEPPERS
101
+opt_set FIL_RUNOUT2_PIN 16
102
+opt_set FIL_RUNOUT3_PIN 17
103
+opt_set FIL_RUNOUT4_PIN  4
104
+opt_set FIL_RUNOUT5_PIN  5
99 105
 opt_set LCD_LANGUAGE ru
100 106
 exec_test $1 $2 "Azteeg X3 | Mixing Extruder (x5) | Gradient Mix | Greek" "$3"
101 107
 

Loading…
取消
儲存