Exemplo n.º 1
0
def get_car(logcan, sendcan, is_panda_black=False):
    cloudlog.warn("CarParams get_car is loading")
    candidate = "MITSUBISHI MIEV"
    vin = "xxxxxxxxxxxx"
    car_params = CarInterface.get_params(None)
    cloudlog.warn("CarParams is loading %s" % candidate)
    return CarInterface(car_params, CarController), car_params
def can_init():
    global handle, context
    handle = None
    cloudlog.info("attempting can init")

    context = usb1.USBContext()
    #context.setDebug(9)

    for device in context.getDeviceList(skip_on_error=True):
        if device.getVendorID() == 0xbbaa and device.getProductID() == 0xddcc:
            handle = device.open()
            handle.claimInterface(0)
            handle.controlWrite(0x40, 0xdc, SAFETY_ALLOUTPUT, 0, b'')

    if handle is None:
        cloudlog.warn("CAN NOT FOUND")
        exit(-1)

    cloudlog.info("got handle")
    cloudlog.info("can init done")
Exemplo n.º 3
0
    def get_params(candidate, fingerprint, vin=""):

        ret = car.CarParams.new_message()

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

        ret.safetyModel = car.CarParams.SafetyModel.toyota

        # pedal
        ret.enableCruise = not ret.enableGasInterceptor

        ret.steerActuatorDelay = 0.12  # Default delay, Prius has larger delay
        if candidate != CAR.PRIUS:
            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.00  # 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

            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.30  # 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.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6],
                                                                    [0.05]]
            ret.lateralTuning.pid.kf = 0.00006  # full torque for 10 deg at 80mph means 0.00007818594

        elif candidate == CAR.COROLLA:
            stop_and_go = False
            ret.safetyParam = 100
            ret.wheelbase = 2.70
            ret.steerRatio = 17.8
            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 == CAR.COROLLA_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 == 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

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

        #detect the Pedal address
        ret.enableGasInterceptor = 0x201 in fingerprint

        # 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

        # 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 = not check_ecu_msgs(fingerprint, ECU.CAM)
        ret.enableDsu = not check_ecu_msgs(fingerprint, ECU.DSU)
        ret.enableApgs = False  #not check_ecu_msgs(fingerprint, ECU.APGS)
        ret.openpilotLongitudinalControl = ret.enableCamera and ret.enableDsu
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warn("ECU DSU Simulated: %r", ret.enableDsu)
        cloudlog.warn("ECU APGS Simulated: %r", ret.enableApgs)
        cloudlog.warn("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

        ret.steerLimitAlert = False

        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
Exemplo n.º 4
0
    def get_params(candidate, fingerprint):

        # kg of standard extra cargo to count for drive, gas, etc...
        std_cargo = 136

        ret = car.CarParams.new_message()

        ret.carName = "toyota"
        ret.carFingerprint = candidate

        ret.safetyModel = car.CarParams.SafetyModels.toyota

        # pedal
        ret.enableCruise = not ret.enableGasInterceptor

        # FIXME: hardcoding honda civic 2016 touring params so they can be used to
        # scale unknown params for other cars
        mass_civic = 2923 * CV.LB_TO_KG + std_cargo
        wheelbase_civic = 2.70
        centerToFront_civic = wheelbase_civic * 0.4
        centerToRear_civic = wheelbase_civic - centerToFront_civic
        rotationalInertia_civic = 2500
        tireStiffnessFront_civic = 192150
        tireStiffnessRear_civic = 202500

        ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
        ret.steerActuatorDelay = 0.12  # Default delay, Prius has larger delay

        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.00  # unknown end-to-end spec
            tire_stiffness_factor = 0.6371  # hand-tune
            ret.mass = 3045 * CV.LB_TO_KG + std_cargo
            ret.steerKpV, ret.steerKiV = [[0.4], [0.01]]
            ret.steerKf = 0.00006  # full torque for 10 deg at 80mph means 0.00007818594
            # TODO: Prius seem to have very laggy actuators. Understand if it is lag or hysteresis
            ret.steerActuatorDelay = 0.25

        elif candidate in [CAR.RAV4, CAR.RAV4H]:
            stop_and_go = True if (candidate in CAR.RAV4H) else False
            ret.safetyParam = 73  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.65
            ret.steerRatio = 16.30  # 14.5 is spec end-to-end
            tire_stiffness_factor = 0.5533
            ret.mass = 3650 * CV.LB_TO_KG + std_cargo  # mean between normal and hybrid
            ret.steerKpV, ret.steerKiV = [[0.6], [0.05]]
            ret.steerKf = 0.00006  # full torque for 10 deg at 80mph means 0.00007818594

        elif candidate == CAR.COROLLA:
            stop_and_go = False
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.70
            ret.steerRatio = 17.8
            tire_stiffness_factor = 0.444
            ret.mass = 2860 * CV.LB_TO_KG + std_cargo  # mean between normal and hybrid
            ret.steerKpV, ret.steerKiV = [[0.2], [0.05]]
            ret.steerKf = 0.00003  # full torque for 20 deg at 80mph means 0.00007818594

        elif candidate == CAR.LEXUS_RXH:
            stop_and_go = True
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            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  # mean between min and max
            ret.steerKpV, ret.steerKiV = [[0.6], [0.1]]
            ret.steerKf = 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 = 100
            ret.wheelbase = 2.63906
            ret.steerRatio = 13.6
            tire_stiffness_factor = 0.7933
            ret.mass = 3300. * CV.LB_TO_KG + std_cargo
            ret.steerKpV, ret.steerKiV = [[0.723], [0.0428]]
            ret.steerKf = 0.00006

        elif candidate in [CAR.CAMRY, CAR.CAMRYH]:
            stop_and_go = True
            ret.safetyParam = 100
            ret.wheelbase = 2.82448
            ret.steerRatio = 13.7
            tire_stiffness_factor = 0.7933
            ret.mass = 3400 * CV.LB_TO_KG + std_cargo  #mean between normal and hybrid
            ret.steerKpV, ret.steerKiV = [[0.6], [0.1]]
            ret.steerKf = 0.00006

        elif candidate in [CAR.HIGHLANDER, CAR.HIGHLANDERH]:
            stop_and_go = True
            ret.safetyParam = 100
            ret.wheelbase = 2.78
            ret.steerRatio = 16.0
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 4607 * CV.LB_TO_KG + std_cargo  #mean between normal and hybrid limited
            ret.steerKpV, ret.steerKiV = [[0.6], [0.05]]
            ret.steerKf = 0.00006

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

        ret.longPidDeadzoneBP = [0., 9.]
        ret.longPidDeadzoneV = [0., .15]

        #detect the Pedal address
        ret.enableGasInterceptor = 0x201 in fingerprint

        # 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

        centerToRear = ret.wheelbase - ret.centerToFront
        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = rotationalInertia_civic * \
                                ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2)

        # 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 = (tireStiffnessFront_civic * tire_stiffness_factor) * \
                                 ret.mass / mass_civic * \
                                 (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic)
        ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \
                                ret.mass / mass_civic * \
                                (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic)

        # 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 = [5., 20.]
        ret.brakeMaxV = [1., 0.8]

        ret.enableCamera = not check_ecu_msgs(fingerprint, ECU.CAM)
        ret.enableDsu = not check_ecu_msgs(fingerprint, ECU.DSU)
        ret.enableApgs = False  #not check_ecu_msgs(fingerprint, ECU.APGS)
        ret.openpilotLongitudinalControl = ret.enableCamera and ret.enableDsu
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warn("ECU DSU Simulated: %r", ret.enableDsu)
        cloudlog.warn("ECU APGS Simulated: %r", ret.enableApgs)
        cloudlog.warn("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

        ret.steerLimitAlert = False
        ret.longitudinalKpBP = [0., 5., 35.]
        ret.longitudinalKiBP = [0., 35.]
        ret.stoppingControl = False

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

        return ret
Exemplo n.º 5
0
    def get_params(candidate, fingerprint):

        # kg of standard extra cargo to count for drive, gas, etc...
        std_cargo = 136

        ret = car.CarParams.new_message()

        ret.carName = "ford"
        ret.carFingerprint = candidate

        ret.safetyModel = car.CarParams.SafetyModels.ford

        # pedal
        ret.enableCruise = True

        # FIXME: hardcoding honda civic 2016 touring params so they can be used to
        # scale unknown params for other cars
        mass_civic = 2923. * CV.LB_TO_KG + std_cargo
        wheelbase_civic = 2.70
        centerToFront_civic = wheelbase_civic * 0.4
        centerToRear_civic = wheelbase_civic - centerToFront_civic
        rotationalInertia_civic = 2500
        tireStiffnessFront_civic = 85400
        tireStiffnessRear_civic = 90000

        ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
        ret.wheelbase = 2.85
        ret.steerRatio = 14.8
        ret.mass = 3045. * CV.LB_TO_KG + std_cargo
        ret.steerKpV, ret.steerKiV = [[0.01], [0.005]]  # TODO: tune this
        ret.steerKf = 1. / MAX_ANGLE  # MAX Steer angle to normalize FF
        ret.steerActuatorDelay = 0.1  # Default delay, not measured yet
        ret.steerRateCost = 1.0

        f = 1.2
        tireStiffnessFront_civic *= f
        tireStiffnessRear_civic *= f

        ret.centerToFront = ret.wheelbase * 0.44

        ret.longPidDeadzoneBP = [0., 9.]
        ret.longPidDeadzoneV = [0., .15]

        # 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.

        centerToRear = ret.wheelbase - ret.centerToFront
        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = rotationalInertia_civic * \
                                ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2)

        # 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 = tireStiffnessFront_civic * \
                                 ret.mass / mass_civic * \
                                 (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic)
        ret.tireStiffnessRear = tireStiffnessRear_civic * \
                                ret.mass / mass_civic * \
                                (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic)

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

        # steer, gas, brake limitations VS speed
        ret.steerMaxBP = [0.]  # breakpoints at 1 and 40 kph
        ret.steerMaxV = [1.0]  # 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 = not any(
            x for x in [970, 973, 984] if x in fingerprint)
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)

        ret.steerLimitAlert = False
        ret.stoppingControl = False
        ret.startAccel = 0.0

        ret.longitudinalKpBP = [0., 5., 35.]
        ret.longitudinalKpV = [3.6, 2.4, 1.5]
        ret.longitudinalKiBP = [0., 35.]
        ret.longitudinalKiV = [0.54, 0.36]

        return ret
Exemplo n.º 6
0
    def get_params(candidate, fingerprint, vin="", is_panda_black=False):

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

        if candidate in HONDA_BOSCH:
            ret.safetyModel = car.CarParams.SafetyModel.hondaBosch
            ret.enableCamera = True
            ret.radarOffCan = True
            ret.openpilotLongitudinalControl = not any(
                x for x in BOSCH_RADAR_MSGS if x in fingerprint)
            ret.enableCruise = not ret.openpilotLongitudinalControl
        else:
            ret.safetyModel = car.CarParams.SafetyModel.honda
            ret.enableCamera = not any(
                x for x in CAMERA_MSGS if x in fingerprint) or is_panda_black
            ret.enableGasInterceptor = 0x201 in fingerprint
            ret.openpilotLongitudinalControl = ret.enableCamera
            ret.enableCruise = not ret.enableGasInterceptor

        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warn("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.
            # Civic at comma has modified steering FW, so different tuning for the Neo in that car
            is_fw_modified = os.getenv("DONGLE_ID") in ['5b7c365c50084530']
            if is_fw_modified:
                ret.lateralTuning.pid.kf = 0.00004

            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.4
            ], [0.12]] if is_fw_modified else [[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.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
        # TODO: what is the correct way to handle this?
        ret.gasMaxV = [
            1.
        ]  #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
Exemplo n.º 7
0
    def get_params(candidate, fingerprint, vin="", is_panda_black=False):

        ret = car.CarParams.new_message()

        ret.carName = "ford"
        ret.carFingerprint = candidate
        ret.carVin = vin
        ret.isPandaBlack = is_panda_black

        ret.safetyModel = car.CarParams.SafetyModel.ford

        # pedal
        ret.enableCruise = True

        ret.wheelbase = 2.85
        ret.steerRatio = 14.8
        ret.mass = 3045. * CV.LB_TO_KG + STD_CARGO_KG
        ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
        ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.01], [
            0.005
        ]]  # TODO: tune this
        ret.lateralTuning.pid.kf = 1. / MAX_ANGLE  # MAX Steer angle to normalize FF
        ret.steerActuatorDelay = 0.1  # Default delay, not measured yet
        ret.steerRateCost = 1.0
        ret.centerToFront = ret.wheelbase * 0.44
        tire_stiffness_factor = 0.5328

        # 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.

        # 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.angle

        # steer, gas, brake limitations VS speed
        ret.steerMaxBP = [0.]  # breakpoints at 1 and 40 kph
        ret.steerMaxV = [1.0]  # 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 = not any(
            x for x in [970, 973, 984] if x in fingerprint) or is_panda_black
        ret.openpilotLongitudinalControl = False
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)

        ret.steerLimitAlert = 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
Exemplo n.º 8
0
   def get_params(candidate, fingerprint=gen_empty_fingerprint(), vin="", has_relay=False):
    print("CarParams new message")
    ret = car.CarParams.new_message()
    print("CarParams setting fingerprint and safety")
    ret.carName = "mitsubishi"
    ret.carFingerprint = candidate
    ret.carVin = vin
    ret.isPandaBlack = False
    
    ret.safetyModel = car.CarParams.SafetyModel.toyota
    print("CarParams done settng safety model")
    # # pedal
    ret.enableCruise = True #not ret.enableGasInterceptor

    print("CarParams setting car tuning")
 
    ret.steerActuatorDelay = 0.1  # Default delay
    ret.lateralTuning.init('pid')   
    ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]]
    
    print("CarParams set up PID") 
    
    stop_and_go = True
    ret.safetyParam = 100
    ret.wheelbase = 2.55
    ret.steerRatio = 17.
    tire_stiffness_factor = 0.444
    ret.mass = 1080. + STD_CARGO_KG
    ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.01], [0.005]]
    ret.lateralTuning.pid.kf = 0.001388889 # 1 / max angle
    
    print("CarParams done setting tuning")
    
    ret.steerRateCost = 1.0
    print("CarParams steerRateCost set") #% ret.steerRateCost
    ret.centerToFront = ret.wheelbase * 0.44
    print("CarParams centerToFront set") #% ret.centerToFront
    ret.enableGasInterceptor = True
    print("CarParams enableGasInterceptor set to True")

    ret.minEnableSpeed = -1.
    print("CarParams done setting ratecost and min enable speed")

    ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)
    ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront,
                                                                         tire_stiffness_factor=tire_stiffness_factor)
    ret.steerRatioRear = 0.
    ret.steerControlType = car.CarParams.SteerControlType.angle

    # 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 = True #not check_ecu_msgs(fingerprint, ECU.CAM) or is_panda_black
    ret.enableDsu = True #not check_ecu_msgs(fingerprint, ECU.DSU)
    ret.enableApgs = False #not check_ecu_msgs(fingerprint, ECU.APGS)
    ret.openpilotLongitudinalControl = True #ret.enableCamera and ret.enableDsu
    cloudlog.warn("CarParams ECU DSU Simulated: %r", ret.enableDsu)

    ret.steerLimitAlert = False

    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

    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]
    return ret
Exemplo n.º 9
0
    def get_params(candidate, fingerprint):

        ret = car.CarParams.new_message()
        ret.carName = "honda"
        ret.carFingerprint = candidate

        if candidate in HONDA_BOSCH:
            ret.safetyModel = car.CarParams.SafetyModels.hondaBosch
            ret.enableCamera = True
            ret.radarOffCan = True
        else:
            ret.safetyModel = car.CarParams.SafetyModels.honda
            ret.enableCamera = not any(
                x for x in CAMERA_MSGS if x in fingerprint)
            ret.enableGasInterceptor = 0x201 in fingerprint
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warn("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

        ret.enableCruise = not ret.enableGasInterceptor

        # kg of standard extra cargo to count for drive, gas, etc...
        std_cargo = 136

        # FIXME: hardcoding honda civic 2016 touring params so they can be used to
        # scale unknown params for other cars
        mass_civic = 2923 * CV.LB_TO_KG + std_cargo
        wheelbase_civic = 2.70
        centerToFront_civic = wheelbase_civic * 0.4
        centerToRear_civic = wheelbase_civic - centerToFront_civic
        rotationalInertia_civic = 2500
        tireStiffnessFront_civic = 192150
        tireStiffnessRear_civic = 202500

        # 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.steerKiBP, ret.steerKpBP = [[0.], [0.]]

        ret.steerKf = 0.000078  # conservative feed-forward

        if candidate == CAR.CIVIC:
            stop_and_go = True
            ret.mass = mass_civic
            ret.wheelbase = wheelbase_civic
            ret.centerToFront = centerToFront_civic
            ret.steerRatio = 14.63  # 10.93 is end-to-end spec
            tire_stiffness_factor = 1.
            # Civic at comma has modified steering FW, so different tuning for the Neo in that car
            is_fw_modified = os.getenv("DONGLE_ID") in ['99c94dc769b5d96e']
            ret.steerKpV, ret.steerKiV = [[0.33], [0.10]
                                          ] if is_fw_modified else [[0.8],
                                                                    [0.24]]
            if is_fw_modified:
                ret.steerKf = 0.00003
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [3.6, 2.4, 1.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [0.54, 0.36]

        elif candidate == CAR.CIVIC_HATCH:
            stop_and_go = True
            ret.mass = 2916. * CV.LB_TO_KG + std_cargo
            ret.wheelbase = wheelbase_civic
            ret.centerToFront = centerToFront_civic
            ret.steerRatio = 14.63  # 10.93 is spec end-to-end
            tire_stiffness_factor = 1.
            ret.steerKpV, ret.steerKiV = [[0.8], [0.24]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [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 and CRV 5G use an alternate user brake msg
            ret.mass = 3279. * CV.LB_TO_KG + std_cargo
            ret.wheelbase = 2.83
            ret.centerToFront = ret.wheelbase * 0.39
            ret.steerRatio = 15.96  # 11.82 is spec end-to-end
            tire_stiffness_factor = 0.8467
            ret.steerKpV, ret.steerKiV = [[0.6], [0.18]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [0.18, 0.12]

        elif candidate == CAR.ACURA_ILX:
            stop_and_go = False
            ret.mass = 3095 * CV.LB_TO_KG + std_cargo
            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
            # Acura at comma has modified steering FW, so different tuning for the Neo in that car
            is_fw_modified = os.getenv("DONGLE_ID") in ['ff83f397542ab647']
            ret.steerKpV, ret.steerKiV = [[0.45], [0.00]
                                          ] if is_fw_modified else [[0.8],
                                                                    [0.24]]
            if is_fw_modified:
                ret.steerKf = 0.00003
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [0.18, 0.12]

        elif candidate == CAR.CRV:
            stop_and_go = False
            ret.mass = 3572 * CV.LB_TO_KG + std_cargo
            ret.wheelbase = 2.62
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 15.3  # as spec
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.steerKpV, ret.steerKiV = [[0.8], [0.24]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [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
            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.steerKpV, ret.steerKiV = [[0.6], [0.18]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [0.18, 0.12]

        elif candidate == CAR.ACURA_RDX:
            stop_and_go = False
            ret.mass = 3935 * CV.LB_TO_KG + std_cargo
            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.steerKpV, ret.steerKiV = [[0.8], [0.24]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [0.18, 0.12]

        elif candidate == CAR.ODYSSEY:
            stop_and_go = False
            ret.mass = 4471 * CV.LB_TO_KG + std_cargo
            ret.wheelbase = 3.00
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 14.35  # as spec
            tire_stiffness_factor = 0.82
            ret.steerKpV, ret.steerKiV = [[0.45], [0.135]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [0.18, 0.12]

        elif candidate in (CAR.PILOT, CAR.PILOT_2019):
            stop_and_go = False
            ret.mass = 4303 * CV.LB_TO_KG + std_cargo
            ret.wheelbase = 2.81
            ret.centerToFront = ret.wheelbase * 0.41
            ret.steerRatio = 16.0  # as spec
            tire_stiffness_factor = 0.82
            ret.steerKpV, ret.steerKiV = [[0.5], [0.22]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [0.18, 0.12]

        elif candidate == CAR.RIDGELINE:
            stop_and_go = False
            ret.mass = 4515 * CV.LB_TO_KG + std_cargo
            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.steerKpV, ret.steerKiV = [[0.38], [0.11]]
            ret.longitudinalKpBP = [0., 5., 35.]
            ret.longitudinalKpV = [1.2, 0.8, 0.5]
            ret.longitudinalKiBP = [0., 35.]
            ret.longitudinalKiV = [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

        centerToRear = ret.wheelbase - ret.centerToFront
        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = rotationalInertia_civic * \
                                ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2)

        # 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 = (tireStiffnessFront_civic * tire_stiffness_factor) * \
                                 ret.mass / mass_civic * \
                                 (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic)
        ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \
                                ret.mass / mass_civic * \
                                (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic)

        # 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.longPidDeadzoneBP = [0.]
        ret.longPidDeadzoneV = [0.]

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

        ret.steerActuatorDelay = 0.1
        ret.steerRateCost = 0.35

        return ret
Exemplo n.º 10
0
    def get_params(candidate, fingerprint):

        # kg of standard extra cargo to count for drive, gas, etc...
        std_cargo = 136

        ret = car.CarParams.new_message()

        ret.carName = "oldcar"
        ret.carFingerprint = candidate

        ret.safetyModel = car.CarParams.SafetyModels.toyota

        # pedal
        ret.enableCruise = True

        # FIXME: hardcoding honda civic 2016 touring params so they can be used to
        # scale unknown params for other cars
        mass_civic = 2923 * CV.LB_TO_KG + std_cargo
        wheelbase_civic = 2.70
        centerToFront_civic = wheelbase_civic * 0.4
        centerToRear_civic = wheelbase_civic - centerToFront_civic
        rotationalInertia_civic = 2500
        tireStiffnessFront_civic = 192150
        tireStiffnessRear_civic = 202500

        ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
        ret.steerActuatorDelay = 0.12  #0.16  # Default delay, Prius has larger delay

        if candidate == CAR.COROLLA:
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.70
            ret.steerRatio = 17.8
            tire_stiffness_factor = 0.444
            ret.mass = 2860 * CV.LB_TO_KG + std_cargo  # mean between normal and hybrid
            ret.steerKpV, ret.steerKiV = [[0.2], [0.05]]
            ret.steerKf = 0.00003  # full torque for 20 deg at 80mph means 0.00007818594

        elif candidate == CAR.CAMRYH:
            ret.safetyParam = 100
            ret.wheelbase = 2.77622
            ret.steerRatio = 18.0  #14.8
            tire_stiffness_factor = 0.7933
            ret.mass = 3400 * CV.LB_TO_KG + std_cargo  #mean between normal and hybrid
            ret.steerKpV, ret.steerKiV = [[0.6], [0.1]]
            ret.steerKf = 0.00006

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

        ret.longPidDeadzoneBP = [0., 9.]
        ret.longPidDeadzoneV = [0., .15]

        # 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.
        # hybrid models can't do stop and go even though the stock ACC can't
        if candidate in [CAR.CAMRYH]:
            ret.minEnableSpeed = -1.
        elif candidate in [CAR.COROLLA]:  # TODO: hack ICE to do stop and go
            ret.minEnableSpeed = 19. * CV.MPH_TO_MS

        centerToRear = ret.wheelbase - ret.centerToFront
        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = rotationalInertia_civic * \
                                ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2)

        # 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 = (tireStiffnessFront_civic * tire_stiffness_factor) * \
                                 ret.mass / mass_civic * \
                                 (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic)
        ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \
                                ret.mass / mass_civic * \
                                (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic)

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

        #Imported through tesla  no max steer limit VS speed
        ret.steerMaxBP = [0., 15.]  # m/s
        ret.steerMaxV = [420., 420.]  # max steer allowed

        # 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 = not check_ecu_msgs(fingerprint, ECU.CAM)
        ret.enableDsu = not check_ecu_msgs(fingerprint, ECU.DSU)
        ret.enableApgs = False  #not check_ecu_msgs(fingerprint, ECU.APGS)
        ret.openpilotLongitudinalControl = ret.enableCamera and ret.enableDsu
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warn("ECU DSU Simulated: %r", ret.enableDsu)
        cloudlog.warn("ECU APGS Simulated: %r", ret.enableApgs)

        ret.steerLimitAlert = False
        ret.stoppingControl = False
        ret.startAccel = 0.0

        ret.longitudinalKpBP = [0., 5., 35.]
        ret.longitudinalKpV = [3.6, 2.4, 1.5]
        ret.longitudinalKiBP = [0., 35.]
        ret.longitudinalKiV = [0.54, 0.36]

        return ret
Exemplo n.º 11
0
    # 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.gasMaxBP = [0.]
    ret.gasMaxV = [0.5]
    ret.brakeMaxBP = [5., 20.]
    ret.brakeMaxV = [1., 0.8]

    ret.enableCamera = not check_ecu_msgs(fingerprint, candidate, ECU.CAM)
    ret.enableDsu = not check_ecu_msgs(fingerprint, candidate, ECU.DSU)
    ret.enableApgs = False #not check_ecu_msgs(fingerprint, candidate, ECU.APGS)
    cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
    cloudlog.warn("ECU DSU Simulated: %r", ret.enableDsu)
    cloudlog.warn("ECU APGS Simulated: %r", ret.enableApgs)

    ret.steerLimitAlert = False
    ret.stoppingControl = False
    ret.startAccel = 0.0

    ret.longitudinalKpBP = [0., 5., 35.]
    ret.longitudinalKpV = [3.6, 2.4, 1.5]
    ret.longitudinalKiBP = [0., 35.]
    ret.longitudinalKiV = [0.54, 0.36]

    return ret

  # returns a car.CarState
Exemplo n.º 12
0
  def get_params(candidate, fingerprint):

    ret = car.CarParams.new_message()
    ret.carName = "hyundai"
    ret.carFingerprint = candidate

        #remove #radar off can from base

    ret.safetyModel = car.CarParams.SafetyModels.hyundai
     #ret.enableCamera = not any(x for x in CAMERA_MSGS if x in fingerprint)
    ret.enableCamera = not any(x for x in CAMERA_MSGS_SOUL if x in fingerprint)  #2018.09.02 johnwayneairobot change for KIA message
      #ret.enableGasInterceptor = 0x201 in fingerprint
    ret.enableGasInterceptor = 0x93 in fingerprint   #2018.09.02 johnwayneairobot change for gas interceptor to throttle report
    cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
    cloudlog.warn("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

    ret.enableCruise = not ret.enableGasInterceptor

    # kg of standard extra cargo to count for drive, gas, etc...
    std_cargo = 136

    # FIXME: hardcoding honda civic 2016 touring params so they can be used to
    # scale unknown params for other cars
    mass_civic = 2923 * CV.LB_TO_KG + std_cargo
    wheelbase_civic = 2.70
    centerToFront_civic = wheelbase_civic * 0.4
    centerToRear_civic = wheelbase_civic - centerToFront_civic
    rotationalInertia_civic = 2500
    tireStiffnessFront_civic = 192150
    tireStiffnessRear_civic = 202500

    # 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.steerKiBP, ret.steerKpBP = [[0.], [0.]]

    # # 2018.09.04
    # full torque for 20 deg at 80mph means 0.00007818594 comment from hyundai
    ret.steerKf = 0.00006 # conservative feed-forward


    #2018.09.02 johnwayneairobot add Kia soul #TODO need to modified paramater
    if candidate == CAR.SOUL:
      stop_and_go = False
      ret.safetyParam = 7 # define in /boardd/boardd.cc
      ret.mass = 3410. * CV.LB_TO_KG + std_cargo
      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.steerKpV, ret.steerKiV = [[0.6], [0.18]]
      ret.steerKiBP, ret.steerKpBP = [[0.], [0.]] # 2018.09.04 from hyundai
      ret.longitudinalKpBP = [0., 5., 35.]
      ret.longitudinalKpV = [1.2, 0.8, 0.5]
      ret.longitudinalKiBP = [0., 35.]
      ret.longitudinalKiV = [0.18, 0.12]

    elif candidate == CAR.SOUL1:
      stop_and_go = False
      ret.safetyParam = 7  # define in /boardd/boardd.cc
      ret.mass = 3410. * CV.LB_TO_KG + std_cargo
      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.steerKpV, ret.steerKiV = [[0.6], [0.18]]
      ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]  # 2018.09.04 from hyundai
      ret.longitudinalKpBP = [0., 5., 35.]
      ret.longitudinalKpV = [1.2, 0.8, 0.5]
      ret.longitudinalKiBP = [0., 35.]
      ret.longitudinalKiV = [0.18, 0.12]

    elif candidate == CAR.SOUL2:
      stop_and_go = False
      ret.safetyParam = 7  # define in /boardd/boardd.cc
      ret.mass = 3410. * CV.LB_TO_KG + std_cargo
      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.steerKpV, ret.steerKiV = [[0.6], [0.18]]
      ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]  # 2018.09.04 from hyundai
      ret.longitudinalKpBP = [0., 5., 35.]
      ret.longitudinalKpV = [1.2, 0.8, 0.5]
      ret.longitudinalKiBP = [0., 35.]
      ret.longitudinalKiV = [0.18, 0.12]

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

     #TODO 2018.09.04 should modified our steering control type to match kia angle
    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

    centerToRear = ret.wheelbase - ret.centerToFront
    # TODO: get actual value, for now starting with reasonable value for
    # TODO: 2018.09.02 need to scale this value for Kia soul and other car
    # civic and scaling by mass and wheelbase
    ret.rotationalInertia = rotationalInertia_civic * \
                            ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2)

    # 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 = (tireStiffnessFront_civic * tire_stiffness_factor) * \
                             ret.mass / mass_civic * \
                             (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic)
    ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \
                            ret.mass / mass_civic * \
                            (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic)

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

    #2018.09.02 Add separation for Kia soul and other below
    if candidate == CAR.SOUL:
      # no max steer limit VS speed
      ret.steerMaxBP = [0.]  # m/s
      ret.steerMaxV = [1.]  # max steer allowed #Todo:2018.09.02 tune in car and change

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

      ret.longPidDeadzoneBP = [0.]
      ret.longPidDeadzoneV = [0.]

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

      ret.steerActuatorDelay = 0.1
      ret.steerRateCost = 0.5

    elif candidate == CAR.SOUL1:
      # no max steer limit VS speed
      ret.steerMaxBP = [0.]  # m/s
      ret.steerMaxV = [1.]  # max steer allowed #Todo:2018.09.02 tune in car and change

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

      ret.longPidDeadzoneBP = [0.]
      ret.longPidDeadzoneV = [0.]

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

      ret.steerActuatorDelay = 0.1
      ret.steerRateCost = 0.5

    elif candidate == CAR.SOUL2:
      # no max steer limit VS speed
      ret.steerMaxBP = [0.]  # m/s
      ret.steerMaxV = [1.]  # max steer allowed #Todo:2018.09.02 tune in car and change

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

      ret.longPidDeadzoneBP = [0.]
      ret.longPidDeadzoneV = [0.]

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

      ret.steerActuatorDelay = 0.1
      ret.steerRateCost = 0.5

    else:
      # 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.longPidDeadzoneBP = [0.]
      ret.longPidDeadzoneV = [0.]

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

      ret.steerActuatorDelay = 0.1
      ret.steerRateCost = 0.5

    return ret
Exemplo n.º 13
0
    def get_params(candidate, fingerprint):

        # kg of standard extra cargo to count for drive, gas, etc...
        std_cargo = 136

        ret = car.CarParams.new_message()

        ret.carName = "toyota"
        ret.carFingerprint = candidate

        ret.safetyModel = car.CarParams.SafetyModels.toyota

        # pedal
        ret.enableCruise = True

        # FIXME: hardcoding honda civic 2016 touring params so they can be used to
        # scale unknown params for other cars
        mass_civic = 2923 * CV.LB_TO_KG + std_cargo
        wheelbase_civic = 2.70
        centerToFront_civic = wheelbase_civic * 0.4
        centerToRear_civic = wheelbase_civic - centerToFront_civic
        rotationalInertia_civic = 2500
        tireStiffnessFront_civic = 192150
        tireStiffnessRear_civic = 202500

        ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
        ret.steerActuatorDelay = 0.12  # Default delay, Prius has larger delay

        if candidate == CAR.PRIUS:  # experimenting with different values for 2018 prime
            ret.safetyParam = 66  # was 66
            ret.wheelbase = 2.70  # 2.70 verified correct for 2018 prime
            ret.steerRatio = 13.4  # was 15.59, updated for prime per @larryjustin
            tire_stiffness_factor = 0.7933
            ret.mass = 3370 * CV.LB_TO_KG + std_cargo  # was 3045,  updated for prime per @larryjustin
            ret.steerKpV, ret.steerKiV = [
                [0.3], [0.06]
            ]  # was 0.4, 0.01. For minor corrections, car was overshooting. Turn down K, bump I.
            ret.steerKf = 0.00008  # was 0.00006; need more torque to keep car on the road.
            # TODO: Prius seem to have very laggy actuators. Understand if it is lag or hysteresis
            # ret.steerActuatorDelay = 0.25                # was 0.25

        elif candidate in [CAR.RAV4, CAR.RAV4H]:
            ret.safetyParam = 73  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.65
            ret.steerRatio = 16.30  # 14.5 is spec end-to-end
            tire_stiffness_factor = 0.5533
            ret.mass = 3650 * CV.LB_TO_KG + std_cargo  # mean between normal and hybrid
            ret.steerKpV, ret.steerKiV = [[0.6], [0.05]]
            ret.steerKf = 0.00006  # full torque for 10 deg at 80mph means 0.00007818594

        elif candidate == CAR.COROLLA:
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.70
            ret.steerRatio = 17.8
            tire_stiffness_factor = 0.444
            ret.mass = 2860 * CV.LB_TO_KG + std_cargo  # mean between normal and hybrid
            ret.steerKpV, ret.steerKiV = [[0.2], [0.05]]
            ret.steerKf = 0.00003  # full torque for 20 deg at 80mph means 0.00007818594

        elif candidate == CAR.LEXUS_RXH:
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            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  # mean between min and max
            ret.steerKpV, ret.steerKiV = [[0.6], [0.1]]
            ret.steerKf = 0.00006  # full torque for 10 deg at 80mph means 0.00007818594

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

        ret.longPidDeadzoneBP = [0., 9.]
        ret.longPidDeadzoneV = [0., .15]

        # 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.
        if candidate in [CAR.PRIUS, CAR.RAV4H,
                         CAR.LEXUS_RXH]:  # rav4 hybrid can do stop and go
            ret.minEnableSpeed = -1.
        elif candidate in [CAR.RAV4,
                           CAR.COROLLA]:  # TODO: hack ICE to do stop and go
            ret.minEnableSpeed = 19. * CV.MPH_TO_MS

        centerToRear = ret.wheelbase - ret.centerToFront
        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = rotationalInertia_civic * \
                                ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2)

        # 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 = (tireStiffnessFront_civic * tire_stiffness_factor) * \
                                 ret.mass / mass_civic * \
                                 (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic)
        ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \
                                ret.mass / mass_civic * \
                                (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic)

        # 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.gasMaxBP = [0.]
        ret.gasMaxV = [0.5]
        ret.brakeMaxBP = [5., 20.]
        ret.brakeMaxV = [1., 0.8]

        ret.enableCamera = not check_ecu_msgs(fingerprint, candidate, ECU.CAM)
        ret.enableDsu = not check_ecu_msgs(fingerprint, candidate, ECU.DSU)
        ret.enableApgs = False  #not check_ecu_msgs(fingerprint, candidate, ECU.APGS)
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warn("ECU DSU Simulated: %r", ret.enableDsu)
        cloudlog.warn("ECU APGS Simulated: %r", ret.enableApgs)

        ret.steerLimitAlert = False
        ret.stoppingControl = False
        ret.startAccel = 0.0

        ret.longitudinalKpBP = [0., 5., 35.]
        ret.longitudinalKpV = [3.6, 2.4, 1.5]
        ret.longitudinalKiBP = [0., 35.]
        ret.longitudinalKiV = [0.54, 0.36]

        return ret
Exemplo n.º 14
0
    def get_params(candidate, fingerprint):

        # kg of standard extra cargo to count for drive, gas, etc...
        std_cargo = 136

        ret = car.CarParams.new_message()
        ret.carName = "toyota"
        ret.carFingerprint = candidate

        ret.safetyModel = car.CarParams.SafetyModels.toyota

        # pedal
        ret.enableCruise = not ret.enableGasInterceptor

        # FIXME: hardcoding honda civic 2016 touring params so they can be used to
        # scale unknown params for other cars
        mass_civic = 2923 * CV.LB_TO_KG + std_cargo
        wheelbase_civic = 2.70
        centerToFront_civic = wheelbase_civic * 0.4
        centerToRear_civic = wheelbase_civic - centerToFront_civic
        rotationalInertia_civic = 2500
        tireStiffnessFront_civic = 192150
        tireStiffnessRear_civic = 202500

        #ret.steerKiBP, ret.steerKpBP = [[0.], [0.]]
        #ret.steerActuatorDelay = 0.001  # Default delay, Prius has larger delay

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

        if ret.enableGasInterceptor:
            ret.gasMaxBP = [0., 9., 55]
            ret.gasMaxV = [0.2, 0.5, 0.7]
            ret.longitudinalTuning.kpV = [1.0, 0.66, 0.42]  # braking tune
            ret.longitudinalTuning.kiV = [0.135, 0.09]
        else:
            ret.gasMaxBP = [0.]
            ret.gasMaxV = [0.5]
            ret.longitudinalTuning.kpV = [2.0, 1.0,
                                          0.5]  # braking tune from rav4h
            ret.longitudinalTuning.kiV = [0.30, 0.20]

        ret.steerActuatorDelay = 0.12  # Default delay, Prius has larger delay
        if candidate != CAR.PRIUS:
            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.00  # unknown end-to-end spec
            tire_stiffness_factor = 0.6371  # hand-tune
            ret.mass = 3045 * CV.LB_TO_KG + std_cargo

            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

            ret.steerActuatorDelay = 0.5
            ret.steerRateCost = 0.5

        elif candidate in [CAR.RAV4]:
            stop_and_go = True if ret.enableGasInterceptor else False
            ret.safetyParam = 73  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.66  # 2.65 default
            ret.steerRatio = 17.28  # Rav4 0.5.10 tuning value
            ret.mass = 4100. / 2.205 + std_cargo  # mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.3
            ], [0.03]]  #0.6 0.05 default
            ret.wheelbase = 2.65
            tire_stiffness_factor = 0.5533
            ret.lateralTuning.pid.kf = 0.00001  # full torque for 10 deg at 80mph means 0.00007818594

        elif candidate in [CAR.RAV4H]:
            stop_and_go = True
            ret.safetyParam = 73  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.65  # 2.65 default
            ret.steerRatio = 16.53  # 0.5.10 tuning
            ret.mass = 4100. / 2.205 + std_cargo  # mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[
                0.3
            ], [0.03]]  #0.6 0.05 default
            ret.wheelbase = 2.65
            tire_stiffness_factor = 0.5533
            ret.lateralTuning.pid.kf = 0.0001  # full torque for 10 deg at 80mph means 0.00007818594

        elif candidate == CAR.RAV4_2019:
            stop_and_go = True
            ret.safetyParam = 100
            ret.wheelbase = 2.68986
            ret.steerRatio = 17.0
            tire_stiffness_factor = 0.7933
            ret.mass = 3370. * CV.LB_TO_KG + std_cargo
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                    [0.05]]
            ret.lateralTuning.pid.kf = 0.0001

        elif candidate == CAR.COROLLA_HATCH:
            stop_and_go = True
            ret.safetyParam = 100
            ret.wheelbase = 2.63906
            ret.steerRatio = 13.9
            tire_stiffness_factor = 0.444
            ret.mass = 3060. * CV.LB_TO_KG + std_cargo
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.17],
                                                                    [0.03]]
            ret.lateralTuning.pid.kf = 0.00007818594

        elif candidate == CAR.COROLLA:
            stop_and_go = True if ret.enableGasInterceptor else False
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.70
            ret.steerRatio = 17.84  # 0.5.10
            tire_stiffness_factor = 1.01794
            ret.mass = 2860 * CV.LB_TO_KG + std_cargo  # mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2],
                                                                    [0.05]]
            ret.lateralTuning.pid.kf = 0.00003909297  # full torque for 20 deg at 80mph means 0.00007818594

        elif candidate in [CAR.LEXUS_RXH, CAR.LEXUS_RX]:
            stop_and_go = True
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.79
            ret.steerRatio = 18.6  # 0.5.10
            tire_stiffness_factor = 0.517  # 0.5.10
            ret.mass = 4481 * CV.LB_TO_KG + std_cargo  # mean between min and max
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2],
                                                                    [0.02]]
            ret.lateralTuning.pid.kf = 0.00007  # full torque for 10 deg at 80mph means 0.00007818594

        elif candidate == CAR.LEXUS_IS:
            stop_and_go = False
            ret.safetyParam = 100
            ret.wheelbase = 2.79908
            ret.steerRatio = 13.3  #from Q
            tire_stiffness_factor = 0.444  #from Q
            ret.mass = 3737 * CV.LB_TO_KG + std_cargo  # mean between min and max
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.19],
                                                                    [0.04]
                                                                    ]  #from Q
            ret.lateralTuning.pid.kf = 0.00006  #from Q

        elif candidate == CAR.LEXUS_ISH:
            stop_and_go = True
            ret.safetyParam = 66
            ret.wheelbase = 2.80  # in spec
            ret.steerRatio = 13.3  # in spec
            tire_stiffness_factor = 0.444  # from camry
            ret.mass = 3736.8 * CV.LB_TO_KG + std_cargo  # in spec, mean of is300 (1680 kg) / is300h (1720 kg) / is350 (1685 kg)
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.19],
                                                                    [0.04]]
            ret.lateralTuning.pid.kf = 0.00006  # from camry

        elif candidate in [CAR.CHR, CAR.CHRH]:
            stop_and_go = True
            ret.safetyParam = 100
            ret.wheelbase = 2.63906
            ret.steerRatio = 15.6
            tire_stiffness_factor = 0.7933
            ret.mass = 3300. * CV.LB_TO_KG + std_cargo
            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 = 100
            ret.wheelbase = 2.82448
            ret.steerRatio = 17.7  # 0.5.10
            tire_stiffness_factor = 0.7933
            ret.mass = 3400 * CV.LB_TO_KG + std_cargo  #mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.3],
                                                                    [0.03]]
            ret.lateralTuning.pid.kf = 0.0001

        elif candidate in [CAR.HIGHLANDER, CAR.HIGHLANDERH]:
            stop_and_go = True
            ret.safetyParam = 100
            ret.wheelbase = 2.78
            ret.steerRatio = 17.36  # 0.5.10
            tire_stiffness_factor = 0.444  # not optimized yet
            ret.mass = 4607 * CV.LB_TO_KG + std_cargo  #mean between normal and hybrid limited
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.18],
                                                                    [0.0075]]
            ret.lateralTuning.pid.kf = 0.00015

        elif candidate == CAR.AVALON:
            stop_and_go = False
            ret.safetyParam = 73  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.17],
                                                                    [0.03]]
            ret.lateralTuning.pid.kf = 0.00006
            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  # mean between normal and hybrid

        elif candidate == CAR.OLD_CAR:
            stop_and_go = True
            ret.safetyParam = 100  # see conversion factor for STEER_TORQUE_EPS in dbc file
            ret.wheelbase = 2.455
            ret.steerRatio = 17.
            tire_stiffness_factor = 0.444
            ret.mass = 6200 * CV.LB_TO_KG + std_cargo  # mean between normal and hybrid
            ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.10],
                                                                    [0.04]]
            ret.lateralTuning.pid.kf = 0.00004  # full torque for 20 deg at 80mph means 0.00007818594
            if ret.enableGasInterceptor:
                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.gasMaxV = [0.2, 0.5, 0.7]
                ret.longitudinalTuning.kpV = [3.6, 1.1, 1.0]
                ret.longitudinalTuning.kiV = [0.5, 0.24]

        if candidate == CAR.OLD_CAR:
            ret.centerToFront = ret.wheelbase * 0.5
        else:
            ret.centerToFront = ret.wheelbase * 0.44

        ret.steerRateCost = 1.

        #detect the Pedal address
        ret.enableGasInterceptor = 0x201 in fingerprint

        # 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

        centerToRear = ret.wheelbase - ret.centerToFront
        # TODO: get actual value, for now starting with reasonable value for
        # civic and scaling by mass and wheelbase
        ret.rotationalInertia = rotationalInertia_civic * \
                                ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2)

        # 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 = (tireStiffnessFront_civic * tire_stiffness_factor) * \
                                 ret.mass / mass_civic * \
                                 (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic)
        ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \
                                ret.mass / mass_civic * \
                                (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic)

        # 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.gasMaxBP = [0., 9., 35.]
        #ret.gasMaxV = [0.2, 0.5, 0.7]
        ret.brakeMaxBP = [5., 20.]
        ret.brakeMaxV = [1., 0.8]

        ret.enableCamera = not check_ecu_msgs(fingerprint, ECU.CAM)
        ret.enableDsu = not check_ecu_msgs(fingerprint, ECU.DSU)
        ret.enableApgs = False  #not check_ecu_msgs(fingerprint, ECU.APGS)
        ret.openpilotLongitudinalControl = ret.enableCamera and ret.enableDsu
        cloudlog.warn("ECU Camera Simulated: %r", ret.enableCamera)
        cloudlog.warn("ECU DSU Simulated: %r", ret.enableDsu)
        cloudlog.warn("ECU APGS Simulated: %r", ret.enableApgs)
        cloudlog.warn("ECU Gas Interceptor: %r", ret.enableGasInterceptor)

        ret.steerLimitAlert = False

        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