car interfaces: cleanup tire stiffness calculation
Description
Parameterize tire stiffness scaling, and finish the already-started task of moving stiffness scaling to common interface code. Try to leverage the default 1.0 value where it makes sense. Clean up some duplicate comments.
Depends on commaai/cereal#450. The Float64 is sort of overkill, but Float32 doesn't match the original Python double precision and replay outcomes get wrecked.
First of two planned PRs. Once we stop calling scale_tire_stiffness from two different abstraction layers, we can get rid of 138 car interface references to STD_CARGO_KG in favor of common interface code.
Verification
Process replay will flag the new carParam, but everything else should line up. The refactored code will replace the hardcoded front/rear stiffness values for the mock car, but I don't know of any consequences for that.
Process replay alone isn't enough to validate the change, we need to check 100% of cars match before-and-after. I crafted a small helper script to do that.
#!/usr/bin/env python3
from selfdrive.car import gen_empty_fingerprint
from selfdrive.car.car_helpers import interfaces
from selfdrive.car.fingerprints import all_known_cars
if __name__ == "__main__":
for car in all_known_cars():
CarInterface, CarController, CarState = interfaces[car]
car_fw = []
fingerprints = gen_empty_fingerprint()
CP = CarInterface.get_params(car, fingerprints, car_fw, experimental_long=False, docs=False)
print(f"{CP.carFingerprint}: {CP.tireStiffnessFront=} {CP.tireStiffnessRear=}")
(openpilot-py3.8) jyoung@DESKTOP-6JPRDTA:~/openpilot/selfdrive/debug$ git status | head -n 2
On branch master
Your branch is up to date with 'origin/master'.
(openpilot-py3.8) jyoung@DESKTOP-6JPRDTA:~/openpilot/selfdrive/debug$ ./verify_params.py | sort > /tmp/ts-master-params
(openpilot-py3.8) jyoung@DESKTOP-6JPRDTA:~/openpilot/selfdrive/debug$ git status | head -n 2
On branch ts-cleanup
Your branch is up to date with 'jyoung8607/ts-cleanup'.
(openpilot-py3.8) jyoung@DESKTOP-6JPRDTA:~/openpilot/selfdrive/debug$ ./verify_params.py | sort > /tmp/ts-refactor-params
(openpilot-py3.8) jyoung@DESKTOP-6JPRDTA:~/openpilot$ head -n 5 /tmp/ts-refactor-params
ACURA ILX 2016: CP.tireStiffnessFront=153002.34375 CP.tireStiffnessRear=142048.0
ACURA RDX 2018: CP.tireStiffnessFront=115829.09375 CP.tireStiffnessRear=112223.9375
ACURA RDX 2020: CP.tireStiffnessFront=173345.84375 CP.tireStiffnessRear=190423.796875
AUDI A3 3RD GEN: CP.tireStiffnessFront=177221.796875 CP.tireStiffnessRear=229214.90625
AUDI Q2 1ST GEN: CP.tireStiffnessFront=161559.765625 CP.tireStiffnessRear=208957.984375
(openpilot-py3.8) jyoung@DESKTOP-6JPRDTA:~/openpilot$ md5sum /tmp/ts-master-params
6bce7e6cb0e54c31f2cf3c8aa8cad53e /tmp/ts-master-params
(openpilot-py3.8) jyoung@DESKTOP-6JPRDTA:~/openpilot$ md5sum /tmp/ts-refactor-params
6bce7e6cb0e54c31f2cf3c8aa8cad53e /tmp/ts-refactor-params