From 6098dd300a3ef4b3cc797eefd8d6fce38e7f277c Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 1 Jul 2024 11:18:47 -0400 Subject: [PATCH] formatting --- common/params.cc | 1 + .../controls/lib/longitudinal_planner.py | 2 +- .../lib/sunnypilot/accel_controller.py | 53 +++++++++---------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/common/params.cc b/common/params.cc index 473ea89a77..49a8cba9b9 100644 --- a/common/params.cc +++ b/common/params.cc @@ -209,6 +209,7 @@ std::unordered_map keys = { {"UpdaterTargetBranch", CLEAR_ON_MANAGER_START}, {"UpdaterLastFetchTime", PERSISTENT}, {"Version", PERSISTENT}, + {"AccelProfile", PERSISTENT | BACKUP}, {"AccMadsCombo", PERSISTENT | BACKUP}, {"AmapKey1", PERSISTENT | BACKUP}, diff --git a/selfdrive/controls/lib/longitudinal_planner.py b/selfdrive/controls/lib/longitudinal_planner.py index 6b7c56d82e..11bf18c363 100755 --- a/selfdrive/controls/lib/longitudinal_planner.py +++ b/selfdrive/controls/lib/longitudinal_planner.py @@ -19,8 +19,8 @@ from openpilot.selfdrive.controls.lib.longitudinal_mpc_lib.long_mpc import T_IDX from openpilot.selfdrive.controls.lib.drive_helpers import V_CRUISE_MAX, CONTROL_N, get_speed_error from openpilot.selfdrive.controls.lib.vision_turn_controller import VisionTurnController from openpilot.selfdrive.controls.lib.turn_speed_controller import TurnSpeedController -from openpilot.selfdrive.controls.lib.sunnypilot.dynamic_experimental_controller import DynamicExperimentalController from openpilot.selfdrive.controls.lib.sunnypilot.accel_controller import AccelController +from openpilot.selfdrive.controls.lib.sunnypilot.dynamic_experimental_controller import DynamicExperimentalController from openpilot.selfdrive.controls.lib.events import Events from openpilot.common.swaglog import cloudlog diff --git a/selfdrive/controls/lib/sunnypilot/accel_controller.py b/selfdrive/controls/lib/sunnypilot/accel_controller.py index e6911b4a6c..26ad7f6692 100644 --- a/selfdrive/controls/lib/sunnypilot/accel_controller.py +++ b/selfdrive/controls/lib/sunnypilot/accel_controller.py @@ -21,7 +21,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. -# Last update: June 5, 2024 +# Last updated: June 5, 2024 from openpilot.common.numpy_fast import interp @@ -43,34 +43,33 @@ _DP_CRUISE_MAX_BP = [0., 1., 6., 8., 11., 15., 20., 25., 30., 55. class AccelController: + def __init__(self): + # self._params = Params() + self._profile = DP_ACCEL_STOCK - def __init__(self): - # self._params = Params() - self._profile = DP_ACCEL_STOCK + def set_profile(self, profile): + try: + self._profile = int(profile) if int(profile) in [DP_ACCEL_STOCK, DP_ACCEL_ECO, DP_ACCEL_NORMAL, DP_ACCEL_SPORT] else DP_ACCEL_STOCK + except: + self._profile = DP_ACCEL_STOCK - def set_profile(self, profile): - try: - self._profile = int(profile) if int(profile) in [DP_ACCEL_STOCK, DP_ACCEL_ECO, DP_ACCEL_NORMAL, DP_ACCEL_SPORT] else DP_ACCEL_STOCK - except: - self._profile = DP_ACCEL_STOCK + def _dp_calc_cruise_accel_limits(self, v_ego): + if self._profile == DP_ACCEL_ECO: + min_v = _DP_CRUISE_MIN_V_ECO + max_v = _DP_CRUISE_MAX_V_ECO + elif self._profile == DP_ACCEL_SPORT: + min_v = _DP_CRUISE_MIN_V_SPORT + max_v = _DP_CRUISE_MAX_V_SPORT + else: + min_v = _DP_CRUISE_MIN_V + max_v = _DP_CRUISE_MAX_V - def _dp_calc_cruise_accel_limits(self, v_ego): - if self._profile == DP_ACCEL_ECO: - min_v = _DP_CRUISE_MIN_V_ECO - max_v = _DP_CRUISE_MAX_V_ECO - elif self._profile == DP_ACCEL_SPORT: - min_v = _DP_CRUISE_MIN_V_SPORT - max_v = _DP_CRUISE_MAX_V_SPORT - else: - min_v = _DP_CRUISE_MIN_V - max_v = _DP_CRUISE_MAX_V + a_cruise_min = interp(v_ego, _DP_CRUISE_MIN_BP, min_v) + a_cruise_max = interp(v_ego, _DP_CRUISE_MAX_BP, max_v) + return a_cruise_min, a_cruise_max - a_cruise_min = interp(v_ego, _DP_CRUISE_MIN_BP, min_v) - a_cruise_max = interp(v_ego, _DP_CRUISE_MAX_BP, max_v) - return a_cruise_min, a_cruise_max + def get_accel_limits(self, v_ego, accel_limits): + return accel_limits if self._profile == DP_ACCEL_STOCK else self._dp_calc_cruise_accel_limits(v_ego) - def get_accel_limits(self, v_ego, accel_limits): - return accel_limits if self._profile == DP_ACCEL_STOCK else self._dp_calc_cruise_accel_limits(v_ego) - - def is_enabled(self): - return self._profile != DP_ACCEL_STOCK + def is_enabled(self): + return self._profile != DP_ACCEL_STOCK