Skip to content

Commit

Permalink
Merge branch 'master' into PA-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Edison-CBS committed Aug 7, 2024
2 parents 5a2d1ad + ba7a60c commit e4d351f
Show file tree
Hide file tree
Showing 104 changed files with 1,684 additions and 1,528 deletions.
43 changes: 34 additions & 9 deletions .importlinter
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ type = forbidden
source_modules =
openpilot.selfdrive.car
forbidden_modules =
openpilot.common
openpilot.selfdrive.controls
openpilot.selfdrive.debug
openpilot.selfdrive.pandad
openpilot.selfdrive.test
openpilot.system
openpilot.body
openpilot.tools
openpilot.docs
openpilot.msgq
openpilot.panda
Expand All @@ -18,24 +24,43 @@ forbidden_modules =
openpilot.teleoprtc
openpilot.tinygrad
ignore_imports =
# remove these
openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.controls.lib.events
openpilot.selfdrive.car.body.carcontroller -> openpilot.selfdrive.controls.lib.pid
openpilot.selfdrive.car.tests.test_docs -> openpilot.common.basedir
openpilot.selfdrive.car.docs -> openpilot.common.basedir
# car interface will not filter the speed
openpilot.selfdrive.car.interfaces -> openpilot.common.simple_kalman
openpilot.selfdrive.car.gm.interface -> openpilot.common.basedir
openpilot.selfdrive.car.interfaces -> openpilot.common.basedir
# these two will still live in openpilot, but require some modification
openpilot.selfdrive.car.fw_versions -> openpilot.common.params
openpilot.selfdrive.car.ecu_addrs -> openpilot.common.params
# requires generic CAN send/receive functions
openpilot.selfdrive.car.ecu_addrs -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.isotp_parallel_query -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.tests.test_fw_fingerprint -> openpilot.selfdrive.pandad

# these are okay
openpilot.selfdrive.car.card -> openpilot.common.swaglog
openpilot.selfdrive.car.card -> openpilot.common.realtime
openpilot.selfdrive.car.card -> openpilot.selfdrive.controls.lib.events
openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.controls.lib.events
openpilot.selfdrive.car.tests.test_models -> openpilot.tools.lib.logreader
openpilot.selfdrive.car.tests.test_models -> openpilot.selfdrive.car.card
openpilot.selfdrive.car.tests.test_models -> openpilot.tools.lib.route
openpilot.selfdrive.car.tests.test_models -> openpilot.system.hardware.hw
openpilot.selfdrive.car.tests.test_models -> openpilot.selfdrive.test.helpers
openpilot.selfdrive.car.isotp_parallel_query -> openpilot.common.swaglog
openpilot.selfdrive.car.fw_versions -> openpilot.common.swaglog
openpilot.selfdrive.car.disable_ecu -> openpilot.common.swaglog
openpilot.selfdrive.car.vin -> openpilot.common.swaglog
openpilot.selfdrive.car.ecu_addrs -> openpilot.common.swaglog
openpilot.selfdrive.car.car_helpers -> openpilot.common.swaglog
openpilot.selfdrive.car.car_helpers -> openpilot.system.version
openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.controls.lib.drive_helpers
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_angle
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.longcontrol
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_torque
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_pid
openpilot.selfdrive.car.card -> openpilot.common.params
openpilot.selfdrive.car.tests.test_models -> openpilot.common.params
openpilot.selfdrive.car.tests.test_models -> openpilot.common.basedir
openpilot.selfdrive.car.card -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.tests.test_docs -> openpilot.selfdrive.debug.dump_car_docs
openpilot.selfdrive.car.tests.test_docs -> openpilot.selfdrive.debug.print_docs_diff
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.tests.test_models -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.test.fuzzy_generation
unmatched_ignore_imports_alerting = warn
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ openpilot is developed by [comma](https://comma.ai/) and by users like you. We w
* Code documentation lives at https://docs.comma.ai
* Information about running openpilot lives on the [community wiki](https://github.com/commaai/openpilot/wiki)

Want to get paid to work on openpilot? [comma is hiring](https://comma.ai/jobs#open-positions) and offers lots of [bounties](docs/BOUNTIES.md) for external contributors.
Want to get paid to work on openpilot? [comma is hiring](https://comma.ai/jobs#open-positions) and offers lots of [bounties](https://comma.ai/bounties) for external contributors.

Safety and Testing
----
Expand Down
1 change: 0 additions & 1 deletion common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ std::unordered_map<std::string, uint32_t> keys = {
{"CarParamsCache", CLEAR_ON_MANAGER_START},
{"CarParamsPersistent", PERSISTENT},
{"CarParamsPrevRoute", PERSISTENT},
{"CarVin", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION},
{"CompletedTrainingVersion", PERSISTENT},
{"ControlsReady", CLEAR_ON_MANAGER_START | CLEAR_ON_ONROAD_TRANSITION},
{"CurrentBootlog", PERSISTENT},
Expand Down
6 changes: 3 additions & 3 deletions common/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from collections import deque

from openpilot.common.threadname import getthreadname
from setproctitle import getproctitle

from openpilot.system.hardware import PC

Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, rate: float, print_delay_threshold: float | None = 0.0) -> No
self._print_delay_threshold = print_delay_threshold
self._frame = 0
self._remaining = 0.0
self._thread_name = getthreadname()
self._process_name = getproctitle()
self._dts = deque([self._interval], maxlen=100)
self._last_monitor_time = time.monotonic()

Expand Down Expand Up @@ -87,7 +87,7 @@ def monitor_time(self) -> bool:
remaining = self._next_frame_time - time.monotonic()
self._next_frame_time += self._interval
if self._print_delay_threshold is not None and remaining < -self._print_delay_threshold:
print(f"{self._thread_name} lagging by {-remaining * 1000:.2f} ms")
print(f"{self._process_name} lagging by {-remaining * 1000:.2f} ms")
lagged = True
self._frame += 1
self._remaining = remaining
Expand Down
9 changes: 9 additions & 0 deletions common/swaglog.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ def emit(self, record):
pass


class ForwardingHandler(logging.Handler):
def __init__(self, target_logger):
super().__init__()
self.target_logger = target_logger

def emit(self, record):
self.target_logger.handle(record)


def add_file_handler(log):
"""
Function to add the file log handler to swaglog.
Expand Down
8 changes: 0 additions & 8 deletions common/tests/test_threadname.py

This file was deleted.

19 changes: 0 additions & 19 deletions common/threadname.py

This file was deleted.

11 changes: 0 additions & 11 deletions common/utils.py

This file was deleted.

62 changes: 0 additions & 62 deletions docs/BOUNTIES.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/contributing/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ This is the roadmap for the next major openpilot releases. Also check out
* [Milestones](https://github.com/commaai/openpilot/milestones) for minor releases
* [Projects](https://github.com/commaai/openpilot/projects?query=is%3Aopen) for shorter-term projects not tied to releases
* [Bounties](https://comma.ai/bounties) for paid individual issues
* [#current-projects](https://discord.com/channels/469524606043160576/1249579909739708446) in Discord for discussion on work-in-progress projects

## openpilot 0.10

Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/turn-the-speed-blue.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ And if you have a comma 3/3X, we'll deploy the change to your device for testing

Run this to clone openpilot and install all the dependencies:
```bash
curl -fsSL openpilot.comma.ai | bash
bash <(curl -fsSL openpilot.comma.ai)
```

Navigate to openpilot folder & activate a Python virtual environment
Expand Down
2 changes: 1 addition & 1 deletion msgq_repo
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies = [
"pycapnp",
"Cython",
"setuptools",
"numpy",
"numpy < 2.0.0",

# body / webrtcd
"aiohttp",
Expand All @@ -52,13 +52,13 @@ dependencies = [
"websocket_client",

# acados deps
"casadi @ https://github.com/commaai/casadi/releases/download/nightly-release-3.6.6/casadi-3.6.6-cp312-none-manylinux2014_aarch64.whl ; (python_version == '3.12' and platform_machine == 'aarch64')", # TODO: Go back to pypi casadi when they fix aarch64 for python312
"casadi; platform_machine != 'aarch64' or python_version != '3.12'",
"casadi >=3.6.6", # 3.12 fixed in 3.6.6
"future-fstrings",

# these should be removed
"psutil",
"pycryptodome", # used in updated/casync, panda, body, and a test
"setproctitle",

# logreader
"zstandard",
Expand Down Expand Up @@ -165,11 +165,11 @@ testpaths = [
]

[tool.codespell]
count = true
quiet-level = 3
# if you've got a short variable name that's getting flagged, add it here
ignore-words-list = "bu,ro,te,ue,alo,hda,ois,nam,nams,ned,som,parm,setts,inout,warmup,bumb,nd,sie,preints,whit,indexIn"
builtin = "clear,rare,informal,usage,code,names,en-GB_to_en-US"
ignore-words-list = "bu,ro,te,ue,alo,hda,ois,nam,nams,ned,som,parm,setts,inout,warmup,bumb,nd,sie,preints,whit,indexIn,ws,uint,grey,deque,stdio,amin,BA,LITE,atEnd,UIs,errorString,arange,FocusIn,od,tim,relA,hist,copyable"
builtin = "clear,rare,informal,code,names,en-GB_to_en-US"
skip = "./third_party/*, ./tinygrad/*, ./tinygrad_repo/*, ./msgq/*, ./panda/*, ./opendbc/*, ./opendbc_repo/*, ./rednose/*, ./rednose_repo/*, ./teleoprtc/*, ./teleoprtc_repo/*, ./selfdrive/ui/translations/*.ts, uv.lock, *.onnx, ./cereal/gen/*, */c_generated_code/*"

[tool.mypy]
python_version = "3.11"
Expand Down
1 change: 1 addition & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ cd $DIR/../
# https://github.com/commaai/openpilot/blob/4b11c9e914707df9def598616995be2a5d355a6a/.pre-commit-config.yaml#L2

ruff check .
lint-imports
4 changes: 2 additions & 2 deletions scripts/waste.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import numpy as np
from multiprocessing import Process
from openpilot.common.threadname import setthreadname
from setproctitle import setproctitle

def waste(core):
os.sched_setaffinity(0, [core,])
Expand All @@ -16,7 +16,7 @@ def waste(core):
j = 0
while 1:
if (i % 100) == 0:
setthreadname("%3d: %8d" % (core, i))
setproctitle("%3d: %8d" % (core, i))
lt = time.monotonic()
print("%3d: %8d %f %.2f" % (core, i, lt-st, j))
st = lt
Expand Down
22 changes: 20 additions & 2 deletions selfdrive/car/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# functions common among cars
import logging
from collections import namedtuple
from dataclasses import dataclass
from enum import IntFlag, ReprEnum, EnumType
Expand All @@ -8,9 +9,13 @@

from cereal import car
from panda.python.uds import SERVICE_TYPE
from openpilot.common.numpy_fast import clip, interp
from openpilot.common.utils import Freezable
from openpilot.selfdrive.car.docs_definitions import CarDocs
from openpilot.selfdrive.car.helpers import clip, interp

# set up logging
carlog = logging.getLogger('carlog')
carlog.setLevel(logging.INFO)
carlog.propagate = False

DT_CTRL = 0.01 # car state and control loop timestep (s)

Expand Down Expand Up @@ -257,6 +262,19 @@ def override(self, **kwargs):
return replace(self, **kwargs)


class Freezable:
_frozen: bool = False

def freeze(self):
if not self._frozen:
self._frozen = True

def __setattr__(self, *args, **kwargs):
if self._frozen:
raise Exception("cannot modify frozen object")
super().__setattr__(*args, **kwargs)


@dataclass(order=True)
class PlatformConfig(Freezable):
car_docs: list[CarDocs]
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/body/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


class CarController(CarControllerBase):
def __init__(self, dbc_name, CP, VM):
super().__init__(dbc_name, CP, VM)
def __init__(self, dbc_name, CP):
super().__init__(dbc_name, CP)
self.packer = CANPacker(dbc_name)

# PIDs
Expand Down
Loading

0 comments on commit e4d351f

Please sign in to comment.