diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index a4362d966..94004d304 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -6,7 +6,7 @@ from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.toyota import toyotacan from openpilot.selfdrive.car.toyota.values import CAR, STATIC_DSU_MSGS, NO_STOP_TIMER_CAR, TSS2_CAR, \ MIN_ACC_SPEED, PEDAL_TRANSITION, CarControllerParams, ToyotaFlags, \ - UNSUPPORTED_DSU_CAR, STOP_AND_GO_CAR + UNSUPPORTED_DSU_CAR, STOP_AND_GO_CAR, TSS2_CAR from opendbc.can.packer import CANPacker LongCtrlState = car.CarControl.Actuators.LongControlState @@ -38,6 +38,17 @@ PARK = car.CarState.GearShifter.park COMPENSATORY_CALCULATION_THRESHOLD_V = [-0.3, -0.25, 0.] # m/s^2 COMPENSATORY_CALCULATION_THRESHOLD_BP = [0., 11., 23.] # m/s + +def compute_gb_toyota(accel, speed): + creep_brake = 0.0 + creep_speed = 2.3 + creep_brake_value = 0.15 + if speed < creep_speed: + creep_brake = (creep_speed - speed) / creep_speed * creep_brake_value + gb = accel - creep_brake + return gb + + class CarController(CarControllerBase): def __init__(self, dbc_name, CP, VM): self.CP = CP @@ -60,6 +71,9 @@ class CarController(CarControllerBase): params = Params() self.cydia_tune = params.get_bool("CydiaTune") + self.frogs_go_moo_tune = params.get_bool("FrogsGoMooTune") + + self.pcm_accel_comp = 0 self.doors_locked = False self.doors_unlocked = True @@ -151,17 +165,28 @@ class CarController(CarControllerBase): self.prohibit_neg_calculation = False # limit minimum to only positive until first positive is reached after engagement, don't calculate when long isn't active - if CC.longActive and not self.prohibit_neg_calculation and self.cydia_tune: + if CC.longActive and not self.prohibit_neg_calculation and (self.cydia_tune or self.frogs_go_moo_tune and self.CP.carFingerprint not in TSS2_CAR): accel_offset = CS.pcm_neutral_force / self.CP.mass else: accel_offset = 0. + if CC.longActive and self.frogs_go_moo_tune: + wind_brake = interp(CS.out.vEgo, [0.0, 2.3, 35.0], [0.001, 0.002, 0.15]) + gas_accel = compute_gb_toyota(actuators.accel, CS.out.vEgo) + wind_brake + self.pcm_accel_comp = clip(gas_accel - CS.pcm_accel_net, self.pcm_accel_comp - 0.03, self.pcm_accel_comp + 0.03) + # only calculate pcm_accel_cmd when long is active to prevent disengagement from accelerator depression if CC.longActive: if frogpilot_toggles.sport_plus: - pcm_accel_cmd = clip(actuators.accel + accel_offset, self.params.ACCEL_MIN, self.params.ACCEL_MAX_PLUS) + if self.frogs_go_moo_tune: + pcm_accel_cmd = clip(gas_accel + self.pcm_accel_comp, self.params.ACCEL_MIN, self.params.ACCEL_MAX_PLUS) + else: + pcm_accel_cmd = clip(actuators.accel + accel_offset, self.params.ACCEL_MIN, self.params.ACCEL_MAX_PLUS) else: - pcm_accel_cmd = clip(actuators.accel + accel_offset, self.params.ACCEL_MIN, self.params.ACCEL_MAX) + if self.frogs_go_moo_tune: + pcm_accel_cmd = clip(gas_accel + self.pcm_accel_comp, self.params.ACCEL_MIN, self.params.ACCEL_MAX) + else: + pcm_accel_cmd = clip(actuators.accel + accel_offset, self.params.ACCEL_MIN, self.params.ACCEL_MAX) else: pcm_accel_cmd = 0. diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index 8477600be..56bcb2ffb 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -55,6 +55,8 @@ class CarState(CarStateBase): self.zss_compute = False self.zss_cruise_active_last = False + self.pcm_accel_net = 0 + self.pcm_neutral_force = 0 self.zss_angle_offset = 0 self.zss_threshold_count = 0 @@ -221,6 +223,7 @@ class CarState(CarStateBase): message_keys = ["LDA_ON_MESSAGE", "SET_ME_X02"] self.lkas_enabled = any(self.lkas_hud.get(key) == 1 for key in message_keys) + self.pcm_accel_net = cp.vl["PCM_CRUISE"]["ACCEL_NET"] self.pcm_neutral_force = cp.vl["PCM_CRUISE"]["NEUTRAL_FORCE"] # ZSS Support - Credit goes to the DragonPilot team! diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 4666cc5e3..50a82301d 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -159,6 +159,13 @@ class CarInterface(CarInterfaceBase): tune.kiBP = [0., 35.] tune.kpV = [3.6, 2.4, 1.5] tune.kiV = [0.54, 0.36] + elif params.get_bool("FrogsGoMooTune"): + tune.kpV = [0.0] + tune.kiV = [0.5] + ret.stopAccel = -0.4 # Toyota requests -0.4 when stopped + ret.stoppingDecelRate = 0.1 # reach stopping target smoothly + ret.vEgoStopping = 0.15 # car is near 0.1 to 0.2 when car starts requesting stopping accel + ret.vEgoStarting = 0.15 # needs to be > or == vEgoStopping elif candidate in TSS2_CAR or ret.enableGasInterceptor: tune.kpV = [0.0] tune.kiV = [0.5]