Skip to content

Commit 4527d86

Browse files
authored
add metric values
Freedom units have weird multiples compared to metric. Modified so that it increments by 10 km/h on long press and 1 km/h on short press, rather than 8 and 1.6 km/h. This mimics stock hyundai behaviour on metric vehicles.
1 parent 4c7acf6 commit 4527d86

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

selfdrive/controls/lib/drive_helpers.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import math
22
from cereal import car
33
from common.numpy_fast import clip, interp
4+
from common.params import Params
45
from common.realtime import DT_MDL
56
from selfdrive.config import Conversions as CV
67
from selfdrive.modeld.constants import T_IDXS
78

9+
IS_METRIC = Params().get_bool("IsMetric")
810

911
# kph
1012
V_CRUISE_MAX = 135
11-
V_CRUISE_MIN = 8
12-
V_CRUISE_DELTA = 1.6
13-
V_CRUISE_ENABLE_MIN = 40
13+
if IS_METRIC:
14+
V_CRUISE_DELTA = 1
15+
FAST_CRUISE_MULTIPLIER = 10
16+
V_CRUISE_ENABLE_MIN = 30
17+
V_CRUISE_MIN = 5
18+
else:
19+
V_CRUISE_DELTA = 1.6
20+
FAST_CRUISE_MULTIPLIER = 5
21+
V_CRUISE_ENABLE_MIN = 40
22+
V_CRUISE_MIN = 8
1423
LAT_MPC_N = 16
1524
LON_MPC_N = 32
1625
CONTROL_N = 17
@@ -75,7 +84,7 @@ def update_v_cruise(v_cruise_kph, buttonEvents, button_timers, enabled):
7584
break
7685

7786
if button_type:
78-
v_cruise_delta = V_CRUISE_DELTA * (5 if long_press else 1)
87+
v_cruise_delta = V_CRUISE_DELTA * (FAST_CRUISE_MULTIPLIER if long_press else 1)
7988
if long_press and v_cruise_kph % v_cruise_delta != 0: # partial interval
8089
v_cruise_kph = CRUISE_NEAREST_FUNC[button_type](v_cruise_kph / v_cruise_delta) * v_cruise_delta
8190
else:

0 commit comments

Comments
 (0)