commaai/opendbc

GitHub: commaai/opendbc

一个用于汽车 CAN 总线通信的 Python 库,支持读取车辆状态和控制转向、油门、刹车等功能。

Stars: 2963 | Forks: 1807

opendbc

opendbc 是一个用于汽车的 Python API。
控制油门、刹车、转向等。读取速度、转向角度等信息。

文档 · 贡献 · Discord

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![X Follow](https://img.shields.io/twitter/follow/comma_ai)](https://x.com/comma_ai) [![Discord](https://img.shields.io/discord/469524606043160576)](https://discord.comma.ai)
得益于 [LKAS](https://en.wikipedia.org/wiki/Lane_departure_warning_system#Lane_keeping_and_next_technologies) 和 [ACC](https://en.wikipedia.org/wiki/Adaptive_cruise_control),自 2016 年以来的大多数汽车都配备了电子致动的转向、油门和刹车。 该项目的目标是支持控制每一辆这类汽车的转向、油门和刹车。 虽然主要重点是支持 [openpilot](https://github.com/commaai/openpilot) 的 ADAS 接口,但我们也有兴趣读取和写入尽可能多的内容(EV 充电状态、车门锁定/解锁等),以便我们能够构建有史以来最好的车辆管理应用程序。 本 README 和 [支持汽车列表](docs/CARS.md) 是 opendbc 项目的所有文档。 您需要了解的关于使用、贡献和扩展 opendbc 的所有内容都在这些文档中。 ## 快速开始 ``` git clone https://github.com/commaai/opendbc.git cd opendbc # 你可能只想使用这个。这是一个用于 dependency # installation、compiling、linting 和 tests 的 all-in-one。它也是在 CI 中运行的内容 ./test.sh # 这里是其运行的 individual commands pip3 install -e .[testing,docs] # install dependencies scons -j8 # build with 8 cores pytest . # run the tests lefthook run lint # run the linter ``` [`examples/`](examples/) 包含一些小程序示例,可以从汽车读取状态并控制转向、油门和刹车。 [`examples/joystick.py`](examples/joystick.py) 允许您使用操纵杆控制汽车。 ### 项目结构 * [`opendbc/dbc/`](opendbc/dbc/) 是 [DBC](https://en.wikipedia.org/wiki/CAN_bus#DBC_(CAN_Database_Files)) 文件的仓库 * [`opendbc/can/`](opendbc/can/) 是一个用于从 DBC 文件解析和构建 CAN 消息的库 * [`opendbc/car/`](opendbc/car/) 是一个使用 Python 与汽车交互的高级库 * [`opendbc/safety/`](opendbc/safety/) 是 `opendbc/car/` 支持的所有汽车的功能安全模块 ## 如何适配一款汽车 本指南涵盖了从为新汽车添加支持到改进现有汽车(例如添加纵向控制或雷达解析)的所有内容。如果与您的汽车类似的车型已经兼容,那么这些工作的大部分可能已经为您完成了。 在最基本的情况下,汽车适配将控制汽车的转向。一个“完整”的汽车适配将包含以下所有内容:横向控制、纵向控制、良好的横向和纵向调优、雷达解析(如果配备)、模糊指纹识别等。新汽车支持文档将清楚地说明每辆汽车的支持级别。 ### 连接到汽车 第一步是使用 comma four 和汽车线束连接到汽车。 汽车线束让您连接到两条不同的 CAN 总线,并分流其中一条总线以发送我们自己的致动消息。 如果幸运的话,与您的汽车兼容的线束可能已经设计好并在 comma.ai/shop 上出售。 如果不走运,请从 comma.ai/shop 购买一个“开发人员线束”,并压接您需要的任何连接器。 ### 适配的结构 根据品牌的不同,这种基本结构的大部分可能已经存在。 汽车适配的全部内容位于 `opendbc/car//`: * `carstate.py`:使用汽车的 DBC 文件从 CAN 流中解析相关信息 * `carcontroller.py`:输出 CAN 消息以控制汽车 * `can.py`:围绕 DBC 文件的轻量级 Python 辅助工具,用于构建 CAN 消息 * `fingerprints.py`:用于识别汽车型号的 ECU 固件版本数据库 * `interface.py`:用于与汽车交互的高级类 * `radar_interface.py`:解析雷达数据 * `values.py`:枚举该品牌支持的汽车 ### 逆向工程 CAN 消息 首先,录制一段包含许多有趣事件的行程:启用 LKAS 和 ACC,将方向盘转到两个极限位置等。然后,在 [cabana](https://github.com/commaai/openpilot/tree/master/tools/cabana) 中加载该行程。 ### 调优 #### 纵向 使用 [longitudinal maneuvers](https://github.com/commaai/openpilot/tree/master/tools/longitudinal_maneuvers) 报告来评估您汽车的纵向控制并进行调优。 ## 贡献 所有 opendbc 的开发都在 GitHub 和 [Discord](https://discord.comma.ai) 上进行协调。请查看 `#dev-opendbc-cars` 频道和 `Vehicle Specific` 版块。 ### 路线图 短期 - [ ] `pip install opendbc` - [ ] 100% 类型覆盖 - [ ] 100% 行覆盖 - [ ] 让汽车适配更容易:重构、工具、测试和文档 - [ ] 更好地公开所有支持汽车的状态:https://github.com/commaai/opendbc/issues/1144 长期 - [ ] 将支持扩展到每一辆具有 LKAS + ACC 接口的汽车 - [ ] 自动横向和纵向控制/调优评估 - [ ] [横向](https://blog.comma.ai/090release/#torqued-an-auto-tuner-for-lateral-control) 和纵向控制的自动调优 - [ ] [自动紧急制动](https://en.wikipedia.org/wiki/Automated_emergency_braking_system) 欢迎为此处的任何内容做出贡献。 ## 安全模型 当 [panda](https://comma.ai/shop/panda) 搭载 [opendbc 安全固件](opendbc/safety) 启动时,默认处于 `SAFETY_SILENT` 模式。在 `SAFETY_SILENT` 模式下,CAN 总线被强制静默。为了发送消息,您必须选择一种安全模式。某些安全模式(例如 `SAFETY_ALLOUTPUT`)在发布版固件中被禁用。为了使用它们,请编译并刷入您自己的构建版本。 安全模式可选支持 `controls_allowed`,它根据板上的可定制状态允许或阻止一部分消息。 ## 代码严谨性 opendbc 安全固件是为结合 [openpilot](https://github.com/commaai/openpilot) 和 [panda](https://github.com/commaai/panda) 使用而编写的。安全固件通过其安全模型提供并强制执行 [openpilot 安全](https://github.com/commaai/openpilot/blob/master/docs/SAFETY.md)。由于其关键功能,`safety` 文件夹中的应用程序代码严谨性必须保持高标准。 以下是我们实施的 [CI 回归测试](https://github.com/commaai/opendbc/actions): * 由 [cppcheck](https://github.com/danmar/cppcheck/) 执行通用静态代码分析。 * 此外,[cppcheck](https://github.com/danmar/cppcheck/) 有一个特定的插件来检查 [MISRA C:2012](https://misra.org.uk/) 违规。请参阅[当前覆盖率](opendbc/safety/tests/misra/coverage_table)。 * 编译器选项相对严格:强制执行标志 `-Wall -Wextra -Wstrict-prototypes -Werror`。 * [安全逻辑](opendbc/safety) 通过每种受支持汽车变体的[单元测试](opendbc/safety/tests) 进行测试和验证。 上述测试本身通过以下方式进行测试: * MISRA 覆盖率上的[变异测试](opendbc/safety/tests/misra/test_mutation.py) * 安全单元测试上强制执行 100% 行覆盖 此外,我们在汽车接口库上运行 [ruff linter](https://github.com/astral-sh/ruff) 和 [ty](https://github.com/astral-sh/ty)。 ### 赏金 每个汽车适配都有资格获得赏金: * $2000 - [任何汽车品牌 / 平台适配](https://github.com/orgs/commaai/projects/26/views/1?pane=issue&itemId=47913774) * $250 - [任何汽车型号适配](https://github.com/orgs/commaai/projects/26/views/1?pane=issue&itemId=47913790) * $300 - [逆向工程新的致动消息](https://github.com/orgs/commaai/projects/26/views/1?pane=issue&itemId=73445563) 除了标准赏金外,我们还为更受欢迎的汽车提供更高价值的赏金。请在 [comma.ai/bounties](comma.ai/bounties) 查看。 ## 常见问题 ***我该如何使用?*** [comma four](https://comma.ai/shop/comma-four) 是定制设计的,是运行和开发 opendbc 及 openpilot 的最佳方式。 ***支持哪些汽车?*** 请参阅[支持汽车列表](docs/CARS.md)。 ***我可以为我的汽车添加支持吗?*** 是的,大多数汽车支持来自社区。请阅读此处的[指南](https://github.com/commaai/opendbc/blob/docs/README.md#how-to-port-a-car)。 ***哪些汽车可以被支持?*** 任何具有 LKAS 和 ACC 的汽车。更多信息请参阅[此处](https://github.com/commaai/openpilot/blob/master/docs/CARS.md#dont-see-your-car-here)。 ***这是如何工作的?*** 简而言之,我们设计了硬件来取代您汽车内置的车道保持和自适应巡航功能。请参阅[此演讲](https://www.youtube.com/watch?v=FL8CxUSfipM)以获取深入解释。 ***添加汽车支持是否有时间表或路线图?*** 没有,大多数汽车支持来自社区,comma 负责最终的安全和质量验证。社区汽车适配越完整,汽车越受欢迎,我们就越有可能选择它作为下一个验证对象。 ### 术语 * **port**:指特定汽车的集成和支持 * **lateral control**:又名转向控制 * **longitudinal control**:又名油门/刹车控制 * **fingerprinting**:用于识别汽车的自动过程 * **[LKAS](https://en.wikipedia.org/wiki/Lane_departure_warning_system)**:车道保持辅助系统 * **[ACC](https://en.wikipedia.org/wiki/Adaptive_cruise_control)**:自适应巡航控制 * **[harness](https://comma.ai/shop/car-harness)**:用于连接汽车并拦截 ADAS 消息的特定汽车硬件 * **[panda](https://github.com/commaai/panda)**:用于连接汽车 CAN 总线的硬件 * **[ECU](https://en.wikipedia.org/wiki/Electronic_control_unit)**:汽车内部的计算机或控制模块 * **[CAN bus](https://en.wikipedia.org/wiki/CAN_bus)**:连接汽车中 ECU 的总线 * **[cabana](https://github.com/commaai/openpilot/tree/master/tools/cabana#readme)**:我们用于逆向工程 CAN 消息的工具 * **[DBC file](https://en.wikipedia.org/wiki/CAN_bus#DBC)**:包含 CAN 总线上消息的定义 * **[openpilot](https://github.com/commaai/openpilot)**:opendbc 支持的汽车 ADAS 系统 * **[comma](https://github.com/commaai)**:opendbc 背后的公司 * **[comma four](https://comma.ai/shop/comma-four)**:用于运行 openpilot 的硬件 ### 更多资源 * [*我们如何控制汽车?*](https://www.youtube.com/watch?v=nNU6ipme878&pp=ygUoY29tbWEgY29uIDIwMjEgaG93IGRvIHdlIGNvbnRyb2wgdGhlIGNhcg%3D%3D) 作者 [@robbederks](https://github.com/robbederks),来自 COMMA_CON 2021 * [*如何适配一款汽车*](https://www.youtube.com/watch?v=XxPS5TpTUnI&t=142s&pp=ygUPamFzb24gY29tbWEgY29u) 作者 [@jyoung8607](https://github.com/jyoung8607),来自 COMMA_CON 2023 * [commaCarSegments](https://huggingface.co/datasets/commaai/commaCarSegments):来自 300 种不同汽车型号的海量 CAN 数据集 * [cabana](https://github.com/commaai/openpilot/tree/master/tools/cabana#readme):我们用于逆向工程 CAN 消息的工具 * [can_print_changes.py](https://github.com/commaai/openpilot/blob/master/selfdrive/debug/can_print_changes.py):比较两次驾驶中的整个 CAN 总线差异,例如一次没有任何 LKAS,一次有 LKAS * [longitudinal maneuvers](https://github.com/commaai/openpilot/tree/master/tools/longitudinal_maneuvers):用于评估和调整纵向控制的工具 * [opendbc data](https://commaai.github.io/opendbc-data/):纵向机动评估的仓库 ## 加入我们 -- [comma.ai/jobs](https://comma.ai/jobs) comma 正在招聘工程师致力于 opendbc 和 [openpilot](https://github.com/commaai/openpilot)。我们喜欢招聘贡献者。
标签:ACC, ADAS, CAN总线, comma.ai, DBC文件, ECU, lane-keeping, openpilot, Python, 云资产清单, 交通行业, 开源硬件, 无后门, 汽车API, 汽车安全, 线控底盘, 自动驾驶, 车联网, 车载系统, 车辆控制, 辅助驾驶, 逆向工具, 逆向工程