New Continuous Filament Mixer (#12098)

This commit is contained in:
AnHardt
2018-10-16 10:38:57 +02:00
committed by Scott Lahteine
parent 2d2cd628c6
commit f56968ba0b
14 changed files with 296 additions and 236 deletions

View File

@ -30,7 +30,7 @@
/**
* M163: Set a single mix factor for a mixing extruder
* This is called "weight" by some systems.
* The 'P' values must sum to 1.0 or must be followed by M164 to normalize them.
* Must be followed by M164 to normalize and commit them.
*
* S[index] The channel index to set
* P[float] The mix value
@ -38,24 +38,23 @@
void GcodeSuite::M163() {
const int mix_index = parser.intval('S');
if (mix_index < MIXING_STEPPERS)
mixing_factor[mix_index] = MAX(parser.floatval('P'), 0.0);
mixer.set_M163_collector(mix_index, MAX(parser.floatval('P'), 0.0));
}
/**
* M164: Normalize and commit the mix.
* If 'S' is given store as a virtual tool. (Requires MIXING_VIRTUAL_TOOLS > 1)
* If 'S' is given store as a virtual tool. Else in T0.
*
* S[index] The virtual tool to store
*/
void GcodeSuite::M164() {
normalize_mix();
#if MIXING_VIRTUAL_TOOLS > 1
const int tool_index = parser.intval('S', -1);
if (WITHIN(tool_index, 0, MIXING_VIRTUAL_TOOLS - 1)) {
for (uint8_t i = 0; i < MIXING_STEPPERS; i++)
mixing_virtual_tool_mix[tool_index][i] = mixing_factor[i];
}
#else
constexpr int tool_index = 0;
#endif
if (WITHIN(tool_index, 0, MIXING_VIRTUAL_TOOLS - 1))
mixer.normalize(tool_index);
}
#if ENABLED(DIRECT_MIXING_IN_G1)
@ -63,7 +62,7 @@ void GcodeSuite::M164() {
/**
* M165: Set multiple mix factors for a mixing extruder.
* Factors that are left out will be set to 0.
* All factors should sum to 1.0, but they will be normalized regardless.
* All factors will be normalized and stored in the current v-tool.
*
* A[factor] Mix factor for extruder stepper 1
* B[factor] Mix factor for extruder stepper 2
@ -72,7 +71,39 @@ void GcodeSuite::M164() {
* H[factor] Mix factor for extruder stepper 5
* I[factor] Mix factor for extruder stepper 6
*/
void GcodeSuite::M165() { gcode_get_mix(); }
void GcodeSuite::M165() {
// Get mixing parameters from the GCode
// The total "must" be 1.0 (but it will be normalized)
// If no mix factors are given, the old mix is preserved
const char mixing_codes[] = { 'A', 'B'
#if MIXING_STEPPERS > 2
, 'C'
#if MIXING_STEPPERS > 3
, 'D'
#if MIXING_STEPPERS > 4
, 'H'
#if MIXING_STEPPERS > 5
, 'I'
#endif // MIXING_STEPPERS > 5
#endif // MIXING_STEPPERS > 4
#endif // MIXING_STEPPERS > 3
#endif // MIXING_STEPPERS > 2
};
uint8_t mix_bits = 0;
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));
}
}
// 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());
}
}
#endif // DIRECT_MIXING_IN_G1