Files
dragonpilot/selfdrive/controls/lib/accel_controller.py
dragonpilot 1abc7d7daa dragonpilot beta3
date: 2023-07-26T22:20:36
commit: c6d842c412052be1985b63d683c63be9dcb2b0eb
2023-07-26 22:20:51 +08:00

49 lines
2.1 KiB
Python

from common.numpy_fast import interp
from common.params import Params
DP_ACCEL_STOCK = 0
DP_ACCEL_ECO = 1
DP_ACCEL_NORMAL = 2
DP_ACCEL_SPORT = 3
# accel profile by @arne182 modified by cgw
_DP_CRUISE_MIN_V = [-0.765, -0.765, -0.80, -0.80, -0.75, -0.70]
_DP_CRUISE_MIN_V_ECO = [-0.760, -0.760, -0.76, -0.76, -0.70, -0.65]
_DP_CRUISE_MIN_V_SPORT = [-0.770, -0.770, -0.90, -1.00, -0.90, -0.80]
_DP_CRUISE_MIN_BP = [0., 15.66, 17.88, 20., 30., 55.]
#DP_CRUISE_MIN_BP in mph=[0., 18, 35, 40, 45, 67, 123]
_DP_CRUISE_MAX_V = [3.4, 2.8, 1.8, 1.4, 1.06, .88, .68, .46, .35, .13]
_DP_CRUISE_MAX_V_ECO = [3.2, 2.6, 1.6, 1.2, .76, .62, .48, .36, .28, .09]
_DP_CRUISE_MAX_V_SPORT = [3.5, 3.0, 2.4, 2.9, 2.1, 1.7, 1.3, .9, .7, .5]
_DP_CRUISE_MAX_BP = [0., 3, 6., 8., 11., 15., 20., 25., 30., 55.]
#DP_CRUISE_MAX_BP in mph=[0., 6.7, 13, 18, 25, 33, 45, 56, 67, 123]
class AccelController:
def __init__(self):
self._params = Params()
self._dp_long_accel_profile = DP_ACCEL_STOCK
def read_params(self):
try:
self._dp_long_accel_profile = int(self._params.get("dp_long_accel_profile", encoding='utf-8'))
except (KeyError, TypeError, ValueError):
self._dp_long_accel_profile = DP_ACCEL_STOCK
def _dp_calc_cruise_accel_limits(self, v_ego):
if self._dp_long_accel_profile == DP_ACCEL_ECO:
a_cruise_min = interp(v_ego, _DP_CRUISE_MIN_BP, _DP_CRUISE_MIN_V_ECO)
a_cruise_max = interp(v_ego, _DP_CRUISE_MAX_BP, _DP_CRUISE_MAX_V_ECO)
elif self._dp_long_accel_profile == DP_ACCEL_SPORT:
a_cruise_min = interp(v_ego, _DP_CRUISE_MIN_BP, _DP_CRUISE_MIN_V_SPORT)
a_cruise_max = interp(v_ego, _DP_CRUISE_MAX_BP, _DP_CRUISE_MAX_V_SPORT)
else:
a_cruise_min = interp(v_ego, _DP_CRUISE_MIN_BP, _DP_CRUISE_MIN_V)
a_cruise_max = interp(v_ego, _DP_CRUISE_MAX_BP, _DP_CRUISE_MAX_V)
return a_cruise_min, a_cruise_max
def get_accel_limits(self, v_ego, accel_limits):
return accel_limits if self._dp_long_accel_profile == DP_ACCEL_STOCK else self._dp_calc_cruise_accel_limits(v_ego)