From 38616df48b407b7f9a56d8659553bd132c5dc582 Mon Sep 17 00:00:00 2001 From: betashepherd Date: Wed, 17 Nov 2021 10:56:43 +0800 Subject: [PATCH] fix v long_press + // - == 5 kph --- selfdrive/controls/lib/drive_helpers.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/selfdrive/controls/lib/drive_helpers.py b/selfdrive/controls/lib/drive_helpers.py index 7c3242240..6a6818c37 100644 --- a/selfdrive/controls/lib/drive_helpers.py +++ b/selfdrive/controls/lib/drive_helpers.py @@ -69,7 +69,7 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric): long_press = False button_type = None - v_cruise_delta = 1 if metric else 1.6 + v_cruise_delta = 1 if metric else 1.609344 for b in buttonEvents: if b.type.raw in button_timers and not b.pressed: @@ -85,9 +85,14 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled, metric): break if button_type: + v_cruise_kph = math.floor(v_cruise_kph) v_cruise_delta = v_cruise_delta * (5 if long_press else 1) - if long_press and v_cruise_kph % v_cruise_delta != 0: # partial interval - v_cruise_kph = CRUISE_NEAREST_FUNC[button_type](v_cruise_kph / v_cruise_delta) * v_cruise_delta + if long_press: + remainder = v_cruise_kph % v_cruise_delta + if remainder > 0: + v_cruise_kph += (v_cruise_delta - remainder) * CRUISE_INTERVAL_SIGN[button_type] + else: + v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type] else: v_cruise_kph += v_cruise_delta * CRUISE_INTERVAL_SIGN[button_type] v_cruise_kph = clip(round(v_cruise_kph, 1), V_CRUISE_MIN, V_CRUISE_MAX)