浏览代码

Merge pull request #8772 from thinkyhead/bf1_filwidth_refinement

[1.1.x] Comment, fix filament width sensor
Scott Lahteine 7 年前
父节点
当前提交
be58e137c5
没有帐户链接到提交者的电子邮件
共有 8 个文件被更改,包括 69 次插入48 次删除
  1. 1
    6
      Marlin/Marlin_main.cpp
  2. 29
    1
      Marlin/planner.cpp
  3. 4
    0
      Marlin/planner.h
  4. 3
    3
      Marlin/stepper.cpp
  5. 17
    26
      Marlin/temperature.cpp
  6. 2
    2
      Marlin/temperature.h
  7. 6
    4
      Marlin/ultralcd_impl_DOGM.h
  8. 7
    6
      Marlin/ultralcd_impl_HD44780.h

+ 1
- 6
Marlin/Marlin_main.cpp 查看文件

@@ -9553,7 +9553,7 @@ inline void gcode_M400() { stepper.synchronize(); }
9553 9553
     }
9554 9554
 
9555 9555
     if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
9556
-      const uint8_t temp_ratio = thermalManager.widthFil_to_size_ratio() - 100; // -100 to scale within a signed byte
9556
+      const uint8_t temp_ratio = thermalManager.widthFil_to_size_ratio();
9557 9557
 
9558 9558
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
9559 9559
         measurement_delay[i] = temp_ratio;
@@ -9562,11 +9562,6 @@ inline void gcode_M400() { stepper.synchronize(); }
9562 9562
     }
9563 9563
 
9564 9564
     filament_sensor = true;
9565
-
9566
-    //SERIAL_PROTOCOLPGM("Filament dia (measured mm):");
9567
-    //SERIAL_PROTOCOL(filament_width_meas);
9568
-    //SERIAL_PROTOCOLPGM("Extrusion ratio(%):");
9569
-    //SERIAL_PROTOCOL(planner.flow_percentage[active_extruder]);
9570 9565
   }
9571 9566
 
9572 9567
   /**

+ 29
- 1
Marlin/planner.cpp 查看文件

@@ -550,10 +550,19 @@ void Planner::check_axes_activity() {
550 550
   #endif
551 551
 }
552 552
 
553
+/**
554
+ * Get a volumetric multiplier from a filament diameter.
555
+ * This is the reciprocal of the circular cross-section area.
556
+ * Return 1.0 with volumetric off or a diameter of 0.0.
557
+ */
553 558
 inline float calculate_volumetric_multiplier(const float &diameter) {
554 559
   return (parser.volumetric_enabled && diameter) ? 1.0 / CIRCLE_AREA(diameter * 0.5) : 1.0;
555 560
 }
556 561
 
562
+/**
563
+ * Convert the filament sizes into volumetric multipliers.
564
+ * The multiplier converts a given E value into a length.
565
+ */
557 566
 void Planner::calculate_volumetric_multipliers() {
558 567
   for (uint8_t i = 0; i < COUNT(filament_size); i++) {
559 568
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
@@ -561,6 +570,25 @@ void Planner::calculate_volumetric_multipliers() {
561 570
   }
562 571
 }
563 572
 
573
+#if ENABLED(FILAMENT_WIDTH_SENSOR)
574
+  /**
575
+   * Convert the ratio value given by the filament width sensor
576
+   * into a volumetric multiplier. Conversion differs when using
577
+   * linear extrusion vs volumetric extrusion.
578
+   */
579
+  void Planner::calculate_volumetric_for_width_sensor(const int8_t encoded_ratio) {
580
+    // Reconstitute the nominal/measured ratio
581
+    const float nom_meas_ratio = 1.0 + 0.01 * encoded_ratio,
582
+                ratio_2 = sq(nom_meas_ratio);
583
+
584
+    volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = parser.volumetric_enabled
585
+      ? ratio_2 / CIRCLE_AREA(filament_width_nominal * 0.5) // Volumetric uses a true volumetric multiplier
586
+      : ratio_2;                                            // Linear squares the ratio, which scales the volume
587
+
588
+    refresh_e_factor(FILAMENT_SENSOR_EXTRUDER_NUM);
589
+  }
590
+#endif
591
+
564 592
 #if PLANNER_LEVELING
565 593
   /**
566 594
    * rx, ry, rz - Cartesian positions in mm
@@ -1046,7 +1074,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE], float fr_mm_s, const
1046 1074
         // If the index has changed (must have gone forward)...
1047 1075
         if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
1048 1076
           filwidth_e_count = 0; // Reset the E movement counter
1049
-          const uint8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
1077
+          const uint8_t meas_sample = thermalManager.widthFil_to_size_ratio();
1050 1078
           do {
1051 1079
             filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
1052 1080
             measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement

+ 4
- 0
Marlin/planner.h 查看文件

@@ -289,6 +289,10 @@ class Planner {
289 289
     // Update multipliers based on new diameter measurements
290 290
     static void calculate_volumetric_multipliers();
291 291
 
292
+    #if ENABLED(FILAMENT_WIDTH_SENSOR)
293
+      void calculate_volumetric_for_width_sensor(const int8_t encoded_ratio);
294
+    #endif
295
+
292 296
     FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
293 297
       filament_size[e] = v;
294 298
       // make sure all extruders have some sane value for the filament size

+ 3
- 3
Marlin/stepper.cpp 查看文件

@@ -723,7 +723,7 @@ void Stepper::isr() {
723 723
     // step_rate to timer interval
724 724
     const uint16_t interval = calc_timer_interval(acc_step_rate);
725 725
 
726
-    SPLIT(interval);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
726
+    SPLIT(interval);  // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
727 727
     _NEXT_ISR(ocr_val);
728 728
 
729 729
     acceleration_time += interval;
@@ -756,7 +756,7 @@ void Stepper::isr() {
756 756
     // step_rate to timer interval
757 757
     const uint16_t interval = calc_timer_interval(step_rate);
758 758
 
759
-    SPLIT(interval);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
759
+    SPLIT(interval);  // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
760 760
     _NEXT_ISR(ocr_val);
761 761
 
762 762
     deceleration_time += interval;
@@ -786,7 +786,7 @@ void Stepper::isr() {
786 786
 
787 787
     #endif
788 788
 
789
-    SPLIT(OCR1A_nominal);  // split step into multiple ISRs if larger than  ENDSTOP_NOMINAL_OCR_VAL
789
+    SPLIT(OCR1A_nominal);  // split step into multiple ISRs if larger than ENDSTOP_NOMINAL_OCR_VAL
790 790
     _NEXT_ISR(ocr_val);
791 791
 
792 792
     // ensure we're running at the correct step rate, even if we just came off an acceleration

+ 17
- 26
Marlin/temperature.cpp 查看文件

@@ -736,17 +736,6 @@ float Temperature::get_pid_output(const int8_t e) {
736 736
  *  - Apply filament width to the extrusion rate (may move)
737 737
  *  - Update the heated bed PID output value
738 738
  */
739
-
740
-/**
741
- * The following line SOMETIMES results in the dreaded "unable to find a register to spill in class 'POINTER_REGS'"
742
- * compile error.
743
- *    thermal_runaway_protection(&thermal_runaway_state_machine[e], &thermal_runaway_timer[e], current_temperature[e], target_temperature[e], e, THERMAL_PROTECTION_PERIOD, THERMAL_PROTECTION_HYSTERESIS);
744
- *
745
- * This is due to a bug in the C++ compiler used by the Arduino IDE from 1.6.10 to at least 1.8.1.
746
- *
747
- * The work around is to add the compiler flag "__attribute__((__optimize__("O2")))" to the declaration for manage_heater()
748
- */
749
-//void Temperature::manage_heater()  __attribute__((__optimize__("O2")));
750 739
 void Temperature::manage_heater() {
751 740
 
752 741
   if (!temp_meas_ready) return;
@@ -801,19 +790,16 @@ void Temperature::manage_heater() {
801 790
     }
802 791
   #endif
803 792
 
804
-  // Control the extruder rate based on the width sensor
805 793
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
794
+    /**
795
+     * Filament Width Sensor dynamically sets the volumetric multiplier
796
+     * based on a delayed measurement of the filament diameter.
797
+     */
806 798
     if (filament_sensor) {
807 799
       meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
808 800
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
809 801
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
810
-
811
-      // Get the delayed info and add 100 to reconstitute to a percent of
812
-      // the nominal filament diameter then square it to get an area
813
-      float vmroot = measurement_delay[meas_shift_index] * 0.01 + 1.0;
814
-      NOLESS(vmroot, 0.1);
815
-      planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM] = 1.0 / CIRCLE_AREA(vmroot / 2);
816
-      planner.refresh_e_factor(FILAMENT_SENSOR_EXTRUDER_NUM);
802
+      calculate_volumetric_for_width_sensor(measurement_delay[meas_shift_index])
817 803
     }
818 804
   #endif // FILAMENT_WIDTH_SENSOR
819 805
 
@@ -999,15 +985,20 @@ void Temperature::updateTemperaturesFromRawValues() {
999 985
   // Convert raw Filament Width to millimeters
1000 986
   float Temperature::analog2widthFil() {
1001 987
     return current_raw_filwidth * 5.0 * (1.0 / 16383.0);
1002
-    //return current_raw_filwidth;
1003 988
   }
1004 989
 
1005
-  // Convert raw Filament Width to a ratio
1006
-  int Temperature::widthFil_to_size_ratio() {
1007
-    float temp = filament_width_meas;
1008
-    if (temp < MEASURED_LOWER_LIMIT) temp = filament_width_nominal;  //assume sensor cut out
1009
-    else NOMORE(temp, MEASURED_UPPER_LIMIT);
1010
-    return filament_width_nominal / temp * 100;
990
+  /**
991
+   * Convert Filament Width (mm) to a simple ratio
992
+   * and reduce to an 8 bit value.
993
+   *
994
+   * A nominal width of 1.75 and measured width of 1.73
995
+   * gives (100 * 1.75 / 1.73) for a ratio of 101 and
996
+   * a return value of 1.
997
+   */
998
+  int8_t Temperature::widthFil_to_size_ratio() {
999
+    if (WITHIN(filament_width_meas, MEASURED_LOWER_LIMIT, MEASURED_UPPER_LIMIT))
1000
+      return int(100.0 * filament_width_nominal / filament_width_meas) - 100;
1001
+    return 0;
1011 1002
   }
1012 1003
 
1013 1004
 #endif

+ 2
- 2
Marlin/temperature.h 查看文件

@@ -333,8 +333,8 @@ class Temperature {
333 333
     #endif
334 334
 
335 335
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
336
-      static float analog2widthFil(); // Convert raw Filament Width to millimeters
337
-      static int widthFil_to_size_ratio(); // Convert raw Filament Width to an extrusion ratio
336
+      static float analog2widthFil();         // Convert raw Filament Width to millimeters
337
+      static int8_t widthFil_to_size_ratio(); // Convert Filament Width (mm) to an extrusion ratio
338 338
     #endif
339 339
 
340 340
 

+ 6
- 4
Marlin/ultralcd_impl_DOGM.h 查看文件

@@ -650,10 +650,12 @@ static void lcd_implementation_status_screen() {
650 650
     strcpy(zstring, ftostr52sp(FIXFLOAT(LOGICAL_Z_POSITION(current_position[Z_AXIS]))));
651 651
     #if ENABLED(FILAMENT_LCD_DISPLAY)
652 652
       strcpy(wstring, ftostr12ns(filament_width_meas));
653
-      if (parser.volumetric_enabled)
654
-        strcpy(mstring, itostr3(100.0 * planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
655
-      else
656
-        strcpy_P(mstring, PSTR("---"));
653
+      strcpy(mstring, itostr3(100.0 * (
654
+          parser.volumetric_enabled
655
+            ? planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
656
+            : planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
657
+        )
658
+      ));
657 659
     #endif
658 660
   }
659 661
 

+ 7
- 6
Marlin/ultralcd_impl_HD44780.h 查看文件

@@ -881,12 +881,13 @@ static void lcd_implementation_status_screen() {
881 881
       lcd_printPGM(PSTR("Dia "));
882 882
       lcd.print(ftostr12ns(filament_width_meas));
883 883
       lcd_printPGM(PSTR(" V"));
884
-      if (parser.volumetric_enabled) {
885
-        lcd.print(itostr3(100.0 * planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
886
-        lcd.write('%');
887
-      }
888
-      else
889
-        lcd_printPGM(PSTR("--- "));
884
+      lcd.print(itostr3(100.0 * (
885
+          parser.volumetric_enabled
886
+            ? planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
887
+            : planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
888
+        )
889
+      ));
890
+      lcd.write('%');
890 891
       return;
891 892
     }
892 893
 

正在加载...
取消
保存