Skip to content

Commit

Permalink
Hall sensor bug fix and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vedderb committed Jul 16, 2023
1 parent 14994c6 commit 1fee16d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions motor/foc_math.c
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1fee16d

Please sign in to comment.