Repository navigation
volvo: solve PSCM_RELATED CHECKSUM_2, fix invalid checksum during rack fault - #11
Open
joeywritesc wants to merge 1 commit into
Open
joeywritesc wants to merge 1 commit into
joeywritesc wants to merge 1 commit into
Conversation
…k fault checksum_2_pscm_related_message was a 15-entry lookup table over byte[2] = 0x80..0x8E, returning 0 on a miss. After the rack resets itself mid-drive it reports byte[2] = 0xA0..0xAE (fault state) until the car is power cycled, so every 0x17 frame openpilot forwarded to the car during a rack fault carried an invalid checksum (0x00). Replace the table with the underlying function: like CHECKSUM_1 it is linear over GF(2), so each set bit of byte[2] flips a fixed pattern of checksum bits. Solved from 19,824 rack frames from one Polestar 2 drive with a real power-steering fault (7,450 frames in the fault state), spanning 30 distinct byte[2] values. Leave-one-out cross-validation predicts 30/30, and all 15 previous table entries are reproduced exactly. Bits 4 and 6 of byte[2] were never observed set and are taken to flip nothing. Adds a regression test with the 15 fault-state values. ./test.sh shows the same pre-existing failures before and after this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Same class of bug as the ECHO=6 fix for CHECKSUM_1, this time in CHECKSUM_2.
Problem
When the rack resets itself mid-drive it switches 0x17 byte[2] from 0x8_ to 0xA_ and holds it until the car is power cycled.
checksum_2_pscm_related_messagewas a lookup table over 0x80..0x8E only, so for 0xA_ it returned 0x00, and every 0x17 frame forwarded to the car during a rack fault had an invalid CHECKSUM_2. CHECKSUM_1 (your GF(2) formula) already handles 0xA_ correctly.Data
A Polestar 2 drive (Nov 7) with a real power-steering failure on StarPilot. The rack data is independent of the fork.
Fix
Replace the table with the linear GF(2) function: each set bit of byte[2] flips a fixed pattern of checksum bits. Solved from the 30 observed byte[2] values; leave-one-out predicts 30/30, and all 15 previous table entries are reproduced exactly.
Test
test_checksum_2_covers_rack_fault_stateadds the 15 fault-state values. It fails on the current code (b2=0xA0: 0 != 0x85) and passes with the fix../test.shhas the same pre-existing failures before and after.Caveat
The fault-state data is from one car and one drive. Bits 4 and 6 of byte[2] have never been seen set, so the formula assumes they flip nothing.
Possible follow-up (separate PR): byte[2] = 0xA_ appears ~690 ms after the rack reboots, on both failures I've looked at, so it could set
steerFaultPermanentfor a proper alert.Validation