这是indexloc提供的服务,不要输入任何密码
Skip to content

Tesla: Autopark init variable breaks safety replay #2768

@AmyJeanes

Description

@AmyJeanes

Many thanks to @sunnyhaibin for discovering this issue, they asked me to raise it here.

To allow autopark to work correctly, we assume that it is always active when openpilot first boots up, until we hear a message from the canbus saying otherwise, to prevent it blocking stock steering commands:

// we need to assume Autopark/Summon on startup since DI_state is a low freq msg.
// this is so that we don't fault if starting while these systems are active
tesla_autopark = true;
tesla_autopark_prev = false;

But it seems that doing this breaks the ./opendbc/safety/tests/safety_replay/replay_drive.py script as it always faults with the following error message on any Tesla route, including this one from the test routes:

CarTestRoute("7dc058789994da80/00000112--adb970f6a8", TESLA.TESLA_MODEL_3),

(openpilot) amy@Amy-PC:~/git/openpilot$ ./opendbc/safety/tests/safety_replay/replay_drive.py 7dc058789994da80/00000112--adb970f6a8
replaying 7dc058789994da80/00000112--adb970f6a8 with safety mode 10, param 0, alternative experience 0
Traceback (most recent call last):
  File "/home/amy/git/openpilot/./opendbc/safety/tests/safety_replay/replay_drive.py", line 99, in <module>
    replay_drive(list(lr), args.mode, args.param, args.alternative_experience)
  File "/home/amy/git/openpilot/./opendbc/safety/tests/safety_replay/replay_drive.py", line 20, in replay_drive
    init_segment(safety, msgs, safety_mode, param)
  File "/home/amy/git/openpilot/opendbc/safety/tests/safety_replay/helpers.py", line 109, in init_segment
    assert safety.safety_tx_hook(msg), "failed to initialize panda safety for segment"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: failed to initialize panda safety for segment

If we instead set it to tesla_autopark = false; in the code above, it works as expected.

(openpilot) amy@Amy-PC:~/git/openpilot$ ./opendbc/safety/tests/safety_replay/replay_drive.py 7dc058789994da80/00000112--adb970f6a8
replaying 7dc058789994da80/00000112--adb970f6a8 with safety mode 10, param 0, alternative experience 0
100%|█████████████████████████████████████████████████████████████| 135146/135146 [00:13<00:00, 9808.01it/s]

RX
total rx msgs: 4335547
invalid rx msgs: 0
safety tick rx invalid: False
invalid addrs: set()

TX
total openpilot msgs: 40471
total msgs with controls allowed: 28233
blocked msgs: 1
blocked with controls allowed: 0
blocked addrs: Counter({1160: 1})

In the safety test helpers, we actually do disable it here already:

// assumes autopark on safety mode init to avoid a fault. get rid of that for testing
tesla_autopark = false;

So I am thinking we might need something similar to this in the safety replay code, or maybe for Tesla specifically assume that the TX hook will fail and don't assert on it here, which is where the error is coming from:

assert safety.safety_tx_hook(msg), "failed to initialize panda safety for segment"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions