From 6ad99f156b500549d2d05b584946ba09ed649ddc Mon Sep 17 00:00:00 2001 From: stijncarelsbergh Date: Thu, 8 Oct 2026 00:04:17 +0200 Subject: [PATCH] fix(current sense): check the polarity of the channel that was just relabelled Same defect as the BLDC alignment: when the stepper alignment decides that the measured phase A is on the other ADC channel, it swaps the pins/offsets/gains but not the samples, so the following `if (c.a < 0)` tests the sample of the channel that is *not* carrying the current (and that reads ~0). The phase A gain ends up with the wrong sign for exactly the wiring the routine is meant to correct. --- src/common/base_classes/CurrentSense.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/base_classes/CurrentSense.cpp b/src/common/base_classes/CurrentSense.cpp index ce96f85b5..ebf6d77f1 100644 --- a/src/common/base_classes/CurrentSense.cpp +++ b/src/common/base_classes/CurrentSense.cpp @@ -450,6 +450,7 @@ int CurrentSense::alignStepperDriver(float voltage, StepperDriver* stepper_drive _swap(pinA, pinB); _swap(offset_ia, offset_ib); _swap(gain_a, gain_b); + _swap(c.a, c.b); phases_switched = true; // signal that pins have been switched } // 2) check if measured current a is positive and invert if not