mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-29 00:03:57 +08:00
Compare commits
188 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| adca218266 | |||
| 92e09398e8 | |||
| 19d1cab0b3 | |||
| c6f6f64e77 | |||
| 50e07e8eef | |||
| b7953cf4a0 | |||
| df7d67c39f | |||
| 439ac2274e | |||
| 1066c1e0f2 | |||
| 76b76080f5 | |||
| 64fdc72c1e | |||
| 3831031635 | |||
| 27aeb44b41 | |||
| 988217726f | |||
| 954edb60af | |||
| 20bef284c6 | |||
| c194a0c092 | |||
| 54fa1a1875 | |||
| a46a504450 | |||
| d47bf5e636 | |||
| 8aa143deb0 | |||
| 3d6d69b70d | |||
| a43597aefe | |||
| 6d5d6c249f | |||
| de8f420d95 | |||
| 37f9e1a9d5 | |||
| 27a4566309 | |||
| f60c2147c0 | |||
| 240edccfd6 | |||
| 26e0f927bd | |||
| 4bf630534f | |||
| 6db575bded | |||
| b7d2723bf0 | |||
| 9b545fa585 | |||
| d0904dfaaf | |||
| 6938b22db9 | |||
| b56e624681 | |||
| 48717d2b08 | |||
| c3f5283aa4 | |||
| 04df2317fb | |||
| 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 | |||
| 670e65d35a | |||
| 0c52893246 | |||
| 4dbf3f18f5 | |||
| e6acb363ed | |||
| eb9f52a9fe | |||
| f0886a5a23 | |||
| 704d27bfce | |||
| fe89adeca1 | |||
| 25da2438a3 | |||
| 541af7124d | |||
| 81e08eb4f8 | |||
| 4b1644d4a6 | |||
| cf296a2c5d | |||
| fcb9fd0d39 | |||
| 544b9c0d6c | |||
| caa3b2a0f3 | |||
| 944e513e9f | |||
| 13ab471cc5 | |||
| 72aa8b89e1 | |||
| 14babc867a | |||
| 69acfbb085 | |||
| d4ddf420a5 | |||
| 73eb7961d7 | |||
| 273f8b12e8 | |||
| cc36b77b65 | |||
| 3ab9f67c83 | |||
| df47158568 | |||
| bc68e381ae | |||
| f15af75c3a | |||
| 1868dd0b90 | |||
| 5b21a4ba70 | |||
| 6d5466a32f | |||
| 5dbc1d51b6 | |||
| 48971bc6f9 | |||
| 6a958352e2 | |||
| bf8efea392 | |||
| 8f40396736 | |||
| b51d18fd56 | |||
| ac77f9a20c | |||
| 25323cef46 | |||
| b094bcb4f7 | |||
| ca16979a38 | |||
| fa0914406f | |||
| f86381d823 | |||
| 206a8554db | |||
| b32fc5ec98 | |||
| 22d4d34405 | |||
| 0b18c93532 | |||
| 0f8f2a5ace | |||
| a1084ad630 | |||
| 6509fa1a00 | |||
| f06a781387 | |||
| 5c20480f13 | |||
| 13b4344a06 | |||
| be196c0baa | |||
| bf0344ffd7 | |||
| 24b5235ed5 | |||
| 725a530d8e | |||
| 1a53844575 | |||
| eaeb680b0a | |||
| 7e9e2b43b3 | |||
| d0a212be98 |
@@ -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
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
tools/op.sh test \
|
tools/op.sh test \
|
||||||
openpilot/starpilot/flm/tests/test_offroad_backend.py \
|
openpilot/starpilot/flm/tests/test_offroad_backend.py \
|
||||||
|
openpilot/starpilot/flm/tests/test_offroad_report.py \
|
||||||
openpilot/starpilot/flm/tests/test_offroad_coordinate_policy.py \
|
openpilot/starpilot/flm/tests/test_offroad_coordinate_policy.py \
|
||||||
openpilot/starpilot/flm/tests/test_offroad_retained_trials.py \
|
openpilot/starpilot/flm/tests/test_offroad_retained_trials.py \
|
||||||
openpilot/starpilot/flm/tests/test_offroad_process_lifecycle.py \
|
openpilot/starpilot/flm/tests/test_offroad_process_lifecycle.py \
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -309,24 +343,29 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
uv pip install --python .venv/bin/python --only-binary av av==19.0.1
|
uv pip install --python .venv/bin/python --only-binary av av==19.0.1
|
||||||
.venv/bin/python -c "import av; assert 'libx264' in av.codecs_available"
|
.venv/bin/python -c "import av; assert 'libx264' in av.codecs_available"
|
||||||
|
- name: Provide pinned OpenCV DNN for vision contract tests
|
||||||
|
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||||
|
run: |
|
||||||
|
uv pip install --python .venv/bin/python --no-deps --only-binary :all: opencv-python-headless==4.11.0.86
|
||||||
|
.venv/bin/python -c "import cv2; assert cv2.__version__ == '4.11.0'; assert callable(cv2.dnn.readNetFromONNX); assert callable(cv2.dnn.NMSBoxes)"
|
||||||
- name: Provide Mesa software graphics for pixel-level tests
|
- name: Provide Mesa software graphics for pixel-level tests
|
||||||
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
|
||||||
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 +392,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 +476,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 +490,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 +518,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 +645,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 +655,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 +730,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 +740,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,11 +12,14 @@ 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.honda.discovery import nidec_bus0_topology, normal_bus_topology as honda_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,
|
||||||
|
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
|
||||||
from opendbc.car.mazda.discovery import normal_bus0_topology as mazda_normal_bus0_topology
|
from opendbc.car.mazda.discovery import normal_bus0_topology as mazda_normal_bus0_topology
|
||||||
from opendbc.car.chrysler.discovery import normal_bus_topology as chrysler_normal_bus_topology
|
from opendbc.car.chrysler.discovery import normal_bus_topology as chrysler_normal_bus_topology
|
||||||
@@ -117,7 +120,7 @@ def _tesla_fw_uses_normal_bus0() -> bool:
|
|||||||
# **** for use live only ****
|
# **** for use live only ****
|
||||||
def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_multiplexing: ObdCallback,
|
def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_multiplexing: ObdCallback,
|
||||||
cached_params: CarParamsT | None, *, known_gm_bus0: bool = False, known_ford_bus0: bool = False,
|
cached_params: CarParamsT | None, *, known_gm_bus0: bool = False, known_ford_bus0: bool = False,
|
||||||
known_tesla_bus0: bool = False
|
known_tesla_bus0: bool = False, known_honda_accord: bool = False
|
||||||
) -> tuple[str | None, dict, str, list[CarParams.CarFw], CarParams.FingerprintSource, bool]:
|
) -> tuple[str | None, dict, str, list[CarParams.CarFw], CarParams.FingerprintSource, bool]:
|
||||||
if known_ford_bus0 and (known_gm_bus0 or not ford_normal_bus0_queries()):
|
if known_ford_bus0 and (known_gm_bus0 or not ford_normal_bus0_queries()):
|
||||||
raise ValueError('Ford discovery topology no longer uses normal bus 0')
|
raise ValueError('Ford discovery topology no longer uses normal bus 0')
|
||||||
@@ -215,6 +218,15 @@ def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_mu
|
|||||||
else:
|
else:
|
||||||
car_fw = get_fw_versions(can_recv, can_send, set_obd_multiplexing,
|
car_fw = get_fw_versions(can_recv, can_send, set_obd_multiplexing,
|
||||||
query_brand=normal_brand, normal_bus_only=True)
|
query_brand=normal_brand, normal_bus_only=True)
|
||||||
|
if normal_brand == 'honda':
|
||||||
|
candidates = ({HONDA.HONDA_ACCORD} if known_honda_accord or fixed_fingerprint == HONDA.HONDA_ACCORD
|
||||||
|
else match_fw_to_car(car_fw, vin)[1])
|
||||||
|
if honda_eps_needs_obd(candidates, car_fw):
|
||||||
|
# The model can be selected manually even when radar and camera firmware alone don't identify it.
|
||||||
|
# Read the EPS over OBD before deciding which steering protocol to use.
|
||||||
|
set_obd_multiplexing(True)
|
||||||
|
vin_rx_addr, vin_rx_bus, vin = get_vin(can_recv, can_send, (0, 1))
|
||||||
|
car_fw = get_fw_versions(can_recv, can_send, set_obd_multiplexing, query_brand='honda')
|
||||||
ecu_rx_addrs = {(fw.responseAddress, fw.subAddress or None, fw.bus) for fw in car_fw if fw.responseAddress > 0}
|
ecu_rx_addrs = {(fw.responseAddress, fw.subAddress or None, fw.bus) for fw in car_fw if fw.responseAddress > 0}
|
||||||
else:
|
else:
|
||||||
full_scan = True
|
full_scan = True
|
||||||
@@ -263,6 +275,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.
|
||||||
@@ -309,6 +323,9 @@ def get_car(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_multip
|
|||||||
elif known_tesla_bus0:
|
elif known_tesla_bus0:
|
||||||
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(
|
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(
|
||||||
can_recv, can_send, set_obd_multiplexing, cached_params, known_tesla_bus0=True)
|
can_recv, can_send, set_obd_multiplexing, cached_params, known_tesla_bus0=True)
|
||||||
|
elif forced_candidate == HONDA.HONDA_ACCORD:
|
||||||
|
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(
|
||||||
|
can_recv, can_send, set_obd_multiplexing, cached_params, known_honda_accord=True)
|
||||||
else:
|
else:
|
||||||
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(can_recv, can_send, set_obd_multiplexing, cached_params)
|
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(can_recv, can_send, set_obd_multiplexing, cached_params)
|
||||||
|
|
||||||
@@ -327,6 +344,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
|
||||||
|
|||||||
@@ -375,6 +375,7 @@ FW_VERSIONS = {
|
|||||||
b'68402704AB',
|
b'68402704AB',
|
||||||
b'68402707AB',
|
b'68402707AB',
|
||||||
b'68402708AB',
|
b'68402708AB',
|
||||||
|
b'68402710AB',
|
||||||
b'68402714AB',
|
b'68402714AB',
|
||||||
b'68402736AB',
|
b'68402736AB',
|
||||||
b'68402971AD',
|
b'68402971AD',
|
||||||
@@ -421,6 +422,7 @@ FW_VERSIONS = {
|
|||||||
b'68412635AH ',
|
b'68412635AH ',
|
||||||
b'68412660AD ',
|
b'68412660AD ',
|
||||||
b'68412660AF ',
|
b'68412660AF ',
|
||||||
|
b'68422857AD',
|
||||||
b'68422860AB',
|
b'68422860AB',
|
||||||
b'68449435AE ',
|
b'68449435AE ',
|
||||||
b'68496223AA ',
|
b'68496223AA ',
|
||||||
@@ -435,6 +437,7 @@ FW_VERSIONS = {
|
|||||||
b'68419675AC',
|
b'68419675AC',
|
||||||
b'68419678AB',
|
b'68419678AB',
|
||||||
b'68423905AB',
|
b'68423905AB',
|
||||||
|
b'68423907AB',
|
||||||
b'68449258AC',
|
b'68449258AC',
|
||||||
b'68495807AA',
|
b'68495807AA',
|
||||||
b'68495807AB',
|
b'68495807AB',
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
"""Recorded ECU identity for the EU 2019 Grand Cherokee, opendbc issue 4101."""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from opendbc.car import structs
|
||||||
|
from opendbc.car.chrysler.interface import CarInterface
|
||||||
|
from opendbc.car.chrysler.values import CAR, ChryslerFlags
|
||||||
|
from opendbc.car.fingerprints import FW_VERSIONS
|
||||||
|
from opendbc.car.fw_versions import match_fw_to_car
|
||||||
|
|
||||||
|
Ecu = structs.CarParams.Ecu
|
||||||
|
RECORDED = (
|
||||||
|
(Ecu.combinationMeter, 0x742, b'68402710AB'),
|
||||||
|
(Ecu.srs, 0x744, b'68355363AB'),
|
||||||
|
(Ecu.abs, 0x747, b'68408639AC'),
|
||||||
|
(Ecu.fwdRadar, 0x753, b'04672788AA'),
|
||||||
|
(Ecu.eps, 0x75a, b'68417281AA'),
|
||||||
|
(Ecu.engine, 0x7e0, b'68422857AD'),
|
||||||
|
(Ecu.transmission, 0x7e1, b'68423907AB'),
|
||||||
|
)
|
||||||
|
ADDED = {b'68402710AB', b'68422857AD', b'68423907AB'}
|
||||||
|
|
||||||
|
|
||||||
|
def firmware():
|
||||||
|
return [structs.CarParams.CarFw(ecu=ecu, address=address, fwVersion=version, brand='chrysler', bus=0)
|
||||||
|
for ecu, address, version in RECORDED]
|
||||||
|
|
||||||
|
|
||||||
|
def test_recorded_eu_diesel_is_a_unique_exact_match():
|
||||||
|
fw = firmware()
|
||||||
|
assert match_fw_to_car(fw, '', allow_fuzzy=False, log=False) == (True, {CAR.JEEP_GRAND_CHEROKEE_2019})
|
||||||
|
# The route also contains unrelated cross-brand responses at the engine's neighbor.
|
||||||
|
fw.append(structs.CarParams.CarFw(ecu=Ecu.transmission, address=0x7e1, fwVersion=b'\xf1\0\0E\x01\x01', brand='hyundai', bus=1))
|
||||||
|
assert match_fw_to_car(fw, '', allow_fuzzy=False, log=False) == (True, {CAR.JEEP_GRAND_CHEROKEE_2019})
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('index', range(len(RECORDED)))
|
||||||
|
def test_unknown_firmware_still_refuses_exact_match(index):
|
||||||
|
fw = firmware()
|
||||||
|
fw[index].fwVersion = b'UNRECOGNIZED'
|
||||||
|
assert match_fw_to_car(fw, '', allow_fuzzy=False, log=False) == (True, set())
|
||||||
|
|
||||||
|
|
||||||
|
def test_additions_are_scoped_to_the_existing_2019_jeep():
|
||||||
|
for identity, ecus in FW_VERSIONS.items():
|
||||||
|
found = {version for versions in ecus.values() for version in versions} & ADDED
|
||||||
|
assert found == (ADDED if identity == CAR.JEEP_GRAND_CHEROKEE_2019 else set())
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('alpha_long', (False, True))
|
||||||
|
def test_diesel_retains_stock_acc_pid_and_native_limits(alpha_long):
|
||||||
|
cp = CarInterface.get_params(CAR.JEEP_GRAND_CHEROKEE_2019, {b: {} for b in range(8)}, firmware(), alpha_long, False, False)
|
||||||
|
assert cp.pcmCruise and not cp.openpilotLongitudinalControl
|
||||||
|
assert cp.safetyConfigs[0].safetyModel == structs.CarParams.SafetyModel.chrysler
|
||||||
|
assert cp.safetyConfigs[0].safetyParam == 0
|
||||||
|
assert cp.minSteerSpeed == 17.5 and cp.lateralTuning.which() == 'pid'
|
||||||
|
assert cp.flags & ChryslerFlags.HIGHER_MIN_STEERING_SPEED
|
||||||
|
assert not cp.flags & ChryslerFlags.STEERING_SPEED_BYPASS
|
||||||
@@ -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
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from opendbc.car import ACCEL_MAX_TAKEOFF
|
from opendbc.car import ACCEL_MAX_TAKEOFF
|
||||||
|
|
||||||
@@ -10,9 +12,12 @@ from opendbc.car.honda.nidec_interceptor import NidecInterceptor, create_command
|
|||||||
from opendbc.car.honda.bosch_longitudinal import BoschLongitudinal, qualified as bosch_long_qualified
|
from opendbc.car.honda.bosch_longitudinal import BoschLongitudinal, qualified as bosch_long_qualified
|
||||||
from opendbc.car.honda.values import CAR, CruiseButtons, HondaFlags, CarControllerParams
|
from opendbc.car.honda.values import CAR, CruiseButtons, HondaFlags, CarControllerParams
|
||||||
from opendbc.car.interfaces import CarControllerBase
|
from opendbc.car.interfaces import CarControllerBase
|
||||||
|
from opendbc.car.lateral import apply_steer_angle_limits_vm, get_max_angle_delta_vm
|
||||||
|
from opendbc.car.vehicle_model import VehicleModel
|
||||||
|
|
||||||
VisualAlert = structs.CarControl.HUDControl.VisualAlert
|
VisualAlert = structs.CarControl.HUDControl.VisualAlert
|
||||||
LongCtrlState = structs.CarControl.Actuators.LongControlState
|
LongCtrlState = structs.CarControl.Actuators.LongControlState
|
||||||
|
SteerControlType = structs.CarParams.SteerControlType
|
||||||
|
|
||||||
|
|
||||||
def compute_gb_honda_bosch(accel, speed):
|
def compute_gb_honda_bosch(accel, speed):
|
||||||
@@ -120,6 +125,54 @@ class CarController(CarControllerBase):
|
|||||||
self.brake = 0.0
|
self.brake = 0.0
|
||||||
self.last_torque = 0.0
|
self.last_torque = 0.0
|
||||||
|
|
||||||
|
# Accord angle-loop EPS (interface.py sets steerControlType = angle)
|
||||||
|
self.angle_mode = CP.steerControlType == SteerControlType.angle
|
||||||
|
self.VM = VehicleModel(CP) if self.angle_mode else None
|
||||||
|
self.apply_angle_last = None # None until the first frame seeds the limiter from the wheel
|
||||||
|
self.angle_steer_req = False # STEER_TORQUE_REQUEST of the last angle frame
|
||||||
|
|
||||||
|
def _angle_hold_allowed(self, CC, CS) -> bool:
|
||||||
|
# The panda blocks a nonzero 0xE4 field unless lateral_controls_allowed(). Without an AOL policy that is
|
||||||
|
# controls_allowed (needs ACC main on and engagement); with one it is a session-acknowledged axis permission the
|
||||||
|
# carcontroller cannot see, so the hold is sent only in the subset every policy allows: enabled with main on.
|
||||||
|
return bool(CS.out.cruiseState.available) and bool(CC.enabled)
|
||||||
|
|
||||||
|
def _update_angle(self, CC, CS) -> tuple[float, int]:
|
||||||
|
"""Angle setpoint (deg) and the 0xE4 STEER_TORQUE field."""
|
||||||
|
p = self.params
|
||||||
|
steering_angle = float(CS.out.steeringAngleDeg)
|
||||||
|
angle_last = steering_angle if self.apply_angle_last is None else self.apply_angle_last
|
||||||
|
desired = float(CC.actuators.steeringAngleDeg)
|
||||||
|
if CC.latActive:
|
||||||
|
# error clip first: it shapes the request, bounding the P torque the setpoint asks of the EPS
|
||||||
|
error_max = float(np.interp(CS.out.vEgoRaw, p.ANGLE_ERROR_MAX_BP, p.ANGLE_ERROR_MAX_V))
|
||||||
|
desired = float(np.clip(desired, steering_angle - error_max, steering_angle + error_max))
|
||||||
|
# The lateral accel and jerk limits (3.589) are the last adjustment: applied to exactly what is sent and seeded
|
||||||
|
# from the last value sent. The panda runs the same check on the frame (honda.h) and blocks one that exceeds it,
|
||||||
|
# so nothing may change the setpoint after this line.
|
||||||
|
apply_angle = apply_steer_angle_limits_vm(desired, angle_last, CS.out.vEgoRaw, steering_angle, CC.latActive, p, self.VM)
|
||||||
|
self.angle_steer_req = bool(CC.latActive)
|
||||||
|
if CC.latActive:
|
||||||
|
v = max(float(CS.out.vEgoRaw), 1.0)
|
||||||
|
max_delta = min(get_max_angle_delta_vm(v, self.VM, p), p.ANGLE_LIMITS.MAX_ANGLE_RATE)
|
||||||
|
if abs(apply_angle - angle_last) > max_delta + 1e-6:
|
||||||
|
# The accel limit is further from the last value sent than the jerk limit lets one frame move: the wheel is
|
||||||
|
# past the limit as the request starts. No setpoint satisfies both, and the panda would drop the frame, so
|
||||||
|
# the request waits at the wheel until the wheel is back inside.
|
||||||
|
apply_angle = steering_angle
|
||||||
|
self.angle_steer_req = False
|
||||||
|
self.apply_angle_last = apply_angle
|
||||||
|
|
||||||
|
# raw = round(-10 * deg), half-up; left-positive degrees are negative raw
|
||||||
|
if CC.latActive:
|
||||||
|
raw = math.floor(-10.0 * apply_angle + 0.5)
|
||||||
|
elif self._angle_hold_allowed(CC, CS):
|
||||||
|
# idle hold: keep the setpoint at the wheel so engagement starts without a step
|
||||||
|
raw = math.floor(-10.0 * steering_angle + 0.5)
|
||||||
|
else:
|
||||||
|
raw = 0 # the panda blocks a nonzero field here
|
||||||
|
return apply_angle, int(np.clip(raw, -p.ANGLE_RAW_MAX, p.ANGLE_RAW_MAX))
|
||||||
|
|
||||||
def update(self, CC, CS, now_nanos):
|
def update(self, CC, CS, now_nanos):
|
||||||
_projection = self.learning_projection_observer
|
_projection = self.learning_projection_observer
|
||||||
if _projection is not None:
|
if _projection is not None:
|
||||||
@@ -176,7 +229,12 @@ class CarController(CarControllerBase):
|
|||||||
can_sends.append(make_tester_present_msg(0x18DAB0F1, 1, suppress_response=True))
|
can_sends.append(make_tester_present_msg(0x18DAB0F1, 1, suppress_response=True))
|
||||||
|
|
||||||
# Send steering command.
|
# Send steering command.
|
||||||
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_torque, CC.latActive, self.tja_control))
|
if self.angle_mode:
|
||||||
|
apply_angle, angle_raw = self._update_angle(CC, CS)
|
||||||
|
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, angle_raw, self.angle_steer_req,
|
||||||
|
self.tja_control, angle_arm=self.params.ANGLE_ARM))
|
||||||
|
else:
|
||||||
|
can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_torque, CC.latActive, self.tja_control))
|
||||||
if _projection is not None:
|
if _projection is not None:
|
||||||
_projection.emit('honda.STEERING_CONTROL', apply_torque, CC.latActive, can_sends[-1])
|
_projection.emit('honda.STEERING_CONTROL', apply_torque, CC.latActive, can_sends[-1])
|
||||||
|
|
||||||
@@ -286,6 +344,9 @@ class CarController(CarControllerBase):
|
|||||||
new_actuators.brake = self.brake
|
new_actuators.brake = self.brake
|
||||||
new_actuators.torque = self.last_torque
|
new_actuators.torque = self.last_torque
|
||||||
new_actuators.torqueOutputCan = apply_torque
|
new_actuators.torqueOutputCan = apply_torque
|
||||||
|
if self.angle_mode:
|
||||||
|
new_actuators.steeringAngleDeg = apply_angle
|
||||||
|
new_actuators.torqueOutputCan = angle_raw # the 0xE4 STEER_TORQUE field as sent (-10 x deg)
|
||||||
|
|
||||||
self.frame += 1
|
self.frame += 1
|
||||||
if _projection is not None:
|
if _projection is not None:
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from opendbc.car.dashboard_speed_limit import Tracker as LimitTracker, honda_sig
|
|||||||
from opendbc.can.dbc import DBC as CANDBC
|
from opendbc.can.dbc import DBC as CANDBC
|
||||||
|
|
||||||
TransmissionType = structs.CarParams.TransmissionType
|
TransmissionType = structs.CarParams.TransmissionType
|
||||||
|
SteerControlType = structs.CarParams.SteerControlType
|
||||||
ButtonType = structs.CarState.ButtonEvent.Type
|
ButtonType = structs.CarState.ButtonEvent.Type
|
||||||
|
|
||||||
BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise,
|
BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise,
|
||||||
@@ -120,6 +121,16 @@ class CarState(CarStateBase):
|
|||||||
ret.steerFaultPermanent = False
|
ret.steerFaultPermanent = False
|
||||||
ret.steerFaultTemporary = False
|
ret.steerFaultTemporary = False
|
||||||
|
|
||||||
|
if self.CP.flags & HondaFlags.EPS_FW_UNREAD:
|
||||||
|
ret.steerFaultPermanent = True
|
||||||
|
|
||||||
|
if self.CP.steerControlType == SteerControlType.angle and self.CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW:
|
||||||
|
# the angle-loop EPS's angle is a valid absolute angle only while all three sensor status bits read 1; outside
|
||||||
|
# that the EPS would servo from a false angle, so do not steer
|
||||||
|
sensors = cp.vl["STEERING_SENSORS"]
|
||||||
|
if not all(sensors[f"STEER_SENSOR_STATUS_{i}"] == 1 for i in (1, 2, 3)):
|
||||||
|
ret.steerFaultTemporary = True
|
||||||
|
|
||||||
# All Honda EPS cut off slightly above standstill, some much higher
|
# All Honda EPS cut off slightly above standstill, some much higher
|
||||||
# Don't alert in the near-standstill range, but alert for per-vehicle configured minimums above that
|
# Don't alert in the near-standstill range, but alert for per-vehicle configured minimums above that
|
||||||
if CarControllerParams.STEER_GLOBAL_MIN_SPEED < ret.vEgo < (self.CP.minSteerSpeed + 0.5):
|
if CarControllerParams.STEER_GLOBAL_MIN_SPEED < ret.vEgo < (self.CP.minSteerSpeed + 0.5):
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from opendbc.car.honda.hondacan import honda_checksum
|
from opendbc.car.honda.hondacan import honda_checksum
|
||||||
|
from opendbc.car.honda.values import CAR
|
||||||
|
|
||||||
|
|
||||||
# Classic Bosch: PT on bus 1 and the stock ACC camera on bus 2. This selects
|
# Classic Bosch: PT on bus 1 and the stock ACC camera on bus 2. This selects
|
||||||
@@ -30,3 +31,9 @@ def normal_bus_topology(packets, *, layout=NORMAL_BUS_LAYOUT):
|
|||||||
|
|
||||||
def nidec_bus0_topology(packets):
|
def nidec_bus0_topology(packets):
|
||||||
return any(normal_bus_topology(packets, layout=layout) for layout in NIDEC_BUS0_LAYOUTS)
|
return any(normal_bus_topology(packets, layout=layout) for layout in NIDEC_BUS0_LAYOUTS)
|
||||||
|
|
||||||
|
|
||||||
|
def eps_needs_obd(candidates, car_fw) -> bool:
|
||||||
|
"""The Accord's EPS answers only through the OBD port (never on the normal bus 1 wiring), and its firmware
|
||||||
|
family decides between angle and torque steering. A normal-bus read that names the Accord is not complete."""
|
||||||
|
return CAR.HONDA_ACCORD in candidates and not any(fw.ecu == "eps" and not fw.logging for fw in car_fw)
|
||||||
|
|||||||
@@ -117,11 +117,15 @@ def create_acc_commands(packer, CAN, enabled, active, accel, gas, stopping_count
|
|||||||
return commands
|
return commands
|
||||||
|
|
||||||
|
|
||||||
def create_steering_control(packer, CAN, apply_torque, lkas_active, tja_control):
|
def create_steering_control(packer, CAN, apply_torque, lkas_active, tja_control, angle_arm=None):
|
||||||
|
# angle_arm (Accord angle-loop EPS only): STEER_TORQUE is the angle setpoint, sent with the request off too, and
|
||||||
|
# STEER_CONTROL_ARM carries the arm the EPS lane requires. None = the torque frame, unchanged.
|
||||||
values = {
|
values = {
|
||||||
"STEER_TORQUE": apply_torque if lkas_active else 0,
|
"STEER_TORQUE": apply_torque if (lkas_active or angle_arm is not None) else 0,
|
||||||
"STEER_TORQUE_REQUEST": lkas_active,
|
"STEER_TORQUE_REQUEST": lkas_active,
|
||||||
}
|
}
|
||||||
|
if angle_arm is not None:
|
||||||
|
values["STEER_CONTROL_ARM"] = angle_arm
|
||||||
|
|
||||||
if tja_control:
|
if tja_control:
|
||||||
values["STEER_DOWN_TO_ZERO"] = lkas_active
|
values["STEER_DOWN_TO_ZERO"] = lkas_active
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ from opendbc.car import Bus, get_safety_config, structs, uds
|
|||||||
from opendbc.car.common.conversions import Conversions as CV
|
from opendbc.car.common.conversions import Conversions as CV
|
||||||
from opendbc.car.disable_ecu import disable_ecu
|
from opendbc.car.disable_ecu import disable_ecu
|
||||||
from opendbc.car.honda.hondacan import CanBus
|
from opendbc.car.honda.hondacan import CanBus
|
||||||
from opendbc.car.honda.values import CarControllerParams, HondaFlags, CAR, HondaSafetyFlags, MANUAL_TRANS_CARS, MODIFIED_EPS_FW, DBC
|
from opendbc.car.honda.values import CarControllerParams, HondaFlags, CAR, HondaSafetyFlags, MANUAL_TRANS_CARS, MODIFIED_EPS_FW, DBC, \
|
||||||
|
is_accord_eps_angle_loop_fw
|
||||||
|
from opendbc.car.lateral import MAX_LATERAL_ACCEL
|
||||||
from opendbc.car.honda.carcontroller import CarController
|
from opendbc.car.honda.carcontroller import CarController
|
||||||
from opendbc.car.honda.carstate import CarState
|
from opendbc.car.honda.carstate import CarState
|
||||||
from opendbc.car.honda.radar_interface import RadarInterface
|
from opendbc.car.honda.radar_interface import RadarInterface
|
||||||
@@ -100,7 +102,12 @@ class CarInterface(CarInterfaceBase):
|
|||||||
ret.longitudinalTuning.kiV = [1.2, 0.8, 0.5]
|
ret.longitudinalTuning.kiV = [1.2, 0.8, 0.5]
|
||||||
|
|
||||||
eps_observations = [fw for fw in car_fw if fw.ecu == "eps" and not fw.logging]
|
eps_observations = [fw for fw in car_fw if fw.ecu == "eps" and not fw.logging]
|
||||||
modified_eps = any(b"," in fw.fwVersion for fw in eps_observations)
|
# Accord angle-loop EPS firmware (39990-TVA,A16<letter>): the EPS closes the angle loop and openpilot sends the
|
||||||
|
# setpoint. Not a torque-modified EPS, so it is kept out of the MODIFIED_EPS_FW allow-list check below (which would
|
||||||
|
# otherwise make the car dashcam-only). Every EPS response must be the family; a mixed read falls through to it.
|
||||||
|
eps_angle_loop_fw = (candidate == CAR.HONDA_ACCORD and len(eps_observations) > 0 and
|
||||||
|
all(is_accord_eps_angle_loop_fw(fw.fwVersion) for fw in eps_observations))
|
||||||
|
modified_eps = not eps_angle_loop_fw and any(b"," in fw.fwVersion for fw in eps_observations)
|
||||||
eps_modified = bool(modified_eps) and all(
|
eps_modified = bool(modified_eps) and all(
|
||||||
fw.address == 0x18DA30F1 and fw.subAddress == 0 and
|
fw.address == 0x18DA30F1 and fw.subAddress == 0 and
|
||||||
fw.fwVersion in MODIFIED_EPS_FW.get(candidate, ()) for fw in eps_observations)
|
fw.fwVersion in MODIFIED_EPS_FW.get(candidate, ()) for fw in eps_observations)
|
||||||
@@ -121,6 +128,21 @@ class CarInterface(CarInterfaceBase):
|
|||||||
|
|
||||||
elif candidate == CAR.HONDA_ACCORD:
|
elif candidate == CAR.HONDA_ACCORD:
|
||||||
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = ([[0.3], [0.09]] if eps_modified else [[0.6], [0.18]])
|
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = ([[0.3], [0.09]] if eps_modified else [[0.6], [0.18]])
|
||||||
|
if eps_angle_loop_fw:
|
||||||
|
# angle-loop EPS firmware: the EPS closes the angle loop, openpilot sends the setpoint
|
||||||
|
ret.flags |= HondaFlags.EPS_ANGLE_LOOP_FW.value
|
||||||
|
ret.safetyConfigs[-1].safetyParam |= HondaSafetyFlags.ACCORD_ANGLE.value
|
||||||
|
ret.steerControlType = structs.CarParams.SteerControlType.angle
|
||||||
|
ret.steerActuatorDelay = CarControllerParams.ANGLE_STEER_ACTUATOR_DELAY
|
||||||
|
# The torque fit's MAX_LAT_ACCEL_MEASURED (0.32 m/s^2) means nothing to an angle setpoint; the onroad torque
|
||||||
|
# bar divides by this, so normalise it by the angle limit instead (3.589 m/s^2, where the setpoint clamp binds).
|
||||||
|
# Measured engaged hands-off over 35 routes: p99.9 3.46 m/s^2, per-route maxima 3.4-4.1. Only the bar and the
|
||||||
|
# car docs read maxLateralAccel; no controller or torque tune does.
|
||||||
|
ret.maxLateralAccel = MAX_LATERAL_ACCEL
|
||||||
|
elif not docs and not eps_observations:
|
||||||
|
# EPS fw unread: an angle-loop EPS would ignore torque frames (engaged, no steering, no alert), so fault instead.
|
||||||
|
# Note: upstream lists this EPS as non-essential (lost without comma power); such an Accord faults here too.
|
||||||
|
ret.flags |= HondaFlags.EPS_FW_UNREAD.value
|
||||||
|
|
||||||
elif candidate == CAR.HONDA_ACCORD_11G:
|
elif candidate == CAR.HONDA_ACCORD_11G:
|
||||||
ret.longitudinalActuatorDelay = 0.05
|
ret.longitudinalActuatorDelay = 0.05
|
||||||
|
|||||||
@@ -37,8 +37,11 @@ MANUAL_SELECTION_PORTS = CLASSIC_BOSCH | NIDEC | RADARLESS | CANFD_STOCK | ALT_R
|
|||||||
# qualified() runs several times per 100 Hz frame in card and selfdrived, so
|
# qualified() runs several times per 100 Hz frame in card and selfdrived, so
|
||||||
# everything that depends only on this module is computed once, and its flag
|
# everything that depends only on this module is computed once, and its flag
|
||||||
# tests use plain ints: IntFlag operators cost microseconds each in Python.
|
# tests use plain ints: IntFlag operators cost microseconds each in Python.
|
||||||
|
# EPS_ANGLE_LOOP_FW / EPS_FW_UNREAD: Accord-only EPS-firmware detections (interface.py); the angle car keeps AOL, and
|
||||||
|
# an unread EPS is already a permanent steer fault in carstate, so neither may drop the car out of these owners.
|
||||||
_DETECTED = int(HondaFlags.BOSCH_EXT_HUD | HondaFlags.BOSCH_ALT_BRAKE | HondaFlags.HAS_BSM |
|
_DETECTED = int(HondaFlags.BOSCH_EXT_HUD | HondaFlags.BOSCH_ALT_BRAKE | HondaFlags.HAS_BSM |
|
||||||
HondaFlags.EPS_MODIFIED | HondaFlags.HYBRID | HondaFlags.GAS_INTERCEPTOR)
|
HondaFlags.EPS_MODIFIED | HondaFlags.HYBRID | HondaFlags.GAS_INTERCEPTOR |
|
||||||
|
HondaFlags.EPS_ANGLE_LOOP_FW | HondaFlags.EPS_FW_UNREAD)
|
||||||
_ALLOWED_FLAGS = {str(car): int(car.config.flags) | _DETECTED
|
_ALLOWED_FLAGS = {str(car): int(car.config.flags) | _DETECTED
|
||||||
for car in CLASSIC_BOSCH | NIDEC | RADARLESS | CANFD_STOCK | ALT_RADAR_STOCK | {CAR.HONDA_ACCORD_11G}}
|
for car in CLASSIC_BOSCH | NIDEC | RADARLESS | CANFD_STOCK | ALT_RADAR_STOCK | {CAR.HONDA_ACCORD_11G}}
|
||||||
_BOSCH, _BOSCH_RADARLESS, _BOSCH_ALT_BRAKE = int(HondaFlags.BOSCH), int(HondaFlags.BOSCH_RADARLESS), int(HondaFlags.BOSCH_ALT_BRAKE)
|
_BOSCH, _BOSCH_RADARLESS, _BOSCH_ALT_BRAKE = int(HondaFlags.BOSCH), int(HondaFlags.BOSCH_RADARLESS), int(HondaFlags.BOSCH_ALT_BRAKE)
|
||||||
@@ -102,6 +105,8 @@ def qualified(cp, *, marked_only=False):
|
|||||||
safety.safetyModel == _HONDA_NIDEC and safety.safetyParam == expected)
|
safety.safetyModel == _HONDA_NIDEC and safety.safetyParam == expected)
|
||||||
if fingerprint in CLASSIC_BOSCH and flags & _BOSCH and not flags & _BOSCH_RADARLESS:
|
if fingerprint in CLASSIC_BOSCH and flags & _BOSCH and not flags & _BOSCH_RADARLESS:
|
||||||
expected = int(bool(flags & _BOSCH_ALT_BRAKE))
|
expected = int(bool(flags & _BOSCH_ALT_BRAKE))
|
||||||
|
if fingerprint == CAR.HONDA_ACCORD and flags & int(HondaFlags.EPS_ANGLE_LOOP_FW):
|
||||||
|
expected |= int(HondaSafetyFlags.ACCORD_ANGLE)
|
||||||
if cp.openpilotLongitudinalControl:
|
if cp.openpilotLongitudinalControl:
|
||||||
expected |= int(HondaSafetyFlags.BOSCH_LONG)
|
expected |= int(HondaSafetyFlags.BOSCH_LONG)
|
||||||
if fingerprint == CAR.ACURA_RDX_3G:
|
if fingerprint == CAR.ACURA_RDX_3G:
|
||||||
|
|||||||
@@ -39,9 +39,11 @@ def test_mixed_nonlogging_eps_still_refuses_modified_profile(other):
|
|||||||
assert not cp.flags & HondaFlags.EPS_MODIFIED
|
assert not cp.flags & HondaFlags.EPS_MODIFIED
|
||||||
|
|
||||||
|
|
||||||
def test_recorded_custom_angle_eps_remains_unsupported_in_mainline():
|
def test_recorded_custom_angle_eps_steers_by_angle():
|
||||||
cp = params(CAR.HONDA_ACCORD, [eps(ANGLE), eps(SERIAL, logging=True)])
|
cp = params(CAR.HONDA_ACCORD, [eps(ANGLE), eps(SERIAL, logging=True)])
|
||||||
assert cp.dashcamOnly
|
assert not cp.dashcamOnly
|
||||||
|
assert cp.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||||
|
assert cp.steerControlType == structs.CarParams.SteerControlType.angle
|
||||||
assert not cp.flags & HondaFlags.EPS_MODIFIED
|
assert not cp.flags & HondaFlags.EPS_MODIFIED
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,364 @@
|
|||||||
|
"""Accord on the angle-loop EPS firmware (39990-TVA,A16<letter>): detection, the 0xE4 frame, the setpoint limits."""
|
||||||
|
import math
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from opendbc import get_generated_dbcs
|
||||||
|
from opendbc.can import CANPacker
|
||||||
|
from opendbc.car import Bus, gen_empty_fingerprint
|
||||||
|
from opendbc.car.honda.carcontroller import CarController
|
||||||
|
from opendbc.car.honda.carstate import CarState
|
||||||
|
from opendbc.car.honda.hondacan import CanBus, create_steering_control
|
||||||
|
from opendbc.car.honda.interface import CarInterface
|
||||||
|
from opendbc.car.honda.values import CAR, DBC, CarControllerParams, HondaFlags, HondaSafetyFlags, is_accord_eps_angle_loop_fw, \
|
||||||
|
accord_angle_steer_ratio, ACCORD_ANGLE_SR_BP, ACCORD_ANGLE_SR_V
|
||||||
|
from opendbc.car.interfaces import get_torque_params
|
||||||
|
from opendbc.car.lateral import MAX_LATERAL_ACCEL, apply_steer_angle_limits_vm, get_max_angle_delta_vm, get_max_angle_vm
|
||||||
|
from opendbc.car.toyota.interface import CarInterface as ToyotaInterface
|
||||||
|
from opendbc.car.toyota.values import CAR as TOYOTA
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
|
||||||
|
P = CarControllerParams
|
||||||
|
STEERING_CONTROL = 0xE4
|
||||||
|
|
||||||
|
|
||||||
|
def _eps_fw(fw: bytes):
|
||||||
|
return [CarParams.CarFw(ecu=CarParams.Ecu.eps, fwVersion=fw, address=0x18DA30F1, subAddress=0)]
|
||||||
|
|
||||||
|
|
||||||
|
def accord_cp(eps_fw: bytes | None):
|
||||||
|
car_fw = [] if eps_fw is None else _eps_fw(eps_fw)
|
||||||
|
return CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), car_fw, False, False, False)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("fw, expected", [
|
||||||
|
(b"39990-TVA,A16A\x00\x00", True), # V298, NUL-padded as the car reports it
|
||||||
|
(b"39990-TVA,A16B\x00\x00", True), # V299
|
||||||
|
(b"39990-TVA,A16C", True), # the release
|
||||||
|
(b"39990-TVA,A160\x00\x00", False), # torque-map images
|
||||||
|
(b"39990-TVA-A160\x00\x00", False), # stock
|
||||||
|
(b"39990-TVA,A16", False),
|
||||||
|
(b"39990-TVA,A16AB", False),
|
||||||
|
(b"39990-TVA,A16a", False),
|
||||||
|
(b"39990-TVB,A16A", False),
|
||||||
|
])
|
||||||
|
def test_fw_detection(fw, expected):
|
||||||
|
assert is_accord_eps_angle_loop_fw(fw) is expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("fw", [b"39990-TVA,A16A\x00\x00", b"39990-TVA,A16B\x00\x00", b"39990-TVA,A16C\x00\x00"])
|
||||||
|
def test_angle_fw_selects_angle_control(fw):
|
||||||
|
CP = accord_cp(fw)
|
||||||
|
assert CP.steerControlType == CarParams.SteerControlType.angle
|
||||||
|
assert CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||||
|
assert CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||||
|
assert CP.steerActuatorDelay == pytest.approx(P.ANGLE_STEER_ACTUATOR_DELAY)
|
||||||
|
# the angle fw carries a ',' but is not a torque-modified EPS: it must not hit the MODIFIED_EPS_FW dashcam fallback
|
||||||
|
assert not CP.dashcamOnly
|
||||||
|
assert not CP.flags & HondaFlags.EPS_MODIFIED
|
||||||
|
assert not CP.flags & HondaFlags.EPS_FW_UNREAD
|
||||||
|
|
||||||
|
|
||||||
|
def test_angle_fw_on_another_honda_is_not_angle_control():
|
||||||
|
# the family is Accord-only; on any other platform the ',' read is the upstream modified-EPS path
|
||||||
|
CP = CarInterface.get_params(CAR.HONDA_CIVIC_BOSCH, gen_empty_fingerprint(), _eps_fw(b"39990-TVA,A16C\x00\x00"),
|
||||||
|
False, False, False)
|
||||||
|
assert CP.steerControlType == CarParams.SteerControlType.torque
|
||||||
|
assert not CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||||
|
assert not CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||||
|
|
||||||
|
|
||||||
|
def test_mixed_eps_read_is_not_angle_control():
|
||||||
|
car_fw = _eps_fw(b"39990-TVA,A16C\x00\x00") + _eps_fw(b"39990-TVA-A160\x00\x00")
|
||||||
|
CP = CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), car_fw, False, False, False)
|
||||||
|
assert CP.steerControlType == CarParams.SteerControlType.torque
|
||||||
|
assert not CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||||
|
assert not CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||||
|
assert CP.dashcamOnly # upstream: a ',' EPS outside MODIFIED_EPS_FW
|
||||||
|
|
||||||
|
|
||||||
|
def test_angle_control_needs_no_params():
|
||||||
|
"""A fresh install selects angle control from the EPS fw alone and keeps the pid tuning block untouched.
|
||||||
|
|
||||||
|
Old tree (83fa2e68c8) also pinned this against stale torque-era toggles (ForceTorqueController, NNFF, NNFF Lite)
|
||||||
|
passed into get_params; this tree's get_params takes no toggles and has no ForceTorqueController conversion at all,
|
||||||
|
so only the fw-alone half of that test still has an API to exercise."""
|
||||||
|
CP = CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), _eps_fw(b"39990-TVA,A16C"), False, False, False)
|
||||||
|
assert CP.steerControlType == CarParams.SteerControlType.angle
|
||||||
|
assert CP.lateralTuning.which() == "pid"
|
||||||
|
assert CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, CP).angle_mode
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("fw", [None, b"39990-TVA-A160\x00\x00", b"39990-TVA,A160\x00\x00"])
|
||||||
|
def test_other_fw_keeps_torque_control(fw):
|
||||||
|
CP = accord_cp(fw)
|
||||||
|
assert CP.steerControlType == CarParams.SteerControlType.torque
|
||||||
|
assert not CP.flags & HondaFlags.EPS_ANGLE_LOOP_FW
|
||||||
|
assert not CP.safetyConfigs[0].safetyParam & HondaSafetyFlags.ACCORD_ANGLE
|
||||||
|
assert not CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, CP).angle_mode
|
||||||
|
|
||||||
|
|
||||||
|
def test_max_lateral_accel_is_the_angle_limit_only_on_the_angle_fw():
|
||||||
|
# the onroad torque bar divides by CP.maxLateralAccel; the torque fit's 0.32 m/s^2 pegged it on every turn
|
||||||
|
torque_fit = get_torque_params()[CAR.HONDA_ACCORD]['MAX_LAT_ACCEL_MEASURED']
|
||||||
|
assert torque_fit == pytest.approx(0.3247, abs=1e-4)
|
||||||
|
assert accord_cp(b"39990-TVA,A16C").maxLateralAccel == pytest.approx(MAX_LATERAL_ACCEL)
|
||||||
|
assert MAX_LATERAL_ACCEL == pytest.approx(3.589, abs=1e-3)
|
||||||
|
for fw in (None, b"39990-TVA-A160\x00\x00", b"39990-TVA,A160\x00\x00"):
|
||||||
|
assert accord_cp(fw).maxLateralAccel == pytest.approx(torque_fit)
|
||||||
|
angle_fw = _eps_fw(b"39990-TVA,A16C")
|
||||||
|
for car in (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G):
|
||||||
|
CP = CarInterface.get_params(car, gen_empty_fingerprint(), angle_fw, False, False, False)
|
||||||
|
assert CP.maxLateralAccel == pytest.approx(get_torque_params()[car]['MAX_LAT_ACCEL_MEASURED'])
|
||||||
|
CP = ToyotaInterface.get_params(TOYOTA.TOYOTA_RAV4_TSS2, gen_empty_fingerprint(), [], False, False, False)
|
||||||
|
assert CP.maxLateralAccel == pytest.approx(get_torque_params()[TOYOTA.TOYOTA_RAV4_TSS2]['MAX_LAT_ACCEL_MEASURED'])
|
||||||
|
|
||||||
|
|
||||||
|
def _steer_faults(CP):
|
||||||
|
# an unfed parser set: only the fault logic, not the bus contents, is under test
|
||||||
|
CS = CarState(CP)
|
||||||
|
ret = CS.update(CS.get_can_parsers(CP))
|
||||||
|
return ret.steerFaultPermanent
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("fw, angle, unread", [
|
||||||
|
(b"39990-TVA,A16C\x00\x00", True, False), # angle EPS read -> angle mode
|
||||||
|
(b"39990-TVA-A160\x00\x00", False, False), # stock EPS read -> torque mode, no fault
|
||||||
|
(b"39990-TVA,A160\x00\x00", False, False), # torque-map EPS read -> torque mode, no fault
|
||||||
|
(None, False, True), # no EPS fw at all -> permanent fault
|
||||||
|
])
|
||||||
|
def test_eps_fw_unread_faults(fw, angle, unread):
|
||||||
|
CP = accord_cp(fw)
|
||||||
|
assert (CP.steerControlType == CarParams.SteerControlType.angle) == angle
|
||||||
|
assert bool(CP.flags & HondaFlags.EPS_FW_UNREAD) == unread
|
||||||
|
if not angle:
|
||||||
|
# same unfed bus for every case, so the fault is decided by the flag alone (the read cases are the control)
|
||||||
|
assert _steer_faults(CP) == unread
|
||||||
|
|
||||||
|
|
||||||
|
def test_docs_params_do_not_fault():
|
||||||
|
CP = CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), [], False, False, True)
|
||||||
|
assert not CP.flags & HondaFlags.EPS_FW_UNREAD
|
||||||
|
|
||||||
|
|
||||||
|
def _upstream_dbc(tmp_path):
|
||||||
|
# the Accord DBC without STEER_CONTROL_ARM, i.e. as it was before the signal was added. The *_generated DBCs are
|
||||||
|
# built in memory in this tree (opendbc.get_generated_dbcs), so the stripped copy is written out from that content.
|
||||||
|
name = DBC[CAR.HONDA_ACCORD][Bus.pt]
|
||||||
|
content = get_generated_dbcs()[name]
|
||||||
|
assert "STEER_CONTROL_ARM" in content
|
||||||
|
lines = [ln for ln in content.splitlines(keepends=True) if "STEER_CONTROL_ARM" not in ln]
|
||||||
|
path = tmp_path / f"{name}.dbc"
|
||||||
|
path.write_text("".join(lines), encoding="utf-8")
|
||||||
|
return str(path)
|
||||||
|
|
||||||
|
|
||||||
|
def test_torque_frame_unchanged_by_the_dbc_signal(tmp_path):
|
||||||
|
CP = accord_cp(None)
|
||||||
|
new = CANPacker(DBC[CAR.HONDA_ACCORD][Bus.pt])
|
||||||
|
old = CANPacker(_upstream_dbc(tmp_path))
|
||||||
|
can = CanBus(CP)
|
||||||
|
for torque in range(-4096, 4097, 37):
|
||||||
|
for active in (False, True):
|
||||||
|
for tja in (False, True):
|
||||||
|
assert create_steering_control(new, can, torque, active, tja) == create_steering_control(old, can, torque, active, tja)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("active", [False, True])
|
||||||
|
def test_angle_frame_carries_the_arm_and_a_valid_checksum(active):
|
||||||
|
packer = CANPacker(DBC[CAR.HONDA_ACCORD][Bus.pt])
|
||||||
|
can = CanBus(accord_cp(b"39990-TVA,A16C"))
|
||||||
|
for raw in (-4000, -1234, -1, 0, 1, 987, 4000):
|
||||||
|
addr, dat, _ = create_steering_control(packer, can, raw, active, False, angle_arm=P.ANGLE_ARM)
|
||||||
|
assert addr == STEERING_CONTROL
|
||||||
|
assert (dat[2] >> 2) & 0x3 == P.ANGLE_ARM # byte 2 bits 3:2
|
||||||
|
assert int.from_bytes(dat[0:2], "big", signed=True) == raw # setpoint sent with the request off too
|
||||||
|
assert bool(dat[2] & 0x80) == active # STEER_TORQUE_REQUEST
|
||||||
|
sig = packer.dbc.addr_to_msg[addr].sigs["CHECKSUM"]
|
||||||
|
zeroed = bytearray(dat)
|
||||||
|
zeroed[4] &= 0xF0
|
||||||
|
assert sig.calc_checksum(addr, sig, zeroed) == dat[4] & 0xF # CHECKSUM 35|4 = byte 4 low nibble
|
||||||
|
|
||||||
|
|
||||||
|
def _controller(aol=False):
|
||||||
|
CP = accord_cp(b"39990-TVA,A16C")
|
||||||
|
if aol:
|
||||||
|
CP.alternativeExperience |= 32 # always-on lateral: the hold must NOT depend on it (the 7.0 panda predicate is a session grant)
|
||||||
|
return CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, CP)
|
||||||
|
|
||||||
|
|
||||||
|
def _cc_cs(desired, measured, v, lat_active, enabled=True, main_on=True):
|
||||||
|
CC = SimpleNamespace(actuators=SimpleNamespace(steeringAngleDeg=desired), latActive=lat_active, enabled=enabled)
|
||||||
|
CS = SimpleNamespace(out=SimpleNamespace(steeringAngleDeg=measured, vEgoRaw=v, cruiseState=SimpleNamespace(available=main_on)))
|
||||||
|
return CC, CS
|
||||||
|
|
||||||
|
|
||||||
|
def test_error_clip_then_the_accel_and_jerk_limits():
|
||||||
|
# the error clip shapes the request, the accel/jerk limiter runs last on it, and what is sent is the limiter's output
|
||||||
|
cc = _controller()
|
||||||
|
assert cc.angle_mode
|
||||||
|
v, measured = 20.0, 0.0
|
||||||
|
err = float(np.interp(v, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||||
|
state = measured
|
||||||
|
for _ in range(400):
|
||||||
|
state = apply_steer_angle_limits_vm(min(90.0, measured + err), state, v, measured, True, cc.params, cc.VM)
|
||||||
|
apply_angle, raw = cc._update_angle(*_cc_cs(90.0, measured, v, True))
|
||||||
|
assert apply_angle == cc.apply_angle_last == state
|
||||||
|
assert raw == math.floor(-10.0 * apply_angle + 0.5)
|
||||||
|
assert apply_angle == pytest.approx(measured + err) # the wheel never moved: the send settles on the clip
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("v", [1.0, 5.0, 10.0, 17.5, 26.9, 35.0])
|
||||||
|
def test_what_is_sent_never_exceeds_the_accel_and_jerk_limits(v):
|
||||||
|
# whatever the wheel does (a driver holding it far past the limit, or yanking it), every frame sent stays inside
|
||||||
|
# the 3.589 lateral accel angle and steps no further than the 3.589 jerk limit from the previous frame sent
|
||||||
|
rng = np.random.default_rng(int(v * 10))
|
||||||
|
cc = _controller()
|
||||||
|
max_angle = get_max_angle_vm(v, cc.VM, cc.params)
|
||||||
|
max_delta = min(get_max_angle_delta_vm(v, cc.VM, cc.params), P.ANGLE_LIMITS.MAX_ANGLE_RATE)
|
||||||
|
err = float(np.interp(v, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||||
|
wheel = min(max_angle + err + 10.0, 390.0) # held past the limit: the case the old order got wrong
|
||||||
|
prev, _ = cc._update_angle(*_cc_cs(0.0, 0.0, v, True))
|
||||||
|
for i in range(600):
|
||||||
|
if i > 200:
|
||||||
|
wheel = float(np.clip(wheel + rng.normal(0.0, 3.0), -390.0, 390.0)) # then moving up to several hundred deg/s
|
||||||
|
sent, raw = cc._update_angle(*_cc_cs(float(rng.uniform(-400.0, 400.0)), wheel, v, True))
|
||||||
|
assert abs(sent) <= min(max_angle, P.ANGLE_LIMITS.STEER_ANGLE_MAX) + 1e-9
|
||||||
|
assert abs(sent - prev) <= max_delta + 1e-9
|
||||||
|
assert raw == math.floor(-10.0 * sent + 0.5)
|
||||||
|
prev = sent
|
||||||
|
|
||||||
|
|
||||||
|
def test_wheel_motion_inside_the_error_clip_does_not_feed_the_setpoint():
|
||||||
|
# same command, different wheel paths that stay inside the clip: the setpoint must not depend on the wheel
|
||||||
|
rng = np.random.default_rng(0)
|
||||||
|
a, b = _controller(), _controller()
|
||||||
|
a.apply_angle_last = b.apply_angle_last = 0.0
|
||||||
|
err = float(np.interp(12.0, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||||
|
for i in range(300):
|
||||||
|
desired = 20.0 * math.sin(i / 20.0)
|
||||||
|
wheel = float(np.clip(rng.normal(0.0, 10.0), -(err - 21.0), err - 21.0))
|
||||||
|
a._update_angle(*_cc_cs(desired, 0.0, 12.0, True))
|
||||||
|
b._update_angle(*_cc_cs(desired, wheel, 12.0, True))
|
||||||
|
assert a.apply_angle_last == b.apply_angle_last
|
||||||
|
|
||||||
|
|
||||||
|
def test_setpoint_returns_to_the_request_at_the_jerk_limit_after_the_clip_releases():
|
||||||
|
# wheel pushed away (clip binds), then let go: the setpoint walks back, it does not jump
|
||||||
|
cc = _controller()
|
||||||
|
v = 20.0
|
||||||
|
err = float(np.interp(v, P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V))
|
||||||
|
max_delta = get_max_angle_delta_vm(v, cc.VM, cc.params)
|
||||||
|
cc.apply_angle_last = 0.0
|
||||||
|
for _ in range(300):
|
||||||
|
pushed, _ = cc._update_angle(*_cc_cs(0.0, err + 5.0, v, True))
|
||||||
|
assert pushed == pytest.approx(5.0) # held at the clip edge, wheel - err
|
||||||
|
back, _ = cc._update_angle(*_cc_cs(0.0, 0.0, v, True))
|
||||||
|
assert back == pytest.approx(5.0 - max_delta)
|
||||||
|
|
||||||
|
|
||||||
|
def test_request_waits_at_the_wheel_while_the_wheel_is_past_the_accel_limit():
|
||||||
|
# lateral goes active with the wheel past the accel-limit angle: the limit is more than one jerk step away, so no
|
||||||
|
# setpoint is legal. The frame holds the wheel with the request off, and the request starts once the wheel is inside.
|
||||||
|
cc = _controller()
|
||||||
|
v = 26.9
|
||||||
|
max_angle = get_max_angle_vm(v, cc.VM, cc.params)
|
||||||
|
max_delta = get_max_angle_delta_vm(v, cc.VM, cc.params)
|
||||||
|
for wheel in (max_angle + 20.0, max_angle + 5.0, max_angle + max_delta + 0.1):
|
||||||
|
sent, raw = cc._update_angle(*_cc_cs(0.0, wheel, v, True))
|
||||||
|
assert not cc.angle_steer_req
|
||||||
|
assert sent == wheel and raw == math.floor(-10.0 * wheel + 0.5)
|
||||||
|
wheel = max_angle + 0.5 * max_delta
|
||||||
|
cc._update_angle(*_cc_cs(0.0, wheel, v, True)) # the last value sent was the wheel further out: one more frame waits
|
||||||
|
assert not cc.angle_steer_req
|
||||||
|
sent, raw = cc._update_angle(*_cc_cs(0.0, wheel, v, True))
|
||||||
|
assert cc.angle_steer_req
|
||||||
|
assert sent == pytest.approx(wheel - max_delta) # one jerk step in from the wheel, inside the accel limit
|
||||||
|
for _ in range(50): # and it stays on from there
|
||||||
|
prev = sent
|
||||||
|
sent, _ = cc._update_angle(*_cc_cs(0.0, wheel, v, True))
|
||||||
|
assert cc.angle_steer_req and abs(sent - prev) <= max_delta + 1e-9 and abs(sent) <= max_angle + 1e-9
|
||||||
|
|
||||||
|
|
||||||
|
def test_request_bit_follows_lat_active_otherwise():
|
||||||
|
cc = _controller()
|
||||||
|
cc._update_angle(*_cc_cs(3.0, 1.0, 20.0, True))
|
||||||
|
assert cc.angle_steer_req
|
||||||
|
cc._update_angle(*_cc_cs(3.0, 1.0, 20.0, False))
|
||||||
|
assert not cc.angle_steer_req
|
||||||
|
|
||||||
|
|
||||||
|
def test_each_step_is_bounded_by_the_rate_limit():
|
||||||
|
# MAX_ANGLE_RATE = 2.5 deg/frame (250 deg/s): no frame may step further than that
|
||||||
|
cc = _controller()
|
||||||
|
prev = 0.0
|
||||||
|
for _ in range(5):
|
||||||
|
a, _ = cc._update_angle(*_cc_cs(90.0, 0.0, 3.0, True))
|
||||||
|
assert abs(a - prev) <= P.ANGLE_LIMITS.MAX_ANGLE_RATE + 1e-9
|
||||||
|
prev = a
|
||||||
|
|
||||||
|
|
||||||
|
def test_first_frame_seeds_from_the_wheel():
|
||||||
|
cc = _controller()
|
||||||
|
a, _ = cc._update_angle(*_cc_cs(30.0, 25.0, 10.0, True))
|
||||||
|
assert abs(a - 25.0) <= P.ANGLE_LIMITS.MAX_ANGLE_RATE + 1e-9
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("enabled, main_on, aol, holds", [
|
||||||
|
(True, True, False, True),
|
||||||
|
(False, True, True, False), # always-on lateral with ACC main on: the panda's grant is not visible here, so no hold
|
||||||
|
(True, True, True, True),
|
||||||
|
(False, True, False, False),
|
||||||
|
(True, False, False, False), # the panda drops controls_allowed with main off
|
||||||
|
(False, False, True, False),
|
||||||
|
])
|
||||||
|
def test_idle_hold(enabled, main_on, aol, holds):
|
||||||
|
cc = _controller(aol)
|
||||||
|
measured = -12.34
|
||||||
|
apply_angle, raw = cc._update_angle(*_cc_cs(50.0, measured, 15.0, False, enabled, main_on))
|
||||||
|
assert apply_angle == measured # lateral off: the limiter follows the wheel
|
||||||
|
assert raw == (math.floor(-10.0 * measured + 0.5) if holds else 0)
|
||||||
|
|
||||||
|
|
||||||
|
def test_raw_is_clipped():
|
||||||
|
cc = _controller()
|
||||||
|
cc.apply_angle_last = 399.0
|
||||||
|
_, raw = cc._update_angle(*_cc_cs(400.0, 399.0, 1.0, True))
|
||||||
|
assert raw == -P.ANGLE_RAW_MAX
|
||||||
|
|
||||||
|
|
||||||
|
def test_steer_ratio_map_level():
|
||||||
|
assert accord_angle_steer_ratio(0.0) == pytest.approx(16.84)
|
||||||
|
for deg in (0.0, 45.0, 120.0, -200.0, 500.0):
|
||||||
|
expected = float(np.interp(abs(deg), ACCORD_ANGLE_SR_BP, ACCORD_ANGLE_SR_V)) * 16.84 / 16.88
|
||||||
|
assert accord_angle_steer_ratio(deg) == pytest.approx(expected)
|
||||||
|
|
||||||
|
|
||||||
|
def test_error_clip_is_the_p_room_under_the_firmware_sum_clamp():
|
||||||
|
# Operator rule (2026-10-21): the clip is the angle error where the V300 firmware's P term alone equals
|
||||||
|
# Kmax - Imax (sum clamp 15360 after the 254/256 taper, so 15481 before it; I cap 4096 / 6144 / 8192 by
|
||||||
|
# speed). Integer mirror of the image: E = 16 * 10 * deg, E' = (E * G(v)) >> 8, P = (E' * 112) >> 8.
|
||||||
|
g_v = {3.1: 1178, 8.0: 1465, 10.0: 760, 11.75: 560, 17.5: 1068, 26.9: 2188}
|
||||||
|
for v, clip in zip(P.ANGLE_ERROR_MAX_BP, P.ANGLE_ERROR_MAX_V, strict=True):
|
||||||
|
imax = 4096 if v <= 6.0 else (6144 if v <= 12.5 else 8192)
|
||||||
|
p_of = lambda deg, v=v: (((16 * round(10 * deg) * g_v[v]) >> 8) * 112) >> 8 # noqa: E731
|
||||||
|
assert p_of(clip) >= 15481 - imax > p_of(clip - 0.1)
|
||||||
|
|
||||||
|
|
||||||
|
def test_angle_frame_is_sent_by_the_controller():
|
||||||
|
# the full update(): angle mode packs the setpoint with the arm; the projection observer is never installed on angle
|
||||||
|
CP = accord_cp(b"39990-TVA,A16C")
|
||||||
|
ci = CarInterface(CP)
|
||||||
|
from opendbc.car import structs
|
||||||
|
CC = structs.CarControl(enabled=True, latActive=True)
|
||||||
|
CC.actuators.steeringAngleDeg = 5.0
|
||||||
|
ci.update([])
|
||||||
|
out, sends = ci.apply(CC.as_reader(), 1_000_000_000)
|
||||||
|
steer = [s for s in sends if s[0] == STEERING_CONTROL]
|
||||||
|
assert len(steer) == 1
|
||||||
|
dat = steer[0][1]
|
||||||
|
assert (dat[2] >> 2) & 0x3 == P.ANGLE_ARM
|
||||||
|
assert int.from_bytes(dat[0:2], "big", signed=True) == out.torqueOutputCan
|
||||||
|
assert out.steeringAngleDeg == pytest.approx(-out.torqueOutputCan / 10.0, abs=0.05)
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from types import SimpleNamespace
|
||||||
import unittest
|
import unittest
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from opendbc.car.can_definitions import CanData
|
from opendbc.car.can_definitions import CanData
|
||||||
from opendbc.car.car_helpers import fingerprint
|
from opendbc.car.car_helpers import fingerprint, get_car
|
||||||
from opendbc.car import fw_versions
|
from opendbc.car import fw_versions, structs
|
||||||
|
from opendbc.car.honda.values import CAR, HondaFlags
|
||||||
from opendbc.car.vin import VIN_UNKNOWN
|
from opendbc.car.vin import VIN_UNKNOWN
|
||||||
|
|
||||||
|
|
||||||
@@ -33,6 +35,55 @@ class TestHondaNormalDiscovery(unittest.TestCase):
|
|||||||
generic_query.assert_not_called()
|
generic_query.assert_not_called()
|
||||||
self.assertIsNone(actual[0])
|
self.assertIsNone(actual[0])
|
||||||
|
|
||||||
|
def _accord_discovery(self, normal_read, obd_read):
|
||||||
|
switches = []
|
||||||
|
with patch('opendbc.car.car_helpers.get_vin', return_value=(-1, -1, VIN_UNKNOWN)) as vin, \
|
||||||
|
patch('opendbc.car.car_helpers.get_fw_versions', side_effect=[normal_read, obd_read]) as query, \
|
||||||
|
patch('opendbc.car.car_helpers.match_fw_to_car', return_value=(True, {CAR.HONDA_ACCORD})), \
|
||||||
|
patch('opendbc.car.car_helpers.can_fingerprint', return_value=(None, {})):
|
||||||
|
actual = fingerprint(lambda wait_for_one=False: [recorded_frames()], lambda frames: None, switches.append, None)
|
||||||
|
return switches, vin, query, actual
|
||||||
|
|
||||||
|
def test_accord_without_an_eps_read_queries_the_obd_port(self):
|
||||||
|
radar = SimpleNamespace(ecu="fwdRadar", logging=False, responseAddress=0, subAddress=0, bus=1)
|
||||||
|
eps = SimpleNamespace(ecu="eps", logging=False, responseAddress=0, subAddress=0, bus=1)
|
||||||
|
switches, vin, query, actual = self._accord_discovery([radar], [radar, eps])
|
||||||
|
self.assertEqual(switches, [False, True, False])
|
||||||
|
self.assertEqual(vin.call_count, 2)
|
||||||
|
self.assertEqual([call.kwargs for call in query.call_args_list],
|
||||||
|
[{'query_brand': 'honda', 'normal_bus_only': True}, {'query_brand': 'honda'}])
|
||||||
|
self.assertEqual(actual[3], [radar, eps])
|
||||||
|
|
||||||
|
def test_accord_with_an_eps_read_stays_on_normal_wiring(self):
|
||||||
|
eps = SimpleNamespace(ecu="eps", logging=False, responseAddress=0, subAddress=0, bus=1)
|
||||||
|
switches, vin, query, _ = self._accord_discovery([eps], AssertionError("no second query"))
|
||||||
|
self.assertFalse(any(switches))
|
||||||
|
query.assert_called_once()
|
||||||
|
|
||||||
|
def test_manually_selected_accord_queries_eps_when_radar_and_camera_cannot_identify_it(self):
|
||||||
|
radar = structs.CarParams.CarFw.new_message(ecu="fwdRadar", address=0x18DAB0F1, fwVersion=b"36802-TVA-A190\x00\x00", brand="honda")
|
||||||
|
camera = structs.CarParams.CarFw.new_message(ecu="fwdCamera", address=0x18DAB5F1, fwVersion=b"36161-TVA-A060\x00\x00", brand="honda")
|
||||||
|
normal_fw = [radar, camera]
|
||||||
|
self.assertNotIn(CAR.HONDA_ACCORD, fw_versions.match_fw_to_car(normal_fw, VIN_UNKNOWN)[1])
|
||||||
|
|
||||||
|
for version, angle in ((b"39990-TVA-A160\x00\x00", False), (b"39990-TVA,A16C\x00\x00", True), (None, False)):
|
||||||
|
with self.subTest(version=version):
|
||||||
|
switches = []
|
||||||
|
obd_fw = normal_fw.copy()
|
||||||
|
if version is not None:
|
||||||
|
obd_fw.append(structs.CarParams.CarFw.new_message(ecu="eps", address=0x18DA30F1, fwVersion=version, brand="honda"))
|
||||||
|
with patch('opendbc.car.car_helpers.get_vin', return_value=(-1, -1, VIN_UNKNOWN)), \
|
||||||
|
patch('opendbc.car.car_helpers.get_fw_versions', side_effect=[normal_fw, obd_fw]) as query, \
|
||||||
|
patch('opendbc.car.car_helpers.can_fingerprint', return_value=(None, {0: {}, 1: {}, 2: {}})):
|
||||||
|
interface = get_car(lambda wait_for_one=False: [recorded_frames()], lambda frames: None, switches.append,
|
||||||
|
False, False, forced_candidate=CAR.HONDA_ACCORD)
|
||||||
|
self.assertEqual(switches, [False, True, False])
|
||||||
|
self.assertEqual([call.kwargs for call in query.call_args_list],
|
||||||
|
[{'query_brand': 'honda', 'normal_bus_only': True}, {'query_brand': 'honda'}])
|
||||||
|
self.assertEqual(interface.CP.fingerprintSource, structs.CarParams.FingerprintSource.fixed)
|
||||||
|
self.assertEqual(interface.CP.steerControlType == structs.CarParams.SteerControlType.angle, angle)
|
||||||
|
self.assertEqual(bool(interface.CP.flags & HondaFlags.EPS_FW_UNREAD), version is None)
|
||||||
|
|
||||||
def test_incomplete_or_invalid_traffic_cannot_select_honda(self):
|
def test_incomplete_or_invalid_traffic_cannot_select_honda(self):
|
||||||
from opendbc.car.honda.discovery import normal_bus_topology
|
from opendbc.car.honda.discovery import normal_bus_topology
|
||||||
frames = recorded_frames()
|
frames = recorded_frames()
|
||||||
|
|||||||
@@ -301,8 +301,9 @@ def test_starting_during_active_engagement_requires_a_fresh_disabled_epoch():
|
|||||||
assert intent.allowed_latch
|
assert intent.allowed_latch
|
||||||
|
|
||||||
|
|
||||||
def test_actual_card_active_observation_requires_fresh_selfdrive_state(monkeypatch):
|
def test_actual_card_active_observation_requires_fresh_selfdrive_state(monkeypatch, tmp_path):
|
||||||
from openpilot.cereal import log
|
from openpilot.cereal import log
|
||||||
|
from openpilot.common.params import Params
|
||||||
from openpilot.selfdrive.car import card as card_module
|
from openpilot.selfdrive.car import card as card_module
|
||||||
from openpilot.selfdrive.car.card import Car
|
from openpilot.selfdrive.car.card import Car
|
||||||
from openpilot.starpilot.aol.intent import AolCardIntent
|
from openpilot.starpilot.aol.intent import AolCardIntent
|
||||||
@@ -329,6 +330,7 @@ def test_actual_card_active_observation_requires_fresh_selfdrive_state(monkeypat
|
|||||||
host = Car.__new__(Car)
|
host = Car.__new__(Car)
|
||||||
host.CP, host.aol_card_intent = cp, intent
|
host.CP, host.aol_card_intent = cp, intent
|
||||||
host.aol_settings = intent.settings
|
host.aol_settings = intent.settings
|
||||||
|
host.params = Params(str(tmp_path))
|
||||||
host.CI = SimpleNamespace(update=lambda _: cs, CS=SimpleNamespace(),
|
host.CI = SimpleNamespace(update=lambda _: cs, CS=SimpleNamespace(),
|
||||||
can_parsers=CarInterface.CarState(cp).get_can_parsers(cp))
|
can_parsers=CarInterface.CarState(cp).get_can_parsers(cp))
|
||||||
host.RI = SimpleNamespace(update=lambda _: None)
|
host.RI = SimpleNamespace(update=lambda _: None)
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from enum import Enum, IntFlag
|
from enum import Enum, IntFlag
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms, structs, uds
|
from opendbc.car import Bus, CarSpecs, DbcDict, PlatformConfig, Platforms, structs, uds
|
||||||
from opendbc.car.common.conversions import Conversions as CV
|
from opendbc.car.common.conversions import Conversions as CV
|
||||||
from opendbc.car.docs_definitions import CarFootnote, CarHarness, CarDocs, CarParts, Column
|
from opendbc.car.docs_definitions import CarFootnote, CarHarness, CarDocs, CarParts, Column
|
||||||
from opendbc.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16
|
from opendbc.car.fw_query_definitions import FwQueryConfig, Request, StdQueries, p16
|
||||||
from opendbc.car.honda.firmware_validation import validate_fw_match
|
from opendbc.car.honda.firmware_validation import validate_fw_match
|
||||||
|
from opendbc.car.lateral import AngleSteeringLimitsVM, MAX_LATERAL_ACCEL, MAX_LATERAL_JERK
|
||||||
|
|
||||||
Ecu = structs.CarParams.Ecu
|
Ecu = structs.CarParams.Ecu
|
||||||
VisualAlert = structs.CarControl.HUDControl.VisualAlert
|
VisualAlert = structs.CarControl.HUDControl.VisualAlert
|
||||||
@@ -41,6 +44,27 @@ class CarControllerParams:
|
|||||||
STEER_DELTA_DOWN = 3
|
STEER_DELTA_DOWN = 3
|
||||||
STEER_GLOBAL_MIN_SPEED = 3 * CV.MPH_TO_MS
|
STEER_GLOBAL_MIN_SPEED = 3 * CV.MPH_TO_MS
|
||||||
|
|
||||||
|
# ---- Accord on the angle-loop EPS firmware (HondaFlags.EPS_ANGLE_LOOP_FW). 0xE4 STEER_TORQUE carries an angle
|
||||||
|
# setpoint, raw = round(-10 * deg) in carState.steeringAngleDeg's frame, and the EPS closes a 1 kHz angle loop on it.
|
||||||
|
# The panda checks every such frame (STEER_CONTROL_ARM == 2) against the same lateral accel and jerk limits with
|
||||||
|
# the same vehicle model (honda.h, HONDA_ACCORD_ANGLE_PARAMS), and blocks one that exceeds them.
|
||||||
|
ANGLE_LIMITS: AngleSteeringLimitsVM = AngleSteeringLimitsVM(
|
||||||
|
400, # deg; the EPS clamps its setpoint at raw +-4096
|
||||||
|
MAX_LATERAL_ACCEL=MAX_LATERAL_ACCEL, # 3.589 m/s^2
|
||||||
|
MAX_LATERAL_JERK=MAX_LATERAL_JERK, # 3.589 m/s^3
|
||||||
|
MAX_ANGLE_RATE=2.5, # deg/frame = 250 deg/s (V299 drives ran 250; Tesla and Rivian run 250 deg/s too)
|
||||||
|
)
|
||||||
|
# Error clip |setpoint - measured angle| <= ANGLE_ERROR_MAX(v): bounds the P torque the setpoint can demand. Each
|
||||||
|
# knot = the error at which the firmware's P term alone fills the room left under the PID sum clamp when the
|
||||||
|
# integral sits at its cap (operator rule, 2026-10-21): P = Kmax - Imax, read from the V300 image:
|
||||||
|
# P = ((16*10*deg * G(v)) >> 8) * 112 >> 8, Kmax = 15360 after the 254/256 taper (15481 before it),
|
||||||
|
# Imax = 4096 (<= 6 m/s), 6144 (6-12.5 m/s), 8192 (above, the ICL), G(v) = 1178/1465/760/560/1068/2188 at the knots.
|
||||||
|
ANGLE_ERROR_MAX_BP = [3.1, 8.0, 10.0, 11.75, 17.5, 26.9] # m/s, the firmware gain-table knots
|
||||||
|
ANGLE_ERROR_MAX_V = [35.4, 23.4, 45.0, 61.0, 25.0, 12.2] # deg (was 17.0, 15.5, 19.5, 17.0, 8.5, 4.5, model-sized)
|
||||||
|
ANGLE_RAW_MAX = 4000 # raw clip before packing
|
||||||
|
ANGLE_ARM = 2 # 0xE4 STEER_CONTROL_ARM: the EPS lane runs only while it reads 2; sent on every frame
|
||||||
|
ANGLE_STEER_ACTUATOR_DELAY = 0.15 # s, the inner angle loop's lag (model value; lagd learns the rest)
|
||||||
|
|
||||||
def __init__(self, CP):
|
def __init__(self, CP):
|
||||||
self.BOSCH_GAS_LOOKUP_BP = list(type(self).BOSCH_GAS_LOOKUP_BP)
|
self.BOSCH_GAS_LOOKUP_BP = list(type(self).BOSCH_GAS_LOOKUP_BP)
|
||||||
gas_max = {CAR.HONDA_CIVIC_BOSCH: 750, CAR.HONDA_ODYSSEY_5G_MMR: 2000,
|
gas_max = {CAR.HONDA_CIVIC_BOSCH: 750, CAR.HONDA_ODYSSEY_5G_MMR: 2000,
|
||||||
@@ -92,6 +116,7 @@ class HondaSafetyFlags(IntFlag):
|
|||||||
RADARLESS = 8
|
RADARLESS = 8
|
||||||
BOSCH_CANFD = 16
|
BOSCH_CANFD = 16
|
||||||
BOSCH_CANFD_MVL = 64
|
BOSCH_CANFD_MVL = 64
|
||||||
|
ACCORD_ANGLE = 4096
|
||||||
CLASSIC_LONG_AOL = 2048 # Exact marked DEBUG classic Bosch alpha owner.
|
CLASSIC_LONG_AOL = 2048 # Exact marked DEBUG classic Bosch alpha owner.
|
||||||
ALT_RADAR_AOL = 1024 # Exact marked DEBUG alpha owner; physical EPS/gear token.
|
ALT_RADAR_AOL = 1024 # Exact marked DEBUG alpha owner; physical EPS/gear token.
|
||||||
NIDEC_PEDAL_AOL = 512 # Model1 only; distinct from model20 STOCK_TJA.
|
NIDEC_PEDAL_AOL = 512 # Model1 only; distinct from model20 STOCK_TJA.
|
||||||
@@ -121,6 +146,55 @@ class HondaFlags(IntFlag):
|
|||||||
BOSCH_TJA_CONTROL = 4096
|
BOSCH_TJA_CONTROL = 4096
|
||||||
EPS_MODIFIED = 8192
|
EPS_MODIFIED = 8192
|
||||||
GAS_INTERCEPTOR = 16384
|
GAS_INTERCEPTOR = 16384
|
||||||
|
EPS_ANGLE_LOOP_FW = 32768 # the Accord EPS reports the angle-loop firmware (is_accord_eps_angle_loop_fw)
|
||||||
|
EPS_FW_UNREAD = 65536 # Accord with no EPS fw response: the firmware family is unknown, so do not steer
|
||||||
|
|
||||||
|
|
||||||
|
# Accord EPS angle-loop firmware family: 39990-TVA,A16 + exactly one capital letter (A16A, A16B, A16C ...). Torque
|
||||||
|
# images read 39990-TVA,A160 (a digit) and stock 39990-TVA-A1x0, so neither matches.
|
||||||
|
ACCORD_EPS_ANGLE_LOOP_FW_FAMILY = b"39990-TVA,A16"
|
||||||
|
|
||||||
|
|
||||||
|
def is_accord_eps_angle_loop_fw(fw_version: bytes) -> bool:
|
||||||
|
v = bytes(fw_version).rstrip(b"\x00") # the EPS pads fwVersion with NULs
|
||||||
|
family = ACCORD_EPS_ANGLE_LOOP_FW_FAMILY
|
||||||
|
return len(v) == len(family) + 1 and v.startswith(family) and ord("A") <= v[-1] <= ord("Z")
|
||||||
|
|
||||||
|
|
||||||
|
# ---- Accord, angle mode only (steerControlType == angle): the variable-ratio rack map.
|
||||||
|
# In angle mode sR turns the model's curvature 1:1 into the angle setpoint, so the ratio is a tune here and the learner
|
||||||
|
# is ignored. SHAPE: absolute ratios measured over 82 routes, V[0] = the on-centre nominal. Not measurements:
|
||||||
|
# 0-23 deg (pinned by convention, not identified), 31-61 deg (interpolated across two bins that failed the lag test),
|
||||||
|
# 236+ deg (frozen; above 303 deg the data is parking speed). A compensation curve for calc_curvature's k = d/L,
|
||||||
|
# not the rack's true geometry. Bands: shape +/-0.12, level +/-0.57.
|
||||||
|
ACCORD_ANGLE_SR_BP = [0.0, 23.0, 31.0, 61.0, 76.0, 95.0, 116.0, 151.0, 178.0, 227.0, 236.0, 303.0, 380.0] # deg
|
||||||
|
ACCORD_ANGLE_SR_V = [16.88, 16.88, 16.88, 16.25, 15.97, 15.45, 15.03, 14.68, 14.45, 14.09, 14.25, 12.98, 12.31] # :1
|
||||||
|
# LEVEL: the served on-centre ratio; the whole shape is scaled by LEVEL / V[0]. 16.84 = the SteerRatio every angle
|
||||||
|
# drive ran (V298/V299 configs).
|
||||||
|
ACCORD_ANGLE_SR_LEVEL = 16.84
|
||||||
|
|
||||||
|
|
||||||
|
def accord_angle_steer_ratio(steer_angle_deg: float) -> float:
|
||||||
|
"""Local ratio of the Accord's rack at this wheel angle (deg, offset removed)."""
|
||||||
|
ratio = float(np.interp(abs(steer_angle_deg), ACCORD_ANGLE_SR_BP, ACCORD_ANGLE_SR_V))
|
||||||
|
return ratio * ACCORD_ANGLE_SR_LEVEL / ACCORD_ANGLE_SR_V[0]
|
||||||
|
|
||||||
|
|
||||||
|
def accord_angle_at_own_ratio(angle_vm_deg: float, sr_vm: float, max_passes: int = 10) -> float:
|
||||||
|
"""The angle setpoint with the map evaluated at the DESIRED angle instead of the measured one.
|
||||||
|
|
||||||
|
controlsd sets VM.sR = map(measured angle) and get_steer_from_curvature is linear in sR, so the consistent setpoint
|
||||||
|
is the fixed point theta = angle_vm_deg * map(theta) / sr_vm. Each pass shrinks the error by <= 0.44 (worst on the
|
||||||
|
236-303 deg knot); stops within 0.01 deg, a tenth of the EPS setpoint quantum.
|
||||||
|
"""
|
||||||
|
theta = float(angle_vm_deg)
|
||||||
|
for _ in range(max_passes):
|
||||||
|
nxt = float(angle_vm_deg) * accord_angle_steer_ratio(theta) / sr_vm
|
||||||
|
done = abs(nxt - theta) < 0.01
|
||||||
|
theta = nxt
|
||||||
|
if done:
|
||||||
|
break
|
||||||
|
return theta
|
||||||
|
|
||||||
|
|
||||||
# Car button codes
|
# Car button codes
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ class CANFDLfaStatus:
|
|||||||
LENGTH = 16
|
LENGTH = 16
|
||||||
MAX_AGE_NS = MAX_AGE_NS
|
MAX_AGE_NS = MAX_AGE_NS
|
||||||
|
|
||||||
def __init__(self, bus):
|
def __init__(self, bus, *, eps_response_margin_ns=0, track_camera_release=False):
|
||||||
self.bus = bus
|
self.bus = bus
|
||||||
|
self.eps_response_margin_ns = eps_response_margin_ns
|
||||||
|
self.track_camera_release = track_camera_release
|
||||||
self.last_packet_ns = 0
|
self.last_packet_ns = 0
|
||||||
self.counter = None
|
self.counter = None
|
||||||
self.body = None
|
self.body = None
|
||||||
@@ -61,6 +63,7 @@ class CANFDLfaStatus:
|
|||||||
self.camera_integrity = False
|
self.camera_integrity = False
|
||||||
self.camera_healthy_ns = 0
|
self.camera_healthy_ns = 0
|
||||||
self.camera_fault_since_ns = 0
|
self.camera_fault_since_ns = 0
|
||||||
|
self.camera_release_ns = 0
|
||||||
self.camera_fault_same_batch_healthy = False
|
self.camera_fault_same_batch_healthy = False
|
||||||
self.request_active = False
|
self.request_active = False
|
||||||
self.request_since_ns = 0
|
self.request_since_ns = 0
|
||||||
@@ -103,30 +106,46 @@ class CANFDLfaStatus:
|
|||||||
continue
|
continue
|
||||||
if address == self.ADDRESS and bus == self.bus and len(data) != self.LENGTH:
|
if address == self.ADDRESS and bus == self.bus and len(data) != self.LENGTH:
|
||||||
self.camera_integrity = False
|
self.camera_integrity = False
|
||||||
|
if self.track_camera_release:
|
||||||
|
self.camera_healthy_ns = 0
|
||||||
if address != self.ADDRESS or bus != self.bus or len(data) != self.LENGTH:
|
if address != self.ADDRESS or bus != self.bus or len(data) != self.LENGTH:
|
||||||
continue
|
continue
|
||||||
self.last_packet_ns = stamp
|
self.last_packet_ns = stamp
|
||||||
if int.from_bytes(data[:2], 'little') != hkg_can_fd_checksum(address, None, bytearray(data)):
|
if int.from_bytes(data[:2], 'little') != hkg_can_fd_checksum(address, None, bytearray(data)):
|
||||||
self.camera_integrity = False
|
self.camera_integrity = False
|
||||||
|
if self.track_camera_release:
|
||||||
|
self.camera_healthy_ns = 0
|
||||||
continue
|
continue
|
||||||
counter = data[2]
|
counter = data[2]
|
||||||
advancing = self.counter is None or counter == (self.counter + 1) % 256
|
advancing = self.counter is None or counter == (self.counter + 1) % 256
|
||||||
self.counter = counter
|
self.counter = counter
|
||||||
if not advancing:
|
if not advancing:
|
||||||
self.camera_integrity = False
|
self.camera_integrity = False
|
||||||
|
if self.track_camera_release:
|
||||||
|
self.camera_healthy_ns = 0
|
||||||
continue
|
continue
|
||||||
self.camera_integrity = True
|
self.camera_integrity = True
|
||||||
body = bytes(data)
|
body = bytes(data)
|
||||||
if self._ownership_warning(body):
|
camera_request = (body[6] >> 4) & 3
|
||||||
|
camera_warning = self._system_fail(body)
|
||||||
|
if self._ownership_warning(body) or (self.track_camera_release and camera_warning and camera_request == 1):
|
||||||
if not self.camera_fault_since_ns:
|
if not self.camera_fault_since_ns:
|
||||||
self.camera_fault_same_batch_healthy = (self.camera_healthy_ns == stamp and self.observed_ns == stamp and
|
self.camera_fault_same_batch_healthy = (self.camera_healthy_ns == stamp and self.observed_ns == stamp and
|
||||||
self.body is not None and self.body[2] == (counter - 1) % 256)
|
self.body is not None and self.body[2] == (counter - 1) % 256)
|
||||||
self.camera_fault_since_ns = stamp
|
self.camera_fault_since_ns = stamp
|
||||||
|
if camera_request:
|
||||||
|
self.camera_release_ns = 0
|
||||||
|
elif not self.camera_release_ns:
|
||||||
|
self.camera_release_ns = stamp
|
||||||
else:
|
else:
|
||||||
self.camera_fault_since_ns = 0
|
self.camera_fault_since_ns = self.camera_release_ns = 0
|
||||||
self.camera_fault_same_batch_healthy = False
|
self.camera_fault_same_batch_healthy = False
|
||||||
indication = (body[4] >> 6) | ((body[5] & 1) << 2)
|
indication = (body[4] >> 6) | ((body[5] & 1) << 2)
|
||||||
self.camera_healthy_ns = stamp if indication < 4 and not (body[6] & 0xF0 or body[7] >> 4 == 15) else 0
|
normal = indication < 4 and not (body[6] & 0xC0 or body[7] >> 4 == 15)
|
||||||
|
if normal and camera_request == 0:
|
||||||
|
self.camera_healthy_ns = stamp
|
||||||
|
elif not (self.track_camera_release and normal and camera_request == 1):
|
||||||
|
self.camera_healthy_ns = 0
|
||||||
self.body, self.observed_ns = body, stamp
|
self.body, self.observed_ns = body, stamp
|
||||||
|
|
||||||
def current(self, now_ns):
|
def current(self, now_ns):
|
||||||
@@ -135,10 +154,31 @@ class CANFDLfaStatus:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _system_fail(body):
|
||||||
|
return (((body[4] >> 6) | ((body[5] & 1) << 2)) == 4 and body[7] >> 4 == 15 and not body[6] & 0xC0)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _ownership_warning(body):
|
def _ownership_warning(body):
|
||||||
return (((body[4] >> 6) | ((body[5] & 1) << 2)) == 4 and body[7] >> 4 == 15 and
|
return CANFDLfaStatus._system_fail(body) and not body[6] & 0x30
|
||||||
not body[6] & 0xF0)
|
|
||||||
|
def steering_active_current(self, now_ns):
|
||||||
|
return (self.eps_active and self.eps_healthy and
|
||||||
|
0 < self.eps_observed_ns <= now_ns <= self.eps_observed_ns + MAX_AGE_NS)
|
||||||
|
|
||||||
|
def sportage_legacy_display(self, cp, now_ns, *, healthy):
|
||||||
|
if not (healthy and cp.carFingerprint == CAR.KIA_SPORTAGE_5TH_GEN and cp.openpilotLongitudinalControl and
|
||||||
|
cp.alternativeExperience == 32 and len(cp.safetyConfigs) == 1 and
|
||||||
|
cp.safetyConfigs[0].safetyModel == structs.CarParams.SafetyModel.hyundaiCanfd and
|
||||||
|
cp.safetyConfigs[0].safetyParam == 0x82C):
|
||||||
|
return False
|
||||||
|
body = self.current(now_ns)
|
||||||
|
if body is None or not self.camera_integrity or not self.eps_healthy:
|
||||||
|
return False
|
||||||
|
indication = (body[4] >> 6) | ((body[5] & 1) << 2)
|
||||||
|
return (0 < self.eps_observed_ns <= now_ns <= self.eps_observed_ns + MAX_AGE_NS and
|
||||||
|
not (body[6] & 0xC0) and
|
||||||
|
((indication < 4 and body[7] >> 4 == 0) or self._system_fail(body)))
|
||||||
|
|
||||||
def owns_display_status(self, active, now_ns, *, healthy=False):
|
def owns_display_status(self, active, now_ns, *, healthy=False):
|
||||||
if active and not self.request_active:
|
if active and not self.request_active:
|
||||||
@@ -149,7 +189,12 @@ class CANFDLfaStatus:
|
|||||||
if not healthy or body is None or not self.camera_integrity or not eps_fresh or not self.eps_healthy:
|
if not healthy or body is None or not self.camera_integrity or not eps_fresh or not self.eps_healthy:
|
||||||
self.request_since_ns = self.display_fault_since_ns = self.display_last_active_ns = 0
|
self.request_since_ns = self.display_fault_since_ns = self.display_last_active_ns = 0
|
||||||
return False
|
return False
|
||||||
if not self._ownership_warning(body):
|
release_delay = self.camera_release_ns - self.camera_fault_since_ns
|
||||||
|
# A short competing camera request can delay handover evidence until its release.
|
||||||
|
camera_released = (not self.track_camera_release or release_delay == 0 or
|
||||||
|
(0 < release_delay <= MAX_AGE_NS + self.eps_response_margin_ns and
|
||||||
|
not body[5] & 0xFE and body[6] & 0x0F == 8))
|
||||||
|
if not self._ownership_warning(body) or not camera_released:
|
||||||
self.display_fault_since_ns = self.display_last_active_ns = 0
|
self.display_fault_since_ns = self.display_last_active_ns = 0
|
||||||
return False
|
return False
|
||||||
established = self.display_fault_since_ns == self.camera_fault_since_ns and self.display_fault_since_ns > 0
|
established = self.display_fault_since_ns == self.camera_fault_since_ns and self.display_fault_since_ns > 0
|
||||||
@@ -161,7 +206,7 @@ class CANFDLfaStatus:
|
|||||||
qualified = (self.eps_active and 0 < self.request_since_ns <= self.eps_active_since_ns <= self.camera_fault_since_ns and
|
qualified = (self.eps_active and 0 < self.request_since_ns <= self.eps_active_since_ns <= self.camera_fault_since_ns and
|
||||||
((0 < self.camera_fault_since_ns - self.camera_healthy_ns <= MAX_AGE_NS) or
|
((0 < self.camera_fault_since_ns - self.camera_healthy_ns <= MAX_AGE_NS) or
|
||||||
(self.camera_fault_since_ns == self.camera_healthy_ns and self.camera_fault_same_batch_healthy)) and
|
(self.camera_fault_since_ns == self.camera_healthy_ns and self.camera_fault_same_batch_healthy)) and
|
||||||
self.camera_fault_since_ns - self.eps_active_since_ns <= OWNERSHIP_RESPONSE_NS)
|
self.camera_fault_since_ns - self.eps_active_since_ns <= OWNERSHIP_RESPONSE_NS + self.eps_response_margin_ns)
|
||||||
if qualified:
|
if qualified:
|
||||||
self.display_fault_since_ns = self.camera_fault_since_ns
|
self.display_fault_since_ns = self.camera_fault_since_ns
|
||||||
self.display_last_active_ns = now_ns
|
self.display_last_active_ns = now_ns
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ from opendbc.car.hyundai.torque_ev_scc import eligible as torque_ev_scc_eligible
|
|||||||
from opendbc.car.hyundai.ccnc_ev_stock import replacement_requested, qualified as qualified_ccnc_ev_stock
|
from opendbc.car.hyundai.ccnc_ev_stock import replacement_requested, qualified as qualified_ccnc_ev_stock
|
||||||
from opendbc.car.hyundai.angle_tx_recovery import AngleTxRecovery
|
from opendbc.car.hyundai.angle_tx_recovery import AngleTxRecovery
|
||||||
from opendbc.car.hyundai.values import is_blended, HyundaiFlags, HyundaiSafetyFlags, Buttons, CarControllerParams, CAR
|
from opendbc.car.hyundai.values import is_blended, HyundaiFlags, HyundaiSafetyFlags, Buttons, CarControllerParams, CAR
|
||||||
from opendbc.car.interfaces import CarControllerBase
|
from opendbc.car.interfaces import CarControllerBase, V_CRUISE_MAX
|
||||||
from opendbc.car.vehicle_model import VehicleModel
|
from opendbc.car.vehicle_model import VehicleModel
|
||||||
|
|
||||||
EV9_OP_LONG_ANGLE_TARGET_MAX = 140.0
|
EV9_OP_LONG_ANGLE_TARGET_MAX = 140.0
|
||||||
@@ -124,6 +124,7 @@ class CarController(CarControllerBase):
|
|||||||
self.apply_angle_last = 0.0
|
self.apply_angle_last = 0.0
|
||||||
self.angle_gain_last = 0.0
|
self.angle_gain_last = 0.0
|
||||||
self.angle_fault_driver_override = False
|
self.angle_fault_driver_override = False
|
||||||
|
self.stock_angle_lka_active = False
|
||||||
self.angle_tx_recovery = (AngleTxRecovery(0xCB, self.CAN.ECAN)
|
self.angle_tx_recovery = (AngleTxRecovery(0xCB, self.CAN.ECAN)
|
||||||
if pe_long_qualified(CP) or ev9_long_qualified(CP) else AngleTxRecovery(0x110, self.CAN.ACAN)
|
if pe_long_qualified(CP) or ev9_long_qualified(CP) else AngleTxRecovery(0x110, self.CAN.ACAN)
|
||||||
if CP.carFingerprint in (CAR.HYUNDAI_IONIQ_5_PE, CAR.KIA_EV9) and
|
if CP.carFingerprint in (CAR.HYUNDAI_IONIQ_5_PE, CAR.KIA_EV9) and
|
||||||
@@ -177,7 +178,6 @@ class CarController(CarControllerBase):
|
|||||||
int(CP.safetyConfigs[-1].safetyParam) in (0x0811, 0x0891))
|
int(CP.safetyConfigs[-1].safetyParam) in (0x0811, 0x0891))
|
||||||
self.canfd_torque_aol_status = (qualified_canfd_stock_aol(CP) or qualified_canfd_long_aol(CP))
|
self.canfd_torque_aol_status = (qualified_canfd_stock_aol(CP) or qualified_canfd_long_aol(CP))
|
||||||
self.ccnc_fault_ownership_required = preserves_stock_lfa(CP)
|
self.ccnc_fault_ownership_required = preserves_stock_lfa(CP)
|
||||||
self.kona_last_lfa_counter = None
|
|
||||||
self.canfd_dash_icons = CanFDDashIcons() if ioniq6_status or self.canfd_torque_aol_status else None
|
self.canfd_dash_icons = CanFDDashIcons() if ioniq6_status or self.canfd_torque_aol_status else None
|
||||||
self.classic_dash_icons = CanFDDashIcons() if classic_aol_dash_enabled(CP) else None
|
self.classic_dash_icons = CanFDDashIcons() if classic_aol_dash_enabled(CP) else None
|
||||||
self.classic_lfa_icon = None
|
self.classic_lfa_icon = None
|
||||||
@@ -203,7 +203,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.
|
||||||
@@ -445,7 +446,13 @@ class CarController(CarControllerBase):
|
|||||||
_projection = self.learning_projection_observer
|
_projection = self.learning_projection_observer
|
||||||
can_sends = []
|
can_sends = []
|
||||||
stock_popup_owned = False
|
stock_popup_owned = False
|
||||||
|
sportage_legacy_display = False
|
||||||
stock_ccnc_owned = False
|
stock_ccnc_owned = False
|
||||||
|
kona_handoff = (self.CP.carFingerprint == CAR.HYUNDAI_KONA_2ND_GEN and
|
||||||
|
self.CP.safetyConfigs[-1].safetyParam == KONA_IDLE_AOL_WORD)
|
||||||
|
show_cruise = CS.out.cruiseState.available and (not kona_handoff or CC.enabled or
|
||||||
|
0. < CS.out.vCruiseCluster <= V_CRUISE_MAX)
|
||||||
|
show_ccnc_lateral = CC.latActive
|
||||||
canfd_lfa_icon = (self.canfd_dash_icons.update(self.frame, CC.enabled, CC.latActive)
|
canfd_lfa_icon = (self.canfd_dash_icons.update(self.frame, CC.enabled, CC.latActive)
|
||||||
if self.canfd_dash_icons is not None else None)
|
if self.canfd_dash_icons is not None else None)
|
||||||
|
|
||||||
@@ -544,7 +551,9 @@ class CarController(CarControllerBase):
|
|||||||
angle_active, self.params, self.angle_vm)
|
angle_active, self.params, self.angle_vm)
|
||||||
self.angle_gain_last = angle_torque_reduction_gain(CS.out.steeringTorque, CS.out.vEgoRaw,
|
self.angle_gain_last = angle_torque_reduction_gain(CS.out.steeringTorque, CS.out.vEgoRaw,
|
||||||
angle_active, self.angle_gain_last)
|
angle_active, self.angle_gain_last)
|
||||||
if not ccnc_ev_stock or ccnc_ev_replacement:
|
stock_angle_handoff = angle_aol and lka_steering and not ccnc_ev_stock
|
||||||
|
if ((not ccnc_ev_stock or ccnc_ev_replacement) and
|
||||||
|
(not stock_angle_handoff or angle_active or self.stock_angle_lka_active)):
|
||||||
can_sends.extend(
|
can_sends.extend(
|
||||||
hyundaicanfd.create_angle_steering_messages(
|
hyundaicanfd.create_angle_steering_messages(
|
||||||
self.packer,
|
self.packer,
|
||||||
@@ -558,6 +567,7 @@ class CarController(CarControllerBase):
|
|||||||
CS.out.steeringAngleDeg,
|
CS.out.steeringAngleDeg,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self.stock_angle_lka_active = stock_angle_handoff and angle_active
|
||||||
else:
|
else:
|
||||||
steering_status_active = CC.enabled
|
steering_status_active = CC.enabled
|
||||||
if ((self.CP.carFingerprint == CAR.KIA_CARNIVAL_2025 and self.CP.safetyConfigs[-1].safetyParam == 0x28B4) or
|
if ((self.CP.carFingerprint == CAR.KIA_CARNIVAL_2025 and self.CP.safetyConfigs[-1].safetyParam == 0x28B4) or
|
||||||
@@ -569,36 +579,29 @@ class CarController(CarControllerBase):
|
|||||||
stock_lfa = stock_source.current(clock_boot_ns()) if stock_source is not None else None
|
stock_lfa = stock_source.current(clock_boot_ns()) if stock_source is not None else None
|
||||||
stock_faults = stock_source.last_fault() if stock_source is not None and stock_lfa is None else None
|
stock_faults = stock_source.last_fault() if stock_source is not None and stock_lfa is None else None
|
||||||
stock_owned_status = False
|
stock_owned_status = False
|
||||||
|
if kona_handoff:
|
||||||
|
show_ccnc_lateral = bool(apply_steer_req and stock_source is not None and stock_source.steering_active_current(clock_boot_ns()))
|
||||||
if stock_source is not None:
|
if stock_source is not None:
|
||||||
display_healthy = CS.out.canValid and not (CS.out.canTimeout or CS.out.steerFaultTemporary or
|
display_healthy = CS.out.canValid and not (CS.out.canTimeout or CS.out.steerFaultTemporary or
|
||||||
CS.out.steerFaultPermanent or CS.out.accFaulted)
|
CS.out.steerFaultPermanent or CS.out.accFaulted)
|
||||||
stock_owned_status = stock_source.owns_display_status(apply_steer_req, clock_boot_ns(), healthy=display_healthy)
|
stock_owned_status = stock_source.owns_display_status(apply_steer_req, clock_boot_ns(), healthy=display_healthy)
|
||||||
stock_popup_owned = stock_source.owns_disengage_popup(apply_steer_req, clock_boot_ns(), healthy=display_healthy,
|
stock_popup_owned = stock_source.owns_disengage_popup(apply_steer_req, clock_boot_ns(), healthy=display_healthy,
|
||||||
qualified_warning=stock_owned_status)
|
qualified_warning=stock_owned_status)
|
||||||
if ccnc_non_lka:
|
if self.CP.carFingerprint == CAR.KIA_SPORTAGE_5TH_GEN:
|
||||||
|
sportage_legacy_display = stock_source.sportage_legacy_display(self.CP, clock_boot_ns(), healthy=display_healthy)
|
||||||
|
if ccnc_non_lka and not kona_handoff:
|
||||||
stock_ccnc_owned = stock_source.owns_ccnc_fault_status(clock_boot_ns(), display_sample_ns=CS.ccnc_162_ts_ns,
|
stock_ccnc_owned = stock_source.owns_ccnc_fault_status(clock_boot_ns(), display_sample_ns=CS.ccnc_162_ts_ns,
|
||||||
healthy=display_healthy, qualified_warning=stock_owned_status)
|
healthy=display_healthy, qualified_warning=stock_owned_status)
|
||||||
damping_source = getattr(CS, "stock_lkas_damping", None)
|
damping_source = getattr(CS, "stock_lkas_damping", None)
|
||||||
kona_handoff = (self.CP.carFingerprint == CAR.HYUNDAI_KONA_2ND_GEN and
|
can_sends.extend(hyundaicanfd.create_steering_messages(self.packer, self.CP, self.CAN,
|
||||||
self.CP.safetyConfigs[-1].safetyParam == KONA_IDLE_AOL_WORD)
|
steering_status_active, apply_steer_req, apply_torque,
|
||||||
lfa_counter = None
|
stock_lfa=stock_lfa, stock_lfa_faults=stock_faults,
|
||||||
if kona_handoff:
|
stock_lfa_owned_status=stock_owned_status and not kona_handoff,
|
||||||
if (CC.enabled or CC.latActive) and stock_lfa is not None:
|
stock_lkas_damping=(damping_source.current_damping(clock_boot_ns())
|
||||||
if stock_lfa[2] != self.kona_last_lfa_counter:
|
if damping_source is not None else None),
|
||||||
lfa_counter = stock_lfa[2]
|
legacy_lane_display=sportage_legacy_display))
|
||||||
self.kona_last_lfa_counter = lfa_counter
|
if _projection is not None:
|
||||||
else:
|
_projection.emit('hyundai.CANFD_TORQUE', apply_torque, apply_steer_req, can_sends[-1])
|
||||||
self.kona_last_lfa_counter = None
|
|
||||||
if not kona_handoff or lfa_counter is not None:
|
|
||||||
can_sends.extend(hyundaicanfd.create_steering_messages(self.packer, self.CP, self.CAN,
|
|
||||||
steering_status_active, apply_steer_req, apply_torque,
|
|
||||||
stock_lfa=stock_lfa, stock_lfa_faults=stock_faults,
|
|
||||||
stock_lfa_owned_status=stock_owned_status,
|
|
||||||
stock_lkas_damping=(damping_source.current_damping(clock_boot_ns())
|
|
||||||
if damping_source is not None else None),
|
|
||||||
lfa_counter=lfa_counter))
|
|
||||||
if _projection is not None:
|
|
||||||
_projection.emit('hyundai.CANFD_TORQUE', apply_torque, apply_steer_req, can_sends[-1])
|
|
||||||
|
|
||||||
# prevent LFA from activating on LKA steering cars by sending "no lane lines detected" to ADAS ECU
|
# prevent LFA from activating on LKA steering cars by sending "no lane lines detected" to ADAS ECU
|
||||||
if (
|
if (
|
||||||
@@ -628,15 +631,17 @@ class CarController(CarControllerBase):
|
|||||||
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, show_ccnc_lateral,
|
||||||
owned_lfa_status=(stock_ccnc_owned if self.ccnc_fault_ownership_required else None)))
|
owned_lfa_status=stock_ccnc_owned if kona_handoff or 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:
|
||||||
cluster_source = getattr(CS, "stock_cluster_status", None)
|
cluster_source = getattr(CS, "stock_cluster_status", None)
|
||||||
stock_cluster = cluster_source.current(clock_boot_ns()) if cluster_source is not None else None
|
stock_cluster = cluster_source.current(clock_boot_ns()) if cluster_source is not None else None
|
||||||
can_sends.append(hyundaicanfd.create_lfahda_cluster(self.packer, self.CAN, CC.enabled, lfa_icon=canfd_lfa_icon,
|
can_sends.append(hyundaicanfd.create_lfahda_cluster(self.packer, self.CAN, CC.enabled, lfa_icon=canfd_lfa_icon,
|
||||||
stock_cluster=stock_cluster, owned_lfa_status=stock_popup_owned))
|
stock_cluster=stock_cluster, owned_lfa_status=stock_popup_owned,
|
||||||
|
legacy_lane_display=sportage_legacy_display))
|
||||||
|
|
||||||
# blinkers
|
# blinkers
|
||||||
if lka_steering and self.CP.flags & HyundaiFlags.CANFD_ENABLE_BLINKERS:
|
if lka_steering and self.CP.flags & HyundaiFlags.CANFD_ENABLE_BLINKERS:
|
||||||
@@ -689,7 +694,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(show_cruise,
|
||||||
|
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 - 0.02 <= 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"
|
||||||
@@ -64,7 +64,10 @@ class CarState(CarStateBase):
|
|||||||
def __init__(self, CP):
|
def __init__(self, CP):
|
||||||
super().__init__(CP)
|
super().__init__(CP)
|
||||||
preserve_status = preserves_stock_lfa(CP)
|
preserve_status = preserves_stock_lfa(CP)
|
||||||
self.stock_lfa_status = CANFDLfaStatus(CanBus(CP).CAM) if preserve_status else None
|
sportage = CP.carFingerprint == CAR.KIA_SPORTAGE_5TH_GEN
|
||||||
|
self.stock_lfa_status = (CANFDLfaStatus(CanBus(CP).CAM, eps_response_margin_ns=10_000_000 if sportage else 0,
|
||||||
|
track_camera_release=sportage and bool(CP.flags & HyundaiFlags.CANFD_CAMERA_SCC))
|
||||||
|
if preserve_status else None)
|
||||||
self.stock_cluster_status = CANFDClusterStatus(CanBus(CP).CAM) if preserve_status else None
|
self.stock_cluster_status = CANFDClusterStatus(CanBus(CP).CAM) if preserve_status else None
|
||||||
self.stock_lkas_damping = (CANFDLkasDamping(CanBus(CP).CAM, bool(CP.flags & HyundaiFlags.CANFD_LKA_STEER_MSG_ALT))
|
self.stock_lkas_damping = (CANFDLkasDamping(CanBus(CP).CAM, bool(CP.flags & HyundaiFlags.CANFD_LKA_STEER_MSG_ALT))
|
||||||
if preserves_stock_lkas_damping(CP) else None)
|
if preserves_stock_lkas_damping(CP) else None)
|
||||||
@@ -260,6 +263,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 +420,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,
|
||||||
|
|||||||
@@ -45,7 +45,8 @@ LFA_FAULT_MASK = bytes.fromhex("00000000c001c0f00000000000000000")
|
|||||||
|
|
||||||
|
|
||||||
def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, *, stock_lfa=None, stock_lfa_faults=None,
|
def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, *, stock_lfa=None, stock_lfa_faults=None,
|
||||||
stock_lkas_damping=None, stock_lfa_owned_status=False, lfa_counter=None):
|
stock_lkas_damping=None, stock_lfa_owned_status=False,
|
||||||
|
legacy_lane_display=False):
|
||||||
values = {
|
values = {
|
||||||
"LKA_OptUsmSta": 2,
|
"LKA_OptUsmSta": 2,
|
||||||
"LKA_SysIndReq": 2 if enabled else 1,
|
"LKA_SysIndReq": 2 if enabled else 1,
|
||||||
@@ -73,16 +74,15 @@ def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque,
|
|||||||
lkas_values = {**values, "Damping_Gain": damping}
|
lkas_values = {**values, "Damping_Gain": damping}
|
||||||
ret.append(packer.make_can_msg(lkas_msg, CAN.ACAN, lkas_values))
|
ret.append(packer.make_can_msg(lkas_msg, CAN.ACAN, lkas_values))
|
||||||
else:
|
else:
|
||||||
if lfa_counter is not None:
|
|
||||||
values["COUNTER"] = lfa_counter
|
|
||||||
message = packer.make_can_msg("LFA", CAN.ECAN, values)
|
message = packer.make_can_msg("LFA", CAN.ECAN, values)
|
||||||
source = stock_lfa if stock_lfa is not None else stock_lfa_faults
|
source = stock_lfa if stock_lfa is not None else stock_lfa_faults
|
||||||
if source is not None:
|
if source is not None:
|
||||||
# Stale samples retain only faults; a fresh healthy camera sample clears them.
|
# Stale samples retain only faults; a fresh healthy camera sample clears them.
|
||||||
mask = LFA_CONTROL_MASK if stock_lfa is not None else bytes(value ^ 0xFF for value in LFA_FAULT_MASK)
|
mask = LFA_CONTROL_MASK if stock_lfa is not None else bytes(value ^ 0xFF for value in LFA_FAULT_MASK)
|
||||||
stock_indication = (source[4] >> 6) | ((source[5] & 1) << 2)
|
stock_indication = (source[4] >> 6) | ((source[5] & 1) << 2)
|
||||||
owned_status = (stock_lfa is not None and stock_lfa_owned_status and stock_indication == 4 and
|
owned_status = (stock_lfa is not None and stock_indication == 4 and source[7] >> 4 == 15 and
|
||||||
source[7] >> 4 == 15 and not source[6] & 0xF0)
|
not source[6] & 0xC0 and
|
||||||
|
(legacy_lane_display or (stock_lfa_owned_status and not source[6] & 0x30)))
|
||||||
if owned_status:
|
if owned_status:
|
||||||
mask = bytearray(mask)
|
mask = bytearray(mask)
|
||||||
mask[7] |= 0xF0
|
mask[7] |= 0xF0
|
||||||
@@ -228,7 +228,7 @@ def create_acc_cancel(packer, CP, CAN, cruise_info_copy):
|
|||||||
CLUSTER_CONTROL_MASK = bytes.fromhex("ffffff80008001000000000000000000")
|
CLUSTER_CONTROL_MASK = bytes.fromhex("ffffff80008001000000000000000000")
|
||||||
|
|
||||||
|
|
||||||
def create_lfahda_cluster(packer, CAN, enabled, *, lfa_icon=None, stock_cluster=None, owned_lfa_status=False):
|
def create_lfahda_cluster(packer, CAN, enabled, *, lfa_icon=None, stock_cluster=None, owned_lfa_status=False, legacy_lane_display=False):
|
||||||
values = {
|
values = {
|
||||||
"HDA_ICON": 1 if enabled else 0,
|
"HDA_ICON": 1 if enabled else 0,
|
||||||
"LFA_ICON": (2 if enabled else 0) if lfa_icon is None else lfa_icon,
|
"LFA_ICON": (2 if enabled else 0) if lfa_icon is None else lfa_icon,
|
||||||
@@ -237,7 +237,8 @@ def create_lfahda_cluster(packer, CAN, enabled, *, lfa_icon=None, stock_cluster=
|
|||||||
if stock_cluster is not None:
|
if stock_cluster is not None:
|
||||||
data = bytearray((old & ~owned) | (new & owned)
|
data = bytearray((old & ~owned) | (new & owned)
|
||||||
for old, new, owned in zip(stock_cluster, message[1], CLUSTER_CONTROL_MASK, strict=True))
|
for old, new, owned in zip(stock_cluster, message[1], CLUSTER_CONTROL_MASK, strict=True))
|
||||||
if owned_lfa_status and stock_cluster[4] & 7 == 3:
|
popup = stock_cluster[4] & 7
|
||||||
|
if (owned_lfa_status and popup == 3) or (legacy_lane_display and popup in (3, 5, 6)):
|
||||||
data[4] &= 0xF8
|
data[4] &= 0xF8
|
||||||
data[:2] = hkg_can_fd_checksum(message[0], None, data).to_bytes(2, "little")
|
data[:2] = hkg_can_fd_checksum(message[0], None, data).to_bytes(2, "little")
|
||||||
message = (message[0], bytes(data), message[2])
|
message = (message[0], bytes(data), message[2])
|
||||||
@@ -329,7 +330,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 +414,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,33 @@ 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:
|
||||||
|
# Controls may construct a PID for this profile. Keep it inert with valid gains.
|
||||||
|
ret.lateralTuning.pid.kpBP = ret.lateralTuning.pid.kiBP = [0.0]
|
||||||
|
ret.lateralTuning.pid.kpV = ret.lateralTuning.pid.kiV = [0.0]
|
||||||
|
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 +334,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))
|
||||||
|
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ def test_ae0_physical_tracker_is_inactive_until_final_ae32(hda2):
|
|||||||
|
|
||||||
@pytest.mark.parametrize('hda2', (False, True))
|
@pytest.mark.parametrize('hda2', (False, True))
|
||||||
@pytest.mark.parametrize('corruption', ('crc', 'replay', 'wrong_bus', 'inactive'))
|
@pytest.mark.parametrize('corruption', ('crc', 'replay', 'wrong_bus', 'inactive'))
|
||||||
def test_real_controller_invalid_replacement_does_not_acquire_forwarding(hda2, corruption):
|
def test_real_controller_forwarding_requires_valid_replacement(hda2, corruption):
|
||||||
cp = params(hda2)
|
cp = params(hda2)
|
||||||
cp.alternativeExperience = 32
|
cp.alternativeExperience = 32
|
||||||
ci = CarInterface(cp)
|
ci = CarInterface(cp)
|
||||||
@@ -295,7 +295,14 @@ def test_real_controller_invalid_replacement_does_not_acquire_forwarding(hda2, c
|
|||||||
elif corruption == 'wrong_bus':
|
elif corruption == 'wrong_bus':
|
||||||
assert not safety.safety_tx_hook(libsafety_py.make_CANPacket(addr, 1, data))
|
assert not safety.safety_tx_hook(libsafety_py.make_CANPacket(addr, 1, data))
|
||||||
else:
|
else:
|
||||||
|
assert safety.safety_fwd_hook(2, addr) == 0
|
||||||
|
if hda2:
|
||||||
|
assert ((data[6] & 0x1F) << 7 | data[5] >> 1) == 1024
|
||||||
assert safety.safety_tx_hook(libsafety_py.make_CANPacket(addr, bus, data))
|
assert safety.safety_tx_hook(libsafety_py.make_CANPacket(addr, bus, data))
|
||||||
|
if hda2:
|
||||||
|
assert safety.safety_fwd_hook(2, addr) == -1
|
||||||
|
assert safety.safety_fwd_hook(2, 0x2A4) == 0
|
||||||
|
safety.set_timer(((now // 1000) + 200_001) & 0xFFFFFFFF)
|
||||||
assert safety.safety_fwd_hook(2, addr) == 0
|
assert safety.safety_fwd_hook(2, addr) == 0
|
||||||
|
|
||||||
|
|
||||||
@@ -347,7 +354,11 @@ def test_real_controller_crc_fault_revokes_token_then_fresh_gesture_recovers(hda
|
|||||||
assert permission == 0 and not accepted
|
assert permission == 0 and not accepted
|
||||||
assert safety.safety_fwd_hook(2, addr) == 0
|
assert safety.safety_fwd_hook(2, addr) == 0
|
||||||
if 80 <= tick < 100:
|
if 80 <= tick < 100:
|
||||||
assert permission == 0 and safety.safety_fwd_hook(2, addr) == 0
|
assert permission == 0
|
||||||
|
if hda2:
|
||||||
|
assert accepted and ((data[6] & 0x1F) << 7 | data[5] >> 1) == 1024
|
||||||
|
assert safety.safety_fwd_hook(2, 0x2A4) == 0
|
||||||
|
assert safety.safety_fwd_hook(2, addr) == (-1 if hda2 else 0)
|
||||||
if tick >= 115:
|
if tick >= 115:
|
||||||
assert permission == 1 and accepted
|
assert permission == 1 and accepted
|
||||||
assert safety.safety_fwd_hook(2, addr) == -1
|
assert safety.safety_fwd_hook(2, addr) == -1
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -1009,3 +1009,119 @@ def test_ccnc_fault_handover_preserves_obstruction_and_unknown_codes(fault, owne
|
|||||||
for field in ('COUNTER', 'FAULT_FCA', 'FAULT_FSS', 'FAULT_ESS', 'FAULT_SCC'):
|
for field in ('COUNTER', 'FAULT_FCA', 'FAULT_FSS', 'FAULT_ESS', 'FAULT_SCC'):
|
||||||
assert decoder.vl['CCNC_0x162'][field] == original[field]
|
assert decoder.vl['CCNC_0x162'][field] == original[field]
|
||||||
assert decoder.vl['CCNC_0x161']['LFA_ICON'] == decoder.vl['CCNC_0x161']['CENTERLINE'] == 0
|
assert decoder.vl['CCNC_0x161']['LFA_ICON'] == decoder.vl['CCNC_0x161']['CENTERLINE'] == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('alpha', (False, True))
|
||||||
|
@pytest.mark.parametrize('vehicle,case,owned', [
|
||||||
|
(CAR.KIA_SPORTAGE_5TH_GEN, 'recorded', True),
|
||||||
|
(CAR.KIA_SPORTAGE_5TH_GEN, 'late', False),
|
||||||
|
(CAR.KIA_SPORTAGE_5TH_GEN, 'idle', False),
|
||||||
|
(CAR.KIA_SPORTAGE_5TH_GEN, 'eps_fault', False),
|
||||||
|
(CAR.KIA_SPORTAGE_5TH_GEN, 'camera_fault', False),
|
||||||
|
(CAR.KIA_NIRO_EV_2ND_GEN, 'recorded', False),
|
||||||
|
])
|
||||||
|
def test_sportage_display_ownership_accepts_one_camera_frame_of_timing_skew(vehicle, case, owned, alpha, clock):
|
||||||
|
cp = params(vehicle, alpha=alpha, alternate=True)
|
||||||
|
ci = CarInterface(cp)
|
||||||
|
ci.update([])
|
||||||
|
packer = CANPacker(DBC[vehicle][Bus.pt])
|
||||||
|
bus = ci.CC.CAN
|
||||||
|
command = structs.CarControl.new_message()
|
||||||
|
observed = {}
|
||||||
|
for tick in range(28):
|
||||||
|
clock[0] = 30_000_000_000 + tick * 10_000_000 + (310_000 if tick >= 19 else 0)
|
||||||
|
command.enabled = command.latActive = tick >= 2 and case != 'idle'
|
||||||
|
warning = tick >= (21 if case == 'late' else 19)
|
||||||
|
stock = template(packer, bus.CAM, tick, warning=15 if warning else 0, fault=int(warning and case == 'camera_fault'))
|
||||||
|
frames = [frame for frame in physical_frames(ci, packer, tick, stock) if frame[0] != 0xEA]
|
||||||
|
frames.append(packer.make_can_msg('MDPS', bus.ECAN, {'COUNTER': tick,
|
||||||
|
'MDPS_LkaToiActvSta': int(tick >= 4 and case != 'idle'), 'MDPS_LkaFailSta': int(warning and case == 'eps_fault')}))
|
||||||
|
if tick % 5 == 0:
|
||||||
|
frame = packer.make_can_msg('LFAHDA_CLUSTER', bus.CAM, {'COUNTER': tick // 5, 'NEW_SIGNAL_1': 3 if warning else 0})
|
||||||
|
frames.append(frame)
|
||||||
|
assert ci.update([(clock[0], frames)]).canValid
|
||||||
|
_, packets = ci.apply(command.as_reader(), clock[0])
|
||||||
|
if tick >= 25:
|
||||||
|
observed.update((address, body) for address, body, src in packets if src == bus.ECAN and address in (0x12A, 0x1E0))
|
||||||
|
assert observed[0x12A][7] >> 4 == (0 if owned else 15)
|
||||||
|
assert observed[0x12A][6] >> 6 == int(case == 'camera_fault')
|
||||||
|
assert observed[0x1E0][4] & 7 == (0 if owned else 3)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('alpha', (False, True))
|
||||||
|
@pytest.mark.parametrize('case', ('recorded', 'late', 'no_release', 'nonzero_release', 'eps_fault', 'camera_fault', 'crc_gap'))
|
||||||
|
def test_sportage_recovers_display_after_camera_yields_steering(alpha, case, clock):
|
||||||
|
cp = params(CAR.KIA_SPORTAGE_5TH_GEN, alpha=alpha, alternate=True)
|
||||||
|
ci = CarInterface(cp)
|
||||||
|
ci.update([])
|
||||||
|
packer = CANPacker(DBC[cp.carFingerprint][Bus.pt])
|
||||||
|
bus = ci.CC.CAN
|
||||||
|
command = structs.CarControl.new_message()
|
||||||
|
output = {}
|
||||||
|
for tick in range(41):
|
||||||
|
clock[0] = 40_000_000_000 + tick * 10_000_000
|
||||||
|
command.latActive = tick >= 2
|
||||||
|
warning = tick >= 18
|
||||||
|
release = 23 if case not in ('late', 'no_release') else 37 if case == 'late' else 42
|
||||||
|
factory_request = 16 <= tick < release
|
||||||
|
factory_torque = 4 if factory_request or (tick >= release and case == 'nonzero_release') else 0
|
||||||
|
stock = packer.make_can_msg('LFA', bus.CAM, {
|
||||||
|
'COUNTER': tick, 'LKA_SysIndReq': 4 if warning else 1, 'LKA_SysWrn': 15 if warning else 0,
|
||||||
|
'ActToiSta': int(factory_request), 'StrTqReqVal': factory_torque, 'ToiFltSta': int(warning and case == 'camera_fault'),
|
||||||
|
})
|
||||||
|
if case == 'crc_gap' and tick == 20:
|
||||||
|
bad = bytes([stock[1][0] ^ 1]) + stock[1][1:]
|
||||||
|
stock = stock[0], bad, stock[2]
|
||||||
|
frames = [frame for frame in physical_frames(ci, packer, tick, stock) if frame[0] != 0xEA]
|
||||||
|
frames.append(packer.make_can_msg('MDPS', bus.ECAN, {'COUNTER': tick, 'MDPS_LkaToiActvSta': int(tick >= 4),
|
||||||
|
'MDPS_LkaFailSta': int(warning and case == 'eps_fault')}))
|
||||||
|
if tick % 5 == 0:
|
||||||
|
frames.append(packer.make_can_msg('LFAHDA_CLUSTER', bus.CAM, {'COUNTER': tick // 5, 'NEW_SIGNAL_1': 3 if warning else 0}))
|
||||||
|
assert ci.update([(clock[0], frames)]).canValid
|
||||||
|
_, packets = ci.apply(command.as_reader(), clock[0])
|
||||||
|
for addr, data, src in packets:
|
||||||
|
if src != bus.ECAN:
|
||||||
|
continue
|
||||||
|
if addr == 0x12A:
|
||||||
|
assert data[6] >> 4 & 3 == int(command.latActive)
|
||||||
|
if warning and tick < release:
|
||||||
|
assert data[7] >> 4 == 15
|
||||||
|
if addr in (0x12A, 0x1E0):
|
||||||
|
output[addr] = data
|
||||||
|
expected = case == 'recorded'
|
||||||
|
assert output[0x12A][7] >> 4 == (0 if expected else 15)
|
||||||
|
assert output[0x1E0][4] & 7 == (0 if expected else 3)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('popup', (3, 5, 6, 7))
|
||||||
|
@pytest.mark.parametrize('case', ('recorded', 'stock', 'eps_failure', 'camera_failure', 'unknown_warning', 'stale_camera'))
|
||||||
|
def test_sportage_legacy_lane_display_is_scoped_and_fault_aware(popup, case, clock):
|
||||||
|
cp = params(CAR.KIA_SPORTAGE_5TH_GEN, alpha=case != 'stock', alternate=True)
|
||||||
|
cp.safetyConfigs[0].safetyParam = 0x828 if case == 'stock' else 0x82C
|
||||||
|
cp.alternativeExperience = 32
|
||||||
|
ci = CarInterface(cp)
|
||||||
|
ci.update([])
|
||||||
|
packer = CANPacker(DBC[cp.carFingerprint][Bus.pt])
|
||||||
|
bus = ci.CC.CAN
|
||||||
|
command = structs.CarControl.new_message()
|
||||||
|
output = {}
|
||||||
|
for tick in range(16):
|
||||||
|
clock[0] = 40_000_000_000 + tick * 10_000_000
|
||||||
|
warning = 9 if case == 'unknown_warning' else 15
|
||||||
|
stock = packer.make_can_msg('LFA', bus.CAM, {
|
||||||
|
'COUNTER': tick, 'LKA_SysIndReq': 4, 'LKA_SysWrn': warning, 'ActToiSta': 1, 'StrTqReqVal': 17,
|
||||||
|
'ToiFltSta': int(case == 'camera_failure'),
|
||||||
|
})
|
||||||
|
frames = [frame for frame in physical_frames(ci, packer, tick, stock) if frame[0] != 0xEA]
|
||||||
|
if case == 'stale_camera' and tick > 3:
|
||||||
|
frames = [frame for frame in frames if frame[0] != 0x12A]
|
||||||
|
frames.append(packer.make_can_msg('MDPS', bus.ECAN, {'COUNTER': tick, 'MDPS_LkaFailSta': int(case == 'eps_failure')}))
|
||||||
|
if tick % 5 == 0:
|
||||||
|
frames.append(packer.make_can_msg('LFAHDA_CLUSTER', bus.CAM, {'COUNTER': tick // 5, 'NEW_SIGNAL_1': popup}))
|
||||||
|
assert ci.update([(clock[0], frames)]).canValid
|
||||||
|
_, packets = ci.apply(command.as_reader(), clock[0])
|
||||||
|
output.update((addr, data) for addr, data, src in packets if src == bus.ECAN and addr in (0x12A, 0x1E0))
|
||||||
|
assert output[0x12A][7] >> 4 == (0 if case == 'recorded' else warning)
|
||||||
|
assert output[0x12A][6] >> 6 == int(case == 'camera_failure')
|
||||||
|
assert (int.from_bytes(output[0x12A], 'little') >> 41) & 0xFFF == 1024
|
||||||
|
assert output[0x1E0][4] & 7 == (0 if case == 'recorded' and popup != 7 else popup)
|
||||||
|
|||||||
@@ -387,8 +387,21 @@ class TestHyundaiFingerprint(unittest.TestCase):
|
|||||||
fingerprint = gen_empty_fingerprint()
|
fingerprint = gen_empty_fingerprint()
|
||||||
for car_model in CAR:
|
for car_model in CAR:
|
||||||
CP = CarInterface.get_params(car_model, fingerprint, [], False, False, False)
|
CP = CarInterface.get_params(car_model, fingerprint, [], False, False, False)
|
||||||
|
if CP.safetyConfigs[-1].safetyModel == CarParams.SafetyModel.noOutput:
|
||||||
|
assert CP.dashcamOnly
|
||||||
|
continue
|
||||||
assert bool(CP.flags & HyundaiFlags.ALT_LIMITS) == bool(CP.safetyConfigs[-1].safetyParam & HyundaiSafetyFlags.ALT_LIMITS)
|
assert bool(CP.flags & HyundaiFlags.ALT_LIMITS) == bool(CP.safetyConfigs[-1].safetyParam & HyundaiSafetyFlags.ALT_LIMITS)
|
||||||
|
|
||||||
|
def test_i30_2026_remains_dashcam_only(self):
|
||||||
|
for alpha in (False, True):
|
||||||
|
for release in (False, True):
|
||||||
|
with self.subTest(alpha=alpha, release=release):
|
||||||
|
cp = CarInterface.get_params(CAR.HYUNDAI_I30_2026, gen_empty_fingerprint(), [], alpha, release, False)
|
||||||
|
assert cp.dashcamOnly and not cp.openpilotLongitudinalControl
|
||||||
|
assert len(cp.safetyConfigs) == 1 and cp.safetyConfigs[0].safetyModel == CarParams.SafetyModel.noOutput
|
||||||
|
assert cp.lateralTuning.pid.kf == 0
|
||||||
|
assert list(cp.lateralTuning.pid.kpV) == list(cp.lateralTuning.pid.kiV) == [0.0]
|
||||||
|
|
||||||
def test_can_features(self):
|
def test_can_features(self):
|
||||||
for car_model in CAR:
|
for car_model in CAR:
|
||||||
flags = car_model.config.flags
|
flags = car_model.config.flags
|
||||||
@@ -430,7 +443,8 @@ class TestHyundaiFingerprint(unittest.TestCase):
|
|||||||
if b"-" not in code:
|
if b"-" not in code:
|
||||||
continue
|
continue
|
||||||
part = code.split(b"-")[1]
|
part = code.split(b"-")[1]
|
||||||
assert not part.startswith(b'CW'), "Car has bad part number"
|
verified_shared_camera = car_model == CAR.HYUNDAI_TUCSON_4TH_GEN and code == b'NX4-CW010'
|
||||||
|
assert verified_shared_camera or not part.startswith(b'CW'), "Car has bad part number"
|
||||||
|
|
||||||
def test_correct_ecu_response_database(self):
|
def test_correct_ecu_response_database(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from unittest.mock import Mock, patch
|
|||||||
|
|
||||||
from openpilot.starpilot.vehicle_startup import VehicleStartupOwner
|
from openpilot.starpilot.vehicle_startup import VehicleStartupOwner
|
||||||
|
|
||||||
from opendbc.car import gen_empty_fingerprint
|
from opendbc.car import gen_empty_fingerprint, structs
|
||||||
from opendbc.car.can_definitions import CanData
|
from opendbc.car.can_definitions import CanData
|
||||||
from opendbc.car.car_helpers import get_car
|
from opendbc.car.car_helpers import get_car
|
||||||
from opendbc.car.hyundai.ioniq6_handoff import (HandoffOutcome, HandoffResult, ObservingCanRecv, build_ioniq6_hda2_long_candidate,
|
from opendbc.car.hyundai.ioniq6_handoff import (HandoffOutcome, HandoffResult, ObservingCanRecv, build_ioniq6_hda2_long_candidate,
|
||||||
@@ -686,7 +686,7 @@ class TestIoniq6PrepublicationHandoff(unittest.TestCase):
|
|||||||
|
|
||||||
card = self.ready_card(ioniq_selected=True)
|
card = self.ready_card(ioniq_selected=True)
|
||||||
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
||||||
cc = object()
|
cc = structs.CarControl().as_reader()
|
||||||
confirmed = HandoffResult(HandoffOutcome.CONFIRMED, 'confirmed')
|
confirmed = HandoffResult(HandoffOutcome.CONFIRMED, 'confirmed')
|
||||||
with (patch.object(card_module, 'confirm_ioniq6_prepared_takeover', return_value=confirmed) as takeover,
|
with (patch.object(card_module, 'confirm_ioniq6_prepared_takeover', return_value=confirmed) as takeover,
|
||||||
patch.object(card_module.cloudlog, 'event') as logged):
|
patch.object(card_module.cloudlog, 'event') as logged):
|
||||||
@@ -737,7 +737,7 @@ class TestIoniq6PrepublicationHandoff(unittest.TestCase):
|
|||||||
card = self.ready_card(ioniq_selected=True)
|
card = self.ready_card(ioniq_selected=True)
|
||||||
card.sm.valid['carControl'] = True
|
card.sm.valid['carControl'] = True
|
||||||
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
||||||
cc = object()
|
cc = structs.CarControl().as_reader()
|
||||||
failed = HandoffResult(HandoffOutcome.UNAVAILABLE, 'restore unverified')
|
failed = HandoffResult(HandoffOutcome.UNAVAILABLE, 'restore unverified')
|
||||||
with (patch.object(card_module, 'confirm_ioniq6_prepared_takeover', return_value=failed) as takeover,
|
with (patch.object(card_module, 'confirm_ioniq6_prepared_takeover', return_value=failed) as takeover,
|
||||||
patch.object(card_module.cloudlog, 'event') as logged):
|
patch.object(card_module.cloudlog, 'event') as logged):
|
||||||
@@ -760,7 +760,7 @@ class TestIoniq6PrepublicationHandoff(unittest.TestCase):
|
|||||||
card = self.ready_card(ioniq_selected=True)
|
card = self.ready_card(ioniq_selected=True)
|
||||||
card.sm.valid['carControl'] = True
|
card.sm.valid['carControl'] = True
|
||||||
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
||||||
cc = object()
|
cc = structs.CarControl().as_reader()
|
||||||
confirmed = HandoffResult(HandoffOutcome.CONFIRMED, 'confirmed')
|
confirmed = HandoffResult(HandoffOutcome.CONFIRMED, 'confirmed')
|
||||||
with patch.object(card_module, 'confirm_ioniq6_prepared_takeover', return_value=confirmed) as takeover:
|
with patch.object(card_module, 'confirm_ioniq6_prepared_takeover', return_value=confirmed) as takeover:
|
||||||
for mutation in (
|
for mutation in (
|
||||||
@@ -883,7 +883,7 @@ class TestIoniq6PrepublicationHandoff(unittest.TestCase):
|
|||||||
card = self.ready_card(ioniq_selected=True)
|
card = self.ready_card(ioniq_selected=True)
|
||||||
card.sm.valid['carControl'] = True
|
card.sm.valid['carControl'] = True
|
||||||
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
||||||
cc = object()
|
cc = structs.CarControl().as_reader()
|
||||||
clock = [100.0]
|
clock = [100.0]
|
||||||
waiting = HandoffResult(HandoffOutcome.NOT_READY, 'preflight_scc_period')
|
waiting = HandoffResult(HandoffOutcome.NOT_READY, 'preflight_scc_period')
|
||||||
confirmed = HandoffResult(HandoffOutcome.CONFIRMED, 'confirmed')
|
confirmed = HandoffResult(HandoffOutcome.CONFIRMED, 'confirmed')
|
||||||
@@ -911,7 +911,7 @@ class TestIoniq6PrepublicationHandoff(unittest.TestCase):
|
|||||||
def test_generic_ecu_init_waits_for_valid_can_and_live_control_once(self):
|
def test_generic_ecu_init_waits_for_valid_can_and_live_control_once(self):
|
||||||
card = self.ready_card(ioniq_selected=False)
|
card = self.ready_card(ioniq_selected=False)
|
||||||
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
cs = SimpleNamespace(canValid=True, canTimeout=False)
|
||||||
cc = object()
|
cc = structs.CarControl().as_reader()
|
||||||
for _ in range(20):
|
for _ in range(20):
|
||||||
card.controls_update(cs, cc)
|
card.controls_update(cs, cc)
|
||||||
card.CI.init.assert_not_called()
|
card.CI.init.assert_not_called()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
@@ -8,7 +9,7 @@ from opendbc.car.hyundai.canfd_owner import config_index
|
|||||||
from opendbc.car.hyundai.canfd_stock_aol import qualified_long
|
from opendbc.car.hyundai.canfd_stock_aol import qualified_long
|
||||||
from opendbc.car.hyundai.interface import CarInterface
|
from opendbc.car.hyundai.interface import CarInterface
|
||||||
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
||||||
from openpilot.starpilot.car.hyundai.aol import independent_cruise_buttons_supported, native_accepts_cp, policy_for
|
from openpilot.starpilot.car.hyundai.aol import configure_kona_factory_handoff, independent_cruise_buttons_supported, native_accepts_cp, policy_for
|
||||||
|
|
||||||
CARS = (CAR.HYUNDAI_KONA_2ND_GEN, CAR.HYUNDAI_KONA_HEV_2ND_GEN)
|
CARS = (CAR.HYUNDAI_KONA_2ND_GEN, CAR.HYUNDAI_KONA_HEV_2ND_GEN)
|
||||||
|
|
||||||
@@ -202,7 +203,7 @@ def test_wheel_choices_keep_aol_with_either_longitudinal_owner(car, alternate, a
|
|||||||
assert 'Toggle AOL' in feature.choices('MainCruiseButtonControl')
|
assert 'Toggle AOL' in feature.choices('MainCruiseButtonControl')
|
||||||
|
|
||||||
|
|
||||||
def test_idle_handoff_omits_only_kona_steering_packet():
|
def test_kona_steering_has_its_own_continuous_counter():
|
||||||
reference_cp = kona_params(CARS[0])
|
reference_cp = kona_params(CARS[0])
|
||||||
handoff_cp = kona_params(CARS[0])
|
handoff_cp = kona_params(CARS[0])
|
||||||
for cp, word in ((reference_cp, 0x0C0C), (handoff_cp, 0x1C0C)):
|
for cp, word in ((reference_cp, 0x0C0C), (handoff_cp, 0x1C0C)):
|
||||||
@@ -211,11 +212,11 @@ def test_idle_handoff_omits_only_kona_steering_packet():
|
|||||||
reference, candidate = CarInterface(reference_cp), CarInterface(handoff_cp)
|
reference, candidate = CarInterface(reference_cp), CarInterface(handoff_cp)
|
||||||
source = Mock()
|
source = Mock()
|
||||||
source.owns_display_status.return_value = False
|
source.owns_display_status.return_value = False
|
||||||
|
source.last_fault.return_value = None
|
||||||
candidate.CS.stock_lfa_status = source
|
candidate.CS.stock_lfa_status = source
|
||||||
states = ((False, False, 10), (True, True, 11), (False, True, 11), (True, False, 12),
|
states = ((False, False, 10), (True, True, 11), (False, True, 11), (True, False, 12),
|
||||||
(True, True, None), (False, False, 13), (True, True, 14))
|
(True, True, None), (False, False, 13), (True, True, 14))
|
||||||
expected_counters = (None, 11, None, 12, None, None, 14)
|
for expected, (enabled, lateral, camera_counter) in enumerate(states):
|
||||||
for (enabled, lateral, camera_counter), expected in zip(states, expected_counters, strict=True):
|
|
||||||
if camera_counter is None:
|
if camera_counter is None:
|
||||||
source.current.return_value = None
|
source.current.return_value = None
|
||||||
else:
|
else:
|
||||||
@@ -225,4 +226,120 @@ def test_idle_handoff_omits_only_kona_steering_packet():
|
|||||||
_, after = candidate.apply(ctrl, 1_000_000_000)
|
_, after = candidate.apply(ctrl, 1_000_000_000)
|
||||||
assert [frame for frame in after if frame[0] != 0x12A] == [frame for frame in before if frame[0] != 0x12A]
|
assert [frame for frame in after if frame[0] != 0x12A] == [frame for frame in before if frame[0] != 0x12A]
|
||||||
assert any(frame[0] == 0x12A for frame in before)
|
assert any(frame[0] == 0x12A for frame in before)
|
||||||
assert [data[2] for addr, data, _ in after if addr == 0x12A] == ([] if expected is None else [expected])
|
assert [data[2] for addr, data, _ in after if addr == 0x12A] == [expected]
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('panda_type,faults,expected', [('cuatro', [], 0x1C0C), ('redPanda', [], 0x0C0C), ('cuatro', ['fault'], 0x0C0C)])
|
||||||
|
def test_kona_factory_handoff_is_limited_to_healthy_internal_c4(panda_type, faults, expected):
|
||||||
|
cp = kona_params(CARS[0])
|
||||||
|
cp.alternativeExperience = 32
|
||||||
|
cp.safetyConfigs[0].safetyParam = 0x0C0C
|
||||||
|
panda = SimpleNamespace(pandaType=panda_type, faults=faults, ignitionLine=True, ignitionCan=False, controlsAllowed=False)
|
||||||
|
configure_kona_factory_handoff(cp, [panda])
|
||||||
|
assert cp.safetyConfigs[0].safetyParam == expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('handoff,enabled,set_speed,hud_mode', (
|
||||||
|
(True, False, 255., 0), (True, False, 40., 1), (True, True, 40., 2), (False, False, 40., 1),
|
||||||
|
))
|
||||||
|
def test_kona_handoff_cruise_main_display_follows_star_long_engagement(handoff, enabled, set_speed, 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=set_speed).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(hud_mode != 0)
|
||||||
|
assert parser.vl['SCC_CONTROL']['ACCMode'] == int(enabled)
|
||||||
|
display = parser.vl['CCNC_0x161']
|
||||||
|
assert display['SETSPEED_HUD'] == hud_mode
|
||||||
|
assert display['LFA_ICON'] == (0 if handoff else 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
|
||||||
|
elif handoff and not enabled:
|
||||||
|
assert display['SETSPEED_SPEED'] == round(set_speed * (1. if ci.CS.is_metric else 0.621371))
|
||||||
|
assert display['DISTANCE_SPACING'] == 3
|
||||||
|
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, 1.2),
|
||||||
|
(1.75, -2.01, -2.006, False, False, 0x1C0C, 1.2),
|
||||||
|
(1.75, -2.01, -1.80, False, False, 0x1C0C, 5.0),
|
||||||
|
(1.75, -2.10, -2.10, 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)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('eps,age_ms,expected', [(0, 10, 0), (1, 10, 2), (1, 51, 0), (2, 10, 0)])
|
||||||
|
def test_kona_handoff_steering_icon_needs_current_eps_feedback(eps, age_ms, expected, monkeypatch):
|
||||||
|
import time
|
||||||
|
|
||||||
|
from opendbc.can import CANParser
|
||||||
|
from opendbc.car.hyundai import carcontroller
|
||||||
|
|
||||||
|
cp = kona_params(CARS[0])
|
||||||
|
cp.safetyConfigs[0].safetyParam = 0x1C0C
|
||||||
|
cp.alternativeExperience = 32
|
||||||
|
ci = CarInterface(cp)
|
||||||
|
ci.CS.out = structs.CarState(canValid=True, cruiseState={'available': True}).as_reader()
|
||||||
|
now = 2_000_000_000
|
||||||
|
monkeypatch.setattr(time, 'CLOCK_BOOTTIME', time.CLOCK_MONOTONIC, raising=False)
|
||||||
|
monkeypatch.setattr(time, 'clock_gettime_ns', lambda _: now)
|
||||||
|
monkeypatch.setattr(carcontroller, 'clock_boot_ns', lambda: now)
|
||||||
|
for tick in range(5):
|
||||||
|
ci.apply(structs.CarControl().as_reader(), now-(5-tick)*10_000_000)
|
||||||
|
ci.CS.ccnc_161_ts_ns = ci.CS.ccnc_162_ts_ns = now
|
||||||
|
ci.CS.ccnc_161 = {}
|
||||||
|
ci.CS.ccnc_162 = {'FAULT_LSS': 2}
|
||||||
|
mdps = ci.CC.packer.make_can_msg('MDPS', 0, {'MDPS_LkaToiActvSta': eps})
|
||||||
|
ci.CS.stock_lfa_status.update([(now - age_ms * 1_000_000, [mdps])])
|
||||||
|
_, packets = ci.apply(structs.CarControl(latActive=True).as_reader(), now)
|
||||||
|
parser = CANParser('hyundai_canfd_generated', [('CCNC_0x161', 0), ('CCNC_0x162', 0)], 0)
|
||||||
|
assert {0x161, 0x162} <= parser.update((now, packets))
|
||||||
|
assert parser.vl['CCNC_0x161']['LFA_ICON'] == expected
|
||||||
|
assert parser.vl['CCNC_0x162']['FAULT_LSS'] == 2
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -12,7 +12,7 @@ from opendbc.car.hyundai.ecu_startup import Outcome
|
|||||||
from opendbc.car.hyundai.interface import CarInterface
|
from opendbc.car.hyundai.interface import CarInterface
|
||||||
from opendbc.car.hyundai.ioniq6_handoff import TimestampedCanPacket
|
from opendbc.car.hyundai.ioniq6_handoff import TimestampedCanPacket
|
||||||
from opendbc.car.hyundai.ordinary_classic_startup import CARS, OrdinaryClassicStartup
|
from opendbc.car.hyundai.ordinary_classic_startup import CARS, OrdinaryClassicStartup
|
||||||
from opendbc.car.hyundai.values import HyundaiFlags
|
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
||||||
from opendbc.safety.tests.test_hyundai import checksum
|
from opendbc.safety.tests.test_hyundai import checksum
|
||||||
from opendbc.safety.tests.libsafety import libsafety_py
|
from opendbc.safety.tests.libsafety import libsafety_py
|
||||||
from openpilot.cereal import messaging
|
from openpilot.cereal import messaging
|
||||||
@@ -115,6 +115,11 @@ def test_actual_factory_rejection_restores_and_warms_exact_stock_before_publicat
|
|||||||
expected.carFw = []
|
expected.carFw = []
|
||||||
expected.fingerprintSource = desired.fingerprintSource
|
expected.fingerprintSource = desired.fingerprintSource
|
||||||
expected.fuzzyFingerprint = False
|
expected.fuzzyFingerprint = False
|
||||||
|
if identity == CAR.HYUNDAI_I30_2026:
|
||||||
|
assert desired.dashcamOnly and expected.dashcamOnly
|
||||||
|
assert not desired.openpilotLongitudinalControl and not expected.openpilotLongitudinalControl
|
||||||
|
assert desired.safetyConfigs[0].safetyModel == expected.safetyConfigs[0].safetyModel == structs.CarParams.SafetyModel.noOutput
|
||||||
|
return
|
||||||
assert desired.openpilotLongitudinalControl and not expected.openpilotLongitudinalControl
|
assert desired.openpilotLongitudinalControl and not expected.openpilotLongitudinalControl
|
||||||
identified = (identity, fingerprint, '0' * 17, [], desired.fingerprintSource, True)
|
identified = (identity, fingerprint, '0' * 17, [], desired.fingerprintSource, True)
|
||||||
native.set_alternative_experience(0)
|
native.set_alternative_experience(0)
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ def card_publication_sequence(context):
|
|||||||
calls=[statement.value.func.attr for statement in statements if isinstance(statement,ast.Expr)]
|
calls=[statement.value.func.attr for statement in statements if isinstance(statement,ast.Expr)]
|
||||||
assert calls==['configure','finalize_aol_configuration','seal_publication']
|
assert calls==['configure','finalize_aol_configuration','seal_publication']
|
||||||
exec(compile(ast.Module(body=statements,type_ignores=[]),'actual-card-publication-order','exec'),
|
exec(compile(ast.Module(body=statements,type_ignores=[]),'actual-card-publication-order','exec'),
|
||||||
{'self':context,'aol_policy':policy_for(context.CP), 'hyundai_aol_safety_config':hyundai_aol_safety_config})
|
{'self':context,'aol_policy':policy_for(context.CP), 'HYUNDAI_CAR':CAR,
|
||||||
|
'hyundai_aol_safety_config':hyundai_aol_safety_config})
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(params=[(CAR.KIA_EV6,EV6Startup),(CAR.GENESIS_GV70_ELECTRIFIED_1ST_GEN,GV70Startup)])
|
@pytest.fixture(params=[(CAR.KIA_EV6,EV6Startup),(CAR.GENESIS_GV70_ELECTRIFIED_1ST_GEN,GV70Startup)])
|
||||||
|
|||||||
@@ -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,9 +19,11 @@ 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 CI recording.
|
||||||
unrecorded_route_gaps = {
|
unrecorded_route_gaps = {
|
||||||
|
HYUNDAI.HYUNDAI_I30_2026: "hyundai/tests/test_hyundai.py",
|
||||||
SUBARU.SUBARU_CROSSTREK_2018: "subaru/tests/test_supported_firmware.py",
|
SUBARU.SUBARU_CROSSTREK_2018: "subaru/tests/test_supported_firmware.py",
|
||||||
GM.CHEVROLET_VOLT_CC: "gm/tests/test_volt_cc_gas.py",
|
GM.CHEVROLET_VOLT_CC: "gm/tests/test_volt_cc_gas.py",
|
||||||
GM.CHEVROLET_MALIBU_HYBRID_CC: "gm/tests/test_ordinary_cc.py",
|
GM.CHEVROLET_MALIBU_HYBRID_CC: "gm/tests/test_ordinary_cc.py",
|
||||||
@@ -99,6 +101,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 +488,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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from pathlib import Path
|
|||||||
from opendbc.car.values import PLATFORMS
|
from opendbc.car.values import PLATFORMS
|
||||||
from opendbc.car.tests.routes import non_tested_cars, routes, unrecorded_route_gaps
|
from opendbc.car.tests.routes import non_tested_cars, routes, unrecorded_route_gaps
|
||||||
from opendbc.car.gm.values import CAR as GM
|
from opendbc.car.gm.values import CAR as GM
|
||||||
|
from opendbc.car.hyundai.values import CAR as HYUNDAI
|
||||||
from opendbc.car.subaru.values import CAR as SUBARU
|
from opendbc.car.subaru.values import CAR as SUBARU
|
||||||
from opendbc.car.tesla.values import CAR as TESLA
|
from opendbc.car.tesla.values import CAR as TESLA
|
||||||
from opendbc.car.toyota.values import CAR as TOYOTA
|
from opendbc.car.toyota.values import CAR as TOYOTA
|
||||||
@@ -20,6 +21,7 @@ class TestRoutes(unittest.TestCase):
|
|||||||
|
|
||||||
def test_explicit_unrecorded_configuration_gaps(self):
|
def test_explicit_unrecorded_configuration_gaps(self):
|
||||||
self.assertEqual(set(unrecorded_route_gaps), {
|
self.assertEqual(set(unrecorded_route_gaps), {
|
||||||
|
HYUNDAI.HYUNDAI_I30_2026,
|
||||||
GM.CHEVROLET_VOLT_CC, GM.CHEVROLET_MALIBU_HYBRID_CC, TOYOTA.TOYOTA_PRIUS_RETROFIT, TESLA.TESLA_MODEL_S_HW1,
|
GM.CHEVROLET_VOLT_CC, GM.CHEVROLET_MALIBU_HYBRID_CC, TOYOTA.TOYOTA_PRIUS_RETROFIT, TESLA.TESLA_MODEL_S_HW1,
|
||||||
SUBARU.SUBARU_CROSSTREK_2018, VOLVO.VOLVO_XC40_RECHARGE, VOLVO.VOLVO_S60_RECHARGE, VOLVO.POLESTAR_2, VOLVO.VOLVO_V60,
|
SUBARU.SUBARU_CROSSTREK_2018, VOLVO.VOLVO_XC40_RECHARGE, VOLVO.VOLVO_S60_RECHARGE, VOLVO.POLESTAR_2, VOLVO.VOLVO_V60,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -30,9 +30,19 @@ AUTO_RESUME_CARS = frozenset((CAR.TOYOTA_HIGHLANDER, CAR.TOYOTA_PRIUS_V, CAR.TOY
|
|||||||
WORDS = frozenset(word | stock for word in PROFILES.values() for stock in (0, 0x200))
|
WORDS = frozenset(word | stock for word in PROFILES.values() for stock in (0, 0x200))
|
||||||
|
|
||||||
|
|
||||||
|
def corolla_startup_mirror(candidate, fingerprint):
|
||||||
|
if candidate != CAR.TOYOTA_COROLLA:
|
||||||
|
return False
|
||||||
|
pt = fingerprint.get(0, {})
|
||||||
|
return pt == fingerprint.get(2, {}) and all(pt.get(address) == length for address, length in
|
||||||
|
((0xAA, 8), (0x262, 5), (0x1D3, 8), (0x343, 8), (0x4CB, 8)))
|
||||||
|
|
||||||
|
|
||||||
def hardware_supported(candidate, fingerprint, car_fw):
|
def hardware_supported(candidate, fingerprint, car_fw):
|
||||||
if candidate not in PROFILES or any(address in frames for frames in fingerprint.values() for address in (0x201, 0x2FF, 0x2AA)):
|
if candidate not in PROFILES or any(address in frames for frames in fingerprint.values() for address in (0x201, 0x2FF, 0x2AA)):
|
||||||
return False
|
return False
|
||||||
|
if corolla_startup_mirror(candidate, fingerprint):
|
||||||
|
return False
|
||||||
camera = fingerprint.get(2, {})
|
camera = fingerprint.get(2, {})
|
||||||
if not any(camera.get(address) == 8 for address in (0x343, 0x4CB)) or any(camera.get(address, 8) != 8 for address in (0x343, 0x4CB)):
|
if not any(camera.get(address) == 8 for address in (0x343, 0x4CB)) or any(camera.get(address, 8) != 8 for address in (0x343, 0x4CB)):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ def hardware_supported(candidate, fingerprint):
|
|||||||
return False
|
return False
|
||||||
if 0x2FF in frames and not (candidate == CAR.TOYOTA_CAMRY and _cluster_radar_bus(candidate, bus, frames)):
|
if 0x2FF in frames and not (candidate == CAR.TOYOTA_CAMRY and _cluster_radar_bus(candidate, bus, frames)):
|
||||||
return False
|
return False
|
||||||
|
from opendbc.car.toyota.dsu_bypass import corolla_startup_mirror
|
||||||
|
if corolla_startup_mirror(candidate, fingerprint):
|
||||||
|
return True
|
||||||
camera = fingerprint.get(2, {})
|
camera = fingerprint.get(2, {})
|
||||||
if 0x4CB in camera:
|
if 0x4CB in camera:
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -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):
|
||||||
|
|||||||
@@ -89,7 +89,9 @@ class TestToyotaAutoHold(unittest.TestCase):
|
|||||||
self.assertTrue(owner.brake_hold_active)
|
self.assertTrue(owner.brake_hold_active)
|
||||||
|
|
||||||
def test_detected_early_hybrid_uses_manual_aeb_hold(self):
|
def test_detected_early_hybrid_uses_manual_aeb_hold(self):
|
||||||
for car, hybrid, aeb in ((CAR.TOYOTA_RAV4_TSS2, True, True),
|
for car, hybrid, aeb in ((CAR.TOYOTA_COROLLA_TSS2, True, True),
|
||||||
|
(CAR.TOYOTA_COROLLA_TSS2, False, False),
|
||||||
|
(CAR.TOYOTA_RAV4_TSS2, True, True),
|
||||||
(CAR.TOYOTA_RAV4_TSS2, False, False),
|
(CAR.TOYOTA_RAV4_TSS2, False, False),
|
||||||
(CAR.TOYOTA_RAV4_TSS2_2022, True, False),
|
(CAR.TOYOTA_RAV4_TSS2_2022, True, False),
|
||||||
(CAR.TOYOTA_CAMRY_TSS2, False, True)):
|
(CAR.TOYOTA_CAMRY_TSS2, False, True)):
|
||||||
@@ -136,6 +138,10 @@ class TestToyotaAutoHold(unittest.TestCase):
|
|||||||
self.assertTrue(owner.brake_hold_active)
|
self.assertTrue(owner.brake_hold_active)
|
||||||
frame = next(frame for frame in frames if frame[0] == 0x344)
|
frame = next(frame for frame in frames if frame[0] == 0x344)
|
||||||
self.assertEqual(decode(cp, frame, 'PRE_COLLISION_2')['DSS1GDRV'], -1.0)
|
self.assertEqual(decode(cp, frame, 'PRE_COLLISION_2')['DSS1GDRV'], -1.0)
|
||||||
|
state.out.brakePressed = False
|
||||||
|
released = [frame for _ in range(2) for frame in step_hold(owner, command, state) if frame[0] == 0x344]
|
||||||
|
self.assertTrue(owner.brake_hold_active)
|
||||||
|
self.assertEqual(decode(cp, released[0], 'PRE_COLLISION_2')['DSS1GDRV'], -1.0)
|
||||||
state.out.gasPressed = True
|
state.out.gasPressed = True
|
||||||
step_hold(owner, command, state)
|
step_hold(owner, command, state)
|
||||||
self.assertFalse(owner.brake_hold_active)
|
self.assertFalse(owner.brake_hold_active)
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from opendbc.car import gen_empty_fingerprint, structs
|
||||||
|
from opendbc.car.toyota.fingerprints import FW_VERSIONS
|
||||||
|
from opendbc.car.toyota.interface import CarInterface
|
||||||
|
from opendbc.car.toyota.values import CAR
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('mirrored,expected', ((True, 0x5358), (False, 0x8958)))
|
||||||
|
def test_corolla_camera_relay_mirror_is_not_a_dsu_bypass(mirrored, expected):
|
||||||
|
car = CAR.TOYOTA_COROLLA
|
||||||
|
fp = gen_empty_fingerprint()
|
||||||
|
fp[0].update({0xAA: 8, 0x262: 5, 0x1D3: 8, 0x343: 8, 0x4CB: 8, 0x283: 7})
|
||||||
|
fp[2].update(fp[0] if mirrored else {0x343: 8, 0x4CB: 8})
|
||||||
|
fw = [structs.CarParams.CarFw(ecu=ecu, address=addr, subAddress=sub or 0, fwVersion=versions[0], brand='toyota', bus=0)
|
||||||
|
for (ecu, addr, sub), versions in FW_VERSIONS[car].items()]
|
||||||
|
|
||||||
|
cp = CarInterface.get_params(car, fp, fw, False, True, False)
|
||||||
|
assert cp.safetyConfigs[0].safetyParam == expected
|
||||||
|
assert cp.pcmCruise
|
||||||
|
assert cp.openpilotLongitudinalControl is (not mirrored)
|
||||||
@@ -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
|
||||||
@@ -640,7 +639,8 @@ TOYOTA_AUTO_HOLD_AEB_CARS = {CAR.TOYOTA_CAMRY_TSS2}
|
|||||||
|
|
||||||
def uses_toyota_auto_hold_aeb(CP) -> bool:
|
def uses_toyota_auto_hold_aeb(CP) -> bool:
|
||||||
return (CP.carFingerprint in TOYOTA_AUTO_HOLD_AEB_CARS or
|
return (CP.carFingerprint in TOYOTA_AUTO_HOLD_AEB_CARS or
|
||||||
(CP.carFingerprint == CAR.TOYOTA_RAV4_TSS2 and bool(CP.flags & ToyotaFlags.HYBRID)))
|
(CP.carFingerprint in (CAR.TOYOTA_COROLLA_TSS2, CAR.TOYOTA_RAV4_TSS2) and
|
||||||
|
bool(CP.flags & ToyotaFlags.HYBRID)))
|
||||||
|
|
||||||
|
|
||||||
def stopping_decel_rate(CP):
|
def stopping_decel_rate(CP):
|
||||||
|
|||||||
@@ -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}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ BO_ 228 STEERING_CONTROL: 5 EON
|
|||||||
SG_ STEER_TORQUE : 7|16@0- (1,0) [-4096|4096] "" EPS
|
SG_ STEER_TORQUE : 7|16@0- (1,0) [-4096|4096] "" EPS
|
||||||
SG_ DRIVER_OVERRIDE : 17|1@0+ (1,0) [0|1] "" XXX
|
SG_ DRIVER_OVERRIDE : 17|1@0+ (1,0) [0|1] "" XXX
|
||||||
SG_ STEER_TORQUE_REQUEST : 23|1@0+ (1,0) [0|1] "" EPS
|
SG_ STEER_TORQUE_REQUEST : 23|1@0+ (1,0) [0|1] "" EPS
|
||||||
|
SG_ STEER_CONTROL_ARM : 19|2@0+ (1,0) [0|3] "" EPS
|
||||||
SG_ CONTROL_STATE : 26|3@0+ (1,0) [0|7] "" XXX
|
SG_ CONTROL_STATE : 26|3@0+ (1,0) [0|7] "" XXX
|
||||||
SG_ CHECKSUM : 35|4@0+ (1,0) [0|15] "" EPS
|
SG_ CHECKSUM : 35|4@0+ (1,0) [0|15] "" EPS
|
||||||
SG_ COUNTER : 37|2@0+ (1,0) [0|3] "" EPS
|
SG_ COUNTER : 37|2@0+ (1,0) [0|3] "" EPS
|
||||||
@@ -206,6 +207,7 @@ BO_ 13275 LKAS_HUD_B: 8 ADAS
|
|||||||
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" BDY
|
SG_ COUNTER : 61|2@0+ (1,0) [0|3] "" BDY
|
||||||
|
|
||||||
CM_ SG_ 228 DRIVER_OVERRIDE "Appears to acknowledge STEER_STATUS.NO_TORQUE_ALERT_1";
|
CM_ SG_ 228 DRIVER_OVERRIDE "Appears to acknowledge STEER_STATUS.NO_TORQUE_ALERT_1";
|
||||||
|
CM_ SG_ 228 STEER_CONTROL_ARM "Stock camera sends 0 or 1. The Accord angle-loop EPS firmware (39990-TVA,A16x) runs its lane only while this reads 2";
|
||||||
CM_ SG_ 576 LINE_DISTANCE_VISIBLE "Length of line visible, undecoded";
|
CM_ SG_ 576 LINE_DISTANCE_VISIBLE "Length of line visible, undecoded";
|
||||||
CM_ SG_ 577 LINE_FAR_EDGE_POSITION "Appears to be a measure of line thickness, indicates location of the portion of the line furthest from the car, undecoded";
|
CM_ SG_ 577 LINE_FAR_EDGE_POSITION "Appears to be a measure of line thickness, indicates location of the portion of the line furthest from the car, undecoded";
|
||||||
CM_ SG_ 577 LINE_PARAMETER "Unclear if this is low quality line curvature rate or if this is something else, but it is correlated with line curvature, undecoded";
|
CM_ SG_ 577 LINE_PARAMETER "Unclear if this is low quality line curvature rate or if this is something else, but it is correlated with line curvature, undecoded";
|
||||||
|
|||||||
@@ -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))
|
||||||
@@ -232,6 +233,7 @@ typedef bool (*tx_hook)(const CANPacket_t *msg); // returns true if the message
|
|||||||
typedef bool (*fwd_hook)(int bus_num, int addr); // returns true if the message should be blocked from forwarding
|
typedef bool (*fwd_hook)(int bus_num, int addr); // returns true if the message should be blocked from forwarding
|
||||||
|
|
||||||
typedef bool (*fwd_packet_hook)(const CANPacket_t *msg);
|
typedef bool (*fwd_packet_hook)(const CANPacket_t *msg);
|
||||||
|
typedef void (*fwd_output_hook)(const CANPacket_t *msg, CANPacket_t *output, bool *replaced);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
safety_hook_init init;
|
safety_hook_init init;
|
||||||
@@ -240,6 +242,7 @@ typedef struct {
|
|||||||
tx_hook tx;
|
tx_hook tx;
|
||||||
fwd_hook fwd;
|
fwd_hook fwd;
|
||||||
fwd_packet_hook fwd_packet;
|
fwd_packet_hook fwd_packet;
|
||||||
|
fwd_output_hook fwd_output;
|
||||||
get_checksum_t get_checksum;
|
get_checksum_t get_checksum;
|
||||||
compute_checksum_t compute_checksum;
|
compute_checksum_t compute_checksum;
|
||||||
get_counter_t get_counter;
|
get_counter_t get_counter;
|
||||||
@@ -371,6 +374,8 @@ extern safety_config current_safety_config;
|
|||||||
|
|
||||||
int safety_fwd_hook(int bus_num, int addr);
|
int safety_fwd_hook(int bus_num, int addr);
|
||||||
int safety_fwd_packet_hook(const CANPacket_t *msg);
|
int safety_fwd_packet_hook(const CANPacket_t *msg);
|
||||||
|
bool safety_uses_forward_transform(const CANPacket_t *msg);
|
||||||
|
int safety_fwd_output_hook(const CANPacket_t *msg, CANPacket_t *output, bool *replaced);
|
||||||
int set_safety_hooks(uint16_t mode, uint16_t param);
|
int set_safety_hooks(uint16_t mode, uint16_t param);
|
||||||
|
|
||||||
extern const safety_hooks body_hooks;
|
extern const safety_hooks body_hooks;
|
||||||
@@ -402,6 +407,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;
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ static bool honda_fwd_brake = false;
|
|||||||
static bool honda_bosch_long = false;
|
static bool honda_bosch_long = false;
|
||||||
static bool honda_bosch_radarless = false;
|
static bool honda_bosch_radarless = false;
|
||||||
static bool honda_bosch_canfd = false;
|
static bool honda_bosch_canfd = false;
|
||||||
|
static bool honda_accord_angle = false;
|
||||||
|
#define HONDA_PARAM_ACCORD_ANGLE 4096U
|
||||||
static bool honda_mvl_stock = false;
|
static bool honda_mvl_stock = false;
|
||||||
static uint8_t honda_mvl_buttons_fresh = 0U;
|
static uint8_t honda_mvl_buttons_fresh = 0U;
|
||||||
static bool honda_rdx_high_gas = false;
|
static bool honda_rdx_high_gas = false;
|
||||||
@@ -101,6 +103,23 @@ static uint8_t honda_get_counter(const CANPacket_t *msg) {
|
|||||||
return (msg->data[counter_byte] >> 4U) & 0x3U;
|
return (msg->data[counter_byte] >> 4U) & 0x3U;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The Accord angle-loop EPS firmware (39990-TVA,A16x) exists only on classic Bosch. On it a 0xE4 frame with
|
||||||
|
// STEER_CONTROL_ARM == 2 carries an angle setpoint in bytes 0-1 (-0.1 deg); the EPS runs its angle lane on no other
|
||||||
|
// frame, and the stock camera only ever sends 0 or 1 there.
|
||||||
|
static bool honda_angle_setpoint_capable(void) {
|
||||||
|
return (honda_hw == HONDA_BOSCH) && honda_accord_angle;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wheel angle for the angle setpoint check: where a request may start from, and what a request-off frame may hold.
|
||||||
|
// STEERING_SENSORS is not a required RX check on Honda, so it arrives here, and its checksum is verified here.
|
||||||
|
static void honda_optional_rx_hook(const CANPacket_t *msg) {
|
||||||
|
if (honda_angle_setpoint_capable() && msg_matches(msg, 0x14AU, honda_get_pt_bus(), 8U) &&
|
||||||
|
(honda_get_checksum(msg) == honda_compute_checksum(msg))) {
|
||||||
|
// STEER_ANGLE, -0.1 deg: the same units and sign as the 0xE4 setpoint
|
||||||
|
update_sample(&angle_meas, to_signed((msg->data[0] << 8) | msg->data[1], 16));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void honda_rx_hook(const CANPacket_t *msg) {
|
static void honda_rx_hook(const CANPacket_t *msg) {
|
||||||
const bool pcm_cruise = ((honda_hw == HONDA_BOSCH) && !honda_bosch_long) || ((honda_hw == HONDA_NIDEC) && !honda_interceptor);
|
const bool pcm_cruise = ((honda_hw == HONDA_BOSCH) && !honda_bosch_long) || ((honda_hw == HONDA_NIDEC) && !honda_interceptor);
|
||||||
unsigned int pt_bus = honda_get_pt_bus();
|
unsigned int pt_bus = honda_get_pt_bus();
|
||||||
@@ -111,6 +130,14 @@ static void honda_rx_hook(const CANPacket_t *msg) {
|
|||||||
vehicle_moving = msg->data[0] | msg->data[1];
|
vehicle_moving = msg->data[0] | msg->data[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// speed for the angle setpoint check (Accord angle-loop EPS)
|
||||||
|
if (honda_angle_setpoint_capable()) {
|
||||||
|
if (msg_matches(msg, 0x158U, pt_bus)) {
|
||||||
|
// ENGINE_DATA XMISSION_SPEED, 0.01 kph
|
||||||
|
UPDATE_VEHICLE_SPEED(((msg->data[0] << 8) | msg->data[1]) * 0.01 * KPH_TO_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check ACC main state
|
// check ACC main state
|
||||||
// 0x326 for all Bosch and some Nidec, 0x1A6 for some Nidec
|
// 0x326 for all Bosch and some Nidec, 0x1A6 for some Nidec
|
||||||
if ((!aol_honda_bosch_long && ((msg->addr == 0x326U) || (msg->addr == 0x1A6U))) ||
|
if ((!aol_honda_bosch_long && ((msg->addr == 0x326U) || (msg->addr == 0x1A6U))) ||
|
||||||
@@ -317,6 +344,40 @@ static bool honda_tx_hook(const CANPacket_t *msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// STEER: angle setpoint frames (STEER_CONTROL_ARM == 2, Accord angle-loop EPS) must stay inside the lateral
|
||||||
|
// acceleration and jerk limits, checked with the vehicle model on the value as sent
|
||||||
|
if ((msg->addr == 0xE4U) && (((msg->data[2] >> 2) & 0x3U) == 2U)) {
|
||||||
|
const AngleSteeringLimits HONDA_ACCORD_ANGLE_LIMITS = {
|
||||||
|
.max_angle = 4000, // 400 deg, the EPS clamps its setpoint just above this
|
||||||
|
.angle_deg_to_can = 10,
|
||||||
|
.frequency = 100U,
|
||||||
|
};
|
||||||
|
|
||||||
|
// NOTE: HONDA_ACCORD, must match openpilot's VehicleModel
|
||||||
|
const AngleSteeringParams HONDA_ACCORD_ANGLE_PARAMS = {
|
||||||
|
.slip_factor = -0.0006999872680281922, // calc_slip_factor(VM)
|
||||||
|
.steer_ratio = 16.33,
|
||||||
|
.wheelbase = 2.83,
|
||||||
|
};
|
||||||
|
|
||||||
|
const int desired_angle = to_signed((msg->data[0] << 8) | msg->data[1], 16);
|
||||||
|
const bool steer_req = GET_BIT(msg, 23U); // STEER_TORQUE_REQUEST
|
||||||
|
|
||||||
|
bool violation = !honda_angle_setpoint_capable();
|
||||||
|
if (!violation) {
|
||||||
|
if (!steer_req && (desired_angle == 0)) {
|
||||||
|
// request off with a zero field: nothing is commanded, the next request starts from the wheel
|
||||||
|
desired_angle_last = SAFETY_CLAMP(angle_meas.values[0], -HONDA_ACCORD_ANGLE_LIMITS.max_angle, HONDA_ACCORD_ANGLE_LIMITS.max_angle);
|
||||||
|
} else {
|
||||||
|
violation |= steer_angle_cmd_checks_vm(desired_angle, steer_req, HONDA_ACCORD_ANGLE_LIMITS, HONDA_ACCORD_ANGLE_PARAMS);
|
||||||
|
violation |= safety_max_limit_check(desired_angle, HONDA_ACCORD_ANGLE_LIMITS.max_angle, -HONDA_ACCORD_ANGLE_LIMITS.max_angle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (violation) {
|
||||||
|
tx = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Bosch supplemental control check
|
// Bosch supplemental control check
|
||||||
if (msg->addr == 0xE5U) {
|
if (msg->addr == 0xE5U) {
|
||||||
if ((GET_BYTES_64_LE(msg, 0, 8) & 0x00FFFFFFFFFFFFFFULL) != 0x0000000010800004ULL) {
|
if ((GET_BYTES_64_LE(msg, 0, 8) & 0x00FFFFFFFFFFFFFFULL) != 0x0000000010800004ULL) {
|
||||||
@@ -381,6 +442,7 @@ static safety_config honda_nidec_init(uint16_t param) {
|
|||||||
const uint16_t HONDA_PARAM_NIDEC_ALT = 4;
|
const uint16_t HONDA_PARAM_NIDEC_ALT = 4;
|
||||||
|
|
||||||
honda_hw = HONDA_NIDEC;
|
honda_hw = HONDA_NIDEC;
|
||||||
|
honda_accord_angle = false;
|
||||||
honda_brake = 0;
|
honda_brake = 0;
|
||||||
honda_brake_switch_prev = false;
|
honda_brake_switch_prev = false;
|
||||||
honda_fwd_brake = false;
|
honda_fwd_brake = false;
|
||||||
@@ -426,7 +488,14 @@ static safety_config honda_nidec_init(uint16_t param) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static safety_config honda_bosch_init(uint16_t param) {
|
static safety_config honda_bosch_init(uint16_t requested_param) {
|
||||||
|
// Apply the Accord flag only to the classic Bosch base configurations the host can select.
|
||||||
|
const uint16_t param = (uint16_t)(requested_param & ~HONDA_PARAM_ACCORD_ANGLE);
|
||||||
|
bool accord_base = (param == 0U) || (param == 1U);
|
||||||
|
#ifdef ALLOW_DEBUG
|
||||||
|
accord_base = accord_base || (param == 2U) || (param == 3U) || (param == 2082U) || (param == 2083U);
|
||||||
|
#endif
|
||||||
|
honda_accord_angle = GET_FLAG(requested_param, HONDA_PARAM_ACCORD_ANGLE) && accord_base;
|
||||||
honda_mvl_stock = ((param == 80U) || (param == 81U)) && ((alternative_experience == 0) || (alternative_experience == 32));
|
honda_mvl_stock = ((param == 80U) || (param == 81U)) && ((alternative_experience == 0) || (alternative_experience == 32));
|
||||||
honda_mvl_buttons_fresh = 0U;
|
honda_mvl_buttons_fresh = 0U;
|
||||||
honda_interceptor_reset(false);
|
honda_interceptor_reset(false);
|
||||||
@@ -614,6 +683,7 @@ const safety_hooks honda_bosch_hooks = {
|
|||||||
.fwd = honda_mvl_stock_fwd_hook,
|
.fwd = honda_mvl_stock_fwd_hook,
|
||||||
.init = honda_bosch_init,
|
.init = honda_bosch_init,
|
||||||
.rx = honda_rx_hook,
|
.rx = honda_rx_hook,
|
||||||
|
.optional_rx = honda_optional_rx_hook,
|
||||||
.tx = honda_tx_hook,
|
.tx = honda_tx_hook,
|
||||||
.get_counter = honda_get_counter,
|
.get_counter = honda_get_counter,
|
||||||
.get_checksum = honda_get_checksum,
|
.get_checksum = honda_get_checksum,
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,9 @@ static bool blended_aol_token = false;
|
|||||||
static bool blended_aol_claimed = false;
|
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_stock_continuation = 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};
|
||||||
static uint32_t blended_aol_source_ts[3] = {0U, 0U, 0U};
|
static uint32_t blended_aol_source_ts[3] = {0U, 0U, 0U};
|
||||||
@@ -44,6 +47,10 @@ static void blended_aol_clear(void) {
|
|||||||
blended_aol_claimed = false;
|
blended_aol_claimed = false;
|
||||||
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_stock_continuation = false;
|
||||||
|
blended_aol_idle_owned[0] = false;
|
||||||
|
blended_aol_idle_owned[1] = false;
|
||||||
blended_aol_token_ts = 0U;
|
blended_aol_token_ts = 0U;
|
||||||
blended_aol_token_source = 3U;
|
blended_aol_token_source = 3U;
|
||||||
aol_host_axis_mask = 0U;
|
aol_host_axis_mask = 0U;
|
||||||
@@ -71,6 +78,9 @@ static void blended_aol_reset(void) {
|
|||||||
|
|
||||||
static void blended_aol_host_request(uint8_t mask) {
|
static void blended_aol_host_request(uint8_t mask) {
|
||||||
blended_aol_request_seen |= mask != 0U;
|
blended_aol_request_seen |= mask != 0U;
|
||||||
|
if ((mask & 1U) == 0U) {
|
||||||
|
blended_aol_brake_continuation = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t blended_aol_request_mask(void) {
|
static uint8_t blended_aol_request_mask(void) {
|
||||||
@@ -101,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)) {
|
} 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 &&
|
||||||
@@ -145,6 +168,24 @@ 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();
|
||||||
|
const bool stock_hda2 = blended_aol_hda2 && !blended_aol_long;
|
||||||
|
if (stock_hda2 && msg_matches(msg, 0x421U, pt, 8U)) {
|
||||||
|
const bool cruise_main = GET_BIT(msg, 27U);
|
||||||
|
if (blended_aol_main && !cruise_main) {
|
||||||
|
blended_aol_clear();
|
||||||
|
}
|
||||||
|
blended_aol_main_seen = true;
|
||||||
|
blended_aol_main = cruise_main;
|
||||||
|
blended_aol_main_ts = now;
|
||||||
|
}
|
||||||
|
if (stock_hda2 && msg_matches(msg, 0x394U, pt, 8U)) {
|
||||||
|
const bool brake = ((msg->data[5] >> 5U) & 3U) == 2U;
|
||||||
|
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) &&
|
||||||
|
((blended_aol_request_mask() & 1U) != 0U) && aol_rx_healthy()) {
|
||||||
|
blended_aol_brake_continuation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (blended_aol_long && msg_matches(msg, 0x394U, pt, 8U)) {
|
if (blended_aol_long && msg_matches(msg, 0x394U, pt, 8U)) {
|
||||||
blended_aol_main_seen = true;
|
blended_aol_main_seen = true;
|
||||||
blended_aol_main = ((msg->data[5] >> 3U) & 3U) == 0U;
|
blended_aol_main = ((msg->data[5] >> 3U) & 3U) == 0U;
|
||||||
@@ -158,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) {
|
||||||
@@ -323,6 +362,19 @@ static void blended_aol_tx(const CANPacket_t *msg, bool accepted) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
accepted_current &= active;
|
accepted_current &= active;
|
||||||
|
if (blended_aol_hda2) {
|
||||||
|
const bool zero_torque = (((msg->data[6] & 0xFU) << 7U) | (msg->data[5] >> 1U)) == 1024U;
|
||||||
|
blended_aol_idle_owned[0] = accepted && !active && zero_torque && aol_rx_healthy() &&
|
||||||
|
!safety_rx_checks_invalid && !relay_malfunction;
|
||||||
|
if (!blended_aol_idle_owned[0]) {
|
||||||
|
blended_aol_idle_owned[1] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (blended_aol_hda2 && (msg->addr == 0x2A4U) && (msg->bus == 0U) && !retain_camera_ownership) {
|
||||||
|
blended_aol_idle_owned[1] = accepted && blended_aol_idle_owned[0] && aol_rx_healthy() &&
|
||||||
|
!safety_rx_checks_invalid && !relay_malfunction &&
|
||||||
|
(safety_get_ts_elapsed(microsecond_timer_get(), blended_aol_tx_ts[0]) <= AOL_HOST_REQUEST_TIMEOUT_US);
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0U; i < count; i++) {
|
for (unsigned int i = 0U; i < count; i++) {
|
||||||
const unsigned int bus = blended_aol_hda2 && (i >= 2U) ? 1U : 0U;
|
const unsigned int bus = blended_aol_hda2 && (i >= 2U) ? 1U : 0U;
|
||||||
@@ -339,6 +391,16 @@ static bool blended_aol_fwd(int bus, int addr) {
|
|||||||
bool blocked = blended_aol_long && !blended_aol_enabled && (bus == 2) &&
|
bool blocked = blended_aol_long && !blended_aol_enabled && (bus == 2) &&
|
||||||
((addr == (blended_aol_hda2 ? 0x50 : 0x340)) ||
|
((addr == (blended_aol_hda2 ? 0x50 : 0x340)) ||
|
||||||
(addr == (blended_aol_hda2 ? 0x2A4 : 0x364)) || (!blended_aol_hda2 && (addr == 0x485)));
|
(addr == (blended_aol_hda2 ? 0x2A4 : 0x364)) || (!blended_aol_hda2 && (addr == 0x485)));
|
||||||
|
if (blended_aol_enabled && blended_aol_hda2 && (bus == 2) &&
|
||||||
|
aol_rx_healthy() && !safety_rx_checks_invalid && !relay_malfunction) {
|
||||||
|
const uint32_t now = microsecond_timer_get();
|
||||||
|
const bool primary_current = blended_aol_idle_owned[0] &&
|
||||||
|
(safety_get_ts_elapsed(now, blended_aol_tx_ts[0]) <= AOL_HOST_REQUEST_TIMEOUT_US);
|
||||||
|
if (primary_current) {
|
||||||
|
blocked |= (addr == 0x50) || ((addr == 0x2A4) && blended_aol_idle_owned[1] &&
|
||||||
|
(safety_get_ts_elapsed(now, blended_aol_tx_ts[1]) <= AOL_HOST_REQUEST_TIMEOUT_US));
|
||||||
|
}
|
||||||
|
}
|
||||||
if (blended_aol_enabled && (bus == 2) && aol_rx_healthy() && (controls_allowed || (blended_aol_permission_mask() != 0U))) {
|
if (blended_aol_enabled && (bus == 2) && aol_rx_healthy() && (controls_allowed || (blended_aol_permission_mask() != 0U))) {
|
||||||
const uint32_t addresses[4] = {blended_aol_hda2 ? 0x50U : 0x340U, blended_aol_hda2 ? 0x2A4U : 0x364U, 0x485U, 0x340U};
|
const uint32_t addresses[4] = {blended_aol_hda2 ? 0x50U : 0x340U, blended_aol_hda2 ? 0x2A4U : 0x364U, 0x485U, 0x340U};
|
||||||
const unsigned int count = blended_aol_hda2 ? 2U : 3U;
|
const unsigned int count = blended_aol_hda2 ? 2U : 3U;
|
||||||
|
|||||||
@@ -527,7 +527,56 @@ static void hyundai_canfd_ioniq6_optional_rx_hook(const CANPacket_t *msg) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(ALLOW_DEBUG) && !defined(STM32F4)
|
||||||
|
static bool hyundai_kona_ccnc_feedback = false;
|
||||||
|
typedef struct {
|
||||||
|
bool seen;
|
||||||
|
uint8_t counter;
|
||||||
|
uint32_t ts;
|
||||||
|
} HyundaiKonaLfaState;
|
||||||
|
|
||||||
|
static HyundaiKonaLfaState hyundai_kona_camera;
|
||||||
|
static HyundaiKonaLfaState hyundai_kona_host;
|
||||||
|
|
||||||
|
static bool hyundai_kona_lfa_valid(const CANPacket_t *msg) {
|
||||||
|
return !msg->extended && (GET_LEN(msg) == 16U) &&
|
||||||
|
(hyundai_canfd_get_checksum(msg) == (hyundai_common_canfd_compute_checksum(msg) ^ 0x041DU));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hyundai_kona_camera_rx(const CANPacket_t *msg) {
|
||||||
|
if (hyundai_kona_ccnc_feedback && (msg->addr == 0x12AU) && (msg->bus == 2U) &&
|
||||||
|
msg->fd && hyundai_kona_lfa_valid(msg)) {
|
||||||
|
const uint32_t now = microsecond_timer_get();
|
||||||
|
const uint8_t delta = (uint8_t)(msg->data[2] - hyundai_kona_camera.counter);
|
||||||
|
if (!hyundai_kona_camera.seen || (safety_get_ts_elapsed(now, hyundai_kona_camera.ts) > 50000U) ||
|
||||||
|
((delta > 0U) && (delta <= 127U))) {
|
||||||
|
hyundai_kona_camera.seen = true;
|
||||||
|
hyundai_kona_camera.counter = msg->data[2];
|
||||||
|
hyundai_kona_camera.ts = now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hyundai_kona_mdps_output(const CANPacket_t *msg, CANPacket_t *output, bool *replaced) {
|
||||||
|
if (hyundai_kona_ccnc_feedback && (msg->addr == 0xEAU) && (msg->bus == 0U) &&
|
||||||
|
msg->fd && !msg->extended && (GET_LEN(msg) == 24U) &&
|
||||||
|
((msg->data[3] & 7U) == 0U) && ((msg->data[6] & 0xFCU) == 0U) &&
|
||||||
|
((msg->data[6] & 3U) <= 1U) && (hyundai_canfd_get_checksum(msg) == hyundai_common_canfd_compute_checksum(msg))) {
|
||||||
|
// The physical EPS frame is still used unchanged by the vehicle and RX safety.
|
||||||
|
*output = *msg;
|
||||||
|
output->data[6] = 0x04U;
|
||||||
|
const uint16_t checksum = hyundai_common_canfd_compute_checksum(output);
|
||||||
|
output->data[0] = (uint8_t)checksum;
|
||||||
|
output->data[1] = (uint8_t)(checksum >> 8U);
|
||||||
|
*replaced = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void hyundai_canfd_optional_rx_hook(const CANPacket_t *msg) {
|
static void hyundai_canfd_optional_rx_hook(const CANPacket_t *msg) {
|
||||||
|
#if defined(ALLOW_DEBUG) && !defined(STM32F4)
|
||||||
|
hyundai_kona_camera_rx(msg);
|
||||||
|
#endif
|
||||||
hyundai_daw_rx(msg);
|
hyundai_daw_rx(msg);
|
||||||
if (hyundai_canfd_ioniq6_long && (msg->bus == 1U)) {
|
if (hyundai_canfd_ioniq6_long && (msg->bus == 1U)) {
|
||||||
hyundai_canfd_ioniq6_optional_rx_hook(msg);
|
hyundai_canfd_ioniq6_optional_rx_hook(msg);
|
||||||
@@ -820,12 +869,15 @@ static safety_config hyundai_canfd_gv60_extend_tx(const safety_config original,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define HYUNDAI_CANFD_STEER_MAX_TORQUE 409
|
||||||
|
#define HYUNDAI_CANFD_STEER_MAX_RATE_UP 10
|
||||||
|
|
||||||
static bool hyundai_canfd_tx_hook_valid(const CANPacket_t *msg) {
|
static bool hyundai_canfd_tx_hook_valid(const CANPacket_t *msg) {
|
||||||
static uint8_t hyundai_canfd_ioniq6_lfa_mirror[4] = {0};
|
static uint8_t hyundai_canfd_ioniq6_lfa_mirror[4] = {0};
|
||||||
const TorqueSteeringLimits HYUNDAI_CANFD_STEERING_LIMITS = {
|
const TorqueSteeringLimits HYUNDAI_CANFD_STEERING_LIMITS = {
|
||||||
.max_torque = 409,
|
.max_torque = HYUNDAI_CANFD_STEER_MAX_TORQUE,
|
||||||
.max_rt_delta = 375,
|
.max_rt_delta = 375,
|
||||||
.max_rate_up = 10,
|
.max_rate_up = HYUNDAI_CANFD_STEER_MAX_RATE_UP,
|
||||||
.max_rate_down = 3,
|
.max_rate_down = 3,
|
||||||
.driver_torque_allowance = 250,
|
.driver_torque_allowance = 250,
|
||||||
.driver_torque_multiplier = 2,
|
.driver_torque_multiplier = 2,
|
||||||
@@ -1228,70 +1280,11 @@ static bool hyundai_canfd_tx_hook_valid(const CANPacket_t *msg) {
|
|||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ALLOW_DEBUG
|
|
||||||
static bool hyundai_kona_idle_handoff = false;
|
|
||||||
static bool hyundai_kona_camera_seen = false;
|
|
||||||
static bool hyundai_kona_output_seen = false;
|
|
||||||
static bool hyundai_kona_host_output = false;
|
|
||||||
static uint32_t hyundai_kona_camera_ts = 0U;
|
|
||||||
static uint32_t hyundai_kona_output_ts = 0U;
|
|
||||||
static uint8_t hyundai_kona_camera_counter = 0U;
|
|
||||||
static uint8_t hyundai_kona_output_counter = 0U;
|
|
||||||
|
|
||||||
static bool hyundai_kona_host_steering(void) {
|
|
||||||
return controls_allowed || ((aol_get_permission_mask() & 1U) != 0U);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hyundai_kona_lfa_valid(const CANPacket_t *msg) {
|
|
||||||
return msg->fd && !msg->extended && (GET_LEN(msg) == 16U) &&
|
|
||||||
(hyundai_canfd_get_checksum(msg) == (hyundai_common_canfd_compute_checksum(msg) ^ 0x041DU));
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hyundai_kona_output_ready(uint32_t now, bool host, uint8_t counter) {
|
|
||||||
const uint32_t age = safety_get_ts_elapsed(now, hyundai_kona_output_ts);
|
|
||||||
const uint8_t delta = (uint8_t)(counter - hyundai_kona_output_counter);
|
|
||||||
return !hyundai_kona_output_seen ||
|
|
||||||
(((hyundai_kona_host_output == host) || (age >= 10000U)) &&
|
|
||||||
((age > 50000U) || ((delta > 0U) && (delta <= 127U))));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void hyundai_kona_track_output(uint32_t now, bool host, uint8_t counter) {
|
|
||||||
hyundai_kona_output_seen = true;
|
|
||||||
hyundai_kona_host_output = host;
|
|
||||||
hyundai_kona_output_ts = now;
|
|
||||||
hyundai_kona_output_counter = counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool hyundai_kona_camera_fwd(const CANPacket_t *msg) {
|
|
||||||
bool blocked = false;
|
|
||||||
if (hyundai_kona_idle_handoff && (msg->bus == 2U) && (msg->addr == 0x12AU)) {
|
|
||||||
const uint32_t now = microsecond_timer_get();
|
|
||||||
const bool valid = hyundai_kona_lfa_valid(msg);
|
|
||||||
if (valid) {
|
|
||||||
const uint8_t delta = (uint8_t)(msg->data[2] - hyundai_kona_camera_counter);
|
|
||||||
if (!hyundai_kona_camera_seen ||
|
|
||||||
(safety_get_ts_elapsed(now, hyundai_kona_camera_ts) > 50000U) ||
|
|
||||||
((delta > 0U) && (delta <= 127U))) {
|
|
||||||
hyundai_kona_camera_seen = true;
|
|
||||||
hyundai_kona_camera_counter = msg->data[2];
|
|
||||||
hyundai_kona_camera_ts = now;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
blocked = !valid || safety_rx_checks_invalid || !aol_rx_healthy() || hyundai_kona_host_steering() ||
|
|
||||||
(msg->data[2] != hyundai_kona_camera_counter) ||
|
|
||||||
!hyundai_kona_output_ready(now, false, msg->data[2]);
|
|
||||||
if (!blocked) {
|
|
||||||
hyundai_kona_track_output(now, false, msg->data[2]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return blocked;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool hyundai_canfd_tx_hook_checked(const CANPacket_t *msg) {
|
static bool hyundai_canfd_tx_hook_checked(const CANPacket_t *msg) {
|
||||||
bool tx = false;
|
bool tx = false;
|
||||||
const bool ordinary_angle_frame = hyundai_ordinary_angle_stock && ((msg->addr == 0x110U) || (msg->addr == 0x362U));
|
const bool ordinary_angle_frame = hyundai_ordinary_angle_stock && ((msg->addr == 0x110U) || (msg->addr == 0x362U));
|
||||||
bool ordinary_angle_valid = true;
|
bool ordinary_angle_valid = true;
|
||||||
|
const bool stock_angle_hda2 = hyundai_angle_aol_enabled && hyundai_canfd_lka_steer_msg && !hyundai_canfd_ccnc_ev_long;
|
||||||
const bool independent_command = hyundai_angle_aol_enabled &&
|
const bool independent_command = hyundai_angle_aol_enabled &&
|
||||||
((msg->addr == 0x50U) || (msg->addr == 0x110U) ||
|
((msg->addr == 0x50U) || (msg->addr == 0x110U) ||
|
||||||
((msg->addr == 0x12AU) && !hyundai_canfd_angle_observed_adas) || (msg->addr == 0xCBU));
|
((msg->addr == 0x12AU) && !hyundai_canfd_angle_observed_adas) || (msg->addr == 0xCBU));
|
||||||
@@ -1308,9 +1301,18 @@ static bool hyundai_canfd_tx_hook_checked(const CANPacket_t *msg) {
|
|||||||
ordinary_angle_valid &= (delta > 0U) && (delta <= 127U);
|
ordinary_angle_valid &= (delta > 0U) && (delta <= 127U);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (stock_angle_hda2) {
|
||||||
|
const uint32_t xor_out = (GET_LEN(msg) == 16U) ? 0x041DU : 0U;
|
||||||
|
ordinary_angle_valid = hyundai_ordinary_angle_owner_current() &&
|
||||||
|
(hyundai_canfd_get_checksum(msg) == (hyundai_common_canfd_compute_checksum(msg) ^ xor_out));
|
||||||
|
}
|
||||||
hyundai_ordinary_angle_release();
|
hyundai_ordinary_angle_release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (stock_angle_hda2 && ((msg->addr == 0x2A4U) || (msg->addr == 0x362U))) {
|
||||||
|
ordinary_angle_valid = hyundai_ordinary_angle_owner_current() &&
|
||||||
|
(hyundai_canfd_get_checksum(msg) == hyundai_common_canfd_compute_checksum(msg));
|
||||||
|
}
|
||||||
if (hyundai_ordinary_angle_stock && !hyundai_angle_aol_enabled) {
|
if (hyundai_ordinary_angle_stock && !hyundai_angle_aol_enabled) {
|
||||||
// Core whitelisting precedes this hook; relay is its only final denial.
|
// Core whitelisting precedes this hook; relay is its only final denial.
|
||||||
ordinary_angle_valid = !relay_malfunction;
|
ordinary_angle_valid = !relay_malfunction;
|
||||||
@@ -1348,30 +1350,36 @@ static bool hyundai_canfd_tx_hook_checked(const CANPacket_t *msg) {
|
|||||||
if (hyundai_angle_aol_enabled && independent_command && !tx) {
|
if (hyundai_angle_aol_enabled && independent_command && !tx) {
|
||||||
hyundai_ordinary_angle_release();
|
hyundai_ordinary_angle_release();
|
||||||
}
|
}
|
||||||
#ifdef ALLOW_DEBUG
|
|
||||||
if (hyundai_kona_idle_handoff && (msg->addr == 0x12AU) && tx && !relay_malfunction) {
|
|
||||||
hyundai_kona_track_output(microsecond_timer_get(), true, msg->data[2]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return tx;
|
return tx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool hyundai_canfd_tx_hook(const CANPacket_t *msg) {
|
static bool hyundai_canfd_tx_hook(const CANPacket_t *msg) {
|
||||||
#ifdef ALLOW_DEBUG
|
bool allowed;
|
||||||
bool allowed = true;
|
#if defined(ALLOW_DEBUG) && !defined(STM32F4)
|
||||||
if (hyundai_kona_idle_handoff && (msg->addr == 0x12AU)) {
|
if (hyundai_kona_ccnc_feedback && (msg->addr == 0x12AU)) {
|
||||||
const uint32_t now = microsecond_timer_get();
|
const uint32_t now = microsecond_timer_get();
|
||||||
allowed = !safety_rx_checks_invalid && aol_rx_healthy() && hyundai_kona_host_steering() &&
|
const uint8_t delta = (uint8_t)(msg->data[2] - hyundai_kona_host.counter);
|
||||||
hyundai_kona_lfa_valid(msg) && hyundai_kona_camera_seen &&
|
const bool advancing = !hyundai_kona_host.seen ||
|
||||||
(safety_get_ts_elapsed(now, hyundai_kona_camera_ts) <= 50000U) &&
|
(safety_get_ts_elapsed(now, hyundai_kona_host.ts) > 50000U) ||
|
||||||
(msg->data[2] == hyundai_kona_camera_counter) && hyundai_kona_output_ready(now, true, msg->data[2]);
|
((delta > 0U) && (delta <= 127U));
|
||||||
|
const bool active = ((msg->data[5] & 0xFEU) != 0U) || ((msg->data[6] & 0x3FU) != 8U);
|
||||||
|
const bool camera_current = hyundai_kona_camera.seen &&
|
||||||
|
(safety_get_ts_elapsed(now, hyundai_kona_camera.ts) <= 50000U);
|
||||||
|
allowed = !relay_malfunction && advancing && hyundai_kona_lfa_valid(msg) &&
|
||||||
|
(!active || (!safety_rx_checks_invalid && aol_rx_healthy() &&
|
||||||
|
lateral_controls_allowed() && camera_current)) &&
|
||||||
|
hyundai_canfd_tx_hook_checked(msg);
|
||||||
|
if (allowed) {
|
||||||
|
hyundai_kona_host.seen = true;
|
||||||
|
hyundai_kona_host.counter = msg->data[2];
|
||||||
|
hyundai_kona_host.ts = now;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
allowed = hyundai_canfd_tx_hook_checked(msg);
|
||||||
}
|
}
|
||||||
#endif
|
return allowed;
|
||||||
return
|
|
||||||
#ifdef ALLOW_DEBUG
|
|
||||||
allowed &&
|
|
||||||
#endif
|
|
||||||
hyundai_canfd_tx_hook_checked(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void hyundai_canfd_reset_ioniq6_state(void) {
|
static void hyundai_canfd_reset_ioniq6_state(void) {
|
||||||
@@ -1873,8 +1881,8 @@ static safety_config hyundai_canfd_init_validated(uint16_t supplied_param) {
|
|||||||
{0x1DA, 1, 32, .check_relay = false},
|
{0x1DA, 1, 32, .check_relay = false},
|
||||||
};
|
};
|
||||||
static const CanMsg ioniq6_long_lkas_alt_tx_msgs[] = {
|
static const CanMsg ioniq6_long_lkas_alt_tx_msgs[] = {
|
||||||
{0x110, 0, 32, .check_relay = true, .disable_static_blocking = true},
|
{0x110, 0, 32, .check_relay = true},
|
||||||
{0x362, 0, 32, .check_relay = true, .disable_static_blocking = true},
|
{0x362, 0, 32, .check_relay = true},
|
||||||
{0x12A, 1, 16, .check_relay = false},
|
{0x12A, 1, 16, .check_relay = false},
|
||||||
{0x1E0, 1, 16, .check_relay = false},
|
{0x1E0, 1, 16, .check_relay = false},
|
||||||
{0x1A0, 1, 32, .check_relay = true, .check_relay_immediately = true},
|
{0x1A0, 1, 32, .check_relay = true, .check_relay_immediately = true},
|
||||||
@@ -2325,12 +2333,12 @@ static safety_config hyundai_canfd_init(uint16_t raw_param) {
|
|||||||
hyundai_daw_init(true, false);
|
hyundai_daw_init(true, false);
|
||||||
hyundai_canfd_reset_ioniq6_state();
|
hyundai_canfd_reset_ioniq6_state();
|
||||||
hyundai_ordinary_angle_reset();
|
hyundai_ordinary_angle_reset();
|
||||||
#ifdef ALLOW_DEBUG
|
#if defined(ALLOW_DEBUG) && !defined(STM32F4) && !defined(PANDA_BODY)
|
||||||
hyundai_kona_idle_handoff = (raw_param == 0x1C0CU) && (alternative_experience == 32);
|
hyundai_kona_ccnc_feedback = (raw_param == 0x1C0CU) && (alternative_experience == 32);
|
||||||
hyundai_kona_camera_seen = false;
|
hyundai_kona_camera.seen = false;
|
||||||
hyundai_kona_output_seen = false;
|
hyundai_kona_host.seen = false;
|
||||||
const bool kona_profile_valid = (raw_param != 0x1C0CU) || hyundai_kona_idle_handoff;
|
const bool kona_profile_valid = (raw_param != 0x1C0CU) || hyundai_kona_ccnc_feedback;
|
||||||
const uint16_t param = hyundai_kona_idle_handoff ? 0x0C0CU : raw_param;
|
const uint16_t param = hyundai_kona_ccnc_feedback ? 0x0C0CU : raw_param;
|
||||||
const bool valid = !GET_FLAG(param, 32768U) || (param == 0x8015U) || (param == 0x8095U) ||
|
const bool valid = !GET_FLAG(param, 32768U) || (param == 0x8015U) || (param == 0x8095U) ||
|
||||||
(param == 0x8815U) || (param == 0x8895U) ||
|
(param == 0x8815U) || (param == 0x8895U) ||
|
||||||
hyundai_canfd_gv60_long_param(param);
|
hyundai_canfd_gv60_long_param(param);
|
||||||
@@ -2351,20 +2359,6 @@ static safety_config hyundai_canfd_init(uint16_t raw_param) {
|
|||||||
const bool daw_profile = (param == 0x0011U) || (param == 0x0091U) || (param == 0x0811U) || (param == 0x0891U) ||
|
const bool daw_profile = (param == 0x0011U) || (param == 0x0091U) || (param == 0x0811U) || (param == 0x0891U) ||
|
||||||
(param == 0x8015U) || (param == 0x8095U) || (param == 0x8815U) || (param == 0x8895U);
|
(param == 0x8015U) || (param == 0x8095U) || (param == 0x8815U) || (param == 0x8895U);
|
||||||
ret = hyundai_daw_configure(ret, true, daw_profile);
|
ret = hyundai_daw_configure(ret, true, daw_profile);
|
||||||
#ifdef ALLOW_DEBUG
|
|
||||||
if (hyundai_kona_idle_handoff) {
|
|
||||||
static CanMsg kona_tx[64];
|
|
||||||
if (hyundai_canfd_angle_aol_capacity(&ret)) {
|
|
||||||
for (int i = 0; i < ret.tx_msgs_len; i++) {
|
|
||||||
kona_tx[i] = ret.tx_msgs[i];
|
|
||||||
if (kona_tx[i].addr == 0x12A) {
|
|
||||||
kona_tx[i].disable_static_blocking = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret.tx_msgs = kona_tx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -2375,8 +2369,8 @@ const safety_hooks hyundai_canfd_hooks = {
|
|||||||
.optional_rx = hyundai_canfd_optional_rx_hook,
|
.optional_rx = hyundai_canfd_optional_rx_hook,
|
||||||
.tx = hyundai_canfd_tx_hook,
|
.tx = hyundai_canfd_tx_hook,
|
||||||
.fwd = hyundai_canfd_fwd_hook,
|
.fwd = hyundai_canfd_fwd_hook,
|
||||||
#ifdef ALLOW_DEBUG
|
#if defined(ALLOW_DEBUG) && !defined(STM32F4)
|
||||||
.fwd_packet = hyundai_kona_camera_fwd,
|
.fwd_output = hyundai_kona_mdps_output,
|
||||||
#endif
|
#endif
|
||||||
.get_counter = hyundai_canfd_get_counter,
|
.get_counter = hyundai_canfd_get_counter,
|
||||||
.get_checksum = hyundai_canfd_get_checksum,
|
.get_checksum = hyundai_canfd_get_checksum,
|
||||||
|
|||||||
@@ -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) {
|
||||||
@@ -366,6 +367,31 @@ int safety_fwd_packet_hook(const CANPacket_t *msg) {
|
|||||||
return destination_bus;
|
return destination_bus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(STM32F4) && (defined(ALLOW_DEBUG) || !defined(STM32H7))
|
||||||
|
bool safety_uses_forward_transform(const CANPacket_t *msg) {
|
||||||
|
#ifdef ALLOW_DEBUG
|
||||||
|
return (current_safety_mode == SAFETY_HYUNDAI_CANFD) && hyundai_kona_ccnc_feedback &&
|
||||||
|
(msg->addr == 0xEAU) && (msg->bus == 0U);
|
||||||
|
#else
|
||||||
|
(void)msg;
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int safety_fwd_output_hook(const CANPacket_t *msg, CANPacket_t *output, bool *replaced) {
|
||||||
|
int destination;
|
||||||
|
if (current_hooks->fwd_output != NULL) {
|
||||||
|
destination = safety_fwd_hook(msg->bus, msg->addr);
|
||||||
|
if (destination >= 0) {
|
||||||
|
current_hooks->fwd_output(msg, output, replaced);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
destination = safety_fwd_packet_hook(msg);
|
||||||
|
}
|
||||||
|
return destination;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// 1Hz safety function called by main. Now just a check for lagging safety messages
|
// 1Hz safety function called by main. Now just a check for lagging safety messages
|
||||||
void safety_tick(void) {
|
void safety_tick(void) {
|
||||||
const uint8_t MAX_MISSED_MSGS = 10U;
|
const uint8_t MAX_MISSED_MSGS = 10U;
|
||||||
@@ -470,6 +496,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
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ SAFETY_UNUSED(safety_rx_hook);
|
|||||||
SAFETY_UNUSED(safety_tx_hook);
|
SAFETY_UNUSED(safety_tx_hook);
|
||||||
SAFETY_UNUSED(safety_fwd_hook);
|
SAFETY_UNUSED(safety_fwd_hook);
|
||||||
SAFETY_UNUSED(safety_fwd_packet_hook);
|
SAFETY_UNUSED(safety_fwd_packet_hook);
|
||||||
|
SAFETY_UNUSED(safety_uses_forward_transform);
|
||||||
|
SAFETY_UNUSED(safety_fwd_output_hook);
|
||||||
SAFETY_UNUSED(safety_tick);
|
SAFETY_UNUSED(safety_tick);
|
||||||
SAFETY_UNUSED(set_safety_hooks);
|
SAFETY_UNUSED(set_safety_hooks);
|
||||||
// Exported to Panda's USB status handler and the native safety test library.
|
// Exported to Panda's USB status handler and the native safety test library.
|
||||||
|
|||||||
@@ -0,0 +1,279 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Accord angle-loop EPS: the panda bounds the 0xE4 angle setpoint by the lateral accel and jerk limits."""
|
||||||
|
import math
|
||||||
|
import re
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
from types import SimpleNamespace
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from opendbc.car import Bus, gen_empty_fingerprint
|
||||||
|
from opendbc.car.honda.carcontroller import CarController
|
||||||
|
from opendbc.car.honda.interface import CarInterface
|
||||||
|
from opendbc.car.honda.values import CAR, DBC, CarControllerParams, HondaSafetyFlags
|
||||||
|
from opendbc.car.lateral import MAX_LATERAL_ACCEL, get_max_angle_delta_vm, get_max_angle_vm
|
||||||
|
from opendbc.car.structs import CarParams
|
||||||
|
from opendbc.car.vehicle_model import VehicleModel, calc_slip_factor
|
||||||
|
from opendbc.safety.tests.libsafety import libsafety_py
|
||||||
|
from opendbc.safety.tests import test_honda # the module, so its test classes are not collected again here
|
||||||
|
|
||||||
|
P = CarControllerParams
|
||||||
|
ARM = P.ANGLE_ARM
|
||||||
|
DT_US = 10_000 # 0xE4 is sent at 100 Hz
|
||||||
|
SPEEDS = (1.0, 3.0, 5.0, 8.0, 10.0, 12.0, 17.5, 22.0, 26.9, 31.0, 38.0)
|
||||||
|
|
||||||
|
|
||||||
|
def accord_cp():
|
||||||
|
fw = [CarParams.CarFw(ecu=CarParams.Ecu.eps, fwVersion=b"39990-TVA,A16C", address=0x18DA30F1, subAddress=0)]
|
||||||
|
return CarInterface.get_params(CAR.HONDA_ACCORD, gen_empty_fingerprint(), fw, False, False, False)
|
||||||
|
|
||||||
|
|
||||||
|
class TestHondaAccordAngleSetpoint(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.fixture = test_honda.TestHondaBoschAltBrakeSafety('test_spam_cancel_safety_check')
|
||||||
|
self.fixture.setUp()
|
||||||
|
self.safety = self.fixture.safety
|
||||||
|
self.packer = self.fixture.packer
|
||||||
|
self.CP = accord_cp()
|
||||||
|
self.angle_flag = self.CP.safetyConfigs[0].safetyParam
|
||||||
|
self.assertNotEqual(self.angle_flag, 0)
|
||||||
|
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, self.angle_flag | 1), 0)
|
||||||
|
self.safety.init_tests()
|
||||||
|
self.VM = VehicleModel(self.CP)
|
||||||
|
self.params = P(self.CP)
|
||||||
|
self.t = 1_000_000
|
||||||
|
self.safety.set_timer(self.t)
|
||||||
|
|
||||||
|
# ---- helpers
|
||||||
|
def _angle_frame(self, raw, steer_req, arm=ARM, bus=None):
|
||||||
|
values = {"STEER_TORQUE": raw, "STEER_TORQUE_REQUEST": steer_req, "STEER_CONTROL_ARM": arm}
|
||||||
|
return self.packer.make_can_msg_safety("STEERING_CONTROL", self.fixture.STEER_BUS if bus is None else bus, values)
|
||||||
|
|
||||||
|
def _tx(self, raw, steer_req=True, arm=ARM, bus=None):
|
||||||
|
self.t += DT_US
|
||||||
|
self.safety.set_timer(self.t)
|
||||||
|
return self.fixture._tx(self._angle_frame(raw, steer_req, arm, bus))
|
||||||
|
|
||||||
|
def _rx_speed(self, v_ms):
|
||||||
|
self.fixture._rx(self.fixture._speed_msg(v_ms * 3.6))
|
||||||
|
|
||||||
|
def _rx_wheel(self, raw):
|
||||||
|
# STEER_ANGLE is -0.1 deg per count: the raw count equals the 0xE4 raw for the same angle
|
||||||
|
self.fixture._rx(self.packer.make_can_msg_safety("STEERING_SENSORS", self.fixture.PT_BUS, {"STEER_ANGLE": -raw / 10.0}))
|
||||||
|
|
||||||
|
def _settle(self, v_ms, wheel_raw=0):
|
||||||
|
for _ in range(6):
|
||||||
|
self._rx_speed(v_ms)
|
||||||
|
self._rx_wheel(wheel_raw)
|
||||||
|
|
||||||
|
def _panda_max_angle_raw(self, v_ms):
|
||||||
|
# the panda evaluates the model 1 m/s below its slowest speed sample and allows one count of rounding
|
||||||
|
return int(get_max_angle_vm(max(v_ms - 1.0, 1.0), self.VM, self.params) * 10 + 1.0)
|
||||||
|
|
||||||
|
def _panda_max_delta_raw(self, v_ms):
|
||||||
|
return int(get_max_angle_delta_vm(max(v_ms - 1.0, 1.0), self.VM, self.params) * 10 + 1.0)
|
||||||
|
|
||||||
|
def test_stock_profiles_and_incompatible_flag_combinations_reject_angle_frames(self):
|
||||||
|
is_debug = self.safety.set_safety_hooks(CarParams.SafetyModel.allOutput, 0) == 0
|
||||||
|
ordinary = (0, 1, 2, 3, 2082, 2083)
|
||||||
|
invalid = (self.angle_flag | 8, self.angle_flag | 16, self.angle_flag | 128)
|
||||||
|
if not is_debug:
|
||||||
|
invalid += tuple(self.angle_flag | word for word in ordinary if word & 2)
|
||||||
|
for word in ordinary + invalid:
|
||||||
|
with self.subTest(word=word):
|
||||||
|
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, word), 0)
|
||||||
|
self.safety.init_tests()
|
||||||
|
self._settle(10.0)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
bus = int(bool(is_debug and word & 2))
|
||||||
|
self.assertFalse(self._tx(10, bus=bus), word)
|
||||||
|
self.assertFalse(self._tx(0, steer_req=False, bus=bus), word)
|
||||||
|
if word in ordinary:
|
||||||
|
self.assertTrue(self._tx(10, arm=0, bus=bus), word)
|
||||||
|
|
||||||
|
def test_flag_preserves_lateral_on_supported_classic_bosch_configurations(self):
|
||||||
|
is_debug = self.safety.set_safety_hooks(CarParams.SafetyModel.allOutput, 0) == 0
|
||||||
|
base_words = (0, 1, 2, 3, 2082, 2083) if is_debug else (0, 1)
|
||||||
|
for base in base_words:
|
||||||
|
with self.subTest(base=base):
|
||||||
|
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, self.angle_flag | base), 0)
|
||||||
|
self.safety.init_tests()
|
||||||
|
self._settle(10.0)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self.assertTrue(self._tx(10, bus=int(bool(base & 2))), base)
|
||||||
|
|
||||||
|
# ---- the model the panda uses is the one openpilot uses
|
||||||
|
def test_vehicle_model_constants_match_openpilot(self):
|
||||||
|
src = (Path(__file__).parents[1] / "modes" / "honda.h").read_text(encoding="utf-8")
|
||||||
|
block = src[src.index("HONDA_ACCORD_ANGLE_PARAMS = {"):]
|
||||||
|
block = block[:block.index("};")]
|
||||||
|
read = {k: float(v) for k, v in re.findall(r"\.(\w+)\s*=\s*(-?[\d.]+)", block)}
|
||||||
|
self.assertAlmostEqual(read["slip_factor"], calc_slip_factor(self.VM), places=12)
|
||||||
|
self.assertAlmostEqual(read["steer_ratio"], self.CP.steerRatio, places=5)
|
||||||
|
self.assertAlmostEqual(read["wheelbase"], self.CP.wheelbase, places=5)
|
||||||
|
self.assertAlmostEqual(MAX_LATERAL_ACCEL, 3.589, places=3)
|
||||||
|
self.assertEqual(self.params.ANGLE_LIMITS.MAX_LATERAL_ACCEL, MAX_LATERAL_ACCEL)
|
||||||
|
|
||||||
|
# ---- lateral acceleration limit
|
||||||
|
def test_setpoint_beyond_the_lateral_accel_limit_is_blocked(self):
|
||||||
|
for v in SPEEDS:
|
||||||
|
limit = self._panda_max_angle_raw(v)
|
||||||
|
if limit > 4000:
|
||||||
|
continue # below ~5 m/s the 400 deg ceiling binds first (covered below)
|
||||||
|
for sign in (-1, 1):
|
||||||
|
self._settle(v)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self.safety.set_desired_angle_last(sign * limit)
|
||||||
|
self.assertTrue(self._tx(sign * limit), (v, sign))
|
||||||
|
self.assertFalse(self._tx(sign * (limit + 1)), (v, sign))
|
||||||
|
# the first blocked frame resets the panda to the wheel; a setpoint this far out stays blocked
|
||||||
|
self.assertFalse(self._tx(sign * (limit + 1)), (v, sign))
|
||||||
|
|
||||||
|
def test_the_old_order_counterexample_is_blocked(self):
|
||||||
|
# 26.9 m/s, wheel held at 42 deg: the old code sent 29.8 deg (5.4 m/s^2) against a 19.8 deg limit
|
||||||
|
v = 26.9
|
||||||
|
self._settle(v, wheel_raw=420)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self.safety.set_desired_angle_last(298)
|
||||||
|
self.assertFalse(self._tx(298))
|
||||||
|
self.assertGreater(298, self._panda_max_angle_raw(v))
|
||||||
|
|
||||||
|
def test_setpoint_beyond_400_deg_is_blocked(self):
|
||||||
|
self._settle(1.0, wheel_raw=4000)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
for raw, ok in ((4000, True), (4001, False), (-4000, True), (-4001, False), (4096, False)):
|
||||||
|
self.safety.set_desired_angle_last(raw)
|
||||||
|
self.assertEqual(ok, self._tx(raw), raw)
|
||||||
|
|
||||||
|
# ---- lateral jerk limit
|
||||||
|
def test_step_beyond_the_lateral_jerk_limit_is_blocked(self):
|
||||||
|
for v in SPEEDS:
|
||||||
|
delta = self._panda_max_delta_raw(v)
|
||||||
|
for sign in (-1, 1):
|
||||||
|
for start in (0, 50):
|
||||||
|
if start + delta + 1 > min(self._panda_max_angle_raw(v), 4000):
|
||||||
|
continue
|
||||||
|
self._settle(v, wheel_raw=sign * start)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self.safety.set_desired_angle_last(sign * start)
|
||||||
|
self.assertTrue(self._tx(sign * (start + delta)), (v, sign, start))
|
||||||
|
self.safety.set_desired_angle_last(sign * start)
|
||||||
|
self.assertFalse(self._tx(sign * (start + delta + 1)), (v, sign, start))
|
||||||
|
|
||||||
|
def test_a_blocked_frame_restarts_from_the_wheel(self):
|
||||||
|
v = 20.0
|
||||||
|
self._settle(v, wheel_raw=30)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self.safety.set_desired_angle_last(30)
|
||||||
|
self.assertFalse(self._tx(30 + self._panda_max_delta_raw(v) + 1))
|
||||||
|
self.assertEqual(self.safety.get_desired_angle_last(), 30)
|
||||||
|
self.assertTrue(self._tx(30 + self._panda_max_delta_raw(v)))
|
||||||
|
|
||||||
|
# ---- request off
|
||||||
|
def test_request_off_frames(self):
|
||||||
|
v = 15.0
|
||||||
|
self._settle(v, wheel_raw=-234)
|
||||||
|
for allowed in (True, False):
|
||||||
|
self.safety.set_controls_allowed(allowed)
|
||||||
|
self.assertTrue(self._tx(0, steer_req=False)) # nothing commanded
|
||||||
|
self.assertEqual(self.safety.get_desired_angle_last(), -234)
|
||||||
|
self.assertEqual(allowed, self._tx(-234, steer_req=False)) # hold at the wheel: only while lateral is allowed
|
||||||
|
self.assertFalse(self._tx(-200, steer_req=False)) # anything else is not the wheel
|
||||||
|
self.assertFalse(self._tx(100, steer_req=False))
|
||||||
|
|
||||||
|
def test_request_needs_controls_allowed(self):
|
||||||
|
self._settle(15.0, wheel_raw=0)
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
self.assertFalse(self._tx(0, steer_req=True))
|
||||||
|
self.assertFalse(self._tx(5, steer_req=True))
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
self.assertTrue(self._tx(0, steer_req=True))
|
||||||
|
|
||||||
|
def test_engage_from_a_zero_field_starts_at_the_wheel(self):
|
||||||
|
# always-on lateral case: the carcontroller sends a zero field until the request, then starts from the wheel
|
||||||
|
v = 25.0
|
||||||
|
self._settle(v, wheel_raw=150)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
for _ in range(5):
|
||||||
|
self.assertTrue(self._tx(0, steer_req=False))
|
||||||
|
self.assertTrue(self._tx(150 + self._panda_max_delta_raw(v), steer_req=True))
|
||||||
|
|
||||||
|
# ---- torque frames (arm 0 or 1) are not angle setpoints
|
||||||
|
def test_torque_frames_are_unaffected(self):
|
||||||
|
self._settle(30.0)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
for arm in (0, 1):
|
||||||
|
for raw in (-4096, -1000, 0, 1000, 4096):
|
||||||
|
self.assertTrue(self._tx(raw, steer_req=True, arm=arm), (arm, raw))
|
||||||
|
self.safety.set_controls_allowed(False)
|
||||||
|
self.assertTrue(self._tx(0, steer_req=False, arm=0))
|
||||||
|
self.assertFalse(self._tx(1000, steer_req=True, arm=0))
|
||||||
|
|
||||||
|
# ---- message rate
|
||||||
|
def test_message_rate_limit(self):
|
||||||
|
self._settle(20.0)
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
blocked = False
|
||||||
|
for _ in range(40): # 40 frames inside one 250 ms window: more than 100 Hz allows
|
||||||
|
blocked |= not self.fixture._tx(self._angle_frame(0, True))
|
||||||
|
self.assertTrue(blocked)
|
||||||
|
|
||||||
|
# ---- the carcontroller's own output is what the panda checks, and it always passes
|
||||||
|
def _controller_frames(self, v_of, wheel_of, desired_of, frames):
|
||||||
|
cc = CarController({Bus.pt: DBC[CAR.HONDA_ACCORD][Bus.pt]}, self.CP)
|
||||||
|
blocked = withheld = 0
|
||||||
|
for i in range(frames):
|
||||||
|
v, wheel = v_of(i), wheel_of(i)
|
||||||
|
wheel_raw = math.floor(-10.0 * wheel + 0.5)
|
||||||
|
self._rx_speed(v)
|
||||||
|
self._rx_wheel(wheel_raw)
|
||||||
|
active = i >= 12 # as on the road, request-off frames come first: they fill the panda's samples
|
||||||
|
CC = SimpleNamespace(actuators=SimpleNamespace(steeringAngleDeg=desired_of(i)), latActive=active, enabled=True)
|
||||||
|
# carState reads the angle off the same STEER_ANGLE counts and the speed off the wheels
|
||||||
|
CS = SimpleNamespace(out=SimpleNamespace(steeringAngleDeg=-wheel_raw / 10.0, vEgoRaw=v,
|
||||||
|
cruiseState=SimpleNamespace(available=True)))
|
||||||
|
_, raw = cc._update_angle(CC, CS)
|
||||||
|
withheld += active and not cc.angle_steer_req
|
||||||
|
blocked += not self._tx(raw, steer_req=cc.angle_steer_req)
|
||||||
|
return blocked, withheld
|
||||||
|
|
||||||
|
def test_carcontroller_output_is_never_blocked(self):
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
rng = np.random.default_rng(1)
|
||||||
|
cases = {
|
||||||
|
"lane keeping": (lambda i: 28.0, lambda i: 2.0 * math.sin(i / 60.0), lambda i: 3.0 * math.sin(i / 50.0)),
|
||||||
|
"saturating request": (lambda i: 20.0, lambda i: 0.0, lambda i: 300.0 * math.sin(i / 100.0)),
|
||||||
|
"random request": (lambda i: 12.0, lambda i: 10.0 * math.sin(i / 40.0), lambda i: float(rng.uniform(-400, 400))),
|
||||||
|
"tight turn": (lambda i: 4.0, lambda i: min(i * 2.0, 380.0), lambda i: 400.0),
|
||||||
|
"driver past the limit": (lambda i: 26.9, lambda i: min(i * 0.3, 45.0), lambda i: 0.0),
|
||||||
|
"driver yank": (lambda i: 17.5, lambda i: 60.0 * math.sin(i / 8.0), lambda i: 5.0),
|
||||||
|
"braking": (lambda i: max(30.0 - i * 0.03, 2.0), lambda i: 5.0, lambda i: 400.0),
|
||||||
|
"accelerating": (lambda i: min(3.0 + i * 0.03, 35.0), lambda i: 0.0, lambda i: -400.0),
|
||||||
|
}
|
||||||
|
for name, (v_of, wheel_of, desired_of) in cases.items():
|
||||||
|
self.safety.set_controls_allowed(True)
|
||||||
|
blocked, withheld = self._controller_frames(v_of, wheel_of, desired_of, 900)
|
||||||
|
self.assertEqual(0, blocked, name)
|
||||||
|
# the request is withheld only where the wheel is past the limit when it would start: the yank reaches 60 deg
|
||||||
|
# against a 38 deg limit. Everywhere else every frame carries the request.
|
||||||
|
self.assertEqual(name == "driver yank", withheld > 0, (name, withheld))
|
||||||
|
|
||||||
|
|
||||||
|
class TestHondaAngleSetpointOnOtherBosch(unittest.TestCase):
|
||||||
|
"""A radarless or CAN FD Honda has no angle-loop EPS: an armed frame is never sent, and is blocked if it is."""
|
||||||
|
|
||||||
|
def test_armed_frame_is_blocked(self):
|
||||||
|
fixture = test_honda.TestHondaBoschRadarlessSafety('test_spam_cancel_safety_check')
|
||||||
|
fixture.setUp()
|
||||||
|
fixture.safety.set_safety_hooks(CarParams.SafetyModel.hondaBosch, HondaSafetyFlags.RADARLESS)
|
||||||
|
fixture.safety.init_tests()
|
||||||
|
fixture.safety.set_controls_allowed(True)
|
||||||
|
for arm, ok in ((0, True), (1, True), (ARM, False)):
|
||||||
|
# bytes 0-1 zero, STEER_TORQUE_REQUEST set, STEER_CONTROL_ARM in byte 2 bits 3:2
|
||||||
|
packet = libsafety_py.make_CANPacket(0xE4, fixture.STEER_BUS, bytes([0, 0, 0x80 | (arm << 2), 0, 0]))
|
||||||
|
self.assertEqual(ok, fixture._tx(packet), arm)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -221,3 +221,95 @@ class TestHyundaiBlendedStock(unittest.TestCase):
|
|||||||
self.safety.safety_rx_hook(common.make_msg(0, 0x50, 16))
|
self.safety.safety_rx_hook(common.make_msg(0, 0x50, 16))
|
||||||
self.assertTrue(self.safety.get_relay_malfunction())
|
self.assertTrue(self.safety.get_relay_malfunction())
|
||||||
self.safety.set_alternative_experience(0)
|
self.safety.set_alternative_experience(0)
|
||||||
|
|
||||||
|
def _start_hda2_aol(self):
|
||||||
|
self.safety.init_tests()
|
||||||
|
self.safety.set_alternative_experience(32)
|
||||||
|
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.hyundai, 0x2010), 0)
|
||||||
|
self.safety.set_aol_test_heartbeat(True)
|
||||||
|
self.steer_counter = 0
|
||||||
|
self.bus = 1
|
||||||
|
self._refresh_hda2_aol_rx(1_000_000)
|
||||||
|
self.safety.aol_set_host_request(1)
|
||||||
|
|
||||||
|
def _refresh_hda2_aol_rx(self, now):
|
||||||
|
self.safety.set_timer(now)
|
||||||
|
for status in self.safety.rx_status:
|
||||||
|
status.msg_seen = status.valid_checksum = status.valid_quality_flag = True
|
||||||
|
status.last_timestamp = now
|
||||||
|
|
||||||
|
def test_hda2_brake_retains_aol_only_after_accepted_steering(self):
|
||||||
|
for steering_before_brake in (False, True):
|
||||||
|
self._start_hda2_aol()
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(common.make_msg(1, 0x4F1, dat=bytes([1, 0, 0, 0]))))
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(self.scc(0, True)))
|
||||||
|
self.assertTrue(self.safety.get_controls_allowed())
|
||||||
|
if steering_before_brake:
|
||||||
|
self.assertTrue(self.safety.safety_tx_hook(self.steer(3)))
|
||||||
|
self._refresh_hda2_aol_rx(1_010_000)
|
||||||
|
brake = common.make_msg(1, 0x394, dat=bytes.fromhex('036c000003449798'))
|
||||||
|
self.assertTrue(self.safety.safety_rx_hook(brake))
|
||||||
|
self.assertFalse(self.safety.get_controls_allowed())
|
||||||
|
self.assertEqual(bool(self.safety.safety_tx_hook(self.steer(3))), steering_before_brake)
|
||||||
|
self.safety.aol_set_host_request(0)
|
||||||
|
self.safety.aol_set_host_request(1)
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(self.steer(3)))
|
||||||
|
|
||||||
|
def test_hda2_idle_blocks_duplicate_only_while_host_steering_is_fresh(self):
|
||||||
|
self._start_hda2_aol()
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), 0)
|
||||||
|
self.assertTrue(self.safety.safety_tx_hook(self.steer(0, False)))
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), -1)
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x421), 0)
|
||||||
|
self._refresh_hda2_aol_rx(1_500_000)
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), 0)
|
||||||
|
self.safety.set_relay_malfunction(True)
|
||||||
|
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)))
|
||||||
|
|||||||
@@ -249,6 +249,26 @@ class TestHyundaiBlendedAlphaAol(unittest.TestCase):
|
|||||||
for _ in range(8):
|
for _ in range(8):
|
||||||
self.feed()
|
self.feed()
|
||||||
|
|
||||||
|
def test_hda2_idle_steering_has_one_forwarding_owner(self):
|
||||||
|
if self.release:
|
||||||
|
self.skipTest("Mixed Alpha Long requires the debug safety build")
|
||||||
|
self.reset(0x2014)
|
||||||
|
self.warm()
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), 0)
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x2A4), 0)
|
||||||
|
steering = self.packer.make_can_msg_safety('LKAS', 0, {'COUNTER': 1, 'TORQUE_REQUEST': 0})
|
||||||
|
self.assertTrue(self.safety.safety_tx_hook(steering))
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), -1)
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x2A4), 0)
|
||||||
|
camera = self.packer.make_can_msg_safety('CAM_0x2a4', 0, {'COUNTER': self.counter - 1})
|
||||||
|
self.assertTrue(self.safety.safety_tx_hook(camera))
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x2A4), -1)
|
||||||
|
self.assertEqual(self.request(3), 0)
|
||||||
|
self.now += 500_000
|
||||||
|
self.warm()
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x50), 0)
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x2A4), 0)
|
||||||
|
|
||||||
def test_hdai_withdrawal_consumes_valid_counter_without_output_credit(self):
|
def test_hdai_withdrawal_consumes_valid_counter_without_output_credit(self):
|
||||||
from opendbc.car.hyundai.hyundaican import hyundai_checksum
|
from opendbc.car.hyundai.hyundaican import hyundai_checksum
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,19 @@ class TestHyundaiIoniq6Long(unittest.TestCase):
|
|||||||
self.assertTrue(self.safety.safety_rx_hook(self.packet(lamp)))
|
self.assertTrue(self.safety.safety_rx_hook(self.packet(lamp)))
|
||||||
return corner, lamp
|
return corner, lamp
|
||||||
|
|
||||||
|
def test_replacement_steering_blocks_factory_copies_for_both_hda2_topologies(self):
|
||||||
|
if self.release:
|
||||||
|
self.skipTest("RELEASE denies all four exact Ioniq 6 LONG profiles")
|
||||||
|
for words in (RAW_LONG, RAW_AOL):
|
||||||
|
for topology, word in words.items():
|
||||||
|
with self.subTest(topology=topology, word=hex(word)):
|
||||||
|
self.mode(word)
|
||||||
|
addresses = (0x110, 0x362) if topology == "lkas_alt" else (0x50, 0x2A4)
|
||||||
|
for address in addresses:
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, address), -1)
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(0, address), 2)
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, 0x123), 0)
|
||||||
|
|
||||||
def test_bsm_all_sixteen_physical_states_and_exact_paired_frames(self):
|
def test_bsm_all_sixteen_physical_states_and_exact_paired_frames(self):
|
||||||
if self.release:
|
if self.release:
|
||||||
self.skipTest("RELEASE denies all four exact Ioniq 6 LONG profiles")
|
self.skipTest("RELEASE denies all four exact Ioniq 6 LONG profiles")
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from opendbc.car import structs
|
from opendbc.car import structs
|
||||||
|
from opendbc.car.hyundai.hyundaicanfd import hkg_can_fd_checksum
|
||||||
from opendbc.safety.tests.libsafety import libsafety_py
|
from opendbc.safety.tests.libsafety import libsafety_py
|
||||||
|
|
||||||
|
|
||||||
class TestHyundaiKonaCcncHandoff(unittest.TestCase):
|
class TestHyundaiKonaCcncFeedback(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.safety = libsafety_py.libsafety
|
self.safety = libsafety_py.libsafety
|
||||||
self.addCleanup(self.safety.set_alternative_experience, 0)
|
self.addCleanup(self.safety.set_alternative_experience, 0)
|
||||||
@@ -15,64 +16,109 @@ class TestHyundaiKonaCcncHandoff(unittest.TestCase):
|
|||||||
self.safety.set_alternative_experience(alternative)
|
self.safety.set_alternative_experience(alternative)
|
||||||
self.assertEqual(self.safety.set_safety_hooks(structs.CarParams.SafetyModel.hyundaiCanfd, word), 0)
|
self.assertEqual(self.safety.set_safety_hooks(structs.CarParams.SafetyModel.hyundaiCanfd, word), 0)
|
||||||
|
|
||||||
def packet(self, bus, body):
|
@staticmethod
|
||||||
packet = libsafety_py.make_CANPacket(0x12A, bus, bytes.fromhex(body))
|
def packet(address, bus, body):
|
||||||
|
body = bytearray(body)
|
||||||
|
body[:2] = hkg_can_fd_checksum(address, None, body).to_bytes(2, 'little')
|
||||||
|
packet = libsafety_py.make_CANPacket(address, bus, body)
|
||||||
packet[0].fd = 1
|
packet[0].fd = 1
|
||||||
return packet
|
return packet
|
||||||
|
|
||||||
def test_handoff_is_debug_only_and_requires_exact_alternative_experience(self):
|
def forward(self, packet):
|
||||||
debug = self.safety.set_safety_hooks(structs.CarParams.SafetyModel.allOutput, 0) == 0
|
output = libsafety_py.new_CANPacket()
|
||||||
camera = self.packet(2, 'a6770a1880001800000a000000900000')
|
replaced = libsafety_py.ffi.new('bool *')
|
||||||
for experience in ((0,) if debug else (0, 32)):
|
bus = self.safety.safety_fwd_output_hook(packet, output, replaced)
|
||||||
self.mode(0x1C0C, experience)
|
return bus, bool(replaced[0]), output
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(camera), -1)
|
|
||||||
self.assertFalse(self.safety.safety_tx_hook(self.packet(0, 'a6770a1880001800000a000000900000')))
|
|
||||||
self.assertEqual(self.safety.safety_fwd_hook(2, 0x123), -1)
|
|
||||||
|
|
||||||
def test_handoff_requires_current_camera_and_one_output_owner(self):
|
def debug_mode(self):
|
||||||
if self.safety.set_safety_hooks(structs.CarParams.SafetyModel.allOutput, 0) != 0:
|
if self.safety.set_safety_hooks(structs.CarParams.SafetyModel.allOutput, 0) != 0:
|
||||||
self.skipTest('Kona factory handoff is DEBUG only')
|
self.skipTest('Kona feedback profile is DEBUG only')
|
||||||
camera = self.packet(2, 'a6770a1880001800000a000000900000')
|
|
||||||
self.mode(0x0C0C)
|
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(camera), -1)
|
|
||||||
|
|
||||||
self.mode(0x1C0C)
|
self.mode(0x1C0C)
|
||||||
|
|
||||||
|
def test_feedback_is_exact_profile_and_debug_only(self):
|
||||||
|
feedback = self.packet(0xEA, 0, bytes(24))
|
||||||
|
for word, alternative, forward in ((0x1C0C, 0, -1), (0x0C0C, 32, 2), (0x0008, 0, 2)):
|
||||||
|
with self.subTest(word=word, alternative=alternative):
|
||||||
|
self.mode(word, alternative)
|
||||||
|
self.assertFalse(self.safety.safety_uses_forward_transform(feedback))
|
||||||
|
self.assertEqual(self.forward(feedback)[:2], (forward, False))
|
||||||
|
release = libsafety_py.ffi.dlopen(libsafety_py._build_libsafety(release=True))
|
||||||
|
release.set_alternative_experience(32)
|
||||||
|
self.assertEqual(release.set_safety_hooks(structs.CarParams.SafetyModel.hyundaiCanfd, 0x1C0C), 0)
|
||||||
|
self.assertFalse(release.safety_uses_forward_transform(feedback))
|
||||||
|
self.assertEqual(release.safety_fwd_packet_hook(feedback), -1)
|
||||||
|
|
||||||
|
def test_output_hook_without_transform_keeps_normal_forwarding_decision(self):
|
||||||
|
self.assertEqual(self.safety.set_safety_hooks(structs.CarParams.SafetyModel.toyota, 0), 0)
|
||||||
|
packet = self.packet(0xEA, 0, bytes(24))
|
||||||
|
self.assertEqual(self.forward(packet)[:2], (2, False))
|
||||||
|
self.safety.set_relay_malfunction(True)
|
||||||
|
self.assertEqual(self.forward(packet)[:2], (-1, False))
|
||||||
|
|
||||||
|
def test_eps_feedback_preserves_faults_and_never_changes_vehicle_side_input(self):
|
||||||
|
self.debug_mode()
|
||||||
|
for warning_byte, toi_byte, modify in ((0, 0, True), (0, 1, True), (0, 3, False),
|
||||||
|
(1, 1, False), (0, 5, False), (0, 0x10, False), (0, 0x40, False)):
|
||||||
|
with self.subTest(warning_byte=warning_byte, toi_byte=toi_byte):
|
||||||
|
body = bytearray(24)
|
||||||
|
body[2:4] = bytes((0xAA, warning_byte))
|
||||||
|
body[6:9] = bytes((toi_byte, 0x12, 0xA3))
|
||||||
|
packet = self.packet(0xEA, 0, body)
|
||||||
|
original = bytes(packet[0].data[0:24])
|
||||||
|
self.assertTrue(self.safety.safety_uses_forward_transform(packet))
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(self.packet(0xEA, 2, original)))
|
||||||
|
bus, replaced, output = self.forward(packet)
|
||||||
|
self.assertEqual((bus, replaced), (2, modify))
|
||||||
|
self.assertEqual(bytes(packet[0].data[0:24]), original)
|
||||||
|
if modify:
|
||||||
|
body[6] = 4
|
||||||
|
expected = self.packet(0xEA, 0, body)
|
||||||
|
self.assertEqual(bytes(output[0].data[0:24]), bytes(expected[0].data[0:24]))
|
||||||
|
packet[0].data[0] ^= 1
|
||||||
|
self.assertFalse(self.forward(packet)[1])
|
||||||
|
self.safety.set_relay_malfunction(True)
|
||||||
|
self.assertEqual(self.forward(packet)[:2], (-1, False))
|
||||||
|
|
||||||
|
def test_host_steering_is_independent_of_camera_counter_and_respects_authority(self):
|
||||||
|
self.debug_mode()
|
||||||
self.safety.set_timer(1_000_000)
|
self.safety.set_timer(1_000_000)
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(camera), -1)
|
|
||||||
for status in self.safety.rx_status:
|
for status in self.safety.rx_status:
|
||||||
status.msg_seen = True
|
status.msg_seen = True
|
||||||
status.valid_checksum = True
|
status.valid_checksum = True
|
||||||
status.valid_quality_flag = True
|
status.valid_quality_flag = True
|
||||||
status.last_timestamp = 1_000_000
|
status.last_timestamp = 1_000_000
|
||||||
|
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(camera), 0)
|
def lfa(bus, counter, torque, request):
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(camera), -1)
|
body = bytearray.fromhex('0000000280000800000a000000900000')
|
||||||
corrupt = self.packet(2, 'a6770a1881001800000a000000900000')
|
raw_torque = 1024 + torque
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(corrupt), -1)
|
body[2] = counter
|
||||||
self.assertFalse(self.safety.safety_tx_hook(self.packet(0, 'a6770a1880001800000a000000900000')))
|
body[5] = (raw_torque & 127) << 1
|
||||||
warning = self.packet(2, '784d1400000108f0000a000000640000')
|
body[6] = (raw_torque >> 7) | (0x10 if request else 0)
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(warning), 0)
|
return self.packet(0x12A, bus, body)
|
||||||
|
|
||||||
self.safety.set_controls_allowed(True)
|
self.safety.set_controls_allowed(True)
|
||||||
self.safety.set_aol_test_heartbeat(True)
|
self.safety.set_aol_test_heartbeat(True)
|
||||||
self.safety.aol_set_host_request(3)
|
self.safety.aol_set_host_request(3)
|
||||||
following = self.packet(2, '110d1600000108f0000a000000640000')
|
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 254, 5, True)))
|
||||||
host = self.packet(0, 'a009150280001800000a000000900000')
|
camera = lfa(2, 81, 0, False)
|
||||||
self.safety.set_timer(1_009_999)
|
self.assertEqual(self.forward(camera)[:2], (-1, False))
|
||||||
self.assertFalse(self.safety.safety_tx_hook(host)) # Require the matching camera counter first.
|
self.safety.safety_rx_hook(camera)
|
||||||
camera_match = self.packet(2, '5ce51500000108f0000a000000640000')
|
self.assertTrue(self.safety.safety_tx_hook(lfa(0, 254, 5, True)))
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(camera_match), -1)
|
for stamp, count, torque in ((1_010_000, 255, 10), (1_020_000, 0, 15)):
|
||||||
self.assertFalse(self.safety.safety_tx_hook(host))
|
self.safety.set_timer(stamp)
|
||||||
self.safety.set_timer(1_010_000)
|
self.safety.safety_rx_hook(lfa(2, 82, 0, False))
|
||||||
self.assertTrue(self.safety.safety_tx_hook(host))
|
self.assertTrue(self.safety.safety_tx_hook(lfa(0, count, torque, True)))
|
||||||
self.assertFalse(self.safety.safety_tx_hook(host))
|
self.assertFalse(self.safety.safety_tx_hook(lfa(0, count, torque, True)))
|
||||||
|
corrupt = lfa(0, 1, 20, True)
|
||||||
|
corrupt[0].data[0] ^= 1
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(corrupt))
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 1, 500, True)))
|
||||||
|
self.safety.set_timer(1_060_001)
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 1, 15, True)))
|
||||||
|
self.safety.safety_rx_hook(lfa(2, 150, 0, False))
|
||||||
self.safety.set_controls_allowed(False)
|
self.safety.set_controls_allowed(False)
|
||||||
self.safety.aol_set_host_request(0)
|
self.safety.aol_set_host_request(0)
|
||||||
self.safety.set_timer(1_019_999)
|
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 1, 5, True)))
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(following), -1)
|
self.assertTrue(self.safety.safety_tx_hook(lfa(0, 1, 0, False)))
|
||||||
self.safety.set_timer(1_020_000)
|
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(following), 0)
|
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(following), -1)
|
|
||||||
self.safety.set_relay_malfunction(True)
|
self.safety.set_relay_malfunction(True)
|
||||||
self.assertEqual(self.safety.safety_fwd_packet_hook(following), -1)
|
self.assertFalse(self.safety.safety_tx_hook(lfa(0, 2, 0, False)))
|
||||||
self.assertFalse(self.safety.safety_tx_hook(host))
|
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -4,6 +4,7 @@ import unittest
|
|||||||
|
|
||||||
from opendbc.can import CANPacker
|
from opendbc.can import CANPacker
|
||||||
from opendbc.car import structs
|
from opendbc.car import structs
|
||||||
|
from opendbc.car.hyundai.interface import CarInterface
|
||||||
from opendbc.safety.tests.libsafety import libsafety_py
|
from opendbc.safety.tests.libsafety import libsafety_py
|
||||||
|
|
||||||
|
|
||||||
@@ -98,6 +99,8 @@ class TestHyundaiStockAngleAol(unittest.TestCase):
|
|||||||
self.assertFalse(self.safety.safety_test_selected_fwd(2, address))
|
self.assertFalse(self.safety.safety_test_selected_fwd(2, address))
|
||||||
self.assertTrue(self.safety.safety_tx_hook(self.command(word, 3)))
|
self.assertTrue(self.safety.safety_tx_hook(self.command(word, 3)))
|
||||||
self.assertTrue(self.safety.safety_tx_hook(self.command(word, 4, active=False)))
|
self.assertTrue(self.safety.safety_tx_hook(self.command(word, 4, active=False)))
|
||||||
|
if topology.startswith('lka'):
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(self.command(word, 5, active=False)))
|
||||||
self.assertFalse(self.safety.safety_test_selected_fwd(2, address))
|
self.assertFalse(self.safety.safety_test_selected_fwd(2, address))
|
||||||
self.assertTrue(self.safety.safety_tx_hook(self.command(word, 5)))
|
self.assertTrue(self.safety.safety_tx_hook(self.command(word, 5)))
|
||||||
self.safety.set_timer(1_300_001)
|
self.safety.set_timer(1_300_001)
|
||||||
@@ -105,6 +108,38 @@ class TestHyundaiStockAngleAol(unittest.TestCase):
|
|||||||
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
self.assertEqual(self.safety.aol_get_permission_mask(), 0)
|
||||||
self.assertFalse(self.safety.safety_tx_hook(self.command(word, 6)))
|
self.assertFalse(self.safety.safety_tx_hook(self.command(word, 6)))
|
||||||
|
|
||||||
|
def test_hda2_controller_sends_only_one_inactive_release(self):
|
||||||
|
car = angle_profiles.CARS[0]
|
||||||
|
for topology, address, camera_name in (('lka', 0x50, 'CAM_0x2a4'), ('lka_alt', 0x110, 'CAM_0x362')):
|
||||||
|
cp = angle_profiles.params(car, topology, hybrid=True)
|
||||||
|
cp.alternativeExperience = 32
|
||||||
|
word = cp.safetyConfigs[-1].safetyParam
|
||||||
|
self.mode(word)
|
||||||
|
self.sources(word)
|
||||||
|
self.gesture(word)
|
||||||
|
interface = CarInterface(cp)
|
||||||
|
packer, frames = angle_profiles.source_frames(cp, topology)
|
||||||
|
frames.append(packer.make_can_msg(camera_name, 2, {}))
|
||||||
|
state = interface.update([(1_000_000_000, frames)])
|
||||||
|
self.assertTrue(state.canValid)
|
||||||
|
control = structs.CarControl()
|
||||||
|
camera_frame = packer.make_can_msg(camera_name, 0, {})
|
||||||
|
camera = self.packet(camera_frame)
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(camera))
|
||||||
|
for tick, (active, expected) in enumerate(((False, []), (True, [2]), (False, [1]), (False, []))):
|
||||||
|
control.latActive = active
|
||||||
|
_, sends = interface.apply(control.as_reader(), 1_000_000_000 + tick * 10_000_000)
|
||||||
|
steering = [frame for frame in sends if frame[0] == address]
|
||||||
|
self.assertEqual([(frame[1][9] >> 4) & 3 for frame in steering], expected)
|
||||||
|
for frame in steering:
|
||||||
|
self.assertTrue(self.safety.safety_tx_hook(self.packet(frame)))
|
||||||
|
self.assertEqual(self.safety.safety_fwd_hook(2, address), -1 if active else 0)
|
||||||
|
self.assertEqual(bool(self.safety.safety_tx_hook(camera)), active, (topology, tick))
|
||||||
|
if active:
|
||||||
|
bad_camera = self.packet(camera_frame)
|
||||||
|
bad_camera[0].data[0] ^= 1
|
||||||
|
self.assertFalse(self.safety.safety_tx_hook(bad_camera))
|
||||||
|
|
||||||
def test_non_angle_profile_rejects_cb_at_public_and_selected_hooks(self):
|
def test_non_angle_profile_rejects_cb_at_public_and_selected_hooks(self):
|
||||||
self.safety.set_alternative_experience(0)
|
self.safety.set_alternative_experience(0)
|
||||||
self.assertEqual(self.safety.set_safety_hooks(structs.CarParams.SafetyModel.hyundaiCanfd, 0), 0)
|
self.assertEqual(self.safety.set_safety_hooks(structs.CarParams.SafetyModel.hyundaiCanfd, 0), 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()
|
||||||
@@ -380,7 +380,9 @@ def test_recorded_pe_stock_wheel_cutoff_withdraws_native_output_without_new_butt
|
|||||||
assert case.safety.aol_get_permission_mask() == int(moving)
|
assert case.safety.aol_get_permission_mask() == int(moving)
|
||||||
assert bool(case.safety.safety_tx_hook(case.command(word, counter))) is moving
|
assert bool(case.safety.safety_tx_hook(case.command(word, counter))) is moving
|
||||||
if not moving:
|
if not moving:
|
||||||
assert case.safety.safety_tx_hook(case.command(word, counter, active=False))
|
inactive = case.command(word, counter, active=False)
|
||||||
|
assert not case.safety.safety_tx_hook(inactive)
|
||||||
|
assert case.safety.safety_fwd_hook(2, inactive[0].addr) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('identity', ['HYUNDAI_IONIQ_5_PE', 'KIA_EV9'])
|
@pytest.mark.parametrize('identity', ['HYUNDAI_IONIQ_5_PE', 'KIA_EV9'])
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user