From 1fee16de471db4fffe036278f556d76a51ec1975 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Sun, 16 Jul 2023 16:00:41 +0200 Subject: [PATCH] Hall sensor bug fix and tweaks --- CHANGELOG.md | 6 +++++- motor/foc_math.c | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20b6bc153..65826c459 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,11 @@ * Added access to several config parameters. * Many improvements and bug fixes. * Better error descriptions. -* Hall sensors: smooth transition to sensorless. +* Hall sensors improvements: + * Smooth transition to sensorless. + * Bug fix in interpolation. + * Use less noisy speed estimator for interpolation. + * Adjusted rate limit. * Added soft regen cutoff. See https://github.com/vedderb/vesc_tool/pull/310 * Attempt at limiting the input current when using MTPA and field weakening. * Removed built-in balance app. The balance-package can be used instead, which is where new development is done. diff --git a/motor/foc_math.c b/motor/foc_math.c index 278d57c2b..a59096318 100644 --- a/motor/foc_math.c +++ b/motor/foc_math.c @@ -544,7 +544,7 @@ float foc_correct_hall(float angle, float dt, motor_all_state_t *motor, int hall mc_configuration *conf_now = motor->m_conf; motor->m_hall_dt_diff_now += dt; - float rad_per_sec = (M_PI / 3.0) / motor->m_hall_dt_diff_last; + float rad_per_sec = motor->m_speed_est_fast; float rpm_abs = fabsf(RADPS2RPM_f(motor->m_pll_speed)); float rpm_abs_hall = fabsf(RADPS2RPM_f(rad_per_sec)); @@ -603,18 +603,18 @@ float foc_correct_hall(float angle, float dt, motor_all_state_t *motor, int hall } else { // Interpolate float diff = utils_angle_difference_rad(motor->m_ang_hall, ang_hall_now); - if (fabsf(diff) < ((2.0 * M_PI) / 12.0)) { + if (fabsf(diff) < ((2.0 * M_PI) / 12.0) || SIGN(diff) != SIGN(rad_per_sec)) { // Do interpolation motor->m_ang_hall += rad_per_sec * dt; } else { // We are too far away with the interpolation - motor->m_ang_hall -= diff / 100.0; + motor->m_ang_hall -= diff * 0.01; } } // Limit hall sensor rate of change. This will reduce current spikes in the current controllers when the angle estimation // changes fast. - float angle_step = (fmaxf(rpm_abs_hall, conf_now->foc_hall_interp_erpm) / 60.0) * 2.0 * M_PI * dt * 1.5; + float angle_step = (fmaxf(rpm_abs_hall, conf_now->foc_hall_interp_erpm) / 60.0) * 2.0 * M_PI * dt * 1.4; float angle_diff = utils_angle_difference_rad(motor->m_ang_hall, motor->m_ang_hall_rate_limited); if (fabsf(angle_diff) < angle_step) { motor->m_ang_hall_rate_limited = motor->m_ang_hall;