Pre-apply cosmetic changes to mixing
This commit is contained in:
		
							parent
							
								
									0358ffcd4c
								
							
						
					
					
						commit
						a5e3384691
					
				| @ -142,7 +142,7 @@ void FWRetract::retract(const bool retracting | ||||
|   set_destination_from_current(); | ||||
| 
 | ||||
|   #if ENABLED(RETRACT_SYNC_MIXING) | ||||
|     uint8_t old_mixing_tool = mixer.get_current_v_tool(); | ||||
|     uint8_t old_mixing_tool = mixer.get_current_vtool(); | ||||
|     mixer.T(MIXER_AUTORETRACT_TOOL); | ||||
|   #endif | ||||
| 
 | ||||
|  | ||||
| @ -25,22 +25,23 @@ | ||||
| #if ENABLED(MIXING_EXTRUDER) | ||||
| 
 | ||||
| //#define MIXER_NORMALIZER_DEBUG
 | ||||
| #ifdef MIXER_NORMALIZER_DEBUG | ||||
|   #include "../core/serial.h" | ||||
| #endif | ||||
| 
 | ||||
| #include "mixing.h" | ||||
| 
 | ||||
| Mixer mixer; | ||||
| 
 | ||||
| #ifdef MIXER_NORMALIZER_DEBUG | ||||
|   #include "../core/serial.h" | ||||
| #endif | ||||
| 
 | ||||
| // Used up to Planner level
 | ||||
| uint_fast8_t  Mixer::selected_v_tool = 0; | ||||
| float         Mixer::M163_collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
 | ||||
| mixer_color_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS]; | ||||
| uint_fast8_t Mixer::selected_vtool = 0; | ||||
| float        Mixer::collector[MIXING_STEPPERS]; // mix proportion. 0.0 = off, otherwise <= COLOR_A_MASK.
 | ||||
| mixer_comp_t Mixer::color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS]; | ||||
| 
 | ||||
| // Used in Stepper
 | ||||
| int_fast8_t  Mixer::runner = 0; | ||||
| mixer_color_t Mixer::s_color[MIXING_STEPPERS]; | ||||
| mixer_comp_t Mixer::s_color[MIXING_STEPPERS]; | ||||
| mixer_accu_t Mixer::accu[MIXING_STEPPERS] = { 0 }; | ||||
| 
 | ||||
| void Mixer::normalize(const uint8_t tool_index) { | ||||
| @ -49,15 +50,16 @@ void Mixer::normalize(const uint8_t tool_index) { | ||||
|     float csum = 0; | ||||
|   #endif | ||||
|   MIXER_STEPPER_LOOP(i) { | ||||
|     cmax = max(cmax, M163_collector[i]); | ||||
|     const float v = collector[i]; | ||||
|     NOLESS(cmax, v); | ||||
|     #ifdef MIXER_NORMALIZER_DEBUG | ||||
|       csum += M163_collector[i]; | ||||
|       csum += v; | ||||
|     #endif | ||||
|   } | ||||
|   #ifdef MIXER_NORMALIZER_DEBUG | ||||
|     SERIAL_ECHOPGM("Mixer: Relation before normalizing: [ "); | ||||
|     SERIAL_ECHOPGM("Mixer: Old relation : [ "); | ||||
|     MIXER_STEPPER_LOOP(i) { | ||||
|       SERIAL_ECHO_F(M163_collector[i] / csum, 3); | ||||
|       SERIAL_ECHO_F(collector[i] / csum, 3); | ||||
|       SERIAL_CHAR(' '); | ||||
|     } | ||||
|     SERIAL_ECHOPGM("]\n"); | ||||
| @ -66,18 +68,18 @@ void Mixer::normalize(const uint8_t tool_index) { | ||||
|   // Scale all values so their maximum is COLOR_A_MASK
 | ||||
|   const float inverse_max = RECIPROCAL(cmax); | ||||
|   MIXER_STEPPER_LOOP(i) | ||||
|     color[tool_index][i] = M163_collector[i] * COLOR_A_MASK * inverse_max; | ||||
|     color[tool_index][i] = collector[i] * COLOR_A_MASK * inverse_max; | ||||
| 
 | ||||
|   #ifdef MIXER_NORMALIZER_DEBUG | ||||
|     csum = 0; | ||||
|     SERIAL_ECHOPGM("Mixer: Normalizing to             : [ "); | ||||
|     SERIAL_ECHOPGM("Mixer: Normalize to : [ "); | ||||
|     MIXER_STEPPER_LOOP(i) { | ||||
|       SERIAL_ECHO(uint16_t(color[tool_index][i])); | ||||
|       SERIAL_CHAR(' '); | ||||
|       csum += color[tool_index][i]; | ||||
|     } | ||||
|     SERIAL_ECHOLNPGM("]"); | ||||
|     SERIAL_ECHOPGM("Mixer: Relation after normalizing:  [ "); | ||||
|     SERIAL_ECHOPGM("Mixer: New relation : [ "); | ||||
|     MIXER_STEPPER_LOOP(i) { | ||||
|       SERIAL_ECHO_F(uint16_t(color[tool_index][i]) / csum, 3); | ||||
|       SERIAL_CHAR(' '); | ||||
| @ -86,8 +88,7 @@ void Mixer::normalize(const uint8_t tool_index) { | ||||
|   #endif | ||||
| } | ||||
| 
 | ||||
| // called at boot
 | ||||
| void Mixer::init( void ) { | ||||
| void Mixer::reset_vtools() { | ||||
|   // Virtual Tools 0, 1, 2, 3 = Filament 1, 2, 3, 4, etc.
 | ||||
|   // Every virtual tool gets a pure filament
 | ||||
|   for (uint8_t t = 0; t < MIXING_VIRTUAL_TOOLS && t < MIXING_STEPPERS; t++) | ||||
| @ -95,11 +96,17 @@ void Mixer::init( void ) { | ||||
|       color[t][i] = (t == i) ? COLOR_A_MASK : 0; | ||||
| 
 | ||||
|   // Remaining virtual tools are 100% filament 1
 | ||||
|   #if MIXING_STEPPERS < MIXING_VIRTUAL_TOOLS | ||||
|   #if MIXING_VIRTUAL_TOOLS > MIXING_STEPPERS | ||||
|     for (uint8_t t = MIXING_STEPPERS; t < MIXING_VIRTUAL_TOOLS; t++) | ||||
|       MIXER_STEPPER_LOOP(i) | ||||
|         color[t][i] = (i == 0) ? COLOR_A_MASK : 0; | ||||
|   #endif | ||||
| } | ||||
| 
 | ||||
| // called at boot
 | ||||
| void Mixer::init() { | ||||
| 
 | ||||
|   reset_vtools(); | ||||
| 
 | ||||
|   #if ENABLED(RETRACT_SYNC_MIXING) | ||||
|     // AUTORETRACT_TOOL gets the same amount of all filaments
 | ||||
| @ -107,7 +114,7 @@ void Mixer::init( void ) { | ||||
|       color[MIXER_AUTORETRACT_TOOL][i] = COLOR_A_MASK; | ||||
|   #endif | ||||
| 
 | ||||
|   ZERO(M163_collector); | ||||
|   ZERO(collector); | ||||
| } | ||||
| 
 | ||||
| #endif // MIXING_EXTRUDER
 | ||||
|  | ||||
| @ -25,12 +25,12 @@ | ||||
| 
 | ||||
| #ifdef __AVR__ | ||||
|   #define MIXER_ACCU_SIGNED | ||||
|   typedef uint8_t mixer_color_t; | ||||
|   typedef uint8_t mixer_comp_t; | ||||
|   typedef int8_t mixer_accu_t; | ||||
|   #define COLOR_A_MASK 0x80 | ||||
|   #define COLOR_MASK 0x7F | ||||
| #else | ||||
|   typedef uint_fast16_t mixer_color_t; | ||||
|   typedef uint_fast16_t mixer_comp_t; | ||||
|   typedef uint_fast16_t mixer_accu_t; | ||||
|   #define COLOR_A_MASK 0x8000 | ||||
|   #define COLOR_MASK 0x7FFF | ||||
| @ -56,31 +56,37 @@ | ||||
| #define MIXER_STEPPER_LOOP(VAR) \ | ||||
|   for (uint_fast8_t VAR = 0; VAR < MIXING_STEPPERS; VAR++) | ||||
| 
 | ||||
| #define MIXER_BLOCK_DEFINITION mixer_color_t b_color[MIXING_STEPPERS] | ||||
| #define MIXER_BLOCK_FIELD      mixer_comp_t b_color[MIXING_STEPPERS] | ||||
| #define MIXER_POPULATE_BLOCK() mixer.populate_block(block->b_color) | ||||
| #define MIXER_STEPPER_SETUP()  mixer.stepper_setup(current_block->b_color) | ||||
| 
 | ||||
| /**
 | ||||
|  * @brief Mixer class | ||||
|  * @details Contains data and behaviors for a Mixing Extruder | ||||
|  */ | ||||
| class Mixer { | ||||
|   public: | ||||
| 
 | ||||
|   static void init(void); // Populate colors at boot time
 | ||||
|   static void init(); | ||||
| 
 | ||||
|   static void reset_vtools(); | ||||
| 
 | ||||
|   // Used up to Planner level
 | ||||
|   static void normalize(const uint8_t tool_index); | ||||
|   FORCE_INLINE static uint8_t get_current_v_tool(void) { return selected_v_tool; } | ||||
|   FORCE_INLINE static void T(const uint_fast8_t c) { selected_v_tool = c; } | ||||
|   FORCE_INLINE static void set_M163_collector(const uint8_t c, const float f) { M163_collector[c] = f; } | ||||
|   FORCE_INLINE static uint8_t get_current_vtool() { return selected_vtool; } | ||||
|   FORCE_INLINE static void T(const uint_fast8_t c) { selected_vtool = c; } | ||||
|   FORCE_INLINE static void set_collector(const uint8_t c, const float f) { collector[c] = f; } | ||||
| 
 | ||||
|   // Used when dealing with blocks
 | ||||
|   FORCE_INLINE static void populate_block(mixer_color_t b_color[]) { | ||||
|     uint_fast8_t j = get_current_v_tool(); | ||||
|   FORCE_INLINE static void populate_block(mixer_comp_t b_color[]) { | ||||
|     uint_fast8_t j = get_current_vtool(); | ||||
|     MIXER_STEPPER_LOOP(i) b_color[i] = color[j][i]; | ||||
|   } | ||||
|   FORCE_INLINE static void stepper_setup(mixer_color_t b_color[]) { MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i]; } | ||||
|   FORCE_INLINE static void stepper_setup(mixer_comp_t b_color[]) { MIXER_STEPPER_LOOP(i) s_color[i] = b_color[i]; } | ||||
| 
 | ||||
|   // Used in Stepper
 | ||||
|   FORCE_INLINE static uint8_t get_stepper(void) { return runner; } | ||||
|   FORCE_INLINE static uint8_t get_next_stepper(void) { | ||||
|   FORCE_INLINE static uint8_t get_stepper() { return runner; } | ||||
|   FORCE_INLINE static uint8_t get_next_stepper() { | ||||
|     do { | ||||
|       if (--runner < 0) runner = MIXING_STEPPERS - 1; | ||||
|       accu[runner] += s_color[runner]; | ||||
| @ -100,13 +106,13 @@ class Mixer { | ||||
|   private: | ||||
| 
 | ||||
|   // Used up to Planner level
 | ||||
|   static uint_fast8_t  selected_v_tool; | ||||
|   static float         M163_collector[MIXING_STEPPERS]; | ||||
|   static mixer_color_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS]; | ||||
|   static uint_fast8_t selected_vtool; | ||||
|   static float        collector[MIXING_STEPPERS]; | ||||
|   static mixer_comp_t color[NR_MIXING_VIRTUAL_TOOLS][MIXING_STEPPERS]; | ||||
| 
 | ||||
|   // Used in Stepper
 | ||||
|   static int_fast8_t  runner; | ||||
|   static mixer_color_t s_color[MIXING_STEPPERS]; | ||||
|   static mixer_comp_t s_color[MIXING_STEPPERS]; | ||||
|   static mixer_accu_t accu[MIXING_STEPPERS]; | ||||
| }; | ||||
| 
 | ||||
|  | ||||
| @ -38,7 +38,7 @@ | ||||
| void GcodeSuite::M163() { | ||||
|   const int mix_index = parser.intval('S'); | ||||
|   if (mix_index < MIXING_STEPPERS) | ||||
|     mixer.set_M163_collector(mix_index, MAX(parser.floatval('P'), 0.0)); | ||||
|     mixer.set_collector(mix_index, MAX(parser.floatval('P'), 0.0)); | ||||
| } | ||||
| 
 | ||||
| /**
 | ||||
| @ -56,7 +56,7 @@ void GcodeSuite::M164() { | ||||
|   if (WITHIN(tool_index, 0, MIXING_VIRTUAL_TOOLS - 1)) | ||||
|     mixer.normalize(tool_index); | ||||
|   else | ||||
|     mixer.normalize(mixer.get_current_v_tool()); | ||||
|     mixer.normalize(mixer.get_current_vtool()); | ||||
| } | ||||
| 
 | ||||
| #if ENABLED(DIRECT_MIXING_IN_G1) | ||||
| @ -95,15 +95,15 @@ void GcodeSuite::M164() { | ||||
|     MIXER_STEPPER_LOOP(i) { | ||||
|       if (parser.seenval(mixing_codes[i])) { | ||||
|         SBI(mix_bits, i); | ||||
|         mixer.set_M163_collector(i, MAX(parser.value_float(), 0.0f)); | ||||
|         mixer.set_collector(i, MAX(parser.value_float(), 0.0f)); | ||||
|       } | ||||
|     } | ||||
|     // If any mixing factors were included, clear the rest
 | ||||
|     // If none were included, preserve the last mix
 | ||||
|     if (mix_bits) { | ||||
|       MIXER_STEPPER_LOOP(i) | ||||
|         if (!TEST(mix_bits, i)) mixer.set_M163_collector(i, 0.0f); | ||||
|       mixer.normalize(mixer.get_current_v_tool()); | ||||
|         if (!TEST(mix_bits, i)) mixer.set_collector(i, 0.0f); | ||||
|       mixer.normalize(mixer.get_current_vtool()); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | ||||
| @ -2161,7 +2161,7 @@ bool Planner::_populate_block(block_t * const block, bool split_move, | ||||
|       // In worst case, only one extruder running, no change is needed.
 | ||||
|       // In best case, all extruders run the same amount, we can divide by MIXING_STEPPERS
 | ||||
|       float delta_mm_i = 0; | ||||
|       if (i == E_AXIS && mixer.get_current_v_tool() == MIXER_AUTORETRACT_TOOL) | ||||
|       if (i == E_AXIS && mixer.get_current_vtool() == MIXER_AUTORETRACT_TOOL) | ||||
|         delta_mm_i = delta_mm[i] / MIXING_STEPPERS; | ||||
|       else | ||||
|         delta_mm_i = delta_mm[i]; | ||||
|  | ||||
| @ -114,7 +114,7 @@ typedef struct block_t { | ||||
|   #endif | ||||
| 
 | ||||
|   #if ENABLED(MIXING_EXTRUDER) | ||||
|     MIXER_BLOCK_DEFINITION;                 // Normalized color for the mixing steppers
 | ||||
|     MIXER_BLOCK_FIELD;                      // Normalized color for the mixing steppers
 | ||||
|   #endif | ||||
| 
 | ||||
|   // Settings for the trapezoid generator
 | ||||
|  | ||||
| @ -509,7 +509,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n | ||||
| 
 | ||||
|     #if MIXING_VIRTUAL_TOOLS > 1 | ||||
|       // T0-Tnnn: Switch virtual tool by changing the index to the mix
 | ||||
|       mixer.T(uint_fast8_t(tmp_extruder)); | ||||
|       mixer.T(tmp_extruder); | ||||
|     #endif | ||||
| 
 | ||||
|   #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 | ||||
| 
 | ||||
|     mmu2.toolChange(tmp_extruder); | ||||
| 
 | ||||
| 
 | ||||
|   #elif EXTRUDERS < 2 | ||||
| 
 | ||||
|     UNUSED(fr_mm_s); UNUSED(no_move); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user