Esempio n. 1
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   has_relay=False,
                   car_fw=[]):
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint,
                                              has_relay)
        ret.carName = "gm"
        ret.safetyModel = car.CarParams.SafetyModel.gm  # default to gm
        ret.enableCruise = False  # stock cruise control is kept off

        # GM port is considered a community feature, since it disables AEB;
        # TODO: make a port that uses a car harness and it only intercepts the camera
        ret.communityFeature = True

        # Presence of a camera on the object bus is ok.
        # Have to go to read_only if ASCM is online (ACC-enabled cars),
        # or camera is on powertrain bus (LKA cars without ACC).
        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate, Ecu.fwdCamera) or \
                           has_relay or \
                           candidate == CAR.CADILLAC_CT6
        ret.openpilotLongitudinalControl = ret.enableCamera
        tire_stiffness_factor = 0.444  # not optimized yet

        # Start with a baseline lateral tuning for all GM vehicles. Override tuning as needed in each model section below.
        ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2], [0.00]]
        ret.lateralTuning.pid.kf = 0.00004  # full torque for 20 deg at 80mph means 0.00007818594
        ret.steerRateCost = 1.0
        ret.steerActuatorDelay = 0.1  # Default delay, not measured yet
        ret.enableGasInterceptor = 0x201 in fingerprint[0]
        #TODO: this should be case based
        if ret.enableGasInterceptor:
            ret.radarOffCan = False

        if candidate == CAR.VOLT:
            # supports stop and go, but initial engage must be above 18mph (which include conservatism)
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1607. + STD_CARGO_KG
            ret.wheelbase = 2.69
            ret.steerRatio = 15.7
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # wild guess

        elif candidate == CAR.BOLT:
            ret.minEnableSpeed = 25 * CV.MPH_TO_MS
            if ret.enableGasInterceptor:
                ret.minEnableSpeed = 5 * CV.MPH_TO_MS  #steering works down to 5mph; pedal to 0
            ret.mass = 1616. + STD_CARGO_KG
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.60096
            ret.steerRatio = 16.8
            ret.steerRatioRear = 0.
            ret.centerToFront = 2.0828  #ret.wheelbase * 0.4 # wild guess

            #-----------------------------------------------------------------------------
            # INDI
            #-----------------------------------------------------------------------------
            # timeconstant is smoothing. Higher values == more smoothing
            # actuatoreffectiveness is how much it steers. Lower values == more steering
            # outer and inner are gains. Higher values = more steering
            #
            # JJS - removing tuning as it was causing lane crossing
            #ret.steerActuatorDelay = 0.15
            #ret.lateralTuning.init('indi')
            #ret.lateralTuning.indi.innerLoopGain = 4.57 # rate error gain
            #ret.lateralTuning.indi.outerLoopGain = 13.1 # error gain
            #ret.lateralTuning.indi.timeConstant = 5.5
            #ret.lateralTuning.indi.actuatorEffectiveness = 6.79

            tire_stiffness_factor = 1.0

        elif candidate == CAR.MALIBU:
            # supports stop and go, but initial engage must be above 18mph (which include conservatism)
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1496. + STD_CARGO_KG
            ret.wheelbase = 2.83
            ret.steerRatio = 15.8
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # wild guess

        elif candidate == CAR.HOLDEN_ASTRA:
            ret.mass = 1363. + STD_CARGO_KG
            ret.wheelbase = 2.662
            # Remaining parameters copied from Volt for now
            ret.centerToFront = ret.wheelbase * 0.4
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.steerRatio = 15.7
            ret.steerRatioRear = 0.

        elif candidate == CAR.ACADIA:
            ret.minEnableSpeed = -1.  # engage speed is decided by pcm
            ret.mass = 4353. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.86
            ret.steerRatio = 14.4  #end to end is 13.46
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4

        elif candidate == CAR.BUICK_REGAL:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 3779. * CV.LB_TO_KG + STD_CARGO_KG  # (3849+3708)/2
            ret.wheelbase = 2.83  #111.4 inches in meters
            ret.steerRatio = 14.4  # guess for tourx
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # guess for tourx

        elif candidate == CAR.EQUINOX:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 3500. * CV.LB_TO_KG + STD_CARGO_KG  # (3849+3708)/2
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.72  #107.3 inches in meters
            ret.steerRatio = 14.4  # guess for tourx
            ret.steerRatioRear = 0.  # unknown online
            ret.centerToFront = ret.wheelbase * 0.4  # wild guess

        elif candidate == CAR.TAHOE:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 5602. * CV.LB_TO_KG + STD_CARGO_KG  # (3849+3708)/2
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.95  #116 inches in meters
            ret.steerRatio = 17.3  # guess for tourx
            ret.steerRatioRear = 0.  # unknown online
            ret.centerToFront = 2.59  # ret.wheelbase * 0.4 # wild guess

        elif candidate == CAR.CADILLAC_ATS:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1601. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 15.3
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.49

        elif candidate == CAR.CADILLAC_CT6:
            # engage speed is decided by pcm
            ret.minEnableSpeed = -1.
            ret.mass = 4016. * CV.LB_TO_KG + STD_CARGO_KG
            ret.safetyModel = car.CarParams.SafetyModel.cadillac
            ret.wheelbase = 3.11
            ret.steerRatio = 14.6  # it's 16.3 without rear active steering
            ret.steerRatioRear = 0.  # TODO: there is RAS on this car!
            ret.centerToFront = ret.wheelbase * 0.465

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        ret.longitudinalTuning.kpBP = [5., 35.]
        ret.longitudinalTuning.kpV = [2.4, 1.5]
        ret.longitudinalTuning.kiBP = [0.]
        ret.longitudinalTuning.kiV = [0.36]

        ret.stoppingControl = True
        ret.startAccel = 0.8

        ret.steerLimitTimer = 0.4
        ret.radarTimeStep = 0.0667  # GM radar runs at 15Hz instead of standard 20Hz

        return ret
Esempio n. 2
0
  def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False, car_fw=[]):  # pylint: disable=dangerous-default-value
    ret = CarInterfaceBase.get_std_params(candidate, fingerprint, has_relay)

    ret.carName = "hyundai"
    ret.safetyModel = car.CarParams.SafetyModel.hyundai
    ret.radarOffCan = True

    # Most Hyundai car ports are community features for now
    ret.communityFeature = candidate not in [CAR.SONATA]

    ret.steerActuatorDelay = 0.1  # Default delay
    ret.steerRateCost = 0.5
    ret.steerLimitTimer = 0.4
    tire_stiffness_factor = 1.

    if candidate == CAR.SANTA_FE:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 3982. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.766
      # Values from optimizer
      ret.steerRatio = 16.55  # 13.8 is spec end-to-end
      tire_stiffness_factor = 0.82
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[9., 22.], [9., 22.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2, 0.35], [0.05, 0.09]]
    elif candidate == CAR.SONATA:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 1513. + STD_CARGO_KG
      ret.wheelbase = 2.84
      ret.steerRatio = 13.27 * 1.15   # 15% higher at the center seems reasonable
      tire_stiffness_factor = 0.65
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate == CAR.SONATA_2019:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 4497. * CV.LB_TO_KG
      ret.wheelbase = 2.804
      ret.steerRatio = 13.27 * 1.15   # 15% higher at the center seems reasonable
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate == CAR.PALISADE:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 1999. + STD_CARGO_KG
      ret.wheelbase = 2.90
      ret.steerRatio = 13.75 * 1.15
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate == CAR.KIA_SORENTO:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 1985. + STD_CARGO_KG
      ret.wheelbase = 2.78
      ret.steerRatio = 14.4 * 1.1   # 10% higher at the center seems reasonable
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
      ret.lateralTuning.pid.kf = 0.00006
      ret.mass = 1275. + STD_CARGO_KG
      ret.wheelbase = 2.7
      ret.steerRatio = 15.4            # 14 is Stock | Settled Params Learner values are steerRatio: 15.401566348670535
      tire_stiffness_factor = 0.385    # stiffnessFactor settled on 1.0081302973865127
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
      ret.minSteerSpeed = 32 * CV.MPH_TO_MS
    elif candidate == CAR.HYUNDAI_GENESIS:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 2060. + STD_CARGO_KG
      ret.wheelbase = 3.01
      ret.steerRatio = 16.5
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16], [0.01]]
      ret.minSteerSpeed = 60 * CV.KPH_TO_MS
    elif candidate == CAR.GENESIS_G80:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 2060. + STD_CARGO_KG
      ret.wheelbase = 3.01
      ret.steerRatio = 16.5
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16], [0.01]]
    elif candidate == CAR.GENESIS_G90:
      ret.mass = 2200
      ret.wheelbase = 3.15
      ret.steerRatio = 12.069
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16], [0.01]]
    elif candidate in [CAR.KIA_OPTIMA, CAR.KIA_OPTIMA_H]:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 3558. * CV.LB_TO_KG
      ret.wheelbase = 2.80
      ret.steerRatio = 13.75
      tire_stiffness_factor = 0.5
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate == CAR.KIA_STINGER:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 1825. + STD_CARGO_KG
      ret.wheelbase = 2.78
      ret.steerRatio = 14.4 * 1.15   # 15% higher at the center seems reasonable
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate == CAR.KONA:
      ret.lateralTuning.pid.kf = 0.00006
      ret.mass = 1275. + STD_CARGO_KG
      ret.wheelbase = 2.7
      ret.steerRatio = 13.73  # Spec
      tire_stiffness_factor = 0.385
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate == CAR.KONA_EV:
      ret.lateralTuning.pid.kf = 0.00006
      ret.mass = 1685. + STD_CARGO_KG
      ret.wheelbase = 2.7
      ret.steerRatio = 13.73  # Spec
      tire_stiffness_factor = 0.385
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
    elif candidate in [CAR.IONIQ, CAR.IONIQ_EV_LTD]:
      ret.lateralTuning.pid.kf = 0.00006
      ret.mass = 1490. + STD_CARGO_KG   #weight per hyundai site https://www.hyundaiusa.com/ioniq-electric/specifications.aspx
      ret.wheelbase = 2.7
      ret.steerRatio = 13.73   #Spec
      tire_stiffness_factor = 0.385
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]
      ret.minSteerSpeed = 32 * CV.MPH_TO_MS
    elif candidate == CAR.KIA_FORTE:
      ret.lateralTuning.pid.kf = 0.00005
      ret.mass = 3558. * CV.LB_TO_KG
      ret.wheelbase = 2.80
      ret.steerRatio = 13.75
      tire_stiffness_factor = 0.5
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]

    # these cars require a special panda safety mode due to missing counters and checksums in the messages
    if candidate in [CAR.HYUNDAI_GENESIS, CAR.IONIQ_EV_LTD, CAR.IONIQ, CAR.KONA_EV, CAR.KIA_SORENTO, CAR.SONATA_2019, CAR.KIA_OPTIMA]:
      ret.safetyModel = car.CarParams.SafetyModel.hyundaiLegacy

    ret.centerToFront = ret.wheelbase * 0.4

    # TODO: get actual value, for now starting with reasonable value for
    # civic and scaling by mass and wheelbase
    ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

    # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
    # mass and CG position, so all cars will have approximately similar dyn behaviors
    ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
                                                                         tire_stiffness_factor=tire_stiffness_factor)

    ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate, Ecu.fwdCamera) or has_relay

    return ret
Esempio n. 3
0
  def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]):  # pylint: disable=dangerous-default-value
    ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
    ret.carName = "honda"

    if candidate in HONDA_BOSCH:
      ret.safetyModel = car.CarParams.SafetyModel.hondaBoschHarness
      ret.enableCamera = True
      ret.radarOffCan = True
      ret.openpilotLongitudinalControl = False
    else:
      ret.safetyModel = car.CarParams.SafetyModel.hondaNidec
      ret.enableCamera = True
      ret.enableGasInterceptor = 0x201 in fingerprint[0]
      ret.openpilotLongitudinalControl = ret.enableCamera

    cloudlog.warning("ECU Camera Simulated: %r", ret.enableCamera)
    cloudlog.warning("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

    ret.enableCruise = not ret.enableGasInterceptor
    ret.communityFeature = ret.enableGasInterceptor

    # Certain Hondas have an extra steering sensor at the bottom of the steering rack,
    # which improves controls quality as it removes the steering column torsion from feedback.
    # Tire stiffness factor fictitiously lower if it includes the steering column torsion effect.
    # For modeling details, see p.198-200 in "The Science of Vehicle Dynamics (2014), M. Guiggiani"
    ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0], [0]]
    ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
    ret.lateralTuning.pid.kf = 0.00006  # conservative feed-forward

    eps_modified = False
    for fw in car_fw:
      if fw.ecu == "eps" and b"," in fw.fwVersion:
        eps_modified = True

    if candidate == CAR.CIVIC:
      stop_and_go = True
      ret.mass = CivicParams.MASS
      ret.wheelbase = CivicParams.WHEELBASE
      ret.centerToFront = CivicParams.CENTER_TO_FRONT
      ret.steerRatio = 15.38  # 10.93 is end-to-end spec
      if eps_modified:
        # stock request input values:     0x0000, 0x00DE, 0x014D, 0x01EF, 0x0290, 0x0377, 0x0454, 0x0610, 0x06EE
        # stock request output values:    0x0000, 0x0917, 0x0DC5, 0x1017, 0x119F, 0x140B, 0x1680, 0x1680, 0x1680
        # modified request output values: 0x0000, 0x0917, 0x0DC5, 0x1017, 0x119F, 0x140B, 0x1680, 0x2880, 0x3180
        # stock filter output values:     0x009F, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108
        # modified filter output values:  0x009F, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0400, 0x0480
        # note: max request allowed is 4096, but request is capped at 3840 in firmware, so modifications result in 2x max
        ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 2560, 8000], [0, 2560, 3840]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3], [0.1]]
      else:
        ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 2560], [0, 2560]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[1.1], [0.33]]
      tire_stiffness_factor = 1.

      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [3.6, 2.4, 1.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.54, 0.36]

    elif candidate in (CAR.CIVIC_BOSCH, CAR.CIVIC_BOSCH_DIESEL):
      stop_and_go = True
      ret.mass = CivicParams.MASS
      ret.wheelbase = CivicParams.WHEELBASE
      ret.centerToFront = CivicParams.CENTER_TO_FRONT
      ret.steerRatio = 15.38  # 10.93 is end-to-end spec
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 1.
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8], [0.24]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate in (CAR.ACCORD, CAR.ACCORD_15, CAR.ACCORDH):
      stop_and_go = True
      if not candidate == CAR.ACCORDH:  # Hybrid uses same brake msg as hatch
        ret.safetyParam = 1  # Accord(ICE), CRV 5G, and RDX 3G use an alternate user brake msg
      ret.mass = 3279. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.83
      ret.centerToFront = ret.wheelbase * 0.39
      ret.steerRatio = 16.33  # 11.82 is spec end-to-end
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.8467
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

      if eps_modified:
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3], [0.09]]
      else:
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.18]]

    elif candidate == CAR.ACURA_ILX:
      stop_and_go = False
      ret.mass = 3095. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.67
      ret.centerToFront = ret.wheelbase * 0.37
      ret.steerRatio = 18.61  # 15.3 is spec end-to-end
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 3840], [0, 3840]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.72
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8], [0.24]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate in (CAR.CRV, CAR.CRV_EU):
      stop_and_go = False
      ret.mass = 3572. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.62
      ret.centerToFront = ret.wheelbase * 0.41
      ret.steerRatio = 16.89  # as spec
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 1000], [0, 1000]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.444
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8], [0.24]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.CRV_5G:
      stop_and_go = True
      ret.safetyParam = 1  # Accord(ICE), CRV 5G, and RDX 3G use an alternate user brake msg
      ret.mass = 3410. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.66
      ret.centerToFront = ret.wheelbase * 0.41
      ret.steerRatio = 16.0  # 12.3 is spec end-to-end
      if eps_modified:
        # stock request input values:     0x0000, 0x00DB, 0x01BB, 0x0296, 0x0377, 0x0454, 0x0532, 0x0610, 0x067F
        # stock request output values:    0x0000, 0x0500, 0x0A15, 0x0E6D, 0x1100, 0x1200, 0x129A, 0x134D, 0x1400
        # modified request output values: 0x0000, 0x0500, 0x0A15, 0x0E6D, 0x1100, 0x1200, 0x1ACD, 0x239A, 0x2800
        ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 2560, 10000], [0, 2560, 3840]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.21], [0.07]]
      else:
        ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 3840], [0, 3840]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.64], [0.192]]
      tire_stiffness_factor = 0.677
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.CRV_HYBRID:
      stop_and_go = True
      ret.safetyParam = 1  # Accord(ICE), CRV 5G, and RDX 3G use an alternate user brake msg
      ret.mass = 1667. + STD_CARGO_KG  # mean of 4 models in kg
      ret.wheelbase = 2.66
      ret.centerToFront = ret.wheelbase * 0.41
      ret.steerRatio = 16.0  # 12.3 is spec end-to-end
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.677
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.18]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.FIT:
      stop_and_go = False
      ret.mass = 2644. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.53
      ret.centerToFront = ret.wheelbase * 0.39
      ret.steerRatio = 13.06
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.75
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.06]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.HRV:
      stop_and_go = False
      ret.mass = 3125 * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.61
      ret.centerToFront = ret.wheelbase * 0.41
      ret.steerRatio = 15.2
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]
      tire_stiffness_factor = 0.5
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16], [0.025]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.ACURA_RDX:
      stop_and_go = False
      ret.mass = 3935. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.68
      ret.centerToFront = ret.wheelbase * 0.38
      ret.steerRatio = 15.0  # as spec
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 1000], [0, 1000]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.444
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8], [0.24]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.ACURA_RDX_3G:
      stop_and_go = True
      ret.safetyParam = 1  # Accord(ICE), CRV 5G, and RDX 3G use an alternate user brake msg
      ret.mass = 4068. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.75
      ret.centerToFront = ret.wheelbase * 0.41
      ret.steerRatio = 11.95  # as spec
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 3840], [0, 3840]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.18]]
      tire_stiffness_factor = 0.677
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.ODYSSEY:
      stop_and_go = False
      ret.mass = 4471. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 3.00
      ret.centerToFront = ret.wheelbase * 0.41
      ret.steerRatio = 14.35  # as spec
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.82
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.45], [0.135]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.ODYSSEY_CHN:
      stop_and_go = False
      ret.mass = 1849.2 + STD_CARGO_KG  # mean of 4 models in kg
      ret.wheelbase = 2.90
      ret.centerToFront = ret.wheelbase * 0.41  # from CAR.ODYSSEY
      ret.steerRatio = 14.35
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 32767], [0, 32767]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.82
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.45], [0.135]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate in (CAR.PILOT, CAR.PILOT_2019):
      stop_and_go = False
      ret.mass = 4204. * CV.LB_TO_KG + STD_CARGO_KG  # average weight
      ret.wheelbase = 2.82
      ret.centerToFront = ret.wheelbase * 0.428
      ret.steerRatio = 17.25  # as spec
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.444
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.38], [0.11]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.RIDGELINE:
      stop_and_go = False
      ret.mass = 4515. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 3.18
      ret.centerToFront = ret.wheelbase * 0.41
      ret.steerRatio = 15.59  # as spec
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.444
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.38], [0.11]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    elif candidate == CAR.INSIGHT:
      stop_and_go = True
      ret.mass = 2987. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.7
      ret.centerToFront = ret.wheelbase * 0.39
      ret.steerRatio = 15.0  # 12.58 is spec end-to-end
      ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096], [0, 4096]]  # TODO: determine if there is a dead zone at the top end
      tire_stiffness_factor = 0.82
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.18]]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.12]

    else:
      raise ValueError("unsupported car %s" % candidate)

    # min speed to enable ACC. if car can do stop and go, then set enabling speed
    # to a negative value, so it won't matter. Otherwise, add 0.5 mph margin to not
    # conflict with PCM acc
    ret.minEnableSpeed = -1. if (stop_and_go or ret.enableGasInterceptor) else 25.5 * CV.MPH_TO_MS

    # TODO: get actual value, for now starting with reasonable value for
    # civic and scaling by mass and wheelbase
    ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

    # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
    # mass and CG position, so all cars will have approximately similar dyn behaviors
    ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
                                                                         tire_stiffness_factor=tire_stiffness_factor)

    ret.gasMaxBP = [0.]  # m/s
    ret.gasMaxV = [0.6] if ret.enableGasInterceptor else [0.]  # max gas allowed
    ret.brakeMaxBP = [5., 20.]  # m/s
    ret.brakeMaxV = [1., 0.8]   # max brake allowed

    ret.stoppingControl = True
    ret.startAccel = 0.5

    ret.steerActuatorDelay = 0.1
    ret.steerRateCost = 0.5
    ret.steerLimitTimer = 0.8

    return ret
Esempio n. 4
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   has_relay=False,
                   car_fw=[]):
        global ATOMC
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint,
                                              has_relay)

        ret.carName = "hyundai"
        ret.safetyModel = car.CarParams.SafetyModel.hyundai
        ret.radarOffCan = False  #False(선행차우선)  #True(차선우선)    #선행차량 인식 마크 유무.

        ret.radarOffCan = bool(params.get('OpkrTraceSet') != b'1')
        ret.lateralsRatom.learnerParams = int(params.get('OpkrEnableLearner'))

        # Hyundai port is a community feature for now
        ret.communityFeature = False  #True

        ret.longcontrolEnabled = False
        """
      0.7.5
      ret.steerActuatorDelay = 0.1  # Default delay   0.1
      ret.steerRateCost = 0.5
      ret.steerLimitTimer = 0.4
      tire_stiffness_factor = 1
    """
        """
      0.7.3
      ret.steerActuatorDelay = 0.10  # Default delay   0.15
      ret.steerRateCost = 0.45
      ret.steerLimitTimer = 0.8
      tire_stiffness_factor = 0.7
    """

        tire_stiffness_factor = 1.
        ret.steerActuatorDelay = 0.15  # Default delay
        ret.steerRateCost = 0.5
        ret.steerLimitTimer = 0.4

        if candidate == CAR.GRANDEUR_H_19:
            ret.lateralTuning.pid.kf = 0.000005
            ret.mass = 1675. + STD_CARGO_KG
            ret.wheelbase = 2.845
            ret.steerRatio = 12.5  #12.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        if candidate == CAR.GRANDEUR_H_20:
            ret.steerActuatorDelay = 0.08
            ret.steerLimitTimer = 0.8  # stock is 0.01 but 0.04 seems to work well
            tire_stiffness_factor = 1.0
            ret.steerRateCost = 0.5
            ret.mass = 1675. + STD_CARGO_KG
            ret.wheelbase = 2.885
            ret.steerRatio = 13.0  #12.5

            #ret.lateralTuning.pid.kf = 0.000005
            #ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
            #ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.20], [0.05]]
            #lqr
            ret.lateralTuning.init('lqr')
            ret.lateralTuning.lqr.scale = 2500.0
            ret.lateralTuning.lqr.ki = 0.05
            ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
            ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
            ret.lateralTuning.lqr.c = [1., 0.]
            ret.lateralTuning.lqr.k = [-110.73572306, 451.22718255]
            ret.lateralTuning.lqr.l = [0.3233671, 0.3185757]
            ret.lateralTuning.lqr.dcGain = 0.002237852961363602
            # indi
            #ret.lateralTuning.init('indi')
            #ret.lateralTuning.indi.innerLoopGain = 3.0
            #ret.lateralTuning.indi.outerLoopGain = 2.0
            #ret.lateralTuning.indi.timeConstant = 1.0
            #ret.lateralTuning.indi.actuatorEffectiveness = 1.5

        elif candidate == CAR.SANTA_FE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3982. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.766
            # Values from optimizer
            ret.steerRatio = 16.55  # 13.8 is spec end-to-end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                9., 22.
            ], [9., 22.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.2, 0.35
            ], [0.05, 0.09]]
        elif candidate == CAR.SONATA:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1513. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.SONATA_2019:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 4497. * CV.LB_TO_KG
            ret.wheelbase = 2.804
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.PALISADE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1999. + STD_CARGO_KG
            ret.wheelbase = 2.90
            ret.steerRatio = 13.75 * 1.15
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_SORENTO:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.1  # 10% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 15.4  # 14 is Stock | Settled Params Learner values are steerRatio: 15.401566348670535
            tire_stiffness_factor = 0.385  # stiffnessFactor settled on 1.0081302973865127
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.HYUNDAI_GENESIS:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
            ret.minSteerSpeed = 60 * CV.KPH_TO_MS
        elif candidate == CAR.GENESIS_G80:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate == CAR.GENESIS_G90:
            ret.mass = 2200
            ret.wheelbase = 3.15
            ret.steerRatio = 12.069
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate in [CAR.KIA_OPTIMA, CAR.KIA_OPTIMA_H]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_STINGER:
            #ret.lateralTuning.pid.kf = 0.00005
            #ret.mass = 1825. + STD_CARGO_KG
            #ret.wheelbase = 2.78
            #ret.steerRatio = 14.4 * 1.15   # 15% higher at the center seems reasonable
            #ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
            #ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]]

            #lqr
            #ret.lateralTuning.init('lqr')
            #ret.lateralTuning.lqr.scale = 2500.0
            #ret.lateralTuning.lqr.ki = 0.05
            #ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
            #ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
            #ret.lateralTuning.lqr.c = [1., 0.]
            #ret.lateralTuning.lqr.k = [-110.73572306, 451.22718255]
            #ret.lateralTuning.lqr.l = [0.3233671, 0.3185757]
            #ret.lateralTuning.lqr.dcGain = 0.002237852961363602

            # indi
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGain = 3.0
            ret.lateralTuning.indi.outerLoopGain = 2.0
            ret.lateralTuning.indi.timeConstant = 1.0
            ret.lateralTuning.indi.actuatorEffectiveness = 1.5
            ret.steerActuatorDelay = 0.08  # Stinger GT Limited AWD 3.3T stock value (Tunder's 2020)
            ret.steerLimitTimer = 0.4  # stock is 0.01 but 0.04 seems to work well
            tire_stiffness_factor = 1.125  # LiveParameters (Tunder's 2020)
            ret.steerRateCost = 1.0
            ret.mass = 1825.0 + STD_CARGO_KG
            ret.wheelbase = 2.906  # https://www.kia.com/us/en/stinger/specs
            ret.steerRatio = 13.56  # 10.28 measured by wheel alignment machine/reported steering angle by OP. 2020 GT Limited AWD has a variable steering ratio ultimately ending in 10.28.  13.56 after 1200km in LiveParamaters (Tunder)
        elif candidate == CAR.KONA:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KONA_EV:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1685. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_FORTE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]

        if ATOMC.tun_type == 'pid':
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif ATOMC.tun_type == 'indi':
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGain = 3.0
            ret.lateralTuning.indi.outerLoopGain = 2.0
            ret.lateralTuning.indi.timeConstant = 1.0
            ret.lateralTuning.indi.actuatorEffectiveness = 1.5
        elif ATOMC.tun_type == 'lqr':
            ret.lateralTuning.init('lqr')
            ret.lateralTuning.lqr.scale = 2000.0
            ret.lateralTuning.lqr.ki = 0.02
            ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
            ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
            ret.lateralTuning.lqr.c = [1., 0.]
            ret.lateralTuning.lqr.k = [-100., 450.]
            ret.lateralTuning.lqr.l = [0.22, 0.318]
            ret.lateralTuning.lqr.dcGain = 0.003

        ret.atomTuning.cvKPH = ATOMC.cv_KPH
        ret.atomTuning.cvBPV = ATOMC.cv_BPV
        ret.atomTuning.cvsMaxV = ATOMC.cv_sMaxV
        ret.atomTuning.cvsdUpV = ATOMC.cv_sdUPV
        ret.atomTuning.cvsdDnV = ATOMC.cv_sdDNV

        ret.atomTuning.sRKPH = ATOMC.sR_KPH
        ret.atomTuning.sRBPV = ATOMC.sR_BPV
        ret.atomTuning.sRlqrkiV = ATOMC.sR_lqr_kiV
        ret.atomTuning.sRlqrscaleV = ATOMC.sR_lqr_scaleV
        ret.atomTuning.sRpidKiV = ATOMC.sR_pid_KiV
        ret.atomTuning.sRpidKpV = ATOMC.sR_pid_KpV
        ret.atomTuning.sRsteerRatioV = ATOMC.sR_steerRatioV
        ret.atomTuning.sRsteerActuatorDelayV = ATOMC.sR_ActuatorDelayV

        ret.lateralsRatom.deadzone = ATOMC.sR_pid_deadzone
        ret.lateralsRatom.steerOffset = ATOMC.steerOffset
        ret.lateralsRatom.cameraOffset = ATOMC.cameraOffset

        ret.steerRateCost = ATOMC.steerRateCost
        ret.steerLimitTimer = ATOMC.steerLimitTimer

        ret.centerToFront = ret.wheelbase * 0.4

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS,
                                               ECU_FINGERPRINT, candidate,
                                               Ecu.fwdCamera) or has_relay

        return ret
Esempio n. 5
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   vin="",
                   has_relay=False):
        ret = car.CarParams.new_message()

        ret.carName = "gm"
        ret.carFingerprint = candidate
        ret.carVin = vin
        ret.isPandaBlack = has_relay

        ret.enableCruise = False

        # Presence of a camera on the object bus is ok.
        # Have to go to read_only if ASCM is online (ACC-enabled cars),
        # or camera is on powertrain bus (LKA cars without ACC).
        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate, ECU.CAM) or \
                           has_relay or \
                           candidate == CAR.CADILLAC_CT6
        ret.openpilotLongitudinalControl = ret.enableCamera
        tire_stiffness_factor = 0.444  # not optimized yet
        ret.safetyModelPassive = car.CarParams.SafetyModel.gmPassive

        if candidate == CAR.VOLT:
            # supports stop and go, but initial engage must be above 18mph (which include conservatism)
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1607. + STD_CARGO_KG
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.69
            ret.steerRatio = 15.7
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # wild guess

        elif candidate == CAR.MALIBU:
            # supports stop and go, but initial engage must be above 18mph (which include conservatism)
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1496. + STD_CARGO_KG
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.83
            ret.steerRatio = 15.8
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # wild guess

        elif candidate == CAR.HOLDEN_ASTRA:
            ret.mass = 1363. + STD_CARGO_KG
            ret.wheelbase = 2.662
            # Remaining parameters copied from Volt for now
            ret.centerToFront = ret.wheelbase * 0.4
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.steerRatio = 15.7
            ret.steerRatioRear = 0.

        elif candidate == CAR.ACADIA:
            ret.minEnableSpeed = -1.  # engage speed is decided by pcm
            ret.mass = 4353. * CV.LB_TO_KG + STD_CARGO_KG
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.86
            ret.steerRatio = 14.4  #end to end is 13.46
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4

        elif candidate == CAR.BUICK_REGAL:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 3779. * CV.LB_TO_KG + STD_CARGO_KG  # (3849+3708)/2
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.83  #111.4 inches in meters
            ret.steerRatio = 14.4  # guess for tourx
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # guess for tourx

        elif candidate == CAR.CADILLAC_ATS:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1601. + STD_CARGO_KG
            ret.safetyModel = car.CarParams.SafetyModel.gm
            ret.wheelbase = 2.78
            ret.steerRatio = 15.3
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.49

        elif candidate == CAR.CADILLAC_CT6:
            # engage speed is decided by pcm
            ret.minEnableSpeed = -1.
            ret.mass = 4016. * CV.LB_TO_KG + STD_CARGO_KG
            ret.safetyModel = car.CarParams.SafetyModel.cadillac
            ret.wheelbase = 3.11
            ret.steerRatio = 14.6  # it's 16.3 without rear active steering
            ret.steerRatioRear = 0.  # TODO: there is RAS on this car!
            ret.centerToFront = ret.wheelbase * 0.465

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        # same tuning for Volt and CT6 for now
        ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2], [0.00]]
        ret.lateralTuning.pid.kf = 0.00004  # full torque for 20 deg at 80mph means 0.00007818594

        ret.steerMaxBP = [0.]  # m/s
        ret.steerMaxV = [1.]
        ret.gasMaxBP = [0.]
        ret.gasMaxV = [.5]
        ret.brakeMaxBP = [0.]
        ret.brakeMaxV = [1.]

        ret.longitudinalTuning.kpBP = [5., 35.]
        ret.longitudinalTuning.kpV = [2.4, 1.5]
        ret.longitudinalTuning.kiBP = [0.]
        ret.longitudinalTuning.kiV = [0.36]
        ret.longitudinalTuning.deadzoneBP = [0.]
        ret.longitudinalTuning.deadzoneV = [0.]

        ret.steerLimitAlert = True

        ret.stoppingControl = True
        ret.startAccel = 0.8

        ret.steerActuatorDelay = 0.1  # Default delay, not measured yet
        ret.steerRateCost = 1.0
        ret.steerControlType = car.CarParams.SteerControlType.torque

        return ret
Esempio n. 6
0
  def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False, car_fw=[]):  # pylint: disable=dangerous-default-value
    ret = CarInterfaceBase.get_std_params(candidate, fingerprint, has_relay)

    # Set global default parameters
    ret.radarOffCan = True
    ret.enableCamera = True  # Stock camera detection doesn't apply to VW
    ret.steerRateCost = 1.0
    ret.steerActuatorDelay = 0.05  # Hopefully all racks are similar here
    ret.steerLimitTimer = 0.4

    # Override these per-car as necessary
    ret.lateralTuning.pid.kpBP = [0.]
    ret.lateralTuning.pid.kiBP = [0.]
    ret.lateralTuning.pid.kpV = [0.6]
    ret.lateralTuning.pid.kiV = [0.2]
    ret.lateralTuning.pid.kf = 0.00006

    # PER-PLATFORM PARAMETERS - DO NOT EDIT HERE TO TUNE INDIVIDUAL VEHICLES

    if candidate in MQB_CARS:
      # Configurations shared between all MQB vehicles
      ret.carName = "volkswagen"
      ret.safetyModel = car.CarParams.SafetyModel.volkswagen

      # Determine installed network location and trans type from fingerprint
      ret.networkLocation = NWL.fwdCamera if 0x122 in fingerprint[0] else NWL.gateway
      if 0xAD in fingerprint[0]:  # Getriebe_11
        ret.transmissionType = TRANS.automatic
      elif 0x187 in fingerprint[0]:  # EV_Gearshift
        ret.transmissionType = TRANS.direct
      else:  # No trans at all
        ret.transmissionType = TRANS.manual

    elif candidate in PQ_CARS:
      # Configurations shared between all PQ35/PQ46/NMS vehicles
      ret.carName = "volkswagen"
      ret.safetyModel = car.CarParams.SafetyModel.volkswagenPq

      # Determine installed network location and trans type from fingerprint
      ret.networkLocation = NWL.fwdCamera if 0x368 in fingerprint[0] else NWL.gateway
      if 0x440 in fingerprint[0]:  # Getriebe_1
        ret.transmissionType = TRANS.automatic
      else:  # No trans at all
        ret.transmissionType = TRANS.manual

    # PER-VEHICLE PARAMETERS - EDIT HERE TO TUNE INDIVIDUAL VEHICLES

    if candidate == CAR.GENERICMQB:
      # FIXME: Defaulting to VW Golf Mk7 as a baseline.
      ret.mass = 1500 + STD_CARGO_KG  # Average, varies on trim/package
      ret.wheelbase = 2.64
      ret.centerToFront = ret.wheelbase * 0.45  # Estimated
      ret.steerRatio = 15.6
      tire_stiffness_factor = 1.0

    elif candidate == CAR.GENERICPQ:
      ret.mass = 1375 + STD_CARGO_KG  # Average, varies on trim/package
      ret.wheelbase = 2.58
      ret.centerToFront = ret.wheelbase * 0.45  # Estimated
      ret.steerRatio = 15.6
      tire_stiffness_factor = 1.0

    # TODO: get actual value, for now starting with reasonable value for
    # civic and scaling by mass and wheelbase
    ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

    # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
    # mass and CG position, so all cars will have approximately similar dyn behaviors
    ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
                                                                         tire_stiffness_factor=tire_stiffness_factor)

    return ret
Esempio n. 7
0
 def get_params(candidate,
                fingerprint=gen_empty_fingerprint(),
                car_fw=None):
     raise NotImplementedError
Esempio n. 8
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   car_fw=[],
                   disable_radar=False):  # pylint: disable=dangerous-default-value
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
        ret.carName = "honda"

        if candidate in HONDA_BOSCH:
            ret.safetyConfigs = [
                get_safety_config(car.CarParams.SafetyModel.hondaBosch)
            ]
            ret.radarOffCan = True

            # Disable the radar and let openpilot control longitudinal
            # WARNING: THIS DISABLES AEB!
            ret.openpilotLongitudinalControl = disable_radar

            ret.pcmCruise = not ret.openpilotLongitudinalControl
        else:
            ret.safetyConfigs = [
                get_safety_config(car.CarParams.SafetyModel.hondaNidec)
            ]
            ret.enableGasInterceptor = 0x201 in fingerprint[0]
            ret.openpilotLongitudinalControl = True

            ret.pcmCruise = not ret.enableGasInterceptor

        if candidate == CAR.CRV_5G:
            ret.enableBsm = 0x12f8bfa7 in fingerprint[0]

        # Detect Bosch cars with new HUD msgs
        if any(0x33DA in f for f in fingerprint.values()):
            ret.flags |= HondaFlags.BOSCH_EXT_HUD.value

        # Accord 1.5T CVT has different gearbox message
        if candidate == CAR.ACCORD and 0x191 in fingerprint[1]:
            ret.transmissionType = TransmissionType.cvt

        # Certain Hondas have an extra steering sensor at the bottom of the steering rack,
        # which improves controls quality as it removes the steering column torsion from feedback.
        # Tire stiffness factor fictitiously lower if it includes the steering column torsion effect.
        # For modeling details, see p.198-200 in "The Science of Vehicle Dynamics (2014), M. Guiggiani"
        ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0], [0]]
        ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
        ret.lateralTuning.pid.kf = 0.00006  # conservative feed-forward

        if candidate in HONDA_BOSCH:
            ret.longitudinalTuning.kpV = [0.25]
            ret.longitudinalTuning.kiV = [0.05]
            ret.longitudinalActuatorDelayUpperBound = 0.5  # s
        else:
            # default longitudinal tuning for all hondas
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        eps_modified = False
        for fw in car_fw:
            if fw.ecu == "eps" and b"," in fw.fwVersion:
                eps_modified = True

        if candidate == CAR.CIVIC:
            stop_and_go = True
            ret.mass = CivicParams.MASS
            ret.wheelbase = CivicParams.WHEELBASE
            ret.centerToFront = CivicParams.CENTER_TO_FRONT
            ret.steerRatio = 15.38  # 10.93 is end-to-end spec
            if eps_modified:
                # stock request input values:     0x0000, 0x00DE, 0x014D, 0x01EF, 0x0290, 0x0377, 0x0454, 0x0610, 0x06EE
                # stock request output values:    0x0000, 0x0917, 0x0DC5, 0x1017, 0x119F, 0x140B, 0x1680, 0x1680, 0x1680
                # modified request output values: 0x0000, 0x0917, 0x0DC5, 0x1017, 0x119F, 0x140B, 0x1680, 0x2880, 0x3180
                # stock filter output values:     0x009F, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108
                # modified filter output values:  0x009F, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0108, 0x0400, 0x0480
                # note: max request allowed is 4096, but request is capped at 3840 in firmware, so modifications result in 2x max
                ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[
                    0, 2560, 8000
                ], [0, 2560, 3840]]
                ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                        [0.1]]
            else:
                ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[
                    0, 2560
                ], [0, 2560]]
                ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[1.1],
                                                                        [0.33]]
            tire_stiffness_factor = 1.

        elif candidate in (CAR.CIVIC_BOSCH, CAR.CIVIC_BOSCH_DIESEL):
            stop_and_go = True
            ret.mass = CivicParams.MASS
            ret.wheelbase = CivicParams.WHEELBASE
            ret.centerToFront = CivicParams.CENTER_TO_FRONT
            ret.steerRatio = 15.38  # 10.93 is end-to-end spec
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 1.
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]

        elif candidate in (CAR.ACCORD, CAR.ACCORDH):
            stop_and_go = True
            ret.mass = 3279. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.83
            ret.centerToFront = ret.wheelbase * 0.39
            ret.steerRatio = 16.33  # 11.82 is spec end-to-end
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.8467

            if eps_modified:
                ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                        [0.09]]
            else:
                ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                        [0.18]]

        elif candidate == CAR.ACURA_ILX:
            stop_and_go = False
            ret.mass = 3095. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.37
            ret.steerRatio = 18.61  # 15.3 is spec end-to-end
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 3840], [0, 3840]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.72
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]

        elif candidate in (CAR.CRV, CAR.CRV_EU):
            stop_and_go = False
            ret.mass = 3572. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.62
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 16.89  # as spec
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 1000], [0, 1000]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.444
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]
            ret.wheelSpeedFactor = 1.025

        elif candidate == CAR.CRV_5G:
            stop_and_go = True
            ret.mass = 3410. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.66
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 16.0  # 12.3 is spec end-to-end
            if eps_modified:
                # stock request input values:     0x0000, 0x00DB, 0x01BB, 0x0296, 0x0377, 0x0454, 0x0532, 0x0610, 0x067F
                # stock request output values:    0x0000, 0x0500, 0x0A15, 0x0E6D, 0x1100, 0x1200, 0x129A, 0x134D, 0x1400
                # modified request output values: 0x0000, 0x0500, 0x0A15, 0x0E6D, 0x1100, 0x1200, 0x1ACD, 0x239A, 0x2800
                ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[
                    0, 2560, 10000
                ], [0, 2560, 3840]]
                ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.21],
                                                                        [0.07]]
            else:
                ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[
                    0, 3840
                ], [0, 3840]]
                ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                    0.64
                ], [0.192]]
            tire_stiffness_factor = 0.677
            ret.wheelSpeedFactor = 1.025

        elif candidate == CAR.CRV_HYBRID:
            stop_and_go = True
            ret.mass = 1667. + STD_CARGO_KG  # mean of 4 models in kg
            ret.wheelbase = 2.66
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 16.0  # 12.3 is spec end-to-end
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.677
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.18]]
            ret.wheelSpeedFactor = 1.025

        elif candidate == CAR.FIT:
            stop_and_go = False
            ret.mass = 2644. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.53
            ret.centerToFront = ret.wheelbase * 0.39
            ret.steerRatio = 13.06
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.75
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2],
                                                                    [0.05]]

        elif candidate == CAR.FREED:
            stop_and_go = False
            ret.mass = 3086. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.74
            # the remaining parameters were copied from FIT
            ret.centerToFront = ret.wheelbase * 0.39
            ret.steerRatio = 13.06
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096],
                                                                     [0, 4096]]
            tire_stiffness_factor = 0.75
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2],
                                                                    [0.05]]

        elif candidate == CAR.HRV:
            stop_and_go = False
            ret.mass = 3125 * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.61
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 15.2
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 4096],
                                                                     [0, 4096]]
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.025]]
            ret.wheelSpeedFactor = 1.025

        elif candidate == CAR.ACURA_RDX:
            stop_and_go = False
            ret.mass = 3935. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.68
            ret.centerToFront = ret.wheelbase * 0.38
            ret.steerRatio = 15.0  # as spec
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 1000], [0, 1000]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.444
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]

        elif candidate == CAR.ACURA_RDX_3G:
            stop_and_go = True
            ret.mass = 4068. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.75
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 11.95  # as spec
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [[0, 3840],
                                                                     [0, 3840]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2],
                                                                    [0.06]]
            tire_stiffness_factor = 0.677

        elif candidate == CAR.ODYSSEY:
            stop_and_go = False
            ret.mass = 4471. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 3.00
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 14.35  # as spec
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.28],
                                                                    [0.08]]

        elif candidate == CAR.ODYSSEY_CHN:
            stop_and_go = False
            ret.mass = 1849.2 + STD_CARGO_KG  # mean of 4 models in kg
            ret.wheelbase = 2.90
            ret.centerToFront = ret.wheelbase * 0.41  # from CAR.ODYSSEY
            ret.steerRatio = 14.35
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 32767], [0, 32767]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.28],
                                                                    [0.08]]

        elif candidate in (CAR.PILOT, CAR.PASSPORT):
            stop_and_go = False
            ret.mass = 4204. * CV.LB_TO_KG + STD_CARGO_KG  # average weight
            ret.wheelbase = 2.82
            ret.centerToFront = ret.wheelbase * 0.428
            ret.steerRatio = 17.25  # as spec
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.444
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.38],
                                                                    [0.11]]

        elif candidate == CAR.RIDGELINE:
            stop_and_go = False
            ret.mass = 4515. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 3.18
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 15.59  # as spec
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.444
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.38],
                                                                    [0.11]]

        elif candidate == CAR.INSIGHT:
            stop_and_go = True
            ret.mass = 2987. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.centerToFront = ret.wheelbase * 0.39
            ret.steerRatio = 15.0  # 12.58 is spec end-to-end
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.18]]

        elif candidate == CAR.HONDA_E:
            stop_and_go = True
            ret.mass = 3338.8 * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.5
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 16.71
            ret.lateralParams.torqueBP, ret.lateralParams.torqueV = [
                [0, 4096], [0, 4096]
            ]  # TODO: determine if there is a dead zone at the top end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.6
            ], [0.18]]  # TODO: can probably use some tuning

        else:
            raise ValueError(f"unsupported car {candidate}")

        # These cars use alternate user brake msg (0x1BE)
        if candidate in HONDA_BOSCH_ALT_BRAKE_SIGNAL:
            ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HONDA_ALT_BRAKE

        # These cars use alternate SCM messages (SCM_FEEDBACK AND SCM_BUTTON)
        if candidate in HONDA_NIDEC_ALT_SCM_MESSAGES:
            ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HONDA_NIDEC_ALT

        if ret.openpilotLongitudinalControl and candidate in HONDA_BOSCH:
            ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HONDA_BOSCH_LONG

        # min speed to enable ACC. if car can do stop and go, then set enabling speed
        # to a negative value, so it won't matter. Otherwise, add 0.5 mph margin to not
        # conflict with PCM acc
        ret.minEnableSpeed = -1. if (
            stop_and_go or ret.enableGasInterceptor) else 25.5 * CV.MPH_TO_MS

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        ret.steerActuatorDelay = 0.1
        ret.steerRateCost = 0.5
        ret.steerLimitTimer = 0.8

        return ret
Esempio n. 9
0
  def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]):  # pylint: disable=dangerous-default-value
    ret = CarInterfaceBase.get_std_params(candidate, fingerprint)

    ret.carName = "toyota"
    ret.safetyModel = car.CarParams.SafetyModel.toyota

    ret.steerActuatorDelay = 0.12  # Default delay, Prius has larger delay
    ret.steerLimitTimer = 0.4

    if candidate not in [CAR.PRIUS, CAR.RAV4, CAR.RAV4H]:  # These cars use LQR/INDI
      ret.lateralTuning.init('pid')
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]

    if candidate == CAR.PRIUS:
      stop_and_go = True
      ret.safetyParam = 66  # see conversion factor for STEER_TORQUE_EPS in dbc file
      ret.wheelbase = 2.70
      ret.steerRatio = 15.74   # unknown end-to-end spec
      tire_stiffness_factor = 0.6371   # hand-tune
      ret.mass = 3045. * CV.LB_TO_KG + STD_CARGO_KG

      ret.lateralTuning.init('indi')
      ret.lateralTuning.indi.innerLoopGainBP = [0.]
      ret.lateralTuning.indi.innerLoopGainV = [4.0]
      ret.lateralTuning.indi.outerLoopGainBP = [0.]
      ret.lateralTuning.indi.outerLoopGainV = [3.0]
      ret.lateralTuning.indi.timeConstantBP = [0.]
      ret.lateralTuning.indi.timeConstantV = [1.0]
      ret.lateralTuning.indi.actuatorEffectivenessBP = [0.]
      ret.lateralTuning.indi.actuatorEffectivenessV = [1.0]
      ret.steerActuatorDelay = 0.3

    elif candidate in [CAR.RAV4, CAR.RAV4H]:
      stop_and_go = True if (candidate in CAR.RAV4H) else False
      ret.safetyParam = 73
      ret.wheelbase = 2.65
      ret.steerRatio = 16.88   # 14.5 is spec end-to-end
      tire_stiffness_factor = 0.5533
      ret.mass = 3650. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
      ret.lateralTuning.init('lqr')

      ret.lateralTuning.lqr.scale = 1500.0
      ret.lateralTuning.lqr.ki = 0.05

      ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
      ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
      ret.lateralTuning.lqr.c = [1., 0.]
      ret.lateralTuning.lqr.k = [-110.73572306, 451.22718255]
      ret.lateralTuning.lqr.l = [0.3233671, 0.3185757]
      ret.lateralTuning.lqr.dcGain = 0.002237852961363602

    elif candidate == CAR.COROLLA:
      stop_and_go = False
      ret.safetyParam = 88
      ret.wheelbase = 2.70
      ret.steerRatio = 18.27
      tire_stiffness_factor = 0.444  # not optimized yet
      ret.mass = 2860. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2], [0.05]]
      ret.lateralTuning.pid.kf = 0.00003   # full torque for 20 deg at 80mph means 0.00007818594

    elif candidate == CAR.LEXUS_RX:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.79
      ret.steerRatio = 14.8
      tire_stiffness_factor = 0.5533
      ret.mass = 4387. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.05]]
      ret.lateralTuning.pid.kf = 0.00006

    elif candidate == CAR.LEXUS_RXH:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.79
      ret.steerRatio = 16.  # 14.8 is spec end-to-end
      tire_stiffness_factor = 0.444  # not optimized yet
      ret.mass = 4481. * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00006   # full torque for 10 deg at 80mph means 0.00007818594

    elif candidate == CAR.LEXUS_RX_TSS2:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.79
      ret.steerRatio = 14.8
      tire_stiffness_factor = 0.5533  # not optimized yet
      ret.mass = 4387. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00007818594

    elif candidate == CAR.LEXUS_RXH_TSS2:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.79
      ret.steerRatio = 16.0  # 14.8 is spec end-to-end
      tire_stiffness_factor = 0.444  # not optimized yet
      ret.mass = 4481.0 * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.15]]
      ret.lateralTuning.pid.kf = 0.00007818594

    elif candidate in [CAR.CHR, CAR.CHRH]:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.63906
      ret.steerRatio = 13.6
      tire_stiffness_factor = 0.7933
      ret.mass = 3300. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.723], [0.0428]]
      ret.lateralTuning.pid.kf = 0.00006

    elif candidate in [CAR.CAMRY, CAR.CAMRYH, CAR.CAMRY_TSS2, CAR.CAMRYH_TSS2]:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.82448
      ret.steerRatio = 13.7
      tire_stiffness_factor = 0.7933
      ret.mass = 3400. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00006

    elif candidate in [CAR.HIGHLANDER_TSS2, CAR.HIGHLANDERH_TSS2]:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.84988  # 112.2 in = 2.84988 m
      ret.steerRatio = 16.0
      tire_stiffness_factor = 0.8
      ret.mass = 4700. * CV.LB_TO_KG + STD_CARGO_KG  # 4260 + 4-5 people
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.18], [0.015]]  # community tuning
      ret.lateralTuning.pid.kf = 0.00012  # community tuning

    elif candidate in [CAR.HIGHLANDER, CAR.HIGHLANDERH]:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.78
      ret.steerRatio = 16.0
      tire_stiffness_factor = 0.8
      ret.mass = 4607. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid limited
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.18], [0.015]]  # community tuning
      ret.lateralTuning.pid.kf = 0.00012  # community tuning

    elif candidate in [CAR.AVALON, CAR.AVALON_2019, CAR.AVALONH_2019]:
      stop_and_go = False
      ret.safetyParam = 73
      ret.wheelbase = 2.82
      ret.steerRatio = 14.8  # Found at https://pressroom.toyota.com/releases/2016+avalon+product+specs.download
      tire_stiffness_factor = 0.7983
      ret.mass = 3505. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.17], [0.03]]
      ret.lateralTuning.pid.kf = 0.00006

    elif candidate == CAR.RAV4_TSS2:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.68986
      ret.steerRatio = 14.3
      tire_stiffness_factor = 0.7933
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.15], [0.05]]
      ret.mass = 3370. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kf = 0.00004

      for fw in car_fw:
        if fw.ecu == "eps" and fw.fwVersion == b"8965B42170\x00\x00\x00\x00\x00\x00":
          ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
          ret.lateralTuning.pid.kf = 0.00007818594
          break

    elif candidate == CAR.RAV4H_TSS2:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.68986
      ret.steerRatio = 14.3
      tire_stiffness_factor = 0.7933
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.15], [0.05]]
      ret.mass = 3800. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kf = 0.00004

      for fw in car_fw:
        if fw.ecu == "eps" and fw.fwVersion == b"8965B42170\x00\x00\x00\x00\x00\x00":
          ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
          ret.lateralTuning.pid.kf = 0.00007818594
          break

    elif candidate in [CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2]:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.67  # Average between 2.70 for sedan and 2.64 for hatchback
      ret.steerRatio = 13.9
      tire_stiffness_factor = 0.444  # not optimized yet
      ret.mass = 3060. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00007818594

    elif candidate in [CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2]:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.8702
      ret.steerRatio = 16.0  # not optimized
      tire_stiffness_factor = 0.444  # not optimized yet
      ret.mass = 3704. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00007818594

    elif candidate == CAR.LEXUS_ESH:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.8190
      ret.steerRatio = 16.06
      tire_stiffness_factor = 0.444  # not optimized yet
      ret.mass = 3682. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00007818594

    elif candidate == CAR.SIENNA:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 3.03
      ret.steerRatio = 15.5
      tire_stiffness_factor = 0.444
      ret.mass = 4590. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.19], [0.02]]
      ret.lateralTuning.pid.kf = 0.00007818594

    elif candidate == CAR.LEXUS_IS:
      stop_and_go = False
      ret.safetyParam = 77
      ret.wheelbase = 2.79908
      ret.steerRatio = 13.3
      tire_stiffness_factor = 0.444
      ret.mass = 3736.8 * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3], [0.05]]
      ret.lateralTuning.pid.kf = 0.00006

    elif candidate == CAR.LEXUS_CTH:
      stop_and_go = True
      ret.safetyParam = 100
      ret.wheelbase = 2.60
      ret.steerRatio = 18.6
      tire_stiffness_factor = 0.517
      ret.mass = 3108 * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3], [0.05]]
      ret.lateralTuning.pid.kf = 0.00007

    elif candidate in [CAR.LEXUS_NXH, CAR.LEXUS_NX, CAR.LEXUS_NX_TSS2]:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.66
      ret.steerRatio = 14.7
      tire_stiffness_factor = 0.444  # not optimized yet
      ret.mass = 4070 * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00006

    elif candidate == CAR.PRIUS_TSS2:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.70002  # from toyota online sepc.
      ret.steerRatio = 13.4   # True steerRation from older prius
      tire_stiffness_factor = 0.6371   # hand-tune
      ret.mass = 3115. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.35], [0.15]]
      ret.lateralTuning.pid.kf = 0.00007818594

    elif candidate == CAR.MIRAI:
      stop_and_go = True
      ret.safetyParam = 73
      ret.wheelbase = 2.91
      ret.steerRatio = 14.8
      tire_stiffness_factor = 0.8
      ret.mass = 4300. * CV.LB_TO_KG + STD_CARGO_KG
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]]
      ret.lateralTuning.pid.kf = 0.00006

    ret.steerRateCost = 1.
    ret.centerToFront = ret.wheelbase * 0.44

    # TODO: get actual value, for now starting with reasonable value for
    # civic and scaling by mass and wheelbase
    ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

    # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
    # mass and CG position, so all cars will have approximately similar dyn behaviors
    ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
                                                                         tire_stiffness_factor=tire_stiffness_factor)

    ret.enableCamera = True
    ret.enableBsm = 0x3F6 in fingerprint[0] and candidate in TSS2_CAR
    # Detect smartDSU, which intercepts ACC_CMD from the DSU allowing openpilot to send it
    smartDsu = 0x2FF in fingerprint[0]
    # In TSS2 cars the camera does long control
    found_ecus = [fw.ecu for fw in car_fw]
    ret.enableDsu = (len(found_ecus) > 0) and (Ecu.dsu not in found_ecus) and (candidate not in NO_DSU_CAR)
    ret.enableGasInterceptor = 0x201 in fingerprint[0]
    # if the smartDSU is detected, openpilot can send ACC_CMD (and the smartDSU will block it from the DSU) or not (the DSU is "connected")
    ret.openpilotLongitudinalControl = ret.enableCamera and (smartDsu or ret.enableDsu or candidate in TSS2_CAR)
    cloudlog.warning("ECU DSU Simulated: %r", ret.enableDsu)
    cloudlog.warning("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

    # min speed to enable ACC. if car can do stop and go, then set enabling speed
    # to a negative value, so it won't matter.
    ret.minEnableSpeed = -1. if (stop_and_go or ret.enableGasInterceptor) else MIN_ACC_SPEED

    # removing the DSU disables AEB and it's considered a community maintained feature
    # intercepting the DSU is a community feature since it requires unofficial hardware
    ret.communityFeature = ret.enableGasInterceptor or ret.enableDsu or smartDsu

    if ret.enableGasInterceptor:
      # Transitions from original pedal tuning at MIN_ACC_SPEED to default tuning at MIN_ACC_SPEED + hysteresis gap
      ret.gasMaxBP = [0., MIN_ACC_SPEED]
      ret.gasMaxV = [0.2, 0.5]
      ret.longitudinalTuning.kpBP = [0., 5., MIN_ACC_SPEED, MIN_ACC_SPEED + PEDAL_HYST_GAP, 35.]
      ret.longitudinalTuning.kpV = [1.2, 0.8, 0.765, 2.255, 1.5]
      ret.longitudinalTuning.kiBP = [0., MIN_ACC_SPEED, MIN_ACC_SPEED + PEDAL_HYST_GAP, 35.]
      ret.longitudinalTuning.kiV = [0.18, 0.165, 0.489, 0.36]
    elif candidate in [CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2, CAR.RAV4_TSS2, CAR.RAV4H_TSS2, CAR.LEXUS_NX_TSS2]:
      # Improved longitudinal tune
      ret.longitudinalTuning.deadzoneBP = [0., 8.05]
      ret.longitudinalTuning.deadzoneV = [.0, .14]
      ret.longitudinalTuning.kpBP = [0., 5., 20.]
      ret.longitudinalTuning.kpV = [1.3, 1.0, 0.7]
      ret.longitudinalTuning.kiBP = [0., 5., 12., 20., 27.]
      ret.longitudinalTuning.kiV = [.35, .23, .20, .17, .1]
      ret.stoppingBrakeRate = 0.1  # reach stopping target smoothly
      ret.startingBrakeRate = 2.0  # release brakes fast
      ret.startAccel = 1.2  # Accelerate from 0 faster
    else:
      # Default longitudinal tune
      ret.longitudinalTuning.deadzoneBP = [0., 9.]
      ret.longitudinalTuning.deadzoneV = [0., .15]
      ret.longitudinalTuning.kpBP = [0., 5., 35.]
      ret.longitudinalTuning.kiBP = [0., 35.]
      ret.longitudinalTuning.kpV = [3.6, 2.4, 1.5]
      ret.longitudinalTuning.kiV = [0.54, 0.36]

    return ret
Esempio n. 10
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   vin="",
                   has_relay=False):

        ret = car.CarParams.new_message()
        ret.carName = "honda"
        ret.carFingerprint = candidate
        ret.carVin = vin
        ret.isPandaBlack = has_relay

        if candidate in HONDA_BOSCH:
            ret.safetyModel = car.CarParams.SafetyModel.hondaBosch
            rdr_bus = 0 if has_relay else 2
            ret.enableCamera = is_ecu_disconnected(
                fingerprint[rdr_bus], FINGERPRINTS, ECU_FINGERPRINT, candidate,
                ECU.CAM) or has_relay
            ret.radarOffCan = True
            ret.openpilotLongitudinalControl = False
        else:
            ret.safetyModel = car.CarParams.SafetyModel.honda
            ret.enableCamera = is_ecu_disconnected(
                fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate,
                ECU.CAM) or has_relay
            ret.enableGasInterceptor = 0x201 in fingerprint[0]
            ret.openpilotLongitudinalControl = ret.enableCamera

        cloudlog.warning("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warning("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

        ret.enableCruise = not ret.enableGasInterceptor

        # Optimized car params: tire_stiffness_factor and steerRatio are a result of a vehicle
        # model optimization process. Certain Hondas have an extra steering sensor at the bottom
        # of the steering rack, which improves controls quality as it removes the steering column
        # torsion from feedback.
        # Tire stiffness factor fictitiously lower if it includes the steering column torsion effect.
        # For modeling details, see p.198-200 in "The Science of Vehicle Dynamics (2014), M. Guiggiani"

        ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
        ret.lateralTuning.pid.kf = 0.00006  # conservative feed-forward

        if candidate in [CAR.CIVIC, CAR.CIVIC_BOSCH]:
            stop_and_go = True
            ret.mass = CivicParams.MASS
            ret.wheelbase = CivicParams.WHEELBASE
            ret.centerToFront = CivicParams.CENTER_TO_FRONT
            ret.steerRatio = 15.38  # 10.93 is end-to-end spec
            tire_stiffness_factor = 1.

            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [3.6, 2.4, 1.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.54, 0.36]

        elif candidate in (CAR.ACCORD, CAR.ACCORD_15, CAR.ACCORDH):
            stop_and_go = True
            if not candidate == CAR.ACCORDH:  # Hybrid uses same brake msg as hatch
                ret.safetyParam = 1  # Accord and CRV 5G use an alternate user brake msg
            ret.mass = 3279. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.83
            ret.centerToFront = ret.wheelbase * 0.39
            ret.steerRatio = 16.33  # 11.82 is spec end-to-end
            tire_stiffness_factor = 0.8467
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.18]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.ACURA_ILX:
            stop_and_go = False
            ret.mass = 3095. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.37
            ret.steerRatio = 18.61  # 15.3 is spec end-to-end
            tire_stiffness_factor = 0.72
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.CRV:
            stop_and_go = False
            ret.mass = 3572. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.62
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 16.89  # as spec
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.CRV_5G:
            stop_and_go = True
            ret.safetyParam = 1  # Accord and CRV 5G use an alternate user brake msg
            ret.mass = 3410. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.66
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 16.0  # 12.3 is spec end-to-end
            tire_stiffness_factor = 0.677
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.18]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.CRV_HYBRID:
            stop_and_go = True
            ret.safetyParam = 1  # Accord and CRV 5G use an alternate user brake msg
            ret.mass = 1667. + STD_CARGO_KG  # mean of 4 models in kg
            ret.wheelbase = 2.66
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 16.0  # 12.3 is spec end-to-end
            tire_stiffness_factor = 0.677
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.18]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.FIT:
            stop_and_go = False
            ret.mass = 2644. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.53
            ret.centerToFront = ret.wheelbase * 0.39
            ret.steerRatio = 13.06
            tire_stiffness_factor = 0.75  # not optimized yet
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.06]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.ACURA_RDX:
            stop_and_go = False
            ret.mass = 3935. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.68
            ret.centerToFront = ret.wheelbase * 0.38
            ret.steerRatio = 15.0  # as spec
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.8],
                                                                    [0.24]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.ODYSSEY:
            stop_and_go = False
            ret.mass = 4471. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 3.00
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 14.35  # as spec
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.45],
                                                                    [0.135]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.ODYSSEY_CHN:
            stop_and_go = False
            ret.mass = 1849.2 + STD_CARGO_KG  # mean of 4 models in kg
            ret.wheelbase = 2.90  # spec
            ret.centerToFront = ret.wheelbase * 0.41  # from CAR.ODYSSEY
            ret.steerRatio = 14.35  # from CAR.ODYSSEY
            tire_stiffness_factor = 0.82  # from CAR.ODYSSEY
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.45],
                                                                    [0.135]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate in (CAR.PILOT, CAR.PILOT_2019):
            stop_and_go = False
            ret.mass = 4204. * CV.LB_TO_KG + STD_CARGO_KG  # average weight
            ret.wheelbase = 2.82
            ret.centerToFront = ret.wheelbase * 0.428  # average weight distribution
            ret.steerRatio = 17.25  # as spec
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.38],
                                                                    [0.11]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        elif candidate == CAR.RIDGELINE:
            stop_and_go = False
            ret.mass = 4515. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 3.18
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 15.59  # as spec
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.38],
                                                                    [0.11]]
            ret.longitudinalTuning.kpBP = [0., 5., 35.]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiBP = [0., 35.]
            ret.longitudinalTuning.kiV = [0.18, 0.12]

        else:
            raise ValueError("unsupported car %s" % candidate)

        ret.steerControlType = car.CarParams.SteerControlType.torque

        # min speed to enable ACC. if car can do stop and go, then set enabling speed
        # to a negative value, so it won't matter. Otherwise, add 0.5 mph margin to not
        # conflict with PCM acc
        ret.minEnableSpeed = -1. if (
            stop_and_go or ret.enableGasInterceptor) else 25.5 * CV.MPH_TO_MS

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        # no rear steering, at least on the listed cars above
        ret.steerRatioRear = 0.

        # no max steer limit VS speed
        ret.steerMaxBP = [0.]  # m/s
        ret.steerMaxV = [1.]  # max steer allowed

        ret.gasMaxBP = [0.]  # m/s
        ret.gasMaxV = [0.6] if ret.enableGasInterceptor else [
            0.
        ]  # max gas allowed
        ret.brakeMaxBP = [5., 20.]  # m/s
        ret.brakeMaxV = [1., 0.8]  # max brake allowed

        ret.longitudinalTuning.deadzoneBP = [0.]
        ret.longitudinalTuning.deadzoneV = [0.]

        ret.stoppingControl = True
        ret.steerLimitAlert = True
        ret.startAccel = 0.5

        ret.steerActuatorDelay = 0.1
        ret.steerRateCost = 0.5

        return ret
Esempio n. 11
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   has_relay=False,
                   car_fw=[]):

        ret = car.CarParams.new_message()

        ret.carName = "chrysler"
        ret.carFingerprint = candidate
        ret.isPandaBlack = has_relay

        ret.safetyModel = car.CarParams.SafetyModel.chrysler

        # pedal
        ret.enableCruise = True

        # Speed conversion:              20, 45 mph
        ret.wheelbase = 3.089  # in meters for Pacifica Hybrid 2017
        ret.steerRatio = 16.2  # Pacifica Hybrid 2017
        ret.mass = 2858. + STD_CARGO_KG  # kg curb weight Pacifica Hybrid 2017
        ret.lateralTuning.pid.kpBP, ret.lateralTuning.pid.kiBP = [[9., 20.],
                                                                  [9., 20.]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.15, 0.30],
                                                                [0.03, 0.05]]
        ret.lateralTuning.pid.kf = 0.00006  # full torque for 10 deg at 80mph means 0.00007818594
        ret.steerActuatorDelay = 0.1
        ret.steerRateCost = 0.7
        ret.steerLimitTimer = 0.4

        if candidate in (CAR.JEEP_CHEROKEE, CAR.JEEP_CHEROKEE_2019):
            ret.wheelbase = 2.91  # in meters
            ret.steerRatio = 12.7
            ret.steerActuatorDelay = 0.2  # in seconds

        ret.centerToFront = ret.wheelbase * 0.44

        ret.minSteerSpeed = 3.8  # m/s
        ret.minEnableSpeed = -1.  # enable is done by stock ACC, so ignore this
        if candidate in (CAR.PACIFICA_2019_HYBRID, CAR.JEEP_CHEROKEE_2019):
            ret.minSteerSpeed = 17.5  # m/s 17 on the way up, 13 on the way down once engaged.
            # TODO allow 2019 cars to steer down to 13 m/s if already engaged.

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass, ret.wheelbase, ret.centerToFront)

        # no rear steering, at least on the listed cars above
        ret.steerRatioRear = 0.

        # steer, gas, brake limitations VS speed
        ret.steerMaxBP = [16. * CV.KPH_TO_MS,
                          45. * CV.KPH_TO_MS]  # breakpoints at 1 and 40 kph
        ret.steerMaxV = [1., 1.]  # 2/3rd torque allowed above 45 kph
        ret.gasMaxBP = [0.]
        ret.gasMaxV = [0.5]
        ret.brakeMaxBP = [5., 20.]
        ret.brakeMaxV = [1., 0.8]

        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS,
                                               ECU_FINGERPRINT, candidate,
                                               ECU.CAM) or has_relay
        print("ECU Camera Simulated: {0}".format(ret.enableCamera))
        ret.openpilotLongitudinalControl = False

        ret.stoppingControl = False
        ret.startAccel = 0.0

        ret.longitudinalTuning.deadzoneBP = [0., 9.]
        ret.longitudinalTuning.deadzoneV = [0., .15]
        ret.longitudinalTuning.kpBP = [0., 5., 35.]
        ret.longitudinalTuning.kpV = [3.6, 2.4, 1.5]
        ret.longitudinalTuning.kiBP = [0., 35.]
        ret.longitudinalTuning.kiV = [0.54, 0.36]

        return ret
Esempio n. 12
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   vin="",
                   has_relay=False):

        ret = car.CarParams.new_message()

        ret.carName = "toyota"
        ret.carFingerprint = candidate
        ret.carVin = vin
        ret.isPandaBlack = has_relay

        ret.safetyModel = car.CarParams.SafetyModel.toyota

        ret.enableCruise = True

        ret.steerActuatorDelay = 0.12  # Default delay, Prius has larger delay
        ret.steerLimitTimer = 0.4

        if candidate not in [CAR.PRIUS, CAR.RAV4,
                             CAR.RAV4H]:  # These cars use LQR/INDI
            ret.lateralTuning.init('pid')
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]

        if candidate == CAR.PRIUS:
            stop_and_go = True
            ret.safetyParam = 66  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.70
            ret.steerRatio = 15.74  # unknown end-to-end spec
            tire_stiffness_factor = 0.6371  # hand-tune
            ret.mass = 3045. * CV.LB_TO_KG + STD_CARGO_KG

            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGain = 4.0
            ret.lateralTuning.indi.outerLoopGain = 3.0
            ret.lateralTuning.indi.timeConstant = 1.0
            ret.lateralTuning.indi.actuatorEffectiveness = 1.0

            # TODO: Determine if this is better than INDI
            # ret.lateralTuning.init('lqr')
            # ret.lateralTuning.lqr.scale = 1500.0
            # ret.lateralTuning.lqr.ki = 0.01

            # ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
            # ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
            # ret.lateralTuning.lqr.c = [1., 0.]
            # ret.lateralTuning.lqr.k = [-110.73572306, 451.22718255]
            # ret.lateralTuning.lqr.l = [0.03233671, 0.03185757]
            # ret.lateralTuning.lqr.dcGain = 0.002237852961363602

            ret.steerActuatorDelay = 0.5

        elif candidate in [CAR.RAV4, CAR.RAV4H]:
            stop_and_go = True if (candidate in CAR.RAV4H) else False
            ret.safetyParam = 73
            ret.wheelbase = 2.65
            ret.steerRatio = 16.88  # 14.5 is spec end-to-end
            tire_stiffness_factor = 0.5533
            ret.mass = 3650. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
            ret.lateralTuning.init('lqr')

            ret.lateralTuning.lqr.scale = 1500.0
            ret.lateralTuning.lqr.ki = 0.05

            ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
            ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
            ret.lateralTuning.lqr.c = [1., 0.]
            ret.lateralTuning.lqr.k = [-110.73572306, 451.22718255]
            ret.lateralTuning.lqr.l = [0.3233671, 0.3185757]
            ret.lateralTuning.lqr.dcGain = 0.002237852961363602

        elif candidate == CAR.COROLLA:
            stop_and_go = False
            ret.safetyParam = 100
            ret.wheelbase = 2.70
            ret.steerRatio = 18.27
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 2860. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2],
                                                                    [0.05]]
            ret.lateralTuning.pid.kf = 0.00003  # full torque for 20 deg at 80mph means 0.00007818594

        elif candidate == CAR.LEXUS_RXH:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 2.79
            ret.steerRatio = 16.  # 14.8 is spec end-to-end
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 4481. * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.1]]
            ret.lateralTuning.pid.kf = 0.00006  # full torque for 10 deg at 80mph means 0.00007818594

        elif candidate in [CAR.CHR, CAR.CHRH]:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 2.63906
            ret.steerRatio = 13.6
            tire_stiffness_factor = 0.7933
            ret.mass = 3300. * CV.LB_TO_KG + STD_CARGO_KG
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.723],
                                                                    [0.0428]]
            ret.lateralTuning.pid.kf = 0.00006

        elif candidate in [CAR.CAMRY, CAR.CAMRYH]:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 2.82448
            ret.steerRatio = 13.7
            tire_stiffness_factor = 0.7933
            ret.mass = 3400. * CV.LB_TO_KG + STD_CARGO_KG  #mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.1]]
            ret.lateralTuning.pid.kf = 0.00006

        elif candidate in [CAR.HIGHLANDER, CAR.HIGHLANDERH]:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 2.78
            ret.steerRatio = 16.0
            tire_stiffness_factor = 0.8
            ret.mass = 4607. * CV.LB_TO_KG + STD_CARGO_KG  #mean between normal and hybrid limited
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.18
            ], [0.015]]  # community tuning
            ret.lateralTuning.pid.kf = 0.00012  # community tuning

        elif candidate == CAR.AVALON:
            stop_and_go = False
            ret.safetyParam = 73
            ret.wheelbase = 2.82
            ret.steerRatio = 14.8  #Found at https://pressroom.toyota.com/releases/2016+avalon+product+specs.download
            tire_stiffness_factor = 0.7983
            ret.mass = 3505. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.17],
                                                                    [0.03]]
            ret.lateralTuning.pid.kf = 0.00006

        elif candidate == CAR.RAV4_TSS2:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 2.68986
            ret.steerRatio = 14.3
            tire_stiffness_factor = 0.7933
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.1]]
            ret.mass = 3370. * CV.LB_TO_KG + STD_CARGO_KG
            ret.lateralTuning.pid.kf = 0.00007818594

        elif candidate in [CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2]:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 2.63906
            ret.steerRatio = 13.9
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 3060. * CV.LB_TO_KG + STD_CARGO_KG
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.1]]
            ret.lateralTuning.pid.kf = 0.00007818594

        elif candidate in [CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2]:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 2.8702
            ret.steerRatio = 16.0  # not optimized
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 3704. * CV.LB_TO_KG + STD_CARGO_KG
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.1]]
            ret.lateralTuning.pid.kf = 0.00007818594

        elif candidate == CAR.SIENNA:
            stop_and_go = True
            ret.safetyParam = 73
            ret.wheelbase = 3.03
            ret.steerRatio = 16.0
            tire_stiffness_factor = 0.444
            ret.mass = 4590. * CV.LB_TO_KG + STD_CARGO_KG
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                    [0.05]]
            ret.lateralTuning.pid.kf = 0.00007818594

        elif candidate == CAR.LEXUS_IS:
            stop_and_go = False
            ret.safetyParam = 77
            ret.wheelbase = 2.79908
            ret.steerRatio = 13.3
            tire_stiffness_factor = 0.444
            ret.mass = 3736.8 * CV.LB_TO_KG + STD_CARGO_KG
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                    [0.05]]
            ret.lateralTuning.pid.kf = 0.00006

        elif candidate == CAR.LEXUS_CTH:
            stop_and_go = True
            ret.safetyParam = 100
            ret.wheelbase = 2.60
            ret.steerRatio = 18.6
            tire_stiffness_factor = 0.517
            ret.mass = 3108 * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                    [0.05]]
            ret.lateralTuning.pid.kf = 0.00007

        ret.steerRateCost = 1.
        ret.centerToFront = ret.wheelbase * 0.44

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        # no rear steering, at least on the listed cars above
        ret.steerRatioRear = 0.
        ret.steerControlType = car.CarParams.SteerControlType.torque

        # steer, gas, brake limitations VS speed
        ret.steerMaxBP = [16. * CV.KPH_TO_MS,
                          45. * CV.KPH_TO_MS]  # breakpoints at 1 and 40 kph
        ret.steerMaxV = [1., 1.]  # 2/3rd torque allowed above 45 kph
        ret.brakeMaxBP = [0.]
        ret.brakeMaxV = [1.]

        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS,
                                               ECU_FINGERPRINT, candidate,
                                               ECU.CAM) or has_relay
        # In TSS2 cars the camera does long control
        ret.enableDsu = is_ecu_disconnected(
            fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate,
            ECU.DSU) and candidate not in TSS2_CAR
        ret.enableApgs = False  # is_ecu_disconnected(fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate, ECU.APGS)
        ret.enableGasInterceptor = 0x201 in fingerprint[0]
        ret.openpilotLongitudinalControl = ret.enableCamera and (
            ret.enableDsu or candidate in TSS2_CAR)
        cloudlog.warning("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warning("ECU DSU Simulated: %r", ret.enableDsu)
        cloudlog.warning("ECU APGS Simulated: %r", ret.enableApgs)
        cloudlog.warning("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

        # min speed to enable ACC. if car can do stop and go, then set enabling speed
        # to a negative value, so it won't matter.
        ret.minEnableSpeed = -1. if (
            stop_and_go or ret.enableGasInterceptor) else 19. * CV.MPH_TO_MS

        # removing the DSU disables AEB and it's considered a community maintained feature
        ret.communityFeature = ret.enableGasInterceptor or ret.enableDsu

        ret.longitudinalTuning.deadzoneBP = [0., 9.]
        ret.longitudinalTuning.deadzoneV = [0., .15]
        ret.longitudinalTuning.kpBP = [0., 5., 35.]
        ret.longitudinalTuning.kiBP = [0., 35.]
        ret.stoppingControl = False
        ret.startAccel = 0.0

        if ret.enableGasInterceptor:
            ret.gasMaxBP = [0., 9., 35]
            ret.gasMaxV = [0.2, 0.5, 0.7]
            ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
            ret.longitudinalTuning.kiV = [0.18, 0.12]
        else:
            ret.gasMaxBP = [0.]
            ret.gasMaxV = [0.5]
            ret.longitudinalTuning.kpV = [3.6, 2.4, 1.5]
            ret.longitudinalTuning.kiV = [0.54, 0.36]

        return ret
Esempio n. 13
0
 def get_params(candidate,
                fingerprint=gen_empty_fingerprint(),
                car_fw=None):
     pass
Esempio n. 14
0
def fingerprint(logcan, sendcan):
  fixed_fingerprint = os.environ.get('FINGERPRINT', "")
  skip_fw_query = os.environ.get('SKIP_FW_QUERY', False)

  if not fixed_fingerprint and not skip_fw_query:
    # Vin query only reliably works thorugh OBDII
    bus = 1

    cached_params = Params().get("CarParamsCache")
    if cached_params is not None:
      cached_params = car.CarParams.from_bytes(cached_params)
      if cached_params.carName == "mock":
        cached_params = None

    if cached_params is not None and len(cached_params.carFw) > 0 and cached_params.carVin is not VIN_UNKNOWN:
      cloudlog.warning("Using cached CarParams")
      vin = cached_params.carVin
      car_fw = list(cached_params.carFw)
    else:
      cloudlog.warning("Getting VIN & FW versions")
      _, vin = get_vin(logcan, sendcan, bus)
      car_fw = get_fw_versions(logcan, sendcan, bus)

    exact_fw_match, fw_candidates = match_fw_to_car(car_fw)
  else:
    vin = VIN_UNKNOWN
    exact_fw_match, fw_candidates, car_fw = True, set(), []

  cloudlog.warning("VIN %s", vin)
  Params().put("CarVin", vin)

  finger = gen_empty_fingerprint()
  candidate_cars = {i: all_legacy_fingerprint_cars() for i in [0, 1]}  # attempt fingerprint on both bus 0 and 1
  frame = 0
  frame_fingerprint = 10  # 0.1s
  car_fingerprint = None
  done = False

  while not done:
    a = get_one_can(logcan)

    for can in a.can:
      # The fingerprint dict is generated for all buses, this way the car interface
      # can use it to detect a (valid) multipanda setup and initialize accordingly
      if can.src < 128:
        if can.src not in finger.keys():
          finger[can.src] = {}
        finger[can.src][can.address] = len(can.dat)

      for b in candidate_cars:
        # Ignore extended messages and VIN query response.
        if can.src == b and can.address < 0x800 and can.address not in [0x7df, 0x7e0, 0x7e8]:
          candidate_cars[b] = eliminate_incompatible_cars(can, candidate_cars[b])

    # if we only have one car choice and the time since we got our first
    # message has elapsed, exit
    for b in candidate_cars:
      if len(candidate_cars[b]) == 1 and frame > frame_fingerprint:
        # fingerprint done
        car_fingerprint = candidate_cars[b][0]

    # bail if no cars left or we've been waiting for more than 2s
    failed = (all(len(cc) == 0 for cc in candidate_cars.values()) and frame > frame_fingerprint) or frame > 200
    succeeded = car_fingerprint is not None
    done = failed or succeeded

    frame += 1

  exact_match = True
  source = car.CarParams.FingerprintSource.can

  # If FW query returns exactly 1 candidate, use it
  if len(fw_candidates) == 1:
    car_fingerprint = list(fw_candidates)[0]
    source = car.CarParams.FingerprintSource.fw
    exact_match = exact_fw_match

  if fixed_fingerprint:
    car_fingerprint = fixed_fingerprint
    source = car.CarParams.FingerprintSource.fixed

  cloudlog.event("fingerprinted", car_fingerprint=car_fingerprint,
                 source=source, fuzzy=not exact_match, fw_count=len(car_fw))
  return car_fingerprint, finger, vin, car_fw, source, exact_match
Esempio n. 15
0
    def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]):  # pylint: disable=dangerous-default-value
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint)

        ret.carName = "toyota"
        ret.safetyConfigs = [
            get_safety_config(car.CarParams.SafetyModel.toyota)
        ]
        ret.safetyConfigs[0].safetyParam = EPS_SCALE[candidate]

        ret.steerActuatorDelay = 0.12  # Default delay, Prius has larger delay
        ret.steerLimitTimer = 0.4
        ret.stoppingControl = False  # Toyota starts braking more when it thinks you want to stop

        stop_and_go = False

        if candidate == CAR.PRIUS:
            stop_and_go = True
            ret.wheelbase = 2.70
            ret.steerRatio = 15.74  # unknown end-to-end spec
            tire_stiffness_factor = 0.6371  # hand-tune
            ret.mass = 3045. * CV.LB_TO_KG + STD_CARGO_KG

            set_lat_tune(ret.lateralTuning, LatTunes.INDI_PRIUS)
            ret.steerActuatorDelay = 0.3

        elif candidate == CAR.PRIUS_V:
            stop_and_go = True
            ret.wheelbase = 2.78
            ret.steerRatio = 17.4
            tire_stiffness_factor = 0.5533
            ret.mass = 4387. * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4)

        elif candidate in (CAR.RAV4, CAR.RAV4H):
            stop_and_go = True if (candidate in CAR.RAV4H) else False
            ret.wheelbase = 2.65
            ret.steerRatio = 16.88  # 14.5 is spec end-to-end
            tire_stiffness_factor = 0.5533
            ret.mass = 3650. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
            set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4)

        elif candidate == CAR.COROLLA:
            ret.wheelbase = 2.70
            ret.steerRatio = 18.27
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 2860. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
            set_lat_tune(ret.lateralTuning, LatTunes.PID_A)

        elif candidate in (CAR.LEXUS_RX, CAR.LEXUS_RXH, CAR.LEXUS_RX_TSS2,
                           CAR.LEXUS_RXH_TSS2):
            stop_and_go = True
            ret.wheelbase = 2.79
            ret.steerRatio = 16.  # 14.8 is spec end-to-end
            ret.wheelSpeedFactor = 1.035
            tire_stiffness_factor = 0.5533
            ret.mass = 4481. * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
            set_lat_tune(ret.lateralTuning, LatTunes.PID_C)

        elif candidate in (CAR.CHR, CAR.CHRH):
            stop_and_go = True
            ret.wheelbase = 2.63906
            ret.steerRatio = 13.6
            tire_stiffness_factor = 0.7933
            ret.mass = 3300. * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_F)

        elif candidate in (CAR.CAMRY, CAR.CAMRYH, CAR.CAMRY_TSS2,
                           CAR.CAMRYH_TSS2):
            stop_and_go = True
            ret.wheelbase = 2.82448
            ret.steerRatio = 13.7
            tire_stiffness_factor = 0.7933
            ret.mass = 3400. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
            set_lat_tune(ret.lateralTuning, LatTunes.PID_C)

        elif candidate in (CAR.HIGHLANDER_TSS2, CAR.HIGHLANDERH_TSS2):
            stop_and_go = True
            ret.wheelbase = 2.84988  # 112.2 in = 2.84988 m
            ret.steerRatio = 16.0
            tire_stiffness_factor = 0.8
            ret.mass = 4700. * CV.LB_TO_KG + STD_CARGO_KG  # 4260 + 4-5 people
            set_lat_tune(ret.lateralTuning, LatTunes.PID_G)

        elif candidate in (CAR.HIGHLANDER, CAR.HIGHLANDERH):
            stop_and_go = True
            ret.wheelbase = 2.78
            ret.steerRatio = 16.0
            tire_stiffness_factor = 0.8
            ret.mass = 4607. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid limited
            set_lat_tune(ret.lateralTuning, LatTunes.PID_G)

        elif candidate in (CAR.AVALON, CAR.AVALON_2019, CAR.AVALONH_2019,
                           CAR.AVALON_TSS2):
            ret.wheelbase = 2.82
            ret.steerRatio = 14.8  # Found at https://pressroom.toyota.com/releases/2016+avalon+product+specs.download
            tire_stiffness_factor = 0.7983
            ret.mass = 3505. * CV.LB_TO_KG + STD_CARGO_KG  # mean between normal and hybrid
            set_lat_tune(ret.lateralTuning, LatTunes.PID_H)

        elif candidate in (CAR.RAV4_TSS2, CAR.RAV4H_TSS2):
            stop_and_go = True
            ret.wheelbase = 2.68986
            ret.steerRatio = 14.3
            tire_stiffness_factor = 0.7933
            ret.mass = 3585. * CV.LB_TO_KG + STD_CARGO_KG  # Average between ICE and Hybrid
            set_lat_tune(ret.lateralTuning, LatTunes.PID_D)

            # 2019+ Rav4 TSS2 uses two different steering racks and specific tuning seems to be necessary.
            # See https://github.com/commaai/openpilot/pull/21429#issuecomment-873652891
            for fw in car_fw:
                if fw.ecu == "eps" and (
                        fw.fwVersion.startswith(b'\x02') or fw.fwVersion
                        in [b'8965B42181\x00\x00\x00\x00\x00\x00']):
                    set_lat_tune(ret.lateralTuning, LatTunes.PID_I)
                    break

        elif candidate in (CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2):
            stop_and_go = True
            ret.wheelbase = 2.67  # Average between 2.70 for sedan and 2.64 for hatchback
            ret.steerRatio = 13.9
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 3060. * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_D)

        elif candidate in (CAR.LEXUS_ES_TSS2, CAR.LEXUS_ESH_TSS2,
                           CAR.LEXUS_ESH):
            stop_and_go = True
            ret.wheelbase = 2.8702
            ret.steerRatio = 16.0  # not optimized
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 3677. * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
            set_lat_tune(ret.lateralTuning, LatTunes.PID_D)

        elif candidate == CAR.SIENNA:
            stop_and_go = True
            ret.wheelbase = 3.03
            ret.steerRatio = 15.5
            tire_stiffness_factor = 0.444
            ret.mass = 4590. * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_J)

        elif candidate in (CAR.LEXUS_IS, CAR.LEXUS_RC):
            ret.wheelbase = 2.79908
            ret.steerRatio = 13.3
            tire_stiffness_factor = 0.444
            ret.mass = 3736.8 * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_L)

        elif candidate == CAR.LEXUS_CTH:
            stop_and_go = True
            ret.wheelbase = 2.60
            ret.steerRatio = 18.6
            tire_stiffness_factor = 0.517
            ret.mass = 3108 * CV.LB_TO_KG + STD_CARGO_KG  # mean between min and max
            set_lat_tune(ret.lateralTuning, LatTunes.PID_M)

        elif candidate in (CAR.LEXUS_NXH, CAR.LEXUS_NX, CAR.LEXUS_NX_TSS2):
            stop_and_go = True
            ret.wheelbase = 2.66
            ret.steerRatio = 14.7
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 4070 * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_C)

        elif candidate == CAR.PRIUS_TSS2:
            stop_and_go = True
            ret.wheelbase = 2.70002  # from toyota online sepc.
            ret.steerRatio = 13.4  # True steerRatio from older prius
            tire_stiffness_factor = 0.6371  # hand-tune
            ret.mass = 3115. * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_N)

        elif candidate == CAR.MIRAI:
            stop_and_go = True
            ret.wheelbase = 2.91
            ret.steerRatio = 14.8
            tire_stiffness_factor = 0.8
            ret.mass = 4300. * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_C)

        elif candidate == CAR.ALPHARD_TSS2:
            stop_and_go = True
            ret.wheelbase = 3.00
            ret.steerRatio = 14.2
            tire_stiffness_factor = 0.444
            ret.mass = 4305. * CV.LB_TO_KG + STD_CARGO_KG
            set_lat_tune(ret.lateralTuning, LatTunes.PID_J)

        ret.steerRateCost = 1.
        ret.centerToFront = ret.wheelbase * 0.44

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        ret.enableBsm = 0x3F6 in fingerprint[0] and candidate in TSS2_CAR
        # Detect smartDSU, which intercepts ACC_CMD from the DSU allowing openpilot to send it
        smartDsu = 0x2FF in fingerprint[0]
        # In TSS2 cars the camera does long control
        found_ecus = [fw.ecu for fw in car_fw]
        ret.enableDsu = (len(found_ecus) > 0) and (
            Ecu.dsu
            not in found_ecus) and (candidate
                                    not in NO_DSU_CAR) and (not smartDsu)
        ret.enableGasInterceptor = 0x201 in fingerprint[0]
        # if the smartDSU is detected, openpilot can send ACC_CMD (and the smartDSU will block it from the DSU) or not (the DSU is "connected")
        ret.openpilotLongitudinalControl = smartDsu or ret.enableDsu or candidate in TSS2_CAR

        # we can't use the fingerprint to detect this reliably, since
        # the EV gas pedal signal can take a couple seconds to appear
        if candidate in EV_HYBRID_CAR:
            ret.flags |= ToyotaFlags.HYBRID.value

        # min speed to enable ACC. if car can do stop and go, then set enabling speed
        # to a negative value, so it won't matter.
        ret.minEnableSpeed = -1. if (
            stop_and_go or ret.enableGasInterceptor) else MIN_ACC_SPEED

        if ret.enableGasInterceptor:
            set_long_tune(ret.longitudinalTuning, LongTunes.PEDAL)
        elif candidate in TSS2_CAR:
            set_long_tune(ret.longitudinalTuning, LongTunes.TSS2)
            ret.stoppingDecelRate = 0.3  # reach stopping target smoothly
        else:
            set_long_tune(ret.longitudinalTuning, LongTunes.TSS)

        return ret
Esempio n. 16
0
    def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]):  # pylint: disable=dangerous-default-value
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint)

        ret.carName = "hyundai"
        ret.safetyModel = car.CarParams.SafetyModel.hyundai
        ret.radarOffCan = True

        # Most Hyundai car ports are community features for now
        ret.communityFeature = candidate not in [CAR.SONATA, CAR.PALISADE]

        ret.steerActuatorDelay = 0.1  # Default delay
        ret.steerRateCost = 0.5
        ret.steerLimitTimer = 0.4
        tire_stiffness_factor = 1.

        ret.startAccel = 1.0

        if candidate == CAR.SANTA_FE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3982. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.766
            # Values from optimizer
            ret.steerRatio = 16.55  # 13.8 is spec end-to-end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                9., 22.
            ], [9., 22.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.2, 0.35
            ], [0.05, 0.09]]
        elif candidate == CAR.SONATA:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1513. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            tire_stiffness_factor = 0.65
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.SONATA_LF:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 4497. * CV.LB_TO_KG
            ret.wheelbase = 2.804
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.PALISADE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1999. + STD_CARGO_KG
            ret.wheelbase = 2.90
            ret.steerRatio = 13.75 * 1.15
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                    [0.05]]
        elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 15.4  # 14 is Stock | Settled Params Learner values are steerRatio: 15.401566348670535
            tire_stiffness_factor = 0.385  # stiffnessFactor settled on 1.0081302973865127
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.ELANTRA_2021:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = (2800. * CV.LB_TO_KG) + STD_CARGO_KG
            ret.wheelbase = 2.72
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            tire_stiffness_factor = 0.65
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.ELANTRA_HEV_2021:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = (3017. * CV.LB_TO_KG) + STD_CARGO_KG
            ret.wheelbase = 2.72
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            tire_stiffness_factor = 0.65
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.HYUNDAI_GENESIS:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGainBP = [0.]
            ret.lateralTuning.indi.innerLoopGainV = [3.5]
            ret.lateralTuning.indi.outerLoopGainBP = [0.]
            ret.lateralTuning.indi.outerLoopGainV = [2.0]
            ret.lateralTuning.indi.timeConstantBP = [0.]
            ret.lateralTuning.indi.timeConstantV = [1.4]
            ret.lateralTuning.indi.actuatorEffectivenessBP = [0.]
            ret.lateralTuning.indi.actuatorEffectivenessV = [2.3]
            ret.minSteerSpeed = 60 * CV.KPH_TO_MS
        elif candidate == CAR.KONA:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73 * 1.15  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KONA_EV:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1685. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [
                CAR.IONIQ, CAR.IONIQ_EV_LTD, CAR.IONIQ_EV_2020, CAR.IONIQ_PHEV
        ]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1490. + STD_CARGO_KG  # weight per hyundai site https://www.hyundaiusa.com/ioniq-electric/specifications.aspx
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            if candidate not in [CAR.IONIQ_EV_2020, CAR.IONIQ_PHEV]:
                ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.VELOSTER:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75 * 1.15
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]

        # Kia
        elif candidate == CAR.KIA_SORENTO:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.1  # 10% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_NIRO_EV:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1737. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_SELTOS:
            ret.mass = 1337. + STD_CARGO_KG
            ret.wheelbase = 2.63
            ret.steerRatio = 14.56
            tire_stiffness_factor = 1
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGainBP = [0.]
            ret.lateralTuning.indi.innerLoopGainV = [4.]
            ret.lateralTuning.indi.outerLoopGainBP = [0.]
            ret.lateralTuning.indi.outerLoopGainV = [3.]
            ret.lateralTuning.indi.timeConstantBP = [0.]
            ret.lateralTuning.indi.timeConstantV = [1.4]
            ret.lateralTuning.indi.actuatorEffectivenessBP = [0.]
            ret.lateralTuning.indi.actuatorEffectivenessV = [1.8]
        elif candidate in [CAR.KIA_OPTIMA, CAR.KIA_OPTIMA_H]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_STINGER:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1825. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_FORTE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_CEED:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1450. + STD_CARGO_KG
            ret.wheelbase = 2.65
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]

        # Genesis
        elif candidate == CAR.GENESIS_G70:
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGainBP = [0.]
            ret.lateralTuning.indi.innerLoopGainV = [2.5]
            ret.lateralTuning.indi.outerLoopGainBP = [0.]
            ret.lateralTuning.indi.outerLoopGainV = [3.5]
            ret.lateralTuning.indi.timeConstantBP = [0.]
            ret.lateralTuning.indi.timeConstantV = [1.4]
            ret.lateralTuning.indi.actuatorEffectivenessBP = [0.]
            ret.lateralTuning.indi.actuatorEffectivenessV = [1.8]
            ret.steerActuatorDelay = 0.1
            ret.mass = 1640.0 + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 13.56
        elif candidate == CAR.GENESIS_G80:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate == CAR.GENESIS_G90:
            ret.mass = 2200
            ret.wheelbase = 3.15
            ret.steerRatio = 12.069
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]

        # these cars require a special panda safety mode due to missing counters and checksums in the messages
        if candidate in [
                CAR.HYUNDAI_GENESIS, CAR.IONIQ_EV_2020, CAR.IONIQ_EV_LTD,
                CAR.IONIQ_PHEV, CAR.IONIQ, CAR.KONA_EV, CAR.KIA_SORENTO,
                CAR.SONATA_LF, CAR.KIA_NIRO_EV, CAR.KIA_OPTIMA, CAR.VELOSTER,
                CAR.KIA_STINGER, CAR.KIA_SELTOS, CAR.GENESIS_G70,
                CAR.GENESIS_G80, CAR.KIA_CEED, CAR.ELANTRA
        ]:
            ret.safetyModel = car.CarParams.SafetyModel.hyundaiLegacy

        # set appropriate safety param for gas signal
        if candidate in HYBRID_CAR:
            ret.safetyParam = 2
        elif candidate in EV_CAR:
            ret.safetyParam = 1

        ret.centerToFront = ret.wheelbase * 0.4

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        ret.enableBsm = 0x58b in fingerprint[0]

        return ret
Esempio n. 17
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   car_fw=None):
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint)

        # VW port is a community feature, since we don't own one to test
        ret.communityFeature = True

        if True:  # pylint: disable=using-constant-test
            # Set common MQB parameters that will apply globally
            ret.carName = "volkswagen"
            ret.radarOffCan = True
            ret.safetyModel = car.CarParams.SafetyModel.volkswagen
            ret.steerActuatorDelay = 0.05

            if 0xAD in fingerprint[0]:
                # Getriebe_11 detected: traditional automatic or DSG gearbox
                ret.transmissionType = TransmissionType.automatic
            elif 0x187 in fingerprint[0]:
                # EV_Gearshift detected: e-Golf or similar direct-drive electric
                ret.transmissionType = TransmissionType.direct
            else:
                # No trans message at all, must be a true stick-shift manual
                ret.transmissionType = TransmissionType.manual
            cloudlog.info("Detected transmission type: %s",
                          ret.transmissionType)

        # Global tuning defaults, can be overridden per-vehicle

        ret.steerRateCost = 1.0
        ret.steerLimitTimer = 0.4
        ret.steerRatio = 15.6  # Let the params learner figure this out
        tire_stiffness_factor = 1.0  # Let the params learner figure this out
        ret.lateralTuning.pid.kpBP = [0.]
        ret.lateralTuning.pid.kiBP = [0.]
        ret.lateralTuning.pid.kf = 0.00006
        ret.lateralTuning.pid.kpV = [0.6]
        ret.lateralTuning.pid.kiV = [0.2]

        # Per-chassis tuning values, override tuning defaults here if desired

        if candidate == CAR.GOLF_MK7:
            # Averages of all AU Golf variants
            ret.mass = 1397 + STD_CARGO_KG
            ret.wheelbase = 2.62

        elif candidate == CAR.JETTA_MK7:
            # Averages of all BU Jetta variants
            ret.mass = 1328 + STD_CARGO_KG
            ret.wheelbase = 2.71

        elif candidate == CAR.PASSAT_MK8:
            # Averages of all 3C Passat variants
            ret.mass = 1551 + STD_CARGO_KG
            ret.wheelbase = 2.79

        elif candidate == CAR.TIGUAN_MK2:
            # Average of SWB and LWB variants
            ret.mass = 1715 + STD_CARGO_KG
            ret.wheelbase = 2.74

        elif candidate == CAR.AUDI_A3_MK3:
            # Averages of all 8V A3 variants
            ret.mass = 1335 + STD_CARGO_KG
            ret.wheelbase = 2.61

        elif candidate == CAR.SEAT_ATECA_MK1:
            # Averages of all 5F Ateca variants
            ret.mass = 1900 + STD_CARGO_KG
            ret.wheelbase = 2.64

        elif candidate == CAR.SKODA_KODIAQ_MK1:
            # Averages of all 5N Kodiaq variants
            ret.mass = 1569 + STD_CARGO_KG
            ret.wheelbase = 2.79

        elif candidate == CAR.SKODA_SCALA_MK1:
            # Averages of all NW Scala variants
            ret.mass = 1192 + STD_CARGO_KG
            ret.wheelbase = 2.65

        elif candidate == CAR.SKODA_SUPERB_MK3:
            # Averages of all 3V/NP Scala variants
            ret.mass = 1505 + STD_CARGO_KG
            ret.wheelbase = 2.84

        ret.centerToFront = ret.wheelbase * 0.45

        ret.enableCamera = True  # Stock camera detection doesn't apply to VW

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        return ret
Esempio n. 18
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   has_relay=False,
                   car_fw=[]):
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint,
                                              has_relay)

        # VW port is a community feature, since we don't own one to test
        ret.communityFeature = True

        if candidate == CAR.GOLF:
            # Set common MQB parameters that will apply globally
            ret.carName = "volkswagen"
            ret.radarOffCan = True
            ret.safetyModel = car.CarParams.SafetyModel.volkswagen

            # Additional common MQB parameters that may be overridden per-vehicle
            ret.steerRateCost = 0.5
            ret.steerActuatorDelay = 0.05  # Hopefully all MQB racks are similar here
            ret.steerLimitTimer = 0.4

            # As a starting point for speed-adjusted lateral tuning, use the example
            # map speed breakpoints from a VW Tiguan (SSP 399 page 9). It's unclear
            # whether the driver assist map breakpoints have any direct bearing on
            # HCA assist torque, but if they're good breakpoints for the driver,
            # they're probably good breakpoints for HCA as well. OP won't be driving
            # 250kph/155mph but it provides interpolation scaling above 100kmh/62mph.
            ret.lateralTuning.pid.kpBP = [
                0., 15 * CV.KPH_TO_MS, 50 * CV.KPH_TO_MS
            ]
            ret.lateralTuning.pid.kiBP = [
                0., 15 * CV.KPH_TO_MS, 50 * CV.KPH_TO_MS
            ]

            # FIXME: Per-vehicle parameters need to be reintegrated.
            # For the time being, per-vehicle stuff is being archived since we
            # can't auto-detect very well yet. Now that tuning is figured out,
            # averaged params should work reasonably on a range of cars. Owners
            # can tweak here, as needed, until we have car type auto-detection.

            ret.mass = 1700 + STD_CARGO_KG
            ret.wheelbase = 2.75
            ret.centerToFront = ret.wheelbase * 0.45
            ret.steerRatio = 15.6
            ret.lateralTuning.pid.kf = 0.00006
            ret.lateralTuning.pid.kpV = [0.15, 0.25, 0.60]
            ret.lateralTuning.pid.kiV = [0.05, 0.05, 0.05]
            tire_stiffness_factor = 0.6

        ret.enableCamera = True  # Stock camera detection doesn't apply to VW
        ret.transmissionType = car.CarParams.TransmissionType.automatic

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        return ret
Esempio n. 19
0
    def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]):  # pylint: disable=dangerous-default-value
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint)

        ret.openpilotLongitudinalControl = Params().get_bool(
            'LongControlEnabled')

        ret.carName = "hyundai"
        ret.safetyConfigs = [
            get_safety_config(car.CarParams.SafetyModel.hyundaiLegacy, 0)
        ]

        tire_stiffness_factor = 1.
        ret.maxSteeringAngleDeg = 1000.

        # lateral
        ret.lateralTuning.init('lqr')

        ret.lateralTuning.lqr.scale = 1700.
        ret.lateralTuning.lqr.ki = 0.012
        ret.lateralTuning.lqr.dcGain = 0.00285

        ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
        ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
        ret.lateralTuning.lqr.c = [1., 0.]
        ret.lateralTuning.lqr.k = [-110., 451.]
        ret.lateralTuning.lqr.l = [0.33, 0.318]

        ret.steerRatio = 17.23
        ret.steerActuatorDelay = 0.1
        ret.steerRateCost = 0.41

        ret.steerLimitTimer = 2.5
        ret.steerMaxBP = [0.]
        ret.steerMaxV = [1.5]

        # longitudinal
        ret.longitudinalTuning.kpBP = [
            0., 5. * CV.KPH_TO_MS, 10. * CV.KPH_TO_MS, 20. * CV.KPH_TO_MS,
            130. * CV.KPH_TO_MS
        ]
        ret.longitudinalTuning.kpV = [1.6, 1.18, 0.9, 0.78, 0.48]
        ret.longitudinalTuning.kiBP = [0., 130. * CV.KPH_TO_MS]
        ret.longitudinalTuning.kiV = [0.1, 0.06]
        ret.longitudinalActuatorDelayLowerBound = 0.3
        ret.longitudinalActuatorDelayUpperBound = 0.3

        ret.stopAccel = -2.0
        ret.stoppingDecelRate = 0.6  # brake_travel/s while trying to stop
        ret.vEgoStopping = 0.5
        ret.vEgoStarting = 0.5  # needs to be >= vEgoStopping to avoid state transition oscillation

        # genesis
        if candidate == CAR.GENESIS:
            ret.mass = 1900. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.centerToFront = ret.wheelbase * 0.4
            ret.maxSteeringAngleDeg = 90.
        elif candidate == CAR.GENESIS_G70:
            ret.mass = 1640. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.GENESIS_G80:
            ret.mass = 1855. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.GENESIS_EQ900:
            ret.mass = 2200
            ret.wheelbase = 3.15
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.GENESIS_EQ900_L:
            ret.mass = 2290
            ret.wheelbase = 3.45
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.GENESIS_G90:
            ret.mass = 2150
            ret.wheelbase = 3.16
            ret.centerToFront = ret.wheelbase * 0.4
        # hyundai
        elif candidate in [CAR.SANTA_FE]:
            ret.mass = 1694 + STD_CARGO_KG
            ret.wheelbase = 2.766
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.SANTA_FE_2022, CAR.SANTA_FE_HEV_2022]:
            ret.mass = 1750 + STD_CARGO_KG
            ret.wheelbase = 2.766
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.SONATA, CAR.SONATA_HEV, CAR.SONATA21_HEV]:
            ret.mass = 1513. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.centerToFront = ret.wheelbase * 0.4
            tire_stiffness_factor = 0.65
        elif candidate in [CAR.SONATA19, CAR.SONATA19_HEV]:
            ret.mass = 4497. * CV.LB_TO_KG
            ret.wheelbase = 2.804
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.SONATA_LF_TURBO:
            ret.mass = 1590. + STD_CARGO_KG
            ret.wheelbase = 2.805
            tire_stiffness_factor = 0.65
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.PALISADE:
            ret.mass = 1999. + STD_CARGO_KG
            ret.wheelbase = 2.90
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.ELANTRA_2021:
            ret.mass = (2800. * CV.LB_TO_KG) + STD_CARGO_KG
            ret.wheelbase = 2.72
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            tire_stiffness_factor = 0.65
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.ELANTRA_HEV_2021:
            ret.mass = (3017. * CV.LB_TO_KG) + STD_CARGO_KG
            ret.wheelbase = 2.72
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            tire_stiffness_factor = 0.65
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.KONA:
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.KONA_HEV, CAR.KONA_EV]:
            ret.mass = 1395. + STD_CARGO_KG
            ret.wheelbase = 2.6
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [
                CAR.IONIQ, CAR.IONIQ_EV_LTD, CAR.IONIQ_EV_2020, CAR.IONIQ_PHEV
        ]:
            ret.mass = 1490. + STD_CARGO_KG
            ret.wheelbase = 2.7
            tire_stiffness_factor = 0.385
            #if candidate not in [CAR.IONIQ_EV_2020, CAR.IONIQ_PHEV]:
            #  ret.minSteerSpeed = 32 * CV.MPH_TO_MS
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.GRANDEUR_IG, CAR.GRANDEUR_IG_HEV]:
            tire_stiffness_factor = 0.8
            ret.mass = 1640. + STD_CARGO_KG
            ret.wheelbase = 2.845
            ret.centerToFront = ret.wheelbase * 0.385
            ret.steerRatio = 17.
        elif candidate in [CAR.GRANDEUR_IG_FL, CAR.GRANDEUR_IG_FL_HEV]:
            tire_stiffness_factor = 0.8
            ret.mass = 1725. + STD_CARGO_KG
            ret.wheelbase = 2.885
            ret.centerToFront = ret.wheelbase * 0.385
            ret.steerRatio = 17.
        elif candidate == CAR.VELOSTER:
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            tire_stiffness_factor = 0.9
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.TUCSON_TL_SCC:
            ret.mass = 1594. + STD_CARGO_KG  #1730
            ret.wheelbase = 2.67
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        # kia
        elif candidate == CAR.SORENTO:
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.K5, CAR.K5_HEV]:
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.K5_2021]:
            ret.mass = 3228. * CV.LB_TO_KG
            ret.wheelbase = 2.85
            tire_stiffness_factor = 0.7
        elif candidate == CAR.STINGER:
            tire_stiffness_factor = 1.125  # LiveParameters (Tunder's 2020)
            ret.mass = 1825.0 + STD_CARGO_KG
            ret.wheelbase = 2.906
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.FORTE:
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.CEED:
            ret.mass = 1350. + STD_CARGO_KG
            ret.wheelbase = 2.65
            tire_stiffness_factor = 0.6
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.SPORTAGE:
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate in [CAR.NIRO_EV, CAR.NIRO_HEV, CAR.NIRO_HEV_2021]:
            ret.mass = 1737. + STD_CARGO_KG
            ret.wheelbase = 2.7
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.SELTOS:
            ret.mass = 1310. + STD_CARGO_KG
            ret.wheelbase = 2.6
            tire_stiffness_factor = 0.7
            ret.centerToFront = ret.wheelbase * 0.4
        elif candidate == CAR.MOHAVE:
            ret.mass = 2285. + STD_CARGO_KG
            ret.wheelbase = 2.895
            ret.centerToFront = ret.wheelbase * 0.5
            tire_stiffness_factor = 0.8
        elif candidate in [CAR.K7, CAR.K7_HEV]:
            tire_stiffness_factor = 0.7
            ret.mass = 1650. + STD_CARGO_KG
            ret.wheelbase = 2.855
            ret.centerToFront = ret.wheelbase * 0.4
            ret.steerRatio = 17.5
        elif candidate == CAR.K9:
            ret.mass = 2005. + STD_CARGO_KG
            ret.wheelbase = 3.15
            ret.centerToFront = ret.wheelbase * 0.4
            tire_stiffness_factor = 0.8

            ret.steerRatio = 14.5

            ret.lateralTuning.lqr.scale = 1650.
            ret.lateralTuning.lqr.ki = 0.01
            ret.lateralTuning.lqr.dcGain = 0.0027

        ret.radarTimeStep = 0.05

        if ret.centerToFront == 0:
            ret.centerToFront = ret.wheelbase * 0.4

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        # no rear steering, at least on the listed cars above
        ret.steerRatioRear = 0.
        ret.steerControlType = car.CarParams.SteerControlType.torque

        ret.stoppingControl = True

        ret.enableBsm = 0x58b in fingerprint[0]
        ret.enableAutoHold = 1151 in fingerprint[0]

        # ignore CAN2 address if L-CAN on the same BUS
        ret.mdpsBus = 1 if 593 in fingerprint[1] and 1296 not in fingerprint[
            1] else 0
        ret.sasBus = 1 if 688 in fingerprint[1] and 1296 not in fingerprint[
            1] else 0
        ret.sccBus = 0 if 1056 in fingerprint[0] else 1 if 1056 in fingerprint[1] and 1296 not in fingerprint[1] \
                                                                         else 2 if 1056 in fingerprint[2] else -1

        if ret.sccBus >= 0:
            ret.hasScc13 = 1290 in fingerprint[ret.sccBus]
            ret.hasScc14 = 905 in fingerprint[ret.sccBus]

        ret.hasEms = 608 in fingerprint[0] and 809 in fingerprint[0]
        ret.hasLfaHda = 1157 in fingerprint[0]

        ret.radarOffCan = ret.sccBus == -1
        ret.pcmCruise = not ret.radarOffCan

        # set safety_hyundai_community only for non-SCC, MDPS harrness or SCC harrness cars or cars that have unknown issue
        if ret.radarOffCan or ret.mdpsBus == 1 or ret.openpilotLongitudinalControl or ret.sccBus == 1 or Params(
        ).get_bool('MadModeEnabled'):
            ret.safetyConfigs = [
                get_safety_config(car.CarParams.SafetyModel.hyundaiCommunity,
                                  0)
            ]
        return ret
Esempio n. 20
0
 def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None, disable_radar=False):
   pass
Esempio n. 21
0
 def get_params(candidate,
                fingerprint=gen_empty_fingerprint(),
                has_relay=False,
                car_fw=[]):
     raise NotImplementedError
Esempio n. 22
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   has_relay=False,
                   car_fw=None):
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint,
                                              has_relay)
        ret.carName = "gm"
        ret.safetyModel = car.CarParams.SafetyModel.gm
        ret.enableCruise = False  # stock cruise control is kept off

        # GM port is a community feature
        # TODO: make a port that uses a car harness and it only intercepts the camera
        ret.communityFeature = True

        # Presence of a camera on the object bus is ok.
        # Have to go to read_only if ASCM is online (ACC-enabled cars),
        # or camera is on powertrain bus (LKA cars without ACC).
        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS,
                                               ECU_FINGERPRINT, candidate,
                                               Ecu.fwdCamera) or has_relay
        ret.openpilotLongitudinalControl = ret.enableCamera
        tire_stiffness_factor = 0.444  # not optimized yet

        # Start with a baseline lateral tuning for all GM vehicles. Override tuning as needed in each model section below.
        ret.minSteerSpeed = 7 * CV.MPH_TO_MS
        ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2], [0.00]]
        ret.lateralTuning.pid.kf = 0.00004  # full torque for 20 deg at 80mph means 0.00007818594
        ret.steerRateCost = 1.0
        ret.steerActuatorDelay = 0.1  # Default delay, not measured yet

        if candidate == CAR.VOLT:
            # supports stop and go, but initial engage must be above 18mph (which include conservatism)
            ret.minEnableSpeed = -1
            ret.mass = 1607. + STD_CARGO_KG
            ret.wheelbase = 2.69
            ret.steerRatio = 15.7
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # wild guess

        elif candidate == CAR.MALIBU:
            # supports stop and go, but initial engage must be above 18mph (which include conservatism)
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1496. + STD_CARGO_KG
            ret.wheelbase = 2.83
            ret.steerRatio = 15.8
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # wild guess

        elif candidate == CAR.HOLDEN_ASTRA:
            ret.mass = 1363. + STD_CARGO_KG
            ret.wheelbase = 2.662
            # Remaining parameters copied from Volt for now
            ret.centerToFront = ret.wheelbase * 0.4
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.steerRatio = 15.7
            ret.steerRatioRear = 0.

        elif candidate == CAR.ACADIA:
            ret.minEnableSpeed = -1.  # engage speed is decided by pcm
            ret.mass = 4353. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.86
            ret.steerRatio = 14.4  # end to end is 13.46
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4

        elif candidate == CAR.BUICK_REGAL:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 3779. * CV.LB_TO_KG + STD_CARGO_KG  # (3849+3708)/2
            ret.wheelbase = 2.83  # 111.4 inches in meters
            ret.steerRatio = 14.4  # guess for tourx
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.4  # guess for tourx

        elif candidate == CAR.CADILLAC_ATS:
            ret.minEnableSpeed = 18 * CV.MPH_TO_MS
            ret.mass = 1601. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 15.3
            ret.steerRatioRear = 0.
            ret.centerToFront = ret.wheelbase * 0.49

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        ret.longitudinalTuning.kpBP = [5., 35.]
        ret.longitudinalTuning.kpV = [2.4, 1.5]
        ret.longitudinalTuning.kiBP = [0.]
        ret.longitudinalTuning.kiV = [0.36]

        ret.stoppingControl = True
        ret.startAccel = 0.8

        ret.steerLimitTimer = 0.4
        ret.radarTimeStep = 0.0667  # GM radar runs at 15Hz instead of standard 20Hz

        return ret
Esempio n. 23
0
  def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=None):
    ret = CarInterfaceBase.get_std_params(candidate, fingerprint)
    ret.carName = "gm"
    ret.safetyConfigs = [get_safety_config(car.CarParams.SafetyModel.gm)]
    ret.pcmCruise = False  # stock cruise control is kept off

    # Presence of a camera on the object bus is ok.
    # Have to go to read_only if ASCM is online (ACC-enabled cars),
    # or camera is on powertrain bus (LKA cars without ACC).
    ret.openpilotLongitudinalControl = True
    tire_stiffness_factor = 0.444  # not optimized yet

    # Start with a baseline lateral tuning for all GM vehicles. Override tuning as needed in each model section below.
    ret.minSteerSpeed = 7 * CV.MPH_TO_MS
    ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
    ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2], [0.00]]
    ret.lateralTuning.pid.kf = 0.00004   # full torque for 20 deg at 80mph means 0.00007818594
    ret.steerRateCost = 1.0
    ret.steerActuatorDelay = 0.1  # Default delay, not measured yet

    if candidate == CAR.VOLT:
      # supports stop and go, but initial engage must be above 18mph (which include conservatism)
      ret.minEnableSpeed = 18 * CV.MPH_TO_MS
      ret.mass = 1607. + STD_CARGO_KG
      ret.wheelbase = 2.69
      ret.steerRatio = 17.7  # Stock 15.7, LiveParameters
      tire_stiffness_factor = 0.469 # Stock Michelin Energy Saver A/S, LiveParameters
      ret.steerRatioRear = 0.
      ret.centerToFront = ret.wheelbase * 0.45 # Volt Gen 1, TODO corner weigh

      ret.lateralTuning.pid.kpBP = [0., 40.]
      ret.lateralTuning.pid.kpV = [0., 0.17]
      ret.lateralTuning.pid.kiBP = [0.]
      ret.lateralTuning.pid.kiV = [0.]
      ret.lateralTuning.pid.kf = 1. # get_steer_feedforward_volt()
      ret.steerActuatorDelay = 0.2

    elif candidate == CAR.MALIBU:
      # supports stop and go, but initial engage must be above 18mph (which include conservatism)
      ret.minEnableSpeed = 18 * CV.MPH_TO_MS
      ret.mass = 1496. + STD_CARGO_KG
      ret.wheelbase = 2.83
      ret.steerRatio = 15.8
      ret.steerRatioRear = 0.
      ret.centerToFront = ret.wheelbase * 0.4  # wild guess

    elif candidate == CAR.HOLDEN_ASTRA:
      ret.mass = 1363. + STD_CARGO_KG
      ret.wheelbase = 2.662
      # Remaining parameters copied from Volt for now
      ret.centerToFront = ret.wheelbase * 0.4
      ret.minEnableSpeed = 18 * CV.MPH_TO_MS
      ret.steerRatio = 15.7
      ret.steerRatioRear = 0.

    elif candidate == CAR.ACADIA:
      ret.minEnableSpeed = -1.  # engage speed is decided by pcm
      ret.mass = 4353. * CV.LB_TO_KG + STD_CARGO_KG
      ret.wheelbase = 2.86
      ret.steerRatio = 14.4  # end to end is 13.46
      ret.steerRatioRear = 0.
      ret.centerToFront = ret.wheelbase * 0.4
      ret.lateralTuning.pid.kf = 1. # get_steer_feedforward_acadia()

    elif candidate == CAR.BUICK_REGAL:
      ret.minEnableSpeed = 18 * CV.MPH_TO_MS
      ret.mass = 3779. * CV.LB_TO_KG + STD_CARGO_KG  # (3849+3708)/2
      ret.wheelbase = 2.83  # 111.4 inches in meters
      ret.steerRatio = 14.4  # guess for tourx
      ret.steerRatioRear = 0.
      ret.centerToFront = ret.wheelbase * 0.4  # guess for tourx

    elif candidate == CAR.CADILLAC_ATS:
      ret.minEnableSpeed = 18 * CV.MPH_TO_MS
      ret.mass = 1601. + STD_CARGO_KG
      ret.wheelbase = 2.78
      ret.steerRatio = 15.3
      ret.steerRatioRear = 0.
      ret.centerToFront = ret.wheelbase * 0.49

    elif candidate == CAR.ESCALADE_ESV:
      ret.minEnableSpeed = -1.  # engage speed is decided by pcm
      ret.mass = 2739. + STD_CARGO_KG
      ret.wheelbase = 3.302
      ret.steerRatio = 17.3
      ret.centerToFront = ret.wheelbase * 0.49
      ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[10., 41.0], [10., 41.0]]
      ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.13, 0.24], [0.01, 0.02]]
      ret.lateralTuning.pid.kf = 0.000045
      tire_stiffness_factor = 1.0

    # TODO: get actual value, for now starting with reasonable value for
    # civic and scaling by mass and wheelbase
    ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

    # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
    # mass and CG position, so all cars will have approximately similar dyn behaviors
    ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
                                                                         tire_stiffness_factor=tire_stiffness_factor)

    ret.longitudinalTuning.kpBP = [5., 35.]
    ret.longitudinalTuning.kpV = [2.4, 1.5]
    ret.longitudinalTuning.kiBP = [0.]
    ret.longitudinalTuning.kiV = [0.36]

    ret.steerLimitTimer = 0.4
    ret.radarTimeStep = 0.0667  # GM radar runs at 15Hz instead of standard 20Hz

    return ret
Esempio n. 24
0
    def get_params(candidate, fingerprint=gen_empty_fingerprint(), car_fw=[]):  # pylint: disable=dangerous-default-value
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint)

        ret.carName = "hyundai"
        ret.safetyConfigs = [
            get_safety_config(car.CarParams.SafetyModel.hyundai, 0)
        ]
        ret.radarOffCan = RADAR_START_ADDR not in fingerprint[1]

        # WARNING: disabling radar also disables AEB (and we show the same warning on the instrument cluster as if you manually disabled AEB)
        ret.openpilotLongitudinalControl = Params().get_bool(
            "DisableRadar") and candidate in [
                CAR.SONATA, CAR.SONATA_HYBRID, CAR.PALISADE, CAR.SANTA_FE
            ]

        ret.pcmCruise = not ret.openpilotLongitudinalControl

        ret.steerActuatorDelay = 0.1  # Default delay
        ret.steerRateCost = 0.5
        ret.steerLimitTimer = 0.4
        tire_stiffness_factor = 1.

        ret.stoppingControl = True
        ret.vEgoStopping = 1.0

        ret.longitudinalTuning.kpV = [0.1]
        ret.longitudinalTuning.kiV = [0.0]
        ret.stopAccel = 0.0
        ret.startAccel = 0.0

        ret.longitudinalActuatorDelayUpperBound = 1.0  # s

        if candidate in [CAR.SANTA_FE, CAR.SANTA_FE_2022]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3982. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.766
            # Values from optimizer
            ret.steerRatio = 16.55  # 13.8 is spec end-to-end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                9., 22.
            ], [9., 22.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.2, 0.35
            ], [0.05, 0.09]]
        elif candidate in [CAR.SONATA, CAR.SONATA_HYBRID]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1513. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            tire_stiffness_factor = 0.65
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.SONATA_LF:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 4497. * CV.LB_TO_KG
            ret.wheelbase = 2.804
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.PALISADE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1999. + STD_CARGO_KG
            ret.wheelbase = 2.90
            ret.steerRatio = 15.6 * 1.15
            tire_stiffness_factor = 0.63
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                    [0.05]]
        elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 15.4  # 14 is Stock | Settled Params Learner values are steerRatio: 15.401566348670535
            tire_stiffness_factor = 0.385  # stiffnessFactor settled on 1.0081302973865127
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.ELANTRA_2021:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = (2800. * CV.LB_TO_KG) + STD_CARGO_KG
            ret.wheelbase = 2.72
            ret.steerRatio = 12.9
            tire_stiffness_factor = 0.65
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.ELANTRA_HEV_2021:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = (3017. * CV.LB_TO_KG) + STD_CARGO_KG
            ret.wheelbase = 2.72
            ret.steerRatio = 12.9
            tire_stiffness_factor = 0.65
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.HYUNDAI_GENESIS:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGainBP = [0.]
            ret.lateralTuning.indi.innerLoopGainV = [3.5]
            ret.lateralTuning.indi.outerLoopGainBP = [0.]
            ret.lateralTuning.indi.outerLoopGainV = [2.0]
            ret.lateralTuning.indi.timeConstantBP = [0.]
            ret.lateralTuning.indi.timeConstantV = [1.4]
            ret.lateralTuning.indi.actuatorEffectivenessBP = [0.]
            ret.lateralTuning.indi.actuatorEffectivenessV = [2.3]
            ret.minSteerSpeed = 60 * CV.KPH_TO_MS
        elif candidate in [CAR.KONA, CAR.KONA_EV, CAR.KONA_HEV]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = {
                CAR.KONA_EV: 1685.,
                CAR.KONA_HEV: 1425.
            }.get(candidate, 1275.) + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73 * 1.15  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [
                CAR.IONIQ, CAR.IONIQ_EV_LTD, CAR.IONIQ_EV_2020, CAR.IONIQ_PHEV,
                CAR.IONIQ_HEV_2022
        ]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1490. + STD_CARGO_KG  # weight per hyundai site https://www.hyundaiusa.com/ioniq-electric/specifications.aspx
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            if candidate not in [
                    CAR.IONIQ_EV_2020, CAR.IONIQ_PHEV, CAR.IONIQ_HEV_2022
            ]:
                ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.VELOSTER:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75 * 1.15
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]

        # Kia
        elif candidate == CAR.KIA_SORENTO:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.1  # 10% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [
                CAR.KIA_NIRO_EV, CAR.KIA_NIRO_HEV, CAR.KIA_NIRO_HEV_2021
        ]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1737. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.9 if CAR.KIA_NIRO_HEV_2021 else 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            if candidate == CAR.KIA_NIRO_HEV:
                ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.KIA_SELTOS:
            ret.mass = 1337. + STD_CARGO_KG
            ret.wheelbase = 2.63
            ret.steerRatio = 14.56
            tire_stiffness_factor = 1
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGainBP = [0.]
            ret.lateralTuning.indi.innerLoopGainV = [4.]
            ret.lateralTuning.indi.outerLoopGainBP = [0.]
            ret.lateralTuning.indi.outerLoopGainV = [3.]
            ret.lateralTuning.indi.timeConstantBP = [0.]
            ret.lateralTuning.indi.timeConstantV = [1.4]
            ret.lateralTuning.indi.actuatorEffectivenessBP = [0.]
            ret.lateralTuning.indi.actuatorEffectivenessV = [1.8]
        elif candidate in [CAR.KIA_OPTIMA, CAR.KIA_OPTIMA_H]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_STINGER:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1825. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_FORTE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_CEED:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1450. + STD_CARGO_KG
            ret.wheelbase = 2.65
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_K5_2021:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3228. * CV.LB_TO_KG
            ret.wheelbase = 2.85
            ret.steerRatio = 13.27  # 2021 Kia K5 Steering Ratio (all trims)
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]

        # Genesis
        elif candidate == CAR.GENESIS_G70:
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGainBP = [0.]
            ret.lateralTuning.indi.innerLoopGainV = [2.5]
            ret.lateralTuning.indi.outerLoopGainBP = [0.]
            ret.lateralTuning.indi.outerLoopGainV = [3.5]
            ret.lateralTuning.indi.timeConstantBP = [0.]
            ret.lateralTuning.indi.timeConstantV = [1.4]
            ret.lateralTuning.indi.actuatorEffectivenessBP = [0.]
            ret.lateralTuning.indi.actuatorEffectivenessV = [1.8]
            ret.steerActuatorDelay = 0.1
            ret.mass = 1640.0 + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 13.56
        elif candidate == CAR.GENESIS_G80:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate == CAR.GENESIS_G90:
            ret.mass = 2200
            ret.wheelbase = 3.15
            ret.steerRatio = 12.069
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]

        # these cars require a special panda safety mode due to missing counters and checksums in the messages
        if candidate in [
                CAR.HYUNDAI_GENESIS, CAR.IONIQ_EV_2020, CAR.IONIQ_EV_LTD,
                CAR.IONIQ_PHEV, CAR.IONIQ, CAR.KONA_EV, CAR.KIA_SORENTO,
                CAR.SONATA_LF, CAR.KIA_NIRO_EV, CAR.KIA_OPTIMA, CAR.VELOSTER,
                CAR.KIA_STINGER, CAR.GENESIS_G70, CAR.GENESIS_G80,
                CAR.KIA_CEED, CAR.ELANTRA, CAR.IONIQ_HEV_2022
        ]:
            assert not ret.openpilotLongitudinalControl  # Legacy safety mode doesn't support longitudinal
            ret.safetyConfigs = [
                get_safety_config(car.CarParams.SafetyModel.hyundaiLegacy)
            ]

        # set appropriate safety param for gas signal
        if candidate in HYBRID_CAR:
            ret.safetyConfigs[0].safetyParam = 2
        elif candidate in EV_CAR:
            ret.safetyConfigs[0].safetyParam = 1

        ret.centerToFront = ret.wheelbase * 0.4

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        ret.enableBsm = 0x58b in fingerprint[0]

        if ret.openpilotLongitudinalControl:
            ret.safetyConfigs[0].safetyParam |= Panda.FLAG_HYUNDAI_LONG

        return ret
Esempio n. 25
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   has_relay=False,
                   car_fw=[]):
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint,
                                              has_relay)

        ret.carName = "hyundai"
        ret.safetyModel = car.CarParams.SafetyModel.hyundai

        # Hyundai port is a community feature for now
        ret.communityFeature = True

        ret.steerActuatorDelay = 0.1  # Default delay
        ret.steerRateCost = 0.5
        ret.steerLimitTimer = 0.8
        tire_stiffness_factor = 1.

        if candidate in [CAR.SANTA_FE, CAR.SANTA_FE_1]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3982. * CV.LB_TO_KG + STD_CARGO_KG
            ret.wheelbase = 2.766
            # Values from optimizer
            ret.steerRatio = 16.55  # 13.8 is spec end-to-end
            tire_stiffness_factor = 0.82
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                9., 22.
            ], [9., 22.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.2, 0.35
            ], [0.05, 0.09]]
        elif candidate in [CAR.SONATA, CAR.SONATA_H]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1513. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.SONATA_2019:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 4497. * CV.LB_TO_KG
            ret.wheelbase = 2.804
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.PALISADE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1999. + STD_CARGO_KG
            ret.wheelbase = 2.90
            ret.steerRatio = 13.75 * 1.15
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_SORENTO:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.1  # 10% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 15.4  # 14 is Stock | Settled Params Learner values are steerRatio: 15.401566348670535
            tire_stiffness_factor = 0.385  # stiffnessFactor settled on 1.0081302973865127
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.HYUNDAI_GENESIS:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
            ret.minSteerSpeed = 60 * CV.KPH_TO_MS
        elif candidate == CAR.GENESIS_G80:
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGain = 3.0  #stock is 3.0 - outer and inner are gains. Higher values = more steering
            ret.lateralTuning.indi.outerLoopGain = 2.0  #stock is 2.0 - outer and inner are gains. Higher values = more steering
            ret.lateralTuning.indi.timeConstant = 1.5  #Stock is 1.5 - timeconstant is smoothing. Higher values == more smoothing but less response
            ret.lateralTuning.indi.actuatorEffectiveness = 1.3  #Stock is 1.0 - actuatoreffectiveness is how much it steers. Lower values == more steering
            ret.mass = 2140. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            #ret.lateralTuning.pid.kf = 0.00005
            #ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
            #ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16], [0.01]]
        elif candidate == CAR.GENESIS_G90:
            ret.mass = 2200
            ret.wheelbase = 3.15
            ret.steerRatio = 12.069
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate in [CAR.KIA_OPTIMA, CAR.KIA_OPTIMA_H]:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_STINGER:
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGain = 3.0
            ret.lateralTuning.indi.outerLoopGain = 2.0
            ret.lateralTuning.indi.timeConstant = 1.0
            ret.lateralTuning.indi.actuatorEffectiveness = 1.5
            ret.steerActuatorDelay = 0.08  # Stinger GT Limited AWD 3.3T stock value (Tunder's 2020)
            ret.steerLimitTimer = 0.4  # stock is 0.01 but 0.04 seems to work well
            tire_stiffness_factor = 1.125  # LiveParameters (Tunder's 2020)
            ret.steerRateCost = 1.0
            ret.mass = 1825.0 + STD_CARGO_KG
            ret.wheelbase = 2.906  # https://www.kia.com/us/en/stinger/specs
            ret.steerRatio = 13.56  # 10.28 measured by wheel alignment machine/reported steering angle by OP. 2020 GT Limited AWD has a variable steering ratio ultimately ending in 10.28.  13.56 after 1200km in LiveParamaters (Tunder)
        elif candidate == CAR.KONA:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KONA_EV:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1685. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.IONIQ, CAR.IONIQ_EV_LTD]:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1490. + STD_CARGO_KG  #weight per hyundai site https://www.hyundaiusa.com/ioniq-electric/specifications.aspx
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  #Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            #ret.minSteerSpeed = 32 * CV.MPH_TO_MS
        elif candidate == CAR.KIA_FORTE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_CEED:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1350. + STD_CARGO_KG
            ret.wheelbase = 2.65
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KIA_SPORTAGE:
            ret.lateralTuning.pid.kf = 0.00005
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.1  # 10% higher at the center seems reasonable
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
            ret.minSteerSpeed = 0.
        elif candidate == CAR.KIA_NIRO_EV:
            ret.lateralTuning.pid.kf = 0.00006
            ret.mass = 1737. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  #Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]

        ret.centerToFront = ret.wheelbase * 0.4

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        # no rear steering, at least on the listed cars above
        ret.steerRatioRear = 0.
        ret.steerControlType = car.CarParams.SteerControlType.torque

        ret.longitudinalTuning.kpBP = [0., 5., 35.]
        ret.longitudinalTuning.kpV = [1.2, 0.8, 0.5]
        ret.longitudinalTuning.kiBP = [0., 35.]
        ret.longitudinalTuning.kiV = [0.18, 0.12]
        ret.longitudinalTuning.deadzoneBP = [0.]
        ret.longitudinalTuning.deadzoneV = [0.]

        # steer, gas, brake limitations VS speed
        ret.steerMaxBP = [0.]
        ret.steerMaxV = [1.0]
        ret.gasMaxBP = [0.]
        ret.gasMaxV = [0.5]
        ret.brakeMaxBP = [0., 20.]
        ret.brakeMaxV = [1., 0.8]

        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS,
                                               ECU_FINGERPRINT, candidate,
                                               Ecu.fwdCamera) or has_relay

        ret.stoppingControl = True
        ret.startAccel = 0.0

        # ignore CAN2 address if L-CAN on the same BUS
        ret.mdpsBus = 1 if 593 in fingerprint[1] and 1296 not in fingerprint[
            1] else 0
        ret.sasBus = 1 if 688 in fingerprint[1] and 1296 not in fingerprint[
            1] else 0
        ret.sccBus = 0 if 1056 in fingerprint[0] else 1 if 1056 in fingerprint[1] and 1296 not in fingerprint[1] \
                                                                         else 2 if 1056 in fingerprint[2] else -1
        ret.radarOffCan = ret.sccBus == -1
        ret.openpilotLongitudinalControl = bool(ret.sccBus
                                                and not ret.radarOffCan)
        ret.autoLcaEnabled = True

        return ret
Esempio n. 26
0
  def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False, car_fw=[]):  # pylint: disable=dangerous-default-value
    ret = CarInterfaceBase.get_std_params(candidate, fingerprint, has_relay)

    ret.carName = "hyundai"
    ret.safetyModel = car.CarParams.SafetyModel.hyundaiLegacy
    if candidate in [CAR.SONATA]:
      ret.safetyModel = car.CarParams.SafetyModel.hyundai

    # Most Hyundai car ports are community features for now
    ret.communityFeature = candidate not in [CAR.SONATA, CAR.PALISADE]

    ret.steerActuatorDelay = 0.1  # Default delay
    ret.steerRateCost = 0.5
    ret.steerLimitTimer = 0.8
    tire_stiffness_factor = 1.

    # genesis
    if candidate == CAR.GENESIS:
      ret.mass = 1900. + STD_CARGO_KG
      ret.wheelbase = 3.01
    elif candidate == CAR.GENESIS_G70:
      ret.mass = 1640. + STD_CARGO_KG
      ret.wheelbase = 2.84
    elif candidate == CAR.GENESIS_G80:
      ret.mass = 1855. + STD_CARGO_KG
      ret.wheelbase = 3.01
    elif candidate == CAR.GENESIS_G90:
      ret.mass = 2200
      ret.wheelbase = 3.15
    elif candidate == CAR.GENESIS_G90_L:
      ret.mass = 2290
      ret.wheelbase = 3.45
    # hyundai
    elif candidate in [CAR.SANTA_FE]:
      ret.mass = 1694 + STD_CARGO_KG
      ret.wheelbase = 2.766
    elif candidate in [CAR.SONATA, CAR.SONATA_HEV]:
      ret.mass = 1513. + STD_CARGO_KG
      ret.wheelbase = 2.84
      tire_stiffness_factor = 0.65
    elif candidate in [CAR.SONATA19, CAR.SONATA19_HEV]:
      ret.mass = 4497. * CV.LB_TO_KG
      ret.wheelbase = 2.804
    elif candidate == CAR.SONATA_LF_TURBO:
      ret.mass = 1590. + STD_CARGO_KG
      ret.wheelbase = 2.805
      tire_stiffness_factor = 0.65
    elif candidate == CAR.PALISADE:
      ret.mass = 1999. + STD_CARGO_KG
      ret.wheelbase = 2.90
    elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
      ret.mass = 1275. + STD_CARGO_KG
      ret.wheelbase = 2.7
      tire_stiffness_factor = 0.385    # stiffnessFactor settled on 1.0081302973865127
    elif candidate == CAR.KONA:
      ret.mass = 1275. + STD_CARGO_KG
      ret.wheelbase = 2.7
      tire_stiffness_factor = 0.385
    elif candidate in [CAR.KONA_HEV, CAR.KONA_EV]:
      ret.mass = 1685. + STD_CARGO_KG
      ret.wheelbase = 2.7
      tire_stiffness_factor = 0.385
    elif candidate in [CAR.IONIQ, CAR.IONIQ_EV_LTD]:
      ret.mass = 1490. + STD_CARGO_KG   #weight per hyundai site https://www.hyundaiusa.com/ioniq-electric/specifications.aspx
      ret.wheelbase = 2.7
      tire_stiffness_factor = 0.385
    elif candidate in [CAR.GRANDEUR, CAR.GRANDEUR_HEV]:
      tire_stiffness_factor = 0.8
      ret.mass = 1640. + STD_CARGO_KG
      ret.wheelbase = 2.845
    elif candidate == CAR.VELOSTER:
      ret.mass = 3558. * CV.LB_TO_KG
      ret.wheelbase = 2.80
      tire_stiffness_factor = 0.5
    # kia
    elif candidate == CAR.SORENTO:
      ret.mass = 1985. + STD_CARGO_KG
      ret.wheelbase = 2.78
      tire_stiffness_factor = 0.5
    elif candidate in [CAR.K5, CAR.K5_HEV]:
      ret.mass = 3558. * CV.LB_TO_KG
      ret.wheelbase = 2.80
      tire_stiffness_factor = 0.5
    elif candidate == CAR.STINGER:
      tire_stiffness_factor = 1.125 # LiveParameters (Tunder's 2020)
      ret.mass = 1825.0 + STD_CARGO_KG
      ret.wheelbase = 2.906 # https://www.kia.com/us/en/stinger/specs
    elif candidate == CAR.FORTE:
      ret.mass = 3558. * CV.LB_TO_KG
      ret.wheelbase = 2.80
      tire_stiffness_factor = 0.5
    elif candidate == CAR.CEED:
      ret.mass = 1350. + STD_CARGO_KG
      ret.wheelbase = 2.65
      tire_stiffness_factor = 0.5
    elif candidate == CAR.SPORTAGE:
      ret.mass = 1985. + STD_CARGO_KG
      ret.wheelbase = 2.78
    elif candidate in [CAR.NIRO_HEV, CAR.NIRO_EV]:
      ret.mass = 1737. + STD_CARGO_KG
      ret.wheelbase = 2.7
      tire_stiffness_factor = 0.385
    elif candidate in [CAR.K7, CAR.K7_HEV]:
      tire_stiffness_factor = 0.6
      ret.mass = 1640. + STD_CARGO_KG
      ret.wheelbase = 2.845


    ret.lateralTuning.init('lqr')

    ret.lateralTuning.lqr.scale = 1700.0
    ret.lateralTuning.lqr.ki = 0.01
    ret.lateralTuning.lqr.dcGain = 0.0027

    ret.lateralTuning.lqr.a = [0., 1., -0.22619643, 1.21822268]
    ret.lateralTuning.lqr.b = [-1.92006585e-04, 3.95603032e-05]
    ret.lateralTuning.lqr.c = [1., 0.]
    ret.lateralTuning.lqr.k = [-110., 451.]
    ret.lateralTuning.lqr.l = [0.33, 0.318]

    ret.steerRatio = 16.0
    ret.steerActuatorDelay = 0.25
    ret.steerLimitTimer = 2.5

    ret.steerRateCost = 0.6

    ret.steerMaxBP = [0.]
    ret.steerMaxV = [1.3]



    ret.centerToFront = ret.wheelbase * 0.4

    # TODO: get actual value, for now starting with reasonable value for
    # civic and scaling by mass and wheelbase
    ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

    # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
    # mass and CG position, so all cars will have approximately similar dyn behaviors
    ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
                                                                         tire_stiffness_factor=tire_stiffness_factor)

    # no rear steering, at least on the listed cars above
    ret.steerRatioRear = 0.
    ret.steerControlType = car.CarParams.SteerControlType.torque

    ret.longitudinalTuning.kpBP = [0., 10., 40.]
    ret.longitudinalTuning.kpV = [1.2, 0.6, 0.2]
    ret.longitudinalTuning.kiBP = [0., 10., 30., 40.]
    ret.longitudinalTuning.kiV = [0.05, 0.02, 0.01, 0.005]
    ret.longitudinalTuning.deadzoneBP = [0., 40]
    ret.longitudinalTuning.deadzoneV = [0., 0.02]


    # steer, gas, brake limitations VS speed

    ret.gasMaxBP = [0., 10., 40.]
    ret.gasMaxV = [0.5, 0.5, 0.5]
    ret.brakeMaxBP = [0., 20.]
    ret.brakeMaxV = [1., 0.8]

    ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS, ECU_FINGERPRINT, candidate, Ecu.fwdCamera) or has_relay

    ret.stoppingControl = True
    ret.startAccel = 0.0

    # ignore CAN2 address if L-CAN on the same BUS
    ret.mdpsBus = 1 if 593 in fingerprint[1] and 1296 not in fingerprint[1] else 0
    ret.sasBus = 1 if 688 in fingerprint[1] and 1296 not in fingerprint[1] else 0
    ret.sccBus = 0 if 1056 in fingerprint[0] else 1 if 1056 in fingerprint[1] and 1296 not in fingerprint[1] \
                                                                     else 2 if 1056 in fingerprint[2] else -1
    ret.radarOffCan = ret.sccBus == -1
    ret.openpilotLongitudinalControl = Params().get('LongControlEnabled') == b'1'
    ret.enableCruise = not ret.radarOffCan
    ret.spasEnabled = False
    
    # set safety_hyundai_community only for non-SCC, MDPS harrness or SCC harrness cars or cars that have unknown issue
    if ret.radarOffCan or ret.mdpsBus == 1 or ret.openpilotLongitudinalControl or ret.sccBus == 1 or Params().get('MadModeEnabled') == b'1':
      ret.safetyModel = car.CarParams.SafetyModel.hyundaiCommunity
    return ret
Esempio n. 27
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   has_relay=False,
                   car_fw=[]):  # pylint: disable=dangerous-default-value
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint,
                                              has_relay)

        ret.carName = "hyundai"
        ret.safetyModel = car.CarParams.SafetyModel.hyundaiLegacy
        if candidate in [CAR.SONATA]:
            ret.safetyModel = car.CarParams.SafetyModel.hyundai

        # Most Hyundai car ports are community features for now
        ret.communityFeature = candidate not in [CAR.SONATA, CAR.PALISADE]

        ret.steerActuatorDelay = 0.1  # Default delay
        ret.steerRateCost = 0.5
        ret.steerLimitTimer = 0.8
        tire_stiffness_factor = 1.

        # genesis
        if candidate == CAR.GENESIS:
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate == CAR.GENESIS_G70:
            ret.mass = 1640. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate == CAR.GENESIS_G80:
            ret.mass = 2060. + STD_CARGO_KG
            ret.wheelbase = 3.01
            ret.steerRatio = 16.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        elif candidate == CAR.GENESIS_G90:
            ret.mass = 2200
            ret.wheelbase = 3.15
            ret.steerRatio = 12.069
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16],
                                                                    [0.01]]
        # hyundai
        elif candidate in [CAR.SANTA_FE]:
            ret.mass = 1694 + STD_CARGO_KG
            ret.wheelbase = 2.766
            ret.steerRatio = 13.8 * 1.15  # 13.8 is spec end-to-end
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.SONATA, CAR.SONATA_HEV]:
            ret.mass = 1513. + STD_CARGO_KG
            ret.wheelbase = 2.84
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            tire_stiffness_factor = 0.65
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.SONATA19, CAR.SONATA19_HEV]:
            ret.mass = 4497. * CV.LB_TO_KG
            ret.wheelbase = 2.804
            ret.steerRatio = 13.27 * 1.15  # 15% higher at the center seems reasonable
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.PALISADE:
            ret.mass = 1999. + STD_CARGO_KG
            ret.wheelbase = 2.90
            ret.steerRatio = 13.75 * 1.15
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.ELANTRA, CAR.ELANTRA_GT_I30]:
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 15.4  # 14 is Stock | Settled Params Learner values are steerRatio: 15.401566348670535
            tire_stiffness_factor = 0.385  # stiffnessFactor settled on 1.0081302973865127
            ret.lateralTuning.pid.kf = 0.00006
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.KONA:
            ret.mass = 1275. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73 * 1.15  # Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.KONA_HEV, CAR.KONA_EV]:
            ret.mass = 1685. + STD_CARGO_KG
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kf = 0.00006
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.IONIQ_EV, CAR.IONIQ_HEV]:
            ret.mass = 1490. + STD_CARGO_KG  #weight per hyundai site https://www.hyundaiusa.com/ioniq-electric/specifications.aspx
            ret.wheelbase = 2.7
            ret.steerRatio = 13.73  #Spec
            tire_stiffness_factor = 0.385
            ret.lateralTuning.pid.kf = 0.00006
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.GRANDEUR, CAR.GRANDEUR_HEV]:
            ret.mass = 1719. + STD_CARGO_KG
            ret.wheelbase = 2.8
            ret.steerRatio = 12.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.VELOSTER:
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75 * 1.15
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        # kia
        elif candidate == CAR.SORENTO:
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.1  # 10% higher at the center seems reasonable
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.OPTIMA, CAR.OPTIMA_HEV]:
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.STINGER:
            ret.lateralTuning.init('indi')
            ret.lateralTuning.indi.innerLoopGain = 3.0
            ret.lateralTuning.indi.outerLoopGain = 2.0
            ret.lateralTuning.indi.timeConstant = 1.0
            ret.lateralTuning.indi.actuatorEffectiveness = 1.5
            ret.steerActuatorDelay = 0.08  # Stinger GT Limited AWD 3.3T stock value (Tunder's 2020)
            ret.steerLimitTimer = 0.4  # stock is 0.01 but 0.04 seems to work well
            tire_stiffness_factor = 1.125  # LiveParameters (Tunder's 2020)
            ret.steerRateCost = 1.0
            ret.mass = 1825.0 + STD_CARGO_KG
            ret.wheelbase = 2.906  # https://www.kia.com/us/en/stinger/specs
            ret.steerRatio = 13.56  # 10.28 measured by wheel alignment machine/reported steering angle by OP. 2020 GT Limited AWD has a variable steering ratio ultimately ending in 10.28.  13.56 after 1200km in LiveParamaters (Tunder)
        elif candidate == CAR.FORTE:
            ret.mass = 3558. * CV.LB_TO_KG
            ret.wheelbase = 2.80
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.CEED:
            ret.mass = 1350. + STD_CARGO_KG
            ret.wheelbase = 2.65
            ret.steerRatio = 13.75
            tire_stiffness_factor = 0.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate == CAR.SPORTAGE:
            ret.mass = 1985. + STD_CARGO_KG
            ret.wheelbase = 2.78
            ret.steerRatio = 14.4 * 1.1  # 10% higher at the center seems reasonable
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]
        elif candidate in [CAR.NIRO_HEV, CAR.NIRO_EV]:
            if candidate == CAR.NIRO_EV:
                ret.lateralTuning.init('indi')
                ret.lateralTuning.indi.innerLoopGain = 5.5
                ret.lateralTuning.indi.outerLoopGain = 4.5
                ret.lateralTuning.indi.timeConstant = 1.0
                ret.lateralTuning.indi.actuatorEffectiveness = 1.76
                ret.steerRatio = 24
            else:
                ret.steerRatio = 13.73
                ret.lateralTuning.pid.kf = 0.00005
                ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                          [0.]]
                ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                        [0.05]]
            ret.mass = 1737. + STD_CARGO_KG
            ret.wheelbase = 2.7
            tire_stiffness_factor = 0.385
        elif candidate in [CAR.CADENZA, CAR.CADENZA_HEV]:
            ret.mass = 1575. + STD_CARGO_KG
            ret.wheelbase = 2.85
            ret.steerRatio = 12.5
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.],
                                                                      [0.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25],
                                                                    [0.05]]

        ret.centerToFront = ret.wheelbase * 0.4

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass,
            ret.wheelbase,
            ret.centerToFront,
            tire_stiffness_factor=tire_stiffness_factor)

        # no rear steering, at least on the listed cars above
        ret.steerRatioRear = 0.
        ret.steerControlType = car.CarParams.SteerControlType.torque

        ret.longitudinalTuning.kpBP = [0., 10., 40.]
        ret.longitudinalTuning.kpV = [1.2, 0.6, 0.2]
        ret.longitudinalTuning.kiBP = [0., 10., 30., 40.]
        ret.longitudinalTuning.kiV = [0.05, 0.02, 0.01, 0.005]
        ret.longitudinalTuning.deadzoneBP = [0., 40]
        ret.longitudinalTuning.deadzoneV = [0., 0.02]

        # steer, gas, brake limitations VS speed
        ret.steerMaxBP = [0.]
        ret.steerMaxV = [1.0]
        ret.gasMaxBP = [0., 10., 40.]
        ret.gasMaxV = [0.5, 0.5, 0.5]
        ret.brakeMaxBP = [0., 20.]
        ret.brakeMaxV = [1., 0.8]

        ret.enableCamera = is_ecu_disconnected(fingerprint[0], FINGERPRINTS,
                                               ECU_FINGERPRINT, candidate,
                                               Ecu.fwdCamera) or has_relay

        ret.stoppingControl = True
        ret.startAccel = 0.0

        # ignore CAN2 address if L-CAN on the same BUS
        ret.mdpsBus = 1 if 593 in fingerprint[1] and 1296 not in fingerprint[
            1] else 0
        ret.sasBus = 1 if 688 in fingerprint[1] and 1296 not in fingerprint[
            1] else 0
        ret.sccBus = 0 if 1056 in fingerprint[0] else 1 if 1056 in fingerprint[1] and 1296 not in fingerprint[1] \
                                                                         else 2 if 1056 in fingerprint[2] else -1
        ret.radarOffCan = ret.sccBus == -1
        ret.openpilotLongitudinalControl = Params().get(
            'LongControlEnabled') == b'1'
        ret.enableCruise = not ret.radarOffCan
        ret.spasEnabled = False

        # set safety_hyundai_community only for non-SCC, MDPS harrness or SCC harrness cars or cars that have unknown issue
        if ret.radarOffCan or ret.mdpsBus == 1 or ret.openpilotLongitudinalControl or ret.sccBus == 1 or Params(
        ).get('MadModeEnabled') == b'1':
            ret.safetyModel = car.CarParams.SafetyModel.hyundaiCommunity
        return ret
Esempio n. 28
0
def fingerprint(logcan, sendcan):
  dp_car_assigned = Params().get('dp_car_assigned', encoding='utf8')
  fixed_fingerprint = os.environ.get('FINGERPRINT', "" if dp_car_assigned is None else dp_car_assigned)
  skip_fw_query = os.environ.get('SKIP_FW_QUERY', False)

  if not fixed_fingerprint and not skip_fw_query:
    # Vin query only reliably works thorugh OBDII
    bus = 1

    cached_params = Params().get("CarParamsCache")
    if cached_params is not None:
      cached_params = car.CarParams.from_bytes(cached_params)
      if cached_params.carName == "mock":
        cached_params = None

    if cached_params is not None and len(cached_params.carFw) > 0 and cached_params.carVin is not VIN_UNKNOWN:
      cloudlog.warning("Using cached CarParams")
      vin = cached_params.carVin
      car_fw = list(cached_params.carFw)
    else:
      cloudlog.warning("Getting VIN & FW versions")
      _, vin = get_vin(logcan, sendcan, bus)
      car_fw = get_fw_versions(logcan, sendcan, bus)

    exact_fw_match, fw_candidates = match_fw_to_car(car_fw)
  else:
    vin = VIN_UNKNOWN
    exact_fw_match, fw_candidates, car_fw = True, set(), []

  cloudlog.warning("VIN %s", vin)
  Params().put("CarVin", vin)

  finger = gen_empty_fingerprint()
  candidate_cars = {i: all_legacy_fingerprint_cars() for i in [0, 1]}  # attempt fingerprint on both bus 0 and 1
  frame = 0
  frame_fingerprint = 10  # 0.1s
  car_fingerprint = None
  done = False

  while not done:
    a = get_one_can(logcan)

    for can in a.can:
      # need to independently try to fingerprint both bus 0 and 1 to work
      # for the combo black_panda and honda_bosch. Ignore extended messages
      # and VIN query response.
      # Include bus 2 for toyotas to disambiguate cars using camera messages
      # (ideally should be done for all cars but we can't for Honda Bosch)
      if can.src in range(0, 4):
        finger[can.src][can.address] = len(can.dat)
      for b in candidate_cars:
        if (can.src == b or (only_toyota_left(candidate_cars[b]) and can.src == 2)) and \
           can.address < 0x800 and can.address not in [0x7df, 0x7e0, 0x7e8]:
          candidate_cars[b] = eliminate_incompatible_cars(can, candidate_cars[b])

    # if we only have one car choice and the time since we got our first
    # message has elapsed, exit
    for b in candidate_cars:
      # Toyota needs higher time to fingerprint, since DSU does not broadcast immediately
      if only_toyota_left(candidate_cars[b]):
        frame_fingerprint = 100  # 1s
      if len(candidate_cars[b]) == 1 and frame > frame_fingerprint:
          # fingerprint done
          car_fingerprint = candidate_cars[b][0]

    # bail if no cars left or we've been waiting for more than 2s
    failed = (all(len(cc) == 0 for cc in candidate_cars.values()) and frame > frame_fingerprint) or frame > 200
    succeeded = car_fingerprint is not None
    done = failed or succeeded

    frame += 1

  exact_match = True
  source = car.CarParams.FingerprintSource.can

  # If FW query returns exactly 1 candidate, use it
  if len(fw_candidates) == 1:
    car_fingerprint = list(fw_candidates)[0]
    source = car.CarParams.FingerprintSource.fw
    exact_match = exact_fw_match

  if fixed_fingerprint:
    car_fingerprint = fixed_fingerprint
    source = car.CarParams.FingerprintSource.fixed

  cloudlog.event("fingerprinted", car_fingerprint=car_fingerprint,
                 source=source, fuzzy=not exact_match, fw_count=len(car_fw))
  return car_fingerprint, finger, vin, car_fw, source, exact_match
Esempio n. 29
0
    def get_params(candidate,
                   fingerprint=gen_empty_fingerprint(),
                   car_fw=None,
                   disable_radar=False):
        ret = CarInterfaceBase.get_std_params(candidate, fingerprint)

        ret.carName = "subaru"
        ret.radarOffCan = True

        if candidate in PREGLOBAL_CARS:
            ret.safetyConfigs = [
                get_safety_config(car.CarParams.SafetyModel.subaruLegacy)
            ]
            ret.enableBsm = 0x25c in fingerprint[0]
        else:
            ret.safetyConfigs = [
                get_safety_config(car.CarParams.SafetyModel.subaru)
            ]
            ret.enableBsm = 0x228 in fingerprint[0]

        ret.dashcamOnly = candidate in PREGLOBAL_CARS

        ret.steerRateCost = 0.7
        ret.steerLimitTimer = 0.4

        if candidate == CAR.ASCENT:
            ret.mass = 2031. + STD_CARGO_KG
            ret.wheelbase = 2.89
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 13.5
            ret.steerActuatorDelay = 0.3  # end-to-end angle controller
            ret.lateralTuning.pid.kf = 0.00003
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                0., 20.
            ], [0., 20.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.0025, 0.1
            ], [0.00025, 0.01]]

        if candidate == CAR.IMPREZA:
            ret.mass = 1568. + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 15
            ret.steerActuatorDelay = 0.4  # end-to-end angle controller
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                0., 20.
            ], [0., 20.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2, 0.3],
                                                                    [
                                                                        0.02,
                                                                        0.03
                                                                    ]]

        if candidate == CAR.IMPREZA_2020:
            ret.mass = 1480. + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 17  # learned, 14 stock
            ret.steerActuatorDelay = 0.1
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                0., 14., 23.
            ], [0., 14., 23.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.045, 0.042, 0.20
            ], [0.04, 0.035, 0.045]]

        if candidate == CAR.FORESTER:
            ret.mass = 1568. + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 17  # learned, 14 stock
            ret.steerActuatorDelay = 0.1
            ret.lateralTuning.pid.kf = 0.000038
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                0., 14., 23.
            ], [0., 14., 23.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.01, 0.065, 0.2
            ], [0.001, 0.015, 0.025]]

        if candidate in (CAR.FORESTER_PREGLOBAL, CAR.OUTBACK_PREGLOBAL_2018):
            ret.safetyConfigs[
                0].safetyParam = 1  # Outback 2018-2019 and Forester have reversed driver torque signal
            ret.mass = 1568 + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 20  # learned, 14 stock
            ret.steerActuatorDelay = 0.1
            ret.lateralTuning.pid.kf = 0.000039
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                0., 10., 20.
            ], [0., 10., 20.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.01, 0.05, 0.2
            ], [0.003, 0.018, 0.025]]

        if candidate == CAR.LEGACY_PREGLOBAL:
            ret.mass = 1568 + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 12.5  # 14.5 stock
            ret.steerActuatorDelay = 0.15
            ret.lateralTuning.pid.kf = 0.00005
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                0., 20.
            ], [0., 20.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.1, 0.2],
                                                                    [
                                                                        0.01,
                                                                        0.02
                                                                    ]]

        if candidate == CAR.OUTBACK_PREGLOBAL:
            ret.mass = 1568 + STD_CARGO_KG
            ret.wheelbase = 2.67
            ret.centerToFront = ret.wheelbase * 0.5
            ret.steerRatio = 20  # learned, 14 stock
            ret.steerActuatorDelay = 0.1
            ret.lateralTuning.pid.kf = 0.000039
            ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[
                0., 10., 20.
            ], [0., 10., 20.]]
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.01, 0.05, 0.2
            ], [0.003, 0.018, 0.025]]

        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)

        # TODO: start from empirically derived lateral slip stiffness for the civic and scale by
        # mass and CG position, so all cars will have approximately similar dyn behaviors
        ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(
            ret.mass, ret.wheelbase, ret.centerToFront)

        return ret
Esempio n. 30
0
def fingerprint(logcan, sendcan, has_relay):
    params = Params()
    car_params = params.get("CarParams")

    if not travis:
        cached_fingerprint = params.get('CachedFingerprint')
    else:
        cached_fingerprint = None

    if car_params is not None:
        car_params = car.CarParams.from_bytes(car_params)
    if has_relay:
        # Vin query only reliably works thorugh OBDII
        bus = 1

        cached_params = Params().get("CarParamsCache")
        if cached_params is not None:
            cached_params = car.CarParams.from_bytes(cached_params)
            if cached_params.carName == "mock":
                cached_params = None

        if cached_params is not None and len(
                cached_params.carFw
        ) > 0 and cached_params.carVin is not VIN_UNKNOWN:
            cloudlog.warning("Using cached CarParams")
            vin = cached_params.carVin
            car_fw = list(cached_params.carFw)
        else:
            cloudlog.warning("Getting VIN & FW versions")
            _, vin = get_vin(logcan, sendcan, bus)
            car_fw = get_fw_versions(logcan, sendcan, bus)

        fw_candidates = match_fw_to_car(car_fw)
    else:
        vin = VIN_UNKNOWN
        fw_candidates, car_fw = set(), []

    cloudlog.warning("VIN %s", vin)
    Params().put("CarVin", vin)

    finger = gen_empty_fingerprint()
    candidate_cars = {i: all_known_cars()
                      for i in [0, 1]
                      }  # attempt fingerprint on both bus 0 and 1
    frame = 0
    frame_fingerprint = 10  # 0.1s
    car_fingerprint = None
    done = False

    if cached_fingerprint is not None and use_car_caching:  # if we previously identified a car and fingerprint and user hasn't disabled caching
        cached_fingerprint = json.loads(cached_fingerprint)
        if cached_fingerprint[0] is None or len(cached_fingerprint) < 3:
            params.delete('CachedFingerprint')
        else:
            finger[0] = {
                int(key): value
                for key, value in cached_fingerprint[2].items()
            }
            source = car.CarParams.FingerprintSource.can
            return (str(cached_fingerprint[0]), finger, vin, car_fw,
                    cached_fingerprint[1])

    while not done:
        a = messaging.get_one_can(logcan)

        for can in a.can:
            # need to independently try to fingerprint both bus 0 and 1 to work
            # for the combo black_panda and honda_bosch. Ignore extended messages
            # and VIN query response.
            # Include bus 2 for toyotas to disambiguate cars using camera messages
            # (ideally should be done for all cars but we can't for Honda Bosch)
            if can.src in range(0, 4):
                finger[can.src][can.address] = len(can.dat)
            for b in candidate_cars:
                if (can.src == b or (only_toyota_left(candidate_cars[b]) and can.src == 2)) and \
                   can.address < 0x800 and can.address not in [0x7df, 0x7e0, 0x7e8]:
                    candidate_cars[b] = eliminate_incompatible_cars(
                        can, candidate_cars[b])

        # if we only have one car choice and the time since we got our first
        # message has elapsed, exit
        for b in candidate_cars:
            # Toyota needs higher time to fingerprint, since DSU does not broadcast immediately
            if only_toyota_left(candidate_cars[b]):
                frame_fingerprint = 100  # 1s
            if len(candidate_cars[b]) == 1:
                if frame > frame_fingerprint:
                    # fingerprint done
                    car_fingerprint = candidate_cars[b][0]
            elif len(
                    candidate_cars[b]
            ) < 4:  # For the RAV4 2019 and Corolla 2020 LE Fingerprint problem
                if frame > 180:
                    if any(("TOYOTA COROLLA TSS2 2019" in c)
                           for c in candidate_cars[b]):
                        car_fingerprint = "TOYOTA COROLLA TSS2 2019"
                    if any(("TOYOTA COROLLA HYBRID TSS2 2019" in c)
                           for c in candidate_cars[b]):
                        car_fingerprint = "TOYOTA COROLLA HYBRID TSS2 2019"

        # bail if no cars left or we've been waiting for more than 2s
        failed = all(len(cc) == 0
                     for cc in candidate_cars.values()) or frame > 200
        succeeded = car_fingerprint is not None
        done = failed or succeeded

        frame += 1

    source = car.CarParams.FingerprintSource.can

    # If FW query returns exactly 1 candidate, use it
    if len(fw_candidates) == 1:
        car_fingerprint = list(fw_candidates)[0]
        source = car.CarParams.FingerprintSource.fw

    fixed_fingerprint = os.environ.get('FINGERPRINT', "")
    if len(fixed_fingerprint):
        car_fingerprint = fixed_fingerprint
        source = car.CarParams.FingerprintSource.fixed

    cloudlog.warning("fingerprinted %s", car_fingerprint)
    params.put(
        "CachedFingerprint",
        json.dumps([
            car_fingerprint, source,
            {int(key): value
             for key, value in finger[0].items()}
        ]))
    return car_fingerprint, finger, vin, car_fw, source