Bläddra i källkod

Merge pull request #8772 from thinkyhead/bf1_filwidth_refinement

[1.1.x] Comment, fix filament width sensor
Scott Lahteine 7 år sedan
förälder
incheckning
be58e137c5
Inget konto är kopplat till bidragsgivarens mejladress

+ 1
- 6
Marlin/Marlin_main.cpp Visa fil

9553
     }
9553
     }
9554
 
9554
 
9555
     if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
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
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
9558
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
9559
         measurement_delay[i] = temp_ratio;
9559
         measurement_delay[i] = temp_ratio;
9562
     }
9562
     }
9563
 
9563
 
9564
     filament_sensor = true;
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 Visa fil

550
   #endif
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
 inline float calculate_volumetric_multiplier(const float &diameter) {
558
 inline float calculate_volumetric_multiplier(const float &diameter) {
554
   return (parser.volumetric_enabled && diameter) ? 1.0 / CIRCLE_AREA(diameter * 0.5) : 1.0;
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
 void Planner::calculate_volumetric_multipliers() {
566
 void Planner::calculate_volumetric_multipliers() {
558
   for (uint8_t i = 0; i < COUNT(filament_size); i++) {
567
   for (uint8_t i = 0; i < COUNT(filament_size); i++) {
559
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
568
     volumetric_multiplier[i] = calculate_volumetric_multiplier(filament_size[i]);
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
 #if PLANNER_LEVELING
592
 #if PLANNER_LEVELING
565
   /**
593
   /**
566
    * rx, ry, rz - Cartesian positions in mm
594
    * rx, ry, rz - Cartesian positions in mm
1046
         // If the index has changed (must have gone forward)...
1074
         // If the index has changed (must have gone forward)...
1047
         if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
1075
         if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
1048
           filwidth_e_count = 0; // Reset the E movement counter
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
           do {
1078
           do {
1051
             filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
1079
             filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
1052
             measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement
1080
             measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement

+ 4
- 0
Marlin/planner.h Visa fil

289
     // Update multipliers based on new diameter measurements
289
     // Update multipliers based on new diameter measurements
290
     static void calculate_volumetric_multipliers();
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
     FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
296
     FORCE_INLINE static void set_filament_size(const uint8_t e, const float &v) {
293
       filament_size[e] = v;
297
       filament_size[e] = v;
294
       // make sure all extruders have some sane value for the filament size
298
       // make sure all extruders have some sane value for the filament size

+ 3
- 3
Marlin/stepper.cpp Visa fil

723
     // step_rate to timer interval
723
     // step_rate to timer interval
724
     const uint16_t interval = calc_timer_interval(acc_step_rate);
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
     _NEXT_ISR(ocr_val);
727
     _NEXT_ISR(ocr_val);
728
 
728
 
729
     acceleration_time += interval;
729
     acceleration_time += interval;
756
     // step_rate to timer interval
756
     // step_rate to timer interval
757
     const uint16_t interval = calc_timer_interval(step_rate);
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
     _NEXT_ISR(ocr_val);
760
     _NEXT_ISR(ocr_val);
761
 
761
 
762
     deceleration_time += interval;
762
     deceleration_time += interval;
786
 
786
 
787
     #endif
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
     _NEXT_ISR(ocr_val);
790
     _NEXT_ISR(ocr_val);
791
 
791
 
792
     // ensure we're running at the correct step rate, even if we just came off an acceleration
792
     // ensure we're running at the correct step rate, even if we just came off an acceleration

+ 17
- 26
Marlin/temperature.cpp Visa fil

736
  *  - Apply filament width to the extrusion rate (may move)
736
  *  - Apply filament width to the extrusion rate (may move)
737
  *  - Update the heated bed PID output value
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
 void Temperature::manage_heater() {
739
 void Temperature::manage_heater() {
751
 
740
 
752
   if (!temp_meas_ready) return;
741
   if (!temp_meas_ready) return;
801
     }
790
     }
802
   #endif
791
   #endif
803
 
792
 
804
-  // Control the extruder rate based on the width sensor
805
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
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
     if (filament_sensor) {
798
     if (filament_sensor) {
807
       meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
799
       meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
808
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
800
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
809
       meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY);
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
   #endif // FILAMENT_WIDTH_SENSOR
804
   #endif // FILAMENT_WIDTH_SENSOR
819
 
805
 
999
   // Convert raw Filament Width to millimeters
985
   // Convert raw Filament Width to millimeters
1000
   float Temperature::analog2widthFil() {
986
   float Temperature::analog2widthFil() {
1001
     return current_raw_filwidth * 5.0 * (1.0 / 16383.0);
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
 #endif
1004
 #endif

+ 2
- 2
Marlin/temperature.h Visa fil

333
     #endif
333
     #endif
334
 
334
 
335
     #if ENABLED(FILAMENT_WIDTH_SENSOR)
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
     #endif
338
     #endif
339
 
339
 
340
 
340
 

+ 6
- 4
Marlin/ultralcd_impl_DOGM.h Visa fil

650
     strcpy(zstring, ftostr52sp(FIXFLOAT(LOGICAL_Z_POSITION(current_position[Z_AXIS]))));
650
     strcpy(zstring, ftostr52sp(FIXFLOAT(LOGICAL_Z_POSITION(current_position[Z_AXIS]))));
651
     #if ENABLED(FILAMENT_LCD_DISPLAY)
651
     #if ENABLED(FILAMENT_LCD_DISPLAY)
652
       strcpy(wstring, ftostr12ns(filament_width_meas));
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
     #endif
659
     #endif
658
   }
660
   }
659
 
661
 

+ 7
- 6
Marlin/ultralcd_impl_HD44780.h Visa fil

881
       lcd_printPGM(PSTR("Dia "));
881
       lcd_printPGM(PSTR("Dia "));
882
       lcd.print(ftostr12ns(filament_width_meas));
882
       lcd.print(ftostr12ns(filament_width_meas));
883
       lcd_printPGM(PSTR(" V"));
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
       return;
891
       return;
891
     }
892
     }
892
 
893
 

Laddar…
Avbryt
Spara