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对象。