Skip to content

Hyundai: split 2020 Kia Niro PHEV EX Premium - #3722

Open
Maxwell-Rosen wants to merge 8 commits into
commaai:masterfrom
Maxwell-Rosen:hyundai-niro-phev-2020-ex-premium
Open

Hyundai: split 2020 Kia Niro PHEV EX Premium#3722
Maxwell-Rosen wants to merge 8 commits into
commaai:masterfrom
Maxwell-Rosen:hyundai-niro-phev-2020-ex-premium

Conversation

@Maxwell-Rosen

@Maxwell-Rosen Maxwell-Rosen commented Sep 5, 2026

Copy link
Copy Markdown

Validation

  • Dongle ID: 9428906d33f23137
  • Route: 9428906d33f23137/00000000--08ec836c13/0

Resolves #3384

I've been using a version of opendbc on my car that just removed the two lines of UNSUPPORTED_LONGITUDINAL and MIN_STEER_32_MPH on my Kia Niro PHEV 2020 EX Premium for a while, but I should have PR'd this a long time ago. I'm just getting around to this now. I've thought the right way to handle this would be to create a new vehicle like KIA_NIRO_PHEV_2020_EX_P, but it would be an issue since the same car would be identified as either the EX or Premium since the fingerprint is the same. I had Codex implement this for me, providing vague instructions so it might find the most elegant solution, and it basically did that, constructing a new car KIA_NIRO_PHEV_2020, duplicating the same fingerprints for the other version.

I'm guessing I should give this a test drive and validate this branch before it's merged into main. I'll do this in the next few days.

Here is a summary of the main points of my session with Codex

I wrote this PR a while ago and I'm not sure exactly how to address it. I don't want to break anything in the existing codebase, but I'd
    like to add support for my trim of car. Suggest how we should implement this correctly.

    ### Describe the bug or enhancement

    These flags are specific to the trim of the car, and the flags set for this model do not reflect that. In particular, I've tested on my
    Kia Niro PHEV 2020 EX Premium, and I removed these flags and confirmed that the vehicle does have longitudinal control and can steer all
    the way to 0 MPH. These flags can be removed from the configuration safely.
    ```
     HyundaiFlags.UNSUPPORTED_LONGITUDINAL | HyundaiFlags.MIN_STEER_32_MPH
    ```
    The code that should be modified is here
    https://github.com/commaai/opendbc/blob/a80f6f74f62b7aed6a02b35ec7c61a6a62d14873/opendbc/car/hyundai/values.py#L436

    I do not understand this codebase enough to add a trim-specific version of this car. I think some of the more basic trims would not
    support steering to 0 MPH, so that should be kept as an option


  The safest implementation is a new firmware-identifiable platform for the 2020 EX Premium—not removing the flags from the shared entry.

    Why:

    - KIA_NIRO_PHEV (opendbc/car/hyundai/values.py:439) covers 2018 Hybrid, 2018–19 PHEV, and 2020 PHEV.
    - UNSUPPORTED_LONGITUDINAL enables openpilot longitudinal—not merely stock SCC.
    - MIN_STEER_32_MPH also sets minSteerSpeed during config initialization, so clearing the runtime flag alone is insufficient.
    - Reusing KIA_NIRO_PHEV_2022 could accidentally change steering torque from 255 to 384 and select different cluster behavior.

    Recommended shape:

    KIA_NIRO_PHEV_2020 = HyundaiPlatformConfig(
      [HyundaiCarDocs(
        "Kia Niro Plug-in Hybrid 2020",
        "EX Premium",
        car_parts=CarParts.common([CarHarness.hyundai_d]),
      )],
      KIA_NIRO_EV.specs,
      flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.HYBRID,
    )

    Then:

    1. Remove the 2020 documentation entry from the old platform.
    2. Move your car’s distinguishing camera/EPS firmware into a new entry in opendbc/car/hyundai/fingerprints.py:772. Shared radar firmware
       may remain in both platforms.

    3. Add the new platform beside KIA_NIRO_PHEV in the 255-torque list at opendbc/car/hyundai/values.py:37, preserving the behavior you
       actually tested.

    4. Add its torque substitution and a test route.
    5. Test that the old platform retains both flags while the new one has minSteerSpeed == 0 and alphaLongitudinalAvailable.

    The prerequisite is your recorded CarParams.carFw. If its firmware cannot distinguish the EX Premium from trims lacking these abilities,
  an
    automatic trim split is unsafe; keep the conservative flags until a validated CAN-message discriminator is found. VIN or marketing trim
    guesses should not control these capabilities.


Implement


  Implemented the trim-specific split:

    - Added KIA_NIRO_PHEV_2020 for EX Premium with longitudinal and zero-speed steering.
    - Uses unique camera firmware for identification.
    - Preserved the 255 steering limit and existing behavior.
    - Older trims retain conservative flags.
    - Added torque mapping and regression tests.

    Static checks and lint pass. Runtime tests couldn’t run because pycapnp is unavailable offline. A dedicated EX Premium replay route is
    still needed.

@github-actions github-actions Bot added car related to opendbc/car/ hyundai labels Sep 5, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing to opendbc! In order for us to review your PR as quickly as possible, check the following:

  • Convert your PR to a draft unless it's ready to review
  • Read the contributing docs
  • Before marking as "ready for review", ensure:
    • the goal is clearly stated in the description
    • all the tests are passing
    • include a route or your device' dongle ID if relevant

@Maxwell-Rosen
Maxwell-Rosen marked this pull request as draft September 5, 2026 23:00
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Car behavior report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

Testing 260 segments for: HYUNDAI_AZERA_HEV_6TH_GEN, HYUNDAI_ELANTRA_GT_I30, HYUNDAI_ELANTRA_2021, HYUNDAI_ELANTRA_HEV_2021, HYUNDAI_GENESIS, HYUNDAI_IONIQ, HYUNDAI_IONIQ_HEV_2022, HYUNDAI_IONIQ_EV_2020, HYUNDAI_IONIQ_PHEV_2019, HYUNDAI_IONIQ_PHEV, HYUNDAI_KONA_2022, HYUNDAI_KONA_EV, HYUNDAI_KONA_EV_2022, HYUNDAI_KONA_EV_2ND_GEN, HYUNDAI_SANTA_FE, HYUNDAI_SANTA_FE_2022, HYUNDAI_SANTA_FE_HEV_2022, HYUNDAI_SANTA_FE_PHEV_2022, HYUNDAI_SONATA, HYUNDAI_SONATA_LF, HYUNDAI_STARIA_4TH_GEN, HYUNDAI_PALISADE, HYUNDAI_SONATA_HYBRID, HYUNDAI_IONIQ_5, HYUNDAI_IONIQ_6, HYUNDAI_TUCSON_4TH_GEN, HYUNDAI_SANTA_CRUZ_1ST_GEN, HYUNDAI_CUSTIN_1ST_GEN

✅ 0 changed, 260 passed, 0 errors

… It's now just duplicating the phev varient in the fingerprints to another fingerprint too
@Maxwell-Rosen
Maxwell-Rosen marked this pull request as ready for review September 6, 2026 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

car related to opendbc/car/ hyundai

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kia Niro 2020 PHEV EX Premium supports longitudinal control and steering to 0 MPH

1 participant