From 15b0ae716c49e2ef7836bbb43ded3505845c47e9 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Sun, 28 Feb 2021 22:15:08 +0100 Subject: [PATCH] libs/libdsp/lib_motor.c: refactor --- libs/libdsp/lib_motor.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/libs/libdsp/lib_motor.c b/libs/libdsp/lib_motor.c index d691d19843..7c72830579 100644 --- a/libs/libdsp/lib_motor.c +++ b/libs/libdsp/lib_motor.c @@ -210,20 +210,24 @@ void motor_angle_e_update(FAR struct motor_angle_f32_s *angle, /* Check if we crossed electrical angle boundaries */ - if (dir == DIR_CW && - angle_new - angle->angle_el.angle < -POLE_CNTR_THR) + if (dir == DIR_CW) { /* For CW direction - previous angle is greater than current angle */ - angle->i += 1; + if (angle_new - angle->angle_el.angle < -POLE_CNTR_THR) + { + angle->i += 1; + } } - else if (dir == DIR_CCW && - angle_new - angle->angle_el.angle > POLE_CNTR_THR) + else if (dir == DIR_CCW) { /* For CCW direction - previous angle is lower than current angle */ - angle->i -= 1; + if (angle_new - angle->angle_el.angle > POLE_CNTR_THR) + { + angle->i -= 1; + } } /* Reset pole counter if needed */