From 8db81e9f4e33c808fd5bc8057460cb831938b841 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 14 Jun 2023 23:48:11 -0400 Subject: [PATCH] Ram HD: locked Steering Ratio (#156) * Ram HD: locked SR * gate to only ram hd * attribute error * gotta init first * define type --- selfdrive/car/chrysler/interface.py | 1 + selfdrive/car/chrysler/values.py | 2 ++ selfdrive/controls/controlsd.py | 2 +- selfdrive/controls/lib/vehicle_model.py | 9 ++++++--- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 55c89dceef1e47..cb7784cc663ddb 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -82,6 +82,7 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs): ret.mass = 3405. + STD_CARGO_KG ret.minSteerSpeed = 16 CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning, 1.0, False) + ret.flags |= ChryslerFlags.SP_RAM_HD_FIXED_STEERING_RATIO.value else: raise ValueError(f"Unsupported car: {candidate}") diff --git a/selfdrive/car/chrysler/values.py b/selfdrive/car/chrysler/values.py index c8540c8a599d2b..566a210ad5577f 100644 --- a/selfdrive/car/chrysler/values.py +++ b/selfdrive/car/chrysler/values.py @@ -14,6 +14,8 @@ class ChryslerFlags(IntFlag): HIGHER_MIN_STEERING_SPEED = 1 + SP_RAM_HD_FIXED_STEERING_RATIO = 2 + class CAR: # Chrysler diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index a61e12c6d3cba5..bff6b971fd65c0 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -606,7 +606,7 @@ def state_control(self, CS): lp = self.sm['liveParameters'] x = max(lp.stiffnessFactor, 0.1) sr = max(lp.steerRatio, 0.1) - self.VM.update_params(x, sr) + self.VM.update_params(x, sr, self.CP) # Update Torque Params if self.CP.lateralTuning.which() == 'torque': diff --git a/selfdrive/controls/lib/vehicle_model.py b/selfdrive/controls/lib/vehicle_model.py index 0750384918dc31..1c24dc63aebc3f 100755 --- a/selfdrive/controls/lib/vehicle_model.py +++ b/selfdrive/controls/lib/vehicle_model.py @@ -19,6 +19,8 @@ from cereal import car +from selfdrive.car.chrysler.values import ChryslerFlags + ACCELERATION_DUE_TO_GRAVITY = 9.8 @@ -38,13 +40,14 @@ def __init__(self, CP: car.CarParams): self.cF_orig: float = CP.tireStiffnessFront self.cR_orig: float = CP.tireStiffnessRear - self.update_params(1.0, CP.steerRatio) + self.chrysler_ram_hd: bool = (CP.carName == "chrysler") and CP.flags & ChryslerFlags.SP_RAM_HD_FIXED_STEERING_RATIO.value + self.update_params(1.0, CP.steerRatio, CP) - def update_params(self, stiffness_factor: float, steer_ratio: float) -> None: + def update_params(self, stiffness_factor: float, steer_ratio: float, CP: car.CarParams) -> None: """Update the vehicle model with a new stiffness factor and steer ratio""" self.cF: float = stiffness_factor * self.cF_orig self.cR: float = stiffness_factor * self.cR_orig - self.sR: float = steer_ratio + self.sR: float = CP.steerRatio if self.chrysler_ram_hd else steer_ratio def steady_state_sol(self, sa: float, u: float, roll: float) -> np.ndarray: """Returns the steady state solution.