Skip to content

Commit

Permalink
Merge branch 'commaai:master' into kona-2nd-gen-port
Browse files Browse the repository at this point in the history
  • Loading branch information
royjr authored Oct 17, 2024
2 parents 684c7a6 + 2f0385d commit 57ac750
Show file tree
Hide file tree
Showing 72 changed files with 2,283 additions and 1,067 deletions.
2 changes: 1 addition & 1 deletion .github/labeler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ volkswagen:

fingerprint:
- changed-files:
- any-glob-to-any-file: 'opendbc/car/*/fingerprints.py'
- any-glob-to-all-files: 'opendbc/car/*/fingerprints.py'
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ may end up going in openpilot.
* Expose the state of all supported cars better: https://github.com/commaai/opendbc/issues/1144

Contributions towards anything here is welcome. Join the [Discord](https://discord.comma.ai)!

## FAQ

* **How do I use this?** Depends on what you want to do. [openpilot](https://github.com/commaai/openpilot) is our development target, but you can also use a [panda](https://comma.ai/shop/panda) for basic control or just reading state from your car.
* **Can I add support for my car?** Yes, most car support comes from the community. Join the [Discord](https://discord.comma.ai) and watch this [talk](https://www.youtube.com/watch?v=XxPS5TpTUnI&t=142s&pp=ygUPY29tbWFfY29uIGphc29u) to get started. (We also offer [paid bounties](https://comma.ai/bounties) on car ports.)
* **Which cars are supported?** See the openpilot [supported cars list](https://github.com/commaai/openpilot/blob/master/docs/CARS.md) and `grep` around the codebase.
417 changes: 417 additions & 0 deletions docs/CARS.md

Large diffs are not rendered by default.

78 changes: 78 additions & 0 deletions opendbc/car/CARS_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!--- AUTOGENERATED FROM selfdrive/car/CARS_template.md, DO NOT EDIT. --->

# Support Information for {{car_docs_with_extras | length}} Known Cars

|{{ExtraCarsColumn | map(attribute='value') | join('|') | replace(hardware_col_name, wide_hardware_col_name)}}|
|---|---|---|{% for _ in range((ExtraCarsColumn | length) - 3) %}{{':---:|'}}{% endfor +%}
{% for car_docs in car_docs_with_extras %}
|{% for column in ExtraCarsColumn %}{{car_docs.get_extra_cars_column(column)}}|{% endfor %}

{% endfor %}

# Types of Support

**opendbc can support many more cars than it currently does.** There are a few reasons your car may not be supported.
If your car doesn't fit into any of the incompatibility criteria here, then there's a good chance it can be supported!
We're adding support for new cars all the time. **We don't have a roadmap for car support**, and in fact, most car
support comes from users like you!

## Upstream

A supported vehicle is one that just works when you install a comma device. All supported cars provide a better
experience than any stock system. Supported vehicles reference the US market unless otherwise specified.

## Under Review

A vehicle under review is one for which software support has been merged into upstream openpilot, but hasn't yet been
tested for drive quality and conformance with [comma safety guidelines](https://github.com/commaai/openpilot/blob/master/docs/SAFETY.md).
This is a normal part of the development and quality assurance process. This vehicle will not work when upstream
openpilot is installed, but custom forks may allow their use.

## Custom

Vehicles in this category are not considered plug-and-play. Software support is included in upstream openpilot, but
these vehicles might not have a harness in the comma store, or the physical install might be at an unusual or cumbersome
location, or they might need unusual configuration after install.

## Dashcam

Dashcam vehicles have software support in upstream openpilot, but will go into "dashcam mode" at startup and will not
engage. This may be due to known issues with driving safety or quality, or it may be a work in progress that isn't yet
ready for safety and quality review.

## Community

Although they're not upstream, the community has openpilot running on other makes and models. See the 'Community
Supported Models' section of each make [on our wiki](https://wiki.comma.ai/).

Some notable works-in-progress:
* Honda
* 2024 Acura Integra, commaai/openpilot#32056
* 2023-24 Honda Accord (CAN-FD), commaai/openpilot#32229
* 2024 Honda CR-V (CAN-FD), commaai/openpilot#32806
* 2024 Honda CR-V Hybrid (CAN-FD), commaai/openpilot#31527
* Depends on commaai/opendbc#1100
* 2021-25 Honda Odyssey, commaai/opendbc#1330
* 2023-24 Honda Pilot (CAN-FD), commaai/openpilot#30324
* Camera ACC stability improvements, commaai/openpilot#31022
* Depends on commaai/panda#1814
* Depends on commaai/opendbc#998
* These are being reworked for full-time proxy through openpilot
* Manual transmission support (Civic, Integra)
* Depends on commaai/opendbc#1034 (merged)
* Car port support PR not yet filed

## Incompatible

### CAN Bus Security

Vehicles with CAN security measures, such as AUTOSAR Secure Onboard Communication (SecOC) are not usable with openpilot
unless the owner can recover the message signing key and implement CAN message signing. Examples include certain newer
Toyota, and the GM Global B platform.

### FlexRay

All the cars that openpilot supports use a [CAN bus](https://en.wikipedia.org/wiki/CAN_bus) for communication between all the car's computers, however a
CAN bus isn't the only way that the computers in your car can communicate. Most, if not all, vehicles from the following
manufacturers use [FlexRay](https://en.wikipedia.org/wiki/FlexRay) instead of a CAN bus: **BMW, Mercedes, Audi, Land Rover, and some Volvo**. These cars
may one day be supported, but we have no immediate plans to support FlexRay.
24 changes: 19 additions & 5 deletions opendbc/car/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# functions common among cars
import logging
from collections import namedtuple
from dataclasses import dataclass
from dataclasses import dataclass, field
from enum import IntFlag, ReprEnum, EnumType
from dataclasses import replace

from panda import uds
from opendbc.car import structs
from opendbc.car.can_definitions import CanData
from opendbc.car.docs_definitions import CarDocs
from opendbc.car.docs_definitions import CarDocs, ExtraCarDocs
from opendbc.car.common.numpy_fast import clip, interp

# set up logging
Expand Down Expand Up @@ -270,8 +270,8 @@ def __setattr__(self, *args, **kwargs):


@dataclass(order=True)
class PlatformConfig(Freezable):
car_docs: list[CarDocs]
class PlatformConfigBase(Freezable):
car_docs: list[CarDocs] | list[ExtraCarDocs]
specs: CarSpecs

dbc_dict: DbcDict
Expand All @@ -293,6 +293,20 @@ def __post_init__(self):
self.init()


@dataclass(order=True)
class PlatformConfig(PlatformConfigBase):
car_docs: list[CarDocs]
specs: CarSpecs
dbc_dict: DbcDict


@dataclass(order=True)
class ExtraPlatformConfig(PlatformConfigBase):
car_docs: list[ExtraCarDocs]
specs: CarSpecs = CarSpecs(mass=0., wheelbase=0., steerRatio=0.)
dbc_dict: DbcDict = field(default_factory=lambda: dbc_dict('unknown', None))


class PlatformsType(EnumType):
def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **kwds):
for key in classdict._member_names.keys():
Expand All @@ -303,7 +317,7 @@ def __new__(metacls, cls, bases, classdict, *, boundary=None, _simple=False, **k


class Platforms(str, ReprEnum, metaclass=PlatformsType):
config: PlatformConfig
config: PlatformConfigBase

def __new__(cls, platform_config: PlatformConfig):
member = str.__new__(cls, platform_config.platform_str)
Expand Down
67 changes: 4 additions & 63 deletions opendbc/car/body/carcontroller.py
Original file line number Diff line number Diff line change
@@ -1,71 +1,12 @@
import copy
import numpy as np
from numbers import Number

from opendbc.can.packer import CANPacker
from opendbc.car import DT_CTRL
from opendbc.car.common.numpy_fast import clip, interp
from opendbc.car.common.pid import PIDController
from opendbc.car.body import bodycan
from opendbc.car.body.values import SPEED_FROM_RPM
from opendbc.car.interfaces import CarControllerBase


class PIController:
def __init__(self, k_p, k_i, pos_limit=1e308, neg_limit=-1e308, rate=100):
self._k_p = k_p
self._k_i = k_i
if isinstance(self._k_p, Number):
self._k_p = [[0], [self._k_p]]
if isinstance(self._k_i, Number):
self._k_i = [[0], [self._k_i]]

self.pos_limit = pos_limit
self.neg_limit = neg_limit

self.i_unwind_rate = 0.3 / rate
self.i_rate = 1.0 / rate
self.speed = 0.0

self.reset()

@property
def k_p(self):
return interp(self.speed, self._k_p[0], self._k_p[1])

@property
def k_i(self):
return interp(self.speed, self._k_i[0], self._k_i[1])

@property
def error_integral(self):
return self.i/self.k_i

def reset(self):
self.p = 0.0
self.i = 0.0
self.control = 0

def update(self, error, speed=0.0, freeze_integrator=False):
self.speed = speed

self.p = float(error) * self.k_p

i = self.i + error * self.k_i * self.i_rate
control = self.p + i

# Update when changing i will move the control away from the limits
# or when i will move towards the sign of the error
if ((error >= 0 and (control <= self.pos_limit or i < 0.0)) or
(error <= 0 and (control >= self.neg_limit or i > 0.0))) and \
not freeze_integrator:
self.i = i

control = self.p + self.i

self.control = clip(control, self.neg_limit, self.pos_limit)
return self.control


MAX_TORQUE = 500
MAX_TORQUE_RATE = 50
MAX_ANGLE_ERROR = np.radians(7)
Expand All @@ -79,8 +20,8 @@ def __init__(self, dbc_name, CP):
self.packer = CANPacker(dbc_name)

# PIDs
self.turn_pid = PIController(110, k_i=11.5, rate=1/DT_CTRL)
self.wheeled_speed_pid = PIController(110, k_i=11.5, rate=1/DT_CTRL)
self.turn_pid = PIDController(110, k_i=11.5, rate=1/DT_CTRL)
self.wheeled_speed_pid = PIDController(110, k_i=11.5, rate=1/DT_CTRL)

self.torque_r_filtered = 0.
self.torque_l_filtered = 0.
Expand Down Expand Up @@ -132,7 +73,7 @@ def update(self, CC, CS, now_nanos):
can_sends = []
can_sends.append(bodycan.create_control(self.packer, torque_l, torque_r))

new_actuators = copy.copy(CC.actuators)
new_actuators = CC.actuators.as_builder()
new_actuators.accel = torque_l
new_actuators.steer = torque_r
new_actuators.steerOutputCan = torque_r
Expand Down
Loading

0 comments on commit 57ac750

Please sign in to comment.