mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-27 23:33:41 +08:00
Compare commits
99 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 13c6a58ad2 | |||
| a73d8c0724 | |||
| 6b79f7a227 | |||
| bdef37d674 | |||
| e01e382f81 | |||
| a11067b1a7 | |||
| 03d4f4678b | |||
| bdf5acef74 | |||
| 58581e40b8 | |||
| 108ab4c931 | |||
| a6cd443b63 | |||
| b074188701 | |||
| 2614a5bec6 | |||
| e4dd33148d | |||
| 586da8495e | |||
| 3db077ff93 | |||
| 3c93f81677 | |||
| e81f4ff1c7 | |||
| 553f2f8cd0 | |||
| ab02163241 | |||
| 4ee3010f0d | |||
| 9acdd6f0ad | |||
| 26cb9ba73c | |||
| ea5143fe2c | |||
| ca9adfd5f3 | |||
| 4d721e9cc7 | |||
| e33a942745 | |||
| 090eabda53 | |||
| 4ff8e7a5da | |||
| 00a65fc19f | |||
| 227dffc5b4 | |||
| ca17d3963d | |||
| 1bc4c35a0e | |||
| b13976776a | |||
| 0413e9baa9 | |||
| ed82ef5fde | |||
| 0eb7b7f820 | |||
| 76e2b275f8 | |||
| e8cab33282 | |||
| 763d32b415 | |||
| 487227cea9 | |||
| 4ecf06649b | |||
| c33241ba7e | |||
| 3ca28e6f24 | |||
| 8c34e34701 | |||
| ebb76dce4e | |||
| 06ea4e1913 | |||
| 33f726c85d | |||
| 0730feecc9 | |||
| 250c0917bb | |||
| 0dc219edba | |||
| 12b51d0308 | |||
| 7d3815dbb5 | |||
| 542b4f463a | |||
| 7ff81a0ffb | |||
| 1317718b6d | |||
| 6d40f1b0a5 | |||
| aadc1f5700 | |||
| 7f8c0301d5 | |||
| a147e084dc | |||
| 3b73537247 | |||
| c9bd6fa000 | |||
| 749878055a | |||
| f2b5c13620 | |||
| 5e7287a796 | |||
| 139d8cbe03 | |||
| 3670055c6b | |||
| b022663e6e | |||
| 4b70f5be81 | |||
| d1baceb3ef | |||
| dfa5c3490f | |||
| 4d6e2a3780 | |||
| 2f508d507c | |||
| aec40a8288 | |||
| ab0b4ccf54 | |||
| 6cd506c47a | |||
| 6ef1123e86 | |||
| 9ade0195e9 | |||
| b9f349c72d | |||
| bb2cd1407e | |||
| 83ebdc716b | |||
| e495c527ca | |||
| 7547aeeb5c | |||
| b4c2dfd8b2 | |||
| 1437f6b8f5 | |||
| 0d8918edf8 | |||
| 4dbf3f18f5 | |||
| e6acb363ed | |||
| eb9f52a9fe | |||
| f0886a5a23 | |||
| 704d27bfce | |||
| fe89adeca1 | |||
| 25da2438a3 | |||
| 541af7124d | |||
| 81e08eb4f8 | |||
| 4b1644d4a6 | |||
| cf296a2c5d | |||
| fcb9fd0d39 | |||
| 544b9c0d6c |
@@ -11,6 +11,17 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Close pull requests targeting testing
|
||||||
|
if: github.repository == 'StarPilotHQ/StarPilot' && github.event.pull_request.base.ref == 'testing'
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
run: |
|
||||||
|
current=$(gh pr view "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --json baseRefName,state --jq '.baseRefName + ":" + .state')
|
||||||
|
if [ "$current" = testing:OPEN ]; then
|
||||||
|
gh pr close "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --comment 'Please retarget this pull request to `stable` and reopen it. Maintainers publish qualified changes to `testing`.'
|
||||||
|
fi
|
||||||
|
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
|
|
||||||
# Label PRs
|
# Label PRs
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ jobs:
|
|||||||
|
|
||||||
REPO = "StarPilotHQ/StarPilot"
|
REPO = "StarPilotHQ/StarPilot"
|
||||||
MARKER = "<!-- starpilot-pr-discord-reminder-v1 -->"
|
MARKER = "<!-- starpilot-pr-discord-reminder-v1 -->"
|
||||||
BODY = ("Thank you for your PR! To increase communication and responsiveness, "
|
BODY = ("Thank you for your PR! Once CI passes on your PR against `stable`, "
|
||||||
"please open a ticket describing your PR in the StarPilot discord at "
|
"please open a report describing it in the StarPilot Discord at "
|
||||||
"[https://firestar.link/discord](https://firestar.link/discord)\n\n" + MARKER)
|
"[https://firestar.link/discord](https://firestar.link/discord)\n\n" + MARKER)
|
||||||
|
|
||||||
def remind(event, request):
|
def remind(event, request):
|
||||||
|
|||||||
@@ -180,8 +180,31 @@ jobs:
|
|||||||
timeout-minutes: 1
|
timeout-minutes: 1
|
||||||
run: scripts/lint/lint.sh
|
run: scripts/lint/lint.sh
|
||||||
|
|
||||||
|
build_host:
|
||||||
|
name: build host
|
||||||
|
runs-on: ubuntu-24.04
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v7
|
||||||
|
- run: ./tools/op.sh setup
|
||||||
|
- name: Restore the latest native build cache
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
|
restore-keys: scons-host-x64-
|
||||||
|
- name: Build openpilot once for every host test job
|
||||||
|
run: scons
|
||||||
|
- name: Share the native build cache with host test jobs
|
||||||
|
uses: actions/cache/save@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
|
|
||||||
unit_tests:
|
unit_tests:
|
||||||
name: unit tests
|
name: unit tests
|
||||||
|
needs: build_host
|
||||||
runs-on: ${{
|
runs-on: ${{
|
||||||
(github.repository == 'commaai/openpilot') &&
|
(github.repository == 'commaai/openpilot') &&
|
||||||
((github.event_name != 'pull_request') ||
|
((github.event_name != 'pull_request') ||
|
||||||
@@ -207,6 +230,11 @@ jobs:
|
|||||||
run: go mod download
|
run: go mod download
|
||||||
- run: ./tools/op.sh setup
|
- run: ./tools/op.sh setup
|
||||||
id: setup
|
id: setup
|
||||||
|
- name: Restore the shared native build
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
- name: Build openpilot
|
- name: Build openpilot
|
||||||
id: build
|
id: build
|
||||||
run: scons
|
run: scons
|
||||||
@@ -273,15 +301,16 @@ jobs:
|
|||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
custom_pytest:
|
custom_pytest:
|
||||||
name: custom pytest (${{ matrix.shard }})
|
name: custom pytest (${{ matrix.group }})
|
||||||
|
needs: build_host
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
timeout-minutes: 35
|
timeout-minutes: 45
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
shard: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
|
group: [0, 1, 2, 3, 4, 5, 6, 7, 8]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- name: Provide JavaScript runtime for Galaxy contract tests
|
- name: Provide JavaScript runtime for Galaxy contract tests
|
||||||
@@ -301,6 +330,11 @@ jobs:
|
|||||||
run: go mod download
|
run: go mod download
|
||||||
- run: ./tools/op.sh setup
|
- run: ./tools/op.sh setup
|
||||||
id: setup
|
id: setup
|
||||||
|
- name: Restore the shared native build
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
- name: Build openpilot
|
- name: Build openpilot
|
||||||
id: build
|
id: build
|
||||||
run: scons
|
run: scons
|
||||||
@@ -314,19 +348,19 @@ jobs:
|
|||||||
run: sudo apt-get update && sudo apt-get install -y libegl1 libgles-dev libgl1-mesa-dri
|
run: sudo apt-get update && sudo apt-get install -y libegl1 libgles-dev libgl1-mesa-dri
|
||||||
- name: Test every assigned custom pytest node serially
|
- name: Test every assigned custom pytest node serially
|
||||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||||
timeout-minutes: 20
|
timeout-minutes: 30
|
||||||
env:
|
env:
|
||||||
RAYLIB_BACKEND: headless
|
RAYLIB_BACKEND: headless
|
||||||
STARPILOT_AUTO_GL_TEST: "1"
|
STARPILOT_AUTO_GL_TEST: "1"
|
||||||
STARPILOT_TEST_SOFTWARE_EGL: "1"
|
STARPILOT_TEST_SOFTWARE_EGL: "1"
|
||||||
LIBGL_ALWAYS_SOFTWARE: "1"
|
LIBGL_ALWAYS_SOFTWARE: "1"
|
||||||
run: .venv/bin/python -m tools.ci.custom_pytest_shards run --index "${{ matrix.shard }}" --count 32 --output "ci-results/custom-pytest-${{ matrix.shard }}"
|
run: .venv/bin/python -m tools.ci.custom_pytest_shards run --group "${{ matrix.group }}" --groups 9 --count 32 --output "ci-results/custom-pytest-group-${{ matrix.group }}"
|
||||||
- name: Save collection, every outcome, JUnit and durable worker diagnostics
|
- name: Save collection, every outcome, JUnit and durable worker diagnostics
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: custom-pytest-${{ matrix.shard }}
|
name: custom-pytest-group-${{ matrix.group }}
|
||||||
path: ci-results/custom-pytest-${{ matrix.shard }}/
|
path: ci-results/custom-pytest-group-${{ matrix.group }}/
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
custom_pytest_complete:
|
custom_pytest_complete:
|
||||||
@@ -353,33 +387,39 @@ jobs:
|
|||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
aol_lifecycles:
|
aol_lifecycles:
|
||||||
name: AOL lifecycles (${{ matrix.shard }})
|
name: AOL lifecycles (${{ matrix.group }})
|
||||||
|
needs: build_host
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
timeout-minutes: 35
|
timeout-minutes: 45
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
shard: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
|
group: [0, 1, 2, 3]
|
||||||
env:
|
env:
|
||||||
FUZZ_SEED: '0'
|
FUZZ_SEED: '0'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- run: ./tools/op.sh setup
|
- run: ./tools/op.sh setup
|
||||||
|
- name: Restore the shared native build
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
- name: Build native host dependencies
|
- name: Build native host dependencies
|
||||||
run: scons
|
run: scons
|
||||||
- name: Gate every assigned lifecycle module serially
|
- name: Gate every assigned lifecycle module serially
|
||||||
timeout-minutes: 15
|
timeout-minutes: 30
|
||||||
env:
|
env:
|
||||||
RAYLIB_BACKEND: headless
|
RAYLIB_BACKEND: headless
|
||||||
run: python3 tools/ci/run_vehicle_tests.py --suite aol-lifecycle --shard-index "${{ matrix.shard }}" --shard-count 16 --output "ci-results/aol-lifecycle-${{ matrix.shard }}"
|
run: python3 tools/ci/run_vehicle_tests.py --suite aol-lifecycle --shard-group "${{ matrix.group }}" --shard-groups 4 --shard-count 16 --output "ci-results/aol-lifecycle-group-${{ matrix.group }}"
|
||||||
- name: Save every lifecycle outcome and native build
|
- name: Save every lifecycle outcome and native build
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: aol-lifecycle-${{ matrix.shard }}
|
name: aol-lifecycle-group-${{ matrix.group }}
|
||||||
path: ci-results/aol-lifecycle-${{ matrix.shard }}/
|
path: ci-results/aol-lifecycle-group-${{ matrix.group }}/
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
aol_lifecycle_complete:
|
aol_lifecycle_complete:
|
||||||
@@ -431,6 +471,7 @@ jobs:
|
|||||||
|
|
||||||
vehicle_contracts:
|
vehicle_contracts:
|
||||||
name: vehicle contracts (${{ matrix.suite }})
|
name: vehicle contracts (${{ matrix.suite }})
|
||||||
|
needs: build_host
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
timeout-minutes: 35
|
timeout-minutes: 35
|
||||||
permissions:
|
permissions:
|
||||||
@@ -444,10 +485,17 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- run: ./tools/op.sh setup
|
- run: ./tools/op.sh setup
|
||||||
|
- name: Restore the shared native build
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
- name: Build native host dependencies
|
- name: Build native host dependencies
|
||||||
run: scons
|
run: scons
|
||||||
- name: Run explicit vehicle suite and record every result
|
- name: Run explicit vehicle suite and record every result
|
||||||
timeout-minutes: 20
|
timeout-minutes: 20
|
||||||
|
env:
|
||||||
|
STARPILOT_VEHICLE_WORKERS: ${{ matrix.suite == 'interfaces' && '4' || '1' }}
|
||||||
run: python3 tools/ci/run_vehicle_tests.py --suite "${{ matrix.suite }}" --output "ci-results/${{ matrix.suite }}"
|
run: python3 tools/ci/run_vehicle_tests.py --suite "${{ matrix.suite }}" --output "ci-results/${{ matrix.suite }}"
|
||||||
- name: Require current complete interface regression coverage
|
- name: Require current complete interface regression coverage
|
||||||
if: ${{ always() && matrix.suite == 'interfaces' }}
|
if: ${{ always() && matrix.suite == 'interfaces' }}
|
||||||
@@ -465,33 +513,39 @@ jobs:
|
|||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
safety_release_contracts:
|
safety_release_contracts:
|
||||||
name: RELEASE vehicle contracts (${{ matrix.shard }})
|
name: RELEASE vehicle contracts (${{ matrix.group }})
|
||||||
|
needs: build_host
|
||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
timeout-minutes: 35
|
timeout-minutes: 45
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
shard: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
|
group: [0, 1, 2, 3]
|
||||||
env:
|
env:
|
||||||
FUZZ_SEED: '0'
|
FUZZ_SEED: '0'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- run: ./tools/op.sh setup
|
- run: ./tools/op.sh setup
|
||||||
|
- name: Restore the shared native build
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
- name: Build native host dependencies
|
- name: Build native host dependencies
|
||||||
run: scons
|
run: scons
|
||||||
- name: Run every assigned RELEASE target serially
|
- name: Run every assigned RELEASE target serially
|
||||||
timeout-minutes: 20
|
timeout-minutes: 30
|
||||||
env:
|
env:
|
||||||
RAYLIB_BACKEND: headless
|
RAYLIB_BACKEND: headless
|
||||||
run: python3 tools/ci/run_vehicle_tests.py --suite safety-release --shard-index "${{ matrix.shard }}" --shard-count 16 --output "ci-results/safety-release-${{ matrix.shard }}"
|
run: python3 tools/ci/run_vehicle_tests.py --suite safety-release --shard-group "${{ matrix.group }}" --shard-groups 4 --shard-count 16 --output "ci-results/safety-release-group-${{ matrix.group }}"
|
||||||
- name: Save every RELEASE outcome and native build
|
- name: Save every RELEASE outcome and native build
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: safety-release-${{ matrix.shard }}
|
name: safety-release-group-${{ matrix.group }}
|
||||||
path: ci-results/safety-release-${{ matrix.shard }}/
|
path: ci-results/safety-release-group-${{ matrix.group }}/
|
||||||
if-no-files-found: error
|
if-no-files-found: error
|
||||||
|
|
||||||
safety_release_complete:
|
safety_release_complete:
|
||||||
@@ -586,6 +640,7 @@ jobs:
|
|||||||
|
|
||||||
process_replay:
|
process_replay:
|
||||||
name: process replay
|
name: process replay
|
||||||
|
needs: build_host
|
||||||
runs-on: ${{
|
runs-on: ${{
|
||||||
(github.repository == 'commaai/openpilot') &&
|
(github.repository == 'commaai/openpilot') &&
|
||||||
((github.event_name != 'pull_request') ||
|
((github.event_name != 'pull_request') ||
|
||||||
@@ -595,6 +650,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- run: ./tools/op.sh setup
|
- run: ./tools/op.sh setup
|
||||||
|
- name: Restore the shared native build
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
- name: Build openpilot
|
- name: Build openpilot
|
||||||
run: scons
|
run: scons
|
||||||
- name: Run replay
|
- name: Run replay
|
||||||
@@ -665,6 +725,7 @@ jobs:
|
|||||||
|
|
||||||
create_ui_report:
|
create_ui_report:
|
||||||
name: Create UI Report
|
name: Create UI Report
|
||||||
|
needs: build_host
|
||||||
runs-on: ${{
|
runs-on: ${{
|
||||||
(github.repository == 'commaai/openpilot') &&
|
(github.repository == 'commaai/openpilot') &&
|
||||||
((github.event_name != 'pull_request') ||
|
((github.event_name != 'pull_request') ||
|
||||||
@@ -674,6 +735,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- run: ./tools/op.sh setup
|
- run: ./tools/op.sh setup
|
||||||
|
- name: Restore the shared native build
|
||||||
|
uses: actions/cache/restore@v4
|
||||||
|
with:
|
||||||
|
path: /tmp/scons_cache
|
||||||
|
key: scons-host-x64-${{ github.sha }}
|
||||||
- name: Build openpilot
|
- name: Build openpilot
|
||||||
run: scons
|
run: scons
|
||||||
- name: Create UI Report
|
- name: Create UI Report
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@ The radar interface preserves that attribution while adapting to the current int
|
|||||||
|
|
||||||
## RAV4 Continental ARS510 receiver
|
## RAV4 Continental ARS510 receiver
|
||||||
|
|
||||||
The optional ACC-target and fused-track receivers and DBC preserve firestar5683's Dom integration from `b220a37f4bd119e402225a7aa16a7cd84878d0af` (Sea Turtles, 2026-10-13) and its ARS510 source attribution to ds-sebastian/ars510-radar `fb5b29c2b5999f34afeb6f7ac494a73949d66c67`, copyright 2026 ARS510 radar contributors. The complete MIT permission and warranty notice is retained in THIRD_PARTY_NOTICES.md. Startup/settings ownership is adapted to the current StarPilot architecture; no original firmware binaries or safety permissions are copied.
|
The ACC-target receiver and DBC preserve firestar5683's Dom integration from `b220a37f4bd119e402225a7aa16a7cd84878d0af` (Sea Turtles, 2026-10-13) and its ARS510 source attribution to ds-sebastian/ars510-radar `fb5b29c2b5999f34afeb6f7ac494a73949d66c67`, copyright 2026 ARS510 radar contributors. The DBC is the one in commaai/opendbc#3860 (ds-sebastian/opendbc `ddcc0b07d1759c96a1d208ae1db13ad91ce23435`). The complete MIT permission and warranty notice is retained in THIRD_PARTY_NOTICES.md. Startup/settings ownership is adapted to the current StarPilot architecture; no original firmware binaries or safety permissions are copied.
|
||||||
|
|
||||||
## Spotify Bluetooth output
|
## Spotify Bluetooth output
|
||||||
|
|
||||||
|
|||||||
@@ -92,9 +92,10 @@ The Ford CAN FD camera-radar filtering includes work adapted from BluePilot's `b
|
|||||||
|
|
||||||
## Continental ARS510 radar
|
## Continental ARS510 radar
|
||||||
|
|
||||||
The optional RAV4 radar decoders and `toyota_tss2_ars510.dbc` are adapted from
|
The RAV4 ACC-target radar receiver is adapted from
|
||||||
<https://github.com/ds-sebastian/ars510-radar> at
|
<https://github.com/ds-sebastian/ars510-radar> at
|
||||||
`fb5b29c2b5999f34afeb6f7ac494a73949d66c67`.
|
`fb5b29c2b5999f34afeb6f7ac494a73949d66c67`. `toyota_tss2_ars510.dbc` is the DBC
|
||||||
|
of commaai/opendbc#3860 (ds-sebastian/opendbc `ddcc0b07d1759c96a1d208ae1db13ad91ce23435`).
|
||||||
|
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,9 @@ func BundledManagedRegions() ([]ManagedRegion, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result := make([]ManagedRegion, 0, 242)
|
result := make([]ManagedRegion, 0, 252)
|
||||||
for _, group := range []string{"nation", "us_state", "ca_province"} {
|
// Russian district rectangles follow Geofabrik extract envelopes, split at ±180°.
|
||||||
|
for _, group := range []string{"nation", "us_state", "ca_province", "ru_district"} {
|
||||||
for key, data := range menu[group] {
|
for key, data := range menu[group] {
|
||||||
if key == "" || strings.Contains(key, ".") || data.FullName == "" {
|
if key == "" || strings.Contains(key, ".") || data.FullName == "" {
|
||||||
return nil, errors.New("invalid bundled region")
|
return nil, errors.New("invalid bundled region")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ func TestBundledManagedRegionCoverage(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(regions) != 242 {
|
if len(regions) != 252 {
|
||||||
t.Fatalf("bundled catalog changed: %d", len(regions))
|
t.Fatalf("bundled catalog changed: %d", len(regions))
|
||||||
}
|
}
|
||||||
available := 0
|
available := 0
|
||||||
@@ -23,7 +23,7 @@ func TestBundledManagedRegionCoverage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if available != 238 {
|
if available != 248 {
|
||||||
t.Fatalf("review supported-region count changed: %d", available)
|
t.Fatalf("review supported-region count changed: %d", available)
|
||||||
}
|
}
|
||||||
for token, groups := range map[string]int{"us_state.CA": 36, "us_state.TX": 56, "us_state.IL": 12, "nation.CA": 765, "nation.JP": 72, "nation.US": 390} {
|
for token, groups := range map[string]int{"us_state.CA": 36, "us_state.TX": 56, "us_state.IL": 12, "nation.CA": 765, "nation.JP": 72, "nation.US": 390} {
|
||||||
@@ -39,6 +39,23 @@ func TestBundledManagedRegionCoverage(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRussianDistrictCoverage(t *testing.T) {
|
||||||
|
for token, want := range map[string]struct {
|
||||||
|
bounds [4]float64
|
||||||
|
groups int
|
||||||
|
}{
|
||||||
|
"central": {[4]float64{48, 30, 60, 48}, 54},
|
||||||
|
"moscow": {[4]float64{54, 36, 58, 40}, 4},
|
||||||
|
"far-east": {[4]float64{36, 104, 84, 180}, 912},
|
||||||
|
"far-east-dateline": {[4]float64{62, -180, 74, -168}, 36},
|
||||||
|
} {
|
||||||
|
region, err := ResolveManagedRegion("ru_district." + token)
|
||||||
|
if err != nil || region.Bounds != want.bounds || region.Groups != want.groups {
|
||||||
|
t.Fatalf("%s: %+v %v", token, region, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Province coverage comes from the pinned Geofabrik extract envelopes. Every
|
// Province coverage comes from the pinned Geofabrik extract envelopes. Every
|
||||||
// envelope must survive outward grid alignment without losing any edge.
|
// envelope must survive outward grid alignment without losing any edge.
|
||||||
func TestCanadianProvinceCoverage(t *testing.T) {
|
func TestCanadianProvinceCoverage(t *testing.T) {
|
||||||
|
|||||||
@@ -2183,5 +2183,97 @@
|
|||||||
"max_lat": 70.16293
|
"max_lat": 70.16293
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ru_district": {
|
||||||
|
"central": {
|
||||||
|
"full_name": "Russia - Central Federal District",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 30.6998,
|
||||||
|
"min_lat": 49.5045,
|
||||||
|
"max_lon": 47.6702,
|
||||||
|
"max_lat": 59.6533
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"far-east": {
|
||||||
|
"full_name": "Russia - Far Eastern Federal District (main area)",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 105.4219,
|
||||||
|
"min_lat": 37.3466,
|
||||||
|
"max_lon": 180,
|
||||||
|
"max_lat": 82.0002
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"far-east-dateline": {
|
||||||
|
"full_name": "Russia - Far Eastern Federal District (across the date line)",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": -180,
|
||||||
|
"min_lat": 62.2613,
|
||||||
|
"max_lon": -168.6841,
|
||||||
|
"max_lat": 72.2393
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"moscow": {
|
||||||
|
"full_name": "Russia - Moscow area",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 36,
|
||||||
|
"min_lat": 54,
|
||||||
|
"max_lon": 40,
|
||||||
|
"max_lat": 58
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"north-caucasus": {
|
||||||
|
"full_name": "Russia - North Caucasus Federal District",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 40.6726,
|
||||||
|
"min_lat": 41.1355,
|
||||||
|
"max_lon": 48.8645,
|
||||||
|
"max_lat": 46.2391
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"northwestern": {
|
||||||
|
"full_name": "Russia - Northwestern Federal District",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 19.4084,
|
||||||
|
"min_lat": 54.3128,
|
||||||
|
"max_lon": 72.6248,
|
||||||
|
"max_lat": 82.5456
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"siberian": {
|
||||||
|
"full_name": "Russia - Siberian Federal District",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 70.2748,
|
||||||
|
"min_lat": 49.021,
|
||||||
|
"max_lon": 147.7133,
|
||||||
|
"max_lat": 81.8875
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"southern": {
|
||||||
|
"full_name": "Russia - Southern Federal District",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 36.5232,
|
||||||
|
"min_lat": 43.1896,
|
||||||
|
"max_lon": 49.9367,
|
||||||
|
"max_lat": 51.2554
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ural": {
|
||||||
|
"full_name": "Russia - Ural Federal District",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 57.0426,
|
||||||
|
"min_lat": 51.8264,
|
||||||
|
"max_lon": 86.0952,
|
||||||
|
"max_lat": 75.011
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"volga": {
|
||||||
|
"full_name": "Russia - Volga Federal District",
|
||||||
|
"bounding_box": {
|
||||||
|
"min_lon": 41.7211,
|
||||||
|
"min_lat": 49.751,
|
||||||
|
"max_lon": 61.7337,
|
||||||
|
"max_lat": 61.7197
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ from opendbc.car.psa.psacan import psa_checksum
|
|||||||
from opendbc.car.rivian.riviancan import rivian_checksum
|
from opendbc.car.rivian.riviancan import rivian_checksum
|
||||||
from opendbc.car.ford.fordcan import FORD_CHECKSUM_FIELDS, ford_checksum
|
from opendbc.car.ford.fordcan import FORD_CHECKSUM_FIELDS, ford_checksum
|
||||||
from opendbc.car.mg.mgcan import mg_checksum
|
from opendbc.car.mg.mgcan import mg_checksum
|
||||||
|
from opendbc.car.leapmotor.leapmotorcan import leapmotor_checksum
|
||||||
|
|
||||||
|
|
||||||
class SignalType:
|
class SignalType:
|
||||||
@@ -281,6 +282,8 @@ def get_checksum_state(dbc_name: str) -> ChecksumState | None:
|
|||||||
return ChecksumState(SignalType.BODY_CHECKSUM, body_checksum)
|
return ChecksumState(SignalType.BODY_CHECKSUM, body_checksum)
|
||||||
elif dbc_name.startswith("tesla_model3_party"):
|
elif dbc_name.startswith("tesla_model3_party"):
|
||||||
return ChecksumState(SignalType.TESLA_CHECKSUM, tesla_checksum, tesla_setup_signal)
|
return ChecksumState(SignalType.TESLA_CHECKSUM, tesla_checksum, tesla_setup_signal)
|
||||||
|
elif dbc_name.startswith("leapmotor_"):
|
||||||
|
return ChecksumState(SignalType.VOLKSWAGEN_MQB_MEB_CHECKSUM, leapmotor_checksum)
|
||||||
elif dbc_name.startswith("psa_"):
|
elif dbc_name.startswith("psa_"):
|
||||||
return ChecksumState(SignalType.PSA_CHECKSUM, psa_checksum)
|
return ChecksumState(SignalType.PSA_CHECKSUM, psa_checksum)
|
||||||
elif dbc_name.startswith("byd_"):
|
elif dbc_name.startswith("byd_"):
|
||||||
|
|||||||
@@ -651,6 +651,7 @@ struct CarParams {
|
|||||||
bmw @37;
|
bmw @37;
|
||||||
mg @38;
|
mg @38;
|
||||||
teslaPreap @39;
|
teslaPreap @39;
|
||||||
|
leapmotor @40;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum SteerControlType {
|
enum SteerControlType {
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ from opendbc.car.mock.values import CAR as MOCK
|
|||||||
from opendbc.car.gm.pedal_capability import automatic_bolt_candidate
|
from opendbc.car.gm.pedal_capability import automatic_bolt_candidate
|
||||||
from opendbc.car.gm.discovery import (automatic_trax_candidate, automatic_volt_ascm_candidate, automatic_volt_candidate,
|
from opendbc.car.gm.discovery import (automatic_trax_candidate, automatic_volt_ascm_candidate, automatic_volt_candidate,
|
||||||
normal_bus0_topology as gm_normal_bus0_topology)
|
normal_bus0_topology as gm_normal_bus0_topology)
|
||||||
|
from opendbc.car.gm.values import CAR as GM
|
||||||
from opendbc.car.ford.discovery import (normal_bus0_selection as ford_normal_bus0_selection,
|
from opendbc.car.ford.discovery import (normal_bus0_selection as ford_normal_bus0_selection,
|
||||||
normal_bus0_queries as ford_normal_bus0_queries, normal_bus_query_brand)
|
normal_bus0_queries as ford_normal_bus0_queries, normal_bus_query_brand)
|
||||||
from opendbc.car.volvo.discovery import normal_bus_topology as volvo_normal_bus_topology, v60_bus_topology as volvo_v60_bus_topology
|
from opendbc.car.volvo.discovery import normal_bus_topology as volvo_normal_bus_topology, v60_bus_topology as volvo_v60_bus_topology
|
||||||
from opendbc.car.hyundai.discovery import normal_bus_topology
|
from opendbc.car.hyundai.discovery import kona_electric_se_candidate, normal_bus_topology
|
||||||
|
from opendbc.car.hyundai.values import CAR as HYUNDAI
|
||||||
from opendbc.car.honda.discovery import (eps_needs_obd as honda_eps_needs_obd, nidec_bus0_topology,
|
from opendbc.car.honda.discovery import (eps_needs_obd as honda_eps_needs_obd, nidec_bus0_topology,
|
||||||
normal_bus_topology as honda_normal_bus_topology)
|
normal_bus_topology as honda_normal_bus_topology)
|
||||||
from opendbc.car.honda.values import CAR as HONDA, HondaFlags
|
from opendbc.car.honda.values import CAR as HONDA, HondaFlags
|
||||||
@@ -270,6 +272,8 @@ def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_mu
|
|||||||
# Refine after both automatic sources, before the explicit override below.
|
# Refine after both automatic sources, before the explicit override below.
|
||||||
if not fixed_fingerprint:
|
if not fixed_fingerprint:
|
||||||
car_fingerprint = automatic_bolt_candidate(car_fingerprint, finger, camera_cruise_messages, vin)
|
car_fingerprint = automatic_bolt_candidate(car_fingerprint, finger, camera_cruise_messages, vin)
|
||||||
|
if car_fingerprint is None:
|
||||||
|
car_fingerprint = kona_electric_se_candidate(vin, finger, car_fw)
|
||||||
if car_fingerprint == 'SUBARU_IMPREZA' and source == CarParams.FingerprintSource.fw and exact_match:
|
if car_fingerprint == 'SUBARU_IMPREZA' and source == CarParams.FingerprintSource.fw and exact_match:
|
||||||
# Subaru's early GT Crosstrek and Impreza share a firmware bucket.
|
# Subaru's early GT Crosstrek and Impreza share a firmware bucket.
|
||||||
# NHTSA vPIC identifies JF2GT with model-year codes J and K as Crosstrek.
|
# NHTSA vPIC identifies JF2GT with model-year codes J and K as Crosstrek.
|
||||||
@@ -334,6 +338,8 @@ def get_car(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_multip
|
|||||||
|
|
||||||
CarInterface = interfaces[candidate]
|
CarInterface = interfaces[candidate]
|
||||||
params_options = {'auto_pedal': False} if source == CarParams.FingerprintSource.fixed and candidate in interface_names['gm'] else {}
|
params_options = {'auto_pedal': False} if source == CarParams.FingerprintSource.fixed and candidate in interface_names['gm'] else {}
|
||||||
|
if candidate in (GM.GMC_YUKON_CC, HYUNDAI.HYUNDAI_KONA_EV_2023_NON_SCC):
|
||||||
|
params_options['vin'] = vin
|
||||||
CP: CarParams = CarInterface.get_params(candidate, fingerprints, car_fw, alpha_long_allowed, is_release, docs=False, **params_options)
|
CP: CarParams = CarInterface.get_params(candidate, fingerprints, car_fw, alpha_long_allowed, is_release, docs=False, **params_options)
|
||||||
CP.carVin = vin
|
CP.carVin = vin
|
||||||
CP.carFw = car_fw
|
CP.carFw = car_fw
|
||||||
|
|||||||
@@ -83,6 +83,14 @@ def volvo_sign(speed_kph: float) -> tuple[Status, float]:
|
|||||||
return (Status.VALID, speed_kph / 3.6) if speed_kph > 0 else (Status.ABSENT, 0.0)
|
return (Status.VALID, speed_kph / 3.6) if speed_kph > 0 else (Status.ABSENT, 0.0)
|
||||||
|
|
||||||
|
|
||||||
|
def leapmotor_sign(raw: int) -> tuple[Status, float]:
|
||||||
|
# ROAD_SIGNS.SPEED_LIMIT is in km/h: 20-130 in tens on the B10's drives. 0 and 255 only last single frames, and
|
||||||
|
# no code for "no sign" has been seen, so neither is evidence of absence.
|
||||||
|
if 1 <= raw <= 250:
|
||||||
|
return Status.VALID, raw / 3.6
|
||||||
|
return Status.UNKNOWN, 0.0
|
||||||
|
|
||||||
|
|
||||||
def hyundai_canfd_sign(speed: int, system_status: int, is_metric: bool) -> tuple[Status, float]:
|
def hyundai_canfd_sign(speed: int, system_status: int, is_metric: bool) -> tuple[Status, float]:
|
||||||
# FR_CMR_02_100ms defines 0 as no recognition, 253 as unlimited, and
|
# FR_CMR_02_100ms defines 0 as no recognition, 253 as unlimited, and
|
||||||
# 254/255 as reserved/invalid. A failed ISLW system is not evidence of absence.
|
# 254/255 as reserved/invalid. A failed ISLW system is not evidence of absence.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from opendbc.car import ACCEL_MAX_TAKEOFF
|
|||||||
from math import fabs, exp
|
from math import fabs, exp
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
from opendbc.car import Bus, get_safety_config, structs
|
from opendbc.car import Bus, get_safety_config, scale_rot_inertia, scale_tire_stiffness, structs
|
||||||
from opendbc.car.pedal import supported_pedal_detected
|
from opendbc.car.pedal import supported_pedal_detected
|
||||||
from opendbc.car.gm.pedal_capability import pedal_candidate
|
from opendbc.car.gm.pedal_capability import pedal_candidate
|
||||||
from opendbc.car.common.conversions import Conversions as CV
|
from opendbc.car.common.conversions import Conversions as CV
|
||||||
@@ -22,6 +22,7 @@ from opendbc.car.gm.values import (volt_cc_pedal_profile, CAR, CarControllerPara
|
|||||||
from opendbc.car.gm.values import (malibu_hybrid_profile, MALIBU_HYBRID_SOURCES,
|
from opendbc.car.gm.values import (malibu_hybrid_profile, MALIBU_HYBRID_SOURCES,
|
||||||
is_volt_sdgm_accepted_envelope, volt_sdgm_accepted_accel_max)
|
is_volt_sdgm_accepted_envelope, volt_sdgm_accepted_accel_max)
|
||||||
from opendbc.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, LateralAccelFromTorqueCallbackType
|
from opendbc.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, LateralAccelFromTorqueCallbackType
|
||||||
|
from opendbc.car.vin import VIN_UNKNOWN, is_valid_vin
|
||||||
|
|
||||||
TransmissionType = structs.CarParams.TransmissionType
|
TransmissionType = structs.CarParams.TransmissionType
|
||||||
NetworkLocation = structs.CarParams.NetworkLocation
|
NetworkLocation = structs.CarParams.NetworkLocation
|
||||||
@@ -43,9 +44,16 @@ class CarInterface(CarInterfaceBase):
|
|||||||
structs.CarState.GearShifter.eco, structs.CarState.GearShifter.manumatic)
|
structs.CarState.GearShifter.eco, structs.CarState.GearShifter.manumatic)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_params(cls, candidate, fingerprint, car_fw, alpha_long, is_release, docs, *, auto_pedal=True):
|
def get_params(cls, candidate, fingerprint, car_fw, alpha_long, is_release, docs, *, auto_pedal=True, vin=VIN_UNKNOWN):
|
||||||
selected = pedal_candidate(candidate, fingerprint) if auto_pedal else candidate
|
selected = pedal_candidate(candidate, fingerprint) if auto_pedal else candidate
|
||||||
return super().get_params(selected, fingerprint, car_fw, alpha_long, is_release, docs)
|
ret = super().get_params(selected, fingerprint, car_fw, alpha_long, is_release, docs)
|
||||||
|
# The recorded 2018 Yukon XL SLT uses the same CC profile as the short Yukon.
|
||||||
|
if selected == CAR.GMC_YUKON_CC and is_valid_vin(vin) and vin.startswith('1GKS2GKC') and vin[9] == 'J':
|
||||||
|
ret.wheelbase = 3.302 # GMC 2018 Yukon brochure, 130.0 inches.
|
||||||
|
ret.centerToFront = ret.wheelbase * CAR.GMC_YUKON_CC.config.specs.centerToFrontRatio
|
||||||
|
ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase)
|
||||||
|
ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, ret.tireStiffnessFactor)
|
||||||
|
return ret
|
||||||
|
|
||||||
def apply(self, c, now_nanos=None, *, startup_keepalive=False):
|
def apply(self, c, now_nanos=None, *, startup_keepalive=False):
|
||||||
if startup_keepalive:
|
if startup_keepalive:
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from opendbc.car import car_helpers, gen_empty_fingerprint, scale_rot_inertia, structs
|
||||||
|
from opendbc.car.gm.values import CAR
|
||||||
|
from opendbc.car.vin import VIN_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('candidate,vin,xl', [
|
||||||
|
(CAR.GMC_YUKON_CC, '1GKS2GKC0JR000001', True),
|
||||||
|
(CAR.GMC_YUKON_CC, '1GKS2BKC0JR000001', False),
|
||||||
|
(CAR.GMC_YUKON_CC, '1GKS2GKC0KR000001', False),
|
||||||
|
(CAR.GMC_YUKON_CC, VIN_UNKNOWN, False),
|
||||||
|
(CAR.GMC_YUKON, '1GKS2GKC0JR000001', False),
|
||||||
|
(CAR.BUICK_LACROSSE_ASCM_19US, '1GKS2GKC0JR000001', False),
|
||||||
|
])
|
||||||
|
def test_manual_profile_retains_its_control_config_with_vin_geometry(candidate, vin, xl):
|
||||||
|
fp = gen_empty_fingerprint()
|
||||||
|
with patch.object(car_helpers, 'fingerprint', return_value=(None, fp, vin, [], structs.CarParams.FingerprintSource.can, True)):
|
||||||
|
cp = car_helpers.get_car(lambda **_: [], lambda _: None, lambda _: None, False, True, forced_candidate=candidate).CP
|
||||||
|
|
||||||
|
assert cp.carFingerprint == candidate and cp.fingerprintSource == structs.CarParams.FingerprintSource.fixed
|
||||||
|
baseline = car_helpers.interfaces[candidate].get_params(candidate, fp, [], False, True, False, auto_pedal=False)
|
||||||
|
assert cp.wheelbase == pytest.approx(3.302 if xl else baseline.wheelbase)
|
||||||
|
assert cp.centerToFront == pytest.approx(cp.wheelbase * candidate.config.specs.centerToFrontRatio)
|
||||||
|
assert cp.rotationalInertia == pytest.approx(scale_rot_inertia(cp.mass, cp.wheelbase))
|
||||||
|
assert cp.lateralTuning.to_dict() == baseline.lateralTuning.to_dict()
|
||||||
|
assert cp.safetyConfigs[0].to_dict() == baseline.safetyConfigs[0].to_dict()
|
||||||
|
assert cp.openpilotLongitudinalControl == baseline.openpilotLongitudinalControl
|
||||||
|
assert cp.steerRatio == baseline.steerRatio
|
||||||
@@ -204,7 +204,8 @@ class CarController(CarControllerBase):
|
|||||||
if _projection is not None:
|
if _projection is not None:
|
||||||
_projection.begin(CC.actuators.torque, self.frame)
|
_projection.begin(CC.actuators.torque, self.frame)
|
||||||
actuators = CC.actuators
|
actuators = CC.actuators
|
||||||
if self.CP.carFingerprint == CAR.KIA_EV6_2025 and self.CP.dashcamOnly:
|
if (self.CP.dashcamOnly and self.CP.carFingerprint in
|
||||||
|
(CAR.KIA_EV6_2025, CAR.HYUNDAI_KONA_EV_2023_NON_SCC, CAR.HYUNDAI_I30_2026)):
|
||||||
return actuators.as_builder(), []
|
return actuators.as_builder(), []
|
||||||
hud_control = CC.hudControl
|
hud_control = CC.hudControl
|
||||||
# Card finalizes the AOL safety marker after CarInterface constructs us.
|
# Card finalizes the AOL safety marker after CarInterface constructs us.
|
||||||
@@ -627,13 +628,15 @@ class CarController(CarControllerBase):
|
|||||||
now_nanos - min(CS.ccnc_161_ts_ns, CS.ccnc_162_ts_ns) <= 50_000_000 and
|
now_nanos - min(CS.ccnc_161_ts_ns, CS.ccnc_162_ts_ns) <= 50_000_000 and
|
||||||
abs(CS.ccnc_161_ts_ns - CS.ccnc_162_ts_ns) <= 50_000_000)
|
abs(CS.ccnc_161_ts_ns - CS.ccnc_162_ts_ns) <= 50_000_000)
|
||||||
if fresh_pair:
|
if fresh_pair:
|
||||||
|
show_cruise = CS.out.cruiseState.available and (not kona_handoff or CC.enabled)
|
||||||
support_current = (CS.ccnc_1b5_ts_ns > 0 and CS.ccnc_1b5_ts_ns <= now_nanos and
|
support_current = (CS.ccnc_1b5_ts_ns > 0 and CS.ccnc_1b5_ts_ns <= now_nanos and
|
||||||
abs(CS.ccnc_1b5_ts_ns - pair_ts) <= 50_000_000)
|
abs(CS.ccnc_1b5_ts_ns - pair_ts) <= 50_000_000)
|
||||||
can_sends.extend(hyundaicanfd.create_ccnc(self.packer, self.CAN, self.CP.openpilotLongitudinalControl,
|
can_sends.extend(hyundaicanfd.create_ccnc(self.packer, self.CAN, self.CP.openpilotLongitudinalControl,
|
||||||
CC.enabled, hud_control, CC.leftBlinker, CC.rightBlinker,
|
CC.enabled, hud_control, CC.leftBlinker, CC.rightBlinker,
|
||||||
CS.ccnc_161.copy(), CS.ccnc_162.copy(), CS.ccnc_1b5 if support_current else None,
|
CS.ccnc_161.copy(), CS.ccnc_162.copy(), CS.ccnc_1b5 if support_current else None,
|
||||||
CS.is_metric, CS.out, CS.out.cruiseState.available, CC.latActive,
|
CS.is_metric, CS.out, show_cruise, CC.latActive,
|
||||||
owned_lfa_status=(stock_ccnc_owned if self.ccnc_fault_ownership_required else None)))
|
owned_lfa_status=(stock_ccnc_owned if self.ccnc_fault_ownership_required else None),
|
||||||
|
owned_cruise_status=kona_handoff))
|
||||||
self.last_ccnc_161_ts_ns = CS.ccnc_161_ts_ns
|
self.last_ccnc_161_ts_ns = CS.ccnc_161_ts_ns
|
||||||
self.last_ccnc_162_ts_ns = CS.ccnc_162_ts_ns
|
self.last_ccnc_162_ts_ns = CS.ccnc_162_ts_ns
|
||||||
else:
|
else:
|
||||||
@@ -693,7 +696,12 @@ class CarController(CarControllerBase):
|
|||||||
lead = (self.torque_ev_lead_inputs.update(CS.torque_ev_camera_lead, hud_control.leadVisible, now_nanos)
|
lead = (self.torque_ev_lead_inputs.update(CS.torque_ev_camera_lead, hud_control.leadVisible, now_nanos)
|
||||||
if self.torque_ev_lead_inputs is not None else
|
if self.torque_ev_lead_inputs is not None else
|
||||||
fallback_lead(CS.torque_ev_camera_lead, hud_control.leadVisible, self.torque_ev_floor_boot_ns))
|
fallback_lead(CS.torque_ev_camera_lead, hud_control.leadVisible, self.torque_ev_floor_boot_ns))
|
||||||
acc_options = torque_ev_scc_options(CS.out.cruiseState.available, CC.actuators.longControlState, lead)
|
acc_options = torque_ev_scc_options(CS.out.cruiseState.available and (not kona_handoff or CC.enabled),
|
||||||
|
CC.actuators.longControlState, lead)
|
||||||
|
if (kona_handoff and CC.longActive and not CC.cruiseControl.override and stopping and
|
||||||
|
not (CS.out.standstill or CS.out.brakePressed or CS.out.gasPressed or hud_control.leadVisible or lead.visible) and
|
||||||
|
0.0 < CS.out.vEgo < 3.0 and self.CP.stopAccel < accel < 0.0 and accel >= self.accel_last - 0.02):
|
||||||
|
acc_options["jerk_lower"] = 1.2
|
||||||
elif is_gv70(self.CP):
|
elif is_gv70(self.CP):
|
||||||
request = scc_request(CC.enabled, CC.cruiseControl.override, stopping, accel, self.accel_last)
|
request = scc_request(CC.enabled, CC.cruiseControl.override, stopping, accel, self.accel_last)
|
||||||
accel = request.accel
|
accel = request.accel
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ BUTTONS_DICT = {Buttons.RES_ACCEL: ButtonType.accelCruise, Buttons.SET_DECEL: Bu
|
|||||||
|
|
||||||
|
|
||||||
def get_non_scc_cruise_signals(flags: int, car=None) -> tuple[str, str, str, str, str, str]:
|
def get_non_scc_cruise_signals(flags: int, car=None) -> tuple[str, str, str, str, str, str]:
|
||||||
if car == CAR.KIA_RAY_EV:
|
if car in (CAR.KIA_RAY_EV, CAR.HYUNDAI_KONA_EV_2023_NON_SCC):
|
||||||
return "LABEL11", "CC_React", "LABEL11", "CC_Engaged", "E_EMS11", "Cruise_Limit_Target"
|
return "LABEL11", "CC_React", "LABEL11", "CC_Engaged", "E_EMS11", "Cruise_Limit_Target"
|
||||||
if flags & HyundaiFlags.EV:
|
if flags & HyundaiFlags.EV:
|
||||||
return "LABEL11", "CC_React", "EMS12", "ACC_ACT", "E_EMS11", "Cruise_Limit_Target"
|
return "LABEL11", "CC_React", "EMS12", "ACC_ACT", "E_EMS11", "Cruise_Limit_Target"
|
||||||
@@ -260,6 +260,8 @@ class CarState(CarStateBase):
|
|||||||
available_msg, available_sig, enabled_msg, enabled_sig, speed_msg, speed_sig = get_non_scc_cruise_signals(self.CP.flags, self.CP.carFingerprint)
|
available_msg, available_sig, enabled_msg, enabled_sig, speed_msg, speed_sig = get_non_scc_cruise_signals(self.CP.flags, self.CP.carFingerprint)
|
||||||
ret.cruiseState.available = cp.vl[available_msg][available_sig] != 0
|
ret.cruiseState.available = cp.vl[available_msg][available_sig] != 0
|
||||||
ret.cruiseState.enabled = cp.vl[enabled_msg][enabled_sig] != 0
|
ret.cruiseState.enabled = cp.vl[enabled_msg][enabled_sig] != 0
|
||||||
|
if self.CP.carFingerprint == CAR.HYUNDAI_KONA_EV_2023_NON_SCC:
|
||||||
|
ret.cruiseState.enabled &= ret.cruiseState.available
|
||||||
ret.cruiseState.standstill = False
|
ret.cruiseState.standstill = False
|
||||||
ret.cruiseState.nonAdaptive = False
|
ret.cruiseState.nonAdaptive = False
|
||||||
ret.cruiseState.speed = cp.vl[speed_msg][speed_sig] * speed_conv
|
ret.cruiseState.speed = cp.vl[speed_msg][speed_sig] * speed_conv
|
||||||
@@ -415,6 +417,11 @@ class CarState(CarStateBase):
|
|||||||
ret.buttonEvents = button_events
|
ret.buttonEvents = button_events
|
||||||
|
|
||||||
ret.blockPcmEnable = not self.recent_button_interaction()
|
ret.blockPcmEnable = not self.recent_button_interaction()
|
||||||
|
if self.CP.carFingerprint == CAR.HYUNDAI_KONA_EV_2023_NON_SCC:
|
||||||
|
set_or_resume = next((not main and button in (Buttons.SET_DECEL, Buttons.RES_ACCEL)
|
||||||
|
for button, main in zip(reversed(self.cruise_buttons), reversed(self.main_buttons), strict=True)
|
||||||
|
if main or button in ENABLE_BUTTONS), False)
|
||||||
|
ret.blockPcmEnable = not set_or_resume or ret.brakePressed or ret.gasPressed
|
||||||
|
|
||||||
# low speed steer alert hysteresis logic (only for cars with steer cut off above 10 m/s)
|
# low speed steer alert hysteresis logic (only for cars with steer cut off above 10 m/s)
|
||||||
if ret.vEgo < (self.CP.minSteerSpeed + 2.) and self.CP.minSteerSpeed > 10.:
|
if ret.vEgo < (self.CP.minSteerSpeed + 2.) and self.CP.minSteerSpeed > 10.:
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import time
|
import time
|
||||||
from itertools import product
|
from itertools import product
|
||||||
|
|
||||||
|
from opendbc.car.hyundai.values import CAR
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
from opendbc.car.vin import is_valid_vin
|
||||||
|
|
||||||
|
|
||||||
NORMAL_BUS_LAYOUT = {(2, 0x110): 32, (2, 0x362): 32, (1, 0x35): 32,
|
NORMAL_BUS_LAYOUT = {(2, 0x110): 32, (2, 0x362): 32, (1, 0x35): 32,
|
||||||
(1, 0xEA): 24, (1, 0xA0): 24, (1, 0x1A0): 32,
|
(1, 0xEA): 24, (1, 0xA0): 24, (1, 0x1A0): 32,
|
||||||
@@ -32,6 +36,29 @@ QUIET_CAMERA_NORMAL_BUS_LAYOUT = {(0, 0xEA): 24, (0, 0xA0): 24, (0, 0x1A0): 32,
|
|||||||
**{(1, address): 32 for address in range(0x210, 0x220)}}
|
**{(1, address): 32 for address in range(0x210, 0x220)}}
|
||||||
|
|
||||||
|
|
||||||
|
def kona_electric_se_candidate(vin, fingerprint, car_fw):
|
||||||
|
if not is_valid_vin(vin) or vin[:8] != 'KM8K23AG' or vin[9] != 'P':
|
||||||
|
return None
|
||||||
|
|
||||||
|
layout = {(0, 0x251): 8, (0, 0x371): 8, (0, 0x386): 8, (0, 0x394): 8, (0, 0x4F1): 4,
|
||||||
|
(0, 0x592): 8, (1, 0x329): 8, (2, 0x340): 8}
|
||||||
|
if any(fingerprint.get(bus, {}).get(addr) != length for (bus, addr), length in layout.items()):
|
||||||
|
return None
|
||||||
|
if any(frames.keys() & {0x420, 0x421} for frames in fingerprint.values()):
|
||||||
|
return None
|
||||||
|
|
||||||
|
ecu = CarParams.Ecu
|
||||||
|
if any(fw.ecu == ecu.fwdRadar or (fw.address == 0x7D0 and fw.brand == 'hyundai') for fw in car_fw):
|
||||||
|
return None
|
||||||
|
observed_fw = {(fw.ecu.raw, fw.address, bytes(fw.fwVersion)) for fw in car_fw
|
||||||
|
if fw.brand == 'hyundai' and fw.bus == 0 and not fw.subAddress and not fw.logging}
|
||||||
|
expected_fw = {
|
||||||
|
(ecu.eps, 0x7D4, b'\xf1\x00OSP MDPS C 1.00 1.02 56310K4261\x00 4OEPC102'),
|
||||||
|
(ecu.fwdCamera, 0x7C4, b'\xf1\x00OSP LKA AT USA LHD 1.00 1.04 99211-J9200 904'),
|
||||||
|
}
|
||||||
|
return CAR.HYUNDAI_KONA_EV_2023_NON_SCC if expected_fw <= observed_fw else None
|
||||||
|
|
||||||
|
|
||||||
def _canfd_variant_layouts():
|
def _canfd_variant_layouts():
|
||||||
layouts = []
|
layouts = []
|
||||||
originals = (NORMAL_BUS_LAYOUT, HDA1_NORMAL_BUS_LAYOUT, HDA2_NORMAL_BUS_LAYOUT)
|
originals = (NORMAL_BUS_LAYOUT, HDA1_NORMAL_BUS_LAYOUT, HDA2_NORMAL_BUS_LAYOUT)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
""" AUTO-FORMATTED USING opendbc/car/debug/format_fingerprints.py, EDIT STRUCTURE THERE."""
|
""" AUTO-FORMATTED USING opendbc/car/debug/format_fingerprints.py, EDIT STRUCTURE THERE."""
|
||||||
from opendbc.car.structs import CarParams
|
from opendbc.car.structs import CarParams
|
||||||
from opendbc.car.hyundai.values import CAR
|
from opendbc.car.hyundai.values import CAR, CARNIVAL_2027_CAMERA_FW
|
||||||
|
|
||||||
Ecu = CarParams.Ecu
|
Ecu = CarParams.Ecu
|
||||||
|
|
||||||
@@ -153,10 +153,12 @@ FW_VERSIONS = {
|
|||||||
},
|
},
|
||||||
CAR.KIA_CARNIVAL_2025: {
|
CAR.KIA_CARNIVAL_2025: {
|
||||||
(Ecu.fwdCamera, 0x7c4, None): [
|
(Ecu.fwdCamera, 0x7c4, None): [
|
||||||
|
CARNIVAL_2027_CAMERA_FW,
|
||||||
b'\xf1\x00KA4 MFC AT CAN LHD 1.00 1.00 99210-R0700 250324',
|
b'\xf1\x00KA4 MFC AT CAN LHD 1.00 1.00 99210-R0700 250324',
|
||||||
b'\xf1\x00KA4 MFC AT USA LHD 1.00 1.05 99210-R0500 240305',
|
b'\xf1\x00KA4 MFC AT USA LHD 1.00 1.05 99210-R0500 240305',
|
||||||
],
|
],
|
||||||
(Ecu.fwdRadar, 0x7d0, None): [
|
(Ecu.fwdRadar, 0x7d0, None): [
|
||||||
|
b'\xf1\x00KA4_ RDR ----- 1.00 1.02 99110-R0510 ',
|
||||||
b'\xf1\x00KA4_ SCC FHCUP 1.00 1.01 99110-R0510 ',
|
b'\xf1\x00KA4_ SCC FHCUP 1.00 1.01 99110-R0510 ',
|
||||||
b'\xf1\x00KA4_ RDR ----- 1.00 1.01 99110-R0510 ',
|
b'\xf1\x00KA4_ RDR ----- 1.00 1.01 99110-R0510 ',
|
||||||
],
|
],
|
||||||
@@ -1178,6 +1180,17 @@ FW_VERSIONS = {
|
|||||||
b'\xf1\x00PD__ SCC FNCUP 1.01 1.00 96400-G3000 ',
|
b'\xf1\x00PD__ SCC FNCUP 1.01 1.00 96400-G3000 ',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
CAR.HYUNDAI_I30_2026: {
|
||||||
|
(Ecu.fwdCamera, 0x7c4, None): [
|
||||||
|
b'\xf1\x00PD MFC AT EUR LHD 1.00 1.01 99211-G4600 251223',
|
||||||
|
],
|
||||||
|
(Ecu.eps, 0x7d4, None): [
|
||||||
|
b'\xf1\x00PDe MDPS C 1.00 1.00 56300G4BB0 4P3EC100',
|
||||||
|
],
|
||||||
|
(Ecu.fwdRadar, 0x7d0, None): [
|
||||||
|
b'\xf1\x00PDe_ RDR ----- 1.00 1.01 99110-G4500 ',
|
||||||
|
],
|
||||||
|
},
|
||||||
CAR.HYUNDAI_ELANTRA_2021: {
|
CAR.HYUNDAI_ELANTRA_2021: {
|
||||||
(Ecu.fwdRadar, 0x7d0, None): [
|
(Ecu.fwdRadar, 0x7d0, None): [
|
||||||
b'\xf1\x00CN7_ SCC F-CUP 1.00 1.01 99110-AA000 ',
|
b'\xf1\x00CN7_ SCC F-CUP 1.00 1.01 99110-AA000 ',
|
||||||
@@ -1401,6 +1414,7 @@ FW_VERSIONS = {
|
|||||||
b'\xf1\x00NX4 FR_CMR AT EUR LHD 1.00 1.00 99211-N9220 14K',
|
b'\xf1\x00NX4 FR_CMR AT EUR LHD 1.00 1.00 99211-N9220 14K',
|
||||||
b'\xf1\x00NX4 FR_CMR AT EUR LHD 1.00 1.00 99211-N9240 14Q',
|
b'\xf1\x00NX4 FR_CMR AT EUR LHD 1.00 1.00 99211-N9240 14Q',
|
||||||
b'\xf1\x00NX4 FR_CMR AT EUR LHD 1.00 2.02 99211-N9000 14E',
|
b'\xf1\x00NX4 FR_CMR AT EUR LHD 1.00 2.02 99211-N9000 14E',
|
||||||
|
b'\xf1\x00NX4 FR_CMR AT USA LHD 1.00 1.00 99211-CW010 14X',
|
||||||
b'\xf1\x00NX4 FR_CMR AT USA LHD 1.00 1.00 99211-N9210 14G',
|
b'\xf1\x00NX4 FR_CMR AT USA LHD 1.00 1.00 99211-N9210 14G',
|
||||||
b'\xf1\x00NX4 FR_CMR AT USA LHD 1.00 1.00 99211-N9220 14K',
|
b'\xf1\x00NX4 FR_CMR AT USA LHD 1.00 1.00 99211-N9220 14K',
|
||||||
b'\xf1\x00NX4 FR_CMR AT USA LHD 1.00 1.00 99211-N9240 14Q',
|
b'\xf1\x00NX4 FR_CMR AT USA LHD 1.00 1.00 99211-N9240 14Q',
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ def create_lkas11(packer, frame, CP, apply_torque, steer_req,
|
|||||||
if CP.carFingerprint in (CAR.HYUNDAI_SONATA, CAR.HYUNDAI_PALISADE, CAR.KIA_NIRO_EV, CAR.KIA_NIRO_HEV_2021, CAR.KIA_NIRO_PHEV_2022, CAR.HYUNDAI_SANTA_FE,
|
if CP.carFingerprint in (CAR.HYUNDAI_SONATA, CAR.HYUNDAI_PALISADE, CAR.KIA_NIRO_EV, CAR.KIA_NIRO_HEV_2021, CAR.KIA_NIRO_PHEV_2022, CAR.HYUNDAI_SANTA_FE,
|
||||||
CAR.HYUNDAI_IONIQ_EV_2020, CAR.HYUNDAI_IONIQ_PHEV, CAR.KIA_SELTOS, CAR.HYUNDAI_ELANTRA_2021, CAR.GENESIS_G70_2020,
|
CAR.HYUNDAI_IONIQ_EV_2020, CAR.HYUNDAI_IONIQ_PHEV, CAR.KIA_SELTOS, CAR.HYUNDAI_ELANTRA_2021, CAR.GENESIS_G70_2020,
|
||||||
CAR.HYUNDAI_ELANTRA_HEV_2021, CAR.HYUNDAI_SONATA_HYBRID, CAR.HYUNDAI_KONA_EV, CAR.HYUNDAI_KONA_HEV, CAR.HYUNDAI_KONA_EV_2022,
|
CAR.HYUNDAI_ELANTRA_HEV_2021, CAR.HYUNDAI_SONATA_HYBRID, CAR.HYUNDAI_KONA_EV, CAR.HYUNDAI_KONA_HEV, CAR.HYUNDAI_KONA_EV_2022,
|
||||||
|
CAR.HYUNDAI_KONA_EV_2023_NON_SCC,
|
||||||
CAR.HYUNDAI_SANTA_FE_2022, CAR.KIA_K5_2021, CAR.HYUNDAI_IONIQ_HEV_2022, CAR.HYUNDAI_SANTA_FE_HEV_2022,
|
CAR.HYUNDAI_SANTA_FE_2022, CAR.KIA_K5_2021, CAR.HYUNDAI_IONIQ_HEV_2022, CAR.HYUNDAI_SANTA_FE_HEV_2022,
|
||||||
CAR.HYUNDAI_SANTA_FE_PHEV_2022, CAR.KIA_STINGER_2022, CAR.KIA_K5_HEV_2020, CAR.KIA_CEED, CAR.KIA_XCEED_PHEV, CAR.KIA_CEED_PHEV,
|
CAR.HYUNDAI_SANTA_FE_PHEV_2022, CAR.KIA_STINGER_2022, CAR.KIA_K5_HEV_2020, CAR.KIA_CEED, CAR.KIA_XCEED_PHEV, CAR.KIA_CEED_PHEV,
|
||||||
CAR.HYUNDAI_AZERA_6TH_GEN, CAR.HYUNDAI_AZERA_HEV_6TH_GEN, CAR.HYUNDAI_CUSTIN_1ST_GEN, CAR.HYUNDAI_KONA_2022,
|
CAR.HYUNDAI_AZERA_6TH_GEN, CAR.HYUNDAI_AZERA_HEV_6TH_GEN, CAR.HYUNDAI_CUSTIN_1ST_GEN, CAR.HYUNDAI_KONA_2022,
|
||||||
|
|||||||
@@ -329,7 +329,7 @@ def create_ioniq6_blindspot_status(counter: int, status: BlindspotStatus, *, bus
|
|||||||
|
|
||||||
# Source-derived CCNC camera display transform; the repository MIT notice applies.
|
# Source-derived CCNC camera display transform; the repository MIT notice applies.
|
||||||
def create_ccnc(packer, CAN, openpilot_longitudinal, enabled, hud, left_blinker, right_blinker, msg_161, msg_162, msg_1b5,
|
def create_ccnc(packer, CAN, openpilot_longitudinal, enabled, hud, left_blinker, right_blinker, msg_161, msg_162, msg_1b5,
|
||||||
is_metric, out, main_cruise_enabled, lfa_icon, *, owned_lfa_status=None):
|
is_metric, out, main_cruise_enabled, lfa_icon, *, owned_lfa_status=None, owned_cruise_status=False):
|
||||||
if owned_lfa_status or (owned_lfa_status is None and lfa_icon):
|
if owned_lfa_status or (owned_lfa_status is None and lfa_icon):
|
||||||
# The host owns lateral; keep unrelated faults and obstruction warnings.
|
# The host owns lateral; keep unrelated faults and obstruction warnings.
|
||||||
for field in ("FAULT_LSS", "FAULT_HDA", "FAULT_DAS", "FAULT_LFA", "FAULT_DAW"):
|
for field in ("FAULT_LSS", "FAULT_HDA", "FAULT_DAS", "FAULT_LFA", "FAULT_DAW"):
|
||||||
@@ -413,6 +413,9 @@ def create_ccnc(packer, CAN, openpilot_longitudinal, enabled, hud, left_blinker,
|
|||||||
"DISTANCE_LEAD": 0 if not main_cruise_enabled else 2 if enabled and hud.leadVisible else 1 if hud.leadVisible else 0,
|
"DISTANCE_LEAD": 0 if not main_cruise_enabled else 2 if enabled and hud.leadVisible else 1 if hud.leadVisible else 0,
|
||||||
"DISTANCE_CAR": 0 if not main_cruise_enabled else 2 if enabled else 1,
|
"DISTANCE_CAR": 0 if not main_cruise_enabled else 2 if enabled else 1,
|
||||||
})
|
})
|
||||||
|
if owned_cruise_status:
|
||||||
|
msg_161["SETSPEED"] = msg_161["SETSPEED_HUD"]
|
||||||
|
msg_161["DISTANCE"] = hud.leadDistanceBars if main_cruise_enabled else 0
|
||||||
msg_162["LEAD"] = 0 if not main_cruise_enabled else 2 if enabled else 1
|
msg_162["LEAD"] = 0 if not main_cruise_enabled else 2 if enabled else 1
|
||||||
if msg_1b5 is not None:
|
if msg_1b5 is not None:
|
||||||
msg_162["LEAD_DISTANCE"] = msg_1b5["Longitudinal_Distance"]
|
msg_162["LEAD_DISTANCE"] = msg_1b5["Longitudinal_Distance"]
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ from opendbc.car.hyundai.ioniq5pe_long_profile import required as pe_long_requir
|
|||||||
from opendbc.car.pedal import supported_pedal_detected
|
from opendbc.car.pedal import supported_pedal_detected
|
||||||
from opendbc.car.hyundai.classic_scc_aol import CLASSIC_SCC_IDS
|
from opendbc.car.hyundai.classic_scc_aol import CLASSIC_SCC_IDS
|
||||||
from opendbc.car import Bus, get_safety_config, structs, uds
|
from opendbc.car import Bus, get_safety_config, structs, uds
|
||||||
|
from opendbc.car.hyundai.discovery import kona_electric_se_candidate
|
||||||
from opendbc.car.hyundai.hyundaicanfd import CanBus
|
from opendbc.car.hyundai.hyundaicanfd import CanBus
|
||||||
from opendbc.car.hyundai.non_scc_aol import NON_SCC_IDS
|
from opendbc.car.hyundai.non_scc_aol import NON_SCC_IDS
|
||||||
from opendbc.car.hyundai.values import (is_blended, is_blended_alpha, HyundaiFlags, CAR, DBC, HyundaiSafetyFlags, CANFD_ANGLE_MODEL_BITS,
|
from opendbc.car.hyundai.values import (is_blended, is_blended_alpha, HyundaiFlags, CAR, DBC, HyundaiSafetyFlags, CANFD_ANGLE_MODEL_BITS,
|
||||||
CANFD_ANGLE_OBSERVED_ADAS_BIT, HYUNDAI_MRR35_RADAR_DBC, HYUNDAI_MRR30_RADAR_DBC,
|
CANFD_ANGLE_OBSERVED_ADAS_BIT, CARNIVAL_2027_CAMERA_FW, HYUNDAI_MRR35_RADAR_DBC, HYUNDAI_MRR30_RADAR_DBC,
|
||||||
HYUNDAI_GV70_RADAR_DBC, HYUNDAI_G90_RADAR_DBC, HYUNDAI_MRREVO14F_RADAR_DBC)
|
HYUNDAI_GV70_RADAR_DBC, HYUNDAI_G90_RADAR_DBC, HYUNDAI_MRREVO14F_RADAR_DBC)
|
||||||
from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR, MRR35_RADAR_START_ADDR, MRR30_RADAR_START_ADDR, radar_bus, \
|
from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR, MRR35_RADAR_START_ADDR, MRR30_RADAR_START_ADDR, radar_bus, \
|
||||||
stinger_2022_radar_available
|
stinger_2022_radar_available
|
||||||
@@ -121,10 +122,30 @@ class CarInterface(CarInterfaceBase):
|
|||||||
return -3.5, 3.5
|
return -3.5, 3.5
|
||||||
return CarInterfaceBase.get_pid_accel_limits(CP, current_speed, cruise_speed, faster_takeoffs=faster_takeoffs)
|
return CarInterfaceBase.get_pid_accel_limits(CP, current_speed, cruise_speed, faster_takeoffs=faster_takeoffs)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_params(cls, candidate, fingerprint, car_fw, alpha_long, is_release, docs, *, vin=""):
|
||||||
|
cp = super().get_params(candidate, fingerprint, car_fw, alpha_long, is_release, docs)
|
||||||
|
if candidate == CAR.HYUNDAI_KONA_EV_2023_NON_SCC:
|
||||||
|
identified = kona_electric_se_candidate(vin, fingerprint, car_fw) == candidate
|
||||||
|
if (identified and fingerprint.get(0, {}).get(0x391) == 8 and fingerprint.get(2, {}).get(0x485) == 4 and
|
||||||
|
cp.safetyConfigs[-1].safetyParam == 0x1841):
|
||||||
|
cp.safetyConfigs[-1].safetyParam |= HyundaiSafetyFlags.KONA_EV_LABEL_CRUISE.value
|
||||||
|
else:
|
||||||
|
cp.dashcamOnly = True
|
||||||
|
cp.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.noOutput)]
|
||||||
|
cp.autoResumeSng = False
|
||||||
|
return cp
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, alpha_long, is_release, docs) -> structs.CarParams:
|
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, alpha_long, is_release, docs) -> structs.CarParams:
|
||||||
ret.brand = "hyundai"
|
ret.brand = "hyundai"
|
||||||
|
|
||||||
|
if candidate == CAR.HYUNDAI_I30_2026:
|
||||||
|
ret.dashcamOnly = True
|
||||||
|
ret.radarUnavailable = True
|
||||||
|
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.noOutput)]
|
||||||
|
return ret
|
||||||
|
|
||||||
if is_blended(ret):
|
if is_blended(ret):
|
||||||
cam_can = CanBus(None, fingerprint).CAM
|
cam_can = CanBus(None, fingerprint).CAM
|
||||||
lka_steering = any(fw.ecu == Ecu.adas for fw in car_fw) or 0x50 in fingerprint[cam_can]
|
lka_steering = any(fw.ecu == Ecu.adas for fw in car_fw) or 0x50 in fingerprint[cam_can]
|
||||||
@@ -310,6 +331,8 @@ class CarInterface(CarInterfaceBase):
|
|||||||
ret.alphaLongitudinalAvailable = not is_release
|
ret.alphaLongitudinalAvailable = not is_release
|
||||||
alpha_long = False
|
alpha_long = False
|
||||||
from opendbc.car.hyundai.legacy_long_aol import CARS as legacy_long_cars
|
from opendbc.car.hyundai.legacy_long_aol import CARS as legacy_long_cars
|
||||||
|
if candidate == CAR.KIA_CARNIVAL_2025 and any(fw.ecu == Ecu.fwdCamera and fw.fwVersion == CARNIVAL_2027_CAMERA_FW for fw in car_fw):
|
||||||
|
ret.alphaLongitudinalAvailable = False
|
||||||
ret.openpilotLongitudinalControl = alpha_long and ret.alphaLongitudinalAvailable and candidate not in legacy_long_cars
|
ret.openpilotLongitudinalControl = alpha_long and ret.alphaLongitudinalAvailable and candidate not in legacy_long_cars
|
||||||
if (candidate in (CAR.KIA_CARNIVAL_2025, CAR.KIA_CARNIVAL_HEV_4TH_GEN) and
|
if (candidate in (CAR.KIA_CARNIVAL_2025, CAR.KIA_CARNIVAL_HEV_4TH_GEN) and
|
||||||
ret.flags & HyundaiFlags.CANFD_ALT_BUTTONS and 0x1aa in fingerprint[CAN.ECAN] and
|
ret.flags & HyundaiFlags.CANFD_ALT_BUTTONS and 0x1aa in fingerprint[CAN.ECAN] and
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ from opendbc.car import structs
|
|||||||
from opendbc.car.hyundai.values import CAR, HyundaiFlags, HyundaiSafetyFlags
|
from opendbc.car.hyundai.values import CAR, HyundaiFlags, HyundaiSafetyFlags
|
||||||
|
|
||||||
NON_SCC_IDS = frozenset((CAR.HYUNDAI_BAYON_1ST_GEN_NON_SCC, CAR.HYUNDAI_ELANTRA_2022_NON_SCC,
|
NON_SCC_IDS = frozenset((CAR.HYUNDAI_BAYON_1ST_GEN_NON_SCC, CAR.HYUNDAI_ELANTRA_2022_NON_SCC,
|
||||||
CAR.HYUNDAI_ELANTRA_HEV_2022_NON_SCC, CAR.HYUNDAI_KONA_NON_SCC, CAR.HYUNDAI_KONA_EV_NON_SCC,
|
CAR.HYUNDAI_ELANTRA_HEV_2022_NON_SCC, CAR.HYUNDAI_KONA_NON_SCC, CAR.HYUNDAI_KONA_EV_NON_SCC, CAR.HYUNDAI_KONA_EV_2023_NON_SCC,
|
||||||
CAR.KIA_CEED_PHEV_2022_NON_SCC, CAR.KIA_FORTE_2019_NON_SCC, CAR.KIA_FORTE_2021_NON_SCC,
|
CAR.KIA_CEED_PHEV_2022_NON_SCC, CAR.KIA_FORTE_2019_NON_SCC, CAR.KIA_FORTE_2021_NON_SCC,
|
||||||
CAR.KIA_SELTOS_2023_NON_SCC, CAR.GENESIS_G70_2021_NON_SCC))
|
CAR.KIA_SELTOS_2023_NON_SCC, CAR.GENESIS_G70_2021_NON_SCC))
|
||||||
SOFTWARE_CRUISE = 0x0020
|
SOFTWARE_CRUISE = 0x0020
|
||||||
AOL_MARKER = 0x0400
|
AOL_MARKER = 0x0400
|
||||||
AOL_EXPERIENCE = 32
|
AOL_EXPERIENCE = 32
|
||||||
AOL_WORDS = frozenset((0x1400, 0x1c00, 0x1440, 0x1c40, 0x1441, 0x1c41, 0x1402, 0x1c02))
|
AOL_WORDS = frozenset((0x1400, 0x1c00, 0x1440, 0x1c40, 0x1441, 0x1c41, 0x1c51, 0x1402, 0x1c02))
|
||||||
|
|
||||||
|
|
||||||
def stock_word(cp):
|
def stock_word(cp):
|
||||||
@@ -27,6 +27,8 @@ def stock_word(cp):
|
|||||||
word |= int(safety)
|
word |= int(safety)
|
||||||
if cp.flags & HyundaiFlags.HAS_LDA_BUTTON:
|
if cp.flags & HyundaiFlags.HAS_LDA_BUTTON:
|
||||||
word |= int(HyundaiSafetyFlags.HAS_LDA_BUTTON)
|
word |= int(HyundaiSafetyFlags.HAS_LDA_BUTTON)
|
||||||
|
if cp.carFingerprint == CAR.HYUNDAI_KONA_EV_2023_NON_SCC:
|
||||||
|
word |= int(HyundaiSafetyFlags.KONA_EV_LABEL_CRUISE)
|
||||||
return word
|
return word
|
||||||
|
|
||||||
|
|
||||||
@@ -47,6 +49,9 @@ def qualified(cp):
|
|||||||
# The observed alternative CLU source is marked only at the AOL boundary;
|
# The observed alternative CLU source is marked only at the AOL boundary;
|
||||||
# ordinary safety may still use its original MAIN-only profile.
|
# ordinary safety may still use its original MAIN-only profile.
|
||||||
ordinary = word & ~int(HyundaiSafetyFlags.HAS_LDA_BUTTON)
|
ordinary = word & ~int(HyundaiSafetyFlags.HAS_LDA_BUTTON)
|
||||||
|
if cp.carFingerprint == CAR.HYUNDAI_KONA_EV_2023_NON_SCC:
|
||||||
|
return (safety.safetyModel == structs.CarParams.SafetyModel.hyundai and
|
||||||
|
(safety.safetyParam & ~SOFTWARE_CRUISE) in (0x1851, 0x1C51))
|
||||||
return (safety.safetyModel == structs.CarParams.SafetyModel.hyundai and
|
return (safety.safetyModel == structs.CarParams.SafetyModel.hyundai and
|
||||||
(safety.safetyParam & ~SOFTWARE_CRUISE) in (word, ordinary, word | AOL_MARKER))
|
(safety.safetyParam & ~SOFTWARE_CRUISE) in (word, ordinary, word | AOL_MARKER))
|
||||||
|
|
||||||
|
|||||||
@@ -122,3 +122,31 @@ def test_exact_recorded_configuration_keeps_irq_fault_blocking():
|
|||||||
assert cp.alternativeExperience == 0 and cp.pcmCruise and not cp.openpilotLongitudinalControl
|
assert cp.alternativeExperience == 0 and cp.pcmCruise and not cp.openpilotLongitudinalControl
|
||||||
assert blocking_fault_mask(8, cp)
|
assert blocking_fault_mask(8, cp)
|
||||||
assert blocking_fault_list([log.PandaState.FaultType.interruptRateCan2], cp)
|
assert blocking_fault_list([log.PandaState.FaultType.interruptRateCan2], cp)
|
||||||
|
|
||||||
|
|
||||||
|
def test_carnival_2027_uses_the_gas_ccnc_profile_and_standard_stock_acc():
|
||||||
|
from opendbc.car import gen_empty_fingerprint
|
||||||
|
from opendbc.car.fw_versions import match_fw_to_car
|
||||||
|
from opendbc.car.hyundai.interface import CarInterface
|
||||||
|
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
|
||||||
|
fw = [CarParams.CarFw(ecu=ecu, address=address, fwVersion=version, brand='hyundai') for ecu, address, version in (
|
||||||
|
(CarParams.Ecu.fwdCamera, 0x7c4, b'\xf1\x00KA4 MFC AT USA LHD 1.00 1.02 99210-R0800 251031'),
|
||||||
|
(CarParams.Ecu.fwdRadar, 0x7d0, b'\xf1\x00KA4_ RDR ----- 1.00 1.02 99110-R0510 '),
|
||||||
|
(CarParams.Ecu.adas, 0x730, b'\xf1\x00KA4 FBL6 1.00 1.02 251159'),
|
||||||
|
)]
|
||||||
|
exact, matches = match_fw_to_car(fw, VIN_UNKNOWN)
|
||||||
|
assert exact and matches == {CAR.KIA_CARNIVAL_2025}
|
||||||
|
observed = gen_empty_fingerprint()
|
||||||
|
observed[0].update({0x3A5: 24})
|
||||||
|
observed[1].update({0x100: 32, 0x40: 32, 0xEA: 24, 0xA0: 24, 0x1A0: 32, 0x1CF: 8, 0x1AA: 16})
|
||||||
|
observed[2].update({0x110: 32, 0x362: 32})
|
||||||
|
frames = [CanData(address, bytes(length), bus) for bus in (0, 1, 2) for address, length in observed[bus].items()]
|
||||||
|
assert normal_bus_topology(lambda **kw: [frames])
|
||||||
|
for alpha_requested in (False, True):
|
||||||
|
cp = CarInterface.get_params(CAR.KIA_CARNIVAL_2025, observed, fw, alpha_requested, False, False)
|
||||||
|
assert cp.pcmCruise and not cp.openpilotLongitudinalControl and not cp.alphaLongitudinalAvailable
|
||||||
|
assert cp.flags & HyundaiFlags.CANFD_LKA_STEER_MSG_ALT
|
||||||
|
assert not cp.flags & (HyundaiFlags.CANFD_ALT_BUTTONS | HyundaiFlags.HYBRID)
|
||||||
|
assert cp.safetyConfigs[-1].safetyParam == 0x90
|
||||||
|
|||||||
@@ -236,3 +236,71 @@ def test_kona_factory_handoff_is_limited_to_healthy_internal_c4(panda_type, faul
|
|||||||
panda = SimpleNamespace(pandaType=panda_type, faults=faults, ignitionLine=True, ignitionCan=False, controlsAllowed=False)
|
panda = SimpleNamespace(pandaType=panda_type, faults=faults, ignitionLine=True, ignitionCan=False, controlsAllowed=False)
|
||||||
configure_kona_factory_handoff(cp, [panda])
|
configure_kona_factory_handoff(cp, [panda])
|
||||||
assert cp.safetyConfigs[0].safetyParam == expected
|
assert cp.safetyConfigs[0].safetyParam == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('handoff,enabled,hud_mode', ((True, False, 0), (True, True, 2), (False, False, 1)))
|
||||||
|
def test_kona_handoff_cruise_main_display_follows_star_long_engagement(handoff, enabled, hud_mode):
|
||||||
|
from opendbc.can import CANParser
|
||||||
|
cp = kona_params(CARS[0])
|
||||||
|
cp.safetyConfigs[0].safetyParam = 0x1C0C if handoff else 0x0C0C
|
||||||
|
cp.alternativeExperience = 32
|
||||||
|
ci = CarInterface(cp)
|
||||||
|
ci.CS.out = structs.CarState(cruiseState={'available': True}, vCruiseCluster=40.).as_reader()
|
||||||
|
for frame in range(5):
|
||||||
|
ci.apply(structs.CarControl().as_reader(), 950_000_000 + frame * 10_000_000)
|
||||||
|
ci.CS.ccnc_161_ts_ns = ci.CS.ccnc_162_ts_ns = 1_000_000_000
|
||||||
|
ci.CS.ccnc_161 = {'SETSPEED_HUD': 3, 'SETSPEED_SPEED': 20, 'DISTANCE_SPACING': 1}
|
||||||
|
ci.CS.ccnc_162 = {'FAULT_LSS': 2, 'FAULT_FCA': 1}
|
||||||
|
command = structs.CarControl(enabled=enabled, latActive=True, longActive=enabled)
|
||||||
|
_, packets = ci.apply(command.as_reader(), 1_000_000_000)
|
||||||
|
parser = CANParser('hyundai_canfd_generated', [('CCNC_0x161', 0), ('CCNC_0x162', 0), ('SCC_CONTROL', 0)], 0)
|
||||||
|
# The display runs at 20 Hz and SCC at 50 Hz.
|
||||||
|
_, scc_packets = ci.apply(command.as_reader(), 1_010_000_000)
|
||||||
|
assert {0x161, 0x162} <= parser.update((1_000_000_000, packets))
|
||||||
|
assert 0x1A0 in parser.update((1_010_000_000, scc_packets))
|
||||||
|
assert parser.vl['SCC_CONTROL']['MainMode_ACC'] == int(not handoff or enabled)
|
||||||
|
display = parser.vl['CCNC_0x161']
|
||||||
|
assert display['SETSPEED_HUD'] == hud_mode
|
||||||
|
assert display['LFA_ICON'] == 2
|
||||||
|
if handoff:
|
||||||
|
assert display['SETSPEED'] == hud_mode
|
||||||
|
if hud_mode == 0:
|
||||||
|
assert display['DISTANCE'] == 0
|
||||||
|
assert display['SETSPEED_SPEED'] == 255
|
||||||
|
assert display['DISTANCE_SPACING'] == 0
|
||||||
|
assert parser.vl['CCNC_0x162']['FAULT_LSS'] == 2
|
||||||
|
assert parser.vl['CCNC_0x162']['FAULT_FCA'] == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('speed,accel,previous,standstill,lead,word,cap', [
|
||||||
|
(0.3, -0.27, -0.26, False, False, 0x1C0C, 1.2),
|
||||||
|
(2.2, -0.67, -0.66, False, False, 0x1C0C, 1.2),
|
||||||
|
(2.4, -1.13, -1.12, False, False, 0x1C0C, 1.2),
|
||||||
|
(1.2, -1.80, -1.78, False, False, 0x1C0C, 1.2),
|
||||||
|
(3.0, -0.60, -0.59, False, False, 0x1C0C, 5.0),
|
||||||
|
(0.3, -2.00, -1.99, False, False, 0x1C0C, 5.0),
|
||||||
|
(0.3, -0.45, -0.20, False, False, 0x1C0C, 5.0),
|
||||||
|
(0.1, -0.27, -0.26, True, False, 0x1C0C, 5.0),
|
||||||
|
(0.3, -0.27, -0.26, False, True, 0x1C0C, 5.0),
|
||||||
|
(0.3, -0.27, -0.26, False, False, 0x0C0C, 5.0),
|
||||||
|
])
|
||||||
|
def test_kona_final_braking_jerk(speed, accel, previous, standstill, lead, word, cap):
|
||||||
|
from opendbc.can import CANParser
|
||||||
|
|
||||||
|
cp = kona_params(CARS[0])
|
||||||
|
cp.safetyConfigs[0].safetyParam = word
|
||||||
|
cp.alternativeExperience = 32
|
||||||
|
ci = CarInterface(cp)
|
||||||
|
ci.CS.out = structs.CarState(vEgo=speed, standstill=standstill, cruiseState={'available': True}).as_reader()
|
||||||
|
ci.CC.accel_last = previous
|
||||||
|
command = structs.CarControl(enabled=True, longActive=True,
|
||||||
|
actuators={'accel': accel, 'longControlState': 'stopping'},
|
||||||
|
hudControl={'leadVisible': lead})
|
||||||
|
_, frames = ci.apply(command.as_reader(), 1_000_000_000)
|
||||||
|
parser = CANParser('hyundai_canfd_generated', [('SCC_CONTROL', 0)], 0)
|
||||||
|
assert 0x1A0 in parser.update((1_000_000_000, frames))
|
||||||
|
values = parser.vl['SCC_CONTROL']
|
||||||
|
assert values['aReqValue'] == pytest.approx(accel)
|
||||||
|
assert values['aReqRaw'] == pytest.approx(accel)
|
||||||
|
assert values['ACCMode'] == values['StopReq'] == 1
|
||||||
|
assert values['JerkLowerLimit'] == pytest.approx(cap)
|
||||||
|
|||||||
@@ -0,0 +1,107 @@
|
|||||||
|
from unittest import TestCase, mock
|
||||||
|
|
||||||
|
from opendbc.car import CanData, gen_empty_fingerprint, structs
|
||||||
|
from opendbc.car.car_helpers import get_car
|
||||||
|
from opendbc.car.hyundai import non_scc_aol, software_cruise
|
||||||
|
from opendbc.car.hyundai.discovery import kona_electric_se_candidate
|
||||||
|
from opendbc.car.hyundai.fingerprints import FW_VERSIONS
|
||||||
|
from opendbc.car.hyundai.values import CAR
|
||||||
|
|
||||||
|
MODEL = CAR.HYUNDAI_KONA_EV_2023_NON_SCC
|
||||||
|
SE_VIN = 'KM8K23AG0PU000000'
|
||||||
|
SCC_VIN = 'KM8K53AG1PU000000'
|
||||||
|
SE_LAYOUT = ((0, 0x251, 8), (0, 0x371, 8), (0, 0x386, 8), (0, 0x394, 8), (0, 0x4F1, 4),
|
||||||
|
(0, 0x391, 8), (0, 0x592, 8), (1, 0x329, 8), (2, 0x340, 8), (2, 0x485, 4))
|
||||||
|
|
||||||
|
|
||||||
|
def kona_electric_fw(include_radar=False):
|
||||||
|
ecu = structs.CarParams.Ecu
|
||||||
|
versions = FW_VERSIONS[CAR.HYUNDAI_KONA_EV_2022]
|
||||||
|
firmware = [
|
||||||
|
structs.CarParams.CarFw(ecu=ecu.eps, address=0x7D4, brand='hyundai',
|
||||||
|
fwVersion=b'\xf1\x00OSP MDPS C 1.00 1.02 56310K4261\x00 4OEPC102'),
|
||||||
|
structs.CarParams.CarFw(ecu=ecu.fwdCamera, address=0x7C4, brand='hyundai',
|
||||||
|
fwVersion=b'\xf1\x00OSP LKA AT USA LHD 1.00 1.04 99211-J9200 904'),
|
||||||
|
]
|
||||||
|
if include_radar:
|
||||||
|
firmware.append(structs.CarParams.CarFw(ecu=ecu.fwdRadar, address=0x7D0, brand='hyundai',
|
||||||
|
fwVersion=versions[(ecu.fwdRadar, 0x7D0, None)][0]))
|
||||||
|
return firmware
|
||||||
|
|
||||||
|
|
||||||
|
def interface(vin, layout=SE_LAYOUT, radar=False, forced_candidate=None):
|
||||||
|
packets = [CanData(addr, bytes(length), bus) for bus, addr, length in layout]
|
||||||
|
cached = structs.CarParams(brand='hyundai', carVin=vin, carFw=kona_electric_fw(radar), carFingerprint=forced_candidate or '')
|
||||||
|
with mock.patch.dict('os.environ', clear=True):
|
||||||
|
return get_car(lambda *args, **kwargs: [packets] if kwargs.get('wait_for_one') else [], mock.Mock(), mock.Mock(),
|
||||||
|
alpha_long_allowed=True, is_release=False, cached_params=cached, forced_candidate=forced_candidate)
|
||||||
|
|
||||||
|
|
||||||
|
class TestKonaElectricSE(TestCase):
|
||||||
|
def test_exact_auto_and_manual_identity_use_stock_cruise_steering(self):
|
||||||
|
for manual in (None, MODEL):
|
||||||
|
with self.subTest(manual=manual):
|
||||||
|
ci = interface(SE_VIN, forced_candidate=manual)
|
||||||
|
cp = ci.CP
|
||||||
|
self.assertEqual(cp.carFingerprint, MODEL)
|
||||||
|
self.assertFalse(cp.dashcamOnly)
|
||||||
|
self.assertTrue(cp.pcmCruise)
|
||||||
|
self.assertFalse(cp.alphaLongitudinalAvailable)
|
||||||
|
self.assertFalse(cp.openpilotLongitudinalControl)
|
||||||
|
self.assertFalse(cp.autoResumeSng)
|
||||||
|
self.assertEqual([(s.safetyModel, s.safetyParam) for s in cp.safetyConfigs], [(structs.CarParams.SafetyModel.hyundai, 0x1851)])
|
||||||
|
self.assertTrue(non_scc_aol.qualified(cp))
|
||||||
|
self.assertEqual(non_scc_aol.aol_word(cp), 0x1c51)
|
||||||
|
self.assertFalse(software_cruise.selected(software_cruise.prepare(cp, False)))
|
||||||
|
self.assertTrue(software_cruise.selected(software_cruise.prepare(cp, True)))
|
||||||
|
self.assertEqual(cp.safetyConfigs[0].safetyParam, 0x1871)
|
||||||
|
self.assertEqual(non_scc_aol.aol_word(cp), 0x1c71)
|
||||||
|
|
||||||
|
def test_wrong_manual_match_remains_read_only(self):
|
||||||
|
wrong_lkas = (*SE_LAYOUT[:-1], (2, 0x485, 8))
|
||||||
|
for vin, layout in ((SCC_VIN, SE_LAYOUT), (SE_VIN, wrong_lkas)):
|
||||||
|
with self.subTest(vin=vin, layout=layout):
|
||||||
|
ci = interface(vin, layout, forced_candidate=MODEL)
|
||||||
|
cp = ci.CP
|
||||||
|
self.assertTrue(cp.dashcamOnly)
|
||||||
|
self.assertFalse(software_cruise.eligible(cp))
|
||||||
|
self.assertEqual([(s.safetyModel, s.safetyParam) for s in cp.safetyConfigs], [(structs.CarParams.SafetyModel.noOutput, 0)])
|
||||||
|
cmd = structs.CarControl(enabled=True, latActive=True, longActive=True)
|
||||||
|
self.assertFalse(ci.apply(cmd.as_reader(), 0)[1])
|
||||||
|
|
||||||
|
def test_scc_firmware_still_owns_matching_sibling(self):
|
||||||
|
ci = interface(SCC_VIN, (*SE_LAYOUT, (2, 0x420, 8), (2, 0x421, 8)), radar=True)
|
||||||
|
self.assertEqual(ci.CP.carFingerprint, CAR.HYUNDAI_KONA_EV_2022)
|
||||||
|
self.assertFalse(ci.CP.dashcamOnly)
|
||||||
|
|
||||||
|
def test_evidence_is_conjunctive(self):
|
||||||
|
fp = gen_empty_fingerprint()
|
||||||
|
for bus, addr, length in SE_LAYOUT:
|
||||||
|
fp[bus][addr] = length
|
||||||
|
firmware = kona_electric_fw()
|
||||||
|
self.assertEqual(kona_electric_se_candidate(SE_VIN, fp, firmware), MODEL)
|
||||||
|
for vin in ('', '00000000000000000', SCC_VIN, SE_VIN[:9] + 'N' + SE_VIN[10:]):
|
||||||
|
self.assertIsNone(kona_electric_se_candidate(vin, fp, firmware))
|
||||||
|
self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, firmware[:1]))
|
||||||
|
self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, kona_electric_fw(include_radar=True)))
|
||||||
|
fp[2][0x421] = 8
|
||||||
|
self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, firmware))
|
||||||
|
del fp[2][0x421]
|
||||||
|
fp[1][0x329] = 7
|
||||||
|
self.assertIsNone(kona_electric_se_candidate(SE_VIN, fp, firmware))
|
||||||
|
|
||||||
|
def test_only_regular_set_and_resume_allow_pcm_enable(self):
|
||||||
|
from opendbc.can import CANPacker
|
||||||
|
|
||||||
|
for main, button, permitted in ((True, 0, False), (False, 4, False), (True, 2, False),
|
||||||
|
(False, 2, True), (False, 1, True)):
|
||||||
|
with self.subTest(main=main, button=button):
|
||||||
|
ci = interface(SE_VIN)
|
||||||
|
packer = CANPacker('hyundai_can_generated')
|
||||||
|
stamp = 1_000_000_000
|
||||||
|
ci.CS.cruise_buttons.append(button)
|
||||||
|
ci.CS.main_buttons.append(main)
|
||||||
|
active = packer.make_can_msg('LABEL11', 0, {'CC_React': 1, 'CC_Engaged': 1})
|
||||||
|
result = ci.update([(stamp, [active])])
|
||||||
|
self.assertTrue(result.cruiseState.available and result.cruiseState.enabled)
|
||||||
|
self.assertEqual(not result.blockPcmEnable, permitted)
|
||||||
@@ -78,6 +78,7 @@ class HyundaiSafetyFlags(IntFlag):
|
|||||||
LONG = 4
|
LONG = 4
|
||||||
CAMERA_SCC = 8
|
CAMERA_SCC = 8
|
||||||
CANFD_LKA_STEER_MSG = 16
|
CANFD_LKA_STEER_MSG = 16
|
||||||
|
KONA_EV_LABEL_CRUISE = 16
|
||||||
CANFD_ALT_BUTTONS = 32
|
CANFD_ALT_BUTTONS = 32
|
||||||
ALT_LIMITS = 64
|
ALT_LIMITS = 64
|
||||||
CANFD_LKA_STEER_MSG_ALT = 128
|
CANFD_LKA_STEER_MSG_ALT = 128
|
||||||
@@ -262,6 +263,9 @@ class HyundaiCanFDPlatformConfig(PlatformConfig):
|
|||||||
self.dbc_dict = {Bus.pt: "hyundai_canfd_generated", Bus.radar: self.radar_dbc}
|
self.dbc_dict = {Bus.pt: "hyundai_canfd_generated", Bus.radar: self.radar_dbc}
|
||||||
|
|
||||||
|
|
||||||
|
CARNIVAL_2027_CAMERA_FW = b'\xf1\x00KA4 MFC AT USA LHD 1.00 1.02 99210-R0800 251031'
|
||||||
|
|
||||||
|
|
||||||
class CAR(Platforms):
|
class CAR(Platforms):
|
||||||
# Hyundai
|
# Hyundai
|
||||||
HYUNDAI_AZERA_6TH_GEN = HyundaiPlatformConfig(
|
HYUNDAI_AZERA_6TH_GEN = HyundaiPlatformConfig(
|
||||||
@@ -300,6 +304,7 @@ class CAR(Platforms):
|
|||||||
HYUNDAI_ELANTRA.specs,
|
HYUNDAI_ELANTRA.specs,
|
||||||
flags=HyundaiFlags.LEGACY | HyundaiFlags.CLUSTER_GEARS | HyundaiFlags.MIN_STEER_32_MPH,
|
flags=HyundaiFlags.LEGACY | HyundaiFlags.CLUSTER_GEARS | HyundaiFlags.MIN_STEER_32_MPH,
|
||||||
)
|
)
|
||||||
|
HYUNDAI_I30_2026 = HyundaiPlatformConfig([], HYUNDAI_ELANTRA_GT_I30.specs)
|
||||||
HYUNDAI_ELANTRA_2021 = HyundaiPlatformConfig(
|
HYUNDAI_ELANTRA_2021 = HyundaiPlatformConfig(
|
||||||
[HyundaiCarDocs("Hyundai Elantra 2021-23", video="https://youtu.be/_EdYQtV52-c", car_parts=CarParts.common([CarHarness.hyundai_k]))],
|
[HyundaiCarDocs("Hyundai Elantra 2021-23", video="https://youtu.be/_EdYQtV52-c", car_parts=CarParts.common([CarHarness.hyundai_k]))],
|
||||||
CarSpecs(mass=2800 * CV.LB_TO_KG, wheelbase=2.72, steerRatio=12.9, tireStiffnessFactor=0.65),
|
CarSpecs(mass=2800 * CV.LB_TO_KG, wheelbase=2.72, steerRatio=12.9, tireStiffnessFactor=0.65),
|
||||||
@@ -823,6 +828,7 @@ class CAR(Platforms):
|
|||||||
[
|
[
|
||||||
HyundaiCarDocs("Kia Carnival 2025", car_parts=CarParts.common([CarHarness.hyundai_k])),
|
HyundaiCarDocs("Kia Carnival 2025", car_parts=CarParts.common([CarHarness.hyundai_k])),
|
||||||
HyundaiCarDocs("Kia Carnival (with HDA II) 2025", "Highway Driving Assist II", car_parts=CarParts.common([CarHarness.hyundai_q])),
|
HyundaiCarDocs("Kia Carnival (with HDA II) 2025", "Highway Driving Assist II", car_parts=CarParts.common([CarHarness.hyundai_q])),
|
||||||
|
HyundaiCarDocs("Kia Carnival (with HDA II) 2027", "Highway Driving Assist II", car_parts=CarParts.common([CarHarness.hyundai_q])),
|
||||||
],
|
],
|
||||||
KIA_CARNIVAL_4TH_GEN.specs,
|
KIA_CARNIVAL_4TH_GEN.specs,
|
||||||
flags=HyundaiFlags.CCNC,
|
flags=HyundaiFlags.CCNC,
|
||||||
@@ -950,6 +956,11 @@ class CAR(Platforms):
|
|||||||
HYUNDAI_KONA_EV.specs,
|
HYUNDAI_KONA_EV.specs,
|
||||||
flags=HyundaiFlags.EV | HyundaiFlags.ALT_LIMITS,
|
flags=HyundaiFlags.EV | HyundaiFlags.ALT_LIMITS,
|
||||||
)
|
)
|
||||||
|
HYUNDAI_KONA_EV_2023_NON_SCC = HyundaiNonSccPlatformConfig(
|
||||||
|
[HyundaiNonSccCarDocs("Hyundai Kona Electric SE 2023", package="Non-SCC", car_parts=CarParts.common([CarHarness.hyundai_o]))],
|
||||||
|
HYUNDAI_KONA_EV_2022.specs,
|
||||||
|
flags=HyundaiFlags.EV | HyundaiFlags.ALT_LIMITS,
|
||||||
|
)
|
||||||
KIA_RAY_EV = HyundaiNonSccPlatformConfig(
|
KIA_RAY_EV = HyundaiNonSccPlatformConfig(
|
||||||
[HyundaiNonSccCarDocs("Kia Ray EV 2025", package="Non-SCC with comma pedal (6-byte sensor) and 8-byte LFA; other variants dashcam only",
|
[HyundaiNonSccCarDocs("Kia Ray EV 2025", package="Non-SCC with comma pedal (6-byte sensor) and 8-byte LFA; other variants dashcam only",
|
||||||
car_parts=CarParts.common([CarHarness.hyundai_h]))],
|
car_parts=CarParts.common([CarHarness.hyundai_h]))],
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import math
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from opendbc.can import CANPacker
|
||||||
|
from opendbc.car import Bus
|
||||||
|
from opendbc.car.interfaces import CarControllerBase
|
||||||
|
from opendbc.car.lateral import apply_steer_angle_limits_vm, get_max_angle_vm
|
||||||
|
from opendbc.car.leapmotor import leapmotorcan
|
||||||
|
from opendbc.car.leapmotor.values import CarControllerParams
|
||||||
|
from opendbc.car.vehicle_model import VehicleModel
|
||||||
|
|
||||||
|
|
||||||
|
def get_safety_CP():
|
||||||
|
# the safety model's vehicle-model limits are computed for this platform
|
||||||
|
from opendbc.car.leapmotor.interface import CarInterface
|
||||||
|
return CarInterface.get_non_essential_params("LEAPMOTOR_B10")
|
||||||
|
|
||||||
|
|
||||||
|
class CarController(CarControllerBase):
|
||||||
|
"""Replaces the camera's ADAS_LKA (0x83) with a copy carrying openpilot's angle request, and cancels the
|
||||||
|
stock ACC through the camera's copy of POWERTRAIN_STATE when openpilot disengages."""
|
||||||
|
|
||||||
|
def __init__(self, dbc_names, CP):
|
||||||
|
super().__init__(dbc_names, CP)
|
||||||
|
self.packer = CANPacker(dbc_names[Bus.pt])
|
||||||
|
self.apply_angle_last = 0.
|
||||||
|
self.lcc_ramp = leapmotorcan.LCC_RAMP_IDLE
|
||||||
|
self.lat_active_last = False
|
||||||
|
self.VM = VehicleModel(get_safety_CP())
|
||||||
|
self.adas_lka_idle = leapmotorcan.decode_adas_lka_idle()
|
||||||
|
self.ramp_boost = 0
|
||||||
|
|
||||||
|
def update_ramp_boost(self, lat_active: bool, CS) -> int:
|
||||||
|
"""Extra LCC_RAMP steps: one more per frame while the wheel lags the command at low speed, one fewer once it is
|
||||||
|
back (see CarControllerParams.RAMP_BOOST_LAG), and none past the EPS torque at which the EPS lets go by itself
|
||||||
|
(see CarControllerParams.RAMP_BOOST_EPS_TORQUE_HOLD)."""
|
||||||
|
if not lat_active or CS.out.vEgoRaw * 3.6 > CarControllerParams.RAMP_BOOST_MAX_SPEED:
|
||||||
|
return 0
|
||||||
|
behind = abs(self.apply_angle_last - CS.out.steeringAngleDeg)
|
||||||
|
eps_torque = abs(CS.out.steeringTorqueEps)
|
||||||
|
boost = self.ramp_boost
|
||||||
|
if eps_torque >= CarControllerParams.RAMP_BOOST_EPS_TORQUE_BACK or behind < CarControllerParams.RAMP_BOOST_CAUGHT_UP:
|
||||||
|
boost -= 1
|
||||||
|
elif behind > CarControllerParams.RAMP_BOOST_LAG and eps_torque < CarControllerParams.RAMP_BOOST_EPS_TORQUE_HOLD:
|
||||||
|
boost += 1
|
||||||
|
return min(max(boost, 0), leapmotorcan.LCC_RAMP_STEPS_MAX - leapmotorcan.LCC_RAMP_STEPS_MIN)
|
||||||
|
|
||||||
|
def long_accel(self, CC, camera_lka: dict) -> float | None:
|
||||||
|
"""openpilot's acceleration request for ADAS_LKA, or None to send the camera's.
|
||||||
|
|
||||||
|
Only while the stock ACC is engaged (ACC_STATE 3): the camera keeps engagement, the standstill hold and the
|
||||||
|
accelerator override (ACC_STATE 1), and its request goes through unchanged then. When the camera asks for hard
|
||||||
|
braking, openpilot never asks for less.
|
||||||
|
"""
|
||||||
|
if not (self.CP.openpilotLongitudinalControl and CC.longActive and int(camera_lka["ACC_STATE"]) == 3):
|
||||||
|
return None
|
||||||
|
accel = float(np.clip(CC.actuators.accel, CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX))
|
||||||
|
camera_accel = float(camera_lka["ACC_ACCEL_REQ"])
|
||||||
|
if camera_accel <= CarControllerParams.STOCK_BRAKE_PASSTHROUGH:
|
||||||
|
accel = min(accel, camera_accel)
|
||||||
|
return accel
|
||||||
|
|
||||||
|
def update(self, CC, CS, now_nanos):
|
||||||
|
actuators = CC.actuators
|
||||||
|
can_sends = []
|
||||||
|
# like the stock LCC, let go while the driver steers (the EPS flags it), then ramp back in
|
||||||
|
# (while the wheel follows openpilot's angle, the stricter rule: see CarControllerParams.OVERRIDE_TRACKING_ERROR)
|
||||||
|
tracking = (self.lat_active_last and
|
||||||
|
abs(self.apply_angle_last - CS.out.steeringAngleDeg) < CarControllerParams.OVERRIDE_TRACKING_ERROR)
|
||||||
|
lat_active = CC.latActive and not (CS.driver_override_tracking if tracking else CS.driver_override)
|
||||||
|
# take the wheel back only once it is near the angle openpilot wants: after the driver let go mid-turn at walking
|
||||||
|
# pace with the wheel at +308 deg and the model at +24, the EPS swung it to -203 deg in 3 s
|
||||||
|
if lat_active and not self.lat_active_last:
|
||||||
|
lat_active = abs(actuators.steeringAngleDeg - CS.out.steeringAngleDeg) < CarControllerParams.TAKE_BACK_MAX_ANGLE_ERROR
|
||||||
|
# and within the angle openpilot may command at this speed: otherwise the first frame jumps to that limit, the
|
||||||
|
# panda blocks it, and the missing frame cancels ACC
|
||||||
|
if CS.out.vEgoRaw > 1.:
|
||||||
|
max_angle = get_max_angle_vm(CS.out.vEgoRaw, self.VM, CarControllerParams)
|
||||||
|
lat_active = lat_active and abs(CS.out.steeringAngleDeg) < max_angle - 1.0
|
||||||
|
|
||||||
|
if self.frame % CarControllerParams.STEER_STEP == 0:
|
||||||
|
camera_lka = CS.adas_lka if CS.adas_lka is not None else self.adas_lka_idle
|
||||||
|
self.apply_angle_last = apply_steer_angle_limits_vm(actuators.steeringAngleDeg, self.apply_angle_last, CS.out.vEgoRaw,
|
||||||
|
CS.out.steeringAngleDeg, lat_active, CarControllerParams, self.VM)
|
||||||
|
lat_accel = self.VM.calc_curvature(math.radians(self.apply_angle_last), CS.out.vEgoRaw, 0.) * CS.out.vEgoRaw ** 2
|
||||||
|
self.ramp_boost = self.update_ramp_boost(lat_active, CS)
|
||||||
|
self.lcc_ramp = leapmotorcan.lcc_ramp_next(self.lcc_ramp, lat_active,
|
||||||
|
leapmotorcan.lcc_ramp_target(lat_accel, CS.out.vEgoRaw * 3.6, self.ramp_boost))
|
||||||
|
can_sends.append(leapmotorcan.create_steering_control(self.packer, camera_lka, self.apply_angle_last, lat_active,
|
||||||
|
self.lcc_ramp, self.long_accel(CC, camera_lka)))
|
||||||
|
|
||||||
|
# cancel stock ACC when openpilot asks (it is engaged with ACC, so it cancels ACC whenever it disengages)
|
||||||
|
if CC.cruiseControl.cancel and self.frame % CarControllerParams.STEER_STEP == 0 and CS.powertrain_state is not None:
|
||||||
|
can_sends.append(leapmotorcan.create_cancel(self.packer, CS.powertrain_state))
|
||||||
|
|
||||||
|
self.lat_active_last = lat_active
|
||||||
|
new_actuators = actuators.as_builder()
|
||||||
|
new_actuators.steeringAngleDeg = self.apply_angle_last
|
||||||
|
|
||||||
|
self.frame += 1
|
||||||
|
return new_actuators, can_sends
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
import numpy as np
|
||||||
|
from opendbc.car import DT_CTRL, Bus, create_button_events, structs
|
||||||
|
from opendbc.can.parser import CANParser
|
||||||
|
from opendbc.car.common.conversions import Conversions as CV
|
||||||
|
from opendbc.car.common.filter_simple import FirstOrderFilter
|
||||||
|
from opendbc.car.dashboard_speed_limit import Tracker as LimitTracker, leapmotor_sign, parser_expiry
|
||||||
|
from opendbc.car.interfaces import CarStateBase
|
||||||
|
from opendbc.car.leapmotor.values import DBC, CarControllerParams
|
||||||
|
|
||||||
|
GearShifter = structs.CarState.GearShifter
|
||||||
|
ButtonType = structs.CarState.ButtonEvent.Type
|
||||||
|
GEARS = {0: GearShifter.park, 1: GearShifter.reverse, 2: GearShifter.neutral, 3: GearShifter.drive}
|
||||||
|
# POWERTRAIN_STATE.STALK_PUSH 3 (stalk pushed up) cancels assist; the engage pushes (1, 2) are not reported
|
||||||
|
STALK_CANCEL = 3
|
||||||
|
|
||||||
|
|
||||||
|
class CarState(CarStateBase):
|
||||||
|
def __init__(self, CP):
|
||||||
|
super().__init__(CP)
|
||||||
|
self.steering_angle_last = 0.0
|
||||||
|
self.adas_lka: dict | None = None
|
||||||
|
self.lka_received_seen = False
|
||||||
|
self.driver_override_frames = 0
|
||||||
|
self.driver_override = False
|
||||||
|
# the override used by the controller while the wheel follows openpilot's angle (see OVERRIDE_TRACKING_ERROR)
|
||||||
|
self.tracking_pressed_cnt = 0
|
||||||
|
self.tracking_override_frames = 0
|
||||||
|
self.driver_override_tracking = False
|
||||||
|
# the EPS's own effort as it shows up in the driver-torque reading, which lags it (see EPS_TORQUE_LAG)
|
||||||
|
self.eps_torque_lagged = FirstOrderFilter(0., CarControllerParams.EPS_TORQUE_LAG, DT_CTRL)
|
||||||
|
self.powertrain_state: dict | None = None
|
||||||
|
self.dashboard_limit = LimitTracker()
|
||||||
|
self.stalk_cancel = False
|
||||||
|
|
||||||
|
def update(self, can_parsers) -> structs.CarState:
|
||||||
|
cp = can_parsers[Bus.pt]
|
||||||
|
cp_cam = can_parsers[Bus.cam]
|
||||||
|
ret = structs.CarState()
|
||||||
|
|
||||||
|
# speed
|
||||||
|
self.parse_wheel_speeds(ret,
|
||||||
|
cp.vl['WHEEL_SPEEDS']['WHEEL_SPEED_FL'],
|
||||||
|
cp.vl['WHEEL_SPEEDS']['WHEEL_SPEED_FR'],
|
||||||
|
cp.vl['WHEEL_SPEEDS']['WHEEL_SPEED_RL'],
|
||||||
|
cp.vl['WHEEL_SPEEDS']['WHEEL_SPEED_RR'],
|
||||||
|
)
|
||||||
|
ret.vEgoCluster = cp.vl['CLUSTER']['DISPLAY_SPEED'] * CV.KPH_TO_MS
|
||||||
|
ret.standstill = ret.vEgoRaw < 0.01
|
||||||
|
ret.yawRate = cp.vl['IMU']['YAW_RATE'] * CV.DEG_TO_RAD
|
||||||
|
|
||||||
|
# pedals
|
||||||
|
ret.gasPressed = cp.vl['VEHICLE_STATE']['ACCEL_PEDAL'] > 0
|
||||||
|
ret.brakePressed = bool(cp.vl['VEHICLE_STATE']['BRAKE_PRESSED'])
|
||||||
|
|
||||||
|
# steering: the EPS speed field has no sign, so take the sign from the angle change
|
||||||
|
angle = cp.vl['EPS_STEERING']['STEER_ANGLE']
|
||||||
|
sign = 1.0 if angle > self.steering_angle_last else (-1.0 if angle < self.steering_angle_last else 0.0)
|
||||||
|
ret.steeringAngleDeg = angle
|
||||||
|
ret.steeringRateDeg = sign * cp.vl['EPS_STEERING']['STEER_SPEED_ABS']
|
||||||
|
self.steering_angle_last = angle
|
||||||
|
ret.steeringTorqueEps = cp.vl['EPS_STEERING']['STEER_TORQUE_EPS']
|
||||||
|
# the driver's torque: the reading minus the share that follows the EPS's own effort
|
||||||
|
driver_torque_raw = cp.vl['EPS_STEERING']['STEER_TORQUE_DRIVER']
|
||||||
|
eps_share = self.eps_torque_lagged.update(ret.steeringTorqueEps) / CarControllerParams.EPS_TORQUE_PER_DRIVER_TORQUE
|
||||||
|
ret.steeringTorque = driver_torque_raw + eps_share
|
||||||
|
# the torque reading is coarse: during an LCC override it only reached 2-3, but the EPS flagged the override itself.
|
||||||
|
# The EPS also sets that flag whenever the car is above about 121 km/h, with or without the driver (99% of frames
|
||||||
|
# above 121 km/h on a stock drive, and openpilot's own drive at 125 km/h), so above 118 km/h only the torque counts.
|
||||||
|
eps_override = cp.vl['EPS_STEERING']['DRIVER_OVERRIDE'] and ret.vEgoRaw < 118 * CV.KPH_TO_MS
|
||||||
|
self.driver_override_frames = self.driver_override_frames + 1 if eps_override else 0
|
||||||
|
torque_pressed = self.update_steering_pressed(abs(ret.steeringTorque) > CarControllerParams.STEER_DRIVER_ALLOWANCE, 5)
|
||||||
|
ret.steeringPressed = torque_pressed or self.driver_override_frames >= 2
|
||||||
|
# When to let go of the wheel: on the EPS's own flag, like stock LCC, or on the driver's torque. Not on the raw
|
||||||
|
# reading, which read 5-7 whenever the EPS pushed 65-95 in a curve: letting go on it dropped the EPS to 0 and back
|
||||||
|
# every 0.7 s (41 times in 14 min). The flag alone is not enough: above 118 km/h it is always set, and at walking
|
||||||
|
# pace it stayed off while openpilot pulled the wheel from +324 to -203 deg through the driver's hands.
|
||||||
|
self.driver_override = self.driver_override_frames >= 2 or torque_pressed
|
||||||
|
# While the wheel follows openpilot the share estimate overshoots, so there it only removes torque, and the flag
|
||||||
|
# needs torque against the EPS as well (see CarControllerParams.OVERRIDE_TRACKING_ERROR)
|
||||||
|
tracking_torque = ret.steeringTorque if ret.steeringTorque * eps_share <= 0 else \
|
||||||
|
(driver_torque_raw if driver_torque_raw * eps_share > 0 else 0.)
|
||||||
|
pressed = abs(tracking_torque) > CarControllerParams.STEER_DRIVER_ALLOWANCE
|
||||||
|
self.tracking_pressed_cnt = int(np.clip(self.tracking_pressed_cnt + (1 if pressed else -1), 0, 11))
|
||||||
|
opposing = tracking_torque * eps_share < 0 and abs(tracking_torque) >= CarControllerParams.OVERRIDE_OPPOSING_TORQUE
|
||||||
|
self.tracking_override_frames = self.tracking_override_frames + 1 if eps_override and opposing else 0
|
||||||
|
self.driver_override_tracking = self.tracking_override_frames >= 2 or self.tracking_pressed_cnt > 5
|
||||||
|
# The EPS reports whether it receives ADAS_LKA (0x83): losing it after it was received means our steering frame is
|
||||||
|
# missing or rejected (camera-unplug test). Not set before the camera's first frame after ignition.
|
||||||
|
lka_received = bool(cp.vl['EPS_STEERING']['ADAS_LKA_RECEIVED'])
|
||||||
|
self.lka_received_seen = self.lka_received_seen or lka_received
|
||||||
|
ret.steerFaultTemporary = self.lka_received_seen and not lka_received
|
||||||
|
|
||||||
|
# gear
|
||||||
|
ret.gearShifter = GEARS.get(int(cp.vl['VEHICLE_STATE']['GEAR']), GearShifter.unknown)
|
||||||
|
|
||||||
|
# body
|
||||||
|
ret.leftBlinker, ret.rightBlinker = self.update_blinker_from_lamp(50, cp.vl['BODY_CONTROL']['BLINKER_LEFT'] == 1,
|
||||||
|
cp.vl['BODY_CONTROL']['BLINKER_RIGHT'] == 1)
|
||||||
|
ret.doorOpen = bool(cp.vl['BODY_CONTROL']['DRIVER_DOOR_OPEN'])
|
||||||
|
ret.seatbeltUnlatched = bool(cp.vl['SEATBELT']['DRIVER_SEATBELT_UNLATCHED'])
|
||||||
|
|
||||||
|
# blind-spot radars: silent when stopped, so they are not timeout-checked (see get_can_parsers)
|
||||||
|
ret.leftBlindspot = bool(cp.vl['BSD_LEFT']['OBJECT_DETECTED'])
|
||||||
|
ret.rightBlindspot = bool(cp.vl['BSD_RIGHT']['OBJECT_DETECTED'])
|
||||||
|
|
||||||
|
# stock ACC / LCC, read from the camera side
|
||||||
|
ret.cruiseState.enabled = bool(cp.vl['POWERTRAIN_STATE']['ASSIST_ENGAGED'])
|
||||||
|
# the driver's cancel push, so a cancel the car makes by itself can be told apart from the driver's
|
||||||
|
prev_cancel = self.stalk_cancel
|
||||||
|
self.stalk_cancel = int(cp.vl['POWERTRAIN_STATE']['STALK_PUSH']) == STALK_CANCEL
|
||||||
|
ret.buttonEvents = create_button_events(int(self.stalk_cancel), int(prev_cancel), {1: ButtonType.cancel})
|
||||||
|
# latest VCU frame, copied by the controller to cancel ACC; None until received
|
||||||
|
self.powertrain_state = dict(cp.vl['POWERTRAIN_STATE']) if cp.ts_nanos['POWERTRAIN_STATE']['COUNTER'] > 0 else None
|
||||||
|
# ACC_STATE: 1 not ready (Park, brake, accelerator override), 2 ready, 3 engaged. Engaged also counts as
|
||||||
|
# available so that an accelerator override (state 1 while engaged) does not raise wrongCarMode
|
||||||
|
ret.cruiseState.available = ret.cruiseState.enabled or int(cp_cam.vl['ADAS_LKA']['ACC_STATE']) in (2, 3)
|
||||||
|
ret.cruiseState.speed = cp_cam.vl['ADAS_LKA']['ACC_SET_SPEED'] * CV.KPH_TO_MS
|
||||||
|
ret.cruiseState.speedCluster = ret.cruiseState.speed
|
||||||
|
ret.cruiseState.standstill = ret.cruiseState.enabled and ret.standstill
|
||||||
|
# the camera's forward collision warning, shown by openpilot too
|
||||||
|
ret.stockFcw = bool(cp_cam.vl['ROAD_SIGNS']['FCW'])
|
||||||
|
# the camera's posted speed limit, as the cluster shows it; offered to the speed limit controller as the dashboard
|
||||||
|
timestamp, expiry = parser_expiry(cp_cam, 'ROAD_SIGNS', 'SPEED_LIMIT')
|
||||||
|
if timestamp > self.dashboard_limit.observation.observed_ns:
|
||||||
|
status, value_mps = leapmotor_sign(int(cp_cam.vl['ROAD_SIGNS']['SPEED_LIMIT']))
|
||||||
|
self.dashboard_limit.update(timestamp, status, value_mps, valid_until_ns=expiry)
|
||||||
|
# latest camera frame, rebuilt by the controller; None until the camera's 0x83 has been received
|
||||||
|
self.adas_lka = dict(cp_cam.vl['ADAS_LKA']) if cp_cam.ts_nanos['ADAS_LKA']['COUNTER'] > 0 else None
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_can_parsers(CP):
|
||||||
|
return {
|
||||||
|
Bus.pt: CANParser(DBC[CP.carFingerprint][Bus.pt], [("BSD_LEFT", float('nan')), ("BSD_RIGHT", float('nan'))], 0),
|
||||||
|
Bus.cam: CANParser(DBC[CP.carFingerprint][Bus.pt], [], 2),
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
""" AUTO-FORMATTED USING opendbc/car/debug/format_fingerprints.py, EDIT STRUCTURE THERE."""
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
from opendbc.car.leapmotor.values import CAR
|
||||||
|
|
||||||
|
Ecu = CarParams.Ecu
|
||||||
|
|
||||||
|
FW_VERSIONS = {
|
||||||
|
CAR.LEAPMOTOR_B10: {
|
||||||
|
(Ecu.eps, 0x735, None): [
|
||||||
|
b'3401100-AG01\x00\x00\x00\x00\x00\x00\x00',
|
||||||
|
],
|
||||||
|
(Ecu.abs, 0x736, None): [
|
||||||
|
b'3565101-AG03\x00\x00\x00\x00\x00\x00\x00',
|
||||||
|
],
|
||||||
|
(Ecu.fwdCamera, 0x756, None): [
|
||||||
|
b'8021010-AH01\x00\x00\x00\x00\x00\x00\x00',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
from opendbc.car import structs, get_safety_config
|
||||||
|
from opendbc.car.interfaces import CarInterfaceBase
|
||||||
|
from opendbc.car.leapmotor.carcontroller import CarController
|
||||||
|
from opendbc.car.leapmotor.carstate import CarState
|
||||||
|
from opendbc.car.leapmotor.values import LeapmotorSafetyFlags
|
||||||
|
|
||||||
|
|
||||||
|
class CarInterface(CarInterfaceBase):
|
||||||
|
CarState = CarState
|
||||||
|
CarController = CarController
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, alpha_long, is_release, docs) -> structs.CarParams:
|
||||||
|
ret.brand = 'leapmotor'
|
||||||
|
|
||||||
|
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.leapmotor)]
|
||||||
|
# The camera's angle request (ADAS_LKA.STEER_ANGLE_REQ) leads the measured angle by 70-100 ms during LCC
|
||||||
|
ret.steerControlType = structs.CarParams.SteerControlType.angle
|
||||||
|
ret.steerActuatorDelay = 0.15
|
||||||
|
ret.steerLimitTimer = 0.4
|
||||||
|
ret.steerAtStandstill = False
|
||||||
|
|
||||||
|
ret.radarUnavailable = True
|
||||||
|
|
||||||
|
# Alpha longitudinal: the stock ACC keeps engagement, set speed (knob), cancel and the standstill hold; openpilot
|
||||||
|
# only replaces its acceleration request in ADAS_LKA, which openpilot already sends for steering.
|
||||||
|
ret.alphaLongitudinalAvailable = True
|
||||||
|
if alpha_long:
|
||||||
|
ret.openpilotLongitudinalControl = True
|
||||||
|
ret.safetyConfigs[0].safetyParam |= LeapmotorSafetyFlags.LONG_CONTROL.value
|
||||||
|
# the stock request leads the measured acceleration by about 0.2-0.25 s
|
||||||
|
ret.longitudinalActuatorDelay = 0.25
|
||||||
|
|
||||||
|
return ret
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
from opendbc.car.crc import CRC8H2F
|
||||||
|
|
||||||
|
# AUTOSAR E2E Profile 2 constants, one per counter value, for each message: the same algorithm as
|
||||||
|
# opendbc's volkswagen_mqb_meb_checksum. Learned from logs of a 2025 global-market Leapmotor B10 and
|
||||||
|
# exact on every frame tested from 3 other routes on 2 other days.
|
||||||
|
LEAPMOTOR_E2E_CONSTANTS: dict[int, list[int]] = {
|
||||||
|
0x083: [0xCD, 0x81, 0x0A, 0xC1, 0x99, 0x7F, 0x8D, 0x05, 0x3B, 0xA2, 0x43, 0xD2, 0xB6, 0x72, 0x2A, 0xD9],
|
||||||
|
0x084: [0x5A, 0x77, 0x5F, 0xEA, 0x3F, 0xCD, 0xF9, 0x2E, 0x34, 0xF1, 0x2C, 0x81, 0x60, 0x37, 0xC6, 0x5B],
|
||||||
|
0x0B1: [0x49, 0x56, 0x0E, 0x67, 0x81, 0x1E, 0x76, 0x9F, 0xBF, 0xC1, 0xE5, 0x6C, 0x96, 0x83, 0x7F, 0xC2],
|
||||||
|
0x0B6: [0x71, 0x0D, 0x0B, 0xC2, 0x08, 0xC6, 0x63, 0x4B, 0x3F, 0x2B, 0x06, 0x10, 0xF0, 0xD2, 0x87, 0x0D],
|
||||||
|
0x0B7: [0xEB, 0x4E, 0xAE, 0xCE, 0x79, 0x7C, 0x52, 0x03, 0x6A, 0x84, 0xC2, 0x3A, 0x0A, 0x64, 0x2F, 0x17],
|
||||||
|
0x0B8: [0xB9, 0x24, 0xDD, 0x54, 0x98, 0xE5, 0xB7, 0x87, 0x51, 0xDB, 0x71, 0x31, 0xF9, 0x26, 0x43, 0x6D],
|
||||||
|
0x0CB: [0x44, 0x73, 0x30, 0x2E, 0xA7, 0xAE, 0x40, 0x96, 0x33, 0x58, 0x84, 0x36, 0xF1, 0x43, 0xBF, 0x0A],
|
||||||
|
0x0CD: [0x93, 0x33, 0x70, 0x1A, 0x9A, 0xB5, 0xEA, 0x04, 0x7E, 0xD4, 0xB6, 0x9D, 0x8A, 0x2E, 0x18, 0x41],
|
||||||
|
0x0FA: [0x96, 0x97, 0x8B, 0x02, 0x69, 0xBB, 0x54, 0xE6, 0x4E, 0x46, 0x8D, 0x7B, 0xEA, 0x87, 0xE9, 0xB3],
|
||||||
|
0x0FD: [0x53, 0x58, 0x37, 0xDA, 0x94, 0x57, 0x79, 0x27, 0x8D, 0xDD, 0xD0, 0x39, 0x16, 0x84, 0x07, 0xAF],
|
||||||
|
0x134: [0x1A, 0x04, 0x9D, 0x41, 0xAB, 0x01, 0x5B, 0x2A, 0x8F, 0x6E, 0x46, 0xD0, 0xD8, 0xA8, 0x47, 0x2D],
|
||||||
|
0x138: [0xC1, 0x05, 0xD2, 0xD9, 0xAE, 0x93, 0xB1, 0x90, 0x42, 0x7C, 0x60, 0x33, 0x46, 0xB8, 0x6A, 0xE1],
|
||||||
|
0x142: [0x0E, 0x1E, 0xBF, 0x6C, 0x7F, 0xFA, 0xC0, 0x14, 0x8A, 0xD2, 0x52, 0x3C, 0x8B, 0xA6, 0x92, 0xAD],
|
||||||
|
0x182: [0xE8, 0x40, 0x60, 0xDE, 0xC2, 0xAC, 0xE3, 0xA4, 0x3D, 0x88, 0xD1, 0xEE, 0x51, 0x16, 0xAD, 0x49],
|
||||||
|
0x183: [0xF7, 0xC0, 0x40, 0xA6, 0xA5, 0xDE, 0x62, 0x1C, 0xAC, 0x5A, 0x4F, 0xA4, 0xE5, 0x18, 0x88, 0x08],
|
||||||
|
0x184: [0xD9, 0x90, 0x33, 0xE1, 0x3A, 0x1A, 0xDF, 0xC6, 0xB5, 0xDC, 0xEE, 0x04, 0xFA, 0xD7, 0xD4, 0x99],
|
||||||
|
0x185: [0x5D, 0x96, 0x82, 0x97, 0xB6, 0x8B, 0x24, 0x02, 0xEB, 0x69, 0x20, 0xBB, 0x77, 0x54, 0x86, 0xE6],
|
||||||
|
0x186: [0xD3, 0xE0, 0x75, 0x85, 0x83, 0x55, 0x33, 0xE3, 0x4C, 0x9C, 0x91, 0x1D, 0x23, 0x1A, 0xA6, 0x16],
|
||||||
|
0x18C: [0x0F, 0xD1, 0x6B, 0x63, 0x9E, 0x74, 0x22, 0x94, 0xD7, 0xA1, 0xE7, 0x6F, 0x9C, 0xCF, 0x96, 0xDD],
|
||||||
|
0x18D: [0x61, 0x4B, 0x17, 0xE4, 0x78, 0x0B, 0xA1, 0xB4, 0xBC, 0xD8, 0xEA, 0xF5, 0xD9, 0x21, 0xCA, 0x86],
|
||||||
|
0x227: [0x66, 0xF4, 0xA8, 0xC8, 0xBB, 0xA7, 0xAF, 0x2B, 0xD9, 0x7B, 0xC0, 0x50, 0x56, 0x0F, 0xCE, 0xED],
|
||||||
|
0x228: [0xC5, 0x9E, 0x5D, 0xA1, 0xAC, 0x96, 0x1B, 0x21, 0x82, 0xEE, 0xF9, 0x97, 0xB1, 0xCB, 0xB6, 0x13],
|
||||||
|
0x22A: [0xD5, 0xEB, 0xA2, 0x4E, 0x35, 0xAE, 0x51, 0xCE, 0x2D, 0x79, 0x9F, 0x7C, 0x34, 0x52, 0x09, 0x03],
|
||||||
|
0x233: [0xA5, 0xE9, 0x85, 0x04, 0xFB, 0x6C, 0xDF, 0xF1, 0xDE, 0x90, 0xA8, 0xCB, 0xDD, 0x3B, 0x80, 0x87],
|
||||||
|
0x241: [0x3F, 0xF7, 0x25, 0x5E, 0xAA, 0x47, 0x62, 0x61, 0x5B, 0x3C, 0xDC, 0xE5, 0x73, 0xB4, 0xED, 0x0D],
|
||||||
|
0x243: [0xAC, 0xEE, 0xB6, 0x68, 0x4D, 0x69, 0x1F, 0x0E, 0x86, 0x34, 0x6F, 0x46, 0xED, 0x38, 0x11, 0x1E],
|
||||||
|
0x24D: [0x0B, 0xC6, 0x3F, 0x10, 0x87, 0xF7, 0x42, 0xC5, 0x25, 0xDA, 0x40, 0x5E, 0x69, 0x4A, 0xAA, 0xA5],
|
||||||
|
0x25A: [0x64, 0x5D, 0x7D, 0x96, 0x3D, 0x82, 0xB9, 0x97, 0xD5, 0xB6, 0xAA, 0x8B, 0x5A, 0x24, 0xB4, 0x02],
|
||||||
|
0x290: [0x5C, 0x09, 0x71, 0x2F, 0x23, 0x73, 0x61, 0x25, 0x15, 0x48, 0x93, 0x65, 0x01, 0x4B, 0xAF, 0xF8],
|
||||||
|
0x2A3: [0x14, 0x99, 0x49, 0x0B, 0x04, 0xD5, 0x74, 0xC6, 0x17, 0xF1, 0xE1, 0x3F, 0x50, 0x9B, 0xCB, 0x10],
|
||||||
|
0x2D1: [0x0D, 0x28, 0xB8, 0x6B, 0x64, 0xDF, 0xEC, 0x74, 0xEA, 0x5D, 0x16, 0xD7, 0xC0, 0xC4, 0x7D, 0x6F],
|
||||||
|
0x2D5: [0xB1, 0xB8, 0x77, 0xDF, 0xED, 0xEA, 0x53, 0xD7, 0xCD, 0x7D, 0x44, 0x2E, 0x40, 0x58, 0xF1, 0x66],
|
||||||
|
0x2E1: [0x0E, 0x4D, 0xEE, 0x19, 0x73, 0x03, 0xAF, 0x8F, 0x32, 0x2E, 0x70, 0x31, 0x0B, 0xB3, 0xAE, 0x0E],
|
||||||
|
0x2E5: [0x15, 0xB9, 0xD1, 0xC1, 0x72, 0x93, 0x8C, 0x60, 0x12, 0xE1, 0x01, 0x77, 0xC4, 0xBF, 0x1F, 0x11],
|
||||||
|
0x331: [0x42, 0x4A, 0x62, 0xCD, 0x1B, 0xB4, 0xA0, 0x16, 0x14, 0xE8, 0x0A, 0x71, 0xEF, 0x24, 0x7C, 0xDF],
|
||||||
|
0x332: [0x23, 0xC8, 0x53, 0x83, 0xD9, 0x64, 0xD5, 0x0F, 0x89, 0xC7, 0xAB, 0xB7, 0x65, 0x3F, 0x9A, 0x2D],
|
||||||
|
0x3B0: [0x6D, 0x69, 0x44, 0xAC, 0x7A, 0x73, 0x06, 0x9C, 0x30, 0x17, 0x12, 0x2E, 0x8B, 0xEF, 0xA7, 0xCF],
|
||||||
|
0x3B2: [0xA1, 0x21, 0x97, 0x13, 0x68, 0x02, 0x10, 0x43, 0xBB, 0x0E, 0x57, 0xE6, 0xDF, 0xBD, 0x46, 0x8E],
|
||||||
|
0x3CE: [0x6C, 0x14, 0x3C, 0xAD, 0x93, 0x59, 0x1C, 0x4D, 0xD8, 0x33, 0x5D, 0x89, 0x7B, 0x08, 0x70, 0x34],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def leapmotor_checksum(address: int, sig, d: bytearray) -> int:
|
||||||
|
constants = LEAPMOTOR_E2E_CONSTANTS.get(address)
|
||||||
|
if constants is None:
|
||||||
|
return -1 # unknown message: never matches, so the frame is rejected rather than trusted
|
||||||
|
crc = 0xFF
|
||||||
|
for b in d[1:]:
|
||||||
|
crc = CRC8H2F[crc ^ b]
|
||||||
|
crc = CRC8H2F[crc ^ constants[d[1] & 0x0F]]
|
||||||
|
return crc ^ 0xFF
|
||||||
|
|
||||||
|
|
||||||
|
# LCC_RAMP (bytes 16-17 of ADAS_LKA): 0x7801 when LCC is not steering. While stock LCC steers it moves down a ladder of
|
||||||
|
# 254 per step, one step per frame: from idle to about 31 steps when LCC starts, then deeper with more lateral
|
||||||
|
# acceleration and speed, and back to idle at once when LCC stops. The step count sets how much torque the EPS may use
|
||||||
|
# (about +/-10 early in the ramp, +/-45 at 30-31 steps, +/-70 at 42-46). Stock LCC on 3 routes (142,234 frames):
|
||||||
|
# steps = 19.1 + 9.94 * |lateral accel| + 0.112 * speed (km/h), R^2 0.83, always 25-46. With the idle word the EPS only
|
||||||
|
# applied torque to the right; with a fixed 30 steps (0x5A3D) it could not hold a curve at 75 km/h (torque flat at 61).
|
||||||
|
LCC_RAMP_IDLE = 0x7801
|
||||||
|
LCC_RAMP_STEP = 254
|
||||||
|
LCC_RAMP_STEPS_MIN = 25
|
||||||
|
LCC_RAMP_STEPS_MAX = 46
|
||||||
|
# Ramp-in speed below LCC_RAMP_STEPS_MIN: stock moves one step per frame (0.5 s to 25 steps), and 50-68% of the frames
|
||||||
|
# where the wheel fell > 5 deg behind were in that ramp-in. Two steps per frame reaches 25 steps in 0.25 s; deeper than
|
||||||
|
# that, one step per frame as stock. Not seen from stock: the EPS's response to skipped ladder steps is untested.
|
||||||
|
LCC_RAMP_IN_STEPS_PER_FRAME = 2
|
||||||
|
|
||||||
|
|
||||||
|
def lcc_ramp_target(lat_accel: float, v_ego_kph: float, extra_steps: int = 0) -> int:
|
||||||
|
"""LCC_RAMP word that stock LCC would send for this lateral acceleration (m/s^2) and speed, extra_steps deeper,
|
||||||
|
never beyond the deepest stock value."""
|
||||||
|
steps = min(max(round(19.1 + 9.94 * abs(lat_accel) + 0.112 * v_ego_kph), LCC_RAMP_STEPS_MIN), LCC_RAMP_STEPS_MAX)
|
||||||
|
return LCC_RAMP_IDLE - LCC_RAMP_STEP * min(steps + max(extra_steps, 0), LCC_RAMP_STEPS_MAX)
|
||||||
|
|
||||||
|
|
||||||
|
def lcc_ramp_next(word: int, lat_active: bool, target: int) -> int:
|
||||||
|
"""Next LCC_RAMP value while steering: toward target, LCC_RAMP_IN_STEPS_PER_FRAME ladder steps per frame while ramping
|
||||||
|
in (shallower than LCC_RAMP_STEPS_MIN), one step per frame otherwise; straight back to idle when not steering."""
|
||||||
|
if not lat_active:
|
||||||
|
return LCC_RAMP_IDLE
|
||||||
|
if word > target:
|
||||||
|
ramping_in = word > LCC_RAMP_IDLE - LCC_RAMP_STEP * LCC_RAMP_STEPS_MIN
|
||||||
|
return max(word - LCC_RAMP_STEP * (LCC_RAMP_IN_STEPS_PER_FRAME if ramping_in else 1), target)
|
||||||
|
if word < target:
|
||||||
|
return word + LCC_RAMP_STEP
|
||||||
|
return word
|
||||||
|
|
||||||
|
|
||||||
|
def create_steering_control(packer, camera_lka: dict, apply_angle: float, lat_active: bool, lcc_ramp: int = LCC_RAMP_IDLE,
|
||||||
|
accel: float | None = None):
|
||||||
|
"""Rebuild ADAS_LKA (0x83) from the camera's latest frame, replacing only the steering fields.
|
||||||
|
|
||||||
|
Every other field (ACC state, acceleration request, set speed, constants) is copied unchanged, so the
|
||||||
|
stock ACC keeps working while openpilot steers. The packer recomputes the E2E checksum and runs its own
|
||||||
|
counter, since the EPS only ever sees openpilot's frames once the camera's are blocked.
|
||||||
|
While steering, LCC_RAMP carries lcc_ramp (see lcc_ramp_next); otherwise it is the camera's.
|
||||||
|
With openpilot longitudinal, accel (m/s^2) replaces the camera's ACC_ACCEL_REQ; None keeps the camera's.
|
||||||
|
"""
|
||||||
|
values = {k: v for k, v in camera_lka.items() if k not in ("CHECKSUM", "COUNTER")}
|
||||||
|
if accel is not None:
|
||||||
|
values["ACC_ACCEL_REQ"] = accel
|
||||||
|
values["STEER_ANGLE_REQ"] = apply_angle
|
||||||
|
values["LCC_STEERING_ACTIVE_COPY"] = 1 if lat_active else 0
|
||||||
|
if lat_active:
|
||||||
|
values["LCC_RAMP"] = lcc_ramp
|
||||||
|
return packer.make_can_msg("ADAS_LKA", 0, values)
|
||||||
|
|
||||||
|
|
||||||
|
STALK_PUSH_UP_CANCEL = 3
|
||||||
|
|
||||||
|
# A real ADAS_LKA frame from the camera with ACC and LCC off, used until the camera's first frame is received
|
||||||
|
ADAS_LKA_IDLE = bytes.fromhex("260500446411E100007D00700043E4000178007D000000000000000000000000")
|
||||||
|
|
||||||
|
|
||||||
|
def decode_adas_lka_idle() -> dict:
|
||||||
|
from opendbc.can.dbc import DBC # imported here: opendbc.can.dbc imports this module for the checksum
|
||||||
|
msg = DBC("leapmotor_b10").addr_to_msg[0x83]
|
||||||
|
return {name: sig.get_raw_value(ADAS_LKA_IDLE) * sig.factor + sig.offset for name, sig in msg.sigs.items()}
|
||||||
|
|
||||||
|
|
||||||
|
def create_cancel(packer, powertrain_state: dict):
|
||||||
|
"""Copy of the VCU's latest POWERTRAIN_STATE (0xB7) with the right stalk pushed up, sent to the camera (bus 2).
|
||||||
|
|
||||||
|
The camera runs ACC and reads the stalk from this frame; pushing the stalk up cancels ACC and LCC (14 of 14 logged
|
||||||
|
pushes ended assist within 0.25 s). The copy uses the next counter value, so it takes the place of the next real
|
||||||
|
frame. The safety model only allows this frame with the stalk pushed up.
|
||||||
|
"""
|
||||||
|
values = {k: v for k, v in powertrain_state.items() if k != "CHECKSUM"}
|
||||||
|
values["STALK_PUSH"] = STALK_PUSH_UP_CANCEL
|
||||||
|
values["COUNTER"] = (int(powertrain_state["COUNTER"]) + 1) % 16
|
||||||
|
return packer.make_can_msg("POWERTRAIN_STATE", 2, values)
|
||||||
@@ -0,0 +1,419 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from opendbc.can import CANPacker
|
||||||
|
from opendbc.can.dbc import DBC
|
||||||
|
from opendbc.car import Bus, structs
|
||||||
|
from opendbc.car.leapmotor import leapmotorcan
|
||||||
|
from opendbc.car.leapmotor.carcontroller import CarController, get_safety_CP
|
||||||
|
from opendbc.car.leapmotor.leapmotorcan import leapmotor_checksum
|
||||||
|
from opendbc.car.leapmotor.values import DBC as LEAPMOTOR_DBC, CarControllerParams
|
||||||
|
|
||||||
|
DBC_NAMES = LEAPMOTOR_DBC["LEAPMOTOR_B10"]
|
||||||
|
|
||||||
|
# Real ADAS_LKA (0x83) frames from a 2025 global-market B10: stock LCC steering, ACC only, and assist off
|
||||||
|
REAL_ADAS_LKA = {
|
||||||
|
"lcc": [
|
||||||
|
"6D0C004666007D00007D007009E87E00375D007D000000000000000000000000",
|
||||||
|
"600D004664007D00007D007008A67F004D53007D000000000000000000000000",
|
||||||
|
"A808004664808900007D007008E87E004158007D000000000000000000000000",
|
||||||
|
],
|
||||||
|
"acc": [
|
||||||
|
"B90A005A64005F00007D007000A47F000178007D000008000000000000000000",
|
||||||
|
"B40200465F802500007D007000087F000178007D000000000000000000000000",
|
||||||
|
"BA03004A64C07100007D0070004F7E000178007D000008000000000000000000",
|
||||||
|
],
|
||||||
|
"off": [
|
||||||
|
"260500446411E100007D00700043E4000178007D000000000000000000000000",
|
||||||
|
"4B0700446411E100007D007000A05A000178007D000000000000000000000000",
|
||||||
|
"4008004464918900007D0070002D7E000178007D000000000000000000000000",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
STEERING_BYTES = {12, 13, 14, 16, 17} # LCC_STEERING_ACTIVE_COPY (bit 99), STEER_ANGLE_REQ (104|16), LCC_RAMP (128|16)
|
||||||
|
|
||||||
|
# Real POWERTRAIN_STATE (0xB7) frames while driving with ACC engaged
|
||||||
|
REAL_POWERTRAIN_STATE = [
|
||||||
|
"450B04401004B42C000000800000000055E2048D5E2013000000000000000000",
|
||||||
|
"070C04401004B42C000000800000000055E204855E2A13000000000000000000",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Real frames from the filmed figure-eights at the moments of hardest right and left turn, as measured by the
|
||||||
|
# comma's own gyro (livePose.angularVelocityDevice.z: +36.6 deg/s right, -44.6 deg/s left)
|
||||||
|
HARD_RIGHT = {0x18D: "0B0602CAE4009EC5869A5E012C2C0000D5128658A3E803000000000000000000", 0x233: "4C06C88947811100"}
|
||||||
|
HARD_LEFT = {0x18D: "130E02BA1D0F644386C24D010001000004128702A3E803000000000000000000", 0x233: "7E0A43A647AD3100"}
|
||||||
|
|
||||||
|
# Real ROAD_SIGNS (0x142) frames from the camera just before and during a forward collision warning the driver reported
|
||||||
|
FCW_FRAMES = {False: "F204F4F14002001C8032120000000000", True: "050E310D4402001C8032120000000000"}
|
||||||
|
|
||||||
|
|
||||||
|
class TestLeapmotorCan(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.msg = DBC("leapmotor_b10").addr_to_msg[0x83]
|
||||||
|
|
||||||
|
def unpack(self, dat: bytes) -> dict:
|
||||||
|
return {n: s.get_raw_value(dat) * s.factor + s.offset for n, s in self.msg.sigs.items()}
|
||||||
|
|
||||||
|
def test_fcw(self):
|
||||||
|
sig = DBC("leapmotor_b10").addr_to_msg[0x142].sigs["FCW"]
|
||||||
|
for fcw, hexdata in FCW_FRAMES.items():
|
||||||
|
dat = bytes.fromhex(hexdata)
|
||||||
|
self.assertEqual(sig.get_raw_value(dat), int(fcw))
|
||||||
|
self.assertEqual(dat[0], leapmotor_checksum(0x142, None, bytearray(dat)))
|
||||||
|
|
||||||
|
def test_sign_convention(self):
|
||||||
|
# openpilot expects positive = left for steering angle and yaw rate
|
||||||
|
dbc = DBC("leapmotor_b10")
|
||||||
|
|
||||||
|
def decode(addr, hexdata, name):
|
||||||
|
sig = dbc.addr_to_msg[addr].sigs[name]
|
||||||
|
return sig.get_raw_value(bytes.fromhex(hexdata)) * sig.factor + sig.offset
|
||||||
|
self.assertLess(decode(0x18D, HARD_RIGHT[0x18D], "STEER_ANGLE"), -400)
|
||||||
|
self.assertLess(decode(0x233, HARD_RIGHT[0x233], "YAW_RATE"), -30)
|
||||||
|
self.assertGreater(decode(0x18D, HARD_LEFT[0x18D], "STEER_ANGLE"), 400)
|
||||||
|
self.assertGreater(decode(0x233, HARD_LEFT[0x233], "YAW_RATE"), 30)
|
||||||
|
|
||||||
|
def test_dbc_covers_every_used_bit(self):
|
||||||
|
# unpacking then packing a real frame (with its own counter) must reproduce it exactly
|
||||||
|
packer = CANPacker("leapmotor_b10")
|
||||||
|
for frames in REAL_ADAS_LKA.values():
|
||||||
|
for hexdata in frames:
|
||||||
|
dat = bytes.fromhex(hexdata)
|
||||||
|
values = {k: v for k, v in self.unpack(dat).items() if k != "CHECKSUM"}
|
||||||
|
self.assertEqual(bytes(packer.pack(0x83, values)), dat)
|
||||||
|
|
||||||
|
def test_cancel_changes_only_stalk_and_counter(self):
|
||||||
|
msg = DBC("leapmotor_b10").addr_to_msg[0xB7]
|
||||||
|
for hexdata in REAL_POWERTRAIN_STATE:
|
||||||
|
dat = bytes.fromhex(hexdata)
|
||||||
|
vals = {n: s.get_raw_value(dat) * s.factor + s.offset for n, s in msg.sigs.items()}
|
||||||
|
addr, out, bus = leapmotorcan.create_cancel(CANPacker("leapmotor_b10"), vals)
|
||||||
|
self.assertEqual((addr, bus), (0xB7, 2))
|
||||||
|
self.assertEqual(out[0], leapmotor_checksum(0xB7, None, bytearray(out)))
|
||||||
|
self.assertEqual(out[1] & 0xF, (dat[1] + 1) & 0xF)
|
||||||
|
self.assertEqual(out[5] & 0x3, 3)
|
||||||
|
for i in range(2, len(dat)):
|
||||||
|
if i != 5:
|
||||||
|
self.assertEqual(out[i], dat[i], f"byte {i}")
|
||||||
|
self.assertEqual(out[5] & ~0x3, dat[5] & ~0x3)
|
||||||
|
|
||||||
|
def test_rebuild_changes_only_steering(self):
|
||||||
|
for kind, frames in REAL_ADAS_LKA.items():
|
||||||
|
for hexdata in frames:
|
||||||
|
dat = bytes.fromhex(hexdata)
|
||||||
|
camera = self.unpack(dat)
|
||||||
|
for lat_active, angle in ((False, camera["STEER_ANGLE_REQ"]), (True, -123.46), (True, 456.78)):
|
||||||
|
with self.subTest(kind=kind, lat_active=lat_active, angle=angle):
|
||||||
|
packer = CANPacker("leapmotor_b10")
|
||||||
|
ramp = 0x6B0F # a value in the middle of the stock ramp
|
||||||
|
addr, out, bus = leapmotorcan.create_steering_control(packer, camera, angle, lat_active, ramp)
|
||||||
|
self.assertEqual((addr, bus), (0x83, 0))
|
||||||
|
self.assertEqual(out[0], leapmotor_checksum(0x83, None, bytearray(out)))
|
||||||
|
for i in range(2, len(dat)):
|
||||||
|
if i not in STEERING_BYTES:
|
||||||
|
self.assertEqual(out[i], dat[i], f"byte {i}")
|
||||||
|
got = self.unpack(bytes(out))
|
||||||
|
self.assertAlmostEqual(got["STEER_ANGLE_REQ"], angle, delta=0.011)
|
||||||
|
self.assertEqual(got["LCC_STEERING_ACTIVE_COPY"], int(lat_active))
|
||||||
|
# LCC_RAMP: openpilot's ramp while steering, the camera's otherwise
|
||||||
|
self.assertEqual(got["LCC_RAMP"], ramp if lat_active else camera["LCC_RAMP"])
|
||||||
|
# the ACC fields pass through untouched
|
||||||
|
for sig in ("ACC_STATE", "ACC_ACCEL_REQ", "ACC_SET_SPEED", "ASSIST_OFF", "CONSTANT_72", "CONSTANT_152"):
|
||||||
|
self.assertEqual(got[sig], camera[sig], sig)
|
||||||
|
|
||||||
|
def test_lcc_ramp_matches_stock(self):
|
||||||
|
# stock LCC engagement: LCC_RAMP goes 0x7801, 0x7703, 0x7605, ... one 254 step per frame, then jumps back
|
||||||
|
straight_90 = leapmotorcan.lcc_ramp_target(0.15, 90.0) # a typical straight road: stock median there is 31 steps
|
||||||
|
self.assertEqual(straight_90, 0x593F)
|
||||||
|
word, seen = leapmotorcan.LCC_RAMP_IDLE, []
|
||||||
|
for _ in range(40):
|
||||||
|
word = leapmotorcan.lcc_ramp_next(word, True, straight_90)
|
||||||
|
seen.append(word)
|
||||||
|
# two ladder steps per frame up to 25 steps (stock: one), then one per frame as stock
|
||||||
|
self.assertEqual(seen[:3], [0x7605, 0x7409, 0x720D])
|
||||||
|
steps_seen = [(leapmotorcan.LCC_RAMP_IDLE - w) // leapmotorcan.LCC_RAMP_STEP for w in seen]
|
||||||
|
self.assertTrue(all((leapmotorcan.LCC_RAMP_IDLE - w) % leapmotorcan.LCC_RAMP_STEP == 0 for w in seen)) # on the ladder
|
||||||
|
self.assertEqual(steps_seen.index(26), 12) # 25 steps passed in 13 frames, about 0.26 s
|
||||||
|
self.assertTrue(all(b - a == 1 for a, b in zip(steps_seen[12:], steps_seen[13:], strict=False) if b != a))
|
||||||
|
self.assertEqual(seen.index(straight_90), 17) # 18 frames instead of stock's 31
|
||||||
|
self.assertEqual(seen[-1], straight_90)
|
||||||
|
# never past the target, even when a double step would overshoot it
|
||||||
|
shallow = leapmotorcan.LCC_RAMP_IDLE - 24 * leapmotorcan.LCC_RAMP_STEP
|
||||||
|
target_25 = leapmotorcan.LCC_RAMP_IDLE - 25 * leapmotorcan.LCC_RAMP_STEP
|
||||||
|
self.assertEqual(leapmotorcan.lcc_ramp_next(shallow, True, target_25), target_25)
|
||||||
|
self.assertEqual(leapmotorcan.lcc_ramp_next(seen[-1], False, straight_90), leapmotorcan.LCC_RAMP_IDLE)
|
||||||
|
# one step per frame toward a new target, both ways
|
||||||
|
deeper = leapmotorcan.lcc_ramp_target(1.5, 75.0)
|
||||||
|
self.assertEqual(leapmotorcan.lcc_ramp_next(straight_90, True, deeper), straight_90 - leapmotorcan.LCC_RAMP_STEP)
|
||||||
|
self.assertEqual(leapmotorcan.lcc_ramp_next(deeper, True, straight_90), deeper + leapmotorcan.LCC_RAMP_STEP)
|
||||||
|
# stock medians per lateral-acceleration band (about 90 km/h), within 2 steps, and the stock range 25-46 steps
|
||||||
|
for alat, stock in ((0.15, 0x593F), (0.45, 0x5547), (0.8, 0x534B), (1.25, 0x4F53)):
|
||||||
|
self.assertLessEqual(abs(leapmotorcan.lcc_ramp_target(alat, 90.0) - stock), 2 * leapmotorcan.LCC_RAMP_STEP, alat)
|
||||||
|
for alat, v in ((0.0, 0.0), (5.0, 150.0)):
|
||||||
|
steps = (leapmotorcan.LCC_RAMP_IDLE - leapmotorcan.lcc_ramp_target(alat, v)) // leapmotorcan.LCC_RAMP_STEP
|
||||||
|
self.assertTrue(leapmotorcan.LCC_RAMP_STEPS_MIN <= steps <= leapmotorcan.LCC_RAMP_STEPS_MAX)
|
||||||
|
# the real stock frames agree: idle when not steering, on the ladder within the stock range while steering
|
||||||
|
for hexdata in REAL_ADAS_LKA["acc"] + REAL_ADAS_LKA["off"]:
|
||||||
|
self.assertEqual(self.unpack(bytes.fromhex(hexdata))["LCC_RAMP"], leapmotorcan.LCC_RAMP_IDLE)
|
||||||
|
for hexdata in REAL_ADAS_LKA["lcc"]:
|
||||||
|
# stock occasionally sits 2 off the ladder (steps of -2/+2 also appear between frames)
|
||||||
|
steps = round((leapmotorcan.LCC_RAMP_IDLE - int(self.unpack(bytes.fromhex(hexdata))["LCC_RAMP"])) / leapmotorcan.LCC_RAMP_STEP)
|
||||||
|
self.assertLessEqual(abs(leapmotorcan.LCC_RAMP_IDLE - steps * leapmotorcan.LCC_RAMP_STEP - int(self.unpack(bytes.fromhex(hexdata))["LCC_RAMP"])), 2)
|
||||||
|
self.assertTrue(leapmotorcan.LCC_RAMP_STEPS_MIN <= steps <= leapmotorcan.LCC_RAMP_STEPS_MAX)
|
||||||
|
|
||||||
|
def test_ramp_boost(self):
|
||||||
|
deepest = leapmotorcan.LCC_RAMP_IDLE - leapmotorcan.LCC_RAMP_STEP * leapmotorcan.LCC_RAMP_STEPS_MAX
|
||||||
|
# extra steps go deeper, never beyond the deepest stock value
|
||||||
|
base = leapmotorcan.lcc_ramp_target(0.1, 15.0)
|
||||||
|
self.assertEqual(leapmotorcan.lcc_ramp_target(0.1, 15.0, 3), base - 3 * leapmotorcan.LCC_RAMP_STEP)
|
||||||
|
self.assertEqual(leapmotorcan.lcc_ramp_target(0.1, 15.0, 100), deepest)
|
||||||
|
self.assertEqual(leapmotorcan.lcc_ramp_target(3.0, 120.0, 5), deepest)
|
||||||
|
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from opendbc.car.leapmotor.carcontroller import CarController, get_safety_CP
|
||||||
|
from opendbc.car.leapmotor.values import CarControllerParams, DBC as LEAPMOTOR_DBC
|
||||||
|
controller = CarController(LEAPMOTOR_DBC["LEAPMOTOR_B10"], get_safety_CP())
|
||||||
|
|
||||||
|
def cs(angle, kph, eps=0):
|
||||||
|
return SimpleNamespace(out=SimpleNamespace(steeringAngleDeg=angle, vEgoRaw=kph / 3.6, steeringTorqueEps=eps))
|
||||||
|
controller.apply_angle_last = 90.
|
||||||
|
for i in range(30): # wheel 10 deg behind at 15 km/h: one step deeper per frame, up to the stock maximum
|
||||||
|
controller.ramp_boost = controller.update_ramp_boost(True, cs(80., 15.))
|
||||||
|
self.assertEqual(controller.ramp_boost, min(i + 1, leapmotorcan.LCC_RAMP_STEPS_MAX - leapmotorcan.LCC_RAMP_STEPS_MIN))
|
||||||
|
controller.ramp_boost = controller.update_ramp_boost(True, cs(88., 15.)) # 2 deg behind: hold
|
||||||
|
self.assertEqual(controller.ramp_boost, 21)
|
||||||
|
controller.ramp_boost = controller.update_ramp_boost(True, cs(89.5, 15.)) # caught up: one step back
|
||||||
|
self.assertEqual(controller.ramp_boost, 20)
|
||||||
|
self.assertEqual(controller.update_ramp_boost(False, cs(80., 15.)), 0) # not steering
|
||||||
|
self.assertEqual(controller.update_ramp_boost(True, cs(80., CarControllerParams.RAMP_BOOST_MAX_SPEED + 1)), 0) # fast
|
||||||
|
|
||||||
|
# near the EPS torque at which it flags an override by itself: no deeper, then back off, even while lagging
|
||||||
|
hold, back = CarControllerParams.RAMP_BOOST_EPS_TORQUE_HOLD, CarControllerParams.RAMP_BOOST_EPS_TORQUE_BACK
|
||||||
|
controller.ramp_boost = 10
|
||||||
|
for eps in (hold, -hold, back - 1, -(back - 1)):
|
||||||
|
self.assertEqual(controller.update_ramp_boost(True, cs(80., 15., eps)), 10)
|
||||||
|
for eps in (back, -back, -218):
|
||||||
|
controller.ramp_boost = 10
|
||||||
|
self.assertEqual(controller.update_ramp_boost(True, cs(80., 15., eps)), 9)
|
||||||
|
self.assertEqual(controller.update_ramp_boost(True, cs(80., 15., hold - 1)), 11) # below the hold: deeper again
|
||||||
|
|
||||||
|
def test_driver_torque_lags_the_eps(self):
|
||||||
|
from opendbc.car.leapmotor.carstate import CarState
|
||||||
|
from opendbc.car.leapmotor.interface import CarInterface
|
||||||
|
|
||||||
|
def pressed(driver, eps):
|
||||||
|
CP = CarInterface.get_non_essential_params("LEAPMOTOR_B10")
|
||||||
|
CS = CarState(CP)
|
||||||
|
parsers = CS.get_can_parsers(CP)
|
||||||
|
packer = CANPacker("leapmotor_b10")
|
||||||
|
out = []
|
||||||
|
for i, (d, e) in enumerate(zip(driver, eps, strict=True)):
|
||||||
|
dat = packer.make_can_msg("EPS_STEERING", 0, {"STEER_TORQUE_DRIVER": d, "STEER_TORQUE_EPS": e, "COUNTER": i % 16})[1]
|
||||||
|
parsers[Bus.pt].update([(int((i + 1) * 1e7), [(0x18D, dat, 0)])])
|
||||||
|
parsers[Bus.cam].update([(int((i + 1) * 1e7), [])])
|
||||||
|
CS.update(parsers)
|
||||||
|
out.append(CS.driver_override)
|
||||||
|
return out
|
||||||
|
|
||||||
|
# hands off in a roundabout at 28 km/h (route 264): the EPS swings -99 -> +98 within 0.1 s while the reading barely
|
||||||
|
# moves; subtracting the EPS's share without its lag read above 3 for 8 of these frames and let go of the wheel
|
||||||
|
driver = [2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0]
|
||||||
|
eps = [9, 1, -16, -14, -22, -28, -31, -38, -44, -37, -18, -1, 15, 25, 27, 20, 17, 13, 8, -9, -37, -73, -99, -84, -52,
|
||||||
|
-4, 58, 78, 98, 96, 75, 53, 35, 16, 0, -15]
|
||||||
|
self.assertFalse(any(pressed(driver, eps)))
|
||||||
|
# the driver's lane-change nudge at 126 km/h (route 25c): the EPS holds -57 against the hands, the reading stays at 0
|
||||||
|
driver = [1, 1, 1, 1, 1, 0, 0, 0, 0, 1] + [0] * 20
|
||||||
|
eps = [-12, -7, -7, -6, -8, -14, -28, -47, -57, -56] + [-57] * 20
|
||||||
|
self.assertTrue(any(pressed(driver, eps)))
|
||||||
|
|
||||||
|
def test_override_while_the_wheel_follows(self):
|
||||||
|
# route 0000000a 12:31:42.9, left bend at 33 km/h, the driver's hand resting on the wheel: the EPS holds about 130 into
|
||||||
|
# the turn, the reading follows less of it than assumed and the EPS sets its own flag. The previous rule let go and
|
||||||
|
# the wheel sprang back 14 deg; the tracking rule keeps steering. A driver turning against the EPS still counts.
|
||||||
|
from opendbc.car.leapmotor.carstate import CarState
|
||||||
|
from opendbc.car.leapmotor.interface import CarInterface
|
||||||
|
|
||||||
|
def run(frames, angle=-41.):
|
||||||
|
CP = CarInterface.get_non_essential_params("LEAPMOTOR_B10")
|
||||||
|
CS = CarState(CP)
|
||||||
|
parsers = CS.get_can_parsers(CP)
|
||||||
|
packer = CANPacker("leapmotor_b10")
|
||||||
|
for i, (driver, eps, flag) in enumerate(frames):
|
||||||
|
dat = packer.make_can_msg("EPS_STEERING", 0, {"STEER_TORQUE_DRIVER": driver, "STEER_TORQUE_EPS": eps, "DRIVER_OVERRIDE": flag,
|
||||||
|
"STEER_ANGLE": angle, "COUNTER": i % 16})[1]
|
||||||
|
parsers[Bus.pt].update([(int((i + 1) * 1e7), [(0x18D, dat, 0)])])
|
||||||
|
parsers[Bus.cam].update([(int((i + 1) * 1e7), [])])
|
||||||
|
CS.update(parsers)
|
||||||
|
return CS
|
||||||
|
|
||||||
|
hands_off = [(-4, 120, 0)] * 40 + [(-5, 133, 0)] * 3 + [(-3, 133, 1)] * 3
|
||||||
|
CS = run(hands_off)
|
||||||
|
self.assertTrue(CS.driver_override)
|
||||||
|
self.assertFalse(CS.driver_override_tracking)
|
||||||
|
# the driver straightens the wheel against the EPS: the reading goes well past the EPS's share
|
||||||
|
CS = run([(-4, 120, 0)] * 40 + [(-16, 133, 1)] * 8)
|
||||||
|
self.assertTrue(CS.driver_override)
|
||||||
|
self.assertTrue(CS.driver_override_tracking)
|
||||||
|
|
||||||
|
def test_tracking_rule_only_while_the_wheel_follows(self):
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from opendbc.car import structs as car_structs
|
||||||
|
from opendbc.car.leapmotor.carcontroller import CarController as Controller, get_safety_CP as safety_CP
|
||||||
|
from opendbc.car.leapmotor.values import DBC as CAR_DBC
|
||||||
|
|
||||||
|
def steering(wheel, command=-43.):
|
||||||
|
controller = Controller(CAR_DBC["LEAPMOTOR_B10"], safety_CP())
|
||||||
|
CC = car_structs.CarControl()
|
||||||
|
CC.latActive = True
|
||||||
|
CC.actuators.steeringAngleDeg = command
|
||||||
|
CS = SimpleNamespace(driver_override=False, driver_override_tracking=False, adas_lka=None,
|
||||||
|
powertrain_state=None, out=SimpleNamespace(steeringAngleDeg=-43., vEgoRaw=33 / 3.6, steeringTorqueEps=130))
|
||||||
|
controller.lat_active_last, controller.apply_angle_last = True, command # steering, the wheel following
|
||||||
|
CS.driver_override = True
|
||||||
|
CS.out.steeringAngleDeg = wheel
|
||||||
|
controller.update(CC.as_reader(), CS, 0)
|
||||||
|
return controller.lat_active_last
|
||||||
|
|
||||||
|
self.assertTrue(steering(-41.)) # follows within 3 deg: the tracking rule, which sees no driver
|
||||||
|
self.assertTrue(steering(1., command=2.)) # also near straight ahead
|
||||||
|
self.assertFalse(steering(-36.)) # held 7 deg short: the previous rule lets go
|
||||||
|
self.assertFalse(steering(3., command=12.)) # held straight against a 12 deg command (route 00000010 23:18:35)
|
||||||
|
|
||||||
|
def test_accel_replaces_only_the_request(self):
|
||||||
|
# with openpilot longitudinal, only ACC_ACCEL_REQ changes besides the steering fields
|
||||||
|
for hexdata in REAL_ADAS_LKA["acc"]:
|
||||||
|
dat = bytes.fromhex(hexdata)
|
||||||
|
camera = self.unpack(dat)
|
||||||
|
for accel in (-3.5, -0.75, 0.0, 1.2):
|
||||||
|
_, out, _ = leapmotorcan.create_steering_control(CANPacker("leapmotor_b10"), camera, camera["STEER_ANGLE_REQ"], False,
|
||||||
|
accel=accel)
|
||||||
|
got = self.unpack(bytes(out))
|
||||||
|
self.assertAlmostEqual(got["ACC_ACCEL_REQ"], accel, delta=0.026)
|
||||||
|
for i in range(2, len(dat)):
|
||||||
|
if i not in STEERING_BYTES | {4}:
|
||||||
|
self.assertEqual(out[i], dat[i], f"byte {i}")
|
||||||
|
|
||||||
|
def test_long_accel(self):
|
||||||
|
CP = get_safety_CP()
|
||||||
|
CP.openpilotLongitudinalControl = True
|
||||||
|
CC = structs.CarControl()
|
||||||
|
controller = CarController(DBC_NAMES, CP)
|
||||||
|
limits = CarControllerParams
|
||||||
|
cases = [
|
||||||
|
# longActive, ACC_STATE, camera request, openpilot request -> sent (None = the camera's)
|
||||||
|
(False, 3, -1.0, -0.5, None), # openpilot not in control
|
||||||
|
(True, 2, 0.0, -0.5, None), # stock ACC not engaged
|
||||||
|
(True, 1, 1.5, -0.5, None), # accelerator override
|
||||||
|
(True, 3, -1.0, -0.5, -0.5), # openpilot may brake less than stock ACC's normal braking
|
||||||
|
(True, 3, -1.0, 5.0, limits.ACCEL_MAX),
|
||||||
|
(True, 3, -1.0, -9.0, limits.ACCEL_MIN),
|
||||||
|
(True, 3, -2.0, -0.5, -2.0), # but never less than the camera's hard braking
|
||||||
|
(True, 3, -2.6, -3.0, -3.0),
|
||||||
|
]
|
||||||
|
for long_active, acc_state, camera_accel, accel, expected in cases:
|
||||||
|
with self.subTest(long_active=long_active, acc_state=acc_state, camera_accel=camera_accel, accel=accel):
|
||||||
|
CC.longActive = long_active
|
||||||
|
CC.actuators.accel = accel
|
||||||
|
self.assertEqual(controller.long_accel(CC, {"ACC_STATE": acc_state, "ACC_ACCEL_REQ": camera_accel}), expected)
|
||||||
|
# without openpilot longitudinal the camera's request always goes through
|
||||||
|
CP.openpilotLongitudinalControl = False
|
||||||
|
CC.longActive = True
|
||||||
|
self.assertIsNone(CarController(DBC_NAMES, CP).long_accel(CC, {"ACC_STATE": 3, "ACC_ACCEL_REQ": -1.0}))
|
||||||
|
|
||||||
|
def test_take_back(self):
|
||||||
|
from types import SimpleNamespace
|
||||||
|
from opendbc.car import structs as car_structs
|
||||||
|
from opendbc.car.leapmotor.carcontroller import CarController as Controller, get_safety_CP as safety_CP
|
||||||
|
from opendbc.car.leapmotor.values import DBC as CAR_DBC
|
||||||
|
|
||||||
|
def steering_after_let_go(wanted, wheel, kph=25.):
|
||||||
|
controller = Controller(CAR_DBC["LEAPMOTOR_B10"], safety_CP())
|
||||||
|
CC = car_structs.CarControl()
|
||||||
|
CC.latActive = True
|
||||||
|
CC.actuators.steeringAngleDeg = wanted
|
||||||
|
CS = SimpleNamespace(driver_override=False, adas_lka=None, powertrain_state=None,
|
||||||
|
out=SimpleNamespace(steeringAngleDeg=wheel, vEgoRaw=kph / 3.6, steeringTorqueEps=0))
|
||||||
|
controller.update(CC.as_reader(), CS, 0)
|
||||||
|
return controller.lat_active_last
|
||||||
|
|
||||||
|
# right after the driver lets go in a bend the wheel is 11-27 deg from the model's angle: take it back at once
|
||||||
|
self.assertTrue(steering_after_let_go(100., 73.))
|
||||||
|
self.assertTrue(steering_after_let_go(100., 100. - 44.))
|
||||||
|
# the case the check was made for: wheel at +308 deg, model at +24, at walking pace
|
||||||
|
self.assertFalse(steering_after_let_go(24., 308., kph=5.))
|
||||||
|
|
||||||
|
def test_eps_status_bit_is_not_torque(self):
|
||||||
|
# Real EPS_STEERING frames from route 26e (22:19:39, openpilot steering at 60 km/h): bit 180 turns on for 1 s. Read
|
||||||
|
# as part of the torque it added 4096, which looked like a driver torque of +264 and let go of the wheel mid-turn.
|
||||||
|
frames = ["350B0265810000448EF25001070700002B02870FA30904000000000000000000",
|
||||||
|
"5E0C0265810103448EF75001070700002B02870FA30814000000000000000000"]
|
||||||
|
sigs = DBC("leapmotor_b10").addr_to_msg[0x18D].sigs
|
||||||
|
for hexdata, (torque, status) in zip(frames, ((33, 0), (32, 1)), strict=True):
|
||||||
|
dat = bytes.fromhex(hexdata)
|
||||||
|
self.assertEqual(dat[0], leapmotor_checksum(0x18D, None, bytearray(dat)))
|
||||||
|
eps = sigs["STEER_TORQUE_EPS"]
|
||||||
|
self.assertEqual(eps.get_raw_value(dat) * eps.factor + eps.offset, torque)
|
||||||
|
self.assertEqual(sigs["EPS_STATUS_180"].get_raw_value(dat), status)
|
||||||
|
|
||||||
|
from opendbc.car.leapmotor.carstate import CarState
|
||||||
|
from opendbc.car.leapmotor.interface import CarInterface
|
||||||
|
CP = CarInterface.get_non_essential_params("LEAPMOTOR_B10")
|
||||||
|
CS = CarState(CP)
|
||||||
|
parsers = CS.get_can_parsers(CP)
|
||||||
|
for i in range(20):
|
||||||
|
parsers[Bus.pt].update([(int((i + 1) * 1e7), [(0x18D, bytes.fromhex(frames[min(i, 1)]), 0)])])
|
||||||
|
parsers[Bus.cam].update([(int((i + 1) * 1e7), [])])
|
||||||
|
ret = CS.update(parsers)
|
||||||
|
self.assertLess(abs(ret.steeringTorqueEps), 100)
|
||||||
|
self.assertFalse(CS.driver_override)
|
||||||
|
|
||||||
|
def test_dashboard_speed_limit(self):
|
||||||
|
# the camera's posted limit is offered as the dashboard source, and expires with the camera's frames
|
||||||
|
from opendbc.car.dashboard_speed_limit import Status
|
||||||
|
from opendbc.car.leapmotor.carstate import CarState
|
||||||
|
from opendbc.car.leapmotor.interface import CarInterface
|
||||||
|
CP = CarInterface.get_non_essential_params("LEAPMOTOR_B10")
|
||||||
|
CS = CarState(CP)
|
||||||
|
parsers = CS.get_can_parsers(CP)
|
||||||
|
packer = CANPacker("leapmotor_b10")
|
||||||
|
|
||||||
|
def frame(i, limit):
|
||||||
|
t = int((i + 1) * 2e7)
|
||||||
|
parsers[Bus.pt].update([(t, [])])
|
||||||
|
parsers[Bus.cam].update([(t, [packer.make_can_msg("ROAD_SIGNS", 2, {"SPEED_LIMIT": limit, "COUNTER": i % 16})])])
|
||||||
|
CS.update(parsers)
|
||||||
|
return CS.dashboard_limit.observation, t
|
||||||
|
|
||||||
|
for i in range(60): # the parser learns the camera's frame rate, and so the expiry, after 1 s
|
||||||
|
observation, t = frame(i, 50)
|
||||||
|
self.assertEqual(observation.status, Status.VALID)
|
||||||
|
self.assertAlmostEqual(observation.speed_mps, 50 / 3.6)
|
||||||
|
self.assertEqual(observation.observed_ns, t)
|
||||||
|
self.assertGreater(observation.valid_until_ns, t)
|
||||||
|
episode = observation.episode
|
||||||
|
observation, _ = frame(60, 30)
|
||||||
|
self.assertAlmostEqual(observation.speed_mps, 30 / 3.6)
|
||||||
|
self.assertGreater(observation.episode, episode)
|
||||||
|
for i, limit in enumerate((0, 255), start=61):
|
||||||
|
observation, _ = frame(i, limit)
|
||||||
|
self.assertEqual(observation.status, Status.UNKNOWN)
|
||||||
|
|
||||||
|
def test_cancel_push_is_a_cancel_button(self):
|
||||||
|
# only the stalk pushed up (STALK_PUSH 3) is reported, as a cancel press and release; the engage pushes are not
|
||||||
|
from opendbc.car.leapmotor.carstate import CarState
|
||||||
|
from opendbc.car.leapmotor.interface import CarInterface
|
||||||
|
CP = CarInterface.get_non_essential_params("LEAPMOTOR_B10")
|
||||||
|
CS = CarState(CP)
|
||||||
|
parsers = CS.get_can_parsers(CP)
|
||||||
|
packer = CANPacker("leapmotor_b10")
|
||||||
|
|
||||||
|
def frame(i, stalk):
|
||||||
|
msgs = [packer.make_can_msg("POWERTRAIN_STATE", 0, {"ASSIST_ENGAGED": 1, "STALK_PUSH": stalk, "COUNTER": i % 16})]
|
||||||
|
parsers[Bus.pt].update([(int((i + 1) * 1e7), msgs)])
|
||||||
|
parsers[Bus.cam].update([(int((i + 1) * 1e7), [])])
|
||||||
|
return [(b.type, b.pressed) for b in CS.update(parsers).buttonEvents]
|
||||||
|
|
||||||
|
cancel = structs.CarState.ButtonEvent.Type.cancel
|
||||||
|
pushes = [frame(i, stalk) for i, stalk in enumerate((0, 1, 1, 0, 2, 0, 3, 3, 0))]
|
||||||
|
self.assertEqual(pushes, [[], [], [], [], [], [], [(cancel, True)], [], [(cancel, False)]])
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
from dataclasses import dataclass, field
|
||||||
|
from enum import IntFlag
|
||||||
|
|
||||||
|
from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms
|
||||||
|
from opendbc.car.docs_definitions import CarDocs, CarHarness, CarParts
|
||||||
|
from opendbc.car.lateral import AngleSteeringLimitsVM
|
||||||
|
from opendbc.car.fw_query_definitions import FwQueryConfig, Request
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
|
||||||
|
Ecu = CarParams.Ecu
|
||||||
|
|
||||||
|
|
||||||
|
class CarControllerParams:
|
||||||
|
STEER_STEP = 2 # ADAS_LKA (0x83) is sent at 50 Hz
|
||||||
|
|
||||||
|
# Must match opendbc/safety/modes/leapmotor.h. openpilot's standard vehicle-model limits: lateral accel and
|
||||||
|
# lateral jerk of about 3.6 (m/s^2, m/s^3), so near-full lock is allowed up to about 15 km/h (U-turns) and
|
||||||
|
# about 50 deg at 50 km/h. Stock LCC stays below 2.3 m/s^2 on every recorded route.
|
||||||
|
ANGLE_LIMITS: AngleSteeringLimitsVM = AngleSteeringLimitsVM(
|
||||||
|
500, # deg; mechanical lock is about 522 deg, keep a margin so the EPS never drives into the end stop
|
||||||
|
MAX_ANGLE_RATE=5, # deg per 20 ms frame (250 deg/s): lock to lock in about 4 s. EPS fault rate untested
|
||||||
|
)
|
||||||
|
# EPS_STEERING.STEER_TORQUE_DRIVER (unit unknown) also follows the EPS's own effort: while openpilot steered and the
|
||||||
|
# EPS flagged no override it read -1 per 16.8 of STEER_TORQUE_EPS (r -0.88, 317k frames on 2 drives). Adding that
|
||||||
|
# share back leaves the driver's torque: above 3 on 0.14% of those frames but on 75% of frames the EPS flagged as
|
||||||
|
# overrides. With the 5-frame debounce in carstate it caught all 3 of the driver's lane-change nudges at 125 km/h,
|
||||||
|
# where the raw reading stayed at 1, and nothing else above 118 km/h over the 2 drives.
|
||||||
|
# The reading lags the EPS by a few frames: when the EPS swung its torque quickly in roundabouts (e.g. +76 to -120 in
|
||||||
|
# 0.1 s), subtracting the unlagged share left 4-6 with the driver's hands off and let go of the wheel mid-turn.
|
||||||
|
# Refitted on 665k hands-off frames of 7 drives as a first-order lag of 0.04 s and 1 per 15.5: frames above 3 during
|
||||||
|
# such swings fell from 18% to 2.6%. Replayed on the same drives, the false let-gos right after the EPS pushed 90 or
|
||||||
|
# more fell from 56 to 17; every takeover that lasted 0.5 s or more was still caught (35 of 35, at most 40 ms later),
|
||||||
|
# and so was every let-go above 110 km/h, including all of the 125 km/h nudges.
|
||||||
|
EPS_TORQUE_PER_DRIVER_TORQUE = 15.5
|
||||||
|
EPS_TORQUE_LAG = 0.04 # s
|
||||||
|
STEER_DRIVER_ALLOWANCE = 3
|
||||||
|
# While steering, the EPS often pushes 50-175, and the reading follows less of that than EPS_TORQUE_PER_DRIVER_TORQUE
|
||||||
|
# assumes: what is left over looks like the driver turning with the EPS (3-5), and the EPS's own DRIVER_OVERRIDE flag
|
||||||
|
# comes on with it. openpilot let go, the wheel sprang back 3-94 deg and the car drifted (route 0000000a, 12:30-12:31
|
||||||
|
# in bends, the driver's hand resting on the wheel on the driver camera). So while the wheel follows openpilot's
|
||||||
|
# angle within OVERRIDE_TRACKING_ERROR, torque in the EPS's own direction counts only as far as the raw reading shows
|
||||||
|
# it, and the flag needs the driver's torque against the EPS too. A driver who steers moves the wheel off openpilot's
|
||||||
|
# angle, and from there the previous rule applies: of 218 let-gos on 8 drives, all 101 that came with the wheel
|
||||||
|
# already 3 deg or more off (the driver holding it straight against a 12 deg command at route 00000010 23:18:35
|
||||||
|
# among them) are unchanged. Of the 38 after which the wheel sprang back, 37 no longer happen at that moment.
|
||||||
|
# A model of the EPS torque needed hands-off (from speed, lateral acceleration, angle and rate) did not tell them
|
||||||
|
# apart: at every kind of let-go the EPS was 60-70 above it.
|
||||||
|
OVERRIDE_TRACKING_ERROR = 3. # deg
|
||||||
|
OVERRIDE_OPPOSING_TORQUE = 1.
|
||||||
|
# Largest gap (deg) between openpilot's angle and the wheel's at which it takes the wheel back. It stops the case it was
|
||||||
|
# made for: at walking pace the driver let go with the wheel at +308 deg and the model at +24, and the EPS swung it to
|
||||||
|
# -203 deg. 10 deg was too tight: right after the driver lets go in a bend the gap is 11-27 deg, and on route 26b
|
||||||
|
# openpilot then did not steer for 0.8-1.7 s mid-turn (5 times), drifting wide. The command still starts from the
|
||||||
|
# wheel's angle and is rate limited, and the LCC ramp builds up the torque.
|
||||||
|
TAKE_BACK_MAX_ANGLE_ERROR = 45.
|
||||||
|
# The stock ramp depth follows lateral acceleration, which stays small in sharp turns at low speed: there the wheel
|
||||||
|
# fell > 5 deg behind with the EPS near its torque ceiling (25d, 260). While the wheel is RAMP_BOOST_LAG behind the
|
||||||
|
# command below RAMP_BOOST_MAX_SPEED, the ramp goes one step deeper per frame (up to the deepest stock value, 46 steps,
|
||||||
|
# about +/-70 torque), and back one step per frame once within RAMP_BOOST_CAUGHT_UP. Replayed on 3 drives: active
|
||||||
|
# 23-31% of the time below 30 km/h, 3-7% at 30-80 km/h. Not at speed, where such a lag was the driver's own nudge.
|
||||||
|
RAMP_BOOST_LAG = 3. # deg
|
||||||
|
RAMP_BOOST_CAUGHT_UP = 1.5 # deg
|
||||||
|
RAMP_BOOST_MAX_SPEED = 60. # km/h
|
||||||
|
# Past about 150 of STEER_TORQUE_EPS the EPS sets its own DRIVER_OVERRIDE flag with the driver's hands off, and
|
||||||
|
# openpilot lets go like the stock LCC does: engaged frames with the flag set were 0-1% below 130, 9% at 130-160
|
||||||
|
# and 50% above 160 (a test build ramping to 56 steps; 28% above 160 at 52 steps). In a tightening turn at 25 km/h
|
||||||
|
# the boost drove it to -167..-218 three times, the EPS let go each time and the wheel sprang back 25-30 deg.
|
||||||
|
# So the boost goes no deeper from RAMP_BOOST_EPS_TORQUE_HOLD and backs off from RAMP_BOOST_EPS_TORQUE_BACK. With
|
||||||
|
# it, the EPS peaked at 136 through a 72 deg turn at 33-47 km/h and never flagged an override above 100.
|
||||||
|
RAMP_BOOST_EPS_TORQUE_HOLD = 100
|
||||||
|
RAMP_BOOST_EPS_TORQUE_BACK = 120
|
||||||
|
|
||||||
|
# Longitudinal (alpha): ADAS_LKA.ACC_ACCEL_REQ, 0.05 m/s^2 per bit, raw 100 = 0. Must match opendbc/safety/modes/leapmotor.h.
|
||||||
|
# Stock ACC never asked for less than -2.7 m/s^2 in about 5 h of engaged driving; the car follows the request
|
||||||
|
# (-2.6 asked, -2.69 measured) and blends regen with light friction braking itself.
|
||||||
|
ACCEL_MIN = -3.5 # m/s^2
|
||||||
|
ACCEL_MAX = 2.0 # m/s^2
|
||||||
|
# When the camera asks for this much braking or more, openpilot never asks for less: the camera's emergency braking
|
||||||
|
# path is not yet known and may use this field. Stock ACC went below it on 0.02% of engaged frames.
|
||||||
|
STOCK_BRAKE_PASSTHROUGH = -2.0 # m/s^2
|
||||||
|
|
||||||
|
|
||||||
|
class LeapmotorSafetyFlags(IntFlag):
|
||||||
|
LONG_CONTROL = 1
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class LeapmotorCarDocs(CarDocs):
|
||||||
|
package: str = "Adaptive Cruise Control (ACC) & Lane Centering Control (LCC)"
|
||||||
|
car_parts: CarParts = field(default_factory=CarParts.common([CarHarness.custom]))
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class LeapmotorPlatformConfig(PlatformConfig):
|
||||||
|
dbc_dict: DbcDict = field(default_factory=lambda: {
|
||||||
|
Bus.pt: 'leapmotor_b10',
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
class CAR(Platforms):
|
||||||
|
# wheelbase: Italian brochure, B10 Life with the 56.2 kWh Pro battery.
|
||||||
|
# steerRatio 15.2 is measured from slow figure-eights (steering angle vs. yaw rate / speed).
|
||||||
|
LEAPMOTOR_B10 = LeapmotorPlatformConfig(
|
||||||
|
[LeapmotorCarDocs("Leapmotor B10 2025")],
|
||||||
|
CarSpecs(mass=1780, wheelbase=2.735, steerRatio=15.2),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Part number (F187), physical request = reply minus 8: EPS 0x735, brake 0x736, front camera 0x756, all confirmed by a
|
||||||
|
# read-only UDS probe on the car. No tester present first: the camera did not answer openpilot's query when it led with
|
||||||
|
# one, but answers F187 directly. At ignition, before READY, only the brake answers (the EPS stays silent until READY,
|
||||||
|
# the camera is slow), so the EPS and camera are non-essential; their part numbers are still checked when present.
|
||||||
|
PART_NUMBER_REQUEST = bytes([0x22, 0xF1, 0x87])
|
||||||
|
PART_NUMBER_RESPONSE = bytes([0x62, 0xF1, 0x87])
|
||||||
|
|
||||||
|
FW_QUERY_CONFIG = FwQueryConfig(
|
||||||
|
requests=[
|
||||||
|
Request(
|
||||||
|
[PART_NUMBER_REQUEST],
|
||||||
|
[PART_NUMBER_RESPONSE],
|
||||||
|
whitelist_ecus=[Ecu.eps, Ecu.abs, Ecu.fwdCamera],
|
||||||
|
bus=0,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
non_essential_ecus={
|
||||||
|
Ecu.eps: [CAR.LEAPMOTOR_B10],
|
||||||
|
Ecu.fwdCamera: [CAR.LEAPMOTOR_B10],
|
||||||
|
},
|
||||||
|
# part numbers such as 3401100-AG01, zero-padded to 19 bytes
|
||||||
|
fw_version_regex=br"\d{7}-[A-Z]{2}\d{2}\x00{7}",
|
||||||
|
)
|
||||||
|
|
||||||
|
DBC = CAR.create_dbc_map()
|
||||||
@@ -3,12 +3,17 @@ from opendbc.can import CANDefine, CANParser
|
|||||||
from opendbc.car import Bus, structs, create_button_events
|
from opendbc.car import Bus, structs, create_button_events
|
||||||
from opendbc.car.common.conversions import Conversions as CV
|
from opendbc.car.common.conversions import Conversions as CV
|
||||||
from opendbc.car.interfaces import CarStateBase
|
from opendbc.car.interfaces import CarStateBase
|
||||||
|
from opendbc.car.subaru.stock_aol import qualified as stock_aol_qualified
|
||||||
from opendbc.car.subaru.values import CAR, DBC, CanBus, SubaruFlags
|
from opendbc.car.subaru.values import CAR, DBC, CanBus, SubaruFlags
|
||||||
from opendbc.car import CanSignalRateCalculator
|
from opendbc.car import CanSignalRateCalculator
|
||||||
|
|
||||||
# 8-speed Lineartronic CVT simulated paddle-shift ratios 1..8 on 0x48 Transmission.Gear
|
# 8-speed Lineartronic CVT simulated paddle-shift ratios 1..8 on 0x48 Transmission.Gear
|
||||||
# (bits 0..2 = 0b001 Drive range, bits 3..6 = simulated gear 1..8 or 0 in shift transition, bit 7 = manual mode)
|
# (bits 0..2 = 0b001 Drive range, bits 3..6 = simulated gear 1..8 or 0 in shift transition, bit 7 = manual mode)
|
||||||
SUBARU_CVT_MANUAL_GEARS = frozenset({129, 137, 145, 153, 161, 169, 177, 185, 193})
|
SUBARU_CVT_MANUAL_GEARS = frozenset({129, 137, 145, 153, 161, 169, 177, 185, 193})
|
||||||
|
# Drive range with ratio zero, with either state of the manual-mode bit.
|
||||||
|
PADDLE_EXIT_GEARS = (1, 129)
|
||||||
|
PADDLE_EXIT_WINDOW_NS = 750_000_000
|
||||||
|
PADDLE_EXIT_PAUSE_NS = 150_000_000
|
||||||
|
|
||||||
|
|
||||||
class CarState(CarStateBase):
|
class CarState(CarStateBase):
|
||||||
@@ -20,6 +25,9 @@ class CarState(CarStateBase):
|
|||||||
self.avh_sources = AvhSources() if avh_selected(CP) else None
|
self.avh_sources = AvhSources() if avh_selected(CP) else None
|
||||||
can_define = CANDefine(DBC[CP.carFingerprint][Bus.pt])
|
can_define = CANDefine(DBC[CP.carFingerprint][Bus.pt])
|
||||||
self.shifter_values = can_define.dv["Transmission"]["Gear"]
|
self.shifter_values = can_define.dv["Transmission"]["Gear"]
|
||||||
|
self.paddle_ratio_ns = 0
|
||||||
|
self.paddle_exit_pause_ns = 0
|
||||||
|
self.paddle_exit_in_drive = False
|
||||||
|
|
||||||
self.sng_sources = {}
|
self.sng_sources = {}
|
||||||
self.sng_source_valid = {}
|
self.sng_source_valid = {}
|
||||||
@@ -64,6 +72,36 @@ class CarState(CarStateBase):
|
|||||||
self._lkas_mode_settle_frames = max(0, self._lkas_mode_settle_frames - 1)
|
self._lkas_mode_settle_frames = max(0, self._lkas_mode_settle_frames - 1)
|
||||||
self._prev_aol_enabled = aol
|
self._prev_aol_enabled = aol
|
||||||
|
|
||||||
|
def _paddle_exit_paused(self, parser: CANParser) -> bool:
|
||||||
|
gear_ns = parser.ts_nanos["Transmission"]["Gear"]
|
||||||
|
now_ns = parser.last_nonempty_nanos
|
||||||
|
if parser.bus_timeout or not 0 < gear_ns <= now_ns:
|
||||||
|
self.paddle_ratio_ns = self.paddle_exit_pause_ns = 0
|
||||||
|
self.paddle_exit_in_drive = False
|
||||||
|
return False
|
||||||
|
|
||||||
|
for gear in parser.vl_all["Transmission"]["Gear"]:
|
||||||
|
position = self.shifter_values.get(int(gear))
|
||||||
|
if position in ("1", "2", "3", "4", "5", "6"):
|
||||||
|
self.paddle_ratio_ns = gear_ns
|
||||||
|
self.paddle_exit_in_drive = False
|
||||||
|
self.paddle_exit_pause_ns = 0
|
||||||
|
elif position == "D":
|
||||||
|
self.paddle_exit_in_drive = True
|
||||||
|
self.paddle_exit_pause_ns = 0
|
||||||
|
elif gear in PADDLE_EXIT_GEARS and self.paddle_exit_in_drive:
|
||||||
|
if not self.paddle_exit_pause_ns and 0 < self.paddle_ratio_ns <= gear_ns <= self.paddle_ratio_ns + PADDLE_EXIT_WINDOW_NS:
|
||||||
|
self.paddle_exit_pause_ns = gear_ns
|
||||||
|
self.paddle_ratio_ns = 0
|
||||||
|
else:
|
||||||
|
self.paddle_ratio_ns = self.paddle_exit_pause_ns = 0
|
||||||
|
self.paddle_exit_in_drive = False
|
||||||
|
|
||||||
|
# Report the transition as a paddle pause so both Card and SelfdriveD
|
||||||
|
# withdraw steering until the transmission reports Drive again.
|
||||||
|
return bool(0 < self.paddle_exit_pause_ns <= now_ns < self.paddle_exit_pause_ns + PADDLE_EXIT_PAUSE_NS and
|
||||||
|
stock_aol_qualified(self.CP, marked_only=True))
|
||||||
|
|
||||||
def update(self, can_parsers) -> structs.CarState:
|
def update(self, can_parsers) -> structs.CarState:
|
||||||
cp = can_parsers[Bus.pt]
|
cp = can_parsers[Bus.pt]
|
||||||
cp_cam = can_parsers[Bus.cam]
|
cp_cam = can_parsers[Bus.cam]
|
||||||
@@ -110,7 +148,10 @@ class CarState(CarStateBase):
|
|||||||
can_gear = int(cp_transmission.vl["Transmission"]["Gear"])
|
can_gear = int(cp_transmission.vl["Transmission"]["Gear"])
|
||||||
if self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025 and can_gear in SUBARU_CVT_MANUAL_GEARS:
|
if self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025 and can_gear in SUBARU_CVT_MANUAL_GEARS:
|
||||||
ret.gearShifter = structs.CarState.GearShifter.manumatic
|
ret.gearShifter = structs.CarState.GearShifter.manumatic
|
||||||
elif self.CP.carFingerprint == CAR.SUBARU_IMPREZA_2020 and self.shifter_values.get(can_gear) in ("1", "2", "3", "4", "5", "6"):
|
elif self.CP.carFingerprint == CAR.SUBARU_IMPREZA_2020 and (
|
||||||
|
self._paddle_exit_paused(cp_transmission) or
|
||||||
|
self.shifter_values.get(can_gear) in ("1", "2", "3", "4", "5", "6")
|
||||||
|
):
|
||||||
ret.gearShifter = structs.CarState.GearShifter.manumatic
|
ret.gearShifter = structs.CarState.GearShifter.manumatic
|
||||||
elif self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025 and can_gear == 0:
|
elif self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025 and can_gear == 0:
|
||||||
ret.gearShifter = structs.CarState.GearShifter.neutral
|
ret.gearShifter = structs.CarState.GearShifter.neutral
|
||||||
|
|||||||
@@ -26,5 +26,5 @@ def capture(interface, packets):
|
|||||||
and data[0] == ((address & 255) + (address >> 8) + sum(data[1:])) & 255
|
and data[0] == ((address & 255) + (address >> 8) + sum(data[1:])) & 255
|
||||||
and (previous is None or source_ns > previous[0] and data[1] & 15 != previous[1][1] & 15)
|
and (previous is None or source_ns > previous[0] and data[1] & 15 != previous[1][1] & 15)
|
||||||
):
|
):
|
||||||
state.sng_source_valid[address] = previous is not None and data[1] & 15 == ((previous[1][1] + 1) & 15)
|
state.sng_source_valid[address] = previous is not None and data[1] & 15 != previous[1][1] & 15
|
||||||
state.sng_sources[address] = (source_ns, bytes(data))
|
state.sng_sources[address] = (source_ns, bytes(data))
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ from opendbc.car.body.values import CAR as COMMA
|
|||||||
from opendbc.car.byd.values import CAR as BYD
|
from opendbc.car.byd.values import CAR as BYD
|
||||||
from opendbc.car.psa.values import CAR as PSA
|
from opendbc.car.psa.values import CAR as PSA
|
||||||
from opendbc.car.mg.values import CAR as MG
|
from opendbc.car.mg.values import CAR as MG
|
||||||
|
from opendbc.car.leapmotor.values import CAR as LEAPMOTOR
|
||||||
|
|
||||||
# Configurations with source tests but no matching recorded route.
|
# Configurations with source tests but no matching recorded route.
|
||||||
unrecorded_route_gaps = {
|
unrecorded_route_gaps = {
|
||||||
@@ -99,6 +100,7 @@ non_tested_cars = [
|
|||||||
HYUNDAI.HYUNDAI_ELANTRA_2022_NON_SCC,
|
HYUNDAI.HYUNDAI_ELANTRA_2022_NON_SCC,
|
||||||
HYUNDAI.HYUNDAI_ELANTRA_HEV_2022_NON_SCC,
|
HYUNDAI.HYUNDAI_ELANTRA_HEV_2022_NON_SCC,
|
||||||
HYUNDAI.HYUNDAI_KONA_EV_NON_SCC,
|
HYUNDAI.HYUNDAI_KONA_EV_NON_SCC,
|
||||||
|
HYUNDAI.HYUNDAI_KONA_EV_2023_NON_SCC,
|
||||||
HYUNDAI.HYUNDAI_KONA_NON_SCC,
|
HYUNDAI.HYUNDAI_KONA_NON_SCC,
|
||||||
HYUNDAI.HYUNDAI_IONIQ_5_N,
|
HYUNDAI.HYUNDAI_IONIQ_5_N,
|
||||||
# Frozen exemptions only: these three angle hybrids have no validated route.
|
# Frozen exemptions only: these three angle hybrids have no validated route.
|
||||||
@@ -485,6 +487,8 @@ routes = [
|
|||||||
|
|
||||||
CarTestRoute("5d61e2f6e1f247f3/00000054--d3dfb01b34", MG.MG_5_EV),
|
CarTestRoute("5d61e2f6e1f247f3/00000054--d3dfb01b34", MG.MG_5_EV),
|
||||||
|
|
||||||
|
CarTestRoute("8ae32b57e2f9d13c/0000025f--a58bd2c2f5", LEAPMOTOR.LEAPMOTOR_B10),
|
||||||
|
|
||||||
# Segments that test specific issues
|
# Segments that test specific issues
|
||||||
# Controls mismatch due to standstill threshold
|
# Controls mismatch due to standstill threshold
|
||||||
CarTestRoute("bec2dcfde6a64235/2022-04-08--14-21-32", HONDA.HONDA_CRV_HYBRID, segment=22),
|
CarTestRoute("bec2dcfde6a64235/2022-04-08--14-21-32", HONDA.HONDA_CRV_HYBRID, segment=22),
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ class TestFwFingerprintTiming(unittest.TestCase):
|
|||||||
assert first.whitelist_ecus == second.whitelist_ecus
|
assert first.whitelist_ecus == second.whitelist_ecus
|
||||||
|
|
||||||
def test_fw_query_timing(self):
|
def test_fw_query_timing(self):
|
||||||
total_ref_time = 8.5
|
total_ref_time = 8.6
|
||||||
brand_ref_times = {
|
brand_ref_times = {
|
||||||
'gm': 1.0,
|
'gm': 1.0,
|
||||||
'body': 0.1,
|
'body': 0.1,
|
||||||
@@ -355,6 +355,7 @@ class TestFwFingerprintTiming(unittest.TestCase):
|
|||||||
'rivian': 0.3,
|
'rivian': 0.3,
|
||||||
'psa': 0.1,
|
'psa': 0.1,
|
||||||
'mg': 0.1,
|
'mg': 0.1,
|
||||||
|
'leapmotor': 0.1,
|
||||||
'volvo': 0.1,
|
'volvo': 0.1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
|
|||||||
# BYD angle based controllers
|
# BYD angle based controllers
|
||||||
"BYD_ATTO_3" = [nan, 2.0, nan]
|
"BYD_ATTO_3" = [nan, 2.0, nan]
|
||||||
|
|
||||||
|
# Leapmotor angle based controllers
|
||||||
|
"LEAPMOTOR_B10" = [nan, 2.0, nan]
|
||||||
|
|
||||||
# New subarus angle based controllers
|
# New subarus angle based controllers
|
||||||
"SUBARU_FORESTER_2022" = [nan, 3.0, nan]
|
"SUBARU_FORESTER_2022" = [nan, 3.0, nan]
|
||||||
"SUBARU_OUTBACK_2023" = [nan, 3.0, nan]
|
"SUBARU_OUTBACK_2023" = [nan, 3.0, nan]
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
|
|||||||
"HYUNDAI_ELANTRA" = "HYUNDAI_SONATA_LF"
|
"HYUNDAI_ELANTRA" = "HYUNDAI_SONATA_LF"
|
||||||
"HYUNDAI_ELANTRA_GT_I30" = "HYUNDAI_SONATA_LF"
|
"HYUNDAI_ELANTRA_GT_I30" = "HYUNDAI_SONATA_LF"
|
||||||
"HYUNDAI_ELANTRA_2024" = "HYUNDAI_ELANTRA_2021"
|
"HYUNDAI_ELANTRA_2024" = "HYUNDAI_ELANTRA_2021"
|
||||||
|
"HYUNDAI_I30_2026" = "HYUNDAI_SONATA_LF"
|
||||||
"HYUNDAI_ELANTRA_HEV_2021" = "HYUNDAI_SONATA"
|
"HYUNDAI_ELANTRA_HEV_2021" = "HYUNDAI_SONATA"
|
||||||
"HYUNDAI_ELANTRA_HEV_2024" = "HYUNDAI_SONATA"
|
"HYUNDAI_ELANTRA_HEV_2024" = "HYUNDAI_SONATA"
|
||||||
"HYUNDAI_TUCSON" = "HYUNDAI_SANTA_FE"
|
"HYUNDAI_TUCSON" = "HYUNDAI_SANTA_FE"
|
||||||
@@ -53,6 +54,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"]
|
|||||||
"HYUNDAI_ELANTRA_2022_NON_SCC" = "HYUNDAI_ELANTRA_2021"
|
"HYUNDAI_ELANTRA_2022_NON_SCC" = "HYUNDAI_ELANTRA_2021"
|
||||||
"HYUNDAI_ELANTRA_HEV_2022_NON_SCC" = "HYUNDAI_SONATA"
|
"HYUNDAI_ELANTRA_HEV_2022_NON_SCC" = "HYUNDAI_SONATA"
|
||||||
"HYUNDAI_KONA_EV_NON_SCC" = "HYUNDAI_KONA_EV"
|
"HYUNDAI_KONA_EV_NON_SCC" = "HYUNDAI_KONA_EV"
|
||||||
|
"HYUNDAI_KONA_EV_2023_NON_SCC" = "HYUNDAI_KONA_EV"
|
||||||
"HYUNDAI_KONA_NON_SCC" = "HYUNDAI_KONA_EV"
|
"HYUNDAI_KONA_NON_SCC" = "HYUNDAI_KONA_EV"
|
||||||
"KIA_CEED_PHEV_2022_NON_SCC" = "HYUNDAI_SONATA"
|
"KIA_CEED_PHEV_2022_NON_SCC" = "HYUNDAI_SONATA"
|
||||||
"KIA_FORTE_2019_NON_SCC" = "HYUNDAI_SONATA"
|
"KIA_FORTE_2019_NON_SCC" = "HYUNDAI_SONATA"
|
||||||
|
|||||||
@@ -14,11 +14,10 @@ def configured(cp):
|
|||||||
required |= ToyotaFlags.RADAR_CAN_FILTER
|
required |= ToyotaFlags.RADAR_CAN_FILTER
|
||||||
elif cp.openpilotLongitudinalControl:
|
elif cp.openpilotLongitudinalControl:
|
||||||
required |= ToyotaFlags.DISABLE_RADAR
|
required |= ToyotaFlags.DISABLE_RADAR
|
||||||
allowed = required | ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM | ToyotaFlags.ARS510_RADAR | ToyotaFlags.ARS510_FUSED
|
allowed = required | ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM | ToyotaFlags.ARS510_RADAR
|
||||||
expected = 0x449 | (0x1000 if filtered else 0) | (0 if cp.openpilotLongitudinalControl else 0x200)
|
expected = 0x449 | (0x1000 if filtered else 0) | (0 if cp.openpilotLongitudinalControl else 0x200)
|
||||||
config = cp.safetyConfigs[0]
|
config = cp.safetyConfigs[0]
|
||||||
return bool(cp.flags & required == required and not int(cp.flags) & ~int(allowed) and
|
return bool(cp.flags & required == required and not int(cp.flags) & ~int(allowed) and
|
||||||
(not cp.flags & ToyotaFlags.ARS510_FUSED or cp.flags & ToyotaFlags.ARS510_RADAR) and
|
|
||||||
config.safetyModel == structs.CarParams.SafetyModel.toyota and config.safetyParam == expected)
|
config.safetyModel == structs.CarParams.SafetyModel.toyota and config.safetyParam == expected)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,9 @@ def supported(cp):
|
|||||||
def configure_radar(cp):
|
def configure_radar(cp):
|
||||||
if not supported(cp):
|
if not supported(cp):
|
||||||
return False
|
return False
|
||||||
cp.flags &= ~int(ToyotaFlags.ARS510_RADAR | ToyotaFlags.ARS510_FUSED)
|
cp.flags &= ~int(ToyotaFlags.ARS510_RADAR)
|
||||||
if cp.flags & ToyotaFlags.DISABLE_RADAR:
|
# Alpha long's UDS disable (DISABLE_RADAR) only stops the radar's car-bus (bus 0) output;
|
||||||
cp.radarUnavailable = True
|
# the ACC target on the radar bus (bus 1) keeps running at full rate, so it stays the lead source.
|
||||||
return False
|
|
||||||
cp.flags |= int(ToyotaFlags.ARS510_RADAR)
|
cp.flags |= int(ToyotaFlags.ARS510_RADAR)
|
||||||
cp.radarUnavailable = False
|
cp.radarUnavailable = False
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -1,246 +0,0 @@
|
|||||||
"""Toyota / Continental ARS510 front radar (RAV4 2022+, fwdRadar 8821F0R03100): object list to RadarData.
|
|
||||||
|
|
||||||
The radar sends its object list on bus 1 as one 742-byte record split over 106 frames on 0x80 (consecutive-frame
|
|
||||||
numbers wrap every 16 frames, so it is reassembled here instead of read through a DBC). Each of its 20 slots holds one
|
|
||||||
object; the radar keeps an object in its slot while the slot's age counts up, which gives the track IDs.
|
|
||||||
|
|
||||||
The slot speed has slow, correlated errors at range (false closings of 1-10 s beyond ~40 m). Their size follows the
|
|
||||||
radar's 240|7 code. One Kalman filter per track fuses the slot speed, weighted by that code, with the radar's own ACC target
|
|
||||||
(0x235 / 0x237) for the track it describes. radard then filters as for any radar. radard's lead match weights
|
|
||||||
lateral position only through the camera's uncertainty, so beyond 15 m a track a lane away from the yaw-predicted path
|
|
||||||
is withheld.
|
|
||||||
Adapted from ds-sebastian/ars510-radar at fb5b29c2b5999f34afeb6f7ac494a73949d66c67.
|
|
||||||
Copyright (c) 2026 ARS510 radar contributors. MIT license; see THIRD_PARTY_NOTICES.md.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import zlib
|
|
||||||
from math import isfinite, nan, pi
|
|
||||||
|
|
||||||
from opendbc.car import structs
|
|
||||||
from opendbc.car.interfaces import RadarInterfaceBase
|
|
||||||
|
|
||||||
RADAR_BUS, CAR_BUS = 1, 0
|
|
||||||
SPEED_ADDR, YAW_ADDR, OBJECTS_ADDR, ACC_SPEED_ADDR, ACC_POS_ADDR = 0xB4, 0x24, 0x80, 0x235, 0x237
|
|
||||||
RECORD_FRAMES, RECORD_LEN, SLOT_START, SLOT_LEN, SLOTS = 106, 742, 17, 36, 20
|
|
||||||
IDLE_SLOT = bytes.fromhex("FCE00000A0F07F00FFFDF71FFFA100F807000F0008000000000000000000000000000000")
|
|
||||||
|
|
||||||
EGO_MAX_AGE_S = 0.5
|
|
||||||
PUBLISH_AGE = 60 # ~3.6 s: young tracks have unconverged range and speed
|
|
||||||
RANGE_GAIN = 0.1 # velocity-aided range: cuts 1.5 s range walks by about a third
|
|
||||||
# Kalman speed filter (one state: the lead's over-ground speed)
|
|
||||||
SIGMA_PER_CODE = 0.045 # m/s per 240|7 count, against the radar's ACC target
|
|
||||||
YOUNG_SCALE, YOUNG_AGE = 1.8, 100 # young tracks err more than 240|7 says
|
|
||||||
ACC_SIGMA = 0.13 # m/s, the radar's ACC target speed (its measured noise; blended with the object list, which damps the ACC target's rare slides)
|
|
||||||
LEAD_ACCEL = 1.5 # m/s^2, process noise
|
|
||||||
GATE_SIGMA = 3.0 # innovations beyond 3 sigma count as 3 sigma
|
|
||||||
PUBLISH_STD = 0.75 # m/s: a new track is published once its speed is this certain
|
|
||||||
PATH_GATE, PATH_GATE_MIN_RANGE = 2.5, 15.0 # m: off the yaw-predicted path by more than this = another lane; closer in, cut-ins stay
|
|
||||||
FAR_ACC_ONLY = 60.0 # m: beyond this only the car the radar's ACC follows is published, as Toyota's own ACC uses it
|
|
||||||
STILL, STILL_GATE = 0.5, 1.5 # m/s, m: a stationary track (parked car, roadside object) is path-gated at every range, so it stays out of the lane
|
|
||||||
|
|
||||||
|
|
||||||
def bits(b: bytes, start: int, length: int) -> int:
|
|
||||||
return (int.from_bytes(b, "little") >> start) & ((1 << length) - 1)
|
|
||||||
|
|
||||||
|
|
||||||
def be_bits(b: bytes, start: int, length: int) -> int:
|
|
||||||
return (int.from_bytes(b, "big") >> start) & ((1 << length) - 1)
|
|
||||||
|
|
||||||
|
|
||||||
class Ars510Radar:
|
|
||||||
"""Raw CAN frames in, points (trackId, dRel, yRel, vRel) out once per 0x80 record."""
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.chunks, self.record_t, self.last_frame_t = [], 0.0, None
|
|
||||||
self.v_ego = self.yaw = None # (time, m/s), (time, rad/s left positive)
|
|
||||||
self.slots = {} # slot -> (radar track id, age, time)
|
|
||||||
self.next_tid = 1
|
|
||||||
self.acc_speed = self.acc_pos = self.acc_assoc = None
|
|
||||||
self.kf = {} # tid -> (time, speed, variance)
|
|
||||||
self.rng = {} # tid -> (time, dRel, vRel)
|
|
||||||
self.published = set()
|
|
||||||
|
|
||||||
def update(self, t: float, bus: int, addr: int, dat: bytes):
|
|
||||||
if bus == CAR_BUS and addr == SPEED_ADDR and len(dat) >= 7:
|
|
||||||
self.v_ego = (t, int.from_bytes(dat[5:7], "big") * 0.01 / 3.6)
|
|
||||||
elif bus == CAR_BUS and addr == YAW_ADDR and len(dat) >= 2:
|
|
||||||
self.yaw = (t, (((dat[0] & 0x03) << 8 | dat[1]) * 0.244 - 125.0) * pi / 180.0)
|
|
||||||
elif bus == RADAR_BUS and addr in (ACC_SPEED_ADDR, ACC_POS_ADDR):
|
|
||||||
if len(dat) != 8 or (not dat[1] & 4 if addr == ACC_SPEED_ADDR else dat[2:] == bytes.fromhex("003E80000000")):
|
|
||||||
self.acc_speed = self.acc_pos = None # idle
|
|
||||||
elif addr == ACC_SPEED_ADDR:
|
|
||||||
self.acc_speed = (t, (be_bits(dat, 29, 11) - 1024) * 0.125)
|
|
||||||
else:
|
|
||||||
self.acc_pos = (t, be_bits(dat, 39, 13) * 0.025, (be_bits(dat, 27, 12) - 2000) * 0.01)
|
|
||||||
elif bus == RADAR_BUS and addr == OBJECTS_ADDR:
|
|
||||||
record = self.reassemble(t, dat)
|
|
||||||
if record is not None and int.from_bytes(record[737:741], "little") == zlib.crc32(record[1:737]):
|
|
||||||
return self.points(self.record_t, record)
|
|
||||||
return None
|
|
||||||
|
|
||||||
def reassemble(self, t, dat):
|
|
||||||
"""The 106 frames of one record joined (bytes 1-7 of each); restarts on a first frame (0x12 0xE4)."""
|
|
||||||
if len(dat) != 8 or (self.chunks and t < self.last_frame_t):
|
|
||||||
self.chunks = []
|
|
||||||
if len(dat) != 8:
|
|
||||||
return None
|
|
||||||
if dat[0] == 0x12 and dat[1] == 0xE4:
|
|
||||||
self.chunks, self.record_t = [bytes(dat[1:8])], t
|
|
||||||
elif self.chunks:
|
|
||||||
self.chunks.append(bytes(dat[1:8]))
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
self.last_frame_t = t
|
|
||||||
if len(self.chunks) != RECORD_FRAMES:
|
|
||||||
return None
|
|
||||||
record, self.chunks = b"".join(self.chunks), []
|
|
||||||
return record if len(record) == RECORD_LEN else None
|
|
||||||
|
|
||||||
def track_id(self, t, slot, age):
|
|
||||||
prev = self.slots.get(slot)
|
|
||||||
if prev is not None and t == prev[2]:
|
|
||||||
return prev[0]
|
|
||||||
if prev is None or t - prev[2] > 0.3 or not (age > prev[1] or age == prev[1] == 126):
|
|
||||||
prev = (self.next_tid, age, t)
|
|
||||||
self.next_tid += 1
|
|
||||||
self.slots[slot] = (prev[0], age, t)
|
|
||||||
return prev[0]
|
|
||||||
|
|
||||||
def points(self, t, record):
|
|
||||||
v_ego = self.v_ego[1] if self.v_ego is not None and abs(t - self.v_ego[0]) <= EGO_MAX_AGE_S else None
|
|
||||||
objs = []
|
|
||||||
for slot in range(SLOTS):
|
|
||||||
s = record[SLOT_START + SLOT_LEN * slot : SLOT_START + SLOT_LEN * (slot + 1)]
|
|
||||||
if s == IDLE_SLOT:
|
|
||||||
continue
|
|
||||||
age, lat = bits(s, 24, 7), bits(s, 44, 12) - 2048
|
|
||||||
init_template = age == 1 and bits(s, 56, 7) == 0 and bits(s, 216, 6) == 0
|
|
||||||
# over-ground speed: 0.149 m/s per code against 0xB4 ego speed (DBC factor 0.15)
|
|
||||||
objs.append(
|
|
||||||
dict(
|
|
||||||
tid=self.track_id(t, slot, age),
|
|
||||||
age=age,
|
|
||||||
d=(bits(s, 32, 12) - 160) / 16,
|
|
||||||
y=lat * 0.015,
|
|
||||||
vg=(bits(s, 64, 10) - 510.5) * 0.149,
|
|
||||||
unc=bits(s, 240, 7),
|
|
||||||
valid=age >= 1 and not init_template and abs(lat) < 2000,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
tracks = {o["tid"]: o for o in objs if o["valid"]}
|
|
||||||
acc_tid = self.acc_match(t, tracks)
|
|
||||||
yaw = self.yaw[1] if self.yaw is not None and abs(t - self.yaw[0]) <= EGO_MAX_AGE_S else None
|
|
||||||
out = []
|
|
||||||
for o in objs:
|
|
||||||
if not o["valid"]:
|
|
||||||
continue
|
|
||||||
tid, vrel, std = o["tid"], nan, 0.0
|
|
||||||
if v_ego is not None:
|
|
||||||
readings = [(self.acc_speed[1] + v_ego, ACC_SIGMA)] if tid == acc_tid else []
|
|
||||||
speed, std = self.speed_filter(tid, t, o, readings)
|
|
||||||
vrel = speed - v_ego
|
|
||||||
d_rel = self.fused_range(tid, t, self.acc_pos[1] if tid == acc_tid else o["d"], vrel) # ACC distance for its track
|
|
||||||
if o["age"] < PUBLISH_AGE or (tid not in self.published and std > PUBLISH_STD) or not isfinite(vrel):
|
|
||||||
continue # a point needs a fresh ego speed: one NaN would poison radard's filter
|
|
||||||
still = abs(speed) < STILL and d_rel <= PATH_GATE_MIN_RANGE
|
|
||||||
if tid != acc_tid and (
|
|
||||||
d_rel > FAR_ACC_ONLY
|
|
||||||
or (
|
|
||||||
yaw is not None
|
|
||||||
and (d_rel > PATH_GATE_MIN_RANGE or still)
|
|
||||||
and abs(o["y"] - yaw / max(v_ego, 2.0 if still else 5.0) * d_rel * d_rel / 2) > (STILL_GATE if still else PATH_GATE)
|
|
||||||
)
|
|
||||||
):
|
|
||||||
continue # far: only the car the radar's ACC follows is published (the camera covers the rest); closer in: an object off the path is another lane's
|
|
||||||
self.published.add(tid)
|
|
||||||
out.append((tid, d_rel, o["y"], vrel))
|
|
||||||
self.prune(t)
|
|
||||||
return out
|
|
||||||
|
|
||||||
def speed_filter(self, tid, t, o, readings):
|
|
||||||
"""One-state Kalman filter on the over-ground speed; every reading weighted by its own sigma."""
|
|
||||||
sig = SIGMA_PER_CODE * max(o["unc"], 1)
|
|
||||||
if o["age"] < YOUNG_AGE:
|
|
||||||
sig *= 1.0 + (YOUNG_SCALE - 1.0) * min(max((YOUNG_AGE - o["age"]) / (YOUNG_AGE - PUBLISH_AGE), 0.0), 1.0)
|
|
||||||
prev = self.kf.get(tid)
|
|
||||||
if prev is None or not 0.0 < t - prev[0] <= 0.5:
|
|
||||||
self.kf[tid] = (t, o["vg"], sig * sig)
|
|
||||||
return o["vg"], sig
|
|
||||||
_, v, p = prev
|
|
||||||
p += (LEAD_ACCEL * (t - prev[0])) ** 2
|
|
||||||
for z, r in [(o["vg"], sig)] + readings:
|
|
||||||
s = p + r * r
|
|
||||||
innov = max(min(z - v, GATE_SIGMA * s**0.5), -GATE_SIGMA * s**0.5)
|
|
||||||
v, p = v + p / s * innov, p * (1.0 - p / s)
|
|
||||||
self.kf[tid] = (t, v, p)
|
|
||||||
return v, p**0.5
|
|
||||||
|
|
||||||
def fused_range(self, tid, t, d, vrel):
|
|
||||||
prev = self.rng.get(tid)
|
|
||||||
if prev is not None and isfinite(vrel) and isfinite(prev[2]) and 0.0 < t - prev[0] <= 0.5:
|
|
||||||
pred = prev[1] + 0.5 * (prev[2] + vrel) * (t - prev[0])
|
|
||||||
d = pred + RANGE_GAIN * (d - pred)
|
|
||||||
self.rng[tid] = (t, d, vrel)
|
|
||||||
return d
|
|
||||||
|
|
||||||
def acc_match(self, t, tracks):
|
|
||||||
"""The track the radar's ACC target describes: matched by position, kept while both persist."""
|
|
||||||
if self.acc_speed is None or self.acc_pos is None or max(abs(t - self.acc_speed[0]), abs(t - self.acc_pos[0])) > 0.1:
|
|
||||||
self.acc_assoc = None
|
|
||||||
return None
|
|
||||||
_, ax, ay = self.acc_pos
|
|
||||||
rs = max(12.0, 0.4 * ax) # the object list reads far cars short of the ACC distance; 10-20 % of new tracks by more than 10 m
|
|
||||||
costs = sorted((abs(o["d"] - ax) / rs + abs(o["y"] - ay) / 0.5, tid, o["age"]) for tid, o in tracks.items())
|
|
||||||
if self.acc_assoc is not None:
|
|
||||||
tid0, ax0, ay0 = self.acc_assoc
|
|
||||||
own = next((c for c, tid, _ in costs if tid == tid0), None)
|
|
||||||
if own is not None and own < 4.0 and abs(ax - ax0) <= 8.0 and abs(ay - ay0) <= 1.0:
|
|
||||||
self.acc_assoc = (tid0, ax, ay)
|
|
||||||
return tid0
|
|
||||||
self.acc_assoc = None
|
|
||||||
if not costs or costs[0][0] >= 1.0 or costs[0][2] < 20 or (len(costs) > 1 and costs[1][0] - costs[0][0] <= 1.0):
|
|
||||||
return None
|
|
||||||
self.acc_assoc = (costs[0][1], ax, ay)
|
|
||||||
return costs[0][1]
|
|
||||||
|
|
||||||
def prune(self, t):
|
|
||||||
for store in (self.kf, self.rng):
|
|
||||||
if len(store) > 400:
|
|
||||||
for k in [k for k, v in store.items() if v[0] < t - 5.0]:
|
|
||||||
store.pop(k)
|
|
||||||
if len(self.published) > 400:
|
|
||||||
# A live allocation can outlast its recent speed-filter entry after invalid geometry.
|
|
||||||
self.published &= set(self.kf) | {state[0] for state in self.slots.values()}
|
|
||||||
|
|
||||||
|
|
||||||
class RadarInterface(RadarInterfaceBase):
|
|
||||||
def __init__(self, CP):
|
|
||||||
super().__init__(CP)
|
|
||||||
self.radar = Ars510Radar()
|
|
||||||
self.last_record_t = None
|
|
||||||
|
|
||||||
def update(self, can_packets):
|
|
||||||
self.frame += 1
|
|
||||||
points, t = None, None
|
|
||||||
for nanos, frames in can_packets:
|
|
||||||
t = nanos * 1e-9
|
|
||||||
for address, dat, src in frames:
|
|
||||||
out = self.radar.update(t, src, address, dat)
|
|
||||||
if out is not None:
|
|
||||||
points, self.last_record_t = out, t
|
|
||||||
if points is None: # between scans: report only at 20 Hz, and only before the first scan or once the radar is stale
|
|
||||||
if t is None or self.frame % 5 != 0 or (self.last_record_t is not None and t - self.last_record_t <= 0.5):
|
|
||||||
return None
|
|
||||||
ret = structs.RadarData()
|
|
||||||
ret.errors.radarUnavailableTemporary = self.last_record_t is not None
|
|
||||||
return ret
|
|
||||||
ret = structs.RadarData()
|
|
||||||
pts = []
|
|
||||||
for track_id, d_rel, y_rel, v_rel in points:
|
|
||||||
pt = structs.RadarData.RadarPoint()
|
|
||||||
pt.trackId, pt.dRel, pt.yRel, pt.vRel = track_id, d_rel, y_rel, v_rel
|
|
||||||
pt.deprecated.aRel = pt.deprecated.yvRel = nan
|
|
||||||
pt.deprecated.measured = True
|
|
||||||
pts.append(pt)
|
|
||||||
ret.points = pts
|
|
||||||
return ret
|
|
||||||
@@ -90,12 +90,11 @@ def configured(cp):
|
|||||||
required |= int(ToyotaFlags.RAISED_ACCEL_LIMIT)
|
required |= int(ToyotaFlags.RAISED_ACCEL_LIMIT)
|
||||||
allowed = required | int(ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM)
|
allowed = required | int(ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM)
|
||||||
if cp.carFingerprint in (CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023):
|
if cp.carFingerprint in (CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023):
|
||||||
allowed |= int(ToyotaFlags.ARS510_RADAR | ToyotaFlags.ARS510_FUSED)
|
allowed |= int(ToyotaFlags.ARS510_RADAR)
|
||||||
expected_type = structs.CarParams.SteerControlType.angle if cp.carFingerprint == CAR.TOYOTA_RAV4_TSS2_2023 else structs.CarParams.SteerControlType.torque
|
expected_type = structs.CarParams.SteerControlType.angle if cp.carFingerprint == CAR.TOYOTA_RAV4_TSS2_2023 else structs.CarParams.SteerControlType.torque
|
||||||
return bool(
|
return bool(
|
||||||
cp.flags & required == required
|
cp.flags & required == required
|
||||||
and not int(cp.flags) & ~allowed
|
and not int(cp.flags) & ~allowed
|
||||||
and (not cp.flags & ToyotaFlags.ARS510_FUSED or cp.flags & ToyotaFlags.ARS510_RADAR)
|
|
||||||
and cp.steerControlType == expected_type
|
and cp.steerControlType == expected_type
|
||||||
and cp.safetyConfigs[0].safetyModel == structs.CarParams.SafetyModel.toyota
|
and cp.safetyConfigs[0].safetyModel == structs.CarParams.SafetyModel.toyota
|
||||||
and cp.safetyConfigs[0].safetyParam == words(cp.carFingerprint)[not cp.openpilotLongitudinalControl]
|
and cp.safetyConfigs[0].safetyParam == words(cp.carFingerprint)[not cp.openpilotLongitudinalControl]
|
||||||
|
|||||||
@@ -85,9 +85,7 @@ def configured(cp):
|
|||||||
required |= ToyotaFlags.ANGLE_CONTROL
|
required |= ToyotaFlags.ANGLE_CONTROL
|
||||||
allowed |= ToyotaFlags.ANGLE_CONTROL
|
allowed |= ToyotaFlags.ANGLE_CONTROL
|
||||||
if cp.carFingerprint in (CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023):
|
if cp.carFingerprint in (CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023):
|
||||||
allowed |= ToyotaFlags.ARS510_RADAR | ToyotaFlags.ARS510_FUSED
|
allowed |= ToyotaFlags.ARS510_RADAR
|
||||||
if cp.flags & ToyotaFlags.ARS510_FUSED and not cp.flags & ToyotaFlags.ARS510_RADAR:
|
|
||||||
return False
|
|
||||||
expected_steer = structs.CarParams.SteerControlType.angle if angle else structs.CarParams.SteerControlType.torque
|
expected_steer = structs.CarParams.SteerControlType.angle if angle else structs.CarParams.SteerControlType.torque
|
||||||
if cp.steerControlType != expected_steer:
|
if cp.steerControlType != expected_steer:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from opendbc.car import Bus
|
|||||||
from opendbc.car.structs import RadarData
|
from opendbc.car.structs import RadarData
|
||||||
from opendbc.car.toyota.values import CAR, DBC, ToyotaFlags, ARS510_RADAR_CAR
|
from opendbc.car.toyota.values import CAR, DBC, ToyotaFlags, ARS510_RADAR_CAR
|
||||||
from opendbc.car.toyota.ars510_acc_target import RadarInterface as Ars510AccRadarInterface
|
from opendbc.car.toyota.ars510_acc_target import RadarInterface as Ars510AccRadarInterface
|
||||||
from opendbc.car.toyota.ars510_radar import RadarInterface as Ars510FusedRadarInterface
|
|
||||||
from opendbc.car.interfaces import RadarInterfaceBase
|
from opendbc.car.interfaces import RadarInterfaceBase
|
||||||
|
|
||||||
|
|
||||||
@@ -36,8 +35,7 @@ class RadarInterface(RadarInterfaceBase):
|
|||||||
return
|
return
|
||||||
self.ars510 = None
|
self.ars510 = None
|
||||||
if CP.carFingerprint in ARS510_RADAR_CAR and CP.flags & ToyotaFlags.ARS510_RADAR and not CP.radarUnavailable:
|
if CP.carFingerprint in ARS510_RADAR_CAR and CP.flags & ToyotaFlags.ARS510_RADAR and not CP.radarUnavailable:
|
||||||
parser = Ars510FusedRadarInterface if CP.flags & ToyotaFlags.ARS510_FUSED else Ars510AccRadarInterface
|
self.ars510 = Ars510AccRadarInterface(CP)
|
||||||
self.ars510 = parser(CP)
|
|
||||||
self.rcp = None
|
self.rcp = None
|
||||||
return
|
return
|
||||||
if CP.flags & ToyotaFlags.TSS2:
|
if CP.flags & ToyotaFlags.TSS2:
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
from math import isfinite, isnan
|
from math import isfinite, isnan
|
||||||
import zlib
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from opendbc.can import CANPacker
|
from opendbc.can import CANPacker
|
||||||
from opendbc.car import gen_empty_fingerprint, structs
|
from opendbc.car import gen_empty_fingerprint, structs
|
||||||
from opendbc.car.toyota.ars510_acc_target import RadarInterface as AccRadarInterface, RADAR_DBC
|
from opendbc.car.toyota.ars510_acc_target import RadarInterface as AccRadarInterface, RADAR_DBC
|
||||||
from opendbc.car.toyota.ars510_radar import Ars510Radar, IDLE_SLOT, RadarInterface as FusedRadarInterface
|
|
||||||
from opendbc.car.toyota.interface import CarInterface
|
from opendbc.car.toyota.interface import CarInterface
|
||||||
from opendbc.car.toyota.radar_interface import RadarInterface
|
from opendbc.car.toyota.radar_interface import RadarInterface
|
||||||
from opendbc.car.toyota.values import ARS510_RADAR_CAR, CAR, ToyotaFlags
|
from opendbc.car.toyota.values import ARS510_RADAR_CAR, CAR, ToyotaFlags
|
||||||
@@ -19,137 +17,13 @@ def test_factory_selects_only_live_supported_continental_radar(candidate, alpha_
|
|||||||
if can_filter:
|
if can_filter:
|
||||||
fingerprint[0][0x2AA] = 8
|
fingerprint[0][0x2AA] = 8
|
||||||
cp = CarInterface.get_params(candidate, fingerprint, [], alpha_long, False, False)
|
cp = CarInterface.get_params(candidate, fingerprint, [], alpha_long, False, False)
|
||||||
if candidate in ARS510_RADAR_CAR and not cp.flags & ToyotaFlags.DISABLE_RADAR:
|
if candidate in ARS510_RADAR_CAR:
|
||||||
|
# with or without alpha long's radar disable: the disable leaves the radar bus running
|
||||||
assert cp.flags & ToyotaFlags.ARS510_RADAR, 'AUTOMATIC_CONTINENTAL_RADAR'
|
assert cp.flags & ToyotaFlags.ARS510_RADAR, 'AUTOMATIC_CONTINENTAL_RADAR'
|
||||||
assert not cp.flags & ToyotaFlags.ARS510_FUSED and not cp.radarUnavailable
|
assert not cp.radarUnavailable
|
||||||
assert isinstance(RadarInterface(cp).ars510, AccRadarInterface)
|
assert isinstance(RadarInterface(cp).ars510, AccRadarInterface)
|
||||||
else:
|
else:
|
||||||
assert not cp.flags & (ToyotaFlags.ARS510_RADAR | ToyotaFlags.ARS510_FUSED)
|
assert not cp.flags & ToyotaFlags.ARS510_RADAR
|
||||||
if candidate in ARS510_RADAR_CAR:
|
|
||||||
assert cp.radarUnavailable and RadarInterface(cp).ars510 is None
|
|
||||||
|
|
||||||
|
|
||||||
def set_bits(data, start, length, value):
|
|
||||||
raw = int.from_bytes(data, "little")
|
|
||||||
mask = ((1 << length) - 1) << start
|
|
||||||
data[:] = ((raw & ~mask) | (value << start)).to_bytes(len(data), "little")
|
|
||||||
|
|
||||||
|
|
||||||
def object_record(age=60, distance=30, lateral=0, speed_code=645, uncertainty=1, count=1):
|
|
||||||
record = bytearray(742)
|
|
||||||
record[0] = 0xE4
|
|
||||||
for slot in range(20):
|
|
||||||
data = bytearray(IDLE_SLOT)
|
|
||||||
if slot < count:
|
|
||||||
set_bits(data, 24, 7, age)
|
|
||||||
set_bits(data, 32, 12, round(160 + 16 * distance))
|
|
||||||
set_bits(data, 44, 12, round(2048 + lateral / 0.015))
|
|
||||||
set_bits(data, 64, 10, speed_code)
|
|
||||||
set_bits(data, 240, 7, uncertainty)
|
|
||||||
record[17 + slot * 36 : 17 + (slot + 1) * 36] = data
|
|
||||||
record[737:741] = zlib.crc32(record[1:737]).to_bytes(4, "little")
|
|
||||||
return bytes(record)
|
|
||||||
|
|
||||||
|
|
||||||
def record_frames(record, bus=1):
|
|
||||||
return [(0x80, bytes([0x12 if i == 0 else 0x20 | i % 16]) + record[i * 7 : (i + 1) * 7], bus) for i in range(106)]
|
|
||||||
|
|
||||||
|
|
||||||
def ego_frames(speed=20, yaw_code=512):
|
|
||||||
speed_data = bytearray(8)
|
|
||||||
speed_data[5:7] = round(speed * 3.6 * 100).to_bytes(2, "big")
|
|
||||||
yaw_data = bytes([yaw_code >> 8, yaw_code & 0xFF]) + bytes(6)
|
|
||||||
return [(0xB4, bytes(speed_data), 0), (0x24, yaw_data, 0)]
|
|
||||||
|
|
||||||
|
|
||||||
def fused_radar():
|
|
||||||
return FusedRadarInterface(structs.CarParams(carFingerprint=CAR.TOYOTA_RAV4_TSS2_2023))
|
|
||||||
|
|
||||||
|
|
||||||
def test_fused_decodes_20_slots_and_preserves_left_positive_geometry():
|
|
||||||
radar = fused_radar()
|
|
||||||
ret = radar.update([(1_000_000_000, ego_frames() + record_frames(object_record(count=20, lateral=0.3)))])
|
|
||||||
assert len(ret.points) == 20
|
|
||||||
assert len({pt.trackId for pt in ret.points}) == 20
|
|
||||||
for pt in ret.points:
|
|
||||||
assert (pt.dRel, pt.yRel, pt.vRel) == pytest.approx((30, 0.3, (645 - 510.5) * 0.149 - 20))
|
|
||||||
assert pt.deprecated.measured
|
|
||||||
assert isnan(pt.deprecated.aRel) and isnan(pt.deprecated.yvRel)
|
|
||||||
assert not ret.errors.canError
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("bad_input", ["crc", "short", "truncated", "reordered", "wrong_bus"])
|
|
||||||
def test_fused_rejects_incomplete_corrupt_or_non_native_records(bad_input):
|
|
||||||
radar = fused_radar()
|
|
||||||
record = bytearray(object_record())
|
|
||||||
if bad_input == "crc":
|
|
||||||
record[25] ^= 1
|
|
||||||
frames = record_frames(record, bus=2 if bad_input == "wrong_bus" else 1)
|
|
||||||
if bad_input == "short":
|
|
||||||
frames[50] = (0x80, frames[50][1][:-1], 1)
|
|
||||||
elif bad_input == "truncated":
|
|
||||||
frames.pop(50)
|
|
||||||
elif bad_input == "reordered":
|
|
||||||
frames[30], frames[31] = frames[31], frames[30]
|
|
||||||
assert radar.update([(1_000_000_000, ego_frames() + frames)]) is None
|
|
||||||
assert radar.last_record_t is None
|
|
||||||
|
|
||||||
|
|
||||||
def test_fused_requires_fresh_ego_speed_and_converged_tracks():
|
|
||||||
radar = Ars510Radar()
|
|
||||||
assert radar.points(1.0, object_record()) == []
|
|
||||||
radar.v_ego = (1.0, 20)
|
|
||||||
assert radar.points(1.0, object_record(age=59)) == []
|
|
||||||
assert radar.points(1.1, object_record(age=60))
|
|
||||||
assert radar.points(1.6, object_record(age=61)) == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_fused_lifecycle_age_reset_allocates_a_new_track():
|
|
||||||
radar = Ars510Radar()
|
|
||||||
radar.v_ego = (1.0, 20)
|
|
||||||
first = radar.points(1.0, object_record(age=60))[0][0]
|
|
||||||
assert radar.points(1.06, object_record(age=61))[0][0] == first
|
|
||||||
radar.points(1.12, object_record(age=1))
|
|
||||||
radar.v_ego = (1.18, 20)
|
|
||||||
assert radar.points(1.18, object_record(age=60))[0][0] != first
|
|
||||||
saturated = radar.track_id(2.0, 0, 126)
|
|
||||||
assert radar.track_id(2.06, 0, 126) == saturated
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("kwargs", [{"uncertainty": 127}, {"distance": 61}, {"lateral": 3}])
|
|
||||||
def test_fused_gates_uncertain_far_and_out_of_path_objects(kwargs):
|
|
||||||
radar = Ars510Radar()
|
|
||||||
radar.v_ego = (1.0, 20)
|
|
||||||
radar.yaw = (1.0, 0)
|
|
||||||
assert radar.points(1.0, object_record(**kwargs)) == []
|
|
||||||
|
|
||||||
|
|
||||||
def test_fused_damps_a_high_uncertainty_speed_excursion():
|
|
||||||
radar = Ars510Radar()
|
|
||||||
radar.v_ego = (1.0, 20)
|
|
||||||
first = radar.points(1.0, object_record(age=126))[0]
|
|
||||||
raw_closing = (600 - 510.5) * 0.149 - 20
|
|
||||||
second = radar.points(1.06, object_record(age=126, speed_code=600, uncertainty=127))[0]
|
|
||||||
assert raw_closing < -6
|
|
||||||
assert second[0] == first[0]
|
|
||||||
assert abs(second[3] - first[3]) < 0.2
|
|
||||||
|
|
||||||
|
|
||||||
def test_fused_keeps_healthy_tracks_between_scans_then_reports_actual_silence(monkeypatch):
|
|
||||||
radar = fused_radar()
|
|
||||||
monkeypatch.setattr(radar.radar, "update", lambda t, *_: [(1, 30, 0, -1)] if round(t * 100) % 6 == 0 else None)
|
|
||||||
for i in range(1, 101):
|
|
||||||
ret = radar.update([(i * 10_000_000, [(0x80, bytes(8), 1)])])
|
|
||||||
if i % 6 == 0:
|
|
||||||
assert len(ret.points) == 1
|
|
||||||
elif i > 6:
|
|
||||||
assert ret is None
|
|
||||||
monkeypatch.setattr(radar.radar, "update", lambda *_: None)
|
|
||||||
outputs = [radar.update([(2_000_000_000 + i * 10_000_000, [])]) for i in range(10)]
|
|
||||||
assert any(r is not None and r.errors.radarUnavailableTemporary and not r.points for r in outputs)
|
|
||||||
monkeypatch.setattr(radar.radar, "update", lambda *_: [])
|
|
||||||
ret = radar.update([(2_200_000_000, [(0x80, bytes(8), 1)])])
|
|
||||||
assert not ret.points and not ret.errors.radarUnavailableTemporary
|
|
||||||
|
|
||||||
|
|
||||||
def acc_frames(packer, counter, cycle, present=True, distance=35, relative_speed=-2, target_id=3):
|
def acc_frames(packer, counter, cycle, present=True, distance=35, relative_speed=-2, target_id=3):
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ class ToyotaFlags(IntFlag):
|
|||||||
HAS_BSM = 2 # blind spot monitoring
|
HAS_BSM = 2 # blind spot monitoring
|
||||||
LONG_FILTER = 8192
|
LONG_FILTER = 8192
|
||||||
ARS510_RADAR = 16384
|
ARS510_RADAR = 16384
|
||||||
ARS510_FUSED = 32768
|
|
||||||
DISABLE_RADAR = 4
|
DISABLE_RADAR = 4
|
||||||
|
|
||||||
# Static flags
|
# Static flags
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from opendbc.car.hyundai.values import CAR as HYUNDAI
|
|||||||
from opendbc.car.mazda.values import CAR as MAZDA
|
from opendbc.car.mazda.values import CAR as MAZDA
|
||||||
from opendbc.car.mock.values import CAR as MOCK
|
from opendbc.car.mock.values import CAR as MOCK
|
||||||
from opendbc.car.nissan.values import CAR as NISSAN
|
from opendbc.car.nissan.values import CAR as NISSAN
|
||||||
|
from opendbc.car.leapmotor.values import CAR as LEAPMOTOR
|
||||||
from opendbc.car.psa.values import CAR as PSA
|
from opendbc.car.psa.values import CAR as PSA
|
||||||
from opendbc.car.rivian.values import CAR as RIVIAN
|
from opendbc.car.rivian.values import CAR as RIVIAN
|
||||||
from opendbc.car.mg.values import CAR as MG
|
from opendbc.car.mg.values import CAR as MG
|
||||||
@@ -18,7 +19,8 @@ from opendbc.car.toyota.values import CAR as TOYOTA
|
|||||||
from opendbc.car.volvo.values import CAR as VOLVO
|
from opendbc.car.volvo.values import CAR as VOLVO
|
||||||
from opendbc.car.volkswagen.values import CAR as VOLKSWAGEN
|
from opendbc.car.volkswagen.values import CAR as VOLKSWAGEN
|
||||||
|
|
||||||
Platform = BODY | BYD | CHRYSLER | FORD | GM | HONDA | HYUNDAI | MAZDA | MOCK | MG | NISSAN | PSA | RIVIAN | SUBARU | TESLA | TOYOTA | VOLVO | VOLKSWAGEN
|
Platform = (BODY | BYD | CHRYSLER | FORD | GM | HONDA | HYUNDAI | LEAPMOTOR | MAZDA | MOCK | MG | NISSAN | PSA | RIVIAN | SUBARU | TESLA |
|
||||||
|
TOYOTA | VOLVO | VOLKSWAGEN)
|
||||||
BRANDS = get_args(Platform)
|
BRANDS = get_args(Platform)
|
||||||
|
|
||||||
PLATFORMS: dict[str, Platform] = {str(platform): platform for brand in BRANDS for platform in brand}
|
PLATFORMS: dict[str, Platform] = {str(platform): platform for brand in BRANDS for platform in brand}
|
||||||
|
|||||||
@@ -0,0 +1,213 @@
|
|||||||
|
VERSION ""
|
||||||
|
|
||||||
|
NS_ :
|
||||||
|
|
||||||
|
BS_:
|
||||||
|
|
||||||
|
BU_: XXX
|
||||||
|
|
||||||
|
BO_ 388 WHEEL_SPEEDS: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ WHEEL_SPEED_FL : 16|16@1+ (0.01,0) [0|0] "km/h" XXX
|
||||||
|
SG_ WHEEL_SPEED_FR : 32|16@1+ (0.01,0) [0|0] "km/h" XXX
|
||||||
|
SG_ WHEEL_SPEED_RL : 48|16@1+ (0.01,0) [0|0] "km/h" XXX
|
||||||
|
SG_ WHEEL_SPEED_RR : 64|16@1+ (0.01,0) [0|0] "km/h" XXX
|
||||||
|
|
||||||
|
BO_ 563 IMU: 8 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ YAW_RATE : 41|13@1+ (0.02,-81.92) [0|0] "deg/s" XXX
|
||||||
|
|
||||||
|
BO_ 397 EPS_STEERING: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ STEER_ANGLE : 24|16@1+ (-0.02,649.8) [-661|650] "deg" XXX
|
||||||
|
SG_ STEER_SPEED_ABS : 40|8@1+ (4,0) [0|1020] "deg/s" XXX
|
||||||
|
SG_ DRIVER_OVERRIDE : 63|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ADAS_LKA_RECEIVED : 66|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ LCC_STEERING_ACTIVE : 67|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ADAS_LKA_TIMEOUT : 120|2@1+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ STEER_TORQUE_DRIVER : 80|8@1+ (-1,78) [0|0] "raw" XXX
|
||||||
|
SG_ STEER_TORQUE_EPS : 168|12@1+ (1,-1000) [0|0] "raw" XXX
|
||||||
|
SG_ EPS_STATUS_180 : 180|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 131 ADAS_LKA: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ ACC_STATE : 25|2@1+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ UNKNOWN_27 : 27|3@1+ (1,0) [0|7] "" XXX
|
||||||
|
SG_ UNKNOWN_30 : 30|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ UNKNOWN_31 : 31|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ACC_ACCEL_REQ : 32|8@1+ (0.05,-5) [-5|7.75] "m/s^2" XXX
|
||||||
|
SG_ ASSIST_OFF : 40|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ASSIST_OFF_2 : 44|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ACC_SET_SPEED : 46|11@1+ (0.2,0) [0|409.4] "km/h" XXX
|
||||||
|
SG_ UNKNOWN_60 : 60|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CONSTANT_72 : 72|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ UNKNOWN_81 : 81|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ UNKNOWN_88 : 88|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ UNKNOWN_90 : 90|5@1+ (1,0) [0|31] "" XXX
|
||||||
|
SG_ UNKNOWN_96 : 96|3@1+ (1,0) [0|7] "" XXX
|
||||||
|
SG_ LCC_STEERING_ACTIVE_COPY : 99|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ UNKNOWN_100 : 100|2@1+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ STEER_ANGLE_REQ : 104|16@1+ (-0.02,649.8) [-661|650] "deg" XXX
|
||||||
|
SG_ LCC_RAMP : 128|16@1+ (1,0) [0|65535] "" XXX
|
||||||
|
SG_ UNKNOWN_147 : 147|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ CONSTANT_152 : 152|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ UNKNOWN_176 : 176|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ACC_OVERRIDE : 179|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 389 VEHICLE_ACCEL: 16 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ LONG_ACCEL : 48|10@1+ (0.03125,-16) [-16|15.97] "m/s^2" XXX
|
||||||
|
SG_ SEATBELT_REMINDER : 83|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 656 BODY_CONTROL: 8 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ BLINKER_LEFT : 24|1@1+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ BLINKER_RIGHT : 25|1@1+ (1,0) [0|0] "" XXX
|
||||||
|
SG_ DRIVER_DOOR_OPEN : 44|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 183 POWERTRAIN_STATE: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ ASSIST_ENGAGED : 30|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ STALK_PUSH : 40|2@1+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ TORQUE_DEMAND : 56|8@1+ (1,0) [0|0] "raw" XXX
|
||||||
|
SG_ UNKNOWN_18 : 18|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ UNKNOWN_26 : 26|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ UNKNOWN_33 : 33|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ UNKNOWN_36 : 36|2@1+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ UNKNOWN_42 : 42|3@1+ (1,0) [0|7] "" XXX
|
||||||
|
SG_ UNKNOWN_50 : 50|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ UNKNOWN_55 : 55|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ UNKNOWN_64 : 64|11@1+ (1,0) [0|2047] "" XXX
|
||||||
|
SG_ UNKNOWN_80 : 80|11@1+ (1,0) [0|2047] "" XXX
|
||||||
|
SG_ UNKNOWN_95 : 95|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ UNKNOWN_97 : 97|10@1+ (1,0) [0|1023] "" XXX
|
||||||
|
SG_ UNKNOWN_112 : 112|11@1+ (1,0) [0|2047] "" XXX
|
||||||
|
SG_ UNKNOWN_128 : 128|7@1+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ UNKNOWN_136 : 136|11@1+ (1,0) [0|2047] "" XXX
|
||||||
|
SG_ UNKNOWN_151 : 151|2@1+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ UNKNOWN_154 : 154|14@1+ (1,0) [0|16383] "" XXX
|
||||||
|
SG_ UNKNOWN_169 : 169|12@1+ (1,0) [0|4095] "" XXX
|
||||||
|
|
||||||
|
BO_ 182 VEHICLE_STATE: 16 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ ACCEL_PEDAL : 88|8@1+ (0.4,0) [0|102] "%" XXX
|
||||||
|
SG_ BRAKE_PRESSED : 99|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ GEAR : 101|2@1+ (1,0) [0|3] "" XXX
|
||||||
|
|
||||||
|
BO_ 390 BRAKE_PRESSURE: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ BRAKE_PRESSURE : 16|8@1+ (1,0) [0|0] "raw" XXX
|
||||||
|
|
||||||
|
BO_ 322 ROAD_SIGNS: 16 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ FCW : 34|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SPEED_LIMIT : 72|8@1+ (1,0) [0|255] "km/h" XXX
|
||||||
|
|
||||||
|
BO_ 552 BSD_LEFT: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ OBJECT_DETECTED : 17|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 554 BSD_RIGHT: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ OBJECT_DETECTED : 17|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 675 SEATBELT: 16 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ DRIVER_SEATBELT_UNLATCHED : 31|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 589 CLUSTER: 32 XXX
|
||||||
|
SG_ CHECKSUM : 0|8@1+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 8|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
SG_ DISPLAY_SPEED : 80|8@1+ (1,0) [0|255] "km/h" XXX
|
||||||
|
SG_ ASSIST_ENGAGED_COPY : 131|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ LCC_ENGAGED : 132|1@1+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
CM_ "Leapmotor B10 (2025, global market), reverse engineered from comma rlogs. Checksums are AUTOSAR E2E Profile 2 with per-message constants (see CHECKSUM comments). Each signal comment says CONFIRMED (matched filmed actions or a dedicated test), INFERRED or WEAK.";
|
||||||
|
CM_ SG_ 388 WHEEL_SPEED_FL "CONFIRMED: positions from filmed figure-eights: front/rear rises from 1.02 straight to 1.27 near lock, and the left wheels run faster when steering right. Scale matches GPS within 0.1 km/h at a filmed steady 30 km/h. within about 1% of GPS above 60 km/h up to 126 km/h. Width at least 14 bits; no wrap in about 11 hours of logs.";
|
||||||
|
CM_ SG_ 388 WHEEL_SPEED_FR "CONFIRMED: positions from filmed figure-eights: front/rear rises from 1.02 straight to 1.27 near lock, and the left wheels run faster when steering right. Scale matches GPS within 0.1 km/h at a filmed steady 30 km/h. within about 1% of GPS above 60 km/h up to 126 km/h. Width at least 14 bits; no wrap in about 11 hours of logs.";
|
||||||
|
CM_ SG_ 388 WHEEL_SPEED_RL "CONFIRMED: positions from filmed figure-eights: front/rear rises from 1.02 straight to 1.27 near lock, and the left wheels run faster when steering right. Scale matches GPS within 0.1 km/h at a filmed steady 30 km/h. within about 1% of GPS above 60 km/h up to 126 km/h. Width at least 14 bits; no wrap in about 11 hours of logs.";
|
||||||
|
CM_ SG_ 388 WHEEL_SPEED_RR "CONFIRMED: positions from filmed figure-eights: front/rear rises from 1.02 straight to 1.27 near lock, and the left wheels run faster when steering right. Scale matches GPS within 0.1 km/h at a filmed steady 30 km/h. within about 1% of GPS above 60 km/h up to 126 km/h. Width at least 14 bits; no wrap in about 11 hours of logs.";
|
||||||
|
CM_ SG_ 563 YAW_RATE "INFERRED scale, sign CONFIRMED: positive = turning left (openpilot convention); raw rises when turning right, r +0.994 to +1.000 against the comma gyro (livePose.angularVelocityDevice.z, positive right) on 3 traces. R2 0.993-0.999 against livePose on 5 datasets. Fit gives 0.0196; 0.02 assumed.";
|
||||||
|
CM_ SG_ 389 LONG_ACCEL "INFERRED: R2 0.70-0.95 against livePose on 5 datasets. Same encoding as the Leapmotor T03 DBC (10 bits, offset -16), which matches the earlier 9-bit signed reading over the logged range. No wrap down to -6.8 m/s^2.";
|
||||||
|
CM_ SG_ 589 DISPLAY_SPEED "CONFIRMED: equal to the filmed dashboard speed in 6 of 6 checks (50, 70, 100 km/h). Reads about 3.5 percent above the wheel speeds, as dashboards do.";
|
||||||
|
CM_ SG_ 675 DRIVER_SEATBELT_UNLATCHED "CONFIRMED: 1 when the driver belt is unbuckled. Followed 4 of 4 buckle actions in a live capture (cluster warning 0x24D bit 146 0.5 s later), the filmed belt step of recording 1, and read 0 (buckled) at every seatbeltNotLatched refusal caused by the old signal. Constant over whole drives with the belt on.";
|
||||||
|
CM_ BO_ 552 "Rear-left blind-spot radar (20 Hz, silent when stopped). Bytes 8-15 carry object data when something is detected.";
|
||||||
|
CM_ SG_ 552 OBJECT_DETECTED "CONFIRMED on video: on 3 of 3 checked episodes a car appeared in the left lane beside the B10 in the road camera within 1 s of the flag clearing. Set in 8.5% of driving above 50 km/h, less often while signalling left (drivers wait for a clear lane).";
|
||||||
|
CM_ BO_ 554 "Rear-right blind-spot radar, same layout as BSD_LEFT (0x228).";
|
||||||
|
CM_ SG_ 554 OBJECT_DETECTED "INFERRED by symmetry with BSD_LEFT: same layout, set in 0.7% of driving above 50 km/h (in right-hand traffic you are rarely overtaken on the right). The one checked episode was not conclusive on video.";
|
||||||
|
CM_ SG_ 397 DRIVER_OVERRIDE "INFERRED: the EPS flags strong driver input. Set during both filmed driver overrides of LCC (0.4-0.5 s before LCC released) even though STEER_TORQUE_DRIVER only reached 2-3; otherwise set 66% of the time when |STEER_TORQUE_DRIVER| >= 15 and under 0.4% below 8. Short bursts. Also set whenever the car is above about 121 km/h, with or without the driver (on at 121.5, off at 120.1 km/h; 99% of frames above 121 km/h on a stock drive), so it only means driver input below that. The EPS still follows the steering request up there: openpilot steered at up to 134 km/h with it set.";
|
||||||
|
CM_ SG_ 397 ADAS_LKA_RECEIVED "CONFIRMED by the camera-unplug test: 1 while the EPS receives ADAS_LKA (0x83) from the camera, 0 with the camera unplugged (and for the first 0.2 s after ignition, before the camera starts). Bit 60 sets at the same time. Used as a temporary steering fault: the EPS is not receiving a valid steering frame.";
|
||||||
|
CM_ SG_ 397 ADAS_LKA_TIMEOUT "CONFIRMED by the camera-unplug test: 3 with the camera unplugged (no ADAS_LKA), 0 when it is received; also 3 for the first second after ignition.";
|
||||||
|
CM_ SG_ 397 STEER_ANGLE "CONFIRMED by filmed holds: raw moves about 4450 per 90 deg and 9000 per 180 deg. Sign CONFIRMED: positive = left (openpilot convention); raw rises to the right (r +0.98 against the comma gyro in the figure-eights). Factor is negative so openpilot reads left-positive. Lock is about -515/+522 deg, or 2.9 turns, which the driver confirmed. Centre 32490 from the filmed centre holds; a few counts may remain.";
|
||||||
|
CM_ SG_ 397 STEER_SPEED_ABS "INFERRED: one count is about 202 raw per second, or 4.04 deg/s, R2 0.99 or better on 5 datasets; 4 assumed, the same as the Leapmotor T03 DBC. Magnitude only, no sign.";
|
||||||
|
CM_ SG_ 397 STEER_TORQUE_DRIVER "INFERRED: driver steering torque, positive = left (openpilot convention). Raw 57 and 100 while held still at left and right lock, exactly 78 hands off; raw rises when steering right (r +0.54 to +0.81 with the steering rate on 3 traces). Hands-off LCC never exceeds 3, manual steering while moving reaches 7 (p90) to 20. Unit unknown.";
|
||||||
|
CM_ BO_ 131 "Layout INFERRED from 396,908 frames on 16 traces (5 days): 166 of 256 bits never change; every bit that is not always zero is defined here, so unpack-then-pack reproduces recorded frames exactly. 50 Hz, sent by the ADAS unit.";
|
||||||
|
CM_ SG_ 131 ACC_STATE "INFERRED, strong: 3 while ACC/LCC engaged, 2 when ACC is ready, 1 when not ready (Park, brake pressed) or overridden by the accelerator while engaged (96-100% of those frames have the pedal pressed, on 8 traces).";
|
||||||
|
CM_ SG_ 131 ACC_ACCEL_REQ "INFERRED, strong: the ACC acceleration request. Leads the measured acceleration (0x185 LONG_ACCEL) by about 250 ms, r +0.85 to +0.96 on 8 traces; fit gives zero at raw 99.9 and 0.045 m/s^2 per step (0.05 used, residual 0.08 m/s^2). Raw 100 (0) whenever not engaged.";
|
||||||
|
CM_ SG_ 131 ACC_OVERRIDE "INFERRED: set exactly when ACC_STATE drops to 1 while engaged, i.e. accelerator override (frame-for-frame match on 8 traces).";
|
||||||
|
CM_ SG_ 131 ASSIST_OFF_2 "INFERRED: identical to ASSIST_OFF on every frame.";
|
||||||
|
CM_ SG_ 131 CONSTANT_72 "CONSTANT: 125 (0x7D) on every recorded frame. Meaning unknown; must be sent as-is.";
|
||||||
|
CM_ SG_ 131 CONSTANT_152 "CONSTANT: 125 (0x7D) on every recorded frame. Meaning unknown; must be sent as-is.";
|
||||||
|
CM_ SG_ 131 UNKNOWN_90 "UNKNOWN: 28 on nearly every frame; a handful of other values. Copied from the camera frame.";
|
||||||
|
CM_ SG_ 131 STEER_ANGLE_REQ "INFERRED, strong: the LCC steering angle request, same encoding as STEER_ANGLE (positive = left; r 1.000 with it). On 5 routes it leads the measured angle (0x18D) by 70-100 ms while LCC steers, and the request-minus-measured gap tracks the LCC torque (r +0.35 to +0.59). In manual driving it lags by 20-30 ms, so it echoes the measured angle when not steering. Sent by the ADAS unit (its own clock, with 0x142/0x229/0x2D1/0x2D5). No torque request found in this frame. The camera sends it (it vanished with the camera unplugged), and the EPS followed openpilot's copy both ways with LCC_STEERING_ACTIVE_COPY set and the LCC_RAMP word.";
|
||||||
|
CM_ SG_ 389 SEATBELT_REMINDER "INFERRED, NOT the belt state: matches the belt only before READY. While driving it follows standstill (0 when stopped, 1 when moving) with the belt buckled, which made openpilot refuse to engage from a stop. Use SEATBELT.DRIVER_SEATBELT_UNLATCHED.";
|
||||||
|
CM_ SG_ 656 BLINKER_LEFT "CONFIRMED by filmed step order: left, right, then hazards. Flips every 0.40 s. Both blinker bits on means hazards.";
|
||||||
|
CM_ SG_ 656 BLINKER_RIGHT "CONFIRMED by filmed step order: left, right, then hazards. Flips every 0.40 s.";
|
||||||
|
CM_ SG_ 656 DRIVER_DOOR_OPEN "CONFIRMED once by filmed door opening; 1 for 11.5 s. Bit 46 did the same, so one may be another door or a lamp.";
|
||||||
|
CM_ BO_ 183 "Bits 16 and 28 set when the camera is unplugged (probably ADAS unavailable). Every bit that is not always zero is defined (UNKNOWN_* fields copied as-is), so unpack-then-pack reproduces recorded frames exactly; needed to send the camera a cancel copy of this frame.";
|
||||||
|
CM_ SG_ 183 STALK_PUSH "CONFIRMED by stated order, parked: 1 is a single push (ACC), 2 is a double push (LCC, passing through 1 first), each held about 1 s. INFERRED: 3 is pushing the stalk up, which the driver says cancels assist. All 14 logged value-3 pushes during assist ended it within about 0.25 s.";
|
||||||
|
CM_ SG_ 183 TORQUE_DEMAND "WEAK: rises with acceleration (r 0.78-0.84), but stayed at 0 during 3 filmed accelerator presses in Park. Probably torque demand. Drops to 0 whenever the accelerator is released, even while slowing at -1.5 m/s^2, so it carries no regen.";
|
||||||
|
CM_ SG_ 182 ACCEL_PEDAL "CONFIRMED by 3 filmed presses in Park, peak 254 each. Scale 0.4 percent per count as in the Leapmotor T03 DBC, so 254 is about 100 percent. One-pedal mode was off for this test.";
|
||||||
|
CM_ SG_ 182 BRAKE_PRESSED "CONFIRMED by 3 filmed presses in Park. Ends assist, as the driver says: both logged cases within 0.01 s. One-pedal mode was off for this test. Rarely on while slowing on earlier routes, which the driver says were almost always in one-pedal mode.";
|
||||||
|
CM_ SG_ 182 GEAR "CONFIRMED by filmed shifts and the dashboard. Earlier routes agree: 1 moves only backward, 0 and 2 never move, 3 only forward.";
|
||||||
|
CM_ SG_ 390 BRAKE_PRESSURE "INFERRED: bytes 2-5 are identical, peaks 51-57 on 3 filmed presses, near 0 otherwise. In filmed braking tests it stayed near 0 for much of the time the pedal was pressed, which suggests blended braking (regen first, friction later). Unit unknown.";
|
||||||
|
CM_ SG_ 183 ASSIST_ENGAGED "INFERRED: 1 in all 15 assist periods on 5 routes, including 1 ACC-only period, 0 elsewhere while driving. Also matched a route not used in the search: on 0.6 s after the push, off 0.6 s after the cancel.";
|
||||||
|
CM_ SG_ 589 ASSIST_ENGAGED_COPY "INFERRED: same behaviour as 0xB7 bit 30.";
|
||||||
|
CM_ SG_ 131 ASSIST_OFF "INFERRED: exact inverse of ASSIST_ENGAGED on 5 routes. Bit 44 behaves the same.";
|
||||||
|
CM_ SG_ 589 LCC_ENGAGED "INFERRED: on 95-100% of LCC periods, off in the ACC-only period and when not engaged. Only 1 ACC-only period tested.";
|
||||||
|
CM_ SG_ 397 LCC_STEERING_ACTIVE "INFERRED: never on outside LCC, on for 54-100% of it, so possibly when LCC is steering. Not checked against the dashboard.";
|
||||||
|
CM_ SG_ 131 LCC_STEERING_ACTIVE_COPY "INFERRED: same behaviour as 0x18D bit 67.";
|
||||||
|
CM_ SG_ 397 STEER_TORQUE_EPS "INFERRED, 12 bits (bit 180 is EPS_STATUS_180): exactly 1000 raw when LCC is not steering on most routes, 939-1074 when it is, follows byte 10 (r 0.82-0.91). Possibly the torque applied by LCC. Unit unknown. Sign INFERRED: positive pushes the wheel right, negative left (stock LCC, 90,000 samples on 3 routes: the angle moves the opposite way to the value, r -0.20 to -0.37; confirmed by the stage-2 steering steps). Also moved during a probable lane-departure correction with assist off.";
|
||||||
|
CM_ SG_ 397 EPS_STATUS_180 "INFERRED, meaning unknown: was read as bit 12 of STEER_TORQUE_EPS, which then jumped by 4096 and looked like a huge driver torque. Never set on 7 drives (1.3M frames); set twice on route 26e, for exactly 1.0 s each, while openpilot steered at 60-64 km/h with about 30-60 torque. Not a fixed hands-off timer (117 s and 68 s of steering before it).";
|
||||||
|
CM_ SG_ 322 FCW "INFERRED, strong: forward collision warning from the front camera. On for 1.5-3.3 s at the driver's reported warnings (2 of 2, route 00000261), each time about 2 s before the driver braked hard; ACC was off. About 13 rising edges per drive on 29 earlier drives. 0x229 bit 110 switches with it.";
|
||||||
|
CM_ SG_ 322 SPEED_LIMIT "CONFIRMED against filmed road-sign icons (90, 110): matches once a 1-2 s video timing difference is allowed. Values 20-130 in tens. A brief 50 lasting 0.6 s was not seen on the dashboard. 0 and 255 appear rarely and may mean none or invalid.";
|
||||||
|
CM_ SG_ 131 LCC_RAMP "CONFIRMED on the car (needed to steer left, and sets the EPS torque authority), meaning INFERRED: bytes 16-17 as one word. 0x7801 on every frame without LCC steering. While LCC steers it moves along a ladder of 254 per step (one step per frame): about 31 steps when it starts (0.5-0.6 s), deeper with lateral acceleration and speed, always 25-46 steps; steps = 19.1 + 9.94 * |lateral accel m/s^2| + 0.112 * speed km/h fits 142,234 stock frames (R^2 0.83). It jumps back to 0x7801 when LCC stops. The EPS torque range grows with the step count (about +/-10 early in the ramp, +/-45 at 30, +/-70 at 42-46). Earlier read as three fields; the top 4 bits are what looked like an LCC state (7 off, 6 engaging, 5 active, 4 curve). With the idle word plus the steering bit, the EPS followed openpilot's angle to the right only; with a fixed 30 steps it steered both ways but could not hold a curve at 75 km/h (torque flat at 61).";
|
||||||
|
CM_ SG_ 131 ACC_SET_SPEED "CONFIRMED: equal to the filmed green ACC badge in 6 of 6 checks (50, 70, 100 km/h), steps with knob rotation. Scale 0.2 km/h, unlike the 0.1 of the Leapmotor T03.";
|
||||||
|
CM_ SG_ 388 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 388 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 563 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 563 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 397 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 397 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 131 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 131 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 389 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 389 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 656 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 656 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 183 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 183 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 182 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 182 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 390 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 390 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 322 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 322 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
CM_ SG_ 589 CHECKSUM "CONFIRMED: AUTOSAR E2E Profile 2, as opendbc volkswagen_mqb_meb_checksum: crc=0xFF; for bytes 1..end: crc=CRC8H2F[crc^b]; crc^=K[counter]; crc=CRC8H2F[crc]; checksum=crc^0xFF. K is a 16-entry table per message in checksum_constants.json, learned on route 0000022d and exact on every tested frame of 3 other routes from 2 other days.";
|
||||||
|
CM_ SG_ 589 COUNTER "CONFIRMED: rolling 0-15, one step per frame.";
|
||||||
|
VAL_ 182 GEAR 0 "P" 1 "R" 2 "N" 3 "D" ;
|
||||||
|
VAL_ 183 STALK_PUSH 0 "NONE" 1 "SINGLE" 2 "DOUBLE" 3 "UP_CANCEL" ;
|
||||||
|
VAL_ 131 ACC_STATE 1 "NOT_READY_INFERRED" 2 "READY_INFERRED" 3 "ENGAGED_INFERRED" ;
|
||||||
@@ -34,6 +34,56 @@ NS_ :
|
|||||||
BS_:
|
BS_:
|
||||||
|
|
||||||
BU_: XXX
|
BU_: XXX
|
||||||
|
BO_ 256 PCS_STATE: 7 XXX
|
||||||
|
SG_ PCS_ALARM : 1|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ POWER_UP : 15|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
|
||||||
|
BO_ 400 RADAR_CYCLE: 7 XXX
|
||||||
|
SG_ SUMMARY_COUNT : 3|2@0+ (1,0) [0|3] "" XXX
|
||||||
|
SG_ TIMESTAMP : 23|32@0+ (1,0) [0|4294967295] "us" XXX
|
||||||
|
SG_ CYCLE_COUNTER : 52|4@1+ (1,0) [0|15] "" XXX
|
||||||
|
|
||||||
|
BO_ 401 TARGET_SUMMARY_A_INFO: 8 XXX
|
||||||
|
SG_ SCORE : 1|7@1+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ AGE : 9|7@1+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ TRACK_CODE : 26|6@1+ (1,0) [0|63] "" XXX
|
||||||
|
SG_ WIDTH : 34|6@1+ (0.1,0) [0|6.3] "m" XXX
|
||||||
|
SG_ AGE_COUNTER : 43|5@1+ (1,0) [0|31] "" XXX
|
||||||
|
SG_ HEIGHT : 49|7@1+ (0.1,0) [0|12.7] "m" XXX
|
||||||
|
SG_ LENGTH : 56|8@1+ (0.1,0) [0|25.5] "m" XXX
|
||||||
|
|
||||||
|
BO_ 402 TARGET_SUMMARY_A_POS: 4 XXX
|
||||||
|
SG_ LONG_DIST : 4|13@0+ (0.0625,-10) [-10|501.9375] "m" XXX
|
||||||
|
SG_ LAT_DIST : 20|13@0+ (0.015,-30.72) [-30.72|92.145] "m" XXX
|
||||||
|
|
||||||
|
BO_ 403 TARGET_SUMMARY_B_INFO: 8 XXX
|
||||||
|
SG_ SCORE : 1|7@1+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ AGE : 9|7@1+ (1,0) [0|127] "" XXX
|
||||||
|
SG_ TRACK_CODE : 26|6@1+ (1,0) [0|63] "" XXX
|
||||||
|
SG_ WIDTH : 34|6@1+ (0.1,0) [0|6.3] "m" XXX
|
||||||
|
SG_ AGE_COUNTER : 43|5@1+ (1,0) [0|31] "" XXX
|
||||||
|
SG_ HEIGHT : 49|7@1+ (0.1,0) [0|12.7] "m" XXX
|
||||||
|
SG_ LENGTH : 56|8@1+ (0.1,0) [0|25.5] "m" XXX
|
||||||
|
|
||||||
|
BO_ 404 TARGET_SUMMARY_B_POS: 4 XXX
|
||||||
|
SG_ LONG_DIST : 4|13@0+ (0.0625,-10) [-10|501.9375] "m" XXX
|
||||||
|
SG_ LAT_DIST : 20|13@0+ (0.015,-30.72) [-30.72|92.145] "m" XXX
|
||||||
|
|
||||||
|
BO_ 405 EVENT_OBJECT: 8 XXX
|
||||||
|
SG_ PATH_CURVATURE : 7|16@0+ (7.5e-06,-0.24576) [-0.24576|0.2457525] "1/m" XXX
|
||||||
|
SG_ OBJECT_ACCEL : 23|12@0+ (0.03125,-16) [-16|111.96875] "m/s^2" XXX
|
||||||
|
SG_ OBJECT_SPEED : 27|12@0+ (0.0625,0) [0|255.9375] "m/s" XXX
|
||||||
|
SG_ EGO_TRAVEL_TO_TTC : 46|11@0+ (0.05,0) [0|102.35] "m" XXX
|
||||||
|
SG_ OBJECT_DIST : 50|11@0+ (0.05,0) [0|102.35] "m" XXX
|
||||||
|
|
||||||
|
BO_ 406 EVENT_STATE: 8 XXX
|
||||||
|
SG_ REQUIRED_DECEL : 7|8@0- (0.095,0) [-12.16|12.065] "m/s^2" XXX
|
||||||
|
SG_ RADAR_FAULT : 8|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 514 RADAR_ALIVE: 5 XXX
|
||||||
|
SG_ CHECK_BYTE : 7|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ COUNTER : 15|4@0+ (1,0) [0|15] "" XXX
|
||||||
|
|
||||||
BO_ 565 ACC_TARGET_1: 8 XXX
|
BO_ 565 ACC_TARGET_1: 8 XXX
|
||||||
SG_ CHECK_BYTE : 7|8@0+ (1,0) [0|255] "" XXX
|
SG_ CHECK_BYTE : 7|8@0+ (1,0) [0|255] "" XXX
|
||||||
SG_ COUNTER : 15|4@0+ (1,0) [0|15] "" XXX
|
SG_ COUNTER : 15|4@0+ (1,0) [0|15] "" XXX
|
||||||
@@ -42,7 +92,7 @@ BO_ 565 ACC_TARGET_1: 8 XXX
|
|||||||
SG_ REL_SPEED : 31|11@0+ (0.125,-128) [-128|127.875] "m/s" XXX
|
SG_ REL_SPEED : 31|11@0+ (0.125,-128) [-128|127.875] "m/s" XXX
|
||||||
SG_ LAT_ACCEL : 34|8@0+ (0.125,-12.5) [-12.5|19.375] "m/s^2" XXX
|
SG_ LAT_ACCEL : 34|8@0+ (0.125,-12.5) [-12.5|19.375] "m/s^2" XXX
|
||||||
SG_ LAT_SPEED : 42|11@0+ (0.0125,-12.8) [-12.8|12.7875] "m/s" XXX
|
SG_ LAT_SPEED : 42|11@0+ (0.0125,-12.8) [-12.8|12.7875] "m/s" XXX
|
||||||
SG_ TARGET_ID : 60|5@0+ (1,0) [0|31] "" XXX
|
SG_ TARGET_ID : 61|6@0+ (1,0) [0|63] "" XXX
|
||||||
|
|
||||||
BO_ 567 ACC_TARGET_2: 8 XXX
|
BO_ 567 ACC_TARGET_2: 8 XXX
|
||||||
SG_ CHECK_BYTE : 7|8@0+ (1,0) [0|255] "" XXX
|
SG_ CHECK_BYTE : 7|8@0+ (1,0) [0|255] "" XXX
|
||||||
@@ -70,19 +120,66 @@ BO_ 571 ACC_TARGET_4: 3 XXX
|
|||||||
SG_ COUNTER : 15|4@0+ (1,0) [0|15] "" XXX
|
SG_ COUNTER : 15|4@0+ (1,0) [0|15] "" XXX
|
||||||
SG_ WIDTH : 11|12@0+ (1,0) [0|4095] "cm" XXX
|
SG_ WIDTH : 11|12@0+ (1,0) [0|4095] "cm" XXX
|
||||||
|
|
||||||
CM_ "Continental ARS510 front radar, radar bus: the target the radar's own ACC follows. Used on the radar-ACC platforms: RAV4 2022-25 (fwdRadar 8821F0R01100, 8821F0R03100), C-HR 2021-22 (8821FF4102xx-0500) and Yaris (8821F0D0xxxx). The 0x80 object list and 0x85 metadata record span many frames and are decoded by ars510-radar (ars510/). The radar interface uses STATE, REL_SPEED, TARGET_ID, LONG_DIST, LAT_DIST, PRESENT and TIMESTAMP; the other signals are documented for completeness.";
|
BO_ 591 RADAR_BOOT: 1 XXX
|
||||||
|
SG_ RADAR_RUNNING : 6|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
|
||||||
|
BO_ 1664 OBJECT_STREAM: 8 XXX
|
||||||
|
SG_ SELECTOR : 7|8@0+ (1,0) [0|255] "" XXX
|
||||||
|
SG_ LONG_DIST : 15|13@0+ (0.03125,0) [0|255.96875] "m" XXX
|
||||||
|
SG_ LAT_DIST : 18|11@0- (0.015,0) [-15.36|15.345] "m" XXX
|
||||||
|
SG_ SPEED : 39|10@0+ (0.15,-76.8) [-76.8|76.65] "m/s" XXX
|
||||||
|
SG_ STATIONARY : 40|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ ONCOMING : 41|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ SEEN_MOVING : 43|1@0+ (1,0) [0|1] "" XXX
|
||||||
|
SG_ LAT_SPEED : 55|8@0+ (0.15,-19.2) [-19.2|19.05] "m/s" XXX
|
||||||
|
|
||||||
|
CM_ "Continental ARS510 front radar, radar bus. Used on the radar-ACC platforms: RAV4 2022-25 (fwdRadar 8821F0R01100, 8821F0R03100), C-HR 2021-22 (8821FF4102xx-0500) and Yaris (8821F0D0xxxx). The 0x80 object list and 0x85 metadata record are ISO-TP transfers (740 and 144 bytes, CRC32-protected; flow control on 0x81 / 0x86) and are not described here; neither are values that need a computation across frames or signals (a summary's speed from its range slope, LAT_DIST's hidden 13th bit), which the comments explain instead. The radar interface reads ACC_TARGET_1-3 (STATE, REL_SPEED, TARGET_ID, LONG_DIST, LAT_DIST, PRESENT, TIMESTAMP); the other messages and signals are documented for completeness, decoded from recorded drives on two RAV4s and checked on the C-HR and Yaris test routes. Comments say where a unit or meaning is approximate. Camera-sent frames on this bus (0x101, 0x102, 0x180, 0x197, 0x210, 0x240-0x248, 0x24D, 0x500, 0x501) and the constant 0x103 and 0x23D (all zero) and 0x198 (0x10; 0x90 while RADAR_FAULT is set) are left out.";
|
||||||
|
CM_ BO_ 256 "Radar PCS state, 10 Hz. The first frame after power-up is FF FF (POWER_UP = 255; ignore it); zero otherwise, except PCS_ALARM.";
|
||||||
|
CM_ SG_ 256 PCS_ALARM "Pre-collision alarm: 1 from the same CAN frame as the car-bus PCS alarm (0x283 PCSNOCHG, 0x411 FCW) until it ends; seen in 8 stock alarms on 7 cars, never otherwise.";
|
||||||
|
CM_ SG_ 256 POWER_UP "255 on the first frame after power-up, when every bit is set; 0 otherwise.";
|
||||||
|
CM_ BO_ 514 "Radar alive frame, 16.7 Hz. Bytes 2-4 are constant (03 6D 80) on every recorded car; the first frame after power-up differs.";
|
||||||
|
CM_ SG_ 514 CHECK_BYTE "Depends only on COUNTER.";
|
||||||
|
CM_ SG_ 514 COUNTER "+1 per frame, mod 16.";
|
||||||
|
CM_ BO_ 591 "Radar start-up frame, 33 Hz.";
|
||||||
|
CM_ SG_ 591 RADAR_RUNNING "0 while the radar boots, 1 once running; stays 1 (booted, not healthy). RADAR_FAULT in EVENT_STATE reports object-list loss.";
|
||||||
|
CM_ BO_ 400 "Radar cycle header, once per 60 ms radar cycle, before the target summaries.";
|
||||||
|
CM_ SG_ 400 SUMMARY_COUNT "Number of target summaries this cycle (0-2); TARGET_SUMMARY_A fills first.";
|
||||||
|
CM_ SG_ 400 TIMESTAMP "Radar cycle clock.";
|
||||||
|
CM_ SG_ 400 CYCLE_COUNTER "Cycle counter mod 16, +3 per radar cycle; a different step means a dropped cycle.";
|
||||||
|
CM_ BO_ 401 "Target summary A: one target of the radar's internal tracker (the tracker behind the ACC target): the ACC car or one of the two nearest other moving vehicles. Sentinel FE FE FE FC FC FF FE FF = no target.";
|
||||||
|
CM_ SG_ 401 SCORE "91-100 while a target is present, 127 in the sentinel. Rises with the target's own over-ground speed (95 at 1-5 m/s, 99 at 10-15, 100 above about 15 m/s) and slightly with track age: a moving-vehicle confidence, too coarse for a speed.";
|
||||||
|
CM_ SG_ 401 AGE "Target age in radar cycles, saturates at 126.";
|
||||||
|
CM_ SG_ 401 TRACK_CODE "Track code; stays with a track and can move between summaries A and B.";
|
||||||
|
CM_ SG_ 401 WIDTH "Class template width: 1.8 car, 2.2 truck.";
|
||||||
|
CM_ SG_ 401 AGE_COUNTER "Grows with target age, saturates at 30.";
|
||||||
|
CM_ SG_ 401 HEIGHT "Class template height-like size: 1.5 car, 2.3 truck.";
|
||||||
|
CM_ SG_ 401 LENGTH "Class template length: 4.5 car, 12.0 truck.";
|
||||||
|
CM_ BO_ 402 "Target summary A position. Sentinel 00 FF 00 FF = no target. On the ACC car the distance is the ACC distance rounded down to 1/16 m. No speed is sent; the slope of LONG_DIST per track gives one.";
|
||||||
|
CM_ SG_ 402 LONG_DIST "Distance from the radar.";
|
||||||
|
CM_ SG_ 402 LAT_DIST "Lateral position, left positive.";
|
||||||
|
CM_ BO_ 403 "Target summary B: same layout as TARGET_SUMMARY_A_INFO.";
|
||||||
|
CM_ BO_ 404 "Target summary B position: same layout as TARGET_SUMMARY_A_POS.";
|
||||||
|
CM_ BO_ 405 "Event object: idle (exact payload) except in short time-to-collision states (0.5 % of moving cycles); then one object of the radar's tracker, usually the ACC car.";
|
||||||
|
CM_ SG_ 405 PATH_CURVATURE "Ego path curvature, left positive (about 1/133,000 per m per code).";
|
||||||
|
CM_ SG_ 405 OBJECT_ACCEL "Object over-ground acceleration (about 1/32 m/s^2 per code, approximate).";
|
||||||
|
CM_ SG_ 405 OBJECT_SPEED "Object longitudinal over-ground speed.";
|
||||||
|
CM_ SG_ 405 EGO_TRAVEL_TO_TTC "Ego's predicted travel until the time to collision (v T + a T^2 / 2, T = distance / closing speed), clamped at 0.";
|
||||||
|
CM_ SG_ 405 OBJECT_DIST "Object distance; on the ACC car the ACC distance rounded down to 0.05 m. 0 when idle.";
|
||||||
|
CM_ BO_ 406 "Event state, paired with EVENT_OBJECT.";
|
||||||
|
CM_ SG_ 406 REQUIRED_DECEL "Required deceleration for the event object while active: floor(a_req / 0.095) of a lead-moving / lead-stops formula with a 1.75 m margin.";
|
||||||
|
CM_ SG_ 406 RADAR_FAULT "Radar fault: held while the radar declares itself blocked (car-bus 0x411 dust state; the object list keeps running) and after some object-list outages; also set for the single first cycle after power-up, so require two or more consecutive cycles.";
|
||||||
CM_ BO_ 565 "ACC target, part 1: 50 Hz, content updated once per 60 ms radar cycle.";
|
CM_ BO_ 565 "ACC target, part 1: 50 Hz, content updated once per 60 ms radar cycle.";
|
||||||
CM_ SG_ 565 CHECK_BYTE "Check byte over the rest of the frame (algorithm unknown).";
|
CM_ SG_ 565 CHECK_BYTE "CRC-8 (polynomial 0x1D, MSB first) over the frame's signals serialized as zero-padded 8, 16 or 32-bit integers, not over the raw bytes; linear, so a 56-column table over payload bits plus a constant computes it.";
|
||||||
CM_ SG_ 565 STATE "5 = target present, 1 = idle (bytes 2-7 64 80 0B 24 00 FF), 15 = start-up.";
|
CM_ SG_ 565 STATE "5 = target present, 1 = idle (bytes 2-7 64 80 0B 24 00 FF), 15 = start-up.";
|
||||||
CM_ SG_ 565 REL_ACCEL "Target acceleration relative to ego, positive = opening.";
|
CM_ SG_ 565 REL_ACCEL "Target acceleration relative to ego, positive = opening.";
|
||||||
CM_ SG_ 565 REL_SPEED "Closing speed relative to ego, negative = closing.";
|
CM_ SG_ 565 REL_SPEED "Closing speed relative to ego, negative = closing.";
|
||||||
CM_ SG_ 565 LAT_ACCEL "Relative lateral acceleration, left positive (nominal unit). Mostly minus ego's own lateral acceleration.";
|
CM_ SG_ 565 LAT_ACCEL "Relative lateral acceleration, left positive (nominal unit). Mostly minus ego's own lateral acceleration.";
|
||||||
CM_ SG_ 565 LAT_SPEED "Lateral speed of the target relative to ego, left positive (about 0.0125 m/s per code).";
|
CM_ SG_ 565 LAT_SPEED "Lateral speed of the target relative to ego in the rotating ego frame, left positive (about 0.0125 m/s per code). Wraps above the top code (crossing traffic); the check byte then differs by 0x9C.";
|
||||||
CM_ SG_ 565 TARGET_ID "Changes when the radar switches to a different target; 31 while idle.";
|
CM_ SG_ 565 TARGET_ID "The radar tracker's track number: changes when the radar switches to a different target, kept when it re-acquires the same one. 32-63 occur on a C-HR radar (8821FF410300); the RAV4 radars sent 0-31 in every recorded drive. 63 in the idle payload.";
|
||||||
CM_ BO_ 567 "ACC target, part 2: 50 Hz.";
|
CM_ BO_ 567 "ACC target, part 2: 50 Hz.";
|
||||||
CM_ SG_ 567 CHECK_BYTE "Check byte: an affine parity function of bytes 1-7.";
|
CM_ SG_ 567 CHECK_BYTE "CRC-8 like ACC_TARGET_1's, over this frame's signals.";
|
||||||
CM_ SG_ 567 LONG_DIST "Distance from the radar.";
|
CM_ SG_ 567 LONG_DIST "Distance from the radar.";
|
||||||
CM_ SG_ 567 LAT_DIST "Lateral position, left positive.";
|
CM_ SG_ 567 LAT_DIST "Lateral position, left positive. Holds the low 12 bits of a 13-bit value: beyond +20.95 m (targets 21-53 m to the left in turns and at junctions) it wraps by 40.96 m, and the check byte then differs from the CRC of the visible bits by 0x14. Stops at -20.00 m on the right.";
|
||||||
CM_ SG_ 567 TRACKER_A "Raw tracker byte: about 35 on a steady target, higher while it accelerates or brakes.";
|
CM_ SG_ 567 TRACKER_A "Raw tracker byte: about 35 on a steady target, higher while it accelerates or brakes.";
|
||||||
CM_ SG_ 567 TRACKER_B "Raw tracker byte: about 86 for a stopped target, 128-135 for a steady mover, rises (and wraps) while it accelerates or brakes.";
|
CM_ SG_ 567 TRACKER_B "Raw tracker byte: about 86 for a stopped target, 128-135 for a steady mover, rises (and wraps) while it accelerates or brakes.";
|
||||||
CM_ SG_ 567 IN_PATH "1 while the target is confirmed in the path (level 5).";
|
CM_ SG_ 567 IN_PATH "1 while the target is confirmed in the path (level 5).";
|
||||||
@@ -90,15 +187,24 @@ CM_ SG_ 567 PRESENT "1 = target present.";
|
|||||||
CM_ SG_ 567 IN_PATH_LEVEL "In-path level 5, 4, 3, 2; steps to the neighboring level only; lower levels sit farther from the path.";
|
CM_ SG_ 567 IN_PATH_LEVEL "In-path level 5, 4, 3, 2; steps to the neighboring level only; lower levels sit farther from the path.";
|
||||||
CM_ SG_ 567 IN_PATH_CANDIDATE "1 while the target is a candidate (levels 4-2).";
|
CM_ SG_ 567 IN_PATH_CANDIDATE "1 while the target is a candidate (levels 4-2).";
|
||||||
CM_ BO_ 569 "ACC target, part 3: 50 Hz.";
|
CM_ BO_ 569 "ACC target, part 3: 50 Hz.";
|
||||||
CM_ SG_ 569 CHECK_BYTE "Check byte: an affine parity function of bytes 1-7.";
|
CM_ SG_ 569 CHECK_BYTE "CRC-8 like ACC_TARGET_1's, over this frame's signals.";
|
||||||
CM_ SG_ 569 CLASS "Target class: 1 car, 2 truck, 0 / 4 / 5 / 6 other, 7 idle, 15 start-up.";
|
CM_ SG_ 569 CLASS "Target class: 1 car, 2 truck; likely 0 narrow and 6 wide stationary object, 4 unclassified object, 5 crossing object; 7 idle, 15 start-up; 3 never seen.";
|
||||||
CM_ SG_ 569 STATE "1 with an ACC target, 2 idle.";
|
CM_ SG_ 569 STATE "1 with an ACC target, 2 idle.";
|
||||||
CM_ SG_ 569 IN_OBJECT_LIST "1 while the target also has an object in the 0x80 object list.";
|
CM_ SG_ 569 IN_OBJECT_LIST "1 while the target also has an object in the 0x80 object list.";
|
||||||
CM_ SG_ 569 PRESENT "1 = target present.";
|
CM_ SG_ 569 PRESENT "1 = target present.";
|
||||||
CM_ SG_ 569 TIMESTAMP "Radar cycle clock: changes once per 60 ms radar cycle, when the ACC target is recomputed.";
|
CM_ SG_ 569 TIMESTAMP "Radar cycle clock: changes once per 60 ms radar cycle, when the ACC target is recomputed.";
|
||||||
CM_ BO_ 571 "ACC target, part 4: 50 Hz, 3 bytes.";
|
CM_ BO_ 571 "ACC target, part 4: 50 Hz, 3 bytes.";
|
||||||
CM_ SG_ 571 CHECK_BYTE "CRC-8 (polynomial 0x1D, init 0, xor 0x59) over the counter and width bits.";
|
CM_ SG_ 571 CHECK_BYTE "CRC-8 SAE J1850 (polynomial 0x1D, init 0xFF, final xor 0xFF) over the bytes 0x00, COUNTER, WIDTH as 16 bits.";
|
||||||
CM_ SG_ 571 WIDTH "Target width: 0 while idle, 140-220 cm for the car class, 200-280 cm for the truck class.";
|
CM_ SG_ 571 WIDTH "Target width: 0 while idle, 140-220 cm for the car class, 200-280 cm for the truck class.";
|
||||||
|
CM_ BO_ 1664 "One object from the radar's tracker every 0.5 s: its track number 0, which is the ACC target whenever TARGET_ID is 0 and otherwise mostly a stationary roadside object.";
|
||||||
|
CM_ SG_ 1664 SELECTOR "0 / 1 mostly stationary objects, 3 mostly same-direction vehicles.";
|
||||||
|
CM_ SG_ 1664 LONG_DIST "Longitudinal distance.";
|
||||||
|
CM_ SG_ 1664 LAT_DIST "Lateral position, left positive; covers +-15.36 m.";
|
||||||
|
CM_ SG_ 1664 SPEED "Speed over ground; 0 for stationary objects.";
|
||||||
|
CM_ SG_ 1664 STATIONARY "1 for a stationary object.";
|
||||||
|
CM_ SG_ 1664 ONCOMING "1 for an oncoming object.";
|
||||||
|
CM_ SG_ 1664 SEEN_MOVING "1 once the object has been seen moving (with STATIONARY: a stopped vehicle).";
|
||||||
|
CM_ SG_ 1664 LAT_SPEED "Lateral speed over ground, left positive (about 0.13-0.18 m/s per code, nominal 0.15).";
|
||||||
VAL_ 565 STATE 15 "STARTUP" 5 "TARGET" 1 "NO_TARGET" ;
|
VAL_ 565 STATE 15 "STARTUP" 5 "TARGET" 1 "NO_TARGET" ;
|
||||||
VAL_ 569 CLASS 0 "OTHER_0" 1 "CAR" 2 "TRUCK" 4 "OTHER_4" 5 "OTHER_5" 6 "OTHER_6" 7 "NO_TARGET" 15 "STARTUP" ;
|
VAL_ 569 CLASS 0 "STATIONARY_NARROW" 1 "CAR" 2 "TRUCK" 4 "UNCLASSIFIED" 5 "CROSSING" 6 "STATIONARY_WIDE" 7 "NO_TARGET" 15 "STARTUP" ;
|
||||||
VAL_ 569 STATE 1 "TARGET" 2 "NO_TARGET" ;
|
VAL_ 569 STATE 1 "TARGET" 2 "NO_TARGET" ;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
#define SAFETY_VOLVO 36U
|
#define SAFETY_VOLVO 36U
|
||||||
#define SAFETY_MG 38U
|
#define SAFETY_MG 38U
|
||||||
#define SAFETY_TESLA_PREAP 39U
|
#define SAFETY_TESLA_PREAP 39U
|
||||||
|
#define SAFETY_LEAPMOTOR 40U
|
||||||
|
|
||||||
#define GET_BIT(msg, b) ((bool)!!(((msg)->data[((b) / 8U)] >> ((b) % 8U)) & 0x1U))
|
#define GET_BIT(msg, b) ((bool)!!(((msg)->data[((b) / 8U)] >> ((b) % 8U)) & 0x1U))
|
||||||
#define GET_FLAG(value, mask) (((value) & (mask)) == (mask))
|
#define GET_FLAG(value, mask) (((value) & (mask)) == (mask))
|
||||||
@@ -411,6 +412,7 @@ extern const safety_hooks rivian_hooks;
|
|||||||
extern const safety_hooks psa_hooks;
|
extern const safety_hooks psa_hooks;
|
||||||
extern const safety_hooks byd_hooks;
|
extern const safety_hooks byd_hooks;
|
||||||
extern const safety_hooks mg_hooks;
|
extern const safety_hooks mg_hooks;
|
||||||
|
extern const safety_hooks leapmotor_hooks;
|
||||||
|
|
||||||
extern const safety_hooks volvo_cma_hooks;
|
extern const safety_hooks volvo_cma_hooks;
|
||||||
extern const safety_hooks volvo_c1_hooks;
|
extern const safety_hooks volvo_c1_hooks;
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ static bool hyundai_non_scc_software_cruise_param(uint16_t param) {
|
|||||||
case 0x1020U: case 0x1820U: case 0x1420U: case 0x1C20U:
|
case 0x1020U: case 0x1820U: case 0x1420U: case 0x1C20U:
|
||||||
case 0x1060U: case 0x1860U: case 0x1460U: case 0x1C60U:
|
case 0x1060U: case 0x1860U: case 0x1460U: case 0x1C60U:
|
||||||
case 0x1061U: case 0x1861U: case 0x1461U: case 0x1C61U:
|
case 0x1061U: case 0x1861U: case 0x1461U: case 0x1C61U:
|
||||||
|
case 0x1871U: case 0x1C71U:
|
||||||
case 0x1022U: case 0x1822U: case 0x1422U: case 0x1C22U:
|
case 0x1022U: case 0x1822U: case 0x1422U: case 0x1C22U:
|
||||||
selected = true;
|
selected = true;
|
||||||
break;
|
break;
|
||||||
@@ -252,6 +253,16 @@ static void hyundai_blended_cancel_check(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void hyundai_rx_hook(const CANPacket_t *msg) {
|
static void hyundai_rx_hook(const CANPacket_t *msg) {
|
||||||
|
if (hyundai_kona_ev_label_cruise && (msg->bus == 0U) && (msg->addr == 0x592U) && (GET_LEN(msg) == 8U)) {
|
||||||
|
if (!hyundai_kona_ev_label_fresh()) {
|
||||||
|
controls_allowed = false;
|
||||||
|
cruise_engaged_prev = true;
|
||||||
|
hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
|
||||||
|
classic_non_scc_aol_clear_authorization();
|
||||||
|
}
|
||||||
|
hyundai_kona_ev_label_ts = microsecond_timer_get();
|
||||||
|
hyundai_kona_ev_label_seen = true;
|
||||||
|
}
|
||||||
classic_non_scc_aol_rx(msg);
|
classic_non_scc_aol_rx(msg);
|
||||||
blended_aol_rx(msg);
|
blended_aol_rx(msg);
|
||||||
hyundai_blended_cancel_check();
|
hyundai_blended_cancel_check();
|
||||||
@@ -283,9 +294,14 @@ static void hyundai_rx_hook(const CANPacket_t *msg) {
|
|||||||
hyundai_common_cruise_state_check(GET_BIT(msg, 35U));
|
hyundai_common_cruise_state_check(GET_BIT(msg, 35U));
|
||||||
}
|
}
|
||||||
if (hyundai_non_scc) {
|
if (hyundai_non_scc) {
|
||||||
if ((msg->addr == 0x595U) && hyundai_hybrid_gas_signal) {
|
if (hyundai_kona_ev_label_cruise && (msg->addr == 0x592U) && (GET_LEN(msg) == 8U)) {
|
||||||
|
hyundai_common_cruise_state_check(GET_BIT(msg, 34U) && GET_BIT(msg, 35U));
|
||||||
|
if (brake_pressed || gas_pressed) {
|
||||||
|
controls_allowed = false;
|
||||||
|
}
|
||||||
|
} else if ((msg->addr == 0x595U) && hyundai_hybrid_gas_signal) {
|
||||||
hyundai_common_cruise_state_check(GET_BIT(msg, 51U));
|
hyundai_common_cruise_state_check(GET_BIT(msg, 51U));
|
||||||
} else if ((msg->addr == 0x329U) && hyundai_ev_gas_signal) {
|
} else if ((msg->addr == 0x329U) && hyundai_ev_gas_signal && !hyundai_kona_ev_label_cruise) {
|
||||||
hyundai_common_cruise_state_check(GET_BIT(msg, 30U));
|
hyundai_common_cruise_state_check(GET_BIT(msg, 30U));
|
||||||
} else if ((msg->addr == 0x260U) && !hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) {
|
} else if ((msg->addr == 0x260U) && !hyundai_ev_gas_signal && !hyundai_hybrid_gas_signal) {
|
||||||
hyundai_common_cruise_state_check(GET_BIT(msg, 26U));
|
hyundai_common_cruise_state_check(GET_BIT(msg, 26U));
|
||||||
@@ -321,6 +337,13 @@ static void hyundai_rx_hook(const CANPacket_t *msg) {
|
|||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
cruise_button_prev = cruise_button;
|
cruise_button_prev = cruise_button;
|
||||||
|
} else if (hyundai_kona_ev_label_cruise) {
|
||||||
|
hyundai_common_cruise_buttons_check(cruise_button == HYUNDAI_BTN_CANCEL ? HYUNDAI_BTN_NONE : cruise_button,
|
||||||
|
false, false, hyundai_long_main_policy);
|
||||||
|
if ((cruise_button == HYUNDAI_BTN_CANCEL) || main_button) {
|
||||||
|
controls_allowed = false;
|
||||||
|
hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
hyundai_common_cruise_buttons_check(cruise_button, main_button, false, hyundai_long_main_policy);
|
hyundai_common_cruise_buttons_check(cruise_button, main_button, false, hyundai_long_main_policy);
|
||||||
}
|
}
|
||||||
@@ -513,7 +536,9 @@ static bool hyundai_tx_hook(const CANPacket_t *msg) {
|
|||||||
hyundai_alt_limits_2 ? HYUNDAI_STEERING_LIMITS_ALT_2 :
|
hyundai_alt_limits_2 ? HYUNDAI_STEERING_LIMITS_ALT_2 :
|
||||||
hyundai_alt_limits ? HYUNDAI_STEERING_LIMITS_ALT : HYUNDAI_STEERING_LIMITS;
|
hyundai_alt_limits ? HYUNDAI_STEERING_LIMITS_ALT : HYUNDAI_STEERING_LIMITS;
|
||||||
|
|
||||||
if (steer_torque_cmd_checks(desired_torque, steer_req, limits)) {
|
if (steer_torque_cmd_checks(desired_torque, steer_req, limits) ||
|
||||||
|
(hyundai_kona_ev_label_cruise && ((desired_torque != 0) || steer_req) &&
|
||||||
|
(!hyundai_kona_ev_label_fresh() || !aol_rx_healthy()))) {
|
||||||
tx = false;
|
tx = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -554,7 +579,8 @@ static bool hyundai_tx_hook(const CANPacket_t *msg) {
|
|||||||
allowed_set = (button == HYUNDAI_BTN_SET) && stock_cruise_ready;
|
allowed_set = (button == HYUNDAI_BTN_SET) && stock_cruise_ready;
|
||||||
}
|
}
|
||||||
bool allowed_cancel = (button == 4) && cruise_engaged_prev;
|
bool allowed_cancel = (button == 4) && cruise_engaged_prev;
|
||||||
if (!(allowed_resume || allowed_set || allowed_cancel)) {
|
if (!(allowed_resume || allowed_set || allowed_cancel) ||
|
||||||
|
(hyundai_kona_ev_label_cruise && (!hyundai_kona_ev_label_fresh() || !aol_rx_healthy()))) {
|
||||||
tx = false;
|
tx = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -675,6 +701,7 @@ static safety_config hyundai_init(uint16_t safety_param) {
|
|||||||
hyundai_long_main_policy = HYUNDAI_MAIN_TRACK;
|
hyundai_long_main_policy = HYUNDAI_MAIN_TRACK;
|
||||||
}
|
}
|
||||||
classic_non_scc_aol_configure(param, false);
|
classic_non_scc_aol_configure(param, false);
|
||||||
|
hyundai_kona_ev_label_cruise = (param == 0x1851U) || (param == HYUNDAI_KONA_EV_LABEL_CRUISE_AOL);
|
||||||
blended_aol_configure(param);
|
blended_aol_configure(param);
|
||||||
hyundai_blended_alpha = false;
|
hyundai_blended_alpha = false;
|
||||||
#ifdef ALLOW_DEBUG
|
#ifdef ALLOW_DEBUG
|
||||||
@@ -859,6 +886,11 @@ static safety_config hyundai_init(uint16_t safety_param) {
|
|||||||
HYUNDAI_NON_SCC_HEV_ADDR_CHECK
|
HYUNDAI_NON_SCC_HEV_ADDR_CHECK
|
||||||
HYUNDAI_CLASSIC_AOL_LDA_RX_CHECKS
|
HYUNDAI_CLASSIC_AOL_LDA_RX_CHECKS
|
||||||
};
|
};
|
||||||
|
static RxCheck hyundai_kona_ev_label_rx_checks[] = {
|
||||||
|
HYUNDAI_COMMON_RX_CHECKS(false)
|
||||||
|
HYUNDAI_CLASSIC_AOL_EV_MAIN_RX_CHECK
|
||||||
|
HYUNDAI_LDA_BUTTON_ADDR_CHECK
|
||||||
|
};
|
||||||
static RxCheck hyundai_classic_aol_ev_rx_checks[] = {
|
static RxCheck hyundai_classic_aol_ev_rx_checks[] = {
|
||||||
HYUNDAI_COMMON_RX_CHECKS(false)
|
HYUNDAI_COMMON_RX_CHECKS(false)
|
||||||
HYUNDAI_NON_SCC_EV_ADDR_CHECK
|
HYUNDAI_NON_SCC_EV_ADDR_CHECK
|
||||||
@@ -895,7 +927,9 @@ static safety_config hyundai_init(uint16_t safety_param) {
|
|||||||
SET_TX_MSGS(HYUNDAI_TX_MSGS, ret);
|
SET_TX_MSGS(HYUNDAI_TX_MSGS, ret);
|
||||||
}
|
}
|
||||||
if (hyundai_non_scc) {
|
if (hyundai_non_scc) {
|
||||||
if (classic_non_scc_aol_ev) {
|
if (hyundai_kona_ev_label_cruise) {
|
||||||
|
SET_RX_CHECKS(hyundai_kona_ev_label_rx_checks, ret);
|
||||||
|
} else if (classic_non_scc_aol_ev) {
|
||||||
if (classic_non_scc_aol_lda) {
|
if (classic_non_scc_aol_lda) {
|
||||||
SET_RX_CHECKS(hyundai_classic_aol_ev_lda_rx_checks, ret);
|
SET_RX_CHECKS(hyundai_classic_aol_ev_lda_rx_checks, ret);
|
||||||
} else {
|
} else {
|
||||||
@@ -929,7 +963,8 @@ static safety_config hyundai_init(uint16_t safety_param) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
hyundai_classic_scc_aol_rx_config(&ret, false);
|
hyundai_classic_scc_aol_rx_config(&ret, false);
|
||||||
if (classic_long_aol_param(param) && !classic_long_aol_enabled) {
|
if ((classic_long_aol_param(param) && !classic_long_aol_enabled) ||
|
||||||
|
(!hyundai_non_scc_software_cruise && ((param == 0x1871U) || (param == 0x1C71U)))) {
|
||||||
const safety_config denied = {0};
|
const safety_config denied = {0};
|
||||||
ret = denied;
|
ret = denied;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ static bool blended_aol_claimed = false;
|
|||||||
static bool blended_aol_session = false;
|
static bool blended_aol_session = false;
|
||||||
static bool blended_aol_request_seen = false;
|
static bool blended_aol_request_seen = false;
|
||||||
static bool blended_aol_brake_continuation = false;
|
static bool blended_aol_brake_continuation = false;
|
||||||
|
static bool blended_aol_stock_continuation = false;
|
||||||
static bool blended_aol_idle_owned[2] = {false, false};
|
static bool blended_aol_idle_owned[2] = {false, false};
|
||||||
static bool blended_aol_neutral[3] = {false, false, false};
|
static bool blended_aol_neutral[3] = {false, false, false};
|
||||||
static bool blended_aol_pressed[3] = {false, false, false};
|
static bool blended_aol_pressed[3] = {false, false, false};
|
||||||
@@ -47,6 +48,7 @@ static void blended_aol_clear(void) {
|
|||||||
blended_aol_session = false;
|
blended_aol_session = false;
|
||||||
blended_aol_request_seen = false;
|
blended_aol_request_seen = false;
|
||||||
blended_aol_brake_continuation = false;
|
blended_aol_brake_continuation = false;
|
||||||
|
blended_aol_stock_continuation = false;
|
||||||
blended_aol_idle_owned[0] = false;
|
blended_aol_idle_owned[0] = false;
|
||||||
blended_aol_idle_owned[1] = false;
|
blended_aol_idle_owned[1] = false;
|
||||||
blended_aol_token_ts = 0U;
|
blended_aol_token_ts = 0U;
|
||||||
@@ -109,20 +111,33 @@ static uint8_t blended_aol_request_mask(void) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool blended_aol_main_current(uint32_t now) {
|
||||||
|
return blended_aol_main_seen && blended_aol_main &&
|
||||||
|
(safety_get_ts_elapsed(now, blended_aol_main_ts) <= 100000U);
|
||||||
|
}
|
||||||
|
|
||||||
static uint8_t blended_aol_permission_mask(void) {
|
static uint8_t blended_aol_permission_mask(void) {
|
||||||
uint8_t result = 0U;
|
uint8_t result = 0U;
|
||||||
|
const uint32_t now = microsecond_timer_get();
|
||||||
const bool source_current = (blended_aol_token_source < 3U) &&
|
const bool source_current = (blended_aol_token_source < 3U) &&
|
||||||
(safety_get_ts_elapsed(microsecond_timer_get(), blended_aol_source_ts[blended_aol_token_source]) <= 300000U);
|
(safety_get_ts_elapsed(now, blended_aol_source_ts[blended_aol_token_source]) <= 300000U);
|
||||||
if (!aol_rx_healthy() || (blended_aol_token && !source_current)) {
|
if (!aol_rx_healthy() || (blended_aol_token && !source_current)) {
|
||||||
blended_aol_clear();
|
blended_aol_clear();
|
||||||
} else if (((blended_aol_request_mask() & 1U) != 0U) && (controls_allowed || blended_aol_token || blended_aol_brake_continuation)) {
|
} else if ((blended_aol_request_mask() & 1U) != 0U) {
|
||||||
result = 1U;
|
const bool stock_main = blended_aol_hda2 && !blended_aol_long && blended_aol_main_current(now);
|
||||||
|
const bool stock_buttons_current = (blended_aol_source_ts[0] != 0U) &&
|
||||||
|
(safety_get_ts_elapsed(now, blended_aol_source_ts[0]) <= 300000U);
|
||||||
|
if (stock_main && stock_buttons_current && controls_allowed && cruise_engaged_prev) {
|
||||||
|
blended_aol_stock_continuation = true;
|
||||||
|
}
|
||||||
|
if (controls_allowed || blended_aol_token || blended_aol_brake_continuation ||
|
||||||
|
(blended_aol_stock_continuation && stock_main && stock_buttons_current)) {
|
||||||
|
result = 1U;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
}
|
}
|
||||||
if (blended_aol_long) {
|
if (blended_aol_long) {
|
||||||
const bool main_current = blended_aol_main_seen && blended_aol_main &&
|
if (!blended_aol_main_current(now)) {
|
||||||
(safety_get_ts_elapsed(microsecond_timer_get(), blended_aol_main_ts) <= 100000U);
|
|
||||||
if (!main_current) {
|
|
||||||
blended_aol_clear();
|
blended_aol_clear();
|
||||||
result = 0U;
|
result = 0U;
|
||||||
} else if (aol_rx_healthy() && controls_allowed && !brake_pressed && !gas_pressed &&
|
} else if (aol_rx_healthy() && controls_allowed && !brake_pressed && !gas_pressed &&
|
||||||
@@ -153,7 +168,17 @@ static void blended_aol_rx(const CANPacket_t *msg) {
|
|||||||
if (blended_aol_enabled) {
|
if (blended_aol_enabled) {
|
||||||
const unsigned int pt = blended_aol_hda2 ? 1U : 0U;
|
const unsigned int pt = blended_aol_hda2 ? 1U : 0U;
|
||||||
const uint32_t now = microsecond_timer_get();
|
const uint32_t now = microsecond_timer_get();
|
||||||
if (blended_aol_hda2 && !blended_aol_long && msg_matches(msg, 0x394U, pt, 8U)) {
|
const bool stock_hda2 = blended_aol_hda2 && !blended_aol_long;
|
||||||
|
if (stock_hda2 && msg_matches(msg, 0x421U, pt, 8U)) {
|
||||||
|
const bool main = GET_BIT(msg, 27U);
|
||||||
|
if (blended_aol_main && !main) {
|
||||||
|
blended_aol_clear();
|
||||||
|
}
|
||||||
|
blended_aol_main_seen = true;
|
||||||
|
blended_aol_main = main;
|
||||||
|
blended_aol_main_ts = now;
|
||||||
|
}
|
||||||
|
if (stock_hda2 && msg_matches(msg, 0x394U, pt, 8U)) {
|
||||||
const bool brake = ((msg->data[5] >> 5U) & 3U) == 2U;
|
const bool brake = ((msg->data[5] >> 5U) & 3U) == 2U;
|
||||||
if (brake && !brake_pressed && controls_allowed && blended_aol_owned[0] &&
|
if (brake && !brake_pressed && controls_allowed && blended_aol_owned[0] &&
|
||||||
(safety_get_ts_elapsed(now, blended_aol_tx_ts[0]) <= AOL_HOST_REQUEST_TIMEOUT_US) &&
|
(safety_get_ts_elapsed(now, blended_aol_tx_ts[0]) <= AOL_HOST_REQUEST_TIMEOUT_US) &&
|
||||||
@@ -174,16 +199,14 @@ static void blended_aol_rx(const CANPacket_t *msg) {
|
|||||||
bool pressed = false;
|
bool pressed = false;
|
||||||
if ((msg->bus == pt) && (msg->addr == 0x4F1U) && (GET_LEN(msg) == 4U)) {
|
if ((msg->bus == pt) && (msg->addr == 0x4F1U) && (GET_LEN(msg) == 4U)) {
|
||||||
if ((msg->data[0] & 7U) == 4U) {
|
if ((msg->data[0] & 7U) == 4U) {
|
||||||
// Mixed LONG Pause/Resume still clears ordinary/LONG authority in the
|
|
||||||
// cruise hook. Retain only an already claimed, current lateral token.
|
|
||||||
// CANCEL cannot arm, renew a request/gesture lease, or clear an inhibit.
|
|
||||||
const bool source_current = (blended_aol_token_source < 3U) &&
|
const bool source_current = (blended_aol_token_source < 3U) &&
|
||||||
(safety_get_ts_elapsed(now, blended_aol_source_ts[blended_aol_token_source]) <= 300000U);
|
(safety_get_ts_elapsed(now, blended_aol_source_ts[blended_aol_token_source]) <= 300000U);
|
||||||
const bool retain_lateral = blended_aol_long && !GET_BIT(msg, 3U) &&
|
const bool gesture_owned = blended_aol_token && blended_aol_claimed && source_current &&
|
||||||
blended_aol_token && blended_aol_claimed && blended_aol_session && heartbeat_engaged &&
|
((blended_aol_long && blended_aol_main_current(now)) || stock_hda2);
|
||||||
blended_aol_main_seen && blended_aol_main &&
|
const bool stock_owned = stock_hda2 && blended_aol_stock_continuation && blended_aol_main_current(now) &&
|
||||||
(safety_get_ts_elapsed(now, blended_aol_main_ts) <= 100000U) && source_current &&
|
(blended_aol_source_ts[0] != 0U) && (safety_get_ts_elapsed(now, blended_aol_source_ts[0]) <= 300000U);
|
||||||
blended_aol_request_seen && ((aol_host_axis_mask & 1U) != 0U) &&
|
const bool retain_lateral = !GET_BIT(msg, 3U) && (gesture_owned || stock_owned) &&
|
||||||
|
blended_aol_session && heartbeat_engaged && blended_aol_request_seen && ((aol_host_axis_mask & 1U) != 0U) &&
|
||||||
(safety_get_ts_elapsed(now, aol_host_request_ts) <= AOL_HOST_REQUEST_TIMEOUT_US) &&
|
(safety_get_ts_elapsed(now, aol_host_request_ts) <= AOL_HOST_REQUEST_TIMEOUT_US) &&
|
||||||
aol_rx_healthy() && !relay_malfunction && !safety_rx_checks_invalid;
|
aol_rx_healthy() && !relay_malfunction && !safety_rx_checks_invalid;
|
||||||
if (!retain_lateral) {
|
if (!retain_lateral) {
|
||||||
|
|||||||
@@ -1251,7 +1251,7 @@ static bool hyundai_kona_host_steering(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool hyundai_kona_lfa_valid(const CANPacket_t *msg) {
|
static bool hyundai_kona_lfa_valid(const CANPacket_t *msg) {
|
||||||
return msg->fd && !msg->extended && (GET_LEN(msg) == 16U) &&
|
return !msg->extended && (GET_LEN(msg) == 16U) &&
|
||||||
(hyundai_canfd_get_checksum(msg) == (hyundai_common_canfd_compute_checksum(msg) ^ 0x041DU));
|
(hyundai_canfd_get_checksum(msg) == (hyundai_common_canfd_compute_checksum(msg) ^ 0x041DU));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1277,7 +1277,7 @@ static bool hyundai_kona_camera_without_slot(const CANPacket_t *msg) {
|
|||||||
static bool hyundai_kona_camera_release_current(const CANPacket_t *msg, uint32_t now) {
|
static bool hyundai_kona_camera_release_current(const CANPacket_t *msg, uint32_t now) {
|
||||||
return (msg->bus == 2U) && hyundai_kona_output_seen && hyundai_kona_host_output &&
|
return (msg->bus == 2U) && hyundai_kona_output_seen && hyundai_kona_host_output &&
|
||||||
hyundai_kona_camera_seen && !relay_malfunction && !safety_rx_checks_invalid && aol_rx_healthy() &&
|
hyundai_kona_camera_seen && !relay_malfunction && !safety_rx_checks_invalid && aol_rx_healthy() &&
|
||||||
!hyundai_kona_host_steering() && hyundai_kona_lfa_valid(msg) &&
|
!hyundai_kona_host_steering() && msg->fd && hyundai_kona_lfa_valid(msg) &&
|
||||||
((uint8_t)(msg->data[2] - hyundai_kona_output_counter) == 1U) &&
|
((uint8_t)(msg->data[2] - hyundai_kona_output_counter) == 1U) &&
|
||||||
((uint8_t)(msg->data[2] - hyundai_kona_camera_counter) == 1U) &&
|
((uint8_t)(msg->data[2] - hyundai_kona_camera_counter) == 1U) &&
|
||||||
(safety_get_ts_elapsed(now, hyundai_kona_camera_ts) <= 20000U);
|
(safety_get_ts_elapsed(now, hyundai_kona_camera_ts) <= 20000U);
|
||||||
@@ -1311,7 +1311,7 @@ static bool hyundai_kona_camera_output(const CANPacket_t *msg, CANPacket_t *outp
|
|||||||
const uint8_t delta = (uint8_t)(counter - hyundai_kona_camera_counter);
|
const uint8_t delta = (uint8_t)(counter - hyundai_kona_camera_counter);
|
||||||
const bool advancing = (delta > 0U) && (delta <= 127U);
|
const bool advancing = (delta > 0U) && (delta <= 127U);
|
||||||
const bool consecutive = hyundai_kona_camera_seen && (delta == 1U) && (camera_age <= 20000U);
|
const bool consecutive = hyundai_kona_camera_seen && (delta == 1U) && (camera_age <= 20000U);
|
||||||
blocked = !hyundai_kona_lfa_valid(msg) || safety_rx_checks_invalid || !aol_rx_healthy() ||
|
blocked = !msg->fd || !hyundai_kona_lfa_valid(msg) || safety_rx_checks_invalid || !aol_rx_healthy() ||
|
||||||
(hyundai_kona_camera_seen && (camera_age <= 50000U) && !advancing);
|
(hyundai_kona_camera_seen && (camera_age <= 50000U) && !advancing);
|
||||||
if (!blocked) {
|
if (!blocked) {
|
||||||
hyundai_kona_camera_counter = counter;
|
hyundai_kona_camera_counter = counter;
|
||||||
@@ -1344,6 +1344,7 @@ static bool hyundai_kona_camera_output(const CANPacket_t *msg, CANPacket_t *outp
|
|||||||
candidate.data[5] = (candidate.data[5] & 0x01U) | (uint8_t)((raw & 0x7FU) << 1U);
|
candidate.data[5] = (candidate.data[5] & 0x01U) | (uint8_t)((raw & 0x7FU) << 1U);
|
||||||
candidate.data[6] = (candidate.data[6] & 0xF0U) | (uint8_t)(raw >> 7U);
|
candidate.data[6] = (candidate.data[6] & 0xF0U) | (uint8_t)(raw >> 7U);
|
||||||
}
|
}
|
||||||
|
candidate.fd = msg->fd;
|
||||||
candidate.data[2] = counter;
|
candidate.data[2] = counter;
|
||||||
const uint16_t checksum = hyundai_common_canfd_compute_checksum(&candidate) ^ 0x041DU;
|
const uint16_t checksum = hyundai_common_canfd_compute_checksum(&candidate) ^ 0x041DU;
|
||||||
candidate.data[0] = (uint8_t)checksum;
|
candidate.data[0] = (uint8_t)checksum;
|
||||||
@@ -1358,6 +1359,22 @@ static bool hyundai_kona_camera_output(const CANPacket_t *msg, CANPacket_t *outp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
hyundai_kona_pending = false;
|
hyundai_kona_pending = false;
|
||||||
|
if (!*replaced && authority && consecutive && hyundai_kona_slot_owned) {
|
||||||
|
// Keep the camera's status and counter without repeating old host torque.
|
||||||
|
CANPacket_t neutral = *msg;
|
||||||
|
neutral.data[5] &= 0x01U;
|
||||||
|
neutral.data[6] = (neutral.data[6] & 0xC0U) | 0x08U;
|
||||||
|
const uint16_t checksum = hyundai_common_canfd_compute_checksum(&neutral) ^ 0x041DU;
|
||||||
|
neutral.data[0] = (uint8_t)checksum;
|
||||||
|
neutral.data[1] = (uint8_t)(checksum >> 8U);
|
||||||
|
neutral.bus = 0U;
|
||||||
|
hyundai_kona_emitting = true;
|
||||||
|
*replaced = safety_tx_hook(&neutral);
|
||||||
|
hyundai_kona_emitting = false;
|
||||||
|
if (*replaced) {
|
||||||
|
*output = neutral;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!*replaced) {
|
if (!*replaced) {
|
||||||
const bool camera_neutral = ((msg->data[6] & 0x3FU) == 0x08U) && ((msg->data[5] & 0xFEU) == 0U);
|
const bool camera_neutral = ((msg->data[6] & 0x3FU) == 0x08U) && ((msg->data[5] & 0xFEU) == 0U);
|
||||||
blocked = (hyundai_kona_slot_owned && !camera_neutral) ||
|
blocked = (hyundai_kona_slot_owned && !camera_neutral) ||
|
||||||
@@ -1461,7 +1478,7 @@ static bool hyundai_canfd_tx_hook(const CANPacket_t *msg) {
|
|||||||
if (hyundai_kona_idle_handoff && (msg->addr == 0x12AU)) {
|
if (hyundai_kona_idle_handoff && (msg->addr == 0x12AU)) {
|
||||||
const uint32_t now = microsecond_timer_get();
|
const uint32_t now = microsecond_timer_get();
|
||||||
allowed = hyundai_kona_emitting && !safety_rx_checks_invalid && aol_rx_healthy() && hyundai_kona_host_steering() &&
|
allowed = hyundai_kona_emitting && !safety_rx_checks_invalid && aol_rx_healthy() && hyundai_kona_host_steering() &&
|
||||||
hyundai_kona_lfa_valid(msg) && hyundai_kona_camera_seen &&
|
msg->fd && hyundai_kona_lfa_valid(msg) && hyundai_kona_camera_seen &&
|
||||||
(safety_get_ts_elapsed(now, hyundai_kona_camera_ts) <= 50000U) &&
|
(safety_get_ts_elapsed(now, hyundai_kona_camera_ts) <= 50000U) &&
|
||||||
(msg->data[2] == hyundai_kona_camera_counter) && hyundai_kona_output_ready(now, true, msg->data[2]);
|
(msg->data[2] == hyundai_kona_camera_counter) && hyundai_kona_output_ready(now, true, msg->data[2]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#define HYUNDAI_NON_SCC_HEV_AOL_LDA 0x1C02U
|
#define HYUNDAI_NON_SCC_HEV_AOL_LDA 0x1C02U
|
||||||
#define HYUNDAI_NON_SCC_EV_ALT_AOL_MAIN 0x1441U
|
#define HYUNDAI_NON_SCC_EV_ALT_AOL_MAIN 0x1441U
|
||||||
#define HYUNDAI_NON_SCC_EV_ALT_AOL_LDA 0x1C41U
|
#define HYUNDAI_NON_SCC_EV_ALT_AOL_LDA 0x1C41U
|
||||||
|
#define HYUNDAI_KONA_EV_LABEL_CRUISE_AOL 0x1C51U
|
||||||
#define HYUNDAI_CLASSIC_SOURCE_MAX_AGE_US 300000U
|
#define HYUNDAI_CLASSIC_SOURCE_MAX_AGE_US 300000U
|
||||||
|
|
||||||
static bool classic_scc_aol_enabled = false;
|
static bool classic_scc_aol_enabled = false;
|
||||||
@@ -41,6 +42,15 @@ static bool classic_scc_aol_param(uint16_t param) {
|
|||||||
((param & 3U) != 3U) && ((param & 0x0240U) != 0x0240U));
|
((param & 3U) != 3U) && ((param & 0x0240U) != 0x0240U));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool hyundai_kona_ev_label_cruise = false;
|
||||||
|
static bool hyundai_kona_ev_label_seen = false;
|
||||||
|
static uint32_t hyundai_kona_ev_label_ts = 0U;
|
||||||
|
|
||||||
|
static bool hyundai_kona_ev_label_fresh(void) {
|
||||||
|
return hyundai_kona_ev_label_seen &&
|
||||||
|
(safety_get_ts_elapsed(microsecond_timer_get(), hyundai_kona_ev_label_ts) <= HYUNDAI_CLASSIC_SOURCE_MAX_AGE_US);
|
||||||
|
}
|
||||||
|
|
||||||
static bool classic_non_scc_aol_enabled = false;
|
static bool classic_non_scc_aol_enabled = false;
|
||||||
static bool classic_non_scc_aol_ev = false;
|
static bool classic_non_scc_aol_ev = false;
|
||||||
static bool classic_non_scc_aol_hev = false;
|
static bool classic_non_scc_aol_hev = false;
|
||||||
@@ -83,6 +93,8 @@ static void classic_non_scc_aol_clear_authorization(void) {
|
|||||||
|
|
||||||
static void classic_non_scc_aol_reset(void) {
|
static void classic_non_scc_aol_reset(void) {
|
||||||
classic_non_scc_aol_clear_authorization();
|
classic_non_scc_aol_clear_authorization();
|
||||||
|
hyundai_kona_ev_label_cruise = false;
|
||||||
|
hyundai_kona_ev_label_seen = false;
|
||||||
classic_non_scc_aol_enabled = false;
|
classic_non_scc_aol_enabled = false;
|
||||||
classic_scc_aol_enabled = false;
|
classic_scc_aol_enabled = false;
|
||||||
classic_scc_aol_camera = false;
|
classic_scc_aol_camera = false;
|
||||||
@@ -113,6 +125,7 @@ static uint8_t classic_non_scc_aol_request_mask(void) {
|
|||||||
const bool token_expired = classic_non_scc_aol_token && !classic_non_scc_aol_claimed &&
|
const bool token_expired = classic_non_scc_aol_token && !classic_non_scc_aol_claimed &&
|
||||||
(safety_get_ts_elapsed(now, classic_non_scc_aol_token_ts) > AOL_HOST_REQUEST_TIMEOUT_US);
|
(safety_get_ts_elapsed(now, classic_non_scc_aol_token_ts) > AOL_HOST_REQUEST_TIMEOUT_US);
|
||||||
if (relay_malfunction || safety_rx_checks_invalid || expired || token_expired ||
|
if (relay_malfunction || safety_rx_checks_invalid || expired || token_expired ||
|
||||||
|
(hyundai_kona_ev_label_cruise && !hyundai_kona_ev_label_fresh()) ||
|
||||||
(classic_non_scc_aol_session && !heartbeat_engaged)) {
|
(classic_non_scc_aol_session && !heartbeat_engaged)) {
|
||||||
classic_non_scc_aol_clear_authorization();
|
classic_non_scc_aol_clear_authorization();
|
||||||
} else if (heartbeat_engaged) {
|
} else if (heartbeat_engaged) {
|
||||||
@@ -257,12 +270,14 @@ static void classic_non_scc_aol_configure(uint16_t param, bool legacy) {
|
|||||||
classic_non_scc_aol_enabled = ((!legacy && ((param == HYUNDAI_FORTE_AOL_MAIN) || (param == HYUNDAI_FORTE_AOL_LDA) ||
|
classic_non_scc_aol_enabled = ((!legacy && ((param == HYUNDAI_FORTE_AOL_MAIN) || (param == HYUNDAI_FORTE_AOL_LDA) ||
|
||||||
(param == HYUNDAI_KONA_AOL_MAIN) || (param == HYUNDAI_KONA_AOL_LDA) ||
|
(param == HYUNDAI_KONA_AOL_MAIN) || (param == HYUNDAI_KONA_AOL_LDA) ||
|
||||||
(param == HYUNDAI_NON_SCC_HEV_AOL_MAIN) || (param == HYUNDAI_NON_SCC_HEV_AOL_LDA) ||
|
(param == HYUNDAI_NON_SCC_HEV_AOL_MAIN) || (param == HYUNDAI_NON_SCC_HEV_AOL_LDA) ||
|
||||||
(param == HYUNDAI_NON_SCC_EV_ALT_AOL_MAIN) || (param == HYUNDAI_NON_SCC_EV_ALT_AOL_LDA))) || classic_scc_aol_enabled || classic_long_aol_enabled) &&
|
(param == HYUNDAI_NON_SCC_EV_ALT_AOL_MAIN) || (param == HYUNDAI_NON_SCC_EV_ALT_AOL_LDA) ||
|
||||||
|
(param == HYUNDAI_KONA_EV_LABEL_CRUISE_AOL))) || classic_scc_aol_enabled || classic_long_aol_enabled) &&
|
||||||
((unsigned int)alternative_experience == 32U);
|
((unsigned int)alternative_experience == 32U);
|
||||||
classic_non_scc_aol_lda = classic_non_scc_aol_enabled && (((classic_scc_aol_enabled || classic_long_aol_enabled) && ((param & 0x0800U) != 0U)) || (param == HYUNDAI_FORTE_AOL_LDA) || (param == HYUNDAI_KONA_AOL_LDA) ||
|
classic_non_scc_aol_lda = classic_non_scc_aol_enabled && (((classic_scc_aol_enabled || classic_long_aol_enabled) && ((param & 0x0800U) != 0U)) || (param == HYUNDAI_FORTE_AOL_LDA) || (param == HYUNDAI_KONA_AOL_LDA) ||
|
||||||
(param == HYUNDAI_NON_SCC_HEV_AOL_LDA) ||
|
(param == HYUNDAI_NON_SCC_HEV_AOL_LDA) ||
|
||||||
(param == HYUNDAI_NON_SCC_EV_ALT_AOL_LDA));
|
(param == HYUNDAI_NON_SCC_EV_ALT_AOL_LDA) || (param == HYUNDAI_KONA_EV_LABEL_CRUISE_AOL));
|
||||||
classic_non_scc_aol_ev = classic_non_scc_aol_enabled && ((param == HYUNDAI_NON_SCC_EV_ALT_AOL_MAIN) || (param == HYUNDAI_NON_SCC_EV_ALT_AOL_LDA));
|
classic_non_scc_aol_ev = classic_non_scc_aol_enabled && ((param == HYUNDAI_NON_SCC_EV_ALT_AOL_MAIN) || (param == HYUNDAI_NON_SCC_EV_ALT_AOL_LDA) ||
|
||||||
|
(param == HYUNDAI_KONA_EV_LABEL_CRUISE_AOL));
|
||||||
classic_non_scc_aol_hev = classic_non_scc_aol_enabled && ((param == HYUNDAI_NON_SCC_HEV_AOL_MAIN) || (param == HYUNDAI_NON_SCC_HEV_AOL_LDA));
|
classic_non_scc_aol_hev = classic_non_scc_aol_enabled && ((param == HYUNDAI_NON_SCC_HEV_AOL_MAIN) || (param == HYUNDAI_NON_SCC_HEV_AOL_LDA));
|
||||||
if (classic_non_scc_aol_enabled) {
|
if (classic_non_scc_aol_enabled) {
|
||||||
static const AolSafetyPolicy policy = {
|
static const AolSafetyPolicy policy = {
|
||||||
|
|||||||
@@ -0,0 +1,239 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "opendbc/safety/declarations.h"
|
||||||
|
|
||||||
|
// Leapmotor B10 (2025, global market). The front camera's ADAS_LKA (0x83) carries the LCC steering angle request;
|
||||||
|
// openpilot replaces it through a camera harness. Stock ACC stays in control of longitudinal, unless the longitudinal
|
||||||
|
// flag is set: then openpilot may also replace ADAS_LKA.ACC_ACCEL_REQ while stock ACC stays engaged.
|
||||||
|
|
||||||
|
#define LEAPMOTOR_ADAS_LKA 0x83U // TX from openpilot (stock: front camera), steering angle request
|
||||||
|
#define LEAPMOTOR_VEHICLE_STATE 0xB6U // RX from VCU, accelerator pedal, brake pressed, gear
|
||||||
|
#define LEAPMOTOR_POWERTRAIN_STATE 0xB7U // RX from VCU, stock ACC/LCC engaged; TX to camera: stalk-up cancel only
|
||||||
|
#define LEAPMOTOR_WHEEL_SPEEDS 0x184U // RX from ESC, wheel speeds
|
||||||
|
#define LEAPMOTOR_EPS_STEERING 0x18DU // RX from EPS, steering angle
|
||||||
|
|
||||||
|
#define LEAPMOTOR_MAIN_BUS 0U
|
||||||
|
#define LEAPMOTOR_CAM_BUS 2U
|
||||||
|
|
||||||
|
// Steering angle is 0.02 deg per bit with the center at raw 32490. Raw rises to the right, so the angle is
|
||||||
|
// negated to match openpilot's convention (positive = left)
|
||||||
|
#define LEAPMOTOR_ANGLE_CENTER 32490
|
||||||
|
|
||||||
|
// ADAS_LKA.LCC_RAMP (bytes 16-17, little-endian) sets how much effort the EPS may put into following the angle: idle
|
||||||
|
// 0x7801, 254 lower per step deeper. Stock LCC goes no deeper than 46 steps (0x4A5D), and neither may openpilot.
|
||||||
|
// Must match leapmotorcan.LCC_RAMP_IDLE and LCC_RAMP_STEPS_MAX.
|
||||||
|
#define LEAPMOTOR_LCC_RAMP_IDLE 0x7801
|
||||||
|
#define LEAPMOTOR_LCC_RAMP_DEEPEST 0x4A5D
|
||||||
|
|
||||||
|
// ADAS_LKA.ACC_ACCEL_REQ: byte 4, 0.05 m/s^2 per bit, raw 100 = 0 m/s^2. Must match CarControllerParams.
|
||||||
|
#define LEAPMOTOR_ACCEL_INACTIVE 100
|
||||||
|
// The camera's request at or below this (-2.0 m/s^2) is passed on: openpilot may ask for more braking, not less
|
||||||
|
#define LEAPMOTOR_ACCEL_STOCK_BRAKE 60
|
||||||
|
#define LEAPMOTOR_FLAG_LONGITUDINAL_CONTROL 1U
|
||||||
|
// openpilot builds its frame from a camera frame that can be older than the latest one the panda has seen: on 6 log
|
||||||
|
// segments by 0 (88%), 1 (10%), 2 to 6 frames (0.4%). So the camera's last 8 requests (160 ms at 50 Hz) count.
|
||||||
|
#define LEAPMOTOR_CAMERA_ACCEL_HISTORY 8U
|
||||||
|
|
||||||
|
static bool leapmotor_longitudinal = false;
|
||||||
|
static int leapmotor_camera_accel[LEAPMOTOR_CAMERA_ACCEL_HISTORY]; // the camera's ADAS_LKA.ACC_ACCEL_REQ, raw
|
||||||
|
static uint8_t leapmotor_camera_accel_idx = 0U;
|
||||||
|
|
||||||
|
static void leapmotor_reset_camera_accel(void) {
|
||||||
|
for (uint8_t i = 0U; i < LEAPMOTOR_CAMERA_ACCEL_HISTORY; i++) {
|
||||||
|
leapmotor_camera_accel[i] = LEAPMOTOR_ACCEL_INACTIVE;
|
||||||
|
}
|
||||||
|
leapmotor_camera_accel_idx = 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
// was this request among the camera's recent ones?
|
||||||
|
static bool leapmotor_is_camera_accel(int accel) {
|
||||||
|
bool found = false;
|
||||||
|
for (uint8_t i = 0U; i < LEAPMOTOR_CAMERA_ACCEL_HISTORY; i++) {
|
||||||
|
found = found || (leapmotor_camera_accel[i] == accel);
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the least braking (highest raw) among the camera's recent requests
|
||||||
|
static int leapmotor_camera_accel_max(void) {
|
||||||
|
int max_accel = leapmotor_camera_accel[0];
|
||||||
|
for (uint8_t i = 1U; i < LEAPMOTOR_CAMERA_ACCEL_HISTORY; i++) {
|
||||||
|
max_accel = SAFETY_MAX(max_accel, leapmotor_camera_accel[i]);
|
||||||
|
}
|
||||||
|
return max_accel;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint32_t addr;
|
||||||
|
uint8_t constants[16];
|
||||||
|
} LeapmotorE2EConstants;
|
||||||
|
|
||||||
|
static uint32_t leapmotor_get_checksum(const CANPacket_t *msg) {
|
||||||
|
return (uint8_t)msg->data[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t leapmotor_get_counter(const CANPacket_t *msg) {
|
||||||
|
return (uint8_t)msg->data[1] & 0xFU;
|
||||||
|
}
|
||||||
|
|
||||||
|
// AUTOSAR E2E Profile 2, as volkswagen_mqb_meb_compute_crc: CRC-8H2F over bytes 1..end, then a
|
||||||
|
// per-message constant chosen by the counter. Constants learned from logs; exact on held-out routes.
|
||||||
|
#define LEAPMOTOR_E2E_COUNT 5U
|
||||||
|
|
||||||
|
static uint32_t leapmotor_compute_checksum(const CANPacket_t *msg) {
|
||||||
|
static const LeapmotorE2EConstants E2E[LEAPMOTOR_E2E_COUNT] = {
|
||||||
|
{LEAPMOTOR_WHEEL_SPEEDS, {0xD9U, 0x90U, 0x33U, 0xE1U, 0x3AU, 0x1AU, 0xDFU, 0xC6U, 0xB5U, 0xDCU, 0xEEU, 0x04U, 0xFAU, 0xD7U, 0xD4U, 0x99U}},
|
||||||
|
{LEAPMOTOR_EPS_STEERING, {0x61U, 0x4BU, 0x17U, 0xE4U, 0x78U, 0x0BU, 0xA1U, 0xB4U, 0xBCU, 0xD8U, 0xEAU, 0xF5U, 0xD9U, 0x21U, 0xCAU, 0x86U}},
|
||||||
|
{LEAPMOTOR_VEHICLE_STATE, {0x71U, 0x0DU, 0x0BU, 0xC2U, 0x08U, 0xC6U, 0x63U, 0x4BU, 0x3FU, 0x2BU, 0x06U, 0x10U, 0xF0U, 0xD2U, 0x87U, 0x0DU}},
|
||||||
|
{LEAPMOTOR_POWERTRAIN_STATE, {0xEBU, 0x4EU, 0xAEU, 0xCEU, 0x79U, 0x7CU, 0x52U, 0x03U, 0x6AU, 0x84U, 0xC2U, 0x3AU, 0x0AU, 0x64U, 0x2FU, 0x17U}},
|
||||||
|
{LEAPMOTOR_ADAS_LKA, {0xCDU, 0x81U, 0x0AU, 0xC1U, 0x99U, 0x7FU, 0x8DU, 0x05U, 0x3BU, 0xA2U, 0x43U, 0xD2U, 0xB6U, 0x72U, 0x2AU, 0xD9U}},
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t constant = 0U;
|
||||||
|
for (uint8_t i = 0U; i < LEAPMOTOR_E2E_COUNT; i++) {
|
||||||
|
constant = (E2E[i].addr == msg->addr) ? E2E[i].constants[leapmotor_get_counter(msg)] : constant;
|
||||||
|
}
|
||||||
|
|
||||||
|
int len = GET_LEN(msg);
|
||||||
|
uint8_t crc = 0xFFU;
|
||||||
|
for (int i = 1; i < len; i++) {
|
||||||
|
crc = crc8_update(crc, (uint8_t)msg->data[i], 0x2FU);
|
||||||
|
}
|
||||||
|
crc = crc8_update(crc, constant, 0x2FU);
|
||||||
|
return (uint8_t)(crc ^ 0xFFU);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void leapmotor_rx_hook(const CANPacket_t *msg) {
|
||||||
|
if (msg->bus == LEAPMOTOR_MAIN_BUS) {
|
||||||
|
if (msg->addr == LEAPMOTOR_WHEEL_SPEEDS) {
|
||||||
|
// four 16-bit little-endian wheel speeds at 0.01 km/h: FL, FR, RL, RR
|
||||||
|
uint32_t sum = GET_BYTES_LE(msg, 2, 2) + GET_BYTES_LE(msg, 4, 2) + GET_BYTES_LE(msg, 6, 2) + GET_BYTES_LE(msg, 8, 2);
|
||||||
|
vehicle_moving = sum > 0U;
|
||||||
|
UPDATE_VEHICLE_SPEED((sum / 4.0) * 0.01 * KPH_TO_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->addr == LEAPMOTOR_EPS_STEERING) {
|
||||||
|
int angle_meas_new = LEAPMOTOR_ANGLE_CENTER - (int)GET_BYTES_LE(msg, 3, 2);
|
||||||
|
update_sample(&angle_meas, angle_meas_new);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->addr == LEAPMOTOR_VEHICLE_STATE) {
|
||||||
|
gas_pressed = msg->data[11] > 0U; // ACCEL_PEDAL
|
||||||
|
brake_pressed = GET_BIT(msg, 99U); // BRAKE_PRESSED
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->addr == LEAPMOTOR_POWERTRAIN_STATE) {
|
||||||
|
pcm_cruise_check(GET_BIT(msg, 30U)); // ASSIST_ENGAGED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// only in rx_checks with the longitudinal flag
|
||||||
|
// only rx-checked frames reach this hook, and on the camera bus that is only ADAS_LKA (with the longitudinal flag)
|
||||||
|
if (msg->bus == LEAPMOTOR_CAM_BUS) {
|
||||||
|
leapmotor_camera_accel[leapmotor_camera_accel_idx] = msg->data[4]; // ACC_ACCEL_REQ
|
||||||
|
leapmotor_camera_accel_idx++;
|
||||||
|
if (leapmotor_camera_accel_idx >= LEAPMOTOR_CAMERA_ACCEL_HISTORY) {
|
||||||
|
leapmotor_camera_accel_idx = 0U;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool leapmotor_tx_hook(const CANPacket_t *msg) {
|
||||||
|
// Must match LEAPMOTOR_B10 CarControllerParams.ANGLE_LIMITS: lateral accel and jerk limited through a vehicle model
|
||||||
|
static const AngleSteeringLimits LEAPMOTOR_STEERING_LIMITS = {
|
||||||
|
.max_angle = 25000, // 500 deg at 50 per deg; mechanical lock is about 522 deg
|
||||||
|
.angle_deg_to_can = 50,
|
||||||
|
.frequency = 50U,
|
||||||
|
};
|
||||||
|
|
||||||
|
static const AngleSteeringParams LEAPMOTOR_STEERING_PARAMS = {
|
||||||
|
.slip_factor = -0.0006132659333604452, // calc_slip_factor(VM) for LEAPMOTOR_B10
|
||||||
|
.steer_ratio = 15.2,
|
||||||
|
.wheelbase = 2.735,
|
||||||
|
};
|
||||||
|
|
||||||
|
bool tx = true;
|
||||||
|
|
||||||
|
// Only a cancel may be sent to the camera: STALK_PUSH (bits 40-41) must be 3, stalk pushed up
|
||||||
|
if (msg->addr == LEAPMOTOR_POWERTRAIN_STATE) {
|
||||||
|
if (((msg->data[5]) & 0x3U) != 3U) {
|
||||||
|
tx = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg->addr == LEAPMOTOR_ADAS_LKA) {
|
||||||
|
int desired_angle = LEAPMOTOR_ANGLE_CENTER - (int)GET_BYTES_LE(msg, 13, 2); // STEER_ANGLE_REQ
|
||||||
|
bool lka_active = GET_BIT(msg, 99U); // LCC_STEERING_ACTIVE_COPY
|
||||||
|
if (steer_angle_cmd_checks_vm(desired_angle, lka_active, LEAPMOTOR_STEERING_LIMITS, LEAPMOTOR_STEERING_PARAMS)) {
|
||||||
|
tx = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// while openpilot steers, the EPS effort may go no deeper than the boost's maximum. Otherwise the field carries the
|
||||||
|
// camera's own value, which is not a ramp depth (LCC state bits), and is passed on.
|
||||||
|
int lcc_ramp = (int)GET_BYTES_LE(msg, 16, 2); // LCC_RAMP
|
||||||
|
if (lka_active && ((lcc_ramp < LEAPMOTOR_LCC_RAMP_DEEPEST) || (lcc_ramp > LEAPMOTOR_LCC_RAMP_IDLE))) {
|
||||||
|
tx = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (leapmotor_longitudinal) {
|
||||||
|
int accel = msg->data[4]; // ACC_ACCEL_REQ
|
||||||
|
// The camera's own request may always be passed on: that is what the stock ACC sends when openpilot is not in
|
||||||
|
// control. openpilot's own request must be within -3.5..2.0 m/s^2 (raw 30..140) with controls allowed. Not also
|
||||||
|
// with the accelerator released, as longitudinal_accel_checks() wants: the panda sees a press one frame before
|
||||||
|
// openpilot can hand back to the stock ACC, and a blocked ADAS_LKA cancels the stock ACC. The car follows the
|
||||||
|
// pedal over any ACC request anyway, as with the camera's own requests, which it keeps sending for a few frames.
|
||||||
|
bool own_accel_ok = controls_allowed && !safety_max_limit_check(accel, 140, 30);
|
||||||
|
bool inactive = accel == LEAPMOTOR_ACCEL_INACTIVE;
|
||||||
|
if (!leapmotor_is_camera_accel(accel) && !own_accel_ok && !inactive) {
|
||||||
|
tx = false;
|
||||||
|
}
|
||||||
|
// never less braking than the camera asks for while all its recent requests are hard braking
|
||||||
|
int camera_floor = leapmotor_camera_accel_max();
|
||||||
|
if ((camera_floor <= LEAPMOTOR_ACCEL_STOCK_BRAKE) && (accel > camera_floor)) {
|
||||||
|
tx = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tx;
|
||||||
|
}
|
||||||
|
|
||||||
|
static safety_config leapmotor_init(uint16_t param) {
|
||||||
|
leapmotor_longitudinal = GET_FLAG(param, LEAPMOTOR_FLAG_LONGITUDINAL_CONTROL);
|
||||||
|
leapmotor_reset_camera_accel();
|
||||||
|
|
||||||
|
static const CanMsg LEAPMOTOR_TX_MSGS[] = {
|
||||||
|
{LEAPMOTOR_ADAS_LKA, LEAPMOTOR_MAIN_BUS, 32, .check_relay = true},
|
||||||
|
{LEAPMOTOR_POWERTRAIN_STATE, LEAPMOTOR_CAM_BUS, 32, .check_relay = false},
|
||||||
|
};
|
||||||
|
|
||||||
|
safety_config ret;
|
||||||
|
if (leapmotor_longitudinal) {
|
||||||
|
// with openpilot longitudinal, the camera's own ADAS_LKA is also checked: its acceleration request is passed on
|
||||||
|
static const RxCheck leapmotor_long_rx_checks[] = {
|
||||||
|
{.msg = {{LEAPMOTOR_WHEEL_SPEEDS, LEAPMOTOR_MAIN_BUS, 32, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
{.msg = {{LEAPMOTOR_EPS_STEERING, LEAPMOTOR_MAIN_BUS, 32, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
{.msg = {{LEAPMOTOR_VEHICLE_STATE, LEAPMOTOR_MAIN_BUS, 16, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
{.msg = {{LEAPMOTOR_POWERTRAIN_STATE, LEAPMOTOR_MAIN_BUS, 32, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
{.msg = {{LEAPMOTOR_ADAS_LKA, LEAPMOTOR_CAM_BUS, 32, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
};
|
||||||
|
ret = BUILD_SAFETY_CFG(leapmotor_long_rx_checks, LEAPMOTOR_TX_MSGS);
|
||||||
|
} else {
|
||||||
|
static const RxCheck leapmotor_rx_checks[] = {
|
||||||
|
{.msg = {{LEAPMOTOR_WHEEL_SPEEDS, LEAPMOTOR_MAIN_BUS, 32, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
{.msg = {{LEAPMOTOR_EPS_STEERING, LEAPMOTOR_MAIN_BUS, 32, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
{.msg = {{LEAPMOTOR_VEHICLE_STATE, LEAPMOTOR_MAIN_BUS, 16, 100U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
{.msg = {{LEAPMOTOR_POWERTRAIN_STATE, LEAPMOTOR_MAIN_BUS, 32, 50U, .max_counter = 15U, .ignore_quality_flag = true}, { 0 }, { 0 }}},
|
||||||
|
};
|
||||||
|
ret = BUILD_SAFETY_CFG(leapmotor_rx_checks, LEAPMOTOR_TX_MSGS);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
const safety_hooks leapmotor_hooks = {
|
||||||
|
.init = leapmotor_init,
|
||||||
|
.rx = leapmotor_rx_hook,
|
||||||
|
.tx = leapmotor_tx_hook,
|
||||||
|
.get_counter = leapmotor_get_counter,
|
||||||
|
.get_checksum = leapmotor_get_checksum,
|
||||||
|
.compute_checksum = leapmotor_compute_checksum,
|
||||||
|
};
|
||||||
@@ -33,6 +33,7 @@
|
|||||||
#include "opendbc/safety/modes/body.h"
|
#include "opendbc/safety/modes/body.h"
|
||||||
#include "opendbc/safety/modes/psa.h"
|
#include "opendbc/safety/modes/psa.h"
|
||||||
#include "opendbc/safety/modes/byd.h"
|
#include "opendbc/safety/modes/byd.h"
|
||||||
|
#include "opendbc/safety/modes/leapmotor.h"
|
||||||
#include "opendbc/safety/modes/hyundai_canfd.h"
|
#include "opendbc/safety/modes/hyundai_canfd.h"
|
||||||
|
|
||||||
uint32_t GET_BYTES_LE(const CANPacket_t *msg, int start, int len) {
|
uint32_t GET_BYTES_LE(const CANPacket_t *msg, int start, int len) {
|
||||||
@@ -519,6 +520,7 @@ int set_safety_hooks(uint16_t mode, uint16_t param) {
|
|||||||
{SAFETY_CHRYSLER_CUSW, &chrysler_cusw_hooks},
|
{SAFETY_CHRYSLER_CUSW, &chrysler_cusw_hooks},
|
||||||
{SAFETY_PSA, &psa_hooks},
|
{SAFETY_PSA, &psa_hooks},
|
||||||
{SAFETY_BYD, &byd_hooks},
|
{SAFETY_BYD, &byd_hooks},
|
||||||
|
{SAFETY_LEAPMOTOR, &leapmotor_hooks},
|
||||||
{SAFETY_VOLKSWAGEN_MLB, &volkswagen_mlb_hooks},
|
{SAFETY_VOLKSWAGEN_MLB, &volkswagen_mlb_hooks},
|
||||||
{SAFETY_VOLKSWAGEN_PQ, &volkswagen_pq_hooks},
|
{SAFETY_VOLKSWAGEN_PQ, &volkswagen_pq_hooks},
|
||||||
{SAFETY_ALLOUTPUT, &alloutput_hooks},
|
{SAFETY_ALLOUTPUT, &alloutput_hooks},
|
||||||
|
|||||||
@@ -1010,6 +1010,10 @@ class SafetyTest(SafetyTestBase):
|
|||||||
if attr == 'TestVolkswagenMqbLongSafety' and current_test.startswith('TestHondaBoschRadarless'):
|
if attr == 'TestVolkswagenMqbLongSafety' and current_test.startswith('TestHondaBoschRadarless'):
|
||||||
tx = list(filter(lambda m: m[0] not in [0x30c, ], tx))
|
tx = list(filter(lambda m: m[0] not in [0x30c, ], tx))
|
||||||
|
|
||||||
|
# Leapmotor's steering angle request overlaps Ford's Steering_Data_FD1 (buttons, not actuating)
|
||||||
|
if attr.startswith('TestLeapmotor') and current_test.startswith('TestFord'):
|
||||||
|
tx = list(filter(lambda m: m[0] not in [0x83, ], tx))
|
||||||
|
|
||||||
# TODO: Temporary, should be fixed in panda firmware, safety_honda.h
|
# TODO: Temporary, should be fixed in panda firmware, safety_honda.h
|
||||||
if attr.startswith('TestHonda'):
|
if attr.startswith('TestHonda'):
|
||||||
# exceptions for common msgs across different hondas
|
# exceptions for common msgs across different hondas
|
||||||
|
|||||||
@@ -265,3 +265,51 @@ class TestHyundaiBlendedStock(unittest.TestCase):
|
|||||||
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), 0)
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), 0)
|
||||||
self.safety.set_relay_malfunction(True)
|
self.safety.set_relay_malfunction(True)
|
||||||
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), -1)
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), -1)
|
||||||
|
|
||||||
|
def test_hda2_stock_engagement_retains_lateral_only_through_cancel_and_brake(self):
|
||||||
|
for disarm in ('main', 'main_and_cancel', 'lease', 'relay', 'native_rx'):
|
||||||
|
with self.subTest(disarm=disarm):
|
||||||
|
self._start_hda2_aol()
|
||||||
|
self.safety.aol_set_host_request(3)
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
||||||
|
def button(value):
|
||||||
|
return common.make_msg(1, 0x4F1, dat=bytes([value, 0, 0, 0]))
|
||||||
|
|
||||||
|
def scc(counter, main, active):
|
||||||
|
dat = bytearray(8)
|
||||||
|
dat[1], dat[3] = counter << 4, (int(main) << 3) | (int(active) << 4)
|
||||||
|
return common.make_msg(1, 0x421, dat=bytes(dat))
|
||||||
|
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(button(4)))
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(button(2)))
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(scc(0, True, True)))
|
||||||
|
self.safety.aol_set_host_request(3)
|
||||||
|
self.assertTrue(self.safety.get_controls_allowed())
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 1)
|
||||||
|
self.assertTrue(self.safety.safety_tx_hook(self.steer(3)))
|
||||||
|
|
||||||
|
self._refresh_hda2_aol_rx(1_010_000)
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(button(4)))
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(scc(1, True, False)))
|
||||||
|
self.assertFalse(self.safety.get_controls_allowed())
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 1)
|
||||||
|
self.assertTrue(self.safety.safety_tx_hook(self.steer(3)))
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(common.make_msg(1, 0x421)))
|
||||||
|
brake = common.make_msg(1, 0x394, dat=bytes.fromhex('036c000003449798'))
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(brake))
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 1)
|
||||||
|
|
||||||
|
if disarm == 'main':
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(scc(2, False, False)))
|
||||||
|
elif disarm == 'main_and_cancel':
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(button(12)))
|
||||||
|
elif disarm == 'lease':
|
||||||
|
self._refresh_hda2_aol_rx(1_400_000)
|
||||||
|
elif disarm == 'relay':
|
||||||
|
self.safety.set_relay_malfunction(True)
|
||||||
|
else:
|
||||||
|
self.safety.set_timer(2_000_000)
|
||||||
|
self.safety.safety_tick()
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(self.steer(3)))
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class TestHyundaiKonaCcncHandoff(unittest.TestCase):
|
|||||||
|
|
||||||
def packet(self, bus, body):
|
def packet(self, bus, body):
|
||||||
packet = libsafety_py.make_CANPacket(0x12A, bus, bytes.fromhex(body))
|
packet = libsafety_py.make_CANPacket(0x12A, bus, bytes.fromhex(body))
|
||||||
packet[0].fd = 1
|
packet[0].fd = bus == 2
|
||||||
return packet
|
return packet
|
||||||
|
|
||||||
def test_handoff_is_debug_only_and_requires_exact_alternative_experience(self):
|
def test_handoff_is_debug_only_and_requires_exact_alternative_experience(self):
|
||||||
@@ -71,6 +71,9 @@ class TestHyundaiKonaCcncHandoff(unittest.TestCase):
|
|||||||
status.valid_quality_flag = True
|
status.valid_quality_flag = True
|
||||||
status.last_timestamp = 1_000_000
|
status.last_timestamp = 1_000_000
|
||||||
|
|
||||||
|
camera[0].fd = 0
|
||||||
|
self.assertEqual(self.forward(camera)[0], -1)
|
||||||
|
camera[0].fd = 1
|
||||||
self.assertEqual(self.forward(camera)[:2], (0, False))
|
self.assertEqual(self.forward(camera)[:2], (0, False))
|
||||||
self.assertEqual(self.forward(camera)[0], -1)
|
self.assertEqual(self.forward(camera)[0], -1)
|
||||||
corrupt = self.packet(2, 'a6770a1881001800000a000000900000')
|
corrupt = self.packet(2, 'a6770a1881001800000a000000900000')
|
||||||
@@ -88,11 +91,15 @@ class TestHyundaiKonaCcncHandoff(unittest.TestCase):
|
|||||||
host[0].data[0], host[0].data[1] = crc & 255, crc >> 8
|
host[0].data[0], host[0].data[1] = crc & 255, crc >> 8
|
||||||
self.safety.set_timer(1_005_000)
|
self.safety.set_timer(1_005_000)
|
||||||
self.assertFalse(self.safety.safety_tx_hook(host))
|
self.assertFalse(self.safety.safety_tx_hook(host))
|
||||||
|
host[0].data[0] ^= 1
|
||||||
|
self.assertFalse(self.safety.safety_stage_tx_hook(host))
|
||||||
|
host[0].data[0] ^= 1
|
||||||
self.assertTrue(self.safety.safety_stage_tx_hook(host))
|
self.assertTrue(self.safety.safety_stage_tx_hook(host))
|
||||||
self.safety.set_timer(1_010_000)
|
self.safety.set_timer(1_010_000)
|
||||||
match = self.packet(2, '5ce51500000108f0000a000000640000')
|
match = self.packet(2, '5ce51500000108f0000a000000640000')
|
||||||
bus, replaced, output = self.forward(match)
|
bus, replaced, output = self.forward(match)
|
||||||
self.assertEqual((bus, replaced, output[0].data[2]), (0, True, 21))
|
self.assertEqual((bus, replaced, output[0].data[2]), (0, True, 21))
|
||||||
|
self.assertTrue(output[0].fd)
|
||||||
self.assertEqual(output[0].data[7] & 0xF0, 0xF0)
|
self.assertEqual(output[0].data[7] & 0xF0, 0xF0)
|
||||||
|
|
||||||
self.safety.set_controls_allowed(False)
|
self.safety.set_controls_allowed(False)
|
||||||
@@ -106,3 +113,38 @@ class TestHyundaiKonaCcncHandoff(unittest.TestCase):
|
|||||||
self.safety.set_relay_malfunction(True)
|
self.safety.set_relay_malfunction(True)
|
||||||
self.assertEqual(self.forward(following)[0], -1)
|
self.assertEqual(self.forward(following)[0], -1)
|
||||||
self.assertFalse(self.safety.safety_stage_tx_hook(host))
|
self.assertFalse(self.safety.safety_stage_tx_hook(host))
|
||||||
|
|
||||||
|
def test_empty_owned_slot_uses_neutral_camera_status(self):
|
||||||
|
if self.safety.set_safety_hooks(structs.CarParams.SafetyModel.allOutput, 0) != 0:
|
||||||
|
self.skipTest('Kona factory handoff is DEBUG only')
|
||||||
|
self.mode(0x1C0C)
|
||||||
|
self.safety.set_timer(1_000_000)
|
||||||
|
for status in self.safety.rx_status:
|
||||||
|
status.msg_seen = True
|
||||||
|
status.valid_checksum = True
|
||||||
|
status.valid_quality_flag = True
|
||||||
|
status.last_timestamp = 1_000_000
|
||||||
|
self.assertEqual(self.forward(self.packet(2, '784d1400000108f0000a000000640000'))[:2], (0, False))
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self.safety.set_aol_test_heartbeat(True)
|
||||||
|
self.safety.aol_set_host_request(3)
|
||||||
|
host = self.packet(0, 'a009150280001800000a000000900000')
|
||||||
|
host[0].data[2] = 20
|
||||||
|
from opendbc.car.hyundai.hyundaicanfd import hkg_can_fd_checksum
|
||||||
|
crc = hkg_can_fd_checksum(0x12A, None, bytearray(host[0].data[0:16]))
|
||||||
|
host[0].data[0], host[0].data[1] = crc & 255, crc >> 8
|
||||||
|
self.safety.set_timer(1_005_000)
|
||||||
|
self.assertTrue(self.safety.safety_stage_tx_hook(host))
|
||||||
|
self.safety.set_timer(1_010_000)
|
||||||
|
self.assertEqual(self.forward(self.packet(2, '5ce51500000108f0000a000000640000'))[:2], (0, True))
|
||||||
|
|
||||||
|
self.safety.set_timer(1_019_900)
|
||||||
|
camera = self.packet(2, '110d1600000108f0000a000000640000')
|
||||||
|
bus, replaced, output = self.forward(camera)
|
||||||
|
self.assertEqual((bus, replaced), (0, True))
|
||||||
|
self.assertTrue(output[0].fd)
|
||||||
|
self.assertEqual(output[0].data[2], 22)
|
||||||
|
self.assertEqual(output[0].data[5] & 0xFE, 0)
|
||||||
|
self.assertEqual(output[0].data[6] & 0x3F, 8)
|
||||||
|
self.assertEqual(output[0].data[7], camera[0].data[7])
|
||||||
|
self.assertEqual(self.forward(camera)[0], -1)
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
import unittest
|
||||||
|
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
from opendbc.safety.tests.common import CANPackerSafety, make_msg
|
||||||
|
from opendbc.safety.tests.libsafety import libsafety_py
|
||||||
|
from opendbc.safety.tests.test_hyundai import checksum
|
||||||
|
|
||||||
|
|
||||||
|
class TestHyundaiKonaEvLabel(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.safety = libsafety_py.libsafety
|
||||||
|
self.packer = CANPackerSafety("hyundai_can_generated")
|
||||||
|
self.addCleanup(self.safety.set_alternative_experience, 0)
|
||||||
|
|
||||||
|
def reset(self, word):
|
||||||
|
self.safety.init_tests()
|
||||||
|
self.safety.set_alternative_experience(32 if word & 0x400 else 0)
|
||||||
|
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hyundai, word), 0)
|
||||||
|
self.safety.set_aol_test_heartbeat(True)
|
||||||
|
self.safety.set_timer(1000)
|
||||||
|
self.counter = 0
|
||||||
|
|
||||||
|
def rx(self, name, values, bus=0, fix_checksum=None):
|
||||||
|
return self.safety.safety_rx_hook(self.packer.make_can_msg_safety(name, bus, values, fix_checksum=fix_checksum))
|
||||||
|
|
||||||
|
def label(self, available, engaged, bus=0):
|
||||||
|
self.assertTrue(self.rx("LABEL11", {"CC_React": available, "CC_Engaged": engaged}, bus))
|
||||||
|
|
||||||
|
def button(self, button, main=False):
|
||||||
|
self.assertTrue(self.rx("CLU11", {"CF_Clu_CruiseSwState": button, "CF_Clu_CruiseSwMain": main,
|
||||||
|
"CF_Clu_AliveCnt1": self.counter % 16}))
|
||||||
|
self.counter += 1
|
||||||
|
|
||||||
|
def brake(self, pressed, counter):
|
||||||
|
return self.rx("TCS13", {"DriverOverride": 2 if pressed else 0, "AliveCounterTCS": counter}, fix_checksum=checksum)
|
||||||
|
|
||||||
|
def feed(self, *, with_label=True):
|
||||||
|
self.assertTrue(self.rx("E_EMS11", {"Accel_Pedal_Pos": 0}))
|
||||||
|
self.assertTrue(self.rx("MDPS12", {"CR_Mdps_StrColTq": 0}))
|
||||||
|
self.assertTrue(self.rx("WHL_SPD11", {"WHL_SPD_FL": 40, "WHL_SPD_RR": 40}, fix_checksum=checksum))
|
||||||
|
self.assertTrue(self.brake(False, 0))
|
||||||
|
self.assertTrue(self.rx("BCM_PO_11", {"LDA_BTN": 0}))
|
||||||
|
self.button(0)
|
||||||
|
if with_label:
|
||||||
|
self.label(True, False)
|
||||||
|
|
||||||
|
def engage(self, button=2):
|
||||||
|
self.button(button)
|
||||||
|
self.button(0)
|
||||||
|
self.label(True, True)
|
||||||
|
self.assertTrue(self.safety.get_controls_allowed())
|
||||||
|
|
||||||
|
def tx(self, name, values, bus=0):
|
||||||
|
return self.safety.safety_tx_hook(self.packer.make_can_msg_safety(name, bus, values))
|
||||||
|
|
||||||
|
def steer(self):
|
||||||
|
return self.tx("LKAS11", {"CR_Lkas_StrToqReq": 1, "CF_Lkas_ActToi": 1})
|
||||||
|
|
||||||
|
def software_set(self):
|
||||||
|
return self.tx("CLU11", {"CF_Clu_CruiseSwState": 2})
|
||||||
|
|
||||||
|
def test_exact_variants_and_physical_button_and_brake_release(self):
|
||||||
|
for word in (0x1851, 0x1871, 0x1c51, 0x1c71):
|
||||||
|
with self.subTest(word=hex(word)):
|
||||||
|
self.reset(word)
|
||||||
|
self.feed()
|
||||||
|
self.label(True, True)
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.label(True, False)
|
||||||
|
self.button(2)
|
||||||
|
self.label(False, True)
|
||||||
|
self.label(True, True, bus=1)
|
||||||
|
self.assertTrue(self.rx("EMS12", {"ACC_ACT": 1}))
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.engage()
|
||||||
|
self.safety.aol_set_host_request(1)
|
||||||
|
self.assertTrue(self.steer())
|
||||||
|
self.assertEqual(self.software_set(), bool(word & 0x20))
|
||||||
|
for address, length in ((0x200, 6), (0x38D, 8), (0x420, 8), (0x421, 8), (0x50A, 8), (0x7D0, 8)):
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(make_msg(0, address, length)))
|
||||||
|
self.button(4)
|
||||||
|
self.label(True, True)
|
||||||
|
self.assertFalse(self.safety.get_controls_allowed())
|
||||||
|
self.safety.aol_set_host_request(0)
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.assertFalse(self.software_set())
|
||||||
|
self.label(True, False)
|
||||||
|
self.engage(button=1)
|
||||||
|
self.assertTrue(self.brake(True, 1))
|
||||||
|
self.label(True, True)
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.assertFalse(self.software_set())
|
||||||
|
|
||||||
|
def test_stale_label_and_bad_counter_deny_steering_and_buttons(self):
|
||||||
|
self.reset(0x1871)
|
||||||
|
self.feed()
|
||||||
|
self.engage()
|
||||||
|
self.safety.set_timer(302000)
|
||||||
|
self.feed(with_label=False)
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.assertFalse(self.software_set())
|
||||||
|
self.label(True, True)
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.label(True, False)
|
||||||
|
self.engage()
|
||||||
|
for _ in range(5):
|
||||||
|
self.brake(False, 5)
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.assertFalse(self.software_set())
|
||||||
|
|
||||||
|
def test_aol_uses_physical_lkas_with_main_off_and_requires_fresh_label(self):
|
||||||
|
self.reset(0x1C71)
|
||||||
|
self.feed(with_label=False)
|
||||||
|
self.label(False, False)
|
||||||
|
self.safety.aol_set_host_request(1)
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
||||||
|
self.safety.aol_set_host_request(0)
|
||||||
|
self.assertTrue(self.rx("BCM_PO_11", {"LDA_BTN": 0}))
|
||||||
|
self.assertTrue(self.rx("BCM_PO_11", {"LDA_BTN": 1}))
|
||||||
|
self.safety.aol_set_host_request(3)
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 1)
|
||||||
|
self.assertTrue(self.steer())
|
||||||
|
self.assertFalse(self.software_set())
|
||||||
|
self.safety.set_timer(302000)
|
||||||
|
self.feed(with_label=False)
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
||||||
|
self.assertFalse(self.steer())
|
||||||
|
self.label(False, False)
|
||||||
|
self.safety.aol_set_host_request(1)
|
||||||
|
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
||||||
@@ -0,0 +1,391 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import math
|
||||||
|
import unittest
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from opendbc.car.lateral import get_max_angle_delta_vm, get_max_angle_vm
|
||||||
|
from opendbc.car.leapmotor import leapmotorcan
|
||||||
|
from opendbc.car.leapmotor.carcontroller import get_safety_CP
|
||||||
|
from opendbc.car.leapmotor.values import CarControllerParams, LeapmotorSafetyFlags
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
from opendbc.car.vehicle_model import VehicleModel
|
||||||
|
from opendbc.safety.tests.libsafety import libsafety_py
|
||||||
|
import opendbc.safety.tests.common as common
|
||||||
|
from opendbc.safety.tests.common import CANPackerSafety, away_round, round_speed
|
||||||
|
|
||||||
|
ADAS_LKA = 0x83
|
||||||
|
POWERTRAIN_STATE = 0xB7
|
||||||
|
# ADAS_LKA.LCC_RAMP bounds while steering, as in leapmotor.h
|
||||||
|
LCC_RAMP_IDLE = 0x7801
|
||||||
|
LCC_RAMP_DEEPEST = 0x4A5D
|
||||||
|
|
||||||
|
|
||||||
|
def round_angle(apply_angle, can_offset=0):
|
||||||
|
# STEER_ANGLE_REQ is -0.02 deg per bit, offset 649.8 deg, so 0 deg is exactly representable (raw 32490).
|
||||||
|
# can_offset is in angle units of 0.02 deg (positive = larger angle)
|
||||||
|
raw = math.floor((apply_angle - 649.8) / -0.02 + 0.5) - can_offset
|
||||||
|
return raw * -0.02 + 649.8
|
||||||
|
|
||||||
|
REAL_FRAMES = { # 20 consecutive frames per message from a 2025 global B10, route 00000232 (driving with ACC/LCC)
|
||||||
|
0x184: [
|
||||||
|
"14044E1E7D1EF41D061E55201CF3004FEB02CE59A8DE808888000800000000F0",
|
||||||
|
"BF056B1E881EF41D021E55601D063150FE021C2678DF878888000800000000F0",
|
||||||
|
"06066E1E801EF81DFB1D55901E1A615112030302C8217C8888000800000000F0",
|
||||||
|
"2607521E791E111EED1D55D01F2DA1522503EAF597E0798888000800000000F0",
|
||||||
|
"AA08671E801E0A1EFB1D55002141D153380310EA479E778888000800000000F0",
|
||||||
|
"AB098F1E791EF41D111E5540225401554B03065A08DF808888000800000000F0",
|
||||||
|
"6D0A601E791EFF1D1F1E5570236831565F03D41998A18C8888000800000000F0",
|
||||||
|
"B40B591E961E0D1EE21D55B0247B6157720313EA27E2758888000800000000F0",
|
||||||
|
"B40C801E921EFB1DED1D55E0258FA1588503221AA85E7F8888000800000000F0",
|
||||||
|
"5D0D841E8B1E061E0A1E552027A2D159980303C2D79E778888000800000000F0",
|
||||||
|
"8B0E791E8B1E061EFF1D555028B6015BAB03002638E07D8888000800000000F0",
|
||||||
|
"0A0F6E1E881EF01D0D1E559029CA315CBF03ED01481F878888000800000000F0",
|
||||||
|
"9300641E8F1EED1DF41D55C02ADD615DD203FAF5C7A2778888000800000000F0",
|
||||||
|
"B301761E8F1E111EFF1D55002CF1A15EE503133638617F8888000800000000F0",
|
||||||
|
"B802791E801E0A1EFB1D55302D04D25FF80309D2E71D758888000800000000F0",
|
||||||
|
"7C03761E791EE91D021E55702E1802610B040926B85D838888000800000000F0",
|
||||||
|
"B104591E791EED1DFB1D55A02F2B32621F04E70DA81F848888000800000000F0",
|
||||||
|
"4505591E801EE91DF41D55E0303F6263320413F6C7217D8888000800000000F0",
|
||||||
|
"1406671E761E0A1EF81D55103252A26445040DDE67E0798888000800000000F0",
|
||||||
|
"F0076E1E641E061EF81D55503366D2655804FD7947DE768888000800000000F0",
|
||||||
|
],
|
||||||
|
0x18D: [
|
||||||
|
"300A02717E01F7438EAF4C0104030000F6018807A3D403000000000000000000",
|
||||||
|
"4F0B026E7E00F5438E834C0104040000F4018808A3D503000000000000000000",
|
||||||
|
"440C026E7E00F5438E8B4C0103040000F5018808A3D303000000000000000000",
|
||||||
|
"490D026B7E00F8438EB24C0104030000F7018807A3D403000000000000000000",
|
||||||
|
"A40E026B7E00FB438E984C0103040000F5018808A3D203000000000000000000",
|
||||||
|
"A80F02687E00F9438E924C0104040000F5018808A3D203000000000000000000",
|
||||||
|
"B90002687E01F6438E634C0104040000F3018809A3D303000000000000000000",
|
||||||
|
"530102657E00F6438E9A4C0104040000F5018808A3D003000000000000000000",
|
||||||
|
"840202627E00FB438EA34C0103040000F6018808A3D403000000000000000000",
|
||||||
|
"A20302627E00FC438E694C0104040000F3018809A3CE03000000000000000000",
|
||||||
|
"2704025E7E00F8438E6F4C0104040000F3018809A3D103000000000000000000",
|
||||||
|
"EB05025E7E00F3438E2F4C0105050000F001880AA3CF03000000000000000000",
|
||||||
|
"A606025B7E01F2438E4C4C0104040000F2018809A3D303000000000000000000",
|
||||||
|
"5707025B7E00F9438E7E4C0104040000F4018808A3D103000000000000000000",
|
||||||
|
"930802587E00FE438E824C0103040000F4018808A3D103000000000000000000",
|
||||||
|
"7B0902587E00FC438E514C0105040000F2018809A3CE03000000000000000000",
|
||||||
|
"060A02557E00F7438E454C0104050000F101880AA3D103000000000000000000",
|
||||||
|
"650B02557E00F4438E1C4C0105050000EF01880AA3CD03000000000000000000",
|
||||||
|
"F50C02527E00F6438E604C0104040000F3018809A3D003000000000000000000",
|
||||||
|
"C50D02527E00FB438E3C4C0104050000F101880AA3CC03000000000000000000",
|
||||||
|
],
|
||||||
|
0xB6: [
|
||||||
|
"7C0E2C142C1488138813000060000000",
|
||||||
|
"7C0F2B142B1488138813000060000000",
|
||||||
|
"B2002B142B1488138813000060000000",
|
||||||
|
"60012B142B1488138813000060000000",
|
||||||
|
"84022B142B1488138813000060000000",
|
||||||
|
"FB032B142B1488138813000060000000",
|
||||||
|
"11042C142C1488138813000060000000",
|
||||||
|
"E2052D142D1488138813000060000000",
|
||||||
|
"E7062D142D1488138813000060000000",
|
||||||
|
"C1072D142D1488138813000060000000",
|
||||||
|
"58082D142D1488138813000060000000",
|
||||||
|
"09092C142C1488138813000060000000",
|
||||||
|
"500A2B142B1488138813000060000000",
|
||||||
|
"1E0B2B142B1488138813000060000000",
|
||||||
|
"270C2A142A1488138813000060000000",
|
||||||
|
"490D2B142B1488138813000060000000",
|
||||||
|
"940E2B142B1488138813000060000000",
|
||||||
|
"940F2C142C1488138813000060000000",
|
||||||
|
"5A002C142C1488138813000060000000",
|
||||||
|
"88012C142C1488138813000060000000",
|
||||||
|
],
|
||||||
|
0xB7: [
|
||||||
|
"450B04401004B42C000000800000000055E2048D5E2013000000000000000000",
|
||||||
|
"070C04401004B42C000000800000000055E204855E2A13000000000000000000",
|
||||||
|
"230D04401004B42C000000800000000055E204855E2A13000000000000000000",
|
||||||
|
"A30E04401004B42C000000800000000055E204955E2C13000000000000000000",
|
||||||
|
"370F04401004B42C000000800000000055E204955E2813000000000000000000",
|
||||||
|
"460004401004B42C000000800000000055E204915E2613000000000000000000",
|
||||||
|
"A00104401004B42C000000800000000055E204895E2613000000000000000000",
|
||||||
|
"BC0204401004B42C000000800000000055E204855E1C13000000000000000000",
|
||||||
|
"5A0304401004B42C000000800000000055E204795E2C13000000000000000000",
|
||||||
|
"E50404401004B42C000000800000000055E2047D5E2E13000000000000000000",
|
||||||
|
"240504401004B42C000000800000000055E204895E2013000000000000000000",
|
||||||
|
"130604401004B42C000000800000000055E204855E2413000000000000000000",
|
||||||
|
"2B0704401004B42C000000800000000055E204715E2813000000000000000000",
|
||||||
|
"A60804401004B42C000000800000000055E204715E3013000000000000000000",
|
||||||
|
"E30904401004B42C000000800000000055E2047D5E2213000000000000000000",
|
||||||
|
"890A04401004B42C000000800000000055E204895E2413000000000000000000",
|
||||||
|
"810B04401004B42C000000800000000055E204815E2E13000000000000000000",
|
||||||
|
"8F0C04401004B42C000000800000000055E2047D5E2E13000000000000000000",
|
||||||
|
"7F0D04401004B42C000000800000000055E204855E3213000000000000000000",
|
||||||
|
"260E04401004B42C000000800000000055E204895E2613000000000000000000",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestLeapmotorSafety(common.CarSafetyTest, common.AngleSteeringSafetyTest):
|
||||||
|
RELAY_MALFUNCTION_ADDRS = {0: (ADAS_LKA,)}
|
||||||
|
FWD_BLACKLISTED_ADDRS = {2: [ADAS_LKA]}
|
||||||
|
TX_MSGS = [[ADAS_LKA, 0], [POWERTRAIN_STATE, 2]]
|
||||||
|
|
||||||
|
MAIN_BUS = 0
|
||||||
|
|
||||||
|
STEER_ANGLE_MAX = 500
|
||||||
|
# the 16-bit request field only spans -661..649.8 deg, so test within it
|
||||||
|
STEER_ANGLE_TEST_MAX = 645
|
||||||
|
DEG_TO_CAN = 50
|
||||||
|
|
||||||
|
# lateral accel and jerk are limited through a vehicle model, tested below as for Tesla
|
||||||
|
ANGLE_RATE_BP = None
|
||||||
|
ANGLE_RATE_UP = None
|
||||||
|
ANGLE_RATE_DOWN = None
|
||||||
|
|
||||||
|
LATERAL_FREQUENCY = 50 # Hz
|
||||||
|
|
||||||
|
cnt_angle_cmd = 0
|
||||||
|
|
||||||
|
def _get_steer_cmd_angle_max(self, speed):
|
||||||
|
return get_max_angle_vm(max(speed, 1), self.VM, CarControllerParams)
|
||||||
|
|
||||||
|
SAFETY_PARAM = 0
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.VM = VehicleModel(get_safety_CP())
|
||||||
|
self.packer = CANPackerSafety("leapmotor_b10")
|
||||||
|
self.safety = libsafety_py.libsafety
|
||||||
|
self.safety.set_safety_hooks(CarParams.SafetyModel.leapmotor, self.SAFETY_PARAM)
|
||||||
|
self.safety.init_tests()
|
||||||
|
|
||||||
|
def _angle_cmd_msg(self, angle: float, enabled: bool, increment_timer: bool = True):
|
||||||
|
values = {"STEER_ANGLE_REQ": angle, "LCC_STEERING_ACTIVE_COPY": enabled, "ACC_ACCEL_REQ": 0, "LCC_RAMP": LCC_RAMP_IDLE}
|
||||||
|
if increment_timer:
|
||||||
|
self.safety.set_timer(self.cnt_angle_cmd * int(1e6 / self.LATERAL_FREQUENCY))
|
||||||
|
self.__class__.cnt_angle_cmd += 1
|
||||||
|
return self.packer.make_can_msg_safety("ADAS_LKA", self.MAIN_BUS, values)
|
||||||
|
|
||||||
|
def _angle_meas_msg(self, angle: float):
|
||||||
|
return self.packer.make_can_msg_safety("EPS_STEERING", self.MAIN_BUS, {"STEER_ANGLE": angle})
|
||||||
|
|
||||||
|
def _pcm_status_msg(self, enable):
|
||||||
|
return self.packer.make_can_msg_safety("POWERTRAIN_STATE", self.MAIN_BUS, {"ASSIST_ENGAGED": enable})
|
||||||
|
|
||||||
|
def _speed_msg(self, speed):
|
||||||
|
kph = speed * 3.6
|
||||||
|
values = {"WHEEL_SPEED_FL": kph, "WHEEL_SPEED_FR": kph, "WHEEL_SPEED_RL": kph, "WHEEL_SPEED_RR": kph}
|
||||||
|
return self.packer.make_can_msg_safety("WHEEL_SPEEDS", self.MAIN_BUS, values)
|
||||||
|
|
||||||
|
def _user_brake_msg(self, brake):
|
||||||
|
return self.packer.make_can_msg_safety("VEHICLE_STATE", self.MAIN_BUS, {"BRAKE_PRESSED": brake})
|
||||||
|
|
||||||
|
def _user_gas_msg(self, gas):
|
||||||
|
return self.packer.make_can_msg_safety("VEHICLE_STATE", self.MAIN_BUS, {"ACCEL_PEDAL": gas * 100})
|
||||||
|
|
||||||
|
def test_angle_cmd_when_enabled(self):
|
||||||
|
# lateral acceleration and jerk are tested below
|
||||||
|
pass
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _can_speed(speed):
|
||||||
|
# match WHEEL_SPEEDS rounding (0.01 km/h)
|
||||||
|
return round_speed(away_round(speed * 3.6 / 0.01) * 0.01 / 3.6)
|
||||||
|
|
||||||
|
def test_lateral_accel_limit(self):
|
||||||
|
for speed in np.linspace(0, 40, 100):
|
||||||
|
speed = self._can_speed(max(speed, 1))
|
||||||
|
for sign in (-1, 1):
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self._reset_speed_measurement(speed + 1) # safety fudges the speed
|
||||||
|
|
||||||
|
# at the limit: safety truncates the limit to CAN units and adds 1 unit of tolerance
|
||||||
|
limit_raw = int(get_max_angle_vm(speed, self.VM, CarControllerParams) * self.DEG_TO_CAN) + 1
|
||||||
|
max_angle = np.clip(sign * limit_raw / self.DEG_TO_CAN, -self.STEER_ANGLE_MAX, self.STEER_ANGLE_MAX)
|
||||||
|
self.safety.set_desired_angle_last(round(max_angle * self.DEG_TO_CAN))
|
||||||
|
self.assertTrue(self._tx(self._angle_cmd_msg(max_angle, True)))
|
||||||
|
|
||||||
|
# one unit above the limit, unless the limit is above the EPS maximum (low speed)
|
||||||
|
max_angle_raw = sign * (limit_raw + 1) / self.DEG_TO_CAN
|
||||||
|
max_angle = np.clip(max_angle_raw, -self.STEER_ANGLE_MAX, self.STEER_ANGLE_MAX)
|
||||||
|
self._tx(self._angle_cmd_msg(max_angle, True))
|
||||||
|
should_tx = abs(max_angle_raw) >= self.STEER_ANGLE_MAX
|
||||||
|
self.assertEqual(should_tx, self._tx(self._angle_cmd_msg(max_angle, True)))
|
||||||
|
|
||||||
|
def test_lateral_jerk_limit(self):
|
||||||
|
for speed in np.linspace(0, 40, 100):
|
||||||
|
speed = self._can_speed(max(speed, 1))
|
||||||
|
for sign in (-1, 1):
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self._reset_speed_measurement(speed + 1) # safety fudges the speed
|
||||||
|
self._tx(self._angle_cmd_msg(0, True))
|
||||||
|
|
||||||
|
# within limits: up, hold, down
|
||||||
|
max_angle_delta = round_angle(get_max_angle_delta_vm(speed, self.VM, CarControllerParams) * sign)
|
||||||
|
self.assertTrue(self._tx(self._angle_cmd_msg(max_angle_delta, True)))
|
||||||
|
self.assertTrue(self._tx(self._angle_cmd_msg(max_angle_delta, True)))
|
||||||
|
self.assertTrue(self._tx(self._angle_cmd_msg(0, True)))
|
||||||
|
|
||||||
|
# too fast: up, then down
|
||||||
|
max_angle_delta = round_angle(get_max_angle_delta_vm(speed, self.VM, CarControllerParams) * sign, 2 * sign)
|
||||||
|
self.assertFalse(self._tx(self._angle_cmd_msg(max_angle_delta, True)))
|
||||||
|
self.safety.set_desired_angle_last(round(max_angle_delta * self.DEG_TO_CAN))
|
||||||
|
self.assertTrue(self._tx(self._angle_cmd_msg(max_angle_delta, True)))
|
||||||
|
self.assertFalse(self._tx(self._angle_cmd_msg(0, True)))
|
||||||
|
|
||||||
|
# recover
|
||||||
|
self.assertTrue(self._tx(self._angle_cmd_msg(0, True)))
|
||||||
|
|
||||||
|
def test_cancel_only(self):
|
||||||
|
# the camera copy of POWERTRAIN_STATE may only carry the stalk-up cancel, at any time
|
||||||
|
for allowed in (False, True):
|
||||||
|
self.safety.set_controls_allowed(allowed)
|
||||||
|
for stalk in range(4):
|
||||||
|
msg = self.packer.make_can_msg_safety("POWERTRAIN_STATE", 2, {"STALK_PUSH": stalk})
|
||||||
|
self.assertEqual(stalk == 3, self._tx(msg), stalk)
|
||||||
|
|
||||||
|
def test_rx_hook(self):
|
||||||
|
# a valid frame passes; a bad checksum or a skipped counter is rejected
|
||||||
|
for _ in range(10):
|
||||||
|
self.assertTrue(self._rx(self._speed_msg(0)))
|
||||||
|
msg = self._speed_msg(0)
|
||||||
|
msg[0].data[0] ^= 0xFF
|
||||||
|
self.assertFalse(self._rx(msg))
|
||||||
|
|
||||||
|
def test_angle_sign_matches_dbc(self):
|
||||||
|
# a real frame at right lock must give a negative measured angle in C, as in the DBC (positive = left)
|
||||||
|
right_lock = "0B0602CAE4009EC5869A5E012C2C0000D5128658A3E803000000000000000000" # raw 58570, about -521.6 deg
|
||||||
|
self.assertTrue(self._rx(libsafety_py.make_CANPacket(0x18D, self.MAIN_BUS, bytes.fromhex(right_lock))))
|
||||||
|
# one frame into an empty sample history: the new value is the minimum, the old zeros are the maximum
|
||||||
|
self.assertEqual(self.safety.get_angle_meas_min(), 32490 - 58570)
|
||||||
|
|
||||||
|
def test_real_frames(self):
|
||||||
|
# unmodified frames from a real car must pass the C checksum and counter checks
|
||||||
|
for addr, frames in REAL_FRAMES.items():
|
||||||
|
for hexdata in frames:
|
||||||
|
self.assertTrue(self._rx(libsafety_py.make_CANPacket(addr, self.MAIN_BUS, bytes.fromhex(hexdata))), hex(addr))
|
||||||
|
bad = bytearray.fromhex(frames[-1])
|
||||||
|
bad[0] ^= 0x01
|
||||||
|
self.assertFalse(self._rx(libsafety_py.make_CANPacket(addr, self.MAIN_BUS, bytes(bad))), hex(addr))
|
||||||
|
|
||||||
|
def test_lcc_ramp_limit(self):
|
||||||
|
# while steering, the EPS effort word must be between idle and the deepest stock value; otherwise it is free
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self._reset_speed_measurement(10)
|
||||||
|
for lka_active in (True, False):
|
||||||
|
for ramp in (LCC_RAMP_IDLE + 1, LCC_RAMP_IDLE, LCC_RAMP_DEEPEST, LCC_RAMP_DEEPEST - 1, 0, 0xFFFF):
|
||||||
|
values = {"STEER_ANGLE_REQ": 0, "LCC_STEERING_ACTIVE_COPY": lka_active, "ACC_ACCEL_REQ": 0, "LCC_RAMP": ramp}
|
||||||
|
self.safety.set_desired_angle_last(0)
|
||||||
|
msg = self.packer.make_can_msg_safety("ADAS_LKA", self.MAIN_BUS, values)
|
||||||
|
allowed = not lka_active or LCC_RAMP_DEEPEST <= ramp <= LCC_RAMP_IDLE
|
||||||
|
self.assertEqual(allowed, self._tx(msg), (lka_active, hex(ramp)))
|
||||||
|
|
||||||
|
def test_lcc_ramp_limit_matches_car_code(self):
|
||||||
|
self.assertEqual(LCC_RAMP_IDLE, leapmotorcan.LCC_RAMP_IDLE)
|
||||||
|
self.assertEqual(LCC_RAMP_DEEPEST, leapmotorcan.LCC_RAMP_IDLE - leapmotorcan.LCC_RAMP_STEP * leapmotorcan.LCC_RAMP_STEPS_MAX)
|
||||||
|
|
||||||
|
def test_accel_request_unchecked_without_longitudinal(self):
|
||||||
|
# only with the longitudinal flag is the acceleration request checked: an unknown hard request is then blocked
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
values = {"STEER_ANGLE_REQ": 0, "LCC_STEERING_ACTIVE_COPY": 0, "ACC_ACCEL_REQ": -5.0}
|
||||||
|
msg = self.packer.make_can_msg_safety("ADAS_LKA", self.MAIN_BUS, values)
|
||||||
|
self.assertEqual(not (self.SAFETY_PARAM & LeapmotorSafetyFlags.LONG_CONTROL), self._tx(msg))
|
||||||
|
|
||||||
|
|
||||||
|
class TestLeapmotorLongitudinalSafety(TestLeapmotorSafety, common.LongitudinalAccelSafetyTest):
|
||||||
|
SAFETY_PARAM = LeapmotorSafetyFlags.LONG_CONTROL
|
||||||
|
MAX_ACCEL = CarControllerParams.ACCEL_MAX
|
||||||
|
MIN_ACCEL = CarControllerParams.ACCEL_MIN
|
||||||
|
|
||||||
|
def _accel_msg(self, accel: float, bus: int = 0):
|
||||||
|
# steering inactive, so only the acceleration request is checked
|
||||||
|
values = {"STEER_ANGLE_REQ": 0, "LCC_STEERING_ACTIVE_COPY": 0, "ACC_ACCEL_REQ": accel}
|
||||||
|
return self.packer.make_can_msg_safety("ADAS_LKA", bus, values)
|
||||||
|
|
||||||
|
CAMERA_ACCEL_HISTORY = 8 # LEAPMOTOR_CAMERA_ACCEL_HISTORY
|
||||||
|
|
||||||
|
def _camera_accel(self, *accels):
|
||||||
|
for accel in accels:
|
||||||
|
self.assertTrue(self._rx(self._accel_msg(accel, bus=2)))
|
||||||
|
|
||||||
|
def test_camera_accel_passthrough(self):
|
||||||
|
# without controls allowed, only the camera's own request (or 0) may be sent
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
self._camera_accel(-1.0)
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(-1.0)))
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(0)))
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(-1.5)))
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(0.5)))
|
||||||
|
|
||||||
|
def test_camera_accel_passthrough_lags(self):
|
||||||
|
# openpilot's frame can carry a camera request a few frames older than the panda's latest: any of the last 8 passes
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
self._camera_accel(0.55)
|
||||||
|
self._camera_accel(*[0.6] * (self.CAMERA_ACCEL_HISTORY - 1))
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(0.55)))
|
||||||
|
self._camera_accel(0.6)
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(0.55)))
|
||||||
|
|
||||||
|
def test_camera_accel_beyond_limits(self):
|
||||||
|
# the camera's emergency braking (beyond openpilot's -3.5) is passed on, also as it releases
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self._camera_accel(-4.5, -3.6)
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(-4.5)))
|
||||||
|
self._camera_accel(-1.3)
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(-3.6)))
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(-4.0)))
|
||||||
|
|
||||||
|
def test_accel_with_gas_pressed(self):
|
||||||
|
# the panda sees an accelerator press a frame before openpilot hands back to the stock ACC: its own request stays allowed
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self._rx(self._user_gas_msg(1))
|
||||||
|
self._rx(self._user_gas_msg(1))
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(-1.15)))
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(-3.6)))
|
||||||
|
|
||||||
|
def test_stock_brake_floor(self):
|
||||||
|
# while all the camera's recent requests are hard braking, openpilot may not ask for less than the least of them
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
for camera_accel in (-1.95, -2.0, -2.5, -3.0):
|
||||||
|
self._camera_accel(*[camera_accel] * self.CAMERA_ACCEL_HISTORY)
|
||||||
|
hard = camera_accel <= CarControllerParams.STOCK_BRAKE_PASSTHROUGH
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(camera_accel)))
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(-3.5)))
|
||||||
|
self.assertEqual(not hard, self._tx(self._accel_msg(camera_accel + 0.05)), camera_accel)
|
||||||
|
self.assertEqual(not hard, self._tx(self._accel_msg(1.0)), camera_accel)
|
||||||
|
|
||||||
|
def test_stock_brake_floor_ramp(self):
|
||||||
|
# the camera starts braking hard: openpilot, a frame behind, still sent its own request when it saw -1.95
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self._camera_accel(*[-1.5] * self.CAMERA_ACCEL_HISTORY)
|
||||||
|
self._camera_accel(-1.95, -2.0)
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(-0.7)))
|
||||||
|
# once every recent request is hard braking, the floor holds
|
||||||
|
self._camera_accel(*[-2.6] * self.CAMERA_ACCEL_HISTORY)
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(-0.7)))
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(-2.6)))
|
||||||
|
|
||||||
|
def test_camera_accel_history_starts_inactive(self):
|
||||||
|
# every slot starts inactive, not at raw 0 (-5.0 m/s^2), so no camera request is assumed before the camera sends one
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(-5.0)))
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(0)))
|
||||||
|
|
||||||
|
def test_stock_brake_floor_whole_history(self):
|
||||||
|
# the floor is the least braking of all the recent requests, wherever it is in the history
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self._camera_accel(*[-2.5] * 5, -1.0, *[-2.5] * 2)
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(1.0)))
|
||||||
|
self._camera_accel(-2.5) # -1.0 is still within the last 8
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(1.0)))
|
||||||
|
|
||||||
|
def test_inactive_request_always_allowed(self):
|
||||||
|
# openpilot may always send the inactive request, also when the camera asks for something else
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
self._camera_accel(*[-1.0] * self.CAMERA_ACCEL_HISTORY)
|
||||||
|
self.assertTrue(self._tx(self._accel_msg(0)))
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(0.5)))
|
||||||
|
|
||||||
|
def test_other_camera_messages_ignored(self):
|
||||||
|
# only the camera's ADAS_LKA is a camera request: the same byte in another camera frame is not
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
raw = int(round((-4.0 + 5.0) / 0.05))
|
||||||
|
dat = bytearray(16)
|
||||||
|
dat[4] = raw
|
||||||
|
self.assertTrue(self._rx(libsafety_py.make_CANPacket(0x142, 2, bytes(dat))))
|
||||||
|
self.assertFalse(self._tx(self._accel_msg(-4.0)))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -6282,7 +6282,7 @@ const ::capnp::_::RawSchema s_a1adf400915718e5 = {
|
|||||||
0, 8, i_a1adf400915718e5, nullptr, nullptr, { &s_a1adf400915718e5, nullptr, nullptr, 0, 0, nullptr }, false
|
0, 8, i_a1adf400915718e5, nullptr, nullptr, { &s_a1adf400915718e5, nullptr, nullptr, 0, 0, nullptr }, false
|
||||||
};
|
};
|
||||||
#endif // !CAPNP_LITE
|
#endif // !CAPNP_LITE
|
||||||
static const ::capnp::_::AlignedData<202> b_95551e5b1edaf451 = {
|
static const ::capnp::_::AlignedData<207> b_95551e5b1edaf451 = {
|
||||||
{ 0, 0, 0, 0, 5, 0, 6, 0,
|
{ 0, 0, 0, 0, 5, 0, 6, 0,
|
||||||
81, 244, 218, 30, 91, 30, 85, 149,
|
81, 244, 218, 30, 91, 30, 85, 149,
|
||||||
20, 0, 0, 0, 2, 0, 0, 0,
|
20, 0, 0, 0, 2, 0, 0, 0,
|
||||||
@@ -6292,7 +6292,7 @@ static const ::capnp::_::AlignedData<202> b_95551e5b1edaf451 = {
|
|||||||
21, 0, 0, 0, 2, 1, 0, 0,
|
21, 0, 0, 0, 2, 1, 0, 0,
|
||||||
33, 0, 0, 0, 7, 0, 0, 0,
|
33, 0, 0, 0, 7, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
29, 0, 0, 0, 199, 3, 0, 0,
|
29, 0, 0, 0, 223, 3, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
99, 97, 114, 46, 99, 97, 112, 110,
|
99, 97, 114, 46, 99, 97, 112, 110,
|
||||||
@@ -6300,126 +6300,129 @@ static const ::capnp::_::AlignedData<202> b_95551e5b1edaf451 = {
|
|||||||
97, 109, 115, 46, 83, 97, 102, 101,
|
97, 109, 115, 46, 83, 97, 102, 101,
|
||||||
116, 121, 77, 111, 100, 101, 108, 0,
|
116, 121, 77, 111, 100, 101, 108, 0,
|
||||||
0, 0, 0, 0, 1, 0, 1, 0,
|
0, 0, 0, 0, 1, 0, 1, 0,
|
||||||
160, 0, 0, 0, 1, 0, 2, 0,
|
164, 0, 0, 0, 1, 0, 2, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
217, 1, 0, 0, 58, 0, 0, 0,
|
229, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 0, 0, 0, 0, 0, 0, 0,
|
1, 0, 0, 0, 0, 0, 0, 0,
|
||||||
209, 1, 0, 0, 90, 0, 0, 0,
|
221, 1, 0, 0, 90, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
2, 0, 0, 0, 0, 0, 0, 0,
|
2, 0, 0, 0, 0, 0, 0, 0,
|
||||||
205, 1, 0, 0, 58, 0, 0, 0,
|
217, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
3, 0, 0, 0, 0, 0, 0, 0,
|
3, 0, 0, 0, 0, 0, 0, 0,
|
||||||
197, 1, 0, 0, 58, 0, 0, 0,
|
209, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
4, 0, 0, 0, 0, 0, 0, 0,
|
4, 0, 0, 0, 0, 0, 0, 0,
|
||||||
189, 1, 0, 0, 26, 0, 0, 0,
|
201, 1, 0, 0, 26, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
5, 0, 0, 0, 0, 0, 0, 0,
|
5, 0, 0, 0, 0, 0, 0, 0,
|
||||||
181, 1, 0, 0, 146, 0, 0, 0,
|
193, 1, 0, 0, 146, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
6, 0, 0, 0, 0, 0, 0, 0,
|
6, 0, 0, 0, 0, 0, 0, 0,
|
||||||
181, 1, 0, 0, 42, 0, 0, 0,
|
193, 1, 0, 0, 42, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
7, 0, 0, 0, 0, 0, 0, 0,
|
7, 0, 0, 0, 0, 0, 0, 0,
|
||||||
173, 1, 0, 0, 74, 0, 0, 0,
|
185, 1, 0, 0, 74, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
8, 0, 0, 0, 0, 0, 0, 0,
|
8, 0, 0, 0, 0, 0, 0, 0,
|
||||||
169, 1, 0, 0, 66, 0, 0, 0,
|
181, 1, 0, 0, 66, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
9, 0, 0, 0, 0, 0, 0, 0,
|
9, 0, 0, 0, 0, 0, 0, 0,
|
||||||
161, 1, 0, 0, 74, 0, 0, 0,
|
173, 1, 0, 0, 74, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
10, 0, 0, 0, 0, 0, 0, 0,
|
10, 0, 0, 0, 0, 0, 0, 0,
|
||||||
157, 1, 0, 0, 50, 0, 0, 0,
|
169, 1, 0, 0, 50, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
11, 0, 0, 0, 0, 0, 0, 0,
|
11, 0, 0, 0, 0, 0, 0, 0,
|
||||||
149, 1, 0, 0, 58, 0, 0, 0,
|
161, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
12, 0, 0, 0, 0, 0, 0, 0,
|
12, 0, 0, 0, 0, 0, 0, 0,
|
||||||
141, 1, 0, 0, 82, 0, 0, 0,
|
153, 1, 0, 0, 82, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
13, 0, 0, 0, 0, 0, 0, 0,
|
13, 0, 0, 0, 0, 0, 0, 0,
|
||||||
137, 1, 0, 0, 50, 0, 0, 0,
|
149, 1, 0, 0, 50, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
14, 0, 0, 0, 0, 0, 0, 0,
|
14, 0, 0, 0, 0, 0, 0, 0,
|
||||||
129, 1, 0, 0, 58, 0, 0, 0,
|
141, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
15, 0, 0, 0, 0, 0, 0, 0,
|
15, 0, 0, 0, 0, 0, 0, 0,
|
||||||
121, 1, 0, 0, 90, 0, 0, 0,
|
133, 1, 0, 0, 90, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
16, 0, 0, 0, 0, 0, 0, 0,
|
16, 0, 0, 0, 0, 0, 0, 0,
|
||||||
117, 1, 0, 0, 90, 0, 0, 0,
|
129, 1, 0, 0, 90, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
17, 0, 0, 0, 0, 0, 0, 0,
|
17, 0, 0, 0, 0, 0, 0, 0,
|
||||||
113, 1, 0, 0, 82, 0, 0, 0,
|
125, 1, 0, 0, 82, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
18, 0, 0, 0, 0, 0, 0, 0,
|
18, 0, 0, 0, 0, 0, 0, 0,
|
||||||
109, 1, 0, 0, 58, 0, 0, 0,
|
121, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
19, 0, 0, 0, 0, 0, 0, 0,
|
19, 0, 0, 0, 0, 0, 0, 0,
|
||||||
101, 1, 0, 0, 74, 0, 0, 0,
|
113, 1, 0, 0, 74, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
20, 0, 0, 0, 0, 0, 0, 0,
|
20, 0, 0, 0, 0, 0, 0, 0,
|
||||||
97, 1, 0, 0, 90, 0, 0, 0,
|
109, 1, 0, 0, 90, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
21, 0, 0, 0, 0, 0, 0, 0,
|
21, 0, 0, 0, 0, 0, 0, 0,
|
||||||
93, 1, 0, 0, 106, 0, 0, 0,
|
105, 1, 0, 0, 106, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
22, 0, 0, 0, 0, 0, 0, 0,
|
22, 0, 0, 0, 0, 0, 0, 0,
|
||||||
89, 1, 0, 0, 130, 0, 0, 0,
|
101, 1, 0, 0, 130, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
23, 0, 0, 0, 0, 0, 0, 0,
|
23, 0, 0, 0, 0, 0, 0, 0,
|
||||||
85, 1, 0, 0, 114, 0, 0, 0,
|
97, 1, 0, 0, 114, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
24, 0, 0, 0, 0, 0, 0, 0,
|
24, 0, 0, 0, 0, 0, 0, 0,
|
||||||
81, 1, 0, 0, 138, 0, 0, 0,
|
93, 1, 0, 0, 138, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
25, 0, 0, 0, 0, 0, 0, 0,
|
25, 0, 0, 0, 0, 0, 0, 0,
|
||||||
81, 1, 0, 0, 114, 0, 0, 0,
|
93, 1, 0, 0, 114, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
26, 0, 0, 0, 0, 0, 0, 0,
|
26, 0, 0, 0, 0, 0, 0, 0,
|
||||||
77, 1, 0, 0, 58, 0, 0, 0,
|
89, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
27, 0, 0, 0, 0, 0, 0, 0,
|
27, 0, 0, 0, 0, 0, 0, 0,
|
||||||
69, 1, 0, 0, 42, 0, 0, 0,
|
81, 1, 0, 0, 42, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
28, 0, 0, 0, 0, 0, 0, 0,
|
28, 0, 0, 0, 0, 0, 0, 0,
|
||||||
61, 1, 0, 0, 106, 0, 0, 0,
|
73, 1, 0, 0, 106, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
29, 0, 0, 0, 0, 0, 0, 0,
|
29, 0, 0, 0, 0, 0, 0, 0,
|
||||||
57, 1, 0, 0, 138, 0, 0, 0,
|
69, 1, 0, 0, 138, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
30, 0, 0, 0, 0, 0, 0, 0,
|
30, 0, 0, 0, 0, 0, 0, 0,
|
||||||
57, 1, 0, 0, 106, 0, 0, 0,
|
69, 1, 0, 0, 106, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
31, 0, 0, 0, 0, 0, 0, 0,
|
31, 0, 0, 0, 0, 0, 0, 0,
|
||||||
53, 1, 0, 0, 34, 0, 0, 0,
|
65, 1, 0, 0, 34, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
32, 0, 0, 0, 0, 0, 0, 0,
|
32, 0, 0, 0, 0, 0, 0, 0,
|
||||||
45, 1, 0, 0, 90, 0, 0, 0,
|
57, 1, 0, 0, 90, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
33, 0, 0, 0, 0, 0, 0, 0,
|
33, 0, 0, 0, 0, 0, 0, 0,
|
||||||
41, 1, 0, 0, 58, 0, 0, 0,
|
53, 1, 0, 0, 58, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
34, 0, 0, 0, 0, 0, 0, 0,
|
34, 0, 0, 0, 0, 0, 0, 0,
|
||||||
33, 1, 0, 0, 114, 0, 0, 0,
|
45, 1, 0, 0, 114, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
35, 0, 0, 0, 0, 0, 0, 0,
|
35, 0, 0, 0, 0, 0, 0, 0,
|
||||||
29, 1, 0, 0, 34, 0, 0, 0,
|
41, 1, 0, 0, 34, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
36, 0, 0, 0, 0, 0, 0, 0,
|
36, 0, 0, 0, 0, 0, 0, 0,
|
||||||
21, 1, 0, 0, 50, 0, 0, 0,
|
33, 1, 0, 0, 50, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
37, 0, 0, 0, 0, 0, 0, 0,
|
37, 0, 0, 0, 0, 0, 0, 0,
|
||||||
13, 1, 0, 0, 34, 0, 0, 0,
|
25, 1, 0, 0, 34, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
38, 0, 0, 0, 0, 0, 0, 0,
|
38, 0, 0, 0, 0, 0, 0, 0,
|
||||||
5, 1, 0, 0, 26, 0, 0, 0,
|
17, 1, 0, 0, 26, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
39, 0, 0, 0, 0, 0, 0, 0,
|
39, 0, 0, 0, 0, 0, 0, 0,
|
||||||
253, 0, 0, 0, 90, 0, 0, 0,
|
9, 1, 0, 0, 90, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
40, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
5, 1, 0, 0, 82, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
115, 105, 108, 101, 110, 116, 0, 0,
|
115, 105, 108, 101, 110, 116, 0, 0,
|
||||||
104, 111, 110, 100, 97, 78, 105, 100,
|
104, 111, 110, 100, 97, 78, 105, 100,
|
||||||
@@ -6484,14 +6487,16 @@ static const ::capnp::_::AlignedData<202> b_95551e5b1edaf451 = {
|
|||||||
98, 109, 119, 0, 0, 0, 0, 0,
|
98, 109, 119, 0, 0, 0, 0, 0,
|
||||||
109, 103, 0, 0, 0, 0, 0, 0,
|
109, 103, 0, 0, 0, 0, 0, 0,
|
||||||
116, 101, 115, 108, 97, 80, 114, 101,
|
116, 101, 115, 108, 97, 80, 114, 101,
|
||||||
97, 112, 0, 0, 0, 0, 0, 0, }
|
97, 112, 0, 0, 0, 0, 0, 0,
|
||||||
|
108, 101, 97, 112, 109, 111, 116, 111,
|
||||||
|
114, 0, 0, 0, 0, 0, 0, 0, }
|
||||||
};
|
};
|
||||||
::capnp::word const* const bp_95551e5b1edaf451 = b_95551e5b1edaf451.words;
|
::capnp::word const* const bp_95551e5b1edaf451 = b_95551e5b1edaf451.words;
|
||||||
#if !CAPNP_LITE
|
#if !CAPNP_LITE
|
||||||
static const uint16_t m_95551e5b1edaf451[] = {17, 37, 27, 35, 7, 9, 30, 3, 32, 6, 4, 18, 12, 20, 5, 1, 26, 8, 28, 24, 23, 13, 38, 14, 19, 31, 33, 0, 11, 22, 10, 39, 2, 16, 15, 34, 25, 29, 21, 36};
|
static const uint16_t m_95551e5b1edaf451[] = {17, 37, 27, 35, 7, 9, 30, 3, 32, 6, 4, 18, 12, 20, 5, 1, 26, 8, 28, 24, 23, 40, 13, 38, 14, 19, 31, 33, 0, 11, 22, 10, 39, 2, 16, 15, 34, 25, 29, 21, 36};
|
||||||
const ::capnp::_::RawSchema s_95551e5b1edaf451 = {
|
const ::capnp::_::RawSchema s_95551e5b1edaf451 = {
|
||||||
0x95551e5b1edaf451, b_95551e5b1edaf451.words, 202, nullptr, m_95551e5b1edaf451,
|
0x95551e5b1edaf451, b_95551e5b1edaf451.words, 207, nullptr, m_95551e5b1edaf451,
|
||||||
0, 40, nullptr, nullptr, nullptr, { &s_95551e5b1edaf451, nullptr, nullptr, 0, 0, nullptr }, false
|
0, 41, nullptr, nullptr, nullptr, { &s_95551e5b1edaf451, nullptr, nullptr, 0, 0, nullptr }, false
|
||||||
};
|
};
|
||||||
#endif // !CAPNP_LITE
|
#endif // !CAPNP_LITE
|
||||||
CAPNP_DEFINE_ENUM(SafetyModel_95551e5b1edaf451, 95551e5b1edaf451);
|
CAPNP_DEFINE_ENUM(SafetyModel_95551e5b1edaf451, 95551e5b1edaf451);
|
||||||
|
|||||||
@@ -291,6 +291,7 @@ enum class SafetyModel_95551e5b1edaf451: uint16_t {
|
|||||||
BMW,
|
BMW,
|
||||||
MG,
|
MG,
|
||||||
TESLA_PREAP,
|
TESLA_PREAP,
|
||||||
|
LEAPMOTOR,
|
||||||
};
|
};
|
||||||
CAPNP_DECLARE_ENUM(SafetyModel, 95551e5b1edaf451);
|
CAPNP_DECLARE_ENUM(SafetyModel, 95551e5b1edaf451);
|
||||||
CAPNP_DECLARE_SCHEMA(d661512be2def77f);
|
CAPNP_DECLARE_SCHEMA(d661512be2def77f);
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -31,6 +31,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
|||||||
{"IgnoreIgnitionLine", {PERSISTENT, BOOL, "0"}},
|
{"IgnoreIgnitionLine", {PERSISTENT, BOOL, "0"}},
|
||||||
{"TeslaWakeOnCAN", {PERSISTENT, BOOL, "0"}},
|
{"TeslaWakeOnCAN", {PERSISTENT, BOOL, "0"}},
|
||||||
{"DeveloperUI", {PERSISTENT, BOOL, "0"}},
|
{"DeveloperUI", {PERSISTENT, BOOL, "0"}},
|
||||||
|
{"SettingsAdvanced", {PERSISTENT, BOOL, "0"}},
|
||||||
{"LatSmoothSeconds", {PERSISTENT, FLOAT}},
|
{"LatSmoothSeconds", {PERSISTENT, FLOAT}},
|
||||||
{"SubaruSmoothingContext", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION, BYTES}},
|
{"SubaruSmoothingContext", {CLEAR_ON_MANAGER_START | CLEAR_ON_OFFROAD_TRANSITION, BYTES}},
|
||||||
{"SubaruAvhStartup", {PERSISTENT, BOOL, "0"}},
|
{"SubaruAvhStartup", {PERSISTENT, BOOL, "0"}},
|
||||||
@@ -75,7 +76,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> keys = {
|
|||||||
{"RetiredSettingsEvidence", {PERSISTENT | DONT_LOG, JSON}},
|
{"RetiredSettingsEvidence", {PERSISTENT | DONT_LOG, JSON}},
|
||||||
{"QOLLongitudinal", {PERSISTENT, BOOL}},
|
{"QOLLongitudinal", {PERSISTENT, BOOL}},
|
||||||
{"ReverseCruise", {PERSISTENT, BOOL, "0"}},
|
{"ReverseCruise", {PERSISTENT, BOOL, "0"}},
|
||||||
{"ForceStops", {PERSISTENT, BOOL, "0"}},
|
{"ForceStops", {PERSISTENT, BOOL, "1"}},
|
||||||
{"AlwaysHoldEnhancedStops", {PERSISTENT, BOOL, "0"}},
|
{"AlwaysHoldEnhancedStops", {PERSISTENT, BOOL, "0"}},
|
||||||
{"DriveModeProfiles", {PERSISTENT, BOOL, "0"}},
|
{"DriveModeProfiles", {PERSISTENT, BOOL, "0"}},
|
||||||
{"DriveModeAcceleration", {PERSISTENT, BOOL, "1"}},
|
{"DriveModeAcceleration", {PERSISTENT, BOOL, "1"}},
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ class CarEvents:
|
|||||||
self.low_speed_alert = False
|
self.low_speed_alert = False
|
||||||
self.no_steer_warning = False
|
self.no_steer_warning = False
|
||||||
self.silent_steer_warning = True
|
self.silent_steer_warning = True
|
||||||
|
self.leapmotor_cancel = None
|
||||||
|
if CP.brand == 'leapmotor':
|
||||||
|
from openpilot.starpilot.car.leapmotor.events import CarCancel
|
||||||
|
self.leapmotor_cancel = CarCancel()
|
||||||
|
|
||||||
def update(self, CS: car.CarState, CS_prev: car.CarState, CC: car.CarControl):
|
def update(self, CS: car.CarState, CS_prev: car.CarState, CC: car.CarControl):
|
||||||
if self.CP.brand in ('body', 'mock'):
|
if self.CP.brand in ('body', 'mock'):
|
||||||
@@ -104,6 +108,11 @@ class CarEvents:
|
|||||||
# if CC.eps_timer_soft_disable_alert:
|
# if CC.eps_timer_soft_disable_alert:
|
||||||
# events.add(EventName.steerTimeLimit)
|
# events.add(EventName.steerTimeLimit)
|
||||||
|
|
||||||
|
elif self.CP.brand == 'leapmotor':
|
||||||
|
if self.leapmotor_cancel.update(CS, CS_prev):
|
||||||
|
from openpilot.starpilot.car.leapmotor.events import announce
|
||||||
|
announce(events)
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
||||||
def create_common_events(self, CS: structs.CarState, CS_prev: car.CarState):
|
def create_common_events(self, CS: structs.CarState, CS_prev: car.CarState):
|
||||||
|
|||||||
@@ -697,7 +697,10 @@ class Car:
|
|||||||
getattr(self.aol_transport_feedback, 'subaru_main_retained_native_ns', 0) == int(native.observedMonoTime))
|
getattr(self.aol_transport_feedback, 'subaru_main_retained_native_ns', 0) == int(native.observedMonoTime))
|
||||||
volkswagen_reverse_pending = bool(volkswagen_aol and not transport_reset and native is not None and
|
volkswagen_reverse_pending = bool(volkswagen_aol and not transport_reset and native is not None and
|
||||||
getattr(self.aol_transport_feedback, 'volkswagen_reverse_retained_native_ns', 0) == int(native.observedMonoTime))
|
getattr(self.aol_transport_feedback, 'volkswagen_reverse_retained_native_ns', 0) == int(native.observedMonoTime))
|
||||||
rejected = native_reset or (not angle_arm_pending and not subaru_braked_main_pending and
|
paddle_denial = getattr(getattr(self, 'aol_transport_feedback', None), 'subaru_paddle_denial', None)
|
||||||
|
subaru_paddle_pending = bool(paddle_denial and not transport_reset and native is not None and
|
||||||
|
paddle_denial[0] == int(native.observedMonoTime))
|
||||||
|
rejected = native_reset or (not angle_arm_pending and not subaru_braked_main_pending and not subaru_paddle_pending and
|
||||||
not volkswagen_initial_wait and not volkswagen_reverse_pending and not honda_eps_pending and
|
not volkswagen_initial_wait and not volkswagen_reverse_pending and not honda_eps_pending and
|
||||||
native_latch_rejected(self.CP, native, state=CS if angle_panda_ready else None))
|
native_latch_rejected(self.CP, native, state=CS if angle_panda_ready else None))
|
||||||
rejection_ns = now_ns if native_reset else int(native.observedMonoTime) if rejected else 0
|
rejection_ns = now_ns if native_reset else int(native.observedMonoTime) if rejected else 0
|
||||||
@@ -1081,6 +1084,9 @@ class Car:
|
|||||||
if self.aol_card_intent is not None:
|
if self.aol_card_intent is not None:
|
||||||
allowed_latch, pause_lateral, pause_longitudinal = self.aol_card_intent.output(CS)
|
allowed_latch, pause_lateral, pause_longitudinal = self.aol_card_intent.output(CS)
|
||||||
lateral_armed = self.aol_card_intent.allowed_latch
|
lateral_armed = self.aol_card_intent.allowed_latch
|
||||||
|
paddle_denial = getattr(getattr(self, 'aol_transport_feedback', None), 'subaru_paddle_denial', None)
|
||||||
|
if paddle_denial and not paddle_denial[3]:
|
||||||
|
allowed_latch = False
|
||||||
intent_deadline_ns = int(cs_send.logMonoTime) + 200_000_000
|
intent_deadline_ns = int(cs_send.logMonoTime) + 200_000_000
|
||||||
publication = (getattr(self.aol_card_intent, 'intent_publication', None) if self.CP.brand == 'volkswagen' else None)
|
publication = (getattr(self.aol_card_intent, 'intent_publication', None) if self.CP.brand == 'volkswagen' else None)
|
||||||
if publication is not None:
|
if publication is not None:
|
||||||
@@ -1476,9 +1482,8 @@ class Car:
|
|||||||
|
|
||||||
def _feedback_capture(self, now_ns):
|
def _feedback_capture(self, now_ns):
|
||||||
try:
|
try:
|
||||||
source = self.sm['autoSteeringLearning'].learning.sourceReceipt
|
|
||||||
factory = self.learning_feedback_factory
|
factory = self.learning_feedback_factory
|
||||||
if factory is None or not source.enabled or source.manual:
|
if factory is None:
|
||||||
self.learning_feedback_capture = None
|
self.learning_feedback_capture = None
|
||||||
return None
|
return None
|
||||||
return factory(self, now_ns)
|
return factory(self, now_ns)
|
||||||
@@ -1905,6 +1910,11 @@ class Car:
|
|||||||
subaru_aol.sync_legacy_card_lateral(self, CS, CC)
|
subaru_aol.sync_legacy_card_lateral(self, CS, CC)
|
||||||
if getattr(self, "redneck_cruise", None):
|
if getattr(self, "redneck_cruise", None):
|
||||||
self.redneck_cruise.update(self, CS, CC, now_nanos)
|
self.redneck_cruise.update(self, CS, CC, now_nanos)
|
||||||
|
paddle_denial = getattr(getattr(self, 'aol_transport_feedback', None), 'subaru_paddle_denial', None)
|
||||||
|
if CC.latActive and not CC.enabled and paddle_denial and not paddle_denial[3]:
|
||||||
|
suppressed = CC.as_builder()
|
||||||
|
suppressed.latActive = False
|
||||||
|
CC = suppressed.as_reader()
|
||||||
self.last_actuators_output, can_sends = self.CI.apply(CC, now_nanos)
|
self.last_actuators_output, can_sends = self.CI.apply(CC, now_nanos)
|
||||||
self.publish_sendcan(can_sends, valid=CS.canValid)
|
self.publish_sendcan(can_sends, valid=CS.canValid)
|
||||||
if learning_snapshot is not None and self.learning_send_committed_mono_ns:
|
if learning_snapshot is not None and self.learning_send_committed_mono_ns:
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
|
from dataclasses import replace
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from opendbc.car import structs
|
from opendbc.car import structs
|
||||||
from openpilot.cereal import messaging
|
from openpilot.cereal import messaging
|
||||||
from openpilot.selfdrive.car.card import Car
|
from openpilot.selfdrive.car.card import Car
|
||||||
from openpilot.starpilot.flm.learning_wire import write_source_receipt
|
from openpilot.starpilot.flm.feedback_wire import read_publication
|
||||||
|
from openpilot.starpilot.flm.learning_wire import read_source_receipt, write_source_receipt
|
||||||
from openpilot.starpilot.flm.runtime_adapter_registry import SourceState
|
from openpilot.starpilot.flm.runtime_adapter_registry import SourceState
|
||||||
|
|
||||||
|
|
||||||
@@ -16,7 +18,7 @@ def test_first_calibrated_feedback_uses_startup_preparation():
|
|||||||
stamp = 10_000_000_000
|
stamp = 10_000_000_000
|
||||||
service = 'autoSteeringLearning'
|
service = 'autoSteeringLearning'
|
||||||
packet = messaging.new_message(service, valid=True, logMonoTime=stamp)
|
packet = messaging.new_message(service, valid=True, logMonoTime=stamp)
|
||||||
source = SourceState(True, False, 'boot', 'a' * 64, stamp, stamp + 500_000_000,
|
source = SourceState(True, False, 'boot', 'a' * 64, stamp, stamp + 200_000_000,
|
||||||
card._feedback_cp_sha256, (0., 0., 0.))
|
card._feedback_cp_sha256, (0., 0., 0.))
|
||||||
write_source_receipt(packet, source)
|
write_source_receipt(packet, source)
|
||||||
sm = messaging.SubMaster([service])
|
sm = messaging.SubMaster([service])
|
||||||
@@ -24,12 +26,28 @@ def test_first_calibrated_feedback_uses_startup_preparation():
|
|||||||
sm.alive[service] = sm.freq_ok[service] = True
|
sm.alive[service] = sm.freq_ok[service] = True
|
||||||
card.sm = sm
|
card.sm = sm
|
||||||
|
|
||||||
with patch('openpilot.starpilot.flm.runtime_adapter_registry.car_params_digest', side_effect=AssertionError):
|
with patch('openpilot.starpilot.flm.runtime_adapter_registry.car_params_digest', side_effect=AssertionError), \
|
||||||
|
patch('openpilot.starpilot.flm.learning_wire.read_source_receipt', wraps=read_source_receipt) as decode:
|
||||||
capture = card._feedback_capture(stamp)
|
capture = card._feedback_capture(stamp)
|
||||||
assert capture is not None
|
assert capture is not None
|
||||||
|
assert card._feedback_capture(stamp + 10_000_000) is capture
|
||||||
|
assert decode.call_count == 1
|
||||||
output = messaging.new_message('carOutput', valid=True, logMonoTime=stamp)
|
output = messaging.new_message('carOutput', valid=True, logMonoTime=stamp)
|
||||||
companion = messaging.new_message('starpilotCarState', valid=True, logMonoTime=stamp)
|
companion = messaging.new_message('starpilotCarState', valid=True, logMonoTime=stamp)
|
||||||
card.learning_feedback_writer(companion.starpilotCarState, capture.publication(output))
|
row = capture.publication(output)
|
||||||
assert companion.starpilotCarState.feedbackPublication.version == 1
|
card.learning_feedback_writer(companion.starpilotCarState, row)
|
||||||
assert not companion.starpilotCarState.feedbackPublication.outputKnown
|
assert read_publication(companion.starpilotCarState) == row
|
||||||
assert card._feedback_capture(stamp + 500_000_001) is None
|
assert not row.output_known
|
||||||
|
disabled = messaging.new_message(service, valid=True, logMonoTime=stamp)
|
||||||
|
write_source_receipt(disabled, replace(source, enabled=False))
|
||||||
|
sm.update_msgs((stamp + 20_000_000) / 1e9, [disabled.as_reader()])
|
||||||
|
sm.alive[service] = sm.freq_ok[service] = True
|
||||||
|
assert card._feedback_capture(stamp + 20_000_000) is None
|
||||||
|
assert card._feedback_capture(stamp + 25_000_000) is None
|
||||||
|
assert decode.call_count == 2
|
||||||
|
|
||||||
|
sm.update_msgs((stamp + 30_000_000) / 1e9, [packet.as_reader()])
|
||||||
|
sm.alive[service] = sm.freq_ok[service] = True
|
||||||
|
assert card._feedback_capture(stamp + 30_000_000) is not None
|
||||||
|
assert card._feedback_capture(source.expires_ns + 1) is None
|
||||||
|
assert decode.call_count == 3
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ from collections import deque
|
|||||||
|
|
||||||
from openpilot.cereal import log
|
from openpilot.cereal import log
|
||||||
from opendbc.car import structs
|
from opendbc.car import structs
|
||||||
|
from opendbc.car.honda.values import CAR as HONDA_CAR, HondaFlags
|
||||||
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
||||||
from opendbc.car.lateral import FRICTION_THRESHOLD, get_friction
|
from opendbc.car.lateral import FRICTION_THRESHOLD, get_friction
|
||||||
from opendbc.car.toyota import legacy_advert_filter
|
from opendbc.car.toyota import legacy_advert_filter
|
||||||
@@ -53,7 +54,14 @@ class LatControlTorque(LatControl):
|
|||||||
and not CP.flags & HyundaiFlags.CANFD_ANGLE_STEERING
|
and not CP.flags & HyundaiFlags.CANFD_ANGLE_STEERING
|
||||||
and not (CP.notCar or CP.passive or CP.dashcamOnly)
|
and not (CP.notCar or CP.passive or CP.dashcamOnly)
|
||||||
)
|
)
|
||||||
|
self.kona_se_highway_friction = bool(
|
||||||
|
CP.brand == 'hyundai' and CP.carFingerprint == CAR.HYUNDAI_KONA_EV_2023_NON_SCC and
|
||||||
|
CP.steerControlType == structs.CarParams.SteerControlType.torque and
|
||||||
|
not (CP.notCar or CP.passive or CP.dashcamOnly))
|
||||||
self.controller_mode = default_selection(CP).mode if controller_mode is None else ControllerMode(controller_mode)
|
self.controller_mode = default_selection(CP).mode if controller_mode is None else ControllerMode(controller_mode)
|
||||||
|
self.accord_center_friction = (self.controller_mode == ControllerMode.STARPILOT and
|
||||||
|
CP.carFingerprint == HONDA_CAR.HONDA_ACCORD_9G and CP.openpilotLongitudinalControl and
|
||||||
|
bool(CP.flags & HondaFlags.GAS_INTERCEPTOR) and not CP.flags & HondaFlags.EPS_MODIFIED)
|
||||||
self.sienna_center_friction = (self.controller_mode == ControllerMode.STANDARD and
|
self.sienna_center_friction = (self.controller_mode == ControllerMode.STANDARD and
|
||||||
CP.carFingerprint == TOYOTA_CAR.TOYOTA_SIENNA and legacy_advert_filter.enabled(CP))
|
CP.carFingerprint == TOYOTA_CAR.TOYOTA_SIENNA and legacy_advert_filter.enabled(CP))
|
||||||
self.controller_policy = policy_for(CP)
|
self.controller_policy = policy_for(CP)
|
||||||
@@ -97,7 +105,7 @@ class LatControlTorque(LatControl):
|
|||||||
self.pid.set_limits(self.lateral_accel_from_torque(self.steer_max, self.torque_params), self.lateral_accel_from_torque(-self.steer_max, self.torque_params))
|
self.pid.set_limits(self.lateral_accel_from_torque(self.steer_max, self.torque_params), self.lateral_accel_from_torque(-self.steer_max, self.torque_params))
|
||||||
|
|
||||||
def friction(self, error, deadzone, threshold, CS, setpoint):
|
def friction(self, error, deadzone, threshold, CS, setpoint):
|
||||||
if self.hkg_canfd_torque and not CS.steeringPressed:
|
if (self.hkg_canfd_torque or self.kona_se_highway_friction) and not CS.steeringPressed:
|
||||||
weight = np.interp(CS.vEgo, [50 * CV.MPH_TO_MS, 65 * CV.MPH_TO_MS], [0.0, 1.0])
|
weight = np.interp(CS.vEgo, [50 * CV.MPH_TO_MS, 65 * CV.MPH_TO_MS], [0.0, 1.0])
|
||||||
weight *= np.interp(abs(setpoint), [0.25, 0.65], [1.0, 0.0])
|
weight *= np.interp(abs(setpoint), [0.25, 0.65], [1.0, 0.0])
|
||||||
threshold += max(np.interp(CS.vEgo, [65 * CV.MPH_TO_MS, 75 * CV.MPH_TO_MS], [0.65, 0.78]) - threshold, 0.0) * weight
|
threshold += max(np.interp(CS.vEgo, [65 * CV.MPH_TO_MS, 75 * CV.MPH_TO_MS], [0.65, 0.78]) - threshold, 0.0) * weight
|
||||||
@@ -107,6 +115,10 @@ class LatControlTorque(LatControl):
|
|||||||
speed_weight = np.interp(CS.vEgo * CV.MS_TO_MPH, [34., 39., 50., 56.], [0., 1., 1., 0.])
|
speed_weight = np.interp(CS.vEgo * CV.MS_TO_MPH, [34., 39., 50., 56.], [0., 1., 1., 0.])
|
||||||
center_weight = np.interp(abs(setpoint), [0.22, 0.58], [1., 0.])
|
center_weight = np.interp(abs(setpoint), [0.22, 0.58], [1., 0.])
|
||||||
friction *= 1.0 - 0.5 * speed_weight * center_weight
|
friction *= 1.0 - 0.5 * speed_weight * center_weight
|
||||||
|
if self.accord_center_friction and not CS.steeringPressed:
|
||||||
|
speed_weight = np.interp(CS.vEgo * CV.MS_TO_MPH, [50., 58.], [0., 1.])
|
||||||
|
center_weight = np.interp(abs(setpoint), [0.30, 0.60], [1., 0.])
|
||||||
|
friction *= 1.0 - 0.80 * speed_weight * center_weight
|
||||||
return friction
|
return friction
|
||||||
|
|
||||||
def update(self, active, CS, VM, params, steer_limited_by_safety, desired_curvature, curvature_limited, lat_delay):
|
def update(self, active, CS, VM, params, steer_limited_by_safety, desired_curvature, curvature_limited, lat_delay):
|
||||||
|
|||||||
@@ -197,7 +197,9 @@ class LongitudinalPlanner:
|
|||||||
self.manual_cruise_step_until_ns = 0
|
self.manual_cruise_step_until_ns = 0
|
||||||
self.model_lead_history.clear()
|
self.model_lead_history.clear()
|
||||||
self.plan_drive_id = drive_id
|
self.plan_drive_id = drive_id
|
||||||
faster_takeoffs = bool(faster_lead_takeoff)
|
model_y_no_lead_takeoff = (faster_lead_takeoff and self.CP.carFingerprint == 'TESLA_MODEL_Y' and
|
||||||
|
not any(lead.present for lead in (sm['radarState'].leadOne, sm['radarState'].leadTwo)))
|
||||||
|
faster_takeoffs = bool(faster_lead_takeoff and not model_y_no_lead_takeoff)
|
||||||
accel_ceiling = TAKEOFF_ACCEL_MAX if faster_takeoffs else ACCEL_MAX
|
accel_ceiling = TAKEOFF_ACCEL_MAX if faster_takeoffs else ACCEL_MAX
|
||||||
if self.max_accel_override is not None:
|
if self.max_accel_override is not None:
|
||||||
accel_ceiling = min(accel_ceiling, self.max_accel_override)
|
accel_ceiling = min(accel_ceiling, self.max_accel_override)
|
||||||
@@ -611,6 +613,9 @@ class LongitudinalPlanner:
|
|||||||
output_a_target, self.output_should_stop = self.ford_stop_approach.sample(
|
output_a_target, self.output_should_stop = self.ford_stop_approach.sample(
|
||||||
sm, now_ns=sample_now_ns, drive_id=drive_id, target=float(output_a_target),
|
sm, now_ns=sample_now_ns, drive_id=drive_id, target=float(output_a_target),
|
||||||
stopping=self.output_should_stop, accel_min=ACCEL_MIN, active=profile_eligible and not reset_state)
|
stopping=self.output_should_stop, accel_min=ACCEL_MIN, active=profile_eligible and not reset_state)
|
||||||
|
if model_y_no_lead_takeoff and not reset_state and not self.output_should_stop and abs(v_ego) <= MIN_ALLOW_THROTTLE_SPEED:
|
||||||
|
# Cruise can be preloaded while CEM holds the brakes. Ramp from the published target when it releases.
|
||||||
|
output_a_target = min(output_a_target, max(0., a_prev) + J_CRUISE_VALS[0] * self.dt)
|
||||||
self.output_a_target = np.clip(output_a_target, ACCEL_MIN, 0. if downhill_error is not None else accel_ceiling)
|
self.output_a_target = np.clip(output_a_target, ACCEL_MIN, 0. if downhill_error is not None else accel_ceiling)
|
||||||
|
|
||||||
self.v_desired_filter.x = self.v_desired_filter.x + self.dt * (self.output_a_target + a_prev) / 2.0
|
self.v_desired_filter.x = self.v_desired_filter.x + self.dt * (self.output_a_target + a_prev) / 2.0
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -388,11 +388,11 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool button_expected = false;
|
bool button_expected = false;
|
||||||
for (const uint16_t old_word : {0x1400U, 0x1C00U, 0x1440U, 0x1C40U, 0x1402U, 0x1C02U, 0x1441U, 0x1C41U}) {
|
for (const uint16_t old_word : {0x1400U, 0x1C00U, 0x1440U, 0x1C40U, 0x1402U, 0x1C02U, 0x1441U, 0x1C41U, 0x1C51U}) {
|
||||||
button_expected |= word == (old_word | 0x20U);
|
button_expected |= word == (old_word | 0x20U);
|
||||||
}
|
}
|
||||||
const bool expected = button_expected || word == 0x2000U || word == 0x2004U || word == 0x2010U || word == 0x2014U || word == 0x0500U || word == 0x0D00U || long_expected || scc_expected || word == 0x1400U || word == 0x1C00U || word == 0x1440U || word == 0x1C40U ||
|
const bool expected = button_expected || word == 0x2000U || word == 0x2004U || word == 0x2010U || word == 0x2014U || word == 0x0500U || word == 0x0D00U || long_expected || scc_expected || word == 0x1400U || word == 0x1C00U || word == 0x1440U || word == 0x1C40U ||
|
||||||
word == 0x1402U || word == 0x1C02U || word == 0x1441U || word == 0x1C41U;
|
word == 0x1402U || word == 0x1C02U || word == 0x1441U || word == 0x1C41U || word == 0x1C51U;
|
||||||
assert(aol_capable(forte, HYUNDAI_CLASSIC_AOL_PROFILE.mode, VEHICLE_REGISTRY) == expected);
|
assert(aol_capable(forte, HYUNDAI_CLASSIC_AOL_PROFILE.mode, VEHICLE_REGISTRY) == expected);
|
||||||
assert(aol_runtime_enabled(false, forte, VEHICLE_REGISTRY) == expected);
|
assert(aol_runtime_enabled(false, forte, VEHICLE_REGISTRY) == expected);
|
||||||
forte.capability_flags = 0U;
|
forte.capability_flags = 0U;
|
||||||
|
|||||||
@@ -236,6 +236,15 @@ def user_soft_disable_alert(alert_text_2: str) -> AlertCallbackType:
|
|||||||
return UserSoftDisableAlert(alert_text_2)
|
return UserSoftDisableAlert(alert_text_2)
|
||||||
return func
|
return func
|
||||||
|
|
||||||
|
def temporary_steering_advisory(CP, CS, sm, metric, soft_disable_time, personality) -> Alert:
|
||||||
|
from opendbc.car.mazda.stock_aol import qualified as mazda_aol_qualified
|
||||||
|
|
||||||
|
mazda_aol = mazda_aol_qualified(CP, marked_only=True)
|
||||||
|
return Alert("Steering Assist Temporarily Unavailable", "", AlertStatus.userPrompt, AlertSize.small,
|
||||||
|
Priority.LOW, VisualAlert.none if mazda_aol else VisualAlert.steerRequired,
|
||||||
|
AudibleAlert.none if mazda_aol else AudibleAlert.prompt, 1.8)
|
||||||
|
|
||||||
|
|
||||||
def startup_master_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int, personality) -> Alert:
|
def startup_master_alert(CP: car.CarParams, CS: car.CarState, sm: messaging.SubMaster, metric: bool, soft_disable_time: int, personality) -> Alert:
|
||||||
branch = get_short_branch() # Ensure get_short_branch is cached to avoid lags on startup
|
branch = get_short_branch() # Ensure get_short_branch is cached to avoid lags on startup
|
||||||
if "REPLAY" in os.environ:
|
if "REPLAY" in os.environ:
|
||||||
@@ -511,11 +520,7 @@ EVENTS: dict[int, dict[str, Alert | AlertCallbackType]] = {
|
|||||||
# ********** events only containing alerts that display while engaged **********
|
# ********** events only containing alerts that display while engaged **********
|
||||||
|
|
||||||
EventName.steerTempUnavailableSilent: {
|
EventName.steerTempUnavailableSilent: {
|
||||||
ET.WARNING: Alert(
|
ET.WARNING: temporary_steering_advisory,
|
||||||
"Steering Assist Temporarily Unavailable",
|
|
||||||
"",
|
|
||||||
AlertStatus.userPrompt, AlertSize.small,
|
|
||||||
Priority.LOW, VisualAlert.steerRequired, AudibleAlert.prompt, 1.8),
|
|
||||||
},
|
},
|
||||||
|
|
||||||
EventName.driverDistracted1: {
|
EventName.driverDistracted1: {
|
||||||
|
|||||||
@@ -1617,6 +1617,13 @@ class SelfdriveD:
|
|||||||
if physical_cancel_lateral_allowed(self.CP, CS, intent, native, settings=self.aol_settings,
|
if physical_cancel_lateral_allowed(self.CP, CS, intent, native, settings=self.aol_settings,
|
||||||
previous=decision, source_ns=source_ns, now_ns=now_ns, axis_session_id=self.aol_session_id):
|
previous=decision, source_ns=source_ns, now_ns=now_ns, axis_session_id=self.aol_session_id):
|
||||||
user_disable = any(event.userDisable and event.name != EventName.buttonCancel for event in self.events.to_msg())
|
user_disable = any(event.userDisable and event.name != EventName.buttonCancel for event in self.events.to_msg())
|
||||||
|
if (user_disable and fresh_successor and proof[8] and self.CP.brand == 'volkswagen' and
|
||||||
|
decision.lateral_active and not decision.longitudinal_active):
|
||||||
|
from openpilot.starpilot.car.volkswagen.aol import physical_cancel_lateral_allowed
|
||||||
|
native = current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_session_id)
|
||||||
|
if physical_cancel_lateral_allowed(self.CP, CS, intent, native, settings=self.aol_settings,
|
||||||
|
previous=decision, source_ns=source_ns, now_ns=now_ns, axis_session_id=self.aol_session_id):
|
||||||
|
user_disable = any(event.userDisable and event.name != EventName.buttonCancel for event in self.events.to_msg())
|
||||||
if user_disable and fresh_successor and self.ford_source_deadline_supported():
|
if user_disable and fresh_successor and self.ford_source_deadline_supported():
|
||||||
from openpilot.starpilot.car.ford.aol import physical_cancel_lateral_allowed
|
from openpilot.starpilot.car.ford.aol import physical_cancel_lateral_allowed
|
||||||
native = current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_session_id)
|
native = current_native(self.sm, self.CP, now_ns=now_ns, axis_session_id=self.aol_session_id)
|
||||||
|
|||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
File diff suppressed because one or more lines are too long
Executable → Regular
+8
-3
@@ -12,11 +12,12 @@ from openpilot.common.git import get_commit
|
|||||||
from openpilot.tools.lib.openpilotci import get_url
|
from openpilot.tools.lib.openpilotci import get_url
|
||||||
from openpilot.selfdrive.test.process_replay.compare_logs import compare_logs, format_diff
|
from openpilot.selfdrive.test.process_replay.compare_logs import compare_logs, format_diff
|
||||||
from openpilot.selfdrive.test.process_replay.diff_report import diff_process, diff_report
|
from openpilot.selfdrive.test.process_replay.diff_report import diff_process, diff_report
|
||||||
from tools.ci.replay_fixture_cache import ARTIFACT_COMMIT, OPENPILOT_COMMIT, FIXTURES, verified_fixture_params
|
from tools.ci.replay_fixture_cache import ARTIFACT_COMMIT, B10_REPLAY_SEGMENT, OPENPILOT_COMMIT, FIXTURES, verified_b10_params, verified_fixture_params
|
||||||
from openpilot.selfdrive.test.process_replay.process_replay import CONFIGS, PROC_REPLAY_DIR, FAKEDATA, replay_process, \
|
from openpilot.selfdrive.test.process_replay.process_replay import CONFIGS, PROC_REPLAY_DIR, FAKEDATA, replay_process, \
|
||||||
check_most_messages_valid
|
check_most_messages_valid
|
||||||
from openpilot.tools.lib.filereader import FileReader
|
from openpilot.tools.lib.filereader import FileReader
|
||||||
from openpilot.tools.lib.logreader import LogReader, save_log
|
from openpilot.tools.lib.logreader import LogReader, save_log
|
||||||
|
from openpilot.tools.lib.route import Route
|
||||||
from openpilot.tools.lib.url_file import URLFile
|
from openpilot.tools.lib.url_file import URLFile
|
||||||
from tools.ci.process_replay_coverage import replay_coverage, write_coverage
|
from tools.ci.process_replay_coverage import replay_coverage, write_coverage
|
||||||
from tools.ci.run_vehicle_tests import targets_for
|
from tools.ci.run_vehicle_tests import targets_for
|
||||||
@@ -65,6 +66,7 @@ segments = [
|
|||||||
("FORD", "regen755D8CB1E1F|2025-04-08--23-13-43--0"),
|
("FORD", "regen755D8CB1E1F|2025-04-08--23-13-43--0"),
|
||||||
("RIVIAN", "regen5FCAC896BBE|2025-04-08--23-13-35--0"),
|
("RIVIAN", "regen5FCAC896BBE|2025-04-08--23-13-35--0"),
|
||||||
("TESLA", "aebd8f1d4ea16066|000002d8--5850d3ea5c--2"),
|
("TESLA", "aebd8f1d4ea16066|000002d8--5850d3ea5c--2"),
|
||||||
|
("LEAPMOTOR", B10_REPLAY_SEGMENT), # LEAPMOTOR.LEAPMOTOR_B10
|
||||||
]
|
]
|
||||||
|
|
||||||
# dashcamOnly makes don't need to be tested until a full port is done
|
# dashcamOnly makes don't need to be tested until a full port is done
|
||||||
@@ -100,8 +102,11 @@ def run_test_process(data):
|
|||||||
|
|
||||||
def get_log_data(segment):
|
def get_log_data(segment):
|
||||||
r, n = segment.rsplit("--", 1)
|
r, n = segment.rsplit("--", 1)
|
||||||
with FileReader(get_url(r, n, "rlog.zst")) as f:
|
path = Route(r).log_paths()[int(n)] if segment == B10_REPLAY_SEGMENT else get_url(r, n, "rlog.zst")
|
||||||
|
with FileReader(path) as f:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
|
if segment == B10_REPLAY_SEGMENT:
|
||||||
|
return segment, raw, verified_b10_params(raw)
|
||||||
custom_params = verified_fixture_params(segment, raw) if segment in FIXTURES else None
|
custom_params = verified_fixture_params(segment, raw) if segment in FIXTURES else None
|
||||||
return (segment, raw, custom_params)
|
return (segment, raw, custom_params)
|
||||||
|
|
||||||
@@ -223,7 +228,7 @@ if __name__ == "__main__":
|
|||||||
cur_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{cur_commit}.zst".replace("|", "_"))
|
cur_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{cur_commit}.zst".replace("|", "_"))
|
||||||
if args.update_refs: # reference logs will not exist if routes were just regenerated
|
if args.update_refs: # reference logs will not exist if routes were just regenerated
|
||||||
route, seg_num = segment.rsplit("--", 1)
|
route, seg_num = segment.rsplit("--", 1)
|
||||||
ref_log_path = get_url(route, seg_num, "rlog.zst")
|
ref_log_path = Route(route).log_paths()[int(seg_num)] if segment == B10_REPLAY_SEGMENT else get_url(route, seg_num, "rlog.zst")
|
||||||
else:
|
else:
|
||||||
ref_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{ref_commit}.zst".replace("|", "_"))
|
ref_log_fn = os.path.join(FAKEDATA, f"{segment}_{cfg.proc_name}_{ref_commit}.zst".replace("|", "_"))
|
||||||
if ref_commit == OPENPILOT_COMMIT:
|
if ref_commit == OPENPILOT_COMMIT:
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from openpilot.selfdrive.ui.mici.onroad.driver_state import DriverStateRenderer
|
|||||||
from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer
|
from openpilot.selfdrive.ui.mici.onroad.hud_renderer import HudRenderer
|
||||||
from openpilot.selfdrive.ui.mici.onroad.long_indicator import LongIndicator
|
from openpilot.selfdrive.ui.mici.onroad.long_indicator import LongIndicator
|
||||||
from openpilot.selfdrive.ui.mici.onroad.model_renderer import ModelRenderer
|
from openpilot.selfdrive.ui.mici.onroad.model_renderer import ModelRenderer
|
||||||
|
from openpilot.starpilot.ui.path_markers import PathMarkerInput
|
||||||
from openpilot.selfdrive.ui.mici.onroad.navigation import NavigationPanel, PANEL_WIDTH
|
from openpilot.selfdrive.ui.mici.onroad.navigation import NavigationPanel, PANEL_WIDTH
|
||||||
from openpilot.selfdrive.ui.mici.onroad.confidence_ball import ConfidenceBall
|
from openpilot.selfdrive.ui.mici.onroad.confidence_ball import ConfidenceBall
|
||||||
from openpilot.selfdrive.ui.mici.onroad.cameraview import CameraView
|
from openpilot.selfdrive.ui.mici.onroad.cameraview import CameraView
|
||||||
@@ -252,10 +253,8 @@ class AugmentedRoadView(CameraView):
|
|||||||
self._fade_texture = gui_app.texture("icons_mici/onroad/onroad_fade.png")
|
self._fade_texture = gui_app.texture("icons_mici/onroad/onroad_fade.png")
|
||||||
|
|
||||||
def render_camera_model_layer(self, rect: rl.Rectangle, *, camera_view: int = CAMERA_VIEW_AUTO,
|
def render_camera_model_layer(self, rect: rl.Rectangle, *, camera_view: int = CAMERA_VIEW_AUTO,
|
||||||
reverse_driver: bool = False, lead_indicator: bool = False,
|
reverse_driver: bool = False, markers: PathMarkerInput | None = None,
|
||||||
lead_info_mode: int = 0, lead_info_metric: bool | None = None,
|
road_style: dict | None = None, paint: bool = True, poll_camera: bool = True) -> None:
|
||||||
lateral_active: bool = False, road_style: dict | None = None, paint: bool = True,
|
|
||||||
poll_camera: bool = True) -> None:
|
|
||||||
"""Draw the existing calibrated camera/model without stock HUD or alert."""
|
"""Draw the existing calibrated camera/model without stock HUD or alert."""
|
||||||
if not ui_state.started and ui_state.replay_clock is None:
|
if not ui_state.started and ui_state.replay_clock is None:
|
||||||
return
|
return
|
||||||
@@ -282,8 +281,7 @@ class AugmentedRoadView(CameraView):
|
|||||||
self._model_renderer.road_style = road_style or {}
|
self._model_renderer.road_style = road_style or {}
|
||||||
gui_app.measure_frame_phase("camera", CameraView._render, self, rect, paint=paint, poll_camera=poll_camera)
|
gui_app.measure_frame_phase("camera", CameraView._render, self, rect, paint=paint, poll_camera=poll_camera)
|
||||||
if target != DRIVER_CAM and self.frame is not None:
|
if target != DRIVER_CAM and self.frame is not None:
|
||||||
gui_app.measure_frame_phase("model", self._model_renderer.render_with_lead, rect, lead_indicator,
|
gui_app.measure_frame_phase("model", self._model_renderer.render_with_markers, rect, markers, paint=paint)
|
||||||
lead_info_mode, lead_info_metric, lateral_active=lateral_active, paint=paint)
|
|
||||||
|
|
||||||
def render_model_source_layer(self, rect: rl.Rectangle, *, show_long_indicator: bool | None = False) -> None:
|
def render_model_source_layer(self, rect: rl.Rectangle, *, show_long_indicator: bool | None = False) -> None:
|
||||||
self._hud_renderer._draw_model_source(rect)
|
self._hud_renderer._draw_model_source(rect)
|
||||||
|
|||||||
@@ -1,23 +1,18 @@
|
|||||||
import math
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from openpilot.starpilot.ui.raylib import rl
|
from openpilot.starpilot.ui.raylib import rl
|
||||||
from openpilot.cereal import log, messaging
|
from openpilot.cereal import messaging
|
||||||
from opendbc.car.structs import car
|
from opendbc.car.structs import car
|
||||||
from types import SimpleNamespace
|
|
||||||
from openpilot.common.params import Params
|
from openpilot.common.params import Params
|
||||||
from openpilot.starpilot.ui.appearance_preferences import format_lead_info
|
from openpilot.starpilot.ui.path_markers import PathMarkers, valid_lead_numbers
|
||||||
from openpilot.starpilot.ui.rainbow_path import RainbowPath
|
from openpilot.starpilot.ui.rainbow_path import RainbowPath
|
||||||
from openpilot.starpilot.ui.road_colors import lane_color, lead_marker_color, path_mode, solid_gradient
|
from openpilot.starpilot.ui.road_colors import lane_color, path_mode, solid_gradient
|
||||||
from openpilot.starpilot.ui.onroad_customization import ROAD_COLORS
|
from openpilot.starpilot.ui.onroad_customization import ROAD_COLORS
|
||||||
from openpilot.starpilot.lateral.lane_feedback import BLUE, direction as lane_centering_direction
|
from openpilot.starpilot.lateral.lane_feedback import BLUE, direction as lane_centering_direction
|
||||||
from openpilot.common.filter_simple import FirstOrderFilter
|
from openpilot.common.filter_simple import FirstOrderFilter
|
||||||
from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT
|
from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT
|
||||||
from openpilot.selfdrive.controls.radard import RADAR_TO_CAMERA
|
|
||||||
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
|
from openpilot.selfdrive.ui.ui_state import ui_state, UIStatus
|
||||||
from openpilot.selfdrive.ui.mici.onroad import blend_colors
|
from openpilot.selfdrive.ui.mici.onroad import blend_colors
|
||||||
from openpilot.system.ui.lib.application import gui_app
|
from openpilot.system.ui.lib.application import gui_app
|
||||||
from openpilot.system.ui.lib.application import FontWeight
|
|
||||||
from openpilot.system.ui.lib.text_measure import measure_text_cached
|
|
||||||
from openpilot.system.ui.lib.shader_polygon import draw_polygon, Gradient
|
from openpilot.system.ui.lib.shader_polygon import draw_polygon, Gradient
|
||||||
from openpilot.system.ui.widgets import Widget
|
from openpilot.system.ui.widgets import Widget
|
||||||
from openpilot.selfdrive.ui.onroad.model_renderer import ModelGeometry, ModelPoints
|
from openpilot.selfdrive.ui.onroad.model_renderer import ModelGeometry, ModelPoints
|
||||||
@@ -25,8 +20,6 @@ from openpilot.selfdrive.ui.onroad.model_renderer import ModelGeometry, ModelPoi
|
|||||||
CLIP_MARGIN = 500
|
CLIP_MARGIN = 500
|
||||||
MIN_DRAW_DISTANCE = 10.0
|
MIN_DRAW_DISTANCE = 10.0
|
||||||
MAX_DRAW_DISTANCE = 100.0
|
MAX_DRAW_DISTANCE = 100.0
|
||||||
LEAD_BAR_LENGTH = 12.0
|
|
||||||
LEAD_BAR_WIDTH = 1.8
|
|
||||||
|
|
||||||
THROTTLE_COLORS = [
|
THROTTLE_COLORS = [
|
||||||
rl.Color(13, 248, 122, 102), # HSLF(148/360, 0.94, 0.51, 0.4)
|
rl.Color(13, 248, 122, 102), # HSLF(148/360, 0.94, 0.51, 0.4)
|
||||||
@@ -47,20 +40,10 @@ LANE_LINE_COLORS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ModelRenderer(PathMarkers, ModelGeometry, Widget):
|
||||||
|
LINE_PX = (2, 4)
|
||||||
|
LEAD_INFO_FONT = 32
|
||||||
|
|
||||||
|
|
||||||
class LeadVehicle:
|
|
||||||
def __init__(self):
|
|
||||||
self.info = None
|
|
||||||
self.bar = np.empty((0, 2), dtype=np.float32)
|
|
||||||
self.d_filter = FirstOrderFilter(0.0, 0.2, 1 / gui_app.target_fps, initialized=False)
|
|
||||||
self.y_filter = FirstOrderFilter(0.0, 0.2, 1 / gui_app.target_fps, initialized=False)
|
|
||||||
self.fade_filter = FirstOrderFilter(0.0, 0.1, 1 / gui_app.target_fps)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelRenderer(ModelGeometry, Widget):
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._longitudinal_control = False
|
self._longitudinal_control = False
|
||||||
@@ -72,12 +55,7 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
self._lane_line_probs = np.zeros(4, dtype=np.float32)
|
self._lane_line_probs = np.zeros(4, dtype=np.float32)
|
||||||
self._lane_centering_direction = 0
|
self._lane_centering_direction = 0
|
||||||
self._road_edge_stds = np.zeros(2, dtype=np.float32)
|
self._road_edge_stds = np.zeros(2, dtype=np.float32)
|
||||||
self._lead_vehicles = [LeadVehicle(), LeadVehicle()]
|
self._init_markers()
|
||||||
self._leads_need_reset = False
|
|
||||||
self._lead_indicator_enabled = False
|
|
||||||
self._lead_info_mode = 0
|
|
||||||
self._lead_info_metric = None
|
|
||||||
self._render_lateral_active = False
|
|
||||||
self._path_offset_z = HEIGHT_INIT[0]
|
self._path_offset_z = HEIGHT_INIT[0]
|
||||||
|
|
||||||
# Initialize ModelPoints objects
|
# Initialize ModelPoints objects
|
||||||
@@ -113,24 +91,9 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
self._longitudinal_control = cp.openpilotLongitudinalControl
|
self._longitudinal_control = cp.openpilotLongitudinalControl
|
||||||
|
|
||||||
|
|
||||||
def render_with_lead(self, rect: rl.Rectangle, enabled: bool, info_mode: int = 0, metric: bool | None = None,
|
def _draw_offset(self) -> tuple[float, float]:
|
||||||
lateral_active: bool = False, paint: bool = True):
|
# the car space transform maps to rect-origin space
|
||||||
self._lead_indicator_enabled = enabled
|
return self._rect.x, self._rect.y
|
||||||
self._lead_info_mode = info_mode
|
|
||||||
self._lead_info_metric = metric
|
|
||||||
self._render_lateral_active = lateral_active
|
|
||||||
self._paint = paint
|
|
||||||
try:
|
|
||||||
return self.render(rect)
|
|
||||||
finally:
|
|
||||||
self._lead_indicator_enabled = False
|
|
||||||
self._lead_info_mode = 0
|
|
||||||
self._lead_info_metric = None
|
|
||||||
self._render_lateral_active = False
|
|
||||||
self._paint = True
|
|
||||||
|
|
||||||
def _visual_status(self) -> UIStatus:
|
|
||||||
return UIStatus.ENGAGED if ui_state.status == UIStatus.DISENGAGED and getattr(self, '_render_lateral_active', False) else ui_state.status
|
|
||||||
|
|
||||||
def _render(self, rect: rl.Rectangle):
|
def _render(self, rect: rl.Rectangle):
|
||||||
sm = ui_state.sm
|
sm = ui_state.sm
|
||||||
@@ -163,9 +126,8 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
model = sm['modelV2']
|
model = sm['modelV2']
|
||||||
radar_state = sm['radarState'] if sm.valid['radarState'] else None
|
radar_state = sm['radarState'] if sm.valid['radarState'] else None
|
||||||
lead_one = radar_state.leadOne if radar_state else None
|
lead_one = radar_state.leadOne if radar_state else None
|
||||||
if lead_one and lead_one.present and not self._valid_lead_numbers(lead_one):
|
if lead_one and lead_one.present and not valid_lead_numbers(lead_one):
|
||||||
lead_one = None
|
lead_one = None
|
||||||
render_lead_indicator = self._lead_indicator_enabled
|
|
||||||
|
|
||||||
# Update model data when needed
|
# Update model data when needed
|
||||||
model_updated = sm.updated['modelV2']
|
model_updated = sm.updated['modelV2']
|
||||||
@@ -180,113 +142,13 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
self._update_model(lead_one, path_x_array, update_lane_geometry=model_updated or self._transform_dirty)
|
self._update_model(lead_one, path_x_array, update_lane_geometry=model_updated or self._transform_dirty)
|
||||||
self._transform_dirty = False
|
self._transform_dirty = False
|
||||||
|
|
||||||
lead_ready = render_lead_indicator and bool(self._path.raw_points.size)
|
self._update_markers(sm)
|
||||||
if lead_ready:
|
|
||||||
self._update_leads(sm)
|
|
||||||
self._leads_need_reset = True
|
|
||||||
elif getattr(self, "_leads_need_reset", True):
|
|
||||||
self._lead_vehicles = [LeadVehicle(), LeadVehicle()]
|
|
||||||
self._leads_need_reset = False
|
|
||||||
|
|
||||||
# Draw elements (hide when disengaged)
|
# Draw elements (hide when disengaged)
|
||||||
if self._visual_status() != UIStatus.DISENGAGED:
|
if self._visual_status() != UIStatus.DISENGAGED:
|
||||||
self._draw_lane_lines()
|
self._draw_lane_lines()
|
||||||
self._draw_path(sm)
|
self._draw_path(sm)
|
||||||
|
self._draw_markers()
|
||||||
if lead_ready and getattr(self, '_paint', True):
|
|
||||||
self._draw_lead_indicator()
|
|
||||||
if self._lead_vehicles[0].bar.size and self._lead_vehicles[0].info is not None:
|
|
||||||
text = self._format_lead_info(self._lead_vehicles[0].info, self._lead_info_mode, self._lead_info_metric)
|
|
||||||
if text:
|
|
||||||
self._draw_lead_info(rect, text)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _draw_lead_info(rect: rl.Rectangle, text: str) -> None:
|
|
||||||
font = gui_app.font(FontWeight.SEMI_BOLD)
|
|
||||||
size = measure_text_cached(font, text, 40)
|
|
||||||
x, y = rect.x + (rect.width - size.x) / 2, rect.y + 22
|
|
||||||
for dx, dy in ((-1, -1), (1, -1), (-1, 1), (1, 1)):
|
|
||||||
rl.draw_text_ex(font, text, rl.Vector2(x + dx, y + dy), 40, 0, rl.BLACK)
|
|
||||||
rl.draw_text_ex(font, text, rl.Vector2(x, y), 40, 0, rl.WHITE)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _format_lead_info(lead, mode: int, metric: bool | None) -> str:
|
|
||||||
return format_lead_info(lead, mode, metric)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _valid_lead_numbers(lead) -> bool:
|
|
||||||
try:
|
|
||||||
distance, lateral = float(lead.dRel), float(lead.yRel)
|
|
||||||
relative_speed = float(lead.vRel) if lead.vRel is not None else 0.0
|
|
||||||
return distance > 0 and all(math.isfinite(value) for value in (distance, lateral, relative_speed))
|
|
||||||
except (AttributeError, TypeError, ValueError, OverflowError):
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def _update_leads(self, sm):
|
|
||||||
plan = sm['longitudinalPlan']
|
|
||||||
model = sm['modelV2']
|
|
||||||
e2e = (sm.valid['longitudinalPlan'] and sm.valid['modelV2'] and
|
|
||||||
plan.longitudinalPlanSource == log.LongitudinalPlan.LongitudinalPlanSource.e2e and len(model.leadsV3) > 1)
|
|
||||||
ego_speed = sm['carState'].vEgo if e2e and sm.all_checks(['carState']) else None
|
|
||||||
if ego_speed is not None and not math.isfinite(ego_speed):
|
|
||||||
ego_speed = None
|
|
||||||
leads = []
|
|
||||||
for index in range(2):
|
|
||||||
info = None
|
|
||||||
if e2e:
|
|
||||||
candidate = model.leadsV3[index]
|
|
||||||
if candidate.x and candidate.y and candidate.v:
|
|
||||||
info = SimpleNamespace(present=candidate.prob > 0.5, dRel=candidate.x[0] - RADAR_TO_CAMERA,
|
|
||||||
yRel=-candidate.y[0], vRel=candidate.v[0] - ego_speed if ego_speed is not None else None,
|
|
||||||
vLead=candidate.v[0])
|
|
||||||
elif sm.valid['radarState']:
|
|
||||||
info = (sm['radarState'].leadOne, sm['radarState'].leadTwo)[index]
|
|
||||||
valid = info is not None and info.present and self._valid_lead_numbers(info)
|
|
||||||
distance = float(info.dRel) + RADAR_TO_CAMERA if valid else 0.0
|
|
||||||
leads.append((valid, distance, float(info.yRel) if valid else 0.0, info if valid else None))
|
|
||||||
if leads[0][0] and leads[1][0] and abs(leads[1][1] - leads[0][1]) < 3.0:
|
|
||||||
leads[1] = (False, 0.0, 0.0, None)
|
|
||||||
|
|
||||||
ss, cs = sm['selfdriveState'], sm['carState']
|
|
||||||
available = ss.enabled or ss.engageable or cs.brakePressed or getattr(self, '_render_lateral_active', False)
|
|
||||||
lane = self._path.raw_points
|
|
||||||
geometry_valid = len(lane) > 0 and len(self._path.raw_points) > 0 and np.isfinite(lane).all() and np.isfinite(self._path.raw_points).all()
|
|
||||||
opacity = 0.4 if self._visual_status() == UIStatus.DISENGAGED else 0.8
|
|
||||||
for lead, (present, d_rel, y_rel, info) in zip(self._lead_vehicles, leads, strict=True):
|
|
||||||
visible = available and present and d_rel < MAX_DRAW_DISTANCE and geometry_valid
|
|
||||||
if not visible or abs(y_rel - lead.y_filter.x) > 3.0:
|
|
||||||
lead.d_filter.initialized = lead.y_filter.initialized = False
|
|
||||||
lead.fade_filter.update(opacity if visible else 0.0)
|
|
||||||
lead.info = info if visible else None
|
|
||||||
if visible:
|
|
||||||
lead.bar = self._get_lead_bar(lane, lead.d_filter.update(d_rel), lead.y_filter.update(y_rel))
|
|
||||||
if not lead.bar.size:
|
|
||||||
lead.info = None
|
|
||||||
lead.fade_filter.update(0.0)
|
|
||||||
elif not present or not geometry_valid:
|
|
||||||
lead.bar = np.empty((0, 2), dtype=np.float32)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_lead_bar(self, lane, d_rel, y_rel):
|
|
||||||
# bar on the road behind the lead, following the lane
|
|
||||||
x = np.array([d_rel, d_rel - min(6.0, 0.25 * d_rel)])
|
|
||||||
y = np.interp(x, lane[:, 0], lane[:, 1]) - np.interp(d_rel, lane[:, 0], lane[:, 1]) - y_rel
|
|
||||||
z = np.interp(x, self._path.raw_points[:, 0], self._path.raw_points[:, 2]) + self._path_offset_z
|
|
||||||
corners = np.vstack((np.column_stack((x, y + LEAD_BAR_WIDTH / 2, z)), np.column_stack((x, y - LEAD_BAR_WIDTH / 2, z))[::-1]))
|
|
||||||
pts = self._car_space_transform @ corners.T
|
|
||||||
if not np.isfinite(pts).all() or np.any(np.abs(pts[2]) < 1e-6):
|
|
||||||
return np.empty((0, 2), dtype=np.float32)
|
|
||||||
bar = (pts[:2] / pts[2]).T
|
|
||||||
|
|
||||||
far, near = bar[[0, 3]], bar[[1, 2]]
|
|
||||||
length = np.linalg.norm(near.mean(axis=0) - far.mean(axis=0))
|
|
||||||
if not math.isfinite(length) or length < 1e-6:
|
|
||||||
return np.empty((0, 2), dtype=np.float32)
|
|
||||||
bar[[1, 2]] = far + (near - far) * np.clip(length, 3.0, LEAD_BAR_LENGTH) / length
|
|
||||||
return bar.astype(np.float32)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _update_model(self, lead, path_x_array, *, update_lane_geometry: bool = True):
|
def _update_model(self, lead, path_x_array, *, update_lane_geometry: bool = True):
|
||||||
"""Update model visualization data based on model message"""
|
"""Update model visualization data based on model message"""
|
||||||
@@ -488,16 +350,6 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
else:
|
else:
|
||||||
draw_polygon(self._rect, path_pts, gradient=gradient)
|
draw_polygon(self._rect, path_pts, gradient=gradient)
|
||||||
|
|
||||||
def _draw_lead_indicator(self):
|
|
||||||
offset = np.array([self._rect.x, self._rect.y], dtype=np.float32)
|
|
||||||
for lead in self._lead_vehicles:
|
|
||||||
if not lead.bar.size or lead.fade_filter.x <= 0:
|
|
||||||
continue
|
|
||||||
color = lead_marker_color(self.road_style, lead.fade_filter.x)
|
|
||||||
draw_polygon(self._rect, lead.bar + offset, color if color is not None else rl.Color(255, 255, 255, int(255 * lead.fade_filter.x)))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_path_length_idx(pos_x_array: np.ndarray, path_height: float) -> int:
|
def _get_path_length_idx(pos_x_array: np.ndarray, path_height: float) -> int:
|
||||||
"""Get the index corresponding to the given path height"""
|
"""Get the index corresponding to the given path height"""
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from openpilot.selfdrive.ui.onroad.alert_renderer import AlertRenderer
|
|||||||
from openpilot.selfdrive.ui.onroad.driver_state import DriverStateRenderer
|
from openpilot.selfdrive.ui.onroad.driver_state import DriverStateRenderer
|
||||||
from openpilot.selfdrive.ui.onroad.hud_renderer import HudRenderer
|
from openpilot.selfdrive.ui.onroad.hud_renderer import HudRenderer
|
||||||
from openpilot.selfdrive.ui.onroad.model_renderer import ModelRenderer
|
from openpilot.selfdrive.ui.onroad.model_renderer import ModelRenderer
|
||||||
|
from openpilot.starpilot.ui.path_markers import PathMarkerInput
|
||||||
from openpilot.selfdrive.ui.onroad.cameraview import CameraView
|
from openpilot.selfdrive.ui.onroad.cameraview import CameraView
|
||||||
from openpilot.system.ui.lib.application import gui_app
|
from openpilot.system.ui.lib.application import gui_app
|
||||||
from openpilot.common.transformations.camera import DEVICE_CAMERAS, DeviceCameraConfig, view_frame_from_device_frame
|
from openpilot.common.transformations.camera import DEVICE_CAMERAS, DeviceCameraConfig, view_frame_from_device_frame
|
||||||
@@ -52,7 +53,7 @@ class AugmentedRoadView(CameraView):
|
|||||||
|
|
||||||
def render_camera_model_layer(self, rect: rl.Rectangle, *, camera_view: int = CAMERA_VIEW_AUTO,
|
def render_camera_model_layer(self, rect: rl.Rectangle, *, camera_view: int = CAMERA_VIEW_AUTO,
|
||||||
reverse_driver: bool = False, road_style: dict | None = None,
|
reverse_driver: bool = False, road_style: dict | None = None,
|
||||||
lead_display: tuple[bool, int, bool | None] | None = None, poll_camera: bool = True) -> None:
|
markers: PathMarkerInput | None = None, poll_camera: bool = True) -> None:
|
||||||
"""Draw the existing calibrated camera/model without stock HUD or alert."""
|
"""Draw the existing calibrated camera/model without stock HUD or alert."""
|
||||||
if not ui_state.started and ui_state.replay_clock is None:
|
if not ui_state.started and ui_state.replay_clock is None:
|
||||||
return
|
return
|
||||||
@@ -74,10 +75,9 @@ class AugmentedRoadView(CameraView):
|
|||||||
if ("pathEdge" in getattr(self.model_renderer, "road_style", {})) != ("pathEdge" in style):
|
if ("pathEdge" in getattr(self.model_renderer, "road_style", {})) != ("pathEdge" in style):
|
||||||
self.model_renderer._transform_dirty = True
|
self.model_renderer._transform_dirty = True
|
||||||
self.model_renderer.road_style = style
|
self.model_renderer.road_style = style
|
||||||
self.model_renderer.lead_display = lead_display
|
|
||||||
gui_app.measure_frame_phase("camera", CameraView._render, self, rect, poll_camera=poll_camera)
|
gui_app.measure_frame_phase("camera", CameraView._render, self, rect, poll_camera=poll_camera)
|
||||||
if target != DRIVER_CAM:
|
if target != DRIVER_CAM:
|
||||||
gui_app.measure_frame_phase("model", self.model_renderer.render, rect)
|
gui_app.measure_frame_phase("model", self.model_renderer.render_with_markers, rect, markers)
|
||||||
|
|
||||||
def render_model_source_layer(self, rect: rl.Rectangle, *, show_long_indicator: bool | None = False) -> None:
|
def render_model_source_layer(self, rect: rl.Rectangle, *, show_long_indicator: bool | None = False) -> None:
|
||||||
self._hud_renderer._draw_model_source(rect)
|
self._hud_renderer._draw_model_source(rect)
|
||||||
|
|||||||
@@ -6,15 +6,14 @@ from opendbc.car.structs import car
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from openpilot.common.filter_simple import FirstOrderFilter
|
from openpilot.common.filter_simple import FirstOrderFilter
|
||||||
from openpilot.common.params import Params
|
from openpilot.common.params import Params
|
||||||
from openpilot.starpilot.ui.appearance_preferences import format_lead_info
|
from openpilot.starpilot.ui.path_markers import PathMarkers
|
||||||
from openpilot.starpilot.ui.rainbow_path import RainbowPath
|
from openpilot.starpilot.ui.rainbow_path import RainbowPath
|
||||||
from openpilot.starpilot.ui.road_colors import edge_gradient, lane_color, lead_marker_color, path_mode, solid_gradient
|
from openpilot.starpilot.ui.road_colors import edge_gradient, lane_color, path_mode, solid_gradient
|
||||||
from openpilot.starpilot.ui.onroad_customization import ROAD_COLORS
|
from openpilot.starpilot.ui.onroad_customization import ROAD_COLORS
|
||||||
from openpilot.starpilot.lateral.lane_feedback import BLUE, direction as lane_centering_direction
|
from openpilot.starpilot.lateral.lane_feedback import BLUE, direction as lane_centering_direction
|
||||||
from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT
|
from openpilot.selfdrive.locationd.calibrationd import HEIGHT_INIT
|
||||||
from openpilot.selfdrive.ui.ui_state import ui_state
|
from openpilot.selfdrive.ui.ui_state import ui_state
|
||||||
from openpilot.system.ui.lib.application import FontWeight, gui_app
|
from openpilot.system.ui.lib.application import gui_app
|
||||||
from openpilot.system.ui.lib.text_measure import measure_text_cached
|
|
||||||
from openpilot.system.ui.lib.shader_polygon import draw_polygon, Gradient
|
from openpilot.system.ui.lib.shader_polygon import draw_polygon, Gradient
|
||||||
from openpilot.system.ui.widgets import Widget
|
from openpilot.system.ui.widgets import Widget
|
||||||
|
|
||||||
@@ -41,13 +40,6 @@ class ModelPoints:
|
|||||||
projected_points: np.ndarray = field(default_factory=lambda: np.empty((0, 2), dtype=np.float32))
|
projected_points: np.ndarray = field(default_factory=lambda: np.empty((0, 2), dtype=np.float32))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class LeadVehicle:
|
|
||||||
glow: list[tuple[float, float]] = field(default_factory=list)
|
|
||||||
chevron: list[tuple[float, float]] = field(default_factory=list)
|
|
||||||
fill_alpha: int = 0
|
|
||||||
|
|
||||||
|
|
||||||
class ModelGeometry:
|
class ModelGeometry:
|
||||||
_path: ModelPoints
|
_path: ModelPoints
|
||||||
_lane_lines: list[ModelPoints]
|
_lane_lines: list[ModelPoints]
|
||||||
@@ -106,7 +98,11 @@ class ModelGeometry:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ModelRenderer(ModelGeometry, Widget):
|
class ModelRenderer(PathMarkers, ModelGeometry, Widget):
|
||||||
|
LINE_PX = (12, 28)
|
||||||
|
LEAD_INFO_FONT = LEAD_INFO_MIN = 77 # 96 px drawn: digits near 22 arcmin at 70 cm (ISO 15008 recommends 20)
|
||||||
|
UNIT_SCALE = 32 / 77 # 40 px drawn, the HUD's label size
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._longitudinal_control = False
|
self._longitudinal_control = False
|
||||||
@@ -118,9 +114,7 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
self._lane_line_probs = np.zeros(4, dtype=np.float32)
|
self._lane_line_probs = np.zeros(4, dtype=np.float32)
|
||||||
self._lane_centering_direction = 0
|
self._lane_centering_direction = 0
|
||||||
self._road_edge_stds = np.zeros(2, dtype=np.float32)
|
self._road_edge_stds = np.zeros(2, dtype=np.float32)
|
||||||
self._lead_vehicles = [LeadVehicle(), LeadVehicle()]
|
self._init_markers()
|
||||||
# (show marker, LeadInfoMode, metric) from a screen with its own lead choices; None keeps the stock chevrons.
|
|
||||||
self.lead_display: tuple[bool, int, bool | None] | None = None
|
|
||||||
self._path_offset_z = HEIGHT_INIT[0]
|
self._path_offset_z = HEIGHT_INIT[0]
|
||||||
|
|
||||||
# Initialize ModelPoints objects
|
# Initialize ModelPoints objects
|
||||||
@@ -180,9 +174,6 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
model = sm['modelV2']
|
model = sm['modelV2']
|
||||||
radar_state = sm['radarState'] if sm.valid['radarState'] else None
|
radar_state = sm['radarState'] if sm.valid['radarState'] else None
|
||||||
lead_one = radar_state.leadOne if radar_state else None
|
lead_one = radar_state.leadOne if radar_state else None
|
||||||
lead_display = self.lead_display
|
|
||||||
show_lead = self._longitudinal_control if lead_display is None else lead_display[0]
|
|
||||||
render_lead_indicator = show_lead and radar_state is not None
|
|
||||||
|
|
||||||
# Update model data when needed
|
# Update model data when needed
|
||||||
model_updated = sm.updated['modelV2']
|
model_updated = sm.updated['modelV2']
|
||||||
@@ -195,37 +186,14 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self._update_model(lead_one, path_x_array, update_lane_geometry=model_updated or self._transform_dirty)
|
self._update_model(lead_one, path_x_array, update_lane_geometry=model_updated or self._transform_dirty)
|
||||||
if render_lead_indicator:
|
|
||||||
self._update_leads(radar_state, path_x_array)
|
|
||||||
self._transform_dirty = False
|
self._transform_dirty = False
|
||||||
|
|
||||||
|
self._update_markers(sm)
|
||||||
|
|
||||||
# Draw elements
|
# Draw elements
|
||||||
self._draw_lane_lines()
|
self._draw_lane_lines()
|
||||||
self._draw_path(sm)
|
self._draw_path(sm)
|
||||||
|
self._draw_markers()
|
||||||
if render_lead_indicator and radar_state:
|
|
||||||
self._draw_lead_indicator()
|
|
||||||
if lead_display is not None and self._lead_vehicles[0].chevron:
|
|
||||||
text = format_lead_info(lead_one, lead_display[1], lead_display[2])
|
|
||||||
if text:
|
|
||||||
self._draw_lead_info(self._lead_vehicles[0], text)
|
|
||||||
|
|
||||||
|
|
||||||
def _update_leads(self, radar_state, path_x_array):
|
|
||||||
"""Update positions of lead vehicles"""
|
|
||||||
self._lead_vehicles = [LeadVehicle(), LeadVehicle()]
|
|
||||||
leads = [radar_state.leadOne, radar_state.leadTwo]
|
|
||||||
|
|
||||||
for i, lead_data in enumerate(leads):
|
|
||||||
if lead_data and lead_data.present:
|
|
||||||
d_rel, y_rel, v_rel = lead_data.dRel, lead_data.yRel, lead_data.vRel
|
|
||||||
idx = self._get_path_length_idx(path_x_array, d_rel)
|
|
||||||
|
|
||||||
# Get z-coordinate from path at the lead vehicle position
|
|
||||||
z = self._path.raw_points[idx, 2] if idx < len(self._path.raw_points) else 0.0
|
|
||||||
point = self._map_to_screen(d_rel, -y_rel, z + self._path_offset_z)
|
|
||||||
if point:
|
|
||||||
self._lead_vehicles[i] = self._update_lead_vehicle(d_rel, v_rel, point, self._rect)
|
|
||||||
|
|
||||||
def _update_model(self, lead, path_x_array, *, update_lane_geometry: bool = True):
|
def _update_model(self, lead, path_x_array, *, update_lane_geometry: bool = True):
|
||||||
"""Update model visualization data based on model message"""
|
"""Update model visualization data based on model message"""
|
||||||
@@ -309,30 +277,6 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
stops=gradient_stops,
|
stops=gradient_stops,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _update_lead_vehicle(self, d_rel, v_rel, point, rect):
|
|
||||||
speed_buff, lead_buff = 10.0, 40.0
|
|
||||||
|
|
||||||
# Calculate fill alpha
|
|
||||||
fill_alpha = 0
|
|
||||||
if d_rel < lead_buff:
|
|
||||||
fill_alpha = 255 * (1.0 - (d_rel / lead_buff))
|
|
||||||
if v_rel < 0:
|
|
||||||
fill_alpha += 255 * (-1 * (v_rel / speed_buff))
|
|
||||||
fill_alpha = min(fill_alpha, 255)
|
|
||||||
|
|
||||||
# Calculate size and position
|
|
||||||
sz = np.clip((25 * 30) / (d_rel / 3 + 30), 15.0, 30.0) * 2.35
|
|
||||||
x = np.clip(point[0], 0.0, rect.width - sz / 2)
|
|
||||||
y = min(point[1], rect.height - sz * 0.6)
|
|
||||||
|
|
||||||
g_xo = sz / 5
|
|
||||||
g_yo = sz / 10
|
|
||||||
|
|
||||||
glow = [(x + (sz * 1.35) + g_xo, y + sz + g_yo), (x, y - g_yo), (x - (sz * 1.35) - g_xo, y + sz + g_yo)]
|
|
||||||
chevron = [(x + (sz * 1.25), y + sz), (x, y), (x - (sz * 1.25), y + sz)]
|
|
||||||
|
|
||||||
return LeadVehicle(glow=glow, chevron=chevron, fill_alpha=int(fill_alpha))
|
|
||||||
|
|
||||||
def _draw_lane_lines(self):
|
def _draw_lane_lines(self):
|
||||||
"""Draw lane lines and road edges"""
|
"""Draw lane lines and road edges"""
|
||||||
self._lane_centering_direction = lane_centering_direction(ui_state.sm, ui_state.display_time_ns(), ui_state.started_frame)
|
self._lane_centering_direction = lane_centering_direction(ui_state.sm, ui_state.display_time_ns(), ui_state.started_frame)
|
||||||
@@ -407,29 +351,6 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
gradient = self._default_path_gradient
|
gradient = self._default_path_gradient
|
||||||
draw_polygon(self._rect, self._path.projected_points, gradient=gradient)
|
draw_polygon(self._rect, self._path.projected_points, gradient=gradient)
|
||||||
|
|
||||||
def _draw_lead_indicator(self):
|
|
||||||
# Draw lead vehicles if available
|
|
||||||
for lead in self._lead_vehicles:
|
|
||||||
if not lead.glow or not lead.chevron:
|
|
||||||
continue
|
|
||||||
|
|
||||||
style = self.road_style
|
|
||||||
glow = lead_marker_color(style, 1.0)
|
|
||||||
fill = lead_marker_color(style, lead.fill_alpha / 255)
|
|
||||||
rl.draw_triangle_fan(lead.glow, len(lead.glow), glow if glow is not None else rl.Color(218, 202, 37, 255))
|
|
||||||
rl.draw_triangle_fan(lead.chevron, len(lead.chevron), fill if fill is not None else rl.Color(201, 34, 49, lead.fill_alpha))
|
|
||||||
|
|
||||||
def _draw_lead_info(self, lead: LeadVehicle, text: str) -> None:
|
|
||||||
# Centered just above the chevron's glow, kept on screen.
|
|
||||||
font = gui_app.font(FontWeight.SEMI_BOLD)
|
|
||||||
size = measure_text_cached(font, text, 48)
|
|
||||||
tip_x, tip_y = lead.glow[1]
|
|
||||||
x = min(max(tip_x - size.x / 2, self._rect.x), self._rect.x + self._rect.width - size.x)
|
|
||||||
y = max(tip_y - size.y - 12, self._rect.y)
|
|
||||||
for dx, dy in ((-1, -1), (1, -1), (-1, 1), (1, 1)):
|
|
||||||
rl.draw_text_ex(font, text, rl.Vector2(x + dx, y + dy), 48, 0, rl.BLACK)
|
|
||||||
rl.draw_text_ex(font, text, rl.Vector2(x, y), 48, 0, rl.WHITE)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_path_length_idx(pos_x_array: np.ndarray, path_distance: float) -> int:
|
def _get_path_length_idx(pos_x_array: np.ndarray, path_distance: float) -> int:
|
||||||
"""Get the index corresponding to the given path distance"""
|
"""Get the index corresponding to the given path distance"""
|
||||||
@@ -438,22 +359,6 @@ class ModelRenderer(ModelGeometry, Widget):
|
|||||||
indices = np.where(pos_x_array <= path_distance)[0]
|
indices = np.where(pos_x_array <= path_distance)[0]
|
||||||
return indices[-1] if indices.size > 0 else 0
|
return indices[-1] if indices.size > 0 else 0
|
||||||
|
|
||||||
def _map_to_screen(self, in_x, in_y, in_z):
|
|
||||||
"""Project a point in car space to screen space"""
|
|
||||||
input_pt = np.array([in_x, in_y, in_z])
|
|
||||||
pt = self._car_space_transform @ input_pt
|
|
||||||
|
|
||||||
if abs(pt[2]) < 1e-6:
|
|
||||||
return None
|
|
||||||
|
|
||||||
x, y = pt[0] / pt[2], pt[1] / pt[2]
|
|
||||||
|
|
||||||
clip = self._clip_region
|
|
||||||
if not (clip.x <= x <= clip.x + clip.width and clip.y <= y <= clip.y + clip.height):
|
|
||||||
return None
|
|
||||||
|
|
||||||
return (x, y)
|
|
||||||
|
|
||||||
def _map_lines_to_polygons(self, lines: list[np.ndarray], widths: list[float], z_off: float, max_idx: int,
|
def _map_lines_to_polygons(self, lines: list[np.ndarray], widths: list[float], z_off: float, max_idx: int,
|
||||||
max_distance: float, allow_invert: bool = True) -> list[np.ndarray]:
|
max_distance: float, allow_invert: bool = True) -> list[np.ndarray]:
|
||||||
if len(lines) != len(widths):
|
if len(lines) != len(widths):
|
||||||
|
|||||||
@@ -120,32 +120,22 @@ def test_transform_guard_preserves_render_projection_updates(renderer, monkeypat
|
|||||||
monkeypatch.setattr(model_renderer, "ui_state", SimpleNamespace(sm=sm, started_frame=0))
|
monkeypatch.setattr(model_renderer, "ui_state", SimpleNamespace(sm=sm, started_frame=0))
|
||||||
renderer._torque_filter = Mock()
|
renderer._torque_filter = Mock()
|
||||||
renderer._path = SimpleNamespace(raw_points=np.array([[10, 0, 0]], dtype=np.float32))
|
renderer._path = SimpleNamespace(raw_points=np.array([[10, 0, 0]], dtype=np.float32))
|
||||||
renderer._lead_indicator_enabled = False
|
|
||||||
renderer._visual_status = lambda: model_renderer.UIStatus.DISENGAGED
|
renderer._visual_status = lambda: model_renderer.UIStatus.DISENGAGED
|
||||||
renderer._update_model = Mock()
|
renderer._update_model = Mock()
|
||||||
renderer._update_raw_points = Mock()
|
renderer._update_raw_points = Mock()
|
||||||
|
renderer._update_markers = Mock()
|
||||||
|
renderer._draw_markers = Mock()
|
||||||
renderer._transform_dirty = True
|
renderer._transform_dirty = True
|
||||||
|
|
||||||
renderer._render(renderer._clip_region)
|
renderer._render(renderer._clip_region)
|
||||||
assert renderer._update_model.call_count == 1
|
assert renderer._update_model.call_count == 1
|
||||||
assert not renderer._transform_dirty
|
assert not renderer._transform_dirty
|
||||||
disabled_leads = renderer._lead_vehicles
|
|
||||||
renderer.set_transform(renderer._car_space_transform.copy())
|
renderer.set_transform(renderer._car_space_transform.copy())
|
||||||
renderer._render(renderer._clip_region)
|
renderer._render(renderer._clip_region)
|
||||||
assert renderer._update_model.call_count == 1
|
assert renderer._update_model.call_count == 1
|
||||||
assert renderer._lead_vehicles is disabled_leads
|
# markers keep time every frame, whether or not the model geometry changed
|
||||||
renderer._lead_indicator_enabled = True
|
assert renderer._update_markers.call_count == renderer._draw_markers.call_count == 2
|
||||||
renderer._update_leads = Mock()
|
renderer._update_markers.assert_called_with(sm)
|
||||||
renderer._draw_lead_indicator = Mock()
|
|
||||||
renderer._render(renderer._clip_region)
|
|
||||||
renderer._update_leads.assert_called_once_with(sm)
|
|
||||||
renderer._lead_indicator_enabled = False
|
|
||||||
renderer._render(renderer._clip_region)
|
|
||||||
reset_leads = renderer._lead_vehicles
|
|
||||||
assert reset_leads is not disabled_leads
|
|
||||||
assert all(lead.info is None and not lead.bar.size for lead in reset_leads)
|
|
||||||
renderer._render(renderer._clip_region)
|
|
||||||
assert renderer._lead_vehicles is reset_leads
|
|
||||||
changed = renderer._car_space_transform.copy()
|
changed = renderer._car_space_transform.copy()
|
||||||
changed[0, 0] += 1
|
changed[0, 0] += 1
|
||||||
renderer.set_transform(changed)
|
renderer.set_transform(changed)
|
||||||
@@ -226,7 +216,7 @@ def test_radar_only_reuses_lane_geometry_without_changing_path_filters_or_clip(r
|
|||||||
assert batch_calls[-1].kwargs['z_offsets'] == (0, 0, 0, 0, 0, 0, renderer._path_offset_z)
|
assert batch_calls[-1].kwargs['z_offsets'] == (0, 0, 0, 0, 0, 0, renderer._path_offset_z)
|
||||||
|
|
||||||
|
|
||||||
def test_large_render_preserves_lead_cadence_and_lane_invalidation(renderer, monkeypatch):
|
def test_large_render_updates_markers_every_frame_and_keeps_lane_invalidation(renderer, monkeypatch):
|
||||||
from openpilot.selfdrive.ui.onroad import model_renderer
|
from openpilot.selfdrive.ui.onroad import model_renderer
|
||||||
|
|
||||||
class Messages(dict):
|
class Messages(dict):
|
||||||
@@ -239,21 +229,20 @@ def test_large_render_preserves_lead_cadence_and_lane_invalidation(renderer, mon
|
|||||||
radarState=SimpleNamespace(leadOne=None))
|
radarState=SimpleNamespace(leadOne=None))
|
||||||
monkeypatch.setattr(model_renderer, "ui_state", SimpleNamespace(sm=sm, started_frame=0))
|
monkeypatch.setattr(model_renderer, "ui_state", SimpleNamespace(sm=sm, started_frame=0))
|
||||||
view = object.__new__(LargeModelRenderer)
|
view = object.__new__(LargeModelRenderer)
|
||||||
view.lead_display = None
|
|
||||||
view._path = ModelPoints(raw_points=np.array([[10, 0, 0]], dtype=np.float32))
|
view._path = ModelPoints(raw_points=np.array([[10, 0, 0]], dtype=np.float32))
|
||||||
view._longitudinal_control = True
|
view._longitudinal_control = True
|
||||||
view._update_model = Mock()
|
view._update_model = Mock()
|
||||||
view._update_raw_points = Mock()
|
view._update_raw_points = Mock()
|
||||||
view._update_leads = Mock()
|
view._update_markers = Mock()
|
||||||
view._draw_lane_lines = Mock()
|
view._draw_lane_lines = Mock()
|
||||||
view._draw_path = Mock()
|
view._draw_path = Mock()
|
||||||
view._draw_lead_indicator = Mock()
|
view._draw_markers = Mock()
|
||||||
view._transform_dirty = True
|
view._transform_dirty = True
|
||||||
view._render(renderer._clip_region)
|
view._render(renderer._clip_region)
|
||||||
assert view._update_model.call_args.kwargs == {"update_lane_geometry": True}
|
assert view._update_model.call_args.kwargs == {"update_lane_geometry": True}
|
||||||
assert not view._transform_dirty
|
assert not view._transform_dirty
|
||||||
view._render(renderer._clip_region)
|
view._render(renderer._clip_region)
|
||||||
assert view._update_model.call_count == view._update_leads.call_count == 1
|
assert view._update_model.call_count == 1
|
||||||
sm.updated["radarState"] = True
|
sm.updated["radarState"] = True
|
||||||
view._render(renderer._clip_region)
|
view._render(renderer._clip_region)
|
||||||
assert view._update_model.call_args.kwargs == {"update_lane_geometry": False}
|
assert view._update_model.call_args.kwargs == {"update_lane_geometry": False}
|
||||||
@@ -262,5 +251,5 @@ def test_large_render_preserves_lead_cadence_and_lane_invalidation(renderer, mon
|
|||||||
view._render(renderer._clip_region)
|
view._render(renderer._clip_region)
|
||||||
assert view._update_model.call_args.kwargs == {"update_lane_geometry": True}
|
assert view._update_model.call_args.kwargs == {"update_lane_geometry": True}
|
||||||
view._update_raw_points.assert_called_once_with(sm["modelV2"])
|
view._update_raw_points.assert_called_once_with(sm["modelV2"])
|
||||||
assert view._update_model.call_count == view._update_leads.call_count == 3
|
assert view._update_model.call_count == 3
|
||||||
assert view._draw_path.call_count == view._draw_lead_indicator.call_count == 4
|
assert view._update_markers.call_count == view._draw_path.call_count == view._draw_markers.call_count == 4
|
||||||
|
|||||||
@@ -19598,7 +19598,7 @@ msgid "show speed limits"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
|
|||||||
@@ -19600,8 +19600,8 @@ msgid "show speed limits"
|
|||||||
msgstr "Geschwindigkeitsbegrenzungen anzeigen"
|
msgstr "Geschwindigkeitsbegrenzungen anzeigen"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr "über der Markierung des vorausfahrenden Fahrzeugs angezeigt"
|
msgstr "unter der Linie des vorausfahrenden Fahrzeugs angezeigt"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
msgid "side camera"
|
msgid "side camera"
|
||||||
|
|||||||
@@ -19600,8 +19600,8 @@ msgid "show speed limits"
|
|||||||
msgstr "mostrar límites de velocidad"
|
msgstr "mostrar límites de velocidad"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr "se muestra sobre el marcador del precedente"
|
msgstr "se muestra bajo la línea del precedente"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
msgid "side camera"
|
msgid "side camera"
|
||||||
|
|||||||
@@ -19600,8 +19600,8 @@ msgid "show speed limits"
|
|||||||
msgstr "afficher les limites de vitesse"
|
msgstr "afficher les limites de vitesse"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr "affiché au-dessus du repère du véhicule de tête"
|
msgstr "affiché sous la ligne du véhicule de tête"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
msgid "side camera"
|
msgid "side camera"
|
||||||
|
|||||||
@@ -19596,8 +19596,8 @@ msgid "show speed limits"
|
|||||||
msgstr "速度制限を表示"
|
msgstr "速度制限を表示"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr "先行車マーカーの上に表示"
|
msgstr "先行車ラインの下に表示"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
msgid "side camera"
|
msgid "side camera"
|
||||||
|
|||||||
@@ -19596,8 +19596,8 @@ msgid "show speed limits"
|
|||||||
msgstr "제한 속도 표시"
|
msgstr "제한 속도 표시"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr "선행 차량 표시 위에 표시됨"
|
msgstr "선행 차량 선 아래에 표시됨"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
msgid "side camera"
|
msgid "side camera"
|
||||||
|
|||||||
@@ -19596,8 +19596,8 @@ msgid "show speed limits"
|
|||||||
msgstr "hiện giới hạn tốc độ"
|
msgstr "hiện giới hạn tốc độ"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr "hiện trên dấu xe trước"
|
msgstr "hiện dưới vạch xe trước"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
msgid "side camera"
|
msgid "side camera"
|
||||||
|
|||||||
@@ -22233,8 +22233,8 @@ msgid "show speed limits"
|
|||||||
msgstr "显示限速"
|
msgstr "显示限速"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/appearance_compact.py
|
#: openpilot/starpilot/ui/appearance_compact.py
|
||||||
msgid "shown above the lead marker"
|
msgid "shown below the lead line"
|
||||||
msgstr "显示在前车标记上方"
|
msgstr "显示在前车线下方"
|
||||||
|
|
||||||
#: openpilot/starpilot/ui/onroad_customization.py
|
#: openpilot/starpilot/ui/onroad_customization.py
|
||||||
msgid "side camera"
|
msgid "side camera"
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ class UIState:
|
|||||||
"starpilotLateralState",
|
"starpilotLateralState",
|
||||||
"starpilotNavigation",
|
"starpilotNavigation",
|
||||||
"longitudinalPlan",
|
"longitudinalPlan",
|
||||||
|
"starpilotLongitudinalPlan",
|
||||||
"gpsLocationExternal",
|
"gpsLocationExternal",
|
||||||
"gpsLocation",
|
"gpsLocation",
|
||||||
"navInstruction",
|
"navInstruction",
|
||||||
@@ -142,9 +143,12 @@ class UIState:
|
|||||||
*(["customReserved6", "cabinCameraState", "narrowRoadEncodeIdx", "wideRoadEncodeIdx", "cabinEncodeIdx"]
|
*(["customReserved6", "cabinCameraState", "narrowRoadEncodeIdx", "wideRoadEncodeIdx", "cabinEncodeIdx"]
|
||||||
if self.replay_clock is not None else []),
|
if self.replay_clock is not None else []),
|
||||||
],
|
],
|
||||||
ignore_alive=["slcVisionObservation", "starpilotSelfdriveState", "starpilotLateralState", "aolAxisState", "starpilotCarState"],
|
ignore_alive=["slcVisionObservation", "starpilotSelfdriveState", "starpilotLateralState", "aolAxisState", "starpilotCarState",
|
||||||
ignore_valid=["slcVisionObservation", "starpilotSelfdriveState", "starpilotLateralState", "aolAxisState", "starpilotCarState"],
|
"starpilotLongitudinalPlan"],
|
||||||
ignore_avg_freq=["slcVisionObservation", "starpilotSelfdriveState", "starpilotLateralState", "aolAxisState", "starpilotCarState"],
|
ignore_valid=["slcVisionObservation", "starpilotSelfdriveState", "starpilotLateralState", "aolAxisState", "starpilotCarState",
|
||||||
|
"starpilotLongitudinalPlan"],
|
||||||
|
ignore_avg_freq=["slcVisionObservation", "starpilotSelfdriveState", "starpilotLateralState", "aolAxisState", "starpilotCarState",
|
||||||
|
"starpilotLongitudinalPlan"],
|
||||||
)
|
)
|
||||||
|
|
||||||
self.prime_state = ProjectionPrimeState(self.params) if self.replay_clock is not None or isinstance(self.params, ProjectionParams) else PrimeState()
|
self.prime_state = ProjectionPrimeState(self.params) if self.replay_clock is not None or isinstance(self.params, ProjectionParams) else PrimeState()
|
||||||
|
|||||||
@@ -147,11 +147,14 @@ def disarming_fault(events, CS, *, temporary_ui_process_failure: bool = False,
|
|||||||
|
|
||||||
class AolCardIntent:
|
class AolCardIntent:
|
||||||
def __init__(self, settings: AolSettings, *, explicit_latch: bool = False, lkas_button_supported: bool = True,
|
def __init__(self, settings: AolSettings, *, explicit_latch: bool = False, lkas_button_supported: bool = True,
|
||||||
independent_cruise_buttons: bool = False, preserve_unassigned_cancel: bool = False):
|
independent_cruise_buttons: bool = False, preserve_unassigned_cancel: bool = False,
|
||||||
|
confirm_main_available: bool = False):
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.explicit_latch = explicit_latch
|
self.explicit_latch = explicit_latch
|
||||||
self.independent_cruise_buttons = independent_cruise_buttons
|
self.independent_cruise_buttons = independent_cruise_buttons
|
||||||
self.preserve_unassigned_cancel = preserve_unassigned_cancel
|
self.preserve_unassigned_cancel = preserve_unassigned_cancel
|
||||||
|
self.confirm_main_available = confirm_main_available
|
||||||
|
self._pending_main_arm_ns = 0
|
||||||
self.lkas_button_supported = lkas_button_supported
|
self.lkas_button_supported = lkas_button_supported
|
||||||
self.allowed_latch = False
|
self.allowed_latch = False
|
||||||
# Observational only: records the exact branch that changed True to False.
|
# Observational only: records the exact branch that changed True to False.
|
||||||
@@ -278,6 +281,12 @@ class AolCardIntent:
|
|||||||
self._record_latch_clear('disarming_fault')
|
self._record_latch_clear('disarming_fault')
|
||||||
self.allowed_latch = False
|
self.allowed_latch = False
|
||||||
self._gesture_neutral_seen = False
|
self._gesture_neutral_seen = False
|
||||||
|
if self._pending_main_arm_ns and (
|
||||||
|
not 0 < now_ns - self._pending_main_arm_ns <= 100_000_000 or not self.settings.enabled or
|
||||||
|
self._fault_inhibit or native_rejection_ns or not CS.canValid or CS.canTimeout or CS.accFaulted or
|
||||||
|
CS.vehicleSensorsInvalid or CS.gearShifter not in (GearShifter.drive, GearShifter.sport, GearShifter.low, GearShifter.brake) or
|
||||||
|
any(event.pressed for event in CS.buttonEvents)):
|
||||||
|
self._pending_main_arm_ns = 0
|
||||||
if not CS.canValid or CS.canTimeout:
|
if not CS.canValid or CS.canTimeout:
|
||||||
self._record_latch_clear('can_invalid_or_timeout')
|
self._record_latch_clear('can_invalid_or_timeout')
|
||||||
self.allowed_latch = False
|
self.allowed_latch = False
|
||||||
@@ -365,10 +374,21 @@ class AolCardIntent:
|
|||||||
lateral_engaged = not self.pause_lateral and (self.allowed_latch or standard_enabled)
|
lateral_engaged = not self.pause_lateral and (self.allowed_latch or standard_enabled)
|
||||||
if lateral_engaged:
|
if lateral_engaged:
|
||||||
self._record_latch_clear('physical_toggle')
|
self._record_latch_clear('physical_toggle')
|
||||||
self.allowed_latch = not lateral_engaged
|
if (self.confirm_main_available and not lateral_engaged and self._main_held and not self._lkas_held and
|
||||||
self.pause_lateral = lateral_engaged
|
not CS.cruiseState.available and now_ns > 0):
|
||||||
if not lateral_engaged:
|
if (not native_rejection_ns and not CS.vehicleSensorsInvalid and
|
||||||
self.physical_arm_ns = now_ns
|
CS.gearShifter in (GearShifter.drive, GearShifter.sport, GearShifter.low, GearShifter.brake)):
|
||||||
|
self._pending_main_arm_ns = now_ns
|
||||||
|
else:
|
||||||
|
self.allowed_latch = not lateral_engaged
|
||||||
|
self.pause_lateral = lateral_engaged
|
||||||
|
if not lateral_engaged:
|
||||||
|
self.physical_arm_ns = now_ns
|
||||||
|
|
||||||
|
if self._pending_main_arm_ns and CS.cruiseState.available:
|
||||||
|
self.physical_arm_ns = self._pending_main_arm_ns
|
||||||
|
self._pending_main_arm_ns = 0
|
||||||
|
self._arm_from_full_engagement(CS, source_ns=now_ns)
|
||||||
|
|
||||||
for event in CS.buttonEvents:
|
for event in CS.buttonEvents:
|
||||||
button = int(event.type.raw)
|
button = int(event.type.raw)
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user