From 1fbe78879f3fe3526714e56b5fe794e83e20a9dc Mon Sep 17 00:00:00 2001 From: stijncarelsbergh Date: Thu, 8 Oct 2026 00:04:20 +0200 Subject: [PATCH] fix(current sense): compare current magnitudes, not signed values Two flaws in the same alignment step: - the A-C branch compared `fabs(c.a) - fabs(c.c)` against a threshold without taking the absolute value of the difference, so a channel that reads *higher* than the driven phase passes the check instead of raising the error; - the B-C branch compared c.a with c.c (copy-paste from the branch above) while the message and the comment refer to phase B. (The same defect in the phase-B section no longer exists on dev, so it is not part of this change.) --- src/common/base_classes/CurrentSense.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/base_classes/CurrentSense.cpp b/src/common/base_classes/CurrentSense.cpp index ce96f85b5..0df6dbb0d 100644 --- a/src/common/base_classes/CurrentSense.cpp +++ b/src/common/base_classes/CurrentSense.cpp @@ -629,14 +629,14 @@ int CurrentSense::alignHybridDriver(float voltage, BLDCDriver* bldc_driver, bool if(c.a && c.c){ // if a and mid-phase c measured // verify that they have almost the same magnitude - if((fabs(c.a) - fabs(c.c)) > 0.1f){ + if(fabs(fabs(c.a) - fabs(c.c)) > 0.1f){ SIMPLEFOC_DEBUG("CS: Err A-C currents not equal!"); return 0; } }else if(c.b && c.c){ - // if a and mid-phase c measured + // if b and mid-phase c measured // verify that they have almost the same magnitude - if((fabs(c.a) - fabs(c.c)) > 0.1f){ + if(fabs(fabs(c.b) - fabs(c.c)) > 0.1f){ SIMPLEFOC_DEBUG("CS: Err B-C currents not equal!"); return 0; }else{