Browse Source

2.0.x: Fix normalize_mix() (#11856)

Mix factors needed to be updated consistent with the recent Stepper/Planner code refactor.
pull/1/head
AnHardt 6 years ago
committed by Scott Lahteine
parent
commit
54bd124665
  1. 7
      Marlin/src/feature/mixing.cpp

7
Marlin/src/feature/mixing.cpp

@ -28,7 +28,7 @@
#include "../gcode/parser.h"
#endif
float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise >= 1.0.
float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off, otherwise <= 1.0. (Array must sum to 1.0.)
#if MIXING_VIRTUAL_TOOLS > 1
@ -56,11 +56,12 @@ float mixing_factor[MIXING_STEPPERS]; // Reciprocal of mix proportion. 0.0 = off
void normalize_mix() {
float mix_total = 0.0;
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mix_total += RECIPROCAL(mixing_factor[i]);
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mix_total += mixing_factor[i]; // Ex: 1/4 + 1/8 + 1/8 = 1/2
// Scale all values if they don't add up to ~1.0
if (!NEAR(mix_total, 1.0)) {
SERIAL_PROTOCOLLNPGM("Warning: Mix factors must add up to 1.0. Scaling.");
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mixing_factor[i] *= mix_total;
mix_total = RECIPROCAL(mix_total);
for (uint8_t i = 0; i < MIXING_STEPPERS; i++) mixing_factor[i] *= mix_total; // Ex: 1/4*2 + 1/8*2 + 1/8*2 = 1/2 + 1/4 + 1/4 = 1
}
}

Loading…
Cancel
Save