From 004af85dc1f74dfbbbd99f30d88c50a32c77346d Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Fri, 13 Oct 2023 13:56:03 +0200 Subject: [PATCH] Take both current override limits into account in the relative current mode --- motor/mc_interface.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/motor/mc_interface.c b/motor/mc_interface.c index 5d06bd02..3277d522 100644 --- a/motor/mc_interface.c +++ b/motor/mc_interface.c @@ -734,7 +734,13 @@ void mc_interface_set_current_rel(float val) { } volatile mc_configuration *cfg = &motor_now()->m_conf; - mc_interface_set_current(val * cfg->lo_current_max); + float duty = mc_interface_get_duty_cycle_now(); + + if (fabsf(duty) < 0.02 || SIGN(val) == SIGN(duty)) { + mc_interface_set_current(val * cfg->lo_current_max); + } else { + mc_interface_set_current(val * fabsf(cfg->lo_current_min)); + } if (fabsf(val * cfg->l_abs_current_max) > cfg->cc_min_current) { mc_interface_set_current_off_delay(0.1);