Skip to content

Commit

Permalink
fix issue when tc_speed set lower during running
Browse files Browse the repository at this point in the history
  • Loading branch information
dukelec committed Sep 27, 2022
1 parent 7593acf commit 575707f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions usr/app_motor.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ static inline void t_curve_compute(void)
float delta_v = csa.tc_ac / (CURRENT_LOOP_FREQ / 25.0f);
csa.tc_vc += -sign(csa.tc_vc) * delta_v;
} else {
csa.tc_vc += ((csa.tc_pos >= csa.cal_pos) ? 1 : -1) * v_step;
csa.tc_vc = clip(csa.tc_vc, -(float)csa.tc_speed, (float)csa.tc_speed);
float target_v = ((csa.tc_pos >= csa.cal_pos) ? 1 : -1) * (float)csa.tc_speed;
float delta_v = ((target_v >= csa.tc_vc) ? 1 : -1) * min(v_step, fabsf(target_v - csa.tc_vc));
csa.tc_vc += delta_v;
}

float dt_pos = csa.tc_vc / (CURRENT_LOOP_FREQ / 25.0f);
Expand Down

0 comments on commit 575707f

Please sign in to comment.