dragonpilot - 基於 openpilot 的開源駕駛輔助系統
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

530 lines
17 KiB

5 years ago
#!/usr/bin/env python3
import os
import time
import signal
import platform
from collections import OrderedDict
from dataclasses import dataclass, field
from typing import Dict, List, Optional, Callable
5 years ago
import cereal.messaging as messaging
from cereal import car
5 years ago
from cereal.services import service_list
from common.params import Params
from common.timeout import Timeout
from common.realtime import DT_CTRL
from panda.python import ALTERNATIVE_EXPERIENCE
from selfdrive.car.car_helpers import get_car, interfaces
from selfdrive.manager.process_config import managed_processes
from selfdrive.test.process_replay.helpers import OpenpilotPrefix
# Numpy gives different results based on CPU features after version 19
NUMPY_TOLERANCE = 1e-7
CI = "CI" in os.environ
TIMEOUT = 15
process replay: automatically push refs on fail (#24414) * test failure() * let's just change a tune here * debug revert * debug * use current commit, not ref_commit fix * need to figure out better place for this * quick test * test without upload * temp * use azure token * fixes * shouldn't need this * debug * debug * not getting anything? * does this mean nothing gets envvars? * add azure token to docker environment variables * quote * move back * clean up a bit * more clean up * like this sorting better * replace flags with CI and clean up * test FULL_TEST and minimalize diff a bit * now test all * revert tests comments * remove flags * revert this revert this * now make it fail * now update ref_commit to last commit (make sure we can re-start this test if we commit before last one finishes uploading) * fix fix fix fix * bad commit * why is it not throwing an exception? * debug * URLFile returns empty bytes if using cache and remote file doesn't exist * we always need to download anyway * debug... * duh, wrong file. but neither should have it * add that back and just check explicitly * check both * clean up and make a diff * stylize * see if this is a better diff on files changed * update refs * revert changes * only for owners or members * if we have token access * if we have token access * if we have token access * move up * clean up * revert * move update refs to test_processes * clean up * update messages * update msg * update README and delete update_refs * this isn't possible to reach anymore * fix readme * better help message better help message better help message * only show basename when uploading, only if failed to find * test diff * fix printing old ref commit * change to using * update refs * Revert "update refs" This reverts commit 2e352a736a6de68e2c7064daa4e2e9409ce77686. * revert * ref refers to reference commit/logs, cur refers to current logs/commit (future ref) * like for better * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/test/process_replay/test_processes.py * every time lol Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
PROC_REPLAY_DIR = os.path.dirname(os.path.abspath(__file__))
FAKEDATA = os.path.join(PROC_REPLAY_DIR, "fakedata/")
class ReplayContext:
def __init__(self, cfg):
self.proc_name = cfg.proc_name
self.pubs = cfg.pubs
self.drained_pub = cfg.drained_pub
assert(len(self.pubs) != 0 or self.drained_pub is not None)
def __enter__(self):
messaging.toggle_fake_events(True)
messaging.set_fake_prefix(self.proc_name)
if self.drained_pub is None:
self.events = OrderedDict()
for pub in self.pubs:
self.events[pub] = messaging.fake_event_handle(pub, enable=True)
else:
self.events = {self.drained_pub: messaging.fake_event_handle(self.drained_pub, enable=True)}
return self
def __exit__(self, exc_type, exc_obj, exc_tb):
del self.events
messaging.toggle_fake_events(False)
messaging.delete_fake_prefix()
@property
def all_recv_called_events(self):
return [man.recv_called_event for man in self.events.values()]
@property
def all_recv_ready_events(self):
return [man.recv_ready_event for man in self.events.values()]
def send_sync(self, pm, endpoint, dat):
self.events[endpoint].recv_called_event.wait()
self.events[endpoint].recv_called_event.clear()
pm.send(endpoint, dat)
self.events[endpoint].recv_ready_event.set()
def unlock_sockets(self):
expected_sets = len(self.events)
while expected_sets > 0:
index = messaging.wait_for_one_event(self.all_recv_called_events)
self.all_recv_called_events[index].clear()
self.all_recv_ready_events[index].set()
expected_sets -= 1
def wait_for_recv_called(self):
messaging.wait_for_one_event(self.all_recv_called_events)
def wait_for_next_recv(self, trigger_empty_recv):
index = messaging.wait_for_one_event(self.all_recv_called_events)
if self.drained_pub is not None and trigger_empty_recv:
self.all_recv_called_events[index].clear()
self.all_recv_ready_events[index].set()
self.all_recv_called_events[index].wait()
@dataclass
class ProcessConfig:
proc_name: str
pubs: List[str]
subs: List[str]
ignore: List[str]
config_callback: Optional[Callable]
init_callback: Optional[Callable]
should_recv_callback: Optional[Callable]
tolerance: Optional[float] = None
environ: Dict[str, str] = field(default_factory=dict)
subtest_name: str = ""
field_tolerances: Dict[str, float] = field(default_factory=dict)
timeout: int = 30
simulation: bool = True
drained_pub: Optional[str] = None
5 years ago
class DummySocket:
def __init__(self):
5 years ago
self.data = []
def receive(self, non_blocking=False):
if non_blocking:
return None
return self.data.pop()
5 years ago
def send(self, data):
self.data.append(data)
def controlsd_fingerprint_callback(rc, pm, msgs, fingerprint):
5 years ago
print("start fingerprinting")
params = Params()
canmsgs = [msg for msg in msgs if msg.which() == "can"][:300]
5 years ago
# controlsd expects one arbitrary can and pandaState
rc.send_sync(pm, "can", messaging.new_message("can", 1))
pm.send("pandaStates", messaging.new_message("pandaStates", 1))
rc.send_sync(pm, "can", messaging.new_message("can", 1))
rc.wait_for_next_recv(True)
5 years ago
# fingerprinting is done, when CarParams is set
while params.get("CarParams") is None:
if len(canmsgs) == 0:
raise ValueError("Fingerprinting failed. Run out of can msgs")
5 years ago
m = canmsgs.pop(0)
rc.send_sync(pm, "can", m.as_builder().to_bytes())
rc.wait_for_next_recv(False)
5 years ago
def get_car_params_callback(rc, pm, msgs, fingerprint):
if fingerprint:
CarInterface, _, _ = interfaces[fingerprint]
CP = CarInterface.get_non_essential_params(fingerprint)
else:
can = DummySocket()
sendcan = DummySocket()
5 years ago
canmsgs = [msg for msg in msgs if msg.which() == "can"]
assert len(canmsgs) != 0, "CAN messages are required for carParams initialization"
for m in canmsgs[:300]:
can.send(m.as_builder().to_bytes())
_, CP = get_car(can, sendcan, Params().get_bool("ExperimentalLongitudinalEnabled"))
5 years ago
Params().put("CarParams", CP.to_bytes())
def controlsd_rcv_callback(msg, cfg, frame):
# no sendcan until controlsd is initialized
5 years ago
if msg.which() != "can":
return False
5 years ago
socks = [
s for s in cfg.subs if
frame % int(service_list[msg.which()].frequency / service_list[s].frequency) == 0
]
if "sendcan" in socks and (frame - 1) < 2000:
socks.remove("sendcan")
return len(socks) > 0
5 years ago
def radar_rcv_callback(msg, cfg, frame):
return msg.which() == "can"
5 years ago
def calibration_rcv_callback(msg, cfg, frame):
5 years ago
# calibrationd publishes 1 calibrationData every 5 cameraOdometry packets.
# should_recv always true to increment frame
return (frame - 1) == 0 or msg.which() == 'cameraOdometry'
5 years ago
def torqued_rcv_callback(msg, cfg, frame):
Live torque (#25456) * wip torqued * add basic logic * setup in manager * check sanity and publish msg * add first order filter to outputs * wire up controlsd, and update gains * rename intercept to offset * add cloudlog, live values are not updated * fix bugs, do not reset points for now * fix crashes * rename to main * fix bugs, works offline * fix float in cereal bug * add latacc filter * randomly choose points, approx for iid * add variable decay * local param to capnp instead of dict * verify works in replay * use torqued output in controlsd * use in controlsd; use points from past routes * controlsd bugfix * filter before updating gains, needs to be replaced * save all points to ensure smooth transition across routes, revert friction factor to 1.5 * add filters to prevent noisy low-speed data points; improve fit sanity * add engaged buffer * revert lat_acc thresh * use paramsd realtime process config * make latacc-to-torque generic, and overrideable * move freq to 4Hz, avoid storing in np.array, don't publish points in the message * float instead of np * remove constant while storing pts * rename slope, offset to lat_accet_factor, offset * resolve issues * use camelcase in all capnp params * use camelcase everywhere * reduce latacc threshold or sanity, add car_sane todo, save points properly * add and check tag * write param to disk at end of route * remove args * rebase op, cereal * save on exit * restore default handler * cpu usage check * add to process replay * handle reset better, reduce unnecessary computation * always publish raw values - useful for debug * regen routes * update refs * checks on cache restore * check tuning vals too * clean that up * reduce cpu usage * reduce cpu usage by 75% * cleanup * optimize further * handle reset condition better, don't put points in init, use only in corolla * bump cereal after rebasing * update refs * Update common/params.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * remove unnecessary checks * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
# should_recv always true to increment frame
return (frame - 1) == 0 or msg.which() == 'liveLocationKalman'
class FrequencyBasedRcvCallback:
def __init__(self, trigger_msg_type):
self.trigger_msg_type = trigger_msg_type
def __call__(self, msg, cfg, frame):
if msg.which() != self.trigger_msg_type:
return False
Live torque (#25456) * wip torqued * add basic logic * setup in manager * check sanity and publish msg * add first order filter to outputs * wire up controlsd, and update gains * rename intercept to offset * add cloudlog, live values are not updated * fix bugs, do not reset points for now * fix crashes * rename to main * fix bugs, works offline * fix float in cereal bug * add latacc filter * randomly choose points, approx for iid * add variable decay * local param to capnp instead of dict * verify works in replay * use torqued output in controlsd * use in controlsd; use points from past routes * controlsd bugfix * filter before updating gains, needs to be replaced * save all points to ensure smooth transition across routes, revert friction factor to 1.5 * add filters to prevent noisy low-speed data points; improve fit sanity * add engaged buffer * revert lat_acc thresh * use paramsd realtime process config * make latacc-to-torque generic, and overrideable * move freq to 4Hz, avoid storing in np.array, don't publish points in the message * float instead of np * remove constant while storing pts * rename slope, offset to lat_accet_factor, offset * resolve issues * use camelcase in all capnp params * use camelcase everywhere * reduce latacc threshold or sanity, add car_sane todo, save points properly * add and check tag * write param to disk at end of route * remove args * rebase op, cereal * save on exit * restore default handler * cpu usage check * add to process replay * handle reset better, reduce unnecessary computation * always publish raw values - useful for debug * regen routes * update refs * checks on cache restore * check tuning vals too * clean that up * reduce cpu usage * reduce cpu usage by 75% * cleanup * optimize further * handle reset condition better, don't put points in init, use only in corolla * bump cereal after rebasing * update refs * Update common/params.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * remove unnecessary checks * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
resp_sockets = [
s for s in cfg.subs
if frame % max(1, int(service_list[msg.which()].frequency / service_list[s].frequency)) == 0
]
return bool(len(resp_sockets))
Live torque (#25456) * wip torqued * add basic logic * setup in manager * check sanity and publish msg * add first order filter to outputs * wire up controlsd, and update gains * rename intercept to offset * add cloudlog, live values are not updated * fix bugs, do not reset points for now * fix crashes * rename to main * fix bugs, works offline * fix float in cereal bug * add latacc filter * randomly choose points, approx for iid * add variable decay * local param to capnp instead of dict * verify works in replay * use torqued output in controlsd * use in controlsd; use points from past routes * controlsd bugfix * filter before updating gains, needs to be replaced * save all points to ensure smooth transition across routes, revert friction factor to 1.5 * add filters to prevent noisy low-speed data points; improve fit sanity * add engaged buffer * revert lat_acc thresh * use paramsd realtime process config * make latacc-to-torque generic, and overrideable * move freq to 4Hz, avoid storing in np.array, don't publish points in the message * float instead of np * remove constant while storing pts * rename slope, offset to lat_accet_factor, offset * resolve issues * use camelcase in all capnp params * use camelcase everywhere * reduce latacc threshold or sanity, add car_sane todo, save points properly * add and check tag * write param to disk at end of route * remove args * rebase op, cereal * save on exit * restore default handler * cpu usage check * add to process replay * handle reset better, reduce unnecessary computation * always publish raw values - useful for debug * regen routes * update refs * checks on cache restore * check tuning vals too * clean that up * reduce cpu usage * reduce cpu usage by 75% * cleanup * optimize further * handle reset condition better, don't put points in init, use only in corolla * bump cereal after rebasing * update refs * Update common/params.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * remove unnecessary checks * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
def laikad_config_pubsub_callback(params, cfg):
ublox = params.get_bool("UbloxAvailable")
drained_key = "ubloxGnss" if ublox else "qcomGnss"
sub_keys = ({"qcomGnss", } if ublox else {"ubloxGnss", })
return set(cfg.pubs) - sub_keys, drained_key
def locationd_config_pubsub_callback(params, cfg):
ublox = params.get_bool("UbloxAvailable")
sub_keys = ({"gpsLocation", } if ublox else {"gpsLocationExternal", })
return set(cfg.pubs) - sub_keys, None
5 years ago
CONFIGS = [
ProcessConfig(
proc_name="controlsd",
pubs=[
"can", "deviceState", "pandaStates", "peripheralState", "liveCalibration", "driverMonitoringState",
"longitudinalPlan", "lateralPlan", "liveLocationKalman", "liveParameters", "radarState",
"modelV2", "driverCameraState", "roadCameraState", "wideRoadCameraState", "managerState",
"testJoystick", "liveTorqueParameters"
],
subs=["controlsState", "carState", "carControl", "sendcan", "carEvents", "carParams"],
ignore=["logMonoTime", "valid", "controlsState.startMonoTime", "controlsState.cumLagMs"],
config_callback=None,
init_callback=controlsd_fingerprint_callback,
should_recv_callback=controlsd_rcv_callback,
tolerance=NUMPY_TOLERANCE,
simulation=False,
drained_pub="can",
5 years ago
),
ProcessConfig(
proc_name="radard",
pubs=["can", "carState", "modelV2"],
subs=["radarState", "liveTracks"],
ignore=["logMonoTime", "valid", "radarState.cumLagMs"],
config_callback=None,
init_callback=get_car_params_callback,
5 years ago
should_recv_callback=radar_rcv_callback,
drained_pub="can",
5 years ago
),
ProcessConfig(
proc_name="plannerd",
pubs=["modelV2", "carControl", "carState", "controlsState", "radarState"],
subs=["lateralPlan", "longitudinalPlan", "uiPlan"],
ignore=["logMonoTime", "valid", "longitudinalPlan.processingDelay", "longitudinalPlan.solverExecutionTime", "lateralPlan.solverExecutionTime"],
config_callback=None,
init_callback=get_car_params_callback,
should_recv_callback=FrequencyBasedRcvCallback("modelV2"),
tolerance=NUMPY_TOLERANCE,
5 years ago
),
ProcessConfig(
proc_name="calibrationd",
pubs=["carState", "cameraOdometry", "carParams"],
subs=["liveCalibration"],
ignore=["logMonoTime", "valid"],
config_callback=None,
init_callback=None,
5 years ago
should_recv_callback=calibration_rcv_callback,
),
ProcessConfig(
proc_name="dmonitoringd",
pubs=["driverStateV2", "liveCalibration", "carState", "modelV2", "controlsState"],
subs=["driverMonitoringState"],
ignore=["logMonoTime", "valid"],
config_callback=None,
init_callback=None,
should_recv_callback=FrequencyBasedRcvCallback("driverStateV2"),
tolerance=NUMPY_TOLERANCE,
),
ProcessConfig(
proc_name="locationd",
pubs=[
"cameraOdometry", "accelerometer", "gyroscope", "gpsLocationExternal",
"liveCalibration", "carState", "carParams", "gpsLocation"
],
subs=["liveLocationKalman"],
ignore=["logMonoTime", "valid"],
config_callback=locationd_config_pubsub_callback,
init_callback=None,
should_recv_callback=None,
tolerance=NUMPY_TOLERANCE,
),
ProcessConfig(
proc_name="paramsd",
pubs=["liveLocationKalman", "carState"],
subs=["liveParameters"],
ignore=["logMonoTime", "valid"],
config_callback=None,
init_callback=get_car_params_callback,
should_recv_callback=FrequencyBasedRcvCallback("liveLocationKalman"),
tolerance=NUMPY_TOLERANCE,
),
ProcessConfig(
proc_name="ubloxd",
pubs=["ubloxRaw"],
subs=["ubloxGnss", "gpsLocationExternal"],
ignore=["logMonoTime"],
config_callback=None,
init_callback=None,
should_recv_callback=None,
),
ProcessConfig(
proc_name="laikad",
pubs=["ubloxGnss", "qcomGnss"],
subs=["gnssMeasurements"],
ignore=["logMonoTime"],
config_callback=laikad_config_pubsub_callback,
init_callback=None,
should_recv_callback=None,
tolerance=NUMPY_TOLERANCE,
timeout=60*10, # first messages are blocked on internet assistance
drained_pub="ubloxGnss", # config_callback will switch this to qcom if needed
),
Live torque (#25456) * wip torqued * add basic logic * setup in manager * check sanity and publish msg * add first order filter to outputs * wire up controlsd, and update gains * rename intercept to offset * add cloudlog, live values are not updated * fix bugs, do not reset points for now * fix crashes * rename to main * fix bugs, works offline * fix float in cereal bug * add latacc filter * randomly choose points, approx for iid * add variable decay * local param to capnp instead of dict * verify works in replay * use torqued output in controlsd * use in controlsd; use points from past routes * controlsd bugfix * filter before updating gains, needs to be replaced * save all points to ensure smooth transition across routes, revert friction factor to 1.5 * add filters to prevent noisy low-speed data points; improve fit sanity * add engaged buffer * revert lat_acc thresh * use paramsd realtime process config * make latacc-to-torque generic, and overrideable * move freq to 4Hz, avoid storing in np.array, don't publish points in the message * float instead of np * remove constant while storing pts * rename slope, offset to lat_accet_factor, offset * resolve issues * use camelcase in all capnp params * use camelcase everywhere * reduce latacc threshold or sanity, add car_sane todo, save points properly * add and check tag * write param to disk at end of route * remove args * rebase op, cereal * save on exit * restore default handler * cpu usage check * add to process replay * handle reset better, reduce unnecessary computation * always publish raw values - useful for debug * regen routes * update refs * checks on cache restore * check tuning vals too * clean that up * reduce cpu usage * reduce cpu usage by 75% * cleanup * optimize further * handle reset condition better, don't put points in init, use only in corolla * bump cereal after rebasing * update refs * Update common/params.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * remove unnecessary checks * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
ProcessConfig(
proc_name="torqued",
pubs=["liveLocationKalman", "carState", "carControl"],
subs=["liveTorqueParameters"],
Live torque (#25456) * wip torqued * add basic logic * setup in manager * check sanity and publish msg * add first order filter to outputs * wire up controlsd, and update gains * rename intercept to offset * add cloudlog, live values are not updated * fix bugs, do not reset points for now * fix crashes * rename to main * fix bugs, works offline * fix float in cereal bug * add latacc filter * randomly choose points, approx for iid * add variable decay * local param to capnp instead of dict * verify works in replay * use torqued output in controlsd * use in controlsd; use points from past routes * controlsd bugfix * filter before updating gains, needs to be replaced * save all points to ensure smooth transition across routes, revert friction factor to 1.5 * add filters to prevent noisy low-speed data points; improve fit sanity * add engaged buffer * revert lat_acc thresh * use paramsd realtime process config * make latacc-to-torque generic, and overrideable * move freq to 4Hz, avoid storing in np.array, don't publish points in the message * float instead of np * remove constant while storing pts * rename slope, offset to lat_accet_factor, offset * resolve issues * use camelcase in all capnp params * use camelcase everywhere * reduce latacc threshold or sanity, add car_sane todo, save points properly * add and check tag * write param to disk at end of route * remove args * rebase op, cereal * save on exit * restore default handler * cpu usage check * add to process replay * handle reset better, reduce unnecessary computation * always publish raw values - useful for debug * regen routes * update refs * checks on cache restore * check tuning vals too * clean that up * reduce cpu usage * reduce cpu usage by 75% * cleanup * optimize further * handle reset condition better, don't put points in init, use only in corolla * bump cereal after rebasing * update refs * Update common/params.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * remove unnecessary checks * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
ignore=["logMonoTime"],
config_callback=None,
init_callback=get_car_params_callback,
Live torque (#25456) * wip torqued * add basic logic * setup in manager * check sanity and publish msg * add first order filter to outputs * wire up controlsd, and update gains * rename intercept to offset * add cloudlog, live values are not updated * fix bugs, do not reset points for now * fix crashes * rename to main * fix bugs, works offline * fix float in cereal bug * add latacc filter * randomly choose points, approx for iid * add variable decay * local param to capnp instead of dict * verify works in replay * use torqued output in controlsd * use in controlsd; use points from past routes * controlsd bugfix * filter before updating gains, needs to be replaced * save all points to ensure smooth transition across routes, revert friction factor to 1.5 * add filters to prevent noisy low-speed data points; improve fit sanity * add engaged buffer * revert lat_acc thresh * use paramsd realtime process config * make latacc-to-torque generic, and overrideable * move freq to 4Hz, avoid storing in np.array, don't publish points in the message * float instead of np * remove constant while storing pts * rename slope, offset to lat_accet_factor, offset * resolve issues * use camelcase in all capnp params * use camelcase everywhere * reduce latacc threshold or sanity, add car_sane todo, save points properly * add and check tag * write param to disk at end of route * remove args * rebase op, cereal * save on exit * restore default handler * cpu usage check * add to process replay * handle reset better, reduce unnecessary computation * always publish raw values - useful for debug * regen routes * update refs * checks on cache restore * check tuning vals too * clean that up * reduce cpu usage * reduce cpu usage by 75% * cleanup * optimize further * handle reset condition better, don't put points in init, use only in corolla * bump cereal after rebasing * update refs * Update common/params.cc Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * remove unnecessary checks * Update RELEASES.md Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
3 years ago
should_recv_callback=torqued_rcv_callback,
tolerance=NUMPY_TOLERANCE,
),
5 years ago
]
def get_process_config(name):
try:
return next(c for c in CONFIGS if c.proc_name == name)
except StopIteration as ex:
raise Exception(f"Cannot find process config with name: {name}") from ex
def replay_process_with_name(name, lr, *args, **kwargs):
cfg = get_process_config(name)
return replay_process(cfg, lr, *args, **kwargs)
def replay_process(cfg, lr, fingerprint=None, return_all_logs=False):
all_msgs = list(lr)
process_logs = _replay_single_process(cfg, all_msgs, fingerprint)
if return_all_logs:
keys = set(cfg.subs)
modified_logs = [m for m in all_msgs if m.which() not in keys]
modified_logs.extend(process_logs)
modified_logs.sort(key=lambda m: m.logMonoTime)
log_msgs = modified_logs
else:
log_msgs = process_logs
return log_msgs
def _replay_single_process(cfg, lr, fingerprint):
with OpenpilotPrefix():
controlsState = None
initialized = False
if cfg.proc_name == "controlsd":
for msg in lr:
if msg.which() == "controlsState":
controlsState = msg.controlsState
if initialized:
break
elif msg.which() == "carEvents":
initialized = car.CarEvent.EventName.controlsInitializing not in [e.name for e in msg.carEvents]
assert controlsState is not None and initialized, "controlsState never initialized"
if fingerprint is not None:
setup_env(cfg=cfg, controlsState=controlsState, lr=lr, fingerprint=fingerprint)
process replay: support running in parallel (#24534) * prefix params * set env * prefix in manager * filesystem except * dont delete manager folder * Update selfdrive/common/params.h Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * debug same path * remove cleanup + same default * dont use filesystem lib * param symlink path * prefix helpers * path * dont delete d * parallel loop * refactor loop * msgq * clean msgs * spelling * nestable pool * spelling * logreaders in parallel * bugfix * assert msgq * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Shane Smiskol <shane@smiskol.com> * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Shane Smiskol <shane@smiskol.com> * assert in cereal * folder exists * create dirs in test * bump cereal * Update selfdrive/test/process_replay/process_replay.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * PR feedback * params path in basedir * ref commit * param path * bugfix * upload_only * param path * Update selfdrive/test/process_replay/process_replay.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * msgq path name * python concurrency.features * progress bar * remove progress bar from compare logs * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * defaultdict * context manager * update refs * dont get logs if upload only * upload refs in parallel * cleanup * Update selfdrive/test/process_replay/test_processes.py Co-authored-by: Shane Smiskol <shane@smiskol.com> * cleanup * text Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Shane Smiskol <shane@smiskol.com>
3 years ago
else:
CP = next((m.carParams for m in lr if m.which() == "carParams"), None)
assert CP is not None or "carParams" not in cfg.pubs, "carParams are missing and process needs it"
setup_env(CP=CP, cfg=cfg, controlsState=controlsState, lr=lr)
if cfg.config_callback is not None:
params = Params()
cfg.pubs, cfg.drained_pub = cfg.config_callback(params, cfg)
all_msgs = sorted(lr, key=lambda msg: msg.logMonoTime)
pub_msgs = [msg for msg in all_msgs if msg.which() in set(cfg.pubs)]
with ReplayContext(cfg) as rc:
pm = messaging.PubMaster(cfg.pubs)
sockets = {s: messaging.sub_sock(s, timeout=100) for s in cfg.subs}
managed_processes[cfg.proc_name].prepare()
managed_processes[cfg.proc_name].start()
if cfg.init_callback is not None:
cfg.init_callback(rc, pm, all_msgs, fingerprint)
log_msgs, msg_queue = [], []
try:
# Wait for process to startup
with Timeout(10, error_msg=f"timed out waiting for process to start: {repr(cfg.proc_name)}"):
while not all(pm.all_readers_updated(s) for s in cfg.pubs):
time.sleep(0)
# Do the replay
cnt = 0
for msg in pub_msgs:
with Timeout(cfg.timeout, error_msg=f"timed out testing process {repr(cfg.proc_name)}, {cnt}/{len(pub_msgs)} msgs done"):
resp_sockets, end_of_cycle = cfg.subs, True
if cfg.should_recv_callback is not None:
end_of_cycle = cfg.should_recv_callback(msg, cfg, cnt)
msg_queue.append(msg)
if end_of_cycle:
rc.wait_for_recv_called()
# call recv to let sub-sockets reconnect, after we know the process is ready
if cnt == 0:
for s in sockets.values():
messaging.recv_one_or_none(s)
# empty recv on drained pub indicates the end of messages, only do that if there're any
trigger_empty_recv = False
if cfg.drained_pub:
trigger_empty_recv = next((True for m in msg_queue if m.which() == cfg.drained_pub), False)
for m in msg_queue:
pm.send(m.which(), m.as_builder())
msg_queue = []
rc.unlock_sockets()
rc.wait_for_next_recv(trigger_empty_recv)
for s in resp_sockets:
ms = messaging.drain_sock(sockets[s])
for m in ms:
m = m.as_builder()
m.logMonoTime = msg.logMonoTime
log_msgs.append(m.as_reader())
cnt += 1
assert(managed_processes[cfg.proc_name].proc.is_alive())
finally:
managed_processes[cfg.proc_name].signal(signal.SIGKILL)
managed_processes[cfg.proc_name].stop()
return log_msgs
def setup_env(CP=None, cfg=None, controlsState=None, lr=None, fingerprint=None, log_dir=None):
if platform.system() != "Darwin":
os.environ["PARAMS_ROOT"] = "/dev/shm/params"
if log_dir is not None:
os.environ["LOG_ROOT"] = log_dir
params = Params()
params.clear_all()
params.put_bool("OpenpilotEnabledToggle", True)
params.put_bool("Passive", False)
Add Disengage on Accelerator Toggle (#23977) * Squashed commit of the following: commit 953bcf0ecf8d03f0fec9ce0d5442cc660ae2347d Merge: b4198608d 333257bad Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:58:06 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit b4198608dac9595bfeb9443f95cd6c5d385cd62d Merge: 24f90b2c8 0b9790dd2 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 14:32:54 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 24f90b2c8d6ae509c0776b6e33b743467aa08dee Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 14:07:52 2022 -0700 revert changes and get ready for override commit aa514df6b5e8431f0faa07f6b25eb5cb6c9f2749 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 20:52:24 2022 -0700 temporary commit c874e10c2555968c683f629c4582ab22e51d431f Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 00:30:13 2022 -0700 move gasPressed to controlsd commit fe670439dff5bc6dfc5963d79ca2febe0c5920c7 Merge: 49d3b6d11 81862fce7 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 00:15:48 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 49d3b6d1162893fa94b2294152f0718eeb4698ed Merge: 475b27e74 d60c44e03 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 13:06:08 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 475b27e74fd6479f1d148e9ded1eca6ee476865c Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 20:24:59 2022 -0700 update SAFETY.md commit 0798eadb82749e12ecbaa86f4e57b21bd3dbc7e8 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 17:52:06 2022 -0700 ⛽ ➡️ 🔋 bump commit d2b64b89cf8d7265bc90848b4e3a2276c9a4cb78 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 16:19:34 2022 -0700 these changes will be in border PR these changes will be border PR commit bed31e63de2244c161729773978fef8a9246ddb5 Merge: 491417640 e91613bc6 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 16:17:31 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 49141764098e3a701ff123ead52de4656b31db4d Merge: 9291e9f00 c88ced1f1 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 19:00:26 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 9291e9f0045780669b2ffa7f08fb10373c03b070 Merge: 2aed64157 99c02bdd2 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Mar 18 19:03:13 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 2aed64157d6e9dc993d103a2c6abf7e643410562 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Mar 18 19:03:03 2022 -0700 Revert "send pre-enable state when gas is pressed" This reverts commit 8d82e697dc2efade307413e767d14b56b4d2d079. commit a219defe5342efa731a957b2ff4fd86292c1f239 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 17 12:50:46 2022 -0700 bump cereal commit 8d82e697dc2efade307413e767d14b56b4d2d079 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 16 22:40:13 2022 -0700 send pre-enable state when gas is pressed formatting and it's out forgot one allow gas press show toggle revert changes revert changes commit 5eb4d1ab1b77ac65bdd901f692ebfb848d5187ca Merge: bad1bdc74 db7b49c71 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 16 22:29:43 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit bad1bdc7428c5d8a4a765b259da504f0ade84424 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 15 23:03:56 2022 -0700 clean up a bit commit 7516ed9b786536a07f00a92b9c1742ca252a01d1 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 15 22:55:09 2022 -0700 these are null checks right now commit 408f5f1d633521b29b08d966c9b387fa79dff0d6 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 15 22:51:14 2022 -0700 should work commit be1978e29c03d8843cf073cc9ddf84020fd2b378 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 15 22:36:16 2022 -0700 stash commit f0bd4c47e9d27061c6cd3b88765a7c10995f42db Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 15 22:26:24 2022 -0700 this was flipped commit d5b6e30389a727e8559331acd706422e1b246f60 Merge: 820b19894 5fe00fb77 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 15 22:25:49 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 820b1989496225df1f66f39b477f1e9402db1b19 Merge: 91763f9ff d7c758d4b Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 14 23:39:34 2022 -0700 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 91763f9ff4321986babce1a7b1272fcf64c8f753 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Feb 24 20:15:26 2022 -0800 add icon from jozef 🔥 commit 1885c9e2bacd9351c7e421b1436dcbfbde238436 Merge: 1f591736a 9c70e8bca Author: Shane Smiskol <shane@smiskol.com> Date: Thu Feb 24 20:08:07 2022 -0800 Merge remote-tracking branch 'upstream/master' into disengage-on-gas commit 1f591736a2767b1ed892c29ec5000cc7348f01c7 Merge: 465811f0b 7410160d0 Author: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> Date: Sat Feb 12 10:24:29 2022 -0500 Merge branch 'master' into disengage-on-gas commit 465811f0b4776e43a289398e4d4369362b7da58c Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Feb 11 11:20:32 2022 -0500 Add param to process replay commit 0344363a533505435cff87eb33356b2364a4156f Merge: 700efcb3f 3e915cf62 Author: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> Date: Fri Feb 11 11:07:31 2022 -0500 Merge branch 'master' into disengage-on-gas commit 700efcb3f444092f99ef10e9908f83402429d742 Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Feb 11 11:04:39 2022 -0500 Add param to unsafeMode commit 220ce272fee1f7f5ace2a04052605a6e4f95712b Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Feb 11 10:54:16 2022 -0500 Add param to unsafeMode commit d273bb78acbc23ee5255e461fa71b2f0400a5e03 Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Feb 11 10:52:22 2022 -0500 Resolve conflicts commit 1a85afd60c2f0d3140dfa8e7cd574d6b88abd5e3 Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Feb 11 10:51:50 2022 -0500 Resolve conflicts commit e3be32afc2bb2423d29e2b4f85b3cff3fe72aab9 Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Feb 11 10:51:08 2022 -0500 Resolve conflicts commit f27203af3afe612173bf9a63e15c57118598b5b8 Author: Jason Wen <haibin.wen3@gmail.com> Date: Wed Jan 19 00:30:09 2022 -0500 Add param to process replay commit 04c0ad1a54f4fea5efe74b3203d9bdbd693b64a6 Author: Jason Wen <47793918+sunnyhaibin@users.noreply.github.com> Date: Wed Jan 19 00:28:49 2022 -0500 Update interfaces.py Co-authored-by: Willem Melching <willem.melching@gmail.com> commit 99cf13caeb4d9f2c95c25e1e78b6e353ea508cb6 Author: Jason Wen <haibin.wen3@gmail.com> Date: Sat Jan 15 00:03:38 2022 -0500 Fix missing params lib commit 2230254ca709625d591b0c73d1a6022c450f6ef6 Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Jan 14 23:38:46 2022 -0500 Disengage on gas toggle commit 87475e02cb63cc39c9b16edc67f303e02d17e6ef Author: Jason Wen <haibin.wen3@gmail.com> Date: Fri Jan 14 23:24:00 2022 -0500 Disengage on gas toggle * bump * use ALTERNATIVE_EXPERIENCE * or it * de-bump * update refs * update refs! * you can just ctrl+click ALTERNATIVE_EXPERIENCE! * already have a params * update text
3 years ago
params.put_bool("DisengageOnAccelerator", True)
params.put_bool("WideCameraOnly", False)
params.put_bool("DisableLogging", False)
os.environ["NO_RADAR_SLEEP"] = "1"
os.environ["REPLAY"] = "1"
if fingerprint is not None:
os.environ['SKIP_FW_QUERY'] = "1"
os.environ['FINGERPRINT'] = fingerprint
else:
os.environ["SKIP_FW_QUERY"] = ""
os.environ["FINGERPRINT"] = ""
if lr is not None:
services = {m.which() for m in lr}
params.put_bool("UbloxAvailable", "ubloxGnss" in services)
if cfg is not None:
# Clear all custom processConfig environment variables
for config in CONFIGS:
for k, _ in config.environ.items():
if k in os.environ:
del os.environ[k]
os.environ.update(cfg.environ)
os.environ['PROC_NAME'] = cfg.proc_name
if cfg is not None and cfg.simulation:
os.environ["SIMULATION"] = "1"
elif "SIMULATION" in os.environ:
del os.environ["SIMULATION"]
# Initialize controlsd with a controlsState packet
if controlsState is not None:
params.put("ReplayControlsState", controlsState.as_builder().to_bytes())
else:
params.remove("ReplayControlsState")
# Regen or python process
if CP is not None:
if CP.alternativeExperience == ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS:
params.put_bool("DisengageOnAccelerator", False)
if fingerprint is None:
if CP.fingerprintSource == "fw":
params.put("CarParamsCache", CP.as_builder().to_bytes())
os.environ['SKIP_FW_QUERY'] = ""
os.environ['FINGERPRINT'] = ""
else:
os.environ['SKIP_FW_QUERY'] = "1"
os.environ['FINGERPRINT'] = CP.carFingerprint
if CP.openpilotLongitudinalControl:
params.put_bool("ExperimentalLongitudinalEnabled", True)
def check_openpilot_enabled(msgs):
cur_enabled_count = 0
max_enabled_count = 0
for msg in msgs:
if msg.which() == "carParams":
if msg.carParams.notCar:
return True
elif msg.which() == "controlsState":
if msg.controlsState.active:
cur_enabled_count += 1
else:
cur_enabled_count = 0
max_enabled_count = max(max_enabled_count, cur_enabled_count)
return max_enabled_count > int(10. / DT_CTRL)