Przeglądaj źródła

Pre-apply cosmetic changes to mixing

Scott Lahteine 6 lat temu
rodzic
commit
a5e3384691

+ 1
- 1
Marlin/src/feature/fwretract.cpp Wyświetl plik

@@ -142,7 +142,7 @@ void FWRetract::retract(const bool retracting
142 142
   set_destination_from_current();
143 143
 
144 144
   #if ENABLED(RETRACT_SYNC_MIXING)
145
-    uint8_t old_mixing_tool = mixer.get_current_v_tool();
145
+    uint8_t old_mixing_tool = mixer.get_current_vtool();
146 146
     mixer.T(MIXER_AUTORETRACT_TOOL);
147 147
   #endif
148 148
 

+ 27
- 20
Marlin/src/feature/mixing.cpp Wyświetl plik

@@ -25,23 +25,24 @@
25 25
 #if ENABLED(MIXING_EXTRUDER)
26 26
 
27 27
 //#define MIXER_NORMALIZER_DEBUG
28
-#ifdef MIXER_NORMALIZER_DEBUG
29
-  #include "../core/serial.h"
30
-#endif
31 28
 
32 29
 #include "mixing.h"
33 30
 
34 31
 Mixer mixer;
35 32
 
33
+#ifdef MIXER_NORMALIZER_DEBUG
34
+  #include "../core/serial.h"
35
+#endif
36
+
36 37
 // Used up to Planner level
37
-uint_fast8_t  Mixer::selected_v_tool = 0;
38
-float         Mixer::M163_collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
39
-mixer_color_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
38
+uint_fast8_t Mixer::selected_vtool = 0;
39
+float        Mixer::collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
40
+mixer_comp_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
40 41
 
41 42
 // Used in Stepper
42
-int_fast8_t   Mixer::runner = 0;
43
-mixer_color_t Mixer::s_color[MIXING_STEPPERS];
44
-mixer_accu_t  Mixer::accu[MIXING_STEPPERS] = { 0 };
43
+int_fast8_t  Mixer::runner = 0;
44
+mixer_comp_t Mixer::s_color[MIXING_STEPPERS];
45
+mixer_accu_t Mixer::accu[MIXING_STEPPERS] = { 0 };
45 46
 
46 47
 void Mixer::normalize(const uint8_t tool_index) {
47 48
   float cmax = 0;
@@ -49,15 +50,16 @@ void Mixer::normalize(const uint8_t tool_index) {
49 50
     float csum = 0;
50 51
   #endif
51 52
   MIXER_STEPPER_LOOP(i) {
52
-    cmax = max(cmax, M163_collector[i]);
53
+    const float v = collector[i];
54
+    NOLESS(cmax, v);
53 55
     #ifdef MIXER_NORMALIZER_DEBUG
54
-      csum += M163_collector[i];
56
+      csum += v;
55 57
     #endif
56 58
   }
57 59
   #ifdef MIXER_NORMALIZER_DEBUG
58
-    SERIAL_ECHOPGM("Mixer: Relation before normalizing: [ ");
60
+    SERIAL_ECHOPGM("Mixer: Old relation : [ ");
59 61
     MIXER_STEPPER_LOOP(i) {
60
-      SERIAL_ECHO_F(M163_collector[i] / csum, 3);
62
+      SERIAL_ECHO_F(collector[i] / csum, 3);
61 63
       SERIAL_CHAR(' ');
62 64
     }
63 65
     SERIAL_ECHOPGM("]\n");
@@ -66,18 +68,18 @@ void Mixer::normalize(const uint8_t tool_index) {
66 68
   // Scale all values so their maximum is COLOR_A_MASK
67 69
   const float inverse_max = RECIPROCAL(cmax);
68 70
   MIXER_STEPPER_LOOP(i)
69
-    color[tool_index][i] = M163_collector[i] * COLOR_A_MASK * inverse_max;
71
+    color[tool_index][i] = collector[i] * COLOR_A_MASK * inverse_max;
70 72
 
71 73
   #ifdef MIXER_NORMALIZER_DEBUG
72 74
     csum = 0;
73
-    SERIAL_ECHOPGM("Mixer: Normalizing to             : [ ");
75
+    SERIAL_ECHOPGM("Mixer: Normalize to : [ ");
74 76
     MIXER_STEPPER_LOOP(i) {
75 77
       SERIAL_ECHO(uint16_t(color[tool_index][i]));
76 78
       SERIAL_CHAR(' ');
77 79
       csum += color[tool_index][i];
78 80
     }
79 81
     SERIAL_ECHOLNPGM("]");
80
-    SERIAL_ECHOPGM("Mixer: Relation after normalizing:  [ ");
82
+    SERIAL_ECHOPGM("Mixer: New relation : [ ");
81 83
     MIXER_STEPPER_LOOP(i) {
82 84
       SERIAL_ECHO_F(uint16_t(color[tool_index][i]) / csum, 3);
83 85
       SERIAL_CHAR(' ');
@@ -86,8 +88,7 @@ void Mixer::normalize(const uint8_t tool_index) {
86 88
   #endif
87 89
 }
88 90
 
89
-// called at boot
90
-void Mixer::init( void ) {
91
+void Mixer::reset_vtools() {
91 92
   // Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
92 93
   // Every virtual tool gets a pure filament
93 94
   for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS; t++)
@@ -95,11 +96,17 @@ void Mixer::init( void ) {
95 96
       color[t][i] = (t == i) ? COLOR_A_MASK : 0;
96 97
 
97 98
   // Remaining virtual tools are 100% filament 1
98
-  #if MIXING_STEPPERS < MIXING_VIRTUAL_TOOLS
99
+  #if MIXING_VIRTUAL_TOOLS > MIXING_STEPPERS
99 100
     for (uint8_t t = MIXING_STEPPERS; t < MIXING_VIRTUAL_TOOLS; t++)
100 101
       MIXER_STEPPER_LOOP(i)
101 102
         color[t][i] = (i == 0) ? COLOR_A_MASK : 0;
102 103
   #endif
104
+}
105
+
106
+// called at boot
107
+void Mixer::init() {
108
+
109
+  reset_vtools();
103 110
 
104 111
   #if ENABLED(RETRACT_SYNC_MIXING)
105 112
     // AUTORETRACT_TOOL gets the same amount of all filaments
@@ -107,7 +114,7 @@ void Mixer::init( void ) {
107 114
       color[MIXER_AUTORETRACT_TOOL][i] = COLOR_A_MASK;
108 115
   #endif
109 116
 
110
-  ZERO(M163_collector);
117
+  ZERO(collector);
111 118
 }
112 119
 
113 120
 #endif // MIXING_EXTRUDER

+ 25
- 19
Marlin/src/feature/mixing.h Wyświetl plik

@@ -25,12 +25,12 @@
25 25
 
26 26
 #ifdef __AVR__
27 27
   #define MIXER_ACCU_SIGNED
28
-  typedef uint8_t mixer_color_t;
28
+  typedef uint8_t mixer_comp_t;
29 29
   typedef int8_t mixer_accu_t;
30 30
   #define COLOR_A_MASK 0x80
31 31
   #define COLOR_MASK 0x7F
32 32
 #else
33
-  typedef uint_fast16_t mixer_color_t;
33
+  typedef uint_fast16_t mixer_comp_t;
34 34
   typedef uint_fast16_t mixer_accu_t;
35 35
   #define COLOR_A_MASK 0x8000
36 36
   #define COLOR_MASK 0x7FFF
@@ -56,31 +56,37 @@
56 56
 #define MIXER_STEPPER_LOOP(VAR) \
57 57
   for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++)
58 58
 
59
-#define MIXER_BLOCK_DEFINITION mixer_color_t b_color[MIXING_STEPPERS]
59
+#define MIXER_BLOCK_FIELD      mixer_comp_t b_color[MIXING_STEPPERS]
60 60
 #define MIXER_POPULATE_BLOCK() mixer.populate_block(block->b_color)
61
-#define MIXER_STEPPER_SETUP() mixer.stepper_setup(current_block->b_color)
61
+#define MIXER_STEPPER_SETUP()  mixer.stepper_setup(current_block->b_color)
62 62
 
63
+/**
64
+ * @brief Mixer class
65
+ * @details Contains data and behaviors for a Mixing Extruder
66
+ */
63 67
 class Mixer {
64 68
   public:
65 69
 
66
-  static void init(void); // Populate colors at boot time
70
+  static void init();
71
+
72
+  static void reset_vtools();
67 73
 
68 74
   // Used up to Planner level
69 75
   static void normalize(const uint8_t tool_index);
70
-  FORCE_INLINE static uint8_t get_current_v_tool(void) { return selected_v_tool; }
71
-  FORCE_INLINE static void T(const uint_fast8_t c) { selected_v_tool = c; }
72
-  FORCE_INLINE static void set_M163_collector(const uint8_t c, const float f) { M163_collector[c] = f; }
76
+  FORCE_INLINE static uint8_t get_current_vtool() { return selected_vtool; }
77
+  FORCE_INLINE static void T(const uint_fast8_t c) { selected_vtool = c; }
78
+  FORCE_INLINE static void set_collector(const uint8_t c, const float f) { collector[c] = f; }
73 79
 
74 80
   // Used when dealing with blocks
75
-  FORCE_INLINE static void populate_block(mixer_color_t b_color[]) {
76
-    uint_fast8_t j = get_current_v_tool();
81
+  FORCE_INLINE static void populate_block(mixer_comp_t b_color[]) {
82
+    uint_fast8_t j = get_current_vtool();
77 83
     MIXER_STEPPER_LOOP(i) b_color[i] = color[j][i];
78 84
   }
79
-  FORCE_INLINE static void stepper_setup(mixer_color_t b_color[]) { MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i]; }
85
+  FORCE_INLINE static void stepper_setup(mixer_comp_t b_color[]) { MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i]; }
80 86
 
81 87
   // Used in Stepper
82
-  FORCE_INLINE static uint8_t get_stepper(void) { return runner; }
83
-  FORCE_INLINE static uint8_t get_next_stepper(void) {
88
+  FORCE_INLINE static uint8_t get_stepper() { return runner; }
89
+  FORCE_INLINE static uint8_t get_next_stepper() {
84 90
     do {
85 91
       if (--runner < 0) runner = MIXING_STEPPERS - 1;
86 92
       accu[runner] += s_color[runner];
@@ -100,14 +106,14 @@ class Mixer {
100 106
   private:
101 107
 
102 108
   // Used up to Planner level
103
-  static uint_fast8_t  selected_v_tool;
104
-  static float         M163_collector[MIXING_STEPPERS];
105
-  static mixer_color_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
109
+  static uint_fast8_t selected_vtool;
110
+  static float        collector[MIXING_STEPPERS];
111
+  static mixer_comp_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS];
106 112
 
107 113
   // Used in Stepper
108
-  static int_fast8_t   runner;
109
-  static mixer_color_t s_color[MIXING_STEPPERS];
110
-  static mixer_accu_t  accu[MIXING_STEPPERS];
114
+  static int_fast8_t  runner;
115
+  static mixer_comp_t s_color[MIXING_STEPPERS];
116
+  static mixer_accu_t accu[MIXING_STEPPERS];
111 117
 };
112 118
 
113 119
 extern Mixer mixer;

+ 5
- 5
Marlin/src/gcode/feature/mixing/M163-M165.cpp Wyświetl plik

@@ -38,7 +38,7 @@
38 38
 void GcodeSuite::M163() {
39 39
   const int mix_index = parser.intval('S');
40 40
   if (mix_index < MIXING_STEPPERS)
41
-    mixer.set_M163_collector(mix_index, MAX(parser.floatval('P'), 0.0));
41
+    mixer.set_collector(mix_index, MAX(parser.floatval('P'), 0.0));
42 42
 }
43 43
 
44 44
 /**
@@ -56,7 +56,7 @@ void GcodeSuite::M164() {
56 56
   if (WITHIN(tool_index, 0, MIXING_VIRTUAL_TOOLS - 1))
57 57
     mixer.normalize(tool_index);
58 58
   else
59
-    mixer.normalize(mixer.get_current_v_tool());
59
+    mixer.normalize(mixer.get_current_vtool());
60 60
 }
61 61
 
62 62
 #if ENABLED(DIRECT_MIXING_IN_G1)
@@ -95,15 +95,15 @@ void GcodeSuite::M164() {
95 95
     MIXER_STEPPER_LOOP(i) {
96 96
       if (parser.seenval(mixing_codes[i])) {
97 97
         SBI(mix_bits, i);
98
-        mixer.set_M163_collector(i, MAX(parser.value_float(), 0.0f));
98
+        mixer.set_collector(i, MAX(parser.value_float(), 0.0f));
99 99
       }
100 100
     }
101 101
     // If any mixing factors were included, clear the rest
102 102
     // If none were included, preserve the last mix
103 103
     if (mix_bits) {
104 104
       MIXER_STEPPER_LOOP(i)
105
-        if (!TEST(mix_bits, i)) mixer.set_M163_collector(i, 0.0f);
106
-      mixer.normalize(mixer.get_current_v_tool());
105
+        if (!TEST(mix_bits, i)) mixer.set_collector(i, 0.0f);
106
+      mixer.normalize(mixer.get_current_vtool());
107 107
     }
108 108
   }
109 109
 

+ 1
- 1
Marlin/src/module/planner.cpp Wyświetl plik

@@ -2161,7 +2161,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move,
2161 2161
       // In worst case, only one extruder running, no change is needed.
2162 2162
       // In best case, all extruders run the same amount, we can divide by MIXING_STEPPERS
2163 2163
       float delta_mm_i = 0;
2164
-      if (i == E_AXIS && mixer.get_current_v_tool() == MIXER_AUTORETRACT_TOOL)
2164
+      if (i == E_AXIS && mixer.get_current_vtool() == MIXER_AUTORETRACT_TOOL)
2165 2165
         delta_mm_i = delta_mm[i] / MIXING_STEPPERS;
2166 2166
       else
2167 2167
         delta_mm_i = delta_mm[i];

+ 1
- 1
Marlin/src/module/planner.h Wyświetl plik

@@ -114,7 +114,7 @@ typedef struct block_t {
114 114
   #endif
115 115
 
116 116
   #if ENABLED(MIXING_EXTRUDER)
117
-    MIXER_BLOCK_DEFINITION;                 // Normalized color for the mixing steppers
117
+    MIXER_BLOCK_FIELD;                      // Normalized color for the mixing steppers
118 118
   #endif
119 119
 
120 120
   // Settings for the trapezoid generator

+ 2
- 3
Marlin/src/module/tool_change.cpp Wyświetl plik

@@ -507,9 +507,9 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
507 507
     if (tmp_extruder >= MIXING_VIRTUAL_TOOLS)
508 508
       return invalid_extruder_error(tmp_extruder);
509 509
 
510
-    #if MIXING_VIRTUAL_TOOLS >  1
510
+    #if MIXING_VIRTUAL_TOOLS > 1
511 511
       // T0-Tnnn: Switch virtual tool by changing the index to the mix
512
-      mixer.T(uint_fast8_t(tmp_extruder));
512
+      mixer.T(tmp_extruder);
513 513
     #endif
514 514
 
515 515
   #elif ENABLED(PRUSA_MMU2)
@@ -518,7 +518,6 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
518 518
 
519 519
     mmu2.toolChange(tmp_extruder);
520 520
 
521
-
522 521
   #elif EXTRUDERS < 2
523 522
 
524 523
     UNUSED(fr_mm_s); UNUSED(no_move);

Ładowanie…
Anuluj
Zapisz