diff --git a/panda b/panda index 0ae2be95a1..3018f50847 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit 0ae2be95a114269b12e039eabf0a563c1ca32ece +Subproject commit 3018f50847d7ccfc2e8a86595528d1ff05e0a48f diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index 2584618ebd..45d2c5321e 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -8,7 +8,7 @@ from tqdm import tqdm import panda.python.uds as uds from cereal import car from selfdrive.car.fingerprints import FW_VERSIONS, get_attr_from_cars -from selfdrive.car.isotp_parallel_query import IsoTpParallelQuery +from selfdrive.car.isotp_parallel_query import IsoTpParallelQuery, RX_OFFSET from selfdrive.car.toyota.values import CAR as TOYOTA from selfdrive.swaglog import cloudlog @@ -56,49 +56,74 @@ HYUNDAI_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x4 TOYOTA_VERSION_REQUEST = b'\x1a\x88\x01' TOYOTA_VERSION_RESPONSE = b'\x5a\x88\x01' +VOLKSWAGEN_VERSION_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \ + p16(uds.DATA_IDENTIFIER_TYPE.VEHICLE_MANUFACTURER_SPARE_PART_NUMBER) +VOLKSWAGEN_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + \ + p16(uds.DATA_IDENTIFIER_TYPE.VEHICLE_MANUFACTURER_SPARE_PART_NUMBER) + OBD_VERSION_REQUEST = b'\x09\x04' OBD_VERSION_RESPONSE = b'\x49\x04' -# supports subaddressing, request, response +# brand, request, response, response offset REQUESTS = [ - # Hundai + # Hyundai ( "hyundai", [HYUNDAI_VERSION_REQUEST_SHORT], [HYUNDAI_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, ), ( "hyundai", [HYUNDAI_VERSION_REQUEST_LONG], [HYUNDAI_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, ), ( "hyundai", [HYUNDAI_VERSION_REQUEST_MULTI], [HYUNDAI_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, ), # Honda ( "honda", [UDS_VERSION_REQUEST], [UDS_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, ), # Toyota ( "toyota", [SHORT_TESTER_PRESENT_REQUEST, TOYOTA_VERSION_REQUEST], [SHORT_TESTER_PRESENT_RESPONSE, TOYOTA_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, ), ( "toyota", [SHORT_TESTER_PRESENT_REQUEST, OBD_VERSION_REQUEST], [SHORT_TESTER_PRESENT_RESPONSE, OBD_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, ), ( "toyota", [TESTER_PRESENT_REQUEST, DEFAULT_DIAGNOSTIC_REQUEST, EXTENDED_DIAGNOSTIC_REQUEST, UDS_VERSION_REQUEST], [TESTER_PRESENT_RESPONSE, DEFAULT_DIAGNOSTIC_RESPONSE, EXTENDED_DIAGNOSTIC_RESPONSE, UDS_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, + ), + # Volkswagen + ( + "volkswagen", + [EXTENDED_DIAGNOSTIC_REQUEST, VOLKSWAGEN_VERSION_REQUEST], + [EXTENDED_DIAGNOSTIC_RESPONSE, VOLKSWAGEN_VERSION_RESPONSE], + RX_OFFSET.DEFAULT, + ), + ( + "volkswagen", + [EXTENDED_DIAGNOSTIC_REQUEST, VOLKSWAGEN_VERSION_REQUEST], + [EXTENDED_DIAGNOSTIC_RESPONSE, VOLKSWAGEN_VERSION_RESPONSE], + RX_OFFSET.VOLKSWAGEN, ) ] @@ -173,12 +198,12 @@ def get_fw_versions(logcan, sendcan, bus, extra=None, timeout=0.1, debug=False, fw_versions = {} for i, addr in enumerate(tqdm(addrs, disable=not progress)): for addr_chunk in chunks(addr): - for brand, request, response in REQUESTS: + for brand, request, response, response_offset in REQUESTS: try: addrs = [(a, s) for (b, a, s) in addr_chunk if b in (brand, 'any')] if addrs: - query = IsoTpParallelQuery(sendcan, logcan, bus, addrs, request, response, debug=debug) + query = IsoTpParallelQuery(sendcan, logcan, bus, addrs, request, response, response_offset, debug=debug) t = 2 * timeout if i == 0 else timeout fw_versions.update(query.get_data(t)) except Exception: diff --git a/selfdrive/car/isotp_parallel_query.py b/selfdrive/car/isotp_parallel_query.py index c5185dec5c..1fe7ab16fa 100644 --- a/selfdrive/car/isotp_parallel_query.py +++ b/selfdrive/car/isotp_parallel_query.py @@ -7,9 +7,13 @@ from selfdrive.swaglog import cloudlog from selfdrive.boardd.boardd import can_list_to_can_capnp from panda.python.uds import CanClient, IsoTpMessage, FUNCTIONAL_ADDRS, get_rx_addr_for_tx_addr +class RX_OFFSET: + DEFAULT = 0x8 + VOLKSWAGEN = 0x6a + class IsoTpParallelQuery(): - def __init__(self, sendcan, logcan, bus, addrs, request, response, functional_addr=False, debug=False): + def __init__(self, sendcan, logcan, bus, addrs, request, response, response_offset=RX_OFFSET.DEFAULT, functional_addr=False, debug=False): self.sendcan = sendcan self.logcan = logcan self.bus = bus @@ -25,7 +29,7 @@ class IsoTpParallelQuery(): else: self.real_addrs.append((a, None)) - self.msg_addrs = {tx_addr: get_rx_addr_for_tx_addr(tx_addr[0]) for tx_addr in self.real_addrs} + self.msg_addrs = {tx_addr: get_rx_addr_for_tx_addr(tx_addr[0], rx_offset=response_offset) for tx_addr in self.real_addrs} self.msg_buffer = defaultdict(list) def rx(self): diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index 24c078d7ad..d61f0ee4ec 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -1,5 +1,5 @@ from cereal import car -from selfdrive.car.volkswagen.values import CAR, BUTTON_STATES +from selfdrive.car.volkswagen.values import CAR, MQB_CARS, BUTTON_STATES from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, gen_empty_fingerprint from selfdrive.car.interfaces import CarInterfaceBase @@ -25,7 +25,7 @@ class CarInterface(CarInterfaceBase): # VW port is a community feature, since we don't own one to test ret.communityFeature = True - if candidate in [CAR.GOLF, CAR.AUDI_A3]: + if candidate in MQB_CARS: # Set common MQB parameters that will apply globally ret.carName = "volkswagen" ret.radarOffCan = True @@ -35,19 +35,31 @@ class CarInterface(CarInterfaceBase): ret.steerRateCost = 1.0 ret.steerActuatorDelay = 0.05 # Hopefully all MQB racks are similar here ret.steerLimitTimer = 0.4 + ret.steerRatio = 15.6 # Default, let the params learner figure this out ret.lateralTuning.pid.kpBP = [0.] ret.lateralTuning.pid.kiBP = [0.] - ret.mass = 1500 + STD_CARGO_KG - ret.wheelbase = 2.64 - ret.centerToFront = ret.wheelbase * 0.45 - ret.steerRatio = 15.6 ret.lateralTuning.pid.kf = 0.00006 ret.lateralTuning.pid.kpV = [0.6] ret.lateralTuning.pid.kiV = [0.2] tire_stiffness_factor = 1.0 + # Per-chassis tuning values, override tuning defaults here if desired + + if candidate == CAR.AU_A3_MK3: + # Averages of all A3 variants + ret.mass = 1335 + STD_CARGO_KG + ret.wheelbase = 2.61 + + elif candidate == CAR.VW_GOLF_MK7: + # Averages of all Golf variants + ret.mass = 1397 + STD_CARGO_KG + ret.wheelbase = 2.62 + + ret.centerToFront = ret.wheelbase * 0.45 + + ret.enableCamera = True # Stock camera detection doesn't apply to VW ret.transmissionType = car.CarParams.TransmissionType.automatic diff --git a/selfdrive/car/volkswagen/values.py b/selfdrive/car/volkswagen/values.py index d234cad1c6..91ea187eb8 100644 --- a/selfdrive/car/volkswagen/values.py +++ b/selfdrive/car/volkswagen/values.py @@ -1,6 +1,8 @@ # flake8: noqa from selfdrive.car import dbc_dict +from cereal import car +Ecu = car.CarParams.Ecu class CarControllerParams: HCA_STEP = 2 # HCA_01 message frequency 50Hz @@ -46,19 +48,51 @@ MQB_LDW_MESSAGES = { } class CAR: - GOLF = "VOLKSWAGEN GOLF" - AUDI_A3 = "AUDI A3" + AU_A3_MK3 = "AUDI A3 3RD GEN" + VW_GOLF_MK7 = "VOLKSWAGEN GOLF 7TH GEN" + +MQB_CARS = { + CAR.AU_A3_MK3, # Chassis 8V, 2013-2019, includes A3, A3 e-tron, A3 g-tron, S3, RS3 + CAR.VW_GOLF_MK7 # Chassis AU, 2013-2020, includes Golf, Alltrack, Sportwagen, GTI, GTI TCR, GTE, GTD, Clubsport, Golf R +} FINGERPRINTS = { - CAR.GOLF: [{ - 64: 8, 134: 8, 159: 8, 173: 8, 178: 8, 253: 8, 257: 8, 260: 8, 262: 8, 264: 8, 278: 8, 279: 8, 283: 8, 286: 8, 288: 8, 289: 8, 290: 8, 294: 8, 299: 8, 302: 8, 346: 8, 385: 8, 418: 8, 427: 8, 668: 8, 679: 8, 681: 8, 695: 8, 779: 8, 780: 8, 783: 8, 792: 8, 795: 8, 804: 8, 806: 8, 807: 8, 808: 8, 809: 8, 870: 8, 896: 8, 897: 8, 898: 8, 901: 8, 917: 8, 919: 8, 927: 8, 949: 8, 958: 8, 960: 4, 981: 8, 987: 8, 988: 8, 991: 8, 997: 8, 1000: 8, 1019: 8, 1120: 8, 1122: 8, 1123: 8, 1124: 8, 1153: 8, 1162: 8, 1175: 8, 1312: 8, 1385: 8, 1413: 8, 1440: 5, 1514: 8, 1515: 8, 1520: 8, 1529: 8, 1600: 8, 1601: 8, 1603: 8, 1605: 8, 1624: 8, 1626: 8, 1629: 8, 1631: 8, 1646: 8, 1648: 8, 1712: 6, 1714: 8, 1716: 8, 1717: 8, 1719: 8, 1720: 8, 1721: 8 + CAR.AU_A3_MK3: [{ + 64: 8, 134: 8, 159: 8, 173: 8, 178: 8, 253: 8, 257: 8, 260: 8, 262: 8, 278: 8, 279: 8, 283: 8, 285: 8, 286: 8, 288: 8, 289: 8, 290: 8, 294: 8, 295: 8, 299: 8, 302: 8, 346: 8, 418: 8, 427: 8, 506: 8, 679: 8, 681: 8, 695: 8, 779: 8, 780: 8, 783: 8, 787: 8, 788: 8, 789: 8, 792: 8, 802: 8, 804: 8, 806: 8, 807: 8, 808: 8, 809: 8, 846: 8, 847: 8, 870: 8, 896: 8, 897: 8, 898: 8, 901: 8, 917: 8, 919: 8, 949: 8, 958: 8, 960: 4, 981: 8, 987: 8, 988: 8, 991: 8, 997: 8, 1000: 8, 1019: 8, 1122: 8, 1123: 8, 1124: 8, 1153: 8, 1162: 8, 1175: 8, 1312: 8, 1385: 8, 1413: 8, 1440: 5, 1514: 8, 1515: 8, 1520: 8, 1600: 8, 1601: 8, 1603: 8, 1624: 8, 1629: 8, 1631: 8, 1646: 8, 1648: 8, 1712: 6, 1714: 8, 1716: 8, 1717: 8, 1719: 8, 1720: 8, 1721: 8, 1792: 8, 1872: 8, 1976: 8, 1977: 8, 1982: 8, 1985: 8 }], - CAR.AUDI_A3: [{ - 64: 8, 134: 8, 159: 8, 173: 8, 178: 8, 253: 8, 257: 8, 260: 8, 262: 8, 278: 8, 279: 8, 283: 8, 285: 8, 286: 8, 288: 8, 289: 8, 290: 8, 294: 8, 295: 8, 299: 8, 302: 8, 346: 8, 418: 8, 427: 8, 506: 8, 679: 8, 681: 8, 695: 8, 779: 8, 780: 8, 783: 8, 787: 8, 788: 8, 789: 8, 792: 8, 802: 8, 804: 8, 806: 8, 807: 8, 808: 8, 809: 8, 846: 8, 847: 8, 870: 8, 896: 8, 897: 8, 898: 8, 901: 8, 917: 8, 919: 8, 949: 8, 958: 8, 960: 4, 981: 8, 987: 8, 988: 8, 991: 8, 997: 8, 1000: 8, 1019: 8, 1122: 8, 1123: 8, 1124: 8, 1153: 8, 1162: 8, 1175: 8, 1312: 8, 1385: 8, 1413: 8, 1440: 5, 1514: 8, 1515: 8, 1520: 8, 1600: 8, 1601: 8, 1603: 8, 1624: 8, 1629: 8, 1631: 8, 1646: 8, 1648: 8, 1712: 6, 1714: 8, 1716: 8, 1717: 8, 1719: 8, 1720: 8, 1721: 8, 1792: 8, 1872: 8, 1976: 8, 1977: 8, 1982: 8, 1985: 8 + CAR.VW_GOLF_MK7: [{ + 64: 8, 134: 8, 159: 8, 173: 8, 178: 8, 253: 8, 257: 8, 260: 8, 262: 8, 264: 8, 278: 8, 279: 8, 283: 8, 286: 8, 288: 8, 289: 8, 290: 8, 294: 8, 299: 8, 302: 8, 346: 8, 385: 8, 418: 8, 427: 8, 668: 8, 679: 8, 681: 8, 695: 8, 779: 8, 780: 8, 783: 8, 792: 8, 795: 8, 804: 8, 806: 8, 807: 8, 808: 8, 809: 8, 870: 8, 896: 8, 897: 8, 898: 8, 901: 8, 917: 8, 919: 8, 927: 8, 949: 8, 958: 8, 960: 4, 981: 8, 987: 8, 988: 8, 991: 8, 997: 8, 1000: 8, 1019: 8, 1120: 8, 1122: 8, 1123: 8, 1124: 8, 1153: 8, 1162: 8, 1175: 8, 1312: 8, 1385: 8, 1413: 8, 1440: 5, 1514: 8, 1515: 8, 1520: 8, 1529: 8, 1600: 8, 1601: 8, 1603: 8, 1605: 8, 1624: 8, 1626: 8, 1629: 8, 1631: 8, 1646: 8, 1648: 8, 1712: 6, 1714: 8, 1716: 8, 1717: 8, 1719: 8, 1720: 8, 1721: 8 }], } +FW_VERSIONS = { + CAR.VW_GOLF_MK7: { + # Mk7 2013-2017 and Mk7.5 facelift 2018-2020 + (Ecu.engine, 0x7e0, None): [ + b'8V0906259P ', # 2018 Golf R (DJJA) + ], + (Ecu.transmission, 0x7e1, None): [ + b'0GC300012A ', # 2018 Golf R (DQ381) + ], + (Ecu.esp, 0x713, None): [ + b'5Q0614517CR', # 2018 Golf R + ], + (Ecu.srs, 0x715, None): [ + b'5Q0959655J ', # 2018 Golf R + ], + (Ecu.eps, 0x712, None): [ + b'3Q0909144L ', # Shared + ], + (Ecu.fwdRadar, 0x757, None): [ + b'5Q0907572J ', # Shared + ], + (Ecu.fwdCamera, 0x74f, None): [ + b'3Q0980654H ', # Shared + ], + } +} + DBC = { - CAR.GOLF: dbc_dict('vw_mqb_2010', None), - CAR.AUDI_A3: dbc_dict('vw_mqb_2010', None), + CAR.AU_A3_MK3: dbc_dict('vw_mqb_2010', None), + CAR.VW_GOLF_MK7: dbc_dict('vw_mqb_2010', None), }