diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index 2761146..9b9ac9a 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -7,7 +7,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 @@ -39,6 +39,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 @@ -61,6 +72,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 @@ -160,7 +174,7 @@ 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. @@ -168,9 +182,33 @@ class CarController(CarControllerBase): # only calculate pcm_accel_cmd when long is active to prevent disengagement from accelerator depression if CC.longActive: if frogpilot_variables.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: + 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) + pcm_accel_cmd = gas_accel + self.pcm_accel_comp + + if not CC.longActive: + pcm_accel_cmd = 0.0 + + pcm_accel_cmd = clip(pcm_accel_cmd, 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: + 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) + pcm_accel_cmd = gas_accel + self.pcm_accel_comp + + if not CC.longActive: + pcm_accel_cmd = 0.0 + + pcm_accel_cmd = clip(pcm_accel_cmd, 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 f0fa97a..99d9e1e 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 @@ -222,6 +224,9 @@ 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! if self.CP.flags & ToyotaFlags.ZSS and self.zss_threshold_count < ZSS_THRESHOLD_COUNT: zorro_steer = cp.vl["SECONDARY_STEER_ANGLE"]["ZORRO_STEER"] diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 83108bc..d2ffcf1 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -154,6 +154,25 @@ class CarInterface(CarInterfaceBase): tune.kpV = [0.8, 1.] tune.kiBP = [0., 5.] tune.kiV = [0.3, 1.] + elif params.get_bool("FrogsGoMooTune"): + tune.deadzoneBP = [0., 16., 20., 30.] + tune.deadzoneV = [0., .03, .06, .15] + + tune.kpBP = [0., 5., 20.] + tune.kpV = [1.3, 1.0, 0.7] + + # In MPH = [ 0, 27, 45, 60, 89] + tune.kiBP = [ 0., 12., 20., 27., 40.] + tune.kiV = [.35, .215, .195, .10, .01] + + if candidate in TSS2_CAR: + ret.stopAccel = -0.4 # Toyota requests -0.4 when stopped + else: + ret.stopAccel = -2.5 # on stock Toyota this is -2.5 + + ret.stoppingDecelRate = 0.17 + 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) and params.get_bool("DragonPilotTune"): # Credit goes to the DragonPilot team! tune.deadzoneBP = [0., 16., 20., 30.]