openpilot代码分析

openpliot

openpliot适配不同车型

openpliot支持不同的车型,代码中对车辆创建了一个抽象模型,根据can信息加载不同的车辆文件。代码逻辑在selfdrive/car/car_helpers.py文件。Controls类初始化时调用了car_helpers的get_car函数获取了两个对象CI(Car Interface), CP (car Params)。

def get_car(logcan, sendcan, experimental_long_allowed, num_pandas=1):
  candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(logcan, sendcan, num_pandas)

  if candidate is None:
    cloudlog.event("car doesn't match any fingerprints", fingerprints=fingerprints, error=True)
    candidate = "mock"

  CarInterface, CarController, CarState = interfaces[candidate]
  #创建CP对象
  CP = CarInterface.get_params(candidate, fingerprints, car_fw, experimental_long_allowed, docs=False)
  CP.carVin = vin
  CP.carFw = car_fw
  CP.fingerprintSource = source
  CP.fuzzyFingerprint = not exact_match

  return CarInterface(CP, CarController, CarState), CP
# imports from directory selfdrive/car/<name>/
#_get_interface_names获取selfdrive/car/下的车辆name
interface_names = _get_interface_names()
#load_interfaces import车辆文件:interface.py, carstate.py, carcontroller.py,对应CarInterface, CarController, CarState三个对象
interfaces = load_interfaces(interface_names)

获取到CarInterface对象后,调用CarInterfaceBase类的静态函数get_params,get_params调用CarInterface子类的_get_params对参数进行调整,最终返回CI,CP对象。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值