Skip to content

Commit

Permalink
Merge branch 'master' into PA-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Edison-CBS committed May 13, 2024
2 parents 7e0d8c8 + 7f9ad78 commit aac1038
Show file tree
Hide file tree
Showing 14 changed files with 338 additions and 246 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/stale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
workflow_dispatch:

env:
DAYS_BEFORE_PR_CLOSE: 7
DAYS_BEFORE_PR_STALE: 30
DAYS_BEFORE_PR_CLOSE: 3
DAYS_BEFORE_PR_STALE: 14

jobs:
stale:
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ repos:
- -L bu,ro,te,ue,alo,hda,ois,nam,nams,ned,som,parm,setts,inout,warmup,bumb,nd,sie,preints
- --builtins clear,rare,informal,usage,code,names,en-GB_to_en-US
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
rev: v0.4.4
hooks:
- id: ruff
exclude: '^(third_party/)|(cereal/)|(panda/)|(rednose/)|(rednose_repo/)|(tinygrad/)|(tinygrad_repo/)|(teleoprtc/)|(teleoprtc_repo/)'
Expand Down Expand Up @@ -98,6 +98,6 @@ repos:
args:
- --lock
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.2
rev: 0.28.3
hooks:
- id: check-github-workflows
2 changes: 1 addition & 1 deletion cereal
Submodule cereal updated 1 files
+2 −14 messaging/__init__.py
2 changes: 1 addition & 1 deletion opendbc
2 changes: 1 addition & 1 deletion panda
433 changes: 209 additions & 224 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True, allow_
events.add(EventName.accFaulted)
if cs_out.steeringPressed:
events.add(EventName.steerOverride)
if cs_out.brakePressed and cs_out.standstill:
events.add(EventName.preEnableStandstill)
if cs_out.gasPressed:
events.add(EventName.gasPressedOverride)

# Handle button presses
for b in cs_out.buttonEvents:
Expand Down
2 changes: 2 additions & 0 deletions selfdrive/car/toyota/fingerprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,7 @@
CAR.TOYOTA_RAV4_TSS2_2023: {
(Ecu.abs, 0x7b0, None): [
b'\x01F15260R450\x00\x00\x00\x00\x00\x00',
b'\x01F15260R50000\x00\x00\x00\x00',
b'\x01F15260R51000\x00\x00\x00\x00',
b'\x01F15264283200\x00\x00\x00\x00',
b'\x01F15264283300\x00\x00\x00\x00',
Expand All @@ -1162,6 +1163,7 @@
b'\x01896634AJ2000\x00\x00\x00\x00',
b'\x01896634AL5000\x00\x00\x00\x00',
b'\x01896634AL6000\x00\x00\x00\x00',
b'\x01896634AL8000\x00\x00\x00\x00',
],
(Ecu.fwdRadar, 0x750, 0xf): [
b'\x018821F0R03100\x00\x00\x00\x00',
Expand Down
6 changes: 0 additions & 6 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ def update_events(self, CS):
(CS.regenBraking and (not self.CS_prev.regenBraking or not CS.standstill)):
self.events.add(EventName.pedalPressed)

if CS.brakePressed and CS.standstill:
self.events.add(EventName.preEnableStandstill)

if CS.gasPressed:
self.events.add(EventName.gasPressedOverride)

if not self.CP.notCar:
self.events.add_from_msg(self.sm['driverMonitoringState'].events)

Expand Down
13 changes: 7 additions & 6 deletions selfdrive/controls/lib/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from enum import IntEnum
from collections.abc import Callable
from sortedcontainers import SortedList

from cereal import log, car
import cereal.messaging as messaging
Expand Down Expand Up @@ -48,21 +49,21 @@ class ET:

class Events:
def __init__(self):
self.events: list[int] = []
self.static_events: list[int] = []
self.events: SortedList[int] = SortedList()
self.static_events: SortedList[int] = SortedList()
self.events_prev = dict.fromkeys(EVENTS.keys(), 0)

@property
def names(self) -> list[int]:
def names(self) -> SortedList[int]:
return self.events

def __len__(self) -> int:
return len(self.events)

def add(self, event_name: int, static: bool=False) -> None:
if static:
self.static_events.append(event_name)
self.events.append(event_name)
self.static_events.add(event_name)
self.events.add(event_name)

def clear(self) -> None:
self.events_prev = {k: (v + 1 if k in self.events else 0) for k, v in self.events_prev.items()}
Expand Down Expand Up @@ -92,7 +93,7 @@ def create_alerts(self, event_types: list[str], callback_args=None):

def add_from_msg(self, events):
for e in events:
self.events.append(e.name.raw)
self.events.add(e.name.raw)

def to_msg(self):
ret = []
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/test/process_replay/ref_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
685a2bb9aacdd790e26d14aa49d3792c3ed65125
ef0c8cb36b9cda6381412493555c21a87360e539
4 changes: 3 additions & 1 deletion selfdrive/ui/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ static void update_state(UIState *s) {
auto cam_state = sm["wideRoadCameraState"].getWideRoadCameraState();
float scale = (cam_state.getSensor() == cereal::FrameData::ImageSensor::AR0231) ? 6.0f : 1.0f;
scene.light_sensor = std::max(100.0f - scale * cam_state.getExposureValPercent(), 0.0f);
} else if (!sm.allAliveAndValid({"wideRoadCameraState"})) {
scene.light_sensor = -1;
}
scene.started = sm["deviceState"].getDeviceState().getStarted() && scene.ignition;

Expand Down Expand Up @@ -320,7 +322,7 @@ void Device::resetInteractiveTimeout(int timeout) {

void Device::updateBrightness(const UIState &s) {
float clipped_brightness = offroad_brightness;
if (s.scene.started) {
if (s.scene.started && s.scene.light_sensor > 0) {
clipped_brightness = s.scene.light_sensor;

// CIE 1931 - https://www.photonstophotos.net/GeneralTopics/Exposure/Psychometric_Lightness_and_Gamma.htm
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ typedef struct UIScene {

cereal::LongitudinalPersonality personality;

float light_sensor;
float light_sensor = -1;
bool started, ignition, is_metric, map_on_left, longitudinal_control;
bool world_objects_visible = false;
uint64_t started_frame;
Expand Down
104 changes: 104 additions & 0 deletions tools/rerun/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env python3
import subprocess
import sys
import argparse
import multiprocessing
from functools import partial

from openpilot.tools.lib.logreader import LogReader
from cereal.services import SERVICE_LIST


NUM_CPUS = multiprocessing.cpu_count()
DEMO_ROUTE = "a2a0ccea32023010|2023-07-27--13-01-19"
WHEEL_URL = "https://build.rerun.io/commit/660463d/wheels"


def install():
# currently requires a preview release build
subprocess.run([sys.executable, "-m", "pip", "install", "--pre", "-f", WHEEL_URL, "--upgrade", "rerun-sdk"], check=True)
print("Rerun installed")


def log_msg(msg, parent_key=''):
stack = [(msg, parent_key)]
while stack:
current_msg, current_parent_key = stack.pop()
if isinstance(current_msg, list):
for index, item in enumerate(current_msg):
new_key = f"{current_parent_key}/{index}"
if isinstance(item, (int, float)):
rr.log(str(new_key), rr.Scalar(item))
elif isinstance(item, dict):
stack.append((item, new_key))
elif isinstance(current_msg, dict):
for key, value in current_msg.items():
new_key = f"{current_parent_key}/{key}"
if isinstance(value, (int, float)):
rr.log(str(new_key), rr.Scalar(value))
elif isinstance(value, dict):
stack.append((value, new_key))
elif isinstance(value, list):
for index, item in enumerate(value):
if isinstance(item, (int, float)):
rr.log(f"{new_key}/{index}", rr.Scalar(item))
else:
pass # Not a plottable value


def createBlueprint():
timeSeriesViews = []
for topic in sorted(SERVICE_LIST.keys()):
timeSeriesViews.append(rrb.TimeSeriesView(name=topic, origin=f"/{topic}/", visible=False))
rr.log(topic, rr.SeriesLine(name=topic), timeless=True)
blueprint = rrb.Blueprint(rrb.Grid(rrb.Vertical(*timeSeriesViews,rrb.SelectionPanel(expanded=False),rrb.TimePanel(expanded=False)),
rrb.Spatial2DView(name="thumbnail", origin="/thumbnail")))
return blueprint


def log_thumbnail(thumbnailMsg):
bytesImgData = thumbnailMsg.get('thumbnail')
rr.log("/thumbnail", rr.ImageEncoded(contents=bytesImgData))


def process(blueprint, lr):
ret = []
rr.init("rerun_test", spawn=True, default_blueprint=blueprint)
for msg in lr:
ret.append(msg)
rr.set_time_nanos("TIMELINE", msg.logMonoTime)
if msg.which() != "thumbnail":
log_msg(msg.to_dict()[msg.which()], msg.which())
else:
log_thumbnail(msg.to_dict()[msg.which()])
return ret


if __name__ == '__main__':
parser = argparse.ArgumentParser(description="A helper to run rerun on openpilot routes",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--demo", action="store_true", help="Use the demo route instead of providing one")
parser.add_argument("--install", action="store_true", help="Install or update rerun")
parser.add_argument("route_or_segment_name", nargs='?', help="The route or segment name to plot")

if len(sys.argv) == 1:
parser.print_help()
sys.exit()

args = parser.parse_args()
if args.install:
install()
sys.exit()

try:
import rerun as rr
import rerun.blueprint as rrb
except ImportError:
print("Rerun is not installed, run with --install first")
sys.exit()

route_or_segment_name = DEMO_ROUTE if args.demo else args.route_or_segment_name.strip()
blueprint = createBlueprint()
print("Getting route log paths")
lr = LogReader(route_or_segment_name)
lr.run_across_segments(NUM_CPUS, partial(process, blueprint))

0 comments on commit aac1038

Please sign in to comment.