Openpilot 是L2.5级的自动驾驶辅助系统,由 comma.ai 公司研发并开源,它主要使用 Python/C++ 语言开发,地址:https://github.com/commaai
├── cereal # 消息队列,各个组件通过它相互通信
├── common # 公共库
├── docs # 项目文档
├── opendbc # 汽车can数据解析文件
├── panda # 接收和发送can信号
├── third_party # 项目使用到的三方库
├── pyextra # 扩展python包
└── selfdrive # 辅助驾驶核心实现代码
├── assets # 控制UI使用到的资源文件
├── athena # app通信(上传、通信)
├── boardd # 与panda通信(接收与发送车辆、控车数据)
├── camerad # 通过摄像头器件捕获图像用于模型使用
├── car # 车辆特有实现代码,获取车辆状态和发送控车指令
├── common # 公共库
├── controls # 路径规划和执行(核心辅助逻辑实现)
├── debug # 帮助调试
├── locationd # 坐标定位和车辆参数估测
├── logcatd # 系统日志获取并发送
├── loggerd # 记录并上传车辆行驶记录
├── modeld # 行驶和驾驶员监控模型执行
├── proclogd # 进程状态获取
├── sensord # IMU interface code
├── test # 系统测试
└── ui # 辅助控制系统UI
大概在2022年10月份了解到这个开源项目,经过一段时间的学习,大致了解了openpilot(简称op)运作原理并基于openpilot-0.8.13 fork了自己的分支xgnpilot(实现了全时保持、自动切换车道预测算法等)。
车道保持(主要功能)
辅助变道
车道偏离报警
selfdrive\manager\manager.py 项目启动入口,管理系统中各个组件运行状态。
if __name__ == "__main__":
unblock_stdout()
try:
main() #核心运行逻辑
except Exception:
add_file_handler(cloudlog) #日志记录到磁盘
cloudlog.exception("Manager failed to start")
try:
managed_processes['ui'].stop()
except Exception:
pass
# Show last 3 lines of traceback
error = traceback.format_exc(-3)
error = "Manager failed to start\n\n" + error
with TextWindow(error) as t:
t.wait_for_exit()
raise
# manual exit because we are forked
sys.exit(0)
main 函数里主要处理系统信号SIGTERM、安装、卸载、重启操作。
def main() -> None:
prepare_only = os.getenv("PREPAREONLY") is not None
#初始化系统参数
manager_init()
# Start UI early so prepare can happen in the background
if not prepare_only:
managed_processes['ui'].start()
#初始化各组件进程
manager_prepare()
if prepare_only:
return
# SystemExit on sigterm
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(1))
try:
#启动并监测各个组件进程运行状态
manager_thread()
except Exception:
traceback.print_exc()
sentry.capture_exception()
finally:
manager_cleanup()
params = Params()
#卸载
if params.get_bool("DoUninstall"):
cloudlog.warning("uninstalling")
HARDWARE.uninstall()
#重启
elif params.get_bool("DoReboot"):
cloudlog.warning("reboot")
HARDWARE.reboot()
#关机
elif params.get_bool("DoShutdown"):
cloudlog.warning("shutdown")
HARDWARE.shutdown()
selfdrive\manager\process_config.py
系统所有组件定义
import os
from selfdrive.hardware import EON, TICI, PC
from selfdrive.manager.process import PythonProcess, NativeProcess, DaemonProcess
WEBCAM = os.getenv("USE_WEBCAM") is not None
procs = [
DaemonProcess("manage_athenad", "selfdrive.athena.manage_athenad", "AthenadPid"),
# due to qualcomm kernel bugs SIGKILLing camerad sometimes causes page table corruption
NativeProcess("camerad", "selfdrive/camerad", ["./camerad"], unkillable=True, driverview=True),
NativeProcess("clocksd", "selfdrive/clocksd", ["./clocksd"]),
NativeProcess("dmonitoringmodeld", "selfdrive/modeld", ["./dmonitoringmodeld"], enabled=(not PC or WEBCAM), driverview=True),
NativeProcess("logcatd", "selfdrive/logcatd", ["./logcatd"]),
NativeProcess("loggerd", "selfdrive/loggerd", ["./loggerd"],persistent=True),
NativeProcess("modeld", "selfdrive/modeld", ["./modeld"]),
NativeProcess("navd", "selfdrive/ui/navd", ["./navd"], enabled=(PC or TICI), persistent=True),
NativeProcess("proclogd", "selfdrive/proclogd", ["./proclogd"]),
NativeProcess("sensord", "selfdrive/sensord", ["./sensord"], enabled=not PC, persistent=EON, sigkill=EON),
NativeProcess("ubloxd", "selfdrive/locationd", ["./ubloxd"], enabled=(not PC or WEBCAM)),
NativeProcess("ui", "selfdrive/ui", ["./ui"], persistent=True, watchdog_max_dt=(5 if TICI else None)),
NativeProcess("soundd", "selfdrive/ui/soundd", ["./soundd"], persistent=True),
NativeProcess("locationd", "selfdrive/locationd", ["./locationd"]),
NativeProcess("boardd", "selfdrive/boardd", ["./boardd"], enabled=False),
PythonProcess("calibrationd", "selfdrive.locationd.calibrationd"),
PythonProcess("controlsd", "selfdrive.controls.controlsd"),
PythonProcess("deleter", "selfdrive.loggerd.deleter", persistent=True),
PythonProcess("dmonitoringd", "selfdrive.monitoring.dmonitoringd", enabled=(not PC or WEBCAM), driverview=True),
PythonProcess("logmessaged", "selfdrive.logmessaged", persistent=True),
PythonProcess("pandad", "selfdrive.pandad", persistent=True),
PythonProcess("paramsd", "selfdrive.locationd.paramsd"),
PythonProcess("plannerd", "selfdrive.controls.plannerd"),
PythonProcess("radard", "selfdrive.controls.radard"),
PythonProcess("thermald", "selfdrive.thermald.thermald", persistent=True),
PythonProcess("timezoned", "selfdrive.timezoned", enabled=TICI, persistent=True),
PythonProcess("tombstoned", "selfdrive.tombstoned", enabled=not PC, persistent=True),
PythonProcess("updated", "selfdrive.updated", enabled=not PC, persistent=True),
PythonProcess("uploader", "selfdrive.loggerd.uploader", persistent=True),
PythonProcess("statsd", "selfdrive.statsd", persistent=True),
""" """
# EON only
PythonProcess("rtshield", "selfdrive.rtshield", enabled=EON),
PythonProcess("shutdownd", "selfdrive.hardware.eon.shutdownd", enabled=EON),
PythonProcess("androidd", "selfdrive.hardware.eon.androidd", enabled=EON, persistent=True),
]
managed_processes = {p.name: p for p in procs}
xgnpilot是我从基于openpilot-0.8.13官方分支fork并二次开发的辅助系统,它增加了一些日常驾驶中比较实用的功能,这些功能其它基于openpilot fork的分支已有实现(dragonpilot),该版本只适用于大众车系Sorry(我的车辆是大众)其它车系没有支援。
全时保持
踩刹车或油门时系统依然可以控制车辆方向(横向控制),复杂路况下很实用。
辅助变道
官方已实现了,但官方分支不支持关闭该功能,现实中该功能并不被广泛接受,我实现了该功能的开/闭控制。
完善的自动跟车stop and go,修复了大众车系跟前车行驶当前车停止并重新启动时偶尔不跟车的问题。
显示前车信息
前车车速、距离
地址 https://github.com/dreamxgn/xgnpilot.git