Переглянути джерело

Store Mix factors as reciprocals and multiply

Scott Lahteine 8 роки тому
джерело
коміт
f663220e87
3 змінених файлів з 18 додано та 17 видалено
  1. 15
    16
      Marlin/Marlin_main.cpp
  2. 2
    0
      Marlin/macros.h
  3. 1
    1
      Marlin/planner.cpp

+ 15
- 16
Marlin/Marlin_main.cpp Переглянути файл

@@ -590,7 +590,7 @@ float cartes[XYZ] = { 0 };
590 590
 #endif
591 591
 
592 592
 #if ENABLED(MIXING_EXTRUDER)
593
-  float mixing_factor[MIXING_STEPPERS];
593
+  float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
594 594
   #if MIXING_VIRTUAL_TOOLS > 1
595 595
     float mixing_virtual_tool_mix[MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
596 596
   #endif
@@ -2650,17 +2650,11 @@ static void homeaxis(AxisEnum axis) {
2650 2650
 
2651 2651
   void normalize_mix() {
2652 2652
     float mix_total = 0.0;
2653
-    for (int i = 0; i < MIXING_STEPPERS; i++) {
2654
-      float v = mixing_factor[i];
2655
-      if (v < 0) v = mixing_factor[i] = 0;
2656
-      mix_total += v;
2657
-    }
2653
+    for (int i = 0; i < MIXING_STEPPERS; i++) mix_total += RECIPROCAL(mixing_factor[i]);
2658 2654
     // Scale all values if they don't add up to ~1.0
2659
-    if (mix_total < 0.9999 || mix_total > 1.0001) {
2655
+    if (!NEAR(mix_total, 1.0)) {
2660 2656
       SERIAL_PROTOCOLLNPGM("Warning: Mix factors must add up to 1.0. Scaling.");
2661
-      float mix_scale = 1.0 / mix_total;
2662
-      for (int i = 0; i < MIXING_STEPPERS; i++)
2663
-        mixing_factor[i] *= mix_scale;
2657
+      for (int i = 0; i < MIXING_STEPPERS; i++) mixing_factor[i] *= mix_total;
2664 2658
     }
2665 2659
   }
2666 2660
 
@@ -2670,9 +2664,11 @@ static void homeaxis(AxisEnum axis) {
2670 2664
     // The total "must" be 1.0 (but it will be normalized)
2671 2665
     void gcode_get_mix() {
2672 2666
       const char* mixing_codes = "ABCDHI";
2673
-      for (int i = 0; i < MIXING_STEPPERS; i++)
2674
-        mixing_factor[i] = code_seen(mixing_codes[i]) ? code_value_float() : 0;
2675
-
2667
+      for (int i = 0; i < MIXING_STEPPERS; i++) {
2668
+        float v = code_seen(mixing_codes[i]) ? code_value_float() : 0.0;
2669
+        NOLESS(v, 0.0);
2670
+        mixing_factor[i] = RECIPROCAL(v);
2671
+      }
2676 2672
       normalize_mix();
2677 2673
     }
2678 2674
   #endif
@@ -7142,8 +7138,11 @@ inline void gcode_M907() {
7142 7138
    */
7143 7139
   inline void gcode_M163() {
7144 7140
     int mix_index = code_seen('S') ? code_value_int() : 0;
7145
-    float mix_value = code_seen('P') ? code_value_float() : 0.0;
7146
-    if (mix_index < MIXING_STEPPERS) mixing_factor[mix_index] = mix_value;
7141
+    if (mix_index < MIXING_STEPPERS) {
7142
+      float mix_value = code_seen('P') ? code_value_float() : 0.0;
7143
+      NOLESS(mix_value, 0.0);
7144
+      mixing_factor[mix_index] = RECIPROCAL(mix_value);
7145
+    }
7147 7146
   }
7148 7147
 
7149 7148
   #if MIXING_VIRTUAL_TOOLS > 1
@@ -9881,7 +9880,7 @@ void setup() {
9881 9880
   #if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
9882 9881
     // Initialize mixing to 100% color 1
9883 9882
     for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
9884
-      mixing_factor[i] = (i == 0) ? 1 : 0;
9883
+      mixing_factor[i] = (i == 0) ? 1.0 : 0.0;
9885 9884
     for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS; t++)
9886 9885
       for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
9887 9886
         mixing_virtual_tool_mix[t][i] = mixing_factor[i];

+ 2
- 0
Marlin/macros.h Переглянути файл

@@ -133,4 +133,6 @@
133 133
 #define NEAR_ZERO(x) ((x) > -0.000001 && (x) < 0.000001)
134 134
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
135 135
 
136
+#define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
137
+
136 138
 #endif //__MACROS_H

+ 1
- 1
Marlin/planner.cpp Переглянути файл

@@ -750,7 +750,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
750 750
   // For a mixing extruder, get a magnified step_event_count for each
751 751
   #if ENABLED(MIXING_EXTRUDER)
752 752
     for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
753
-      block->mix_event_count[i] = UNEAR_ZERO(mixing_factor[i]) ? 0 : block->step_event_count / mixing_factor[i];
753
+      block->mix_event_count[i] = mixing_factor[i] * block->step_event_count;
754 754
   #endif
755 755
 
756 756
   #if FAN_COUNT > 0

Завантаження…
Відмінити
Зберегти