Skip to content

Commit

Permalink
Merge branch 'commaai:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasloetkolben authored Aug 19, 2024
2 parents 2fe6b40 + 8866aa7 commit e6b90a4
Show file tree
Hide file tree
Showing 155 changed files with 23,096 additions and 162 deletions.
64 changes: 64 additions & 0 deletions .github/labeler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
car interfacing:
- changed-files:
- any-glob-to-all-files: "{opendbc/car/**}"

can:
- changed-files:
- any-glob-to-all-files: "{opendbc/can/**}"

DBC signals:
- changed-files:
- any-glob-to-all-files: "{opendbc/dbc/**}"


body:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/body/*'

chrysler:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/chrysler/*'

ford:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/ford/*'

gm:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/gm/*'

honda:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/honda/*'

hyundai:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/hyundai/*'

mazda:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/mazda/*'

nissan:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/nissan/*'

subaru:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/subaru/*'

tesla:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/tesla/*'

toyota:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/toyota/*'

volkswagen:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/volkswagen/*'

fingerprint:
- changed-files:
- any-glob-to-all-files: 'opendbc/car/*/fingerprints.py'
50 changes: 50 additions & 0 deletions .github/workflows/auto_pr_review.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: "PR review"
on:
pull_request_target:
types: [opened, reopened, synchronize, edited, edited]

jobs:
labeler:
name: review
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Label PRs
- uses: actions/[email protected]
with:
dot: true
configuration-path: .github/labeler.yaml

# Check PR target branch
- name: check branch
uses: Vankka/pr-target-branch-action@def32ec9d93514138d6ac0132ee62e120a72aed5
if: github.repository == 'commaai/opendbc'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
target: /^(?!master$).*/
exclude: /commaai:.*/
change-to: ${{ github.base_ref }}
already-exists-action: close_this
already-exists-comment: "Your PR should be made against the `master` branch"

# Welcome comment
- name: comment
uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6
if: github.event.pull_request.head.repo.full_name != 'commaai/opendbc'
with:
message: |
<!-- _(run_id **${{ github.run_id }}**)_ -->
Thanks for contributing to opendbc! In order for us to review your PR as quickly as possible, check the following:
* Convert your PR to a draft unless it's ready to review
* Read the [contributing docs](https://github.com/commaai/openpilot/blob/master/docs/CONTRIBUTING.md)
* Before marking as "ready for review", ensure:
* the goal is clearly stated in the description
* all the tests are passing
* include a route or your device' dongle ID if relevant
comment_tag: run_id
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 24 additions & 28 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
name: tests

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:

env:
RUN: docker run -e PYTHONWARNINGS="error,default::DeprecationWarning" --shm-size 1G --rm opendbc /bin/bash -c
BUILD: docker buildx build --pull --load --cache-to type=inline --cache-from type=registry,ref=ghcr.io/commaai/opendbc:latest -t opendbc -f Dockerfile .
PYTHONWARNINGS: error
# TODO: enable this
#env:
# PYTHONWARNINGS: error,default::DeprecationWarning

jobs:
unit-tests:
name: unit tests
runs-on: ubuntu-latest
timeout-minutes: 1
#strategy:
# fail-fast: false
# matrix:
# run: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: eval "$BUILD"
- name: Unit tests
run: ${{ env.RUN }} "pytest -n logical --durations=0"
- uses: actions/setup-python@v5
with:
cache: 'pip'
python-version: '3.11'
- run: pip install -e .[testing,docs]
- run: scons -j$(nproc)
- run: pytest -n logical --durations=0

static-analysis:
name: static analysis
runs-on: ubuntu-latest
timeout-minutes: 1
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: eval "$BUILD"
- name: pre-commit
# TODO: a package pre-commit installs has a warning, remove the unset once that's fixed
run: ${{ env.RUN }} "git init && git add -A && unset PYTHONWARNINGS && pre-commit run --all"

docker-push:
name: docker push
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request' && github.repository == 'commaai/opendbc'
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: eval "$BUILD"
- name: Push to dockerhub
run: |
docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }}
docker tag opendbc ghcr.io/commaai/opendbc:latest
docker push ghcr.io/commaai/opendbc:latest
- uses: actions/setup-python@v5
with:
cache: 'pip'
python-version: '3.11'
- run: sudo apt install --no-install-recommends -y cppcheck
- run: pip install -e .
- uses: pre-commit/[email protected]
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/build/
.mypy_cache/
*.pyc
*.os
Expand All @@ -7,6 +8,8 @@
.*.swp
.DS_Store
.sconsign.dblite
.hypothesis
*.egg-info/

opendbc/can/*.so
opendbc/can/*.a
Expand Down
9 changes: 3 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@ repos:
- id: check-executables-have-shebangs
- id: check-shebang-scripts-are-executable
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
exclude: '\.dbc$'
args:
- --check-hidden
- --builtins clear,rare,informal,usage,code,names,en-GB_to_en-US
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.11.1
hooks:
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
rev: v0.5.7
hooks:
- id: ruff
- repo: https://github.com/MarcoGorelli/cython-lint
Expand Down
47 changes: 0 additions & 47 deletions Dockerfile

This file was deleted.

77 changes: 28 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,28 @@
## DBC file basics

A DBC file encodes, in a humanly readable way, the information needed to understand a vehicle's CAN bus traffic. A vehicle might have multiple CAN buses and every CAN bus is represented by its own dbc file.
Wondering what's the DBC file format? [Here](http://www.socialledge.com/sjsu/index.php?title=DBC_Format) and [Here](https://github.com/stefanhoelzl/CANpy/blob/master/docs/DBC_Specification.md) a couple of good overviews.

## How to start reverse engineering cars

[opendbc](https://github.com/commaai/opendbc) is integrated with [cabana](https://github.com/commaai/openpilot/tree/master/tools/cabana).

Use [panda](https://github.com/commaai/panda) to connect your car to a computer.

## How to use reverse engineered DBC
To create custom CAN simulations or send reverse engineered signals back to the car you can use [CANdevStudio](https://github.com/GENIVI/CANdevStudio) project.

## DBC file preprocessor

DBC files for different models of the same brand have a lot of overlap. Therefore, we wrote a preprocessor to create DBC files from a brand DBC file and a model specific DBC file. The source DBC files can be found in the generator folder. After changing one of the files run the generator.py script to regenerate the output files. These output files will be placed in the root of the opendbc repository and are suffixed by _generated.

## Good practices for contributing to opendbc

- Comments: the best way to store comments is to add them directly to the DBC files. For example:
```
CM_ SG_ 490 LONG_ACCEL "wheel speed derivative, noisy and zero snapping";
```
is a comment that refers to signal `LONG_ACCEL` in message `490`. Using comments is highly recommended, especially for doubts and uncertainties. [cabana](https://community.comma.ai/cabana/) can easily display/add/edit comments to signals and messages.
- Units: when applicable, it's recommended to convert signals into physical units, by using a proper signal factor. Using a SI unit is preferred, unless a non-SI unit rounds the signal factor much better.
For example:
```
SG_ VEHICLE_SPEED : 7|15@0+ (0.00278,0) [0|70] "m/s" PCM
```
is better than:
```
SG_ VEHICLE_SPEED : 7|15@0+ (0.00620,0) [0|115] "mph" PCM
```
However, the cleanest option is really:
```
SG_ VEHICLE_SPEED : 7|15@0+ (0.01,0) [0|250] "kph" PCM
```
- Signal size: always use the smallest amount of bits possible. For example, let's say I'm reverse engineering the gas pedal position and I've determined that it's in a 3 bytes message. For 0% pedal position I read a message value of `0x00 0x00 0x00`, while for 100% of pedal position I read `0x64 0x00 0x00`: clearly, the gas pedal position is within the first byte of the message and I might be tempted to define the signal `GAS_POS` as:
```
SG_ GAS_POS : 7|8@0+ (1,0) [0|100] "%" PCM
```
However, I can't be sure that the very first bit of the message is referred to the pedal position: I haven't seen it changing! Therefore, a safer way of defining the signal is:
```
SG_ GAS_POS : 6|7@0+ (1,0) [0|100] "%" PCM
```
which leaves the first bit unallocated. This prevents from very erroneous reading of the gas pedal position, in case the first bit is indeed used for something else.
# opendbc

opendbc is a Python API for your car. Read the speed, steering angle, and more. Send gas, braking, and steering commands.

## Structure
* [`opendbc/dbc/`](opendbc/dbc/) is a repository of [DBC](https://en.wikipedia.org/wiki/CAN_bus#DBC) files
* [`opendbc/can/`](opendbc/can/) is a library for parsing and building CAN messages from DBC files
* [`opendbc/car/`](opendbc/car/) is a high-level library for interfacing with cars using Python

## Quick start

```bash
git clone https://github.com/commaai/opendbc.git

cd opendbc

# Install the dependencies
pip3 install -e .[testing,docs]

# Build
scons -j8

# Run the tests
pytest .

# Run the linter
pre-commit run --all-files
```
8 changes: 4 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import subprocess
import sysconfig
import numpy as np

zmq = 'zmq'
arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()

python_path = sysconfig.get_paths()['include']
Expand All @@ -28,8 +27,8 @@ ldflags_asan = ["-fsanitize=address"] if GetOption('asan') else []

env = Environment(
ENV=os.environ,
CC='clang',
CXX='clang++',
CC='gcc',
CXX='g++',
CCFLAGS=[
"-g",
"-fPIC",
Expand All @@ -38,6 +37,7 @@ env = Environment(
"-Werror",
"-Wshadow",
"-Wno-vla-cxx-extension",
"-Wno-unknown-warning-option", # for compatibility across compiler versions
] + ccflags_asan,
LDFLAGS=ldflags_asan,
LINKFLAGS=ldflags_asan,
Expand All @@ -52,7 +52,7 @@ env = Environment(
)

common = ''
Export('env', 'zmq', 'arch', 'common')
Export('env', 'arch', 'common')

envCython = env.Clone()
envCython["CPPPATH"] += [np.get_include()]
Expand Down
Loading

0 comments on commit e6b90a4

Please sign in to comment.