Browse Source

Tweak Filament Width variables

Scott Lahteine 8 years ago
parent
commit
6ac9d895ca
4 changed files with 19 additions and 21 deletions
  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 View File

342
 #endif
342
 #endif
343
 
343
 
344
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
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
 #endif
351
 #endif
352
 
352
 
353
 #if ENABLED(FILAMENT_CHANGE_FEATURE)
353
 #if ENABLED(FILAMENT_CHANGE_FEATURE)

+ 6
- 8
Marlin/Marlin_main.cpp View File

500
 #endif
500
 #endif
501
 
501
 
502
 #if ENABLED(FILAMENT_WIDTH_SENSOR)
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
   bool filament_sensor = false;  //M405 turns on filament_sensor control, M406 turns it off
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
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
508
   int meas_delay_cm = MEASUREMENT_DELAY_CM;  //distance delay setting
511
 #endif
509
 #endif
512
 
510
 
6137
     if (code_seen('D')) meas_delay_cm = code_value_int();
6135
     if (code_seen('D')) meas_delay_cm = code_value_int();
6138
     NOMORE(meas_delay_cm, MAX_MEASUREMENT_DELAY);
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
       int temp_ratio = thermalManager.widthFil_to_size_ratio();
6139
       int temp_ratio = thermalManager.widthFil_to_size_ratio();
6142
 
6140
 
6143
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
6141
       for (uint8_t i = 0; i < COUNT(measurement_delay); ++i)
6144
         measurement_delay[i] = temp_ratio - 100;  // Subtract 100 to scale within a signed byte
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
     filament_sensor = true;
6147
     filament_sensor = true;

+ 6
- 6
Marlin/planner.cpp View File

868
     static float filwidth_e_count = 0, filwidth_delay_dist = 0;
868
     static float filwidth_e_count = 0, filwidth_delay_dist = 0;
869
 
869
 
870
     //FMM update ring buffer used for delay with filament measurements
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
       const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
873
       const int MMD_CM = MAX_MEASUREMENT_DELAY + 1, MMD_MM = MMD_CM * 10;
874
 
874
 
883
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
883
         while (filwidth_delay_dist >= MMD_MM) filwidth_delay_dist -= MMD_MM;
884
 
884
 
885
         // Convert into an index into the measurement array
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
         // If the index has changed (must have gone forward)...
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
           filwidth_e_count = 0; // Reset the E movement counter
890
           filwidth_e_count = 0; // Reset the E movement counter
891
           int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
891
           int8_t meas_sample = thermalManager.widthFil_to_size_ratio() - 100; // Subtract 100 to reduce magnitude - to store in a signed char
892
           do {
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 View File

755
   // Control the extruder rate based on the width sensor
755
   // Control the extruder rate based on the width sensor
756
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
756
   #if ENABLED(FILAMENT_WIDTH_SENSOR)
757
     if (filament_sensor) {
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
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
759
       if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1;  //loop around buffer if needed
760
 
760
 
761
       // Get the delayed info and add 100 to reconstitute to a percent of
761
       // Get the delayed info and add 100 to reconstitute to a percent of

Loading…
Cancel
Save