From 748dce74d645d58d27212e10dd0e4d0f54fb08f4 Mon Sep 17 00:00:00 2001 From: dzid26 Date: Mon, 4 Nov 2024 00:36:36 +0000 Subject: [PATCH] refactor/fix loop --- firmware/src/BSP/calibration.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/firmware/src/BSP/calibration.c b/firmware/src/BSP/calibration.c index b9e0bcc..47dea38 100644 --- a/firmware/src/BSP/calibration.c +++ b/firmware/src/BSP/calibration.c @@ -370,20 +370,18 @@ int8_t Estimate_motor_k_bemf() { StepperCtrl_setCurrent(-MAX_CURRENT); //accelerate delay_ms(300); } + StepperCtrl_setCurrent(0); - for (int16_t i = 0; i < 10; ++i) { + int16_t i = 0; + while ((fastAbs(speed_slow) > base_speed * 9 / 10) && (i < 10)) { + ++i; delay_ms(100); - if (fastAbs(speed_slow) < base_speed * 9 / 10) { - break; - delay_ms(200); - }else{ - // decay motor_k_bemf - motor_k_bemf = (int16_t)((int32_t)motor_k_bemf * 999 / 1000); - } - } + // decay motor_k_bemf + motor_k_bemf = (int16_t)((int32_t)motor_k_bemf * 999 / 1000); + } + delay_ms(200); } - StepperCtrl_setMotionMode(STEPCTRL_OFF); return motor_k_bemf; }