mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 20:03:53 +08:00
tools: improved CAN replay (#27975)
This commit is contained in:
@@ -5,16 +5,16 @@
|
||||
`replay` replays all the messages logged while running openpilot.
|
||||
|
||||
```bash
|
||||
# Log in via browser to have access to non-public routes
|
||||
# Log in via browser to have access to routes from your comma account
|
||||
python tools/lib/auth.py
|
||||
|
||||
# Start a replay
|
||||
tools/replay/replay <route-name>
|
||||
|
||||
# Example:
|
||||
# tools/replay/replay '4cf7a6ad03080c90|2021-09-29--13-46-36'
|
||||
tools/replay/replay '4cf7a6ad03080c90|2021-09-29--13-46-36'
|
||||
# or use --demo to replay the default demo route:
|
||||
# tools/replay/replay --demo
|
||||
tools/replay/replay --demo
|
||||
|
||||
# watch the replay with the normal openpilot UI
|
||||
cd selfdrive/ui && ./ui
|
||||
@@ -64,12 +64,24 @@ cd selfdrive/ui && ./watch3
|
||||
|
||||
Replay CAN messages as they were recorded using a [panda jungle](https://comma.ai/shop/products/panda-jungle). The jungle has 6x OBD-C ports for connecting all your comma devices. Check out the [jungle repo](https://github.com/commaai/panda_jungle) for more info.
|
||||
|
||||
`can_replay.py` is a convenient script for when any CAN data will do.
|
||||
In order to run your device as if it was in a car:
|
||||
* connect a panda jungle to your PC
|
||||
* connect a comma device or panda to the jungle via OBD-C
|
||||
* run `can_replay.py`
|
||||
|
||||
In order to replay specific route:
|
||||
```bash
|
||||
MOCK=1 selfdrive/boardd/tests/boardd_old.py
|
||||
``` bash
|
||||
batman:replay$ ./can_replay.py -h
|
||||
usage: can_replay.py [-h] [route_or_segment_name]
|
||||
|
||||
# In another terminal:
|
||||
tools/replay/replay <route-name>
|
||||
Replay CAN messages from a route to all connected pandas and jungles
|
||||
in a loop.
|
||||
|
||||
positional arguments:
|
||||
route_or_segment_name
|
||||
The route or segment name to replay. If not
|
||||
specified, a default public route will be
|
||||
used. (default: None)
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
```
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
@@ -11,6 +12,7 @@ from common.basedir import BASEDIR
|
||||
from common.realtime import config_realtime_process, Ratekeeper, DT_CTRL
|
||||
from selfdrive.boardd.boardd import can_capnp_to_can_list
|
||||
from tools.plotjuggler.juggle import load_segment
|
||||
from tools.lib.logreader import logreader_from_route_or_segment
|
||||
from panda import Panda
|
||||
|
||||
try:
|
||||
@@ -87,18 +89,27 @@ def connect():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description="Replay CAN messages from a route to all connected pandas and jungles in a loop.",
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("route_or_segment_name", nargs='?', help="The route or segment name to replay. If not specified, a default public route will be used.")
|
||||
args = parser.parse_args()
|
||||
|
||||
if not panda_jungle_imported:
|
||||
print("\33[31m", "WARNING: cannot connect to jungles. Clone the jungle library to enable support:", "\033[0m")
|
||||
print("\033[34m", f"cd {BASEDIR} && git clone https://github.com/commaai/panda_jungle", "\033[0m")
|
||||
|
||||
print("Loading log...")
|
||||
ROUTE = "77611a1fac303767/2020-03-24--09-50-38"
|
||||
REPLAY_SEGS = list(range(10, 16)) # route has 82 segments available
|
||||
CAN_MSGS = []
|
||||
logs = [f"https://commadataci.blob.core.windows.net/openpilotci/{ROUTE}/{i}/rlog.bz2" for i in REPLAY_SEGS]
|
||||
with multiprocessing.Pool(24) as pool:
|
||||
for lr in tqdm(pool.map(load_segment, logs)):
|
||||
CAN_MSGS += [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can']
|
||||
if args.route_or_segment_name is None:
|
||||
ROUTE = "77611a1fac303767/2020-03-24--09-50-38"
|
||||
REPLAY_SEGS = list(range(10, 16)) # route has 82 segments available
|
||||
CAN_MSGS = []
|
||||
logs = [f"https://commadataci.blob.core.windows.net/openpilotci/{ROUTE}/{i}/rlog.bz2" for i in REPLAY_SEGS]
|
||||
with multiprocessing.Pool(24) as pool:
|
||||
for lr in tqdm(pool.map(load_segment, logs)):
|
||||
CAN_MSGS += [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can']
|
||||
else:
|
||||
lr = logreader_from_route_or_segment(args.route_or_segment_name)
|
||||
CAN_MSGS = [can_capnp_to_can_list(m.can) for m in lr if m.which() == 'can']
|
||||
|
||||
# set both to cycle ignition
|
||||
IGN_ON = int(os.getenv("ON", "0"))
|
||||
|
||||
Reference in New Issue
Block a user