Преглед изворни кода

Tweak Filament Width variables

Scott Lahteine пре 8 година
родитељ
комит
6ac9d895ca
4 измењених фајлова са 19 додато и 21 уклоњено
  1. 6
    6
      Marlin/Marlin.h
  2. 6
    8
      Marlin/Marlin_main.cpp
  3. 6
    6
      Marlin/planner.cpp
  4. 1
    1
      Marlin/temperature.cpp

+ 6
- 6
Marlin/Marlin.h Прегледај датотеку

@@ -342,12 +342,12 @@ float code_value_temp_diff();
342 342
 #endif
343 343
 
344 344
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
345
-  extern float filament_width_nominal;  //holds the theoretical filament diameter i.e., 3.00 or 1.75
346
-  extern bool filament_sensor;  //indicates that filament sensor readings should control extrusion
347
-  extern float filament_width_meas; //holds the filament diameter as accurately measured
348
-  extern int8_t measurement_delay[];  //ring buffer to delay measurement
349
-  extern int filwidth_delay_index1, filwidth_delay_index2;  //ring buffer index. used by planner, temperature, and main code
350
-  extern int meas_delay_cm; //delay distance
345
+  extern bool filament_sensor;         // Flag that filament sensor readings should control extrusion
346
+  extern float filament_width_nominal, // Theoretical filament diameter i.e., 3.00 or 1.75
347
+               filament_width_meas;    // Measured filament diameter
348
+  extern int8_t measurement_delay[];   // Ring buffer to delay measurement
349
+  extern int filwidth_delay_index[2];  // Ring buffer indexes. Used by planner, temperature, and main code
350
+  extern int meas_delay_cm;            // Delay distance
351 351
 #endif
352 352
 
353 353
 #if ENABLED(FILAMENT_CHANGE_FEATURE)

+ 6
- 8
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -500,13 +500,11 @@ static uint8_t target_extruder;
500 500
 #endif
501 501
 
502 502
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
503
-  //Variables for Filament Sensor input
504
-  float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA;  //Set nominal filament width, can be changed with M404
505 503
   bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
506
-  float filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA; //Stores the measured filament diameter
507
-  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; //ring buffer to delay measurement  store extruder factor after subtracting 100
508
-  int filwidth_delay_index1 = 0;  //index into ring buffer
509
-  int filwidth_delay_index2 = -1;  //index into ring buffer - set to -1 on startup to indicate ring buffer needs to be initialized
504
+  float filament_width_nominal = DEFAULT_NOMINAL_FILAMENT_DIA,  // Nominal filament width. Change with M404
505
+        filament_width_meas = DEFAULT_MEASURED_FILAMENT_DIA;    // Measured filament diameter
506
+  int8_t measurement_delay[MAX_MEASUREMENT_DELAY + 1]; // Ring buffer to delayed measurement. Store extruder factor after subtracting 100
507
+  int filwidth_delay_index[2] = { 0, -1 };  // Indexes into ring buffer
510 508
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
511 509
 #endif
512 510
 
@@ -6137,13 +6135,13 @@ inline void gcode_M400() { stepper.synchronize(); }
6137 6135
     if (code_seen('D')) meas_delay_cm = code_value_int();
6138 6136
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
6139 6137
 
6140
-    if (filwidth_delay_index2 == -1) { // Initialize the ring buffer if not done since startup
6138
+    if (filwidth_delay_index[1] == -1) { // Initialize the ring buffer if not done since startup
6141 6139
       int temp_ratio = thermalManager.widthFil_to_size_ratio();
6142 6140
 
6143 6141
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
6144 6142
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
6145 6143
 
6146
-      filwidth_delay_index1 = filwidth_delay_index2 = 0;
6144
+      filwidth_delay_index[0] = filwidth_delay_index[1] = 0;
6147 6145
     }
6148 6146
 
6149 6147
     filament_sensor = true;

+ 6
- 6
Marlin/planner.cpp Прегледај датотеку

@@ -868,7 +868,7 @@ void Planner::check_axes_activity() {
868 868
     static float filwidth_e_count = 0, filwidth_delay_dist = 0;
869 869
 
870 870
     //FMM update ring buffer used for delay with filament measurements
871
-    if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index2 >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
871
+    if (extruder == FILAMENT_SENSOR_EXTRUDER_NUM && filwidth_delay_index[1] >= 0) {  //only for extruder with filament sensor and if ring buffer is initialized
872 872
 
873 873
       const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
874 874
 
@@ -883,16 +883,16 @@ void Planner::check_axes_activity() {
883 883
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
884 884
 
885 885
         // Convert into an index into the measurement array
886
-        filwidth_delay_index1 = (int)(filwidth_delay_dist * 0.1 + 0.0001);
886
+        filwidth_delay_index[0] = (int)(filwidth_delay_dist * 0.1 + 0.0001);
887 887
 
888 888
         // If the index has changed (must have gone forward)...
889
-        if (filwidth_delay_index1 != filwidth_delay_index2) {
889
+        if (filwidth_delay_index[0] != filwidth_delay_index[1]) {
890 890
           filwidth_e_count = 0; // Reset the E movement counter
891 891
           int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
892 892
           do {
893
-            filwidth_delay_index2 = (filwidth_delay_index2 + 1) % MMD_CM; // The next unused slot
894
-            measurement_delay[filwidth_delay_index2] = meas_sample;       // Store the measurement
895
-          } while (filwidth_delay_index1 != filwidth_delay_index2);       // More slots to fill?
893
+            filwidth_delay_index[1] = (filwidth_delay_index[1] + 1) % MMD_CM; // The next unused slot
894
+            measurement_delay[filwidth_delay_index[1]] = meas_sample;         // Store the measurement
895
+          } while (filwidth_delay_index[0] != filwidth_delay_index[1]);       // More slots to fill?
896 896
         }
897 897
       }
898 898
     }

+ 1
- 1
Marlin/temperature.cpp Прегледај датотеку

@@ -755,7 +755,7 @@ void Temperature::manage_heater() {
755 755
   // Control the extruder rate based on the width sensor
756 756
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
757 757
     if (filament_sensor) {
758
-      meas_shift_index = filwidth_delay_index1 - meas_delay_cm;
758
+      meas_shift_index = filwidth_delay_index[0] - meas_delay_cm;
759 759
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
760 760
 
761 761
       // Get the delayed info and add 100 to reconstitute to a percent of

Loading…
Откажи
Сачувај