From e5328b2a9101e5876db5d3c19dca5c2e556afab1 Mon Sep 17 00:00:00 2001 From: dk Date: Mon, 1 Jul 2019 19:27:33 -0400 Subject: [PATCH 1/7] move civic params out --- selfdrive/car/__init__.py | 32 +++++++++++++++++++++++++- selfdrive/car/chrysler/interface.py | 27 ++++++---------------- selfdrive/car/ford/interface.py | 31 +++++++------------------ selfdrive/car/gm/interface.py | 32 ++++++++++---------------- selfdrive/car/honda/interface.py | 31 +++++++------------------ selfdrive/car/hyundai/interface.py | 30 +++++++------------------ selfdrive/car/subaru/interface.py | 25 +++++---------------- selfdrive/car/toyota/interface.py | 35 +++++++++-------------------- 8 files changed, 89 insertions(+), 154 deletions(-) diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index bb996e5885e37a..46cd2a9bfa70fd 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -1,8 +1,38 @@ # functions common among cars from common.numpy_fast import clip - +from selfdrive.config import Conversions as CV # kg of standard extra cargo to count for drive, gas, etc... STD_CARGO_KG = 136. + +# FIXME: hardcoding honda civic 2016 touring params so they can be used to +# scale unknown params for other cars +class CivicParams: + mass = 2923. * CV.LB_TO_KG + STD_CARGO_KG + wheelbase = 2.70 + centerToFront = wheelbase * 0.4 + centerToRear = wheelbase - centerToFront + rotationalInertia = 2500 + tireStiffnessFront = 192150 + tireStiffnessRear = 202500 + +# TODO: get actual value, for now starting with reasonable value for +# civic and scaling by mass and wheelbase +def scaleRotInertia(mass, wheelbase): + return CivicParams.rotationalInertia * mass * wheelbase ** 2 / (CivicParams.mass * CivicParams.wheelbase ** 2) + +# TODO: start from empirically derived lateral slip stiffness for the civic and scale by +# mass and CG position, so all cars will have approximately similar dyn behaviors +def scaleTireStiffness(mass, wheelbase, center_to_front, tire_stiffness_factor): + center_to_rear = wheelbase - center_to_front + tire_stiffness_front = (CivicParams.tireStiffnessFront * tire_stiffness_factor) * \ + mass / CivicParams.mass * \ + (center_to_rear / wheelbase) / (CivicParams.centerToRear / CivicParams.wheelbase) + + tire_stiffness_rear = (CivicParams.tireStiffnessRear * tire_stiffness_factor) * \ + mass / CivicParams.mass * \ + (center_to_front / wheelbase) / (CivicParams.centerToFront / CivicParams.wheelbase) + + return tire_stiffness_front, tire_stiffness_rear def dbc_dict(pt_dbc, radar_dbc, chassis_dbc=None): return {'pt': pt_dbc, 'radar': radar_dbc, 'chassis': chassis_dbc} diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 6621c7e20ffcdf..dcee8d8a60d684 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.chrysler.carstate import CarState, get_can_parser, get_camera_parser from selfdrive.car.chrysler.values import ECU, check_ecu_msgs, CAR -from selfdrive.car import STD_CARGO_KG +from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness class CarInterface(object): @@ -51,16 +51,6 @@ def get_params(candidate, fingerprint, vin=""): # pedal ret.enableCruise = True - # FIXME: hardcoding honda civic 2016 touring params so they can be used to - # scale unknown params for other cars - mass_civic = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase_civic = 2.70 - centerToFront_civic = wheelbase_civic * 0.4 - centerToRear_civic = wheelbase_civic - centerToFront_civic - rotationalInertia_civic = 2500 - tireStiffnessFront_civic = 85400 * 2.0 - tireStiffnessRear_civic = 90000 * 2.0 - # Speed conversion: 20, 45 mph ret.wheelbase = 3.089 # in meters for Pacifica Hybrid 2017 ret.steerRatio = 16.2 # Pacifica Hybrid 2017 @@ -70,11 +60,13 @@ def get_params(candidate, fingerprint, vin=""): ret.lateralTuning.pid.kf = 0.00006 # full torque for 10 deg at 80mph means 0.00007818594 ret.steerActuatorDelay = 0.1 ret.steerRateCost = 0.7 + tire_stiffness_factor = 0.444 # not optimized yet if candidate in (CAR.JEEP_CHEROKEE, CAR.JEEP_CHEROKEE_2019): ret.wheelbase = 2.91 # in meters ret.steerRatio = 12.7 ret.steerActuatorDelay = 0.2 # in seconds + tire_stiffness_factor = 0.444 # not optimized yet ret.centerToFront = ret.wheelbase * 0.44 @@ -85,20 +77,15 @@ def get_params(candidate, fingerprint, vin=""): ret.minSteerSpeed = 17.5 # m/s 17 on the way up, 13 on the way down once engaged. # TODO allow 2019 cars to steer down to 13 m/s if already engaged. - centerToRear = ret.wheelbase - ret.centerToFront # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = rotationalInertia_civic * \ - ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2) + ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront = tireStiffnessFront_civic * \ - ret.mass / mass_civic * \ - (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic) - ret.tireStiffnessRear = tireStiffnessRear_civic * \ - ret.mass / mass_civic * \ - (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic) + ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 7664d99640eaab..020e7ff68ed703 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -7,7 +7,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.ford.carstate import CarState, get_can_parser from selfdrive.car.ford.values import MAX_ANGLE -from selfdrive.car import STD_CARGO_KG +from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness class CarInterface(object): @@ -51,16 +51,6 @@ def get_params(candidate, fingerprint, vin=""): # pedal ret.enableCruise = True - # FIXME: hardcoding honda civic 2016 touring params so they can be used to - # scale unknown params for other cars - mass_civic = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase_civic = 2.70 - centerToFront_civic = wheelbase_civic * 0.4 - centerToRear_civic = wheelbase_civic - centerToFront_civic - rotationalInertia_civic = 2500 - tireStiffnessFront_civic = 85400 - tireStiffnessRear_civic = 90000 - ret.wheelbase = 2.85 ret.steerRatio = 14.8 ret.mass = 3045. * CV.LB_TO_KG + STD_CARGO_KG @@ -71,30 +61,25 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRateCost = 1.0 f = 1.2 - tireStiffnessFront_civic *= f - tireStiffnessRear_civic *= f + CivicParams.tireStiffnessFront *= f + CivicParams.tireStiffnessRear_civic *= f ret.centerToFront = ret.wheelbase * 0.44 - + tire_stiffness_factor = 0.444 # not optimized # min speed to enable ACC. if car can do stop and go, then set enabling speed # to a negative value, so it won't matter. ret.minEnableSpeed = -1. - centerToRear = ret.wheelbase - ret.centerToFront # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = rotationalInertia_civic * \ - ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2) + ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront = tireStiffnessFront_civic * \ - ret.mass / mass_civic * \ - (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic) - ret.tireStiffnessRear = tireStiffnessRear_civic * \ - ret.mass / mass_civic * \ - (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic) + ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 4a909bc84403ff..70d3936e37826b 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -7,7 +7,7 @@ from selfdrive.car.gm.values import DBC, CAR, STOCK_CONTROL_MSGS, AUDIO_HUD, \ SUPERCRUISE_CARS, AccState from selfdrive.car.gm.carstate import CarState, CruiseButtons, get_powertrain_can_parser -from selfdrive.car import STD_CARGO_KG +from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness class CanBus(object): @@ -70,6 +70,7 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 15.7 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 # wild guess + tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.MALIBU: # supports stop and go, but initial engage must be above 18mph (which include conservatism) @@ -80,6 +81,7 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 15.8 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 # wild guess + tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.HOLDEN_ASTRA: ret.mass = 1363. + STD_CARGO_KG @@ -90,6 +92,7 @@ def get_params(candidate, fingerprint, vin=""): ret.safetyModel = car.CarParams.SafetyModel.gm ret.steerRatio = 15.7 ret.steerRatioRear = 0. + tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.ACADIA: ret.minEnableSpeed = -1. # engage speed is decided by pcm @@ -99,6 +102,7 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 14.4 #end to end is 13.46 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 + tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.BUICK_REGAL: ret.minEnableSpeed = 18 * CV.MPH_TO_MS @@ -108,6 +112,7 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 14.4 # guess for tourx ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 # guess for tourx + tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.CADILLAC_ATS: ret.minEnableSpeed = 18 * CV.MPH_TO_MS @@ -117,6 +122,7 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 15.3 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.49 + tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.CADILLAC_CT6: # engage speed is decided by pcm @@ -127,32 +133,18 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 14.6 # it's 16.3 without rear active steering ret.steerRatioRear = 0. # TODO: there is RAS on this car! ret.centerToFront = ret.wheelbase * 0.465 + tire_stiffness_factor = 0.444 # not optimized yet - # hardcoding honda civic 2016 touring params so they can be used to - # scale unknown params for other cars - mass_civic = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase_civic = 2.70 - centerToFront_civic = wheelbase_civic * 0.4 - centerToRear_civic = wheelbase_civic - centerToFront_civic - rotationalInertia_civic = 2500 - tireStiffnessFront_civic = 85400 - tireStiffnessRear_civic = 90000 - - centerToRear = ret.wheelbase - ret.centerToFront # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = rotationalInertia_civic * \ - ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2) + ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront = tireStiffnessFront_civic * \ - ret.mass / mass_civic * \ - (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic) - ret.tireStiffnessRear = tireStiffnessRear_civic * \ - ret.mass / mass_civic * \ - (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic) + ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # same tuning for Volt and CT6 for now ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 72c85c862cea57..f9f9263f9accb5 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -10,7 +10,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.honda.carstate import CarState, get_can_parser, get_cam_can_parser from selfdrive.car.honda.values import CruiseButtons, CAR, HONDA_BOSCH, AUDIO_HUD, VISUAL_HUD, CAMERA_MSGS -from selfdrive.car import STD_CARGO_KG +from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness from selfdrive.controls.lib.planner import _A_CRUISE_MAX_V_FOLLOWING A_ACC_MAX = max(_A_CRUISE_MAX_V_FOLLOWING) @@ -152,16 +152,6 @@ def get_params(candidate, fingerprint, vin=""): ret.enableCruise = not ret.enableGasInterceptor - # FIXME: hardcoding honda civic 2016 touring params so they can be used to - # scale unknown params for other cars - mass_civic = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase_civic = 2.70 - centerToFront_civic = wheelbase_civic * 0.4 - centerToRear_civic = wheelbase_civic - centerToFront_civic - rotationalInertia_civic = 2500 - tireStiffnessFront_civic = 192150 - tireStiffnessRear_civic = 202500 - # Optimized car params: tire_stiffness_factor and steerRatio are a result of a vehicle # model optimization process. Certain Hondas have an extra steering sensor at the bottom # of the steering rack, which improves controls quality as it removes the steering column @@ -174,9 +164,9 @@ def get_params(candidate, fingerprint, vin=""): if candidate in [CAR.CIVIC, CAR.CIVIC_BOSCH]: stop_and_go = True - ret.mass = mass_civic - ret.wheelbase = wheelbase_civic - ret.centerToFront = centerToFront_civic + ret.mass = CivicParams.mass + ret.wheelbase = CivicParams.wheelbase + ret.centerToFront = CivicParams.centerToFront ret.steerRatio = 14.63 # 10.93 is end-to-end spec tire_stiffness_factor = 1. # Civic at comma has modified steering FW, so different tuning for the Neo in that car @@ -334,20 +324,15 @@ def get_params(candidate, fingerprint, vin=""): # conflict with PCM acc ret.minEnableSpeed = -1. if (stop_and_go or ret.enableGasInterceptor) else 25.5 * CV.MPH_TO_MS - centerToRear = ret.wheelbase - ret.centerToFront # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = rotationalInertia_civic * \ - ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2) + ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront = (tireStiffnessFront_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic) - ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic) + ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index bd99eaa5ac7b91..974e8e7198c1de 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.hyundai.carstate import CarState, get_can_parser, get_camera_parser from selfdrive.car.hyundai.values import CAMERA_MSGS, CAR, get_hud_alerts, FEATURES -from selfdrive.car import STD_CARGO_KG +from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness class CarInterface(object): @@ -51,17 +51,6 @@ def get_params(candidate, fingerprint, vin=""): ret.safetyModel = car.CarParams.SafetyModel.hyundai ret.enableCruise = True # stock acc - # FIXME: hardcoding honda civic 2016 touring params so they can be used to - # scale unknown params for other cars - mass_civic = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase_civic = 2.70 - centerToFront_civic = wheelbase_civic * 0.4 - centerToRear_civic = wheelbase_civic - centerToFront_civic - rotationalInertia_civic = 2500 - tireStiffnessFront_civic = 192150 - tireStiffnessRear_civic = 202500 - tire_stiffness_factor = 1. - ret.steerActuatorDelay = 0.1 # Default delay ret.steerRateCost = 0.5 @@ -82,6 +71,7 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 1985. + STD_CARGO_KG ret.wheelbase = 2.78 ret.steerRatio = 14.4 * 1.1 # 10% higher at the center seems reasonable + tire_stiffness_factor = 0.444 # not optimized yet ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] ret.minSteerSpeed = 0. @@ -99,6 +89,7 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 2060. + STD_CARGO_KG ret.wheelbase = 3.01 ret.steerRatio = 16.5 + tire_stiffness_factor = 0.444 # not optimized yet ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16], [0.01]] ret.minSteerSpeed = 35 * CV.MPH_TO_MS @@ -115,6 +106,7 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 1825. + STD_CARGO_KG ret.wheelbase = 2.78 ret.steerRatio = 14.4 * 1.15 # 15% higher at the center seems reasonable + tire_stiffness_factor = 0.444 # not optimized yet ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] ret.minSteerSpeed = 0. @@ -129,21 +121,15 @@ def get_params(candidate, fingerprint, vin=""): ret.centerToFront = ret.wheelbase * 0.4 - centerToRear = ret.wheelbase - ret.centerToFront - # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = rotationalInertia_civic * \ - ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2) + ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront = (tireStiffnessFront_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic) - ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic) + ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index a609ee9092c115..16e561bd289008 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.subaru.values import CAR from selfdrive.car.subaru.carstate import CarState, get_powertrain_can_parser, get_camera_can_parser -from selfdrive.car import STD_CARGO_KG +from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness class CarInterface(object): @@ -84,30 +84,15 @@ def get_params(candidate, fingerprint, vin=""): # end from gm - # hardcoding honda civic 2016 touring params so they can be used to - # scale unknown params for other cars - mass_civic = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase_civic = 2.70 - centerToFront_civic = wheelbase_civic * 0.4 - centerToRear_civic = wheelbase_civic - centerToFront_civic - rotationalInertia_civic = 2500 - tireStiffnessFront_civic = 192150 - tireStiffnessRear_civic = 202500 - centerToRear = ret.wheelbase - ret.centerToFront - # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = rotationalInertia_civic * \ - ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2) + ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront = (tireStiffnessFront_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic) - ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic) + ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) return ret diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 83bf921d95d6dd..fe177aa615d09f 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.toyota.carstate import CarState, get_can_parser, get_cam_can_parser from selfdrive.car.toyota.values import ECU, check_ecu_msgs, CAR, NO_STOP_TIMER_CAR -from selfdrive.car import STD_CARGO_KG +from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness from selfdrive.swaglog import cloudlog @@ -54,16 +54,6 @@ def get_params(candidate, fingerprint, vin=""): # pedal ret.enableCruise = not ret.enableGasInterceptor - # FIXME: hardcoding honda civic 2016 touring params so they can be used to - # scale unknown params for other cars - mass_civic = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase_civic = 2.70 - centerToFront_civic = wheelbase_civic * 0.4 - centerToRear_civic = wheelbase_civic - centerToFront_civic - rotationalInertia_civic = 2500 - tireStiffnessFront_civic = 192150 - tireStiffnessRear_civic = 202500 - ret.steerActuatorDelay = 0.12 # Default delay, Prius has larger delay if candidate != CAR.PRIUS: ret.lateralTuning.init('pid') @@ -100,7 +90,7 @@ def get_params(candidate, fingerprint, vin=""): ret.safetyParam = 100 ret.wheelbase = 2.70 ret.steerRatio = 17.8 - tire_stiffness_factor = 0.444 + tire_stiffness_factor = 0.444 # not optimized yet ret.mass = 2860. * CV.LB_TO_KG + STD_CARGO_KG # mean between normal and hybrid ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2], [0.05]] ret.lateralTuning.pid.kf = 0.00003 # full torque for 20 deg at 80mph means 0.00007818594 @@ -140,7 +130,7 @@ def get_params(candidate, fingerprint, vin=""): ret.safetyParam = 73 ret.wheelbase = 2.78 ret.steerRatio = 16.0 - tire_stiffness_factor = 0.444 # not optimized yet + tire_stiffness_factor = 0.444 # not optimized yet ret.mass = 4607. * CV.LB_TO_KG + STD_CARGO_KG #mean between normal and hybrid limited ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.05]] ret.lateralTuning.pid.kf = 0.00006 @@ -170,7 +160,7 @@ def get_params(candidate, fingerprint, vin=""): ret.safetyParam = 73 ret.wheelbase = 2.63906 ret.steerRatio = 13.9 - tire_stiffness_factor = 0.444 + tire_stiffness_factor = 0.444 # not optimized yet ret.mass = 3060. * CV.LB_TO_KG + STD_CARGO_KG ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]] ret.lateralTuning.pid.kf = 0.00007818594 @@ -179,8 +169,8 @@ def get_params(candidate, fingerprint, vin=""): stop_and_go = True ret.safetyParam = 73 ret.wheelbase = 2.8702 - ret.steerRatio = 16.0 #not optimized - tire_stiffness_factor = 0.444 + ret.steerRatio = 16.0 # not optimized + tire_stiffness_factor = 0.444 # not optimized yet ret.mass = 3704. * CV.LB_TO_KG + STD_CARGO_KG ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]] ret.lateralTuning.pid.kf = 0.00007818594 @@ -195,20 +185,15 @@ def get_params(candidate, fingerprint, vin=""): # to a negative value, so it won't matter. ret.minEnableSpeed = -1. if (stop_and_go or ret.enableGasInterceptor) else 19. * CV.MPH_TO_MS - centerToRear = ret.wheelbase - ret.centerToFront # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = rotationalInertia_civic * \ - ret.mass * ret.wheelbase**2 / (mass_civic * wheelbase_civic**2) + ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront = (tireStiffnessFront_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (centerToRear / ret.wheelbase) / (centerToRear_civic / wheelbase_civic) - ret.tireStiffnessRear = (tireStiffnessRear_civic * tire_stiffness_factor) * \ - ret.mass / mass_civic * \ - (ret.centerToFront / ret.wheelbase) / (centerToFront_civic / wheelbase_civic) + ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. From d7e0f25f627500436f84f4fc7d4f41521adcc87d Mon Sep 17 00:00:00 2001 From: dk Date: Mon, 1 Jul 2019 19:37:13 -0400 Subject: [PATCH 2/7] fix variable name --- selfdrive/car/ford/interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 020e7ff68ed703..8878cdced07d9a 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -62,7 +62,7 @@ def get_params(candidate, fingerprint, vin=""): f = 1.2 CivicParams.tireStiffnessFront *= f - CivicParams.tireStiffnessRear_civic *= f + CivicParams.tireStiffnessRear *= f ret.centerToFront = ret.wheelbase * 0.44 tire_stiffness_factor = 0.444 # not optimized From 6f024727f01f9a004aa3e5e5930e37c468c8e6c0 Mon Sep 17 00:00:00 2001 From: dk Date: Mon, 1 Jul 2019 19:49:10 -0400 Subject: [PATCH 3/7] simplify ford scaling --- selfdrive/car/ford/interface.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 8878cdced07d9a..796f755dd91389 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -59,11 +59,6 @@ def get_params(candidate, fingerprint, vin=""): ret.lateralTuning.pid.kf = 1. / MAX_ANGLE # MAX Steer angle to normalize FF ret.steerActuatorDelay = 0.1 # Default delay, not measured yet ret.steerRateCost = 1.0 - - f = 1.2 - CivicParams.tireStiffnessFront *= f - CivicParams.tireStiffnessRear *= f - ret.centerToFront = ret.wheelbase * 0.44 tire_stiffness_factor = 0.444 # not optimized From ea8d291fba447de213879cf70aad84b5e926e146 Mon Sep 17 00:00:00 2001 From: dk Date: Mon, 1 Jul 2019 20:13:46 -0400 Subject: [PATCH 4/7] cleanup --- selfdrive/car/__init__.py | 30 ++++++++++++++--------------- selfdrive/car/chrysler/interface.py | 10 +++++----- selfdrive/car/ford/interface.py | 10 +++++----- selfdrive/car/gm/interface.py | 10 +++++----- selfdrive/car/honda/interface.py | 16 +++++++-------- selfdrive/car/hyundai/interface.py | 10 +++++----- selfdrive/car/subaru/interface.py | 10 +++++----- selfdrive/car/toyota/interface.py | 10 +++++----- 8 files changed, 52 insertions(+), 54 deletions(-) diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index 46cd2a9bfa70fd..bc0ef0f7a143fc 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -7,30 +7,28 @@ # FIXME: hardcoding honda civic 2016 touring params so they can be used to # scale unknown params for other cars class CivicParams: - mass = 2923. * CV.LB_TO_KG + STD_CARGO_KG - wheelbase = 2.70 - centerToFront = wheelbase * 0.4 - centerToRear = wheelbase - centerToFront - rotationalInertia = 2500 - tireStiffnessFront = 192150 - tireStiffnessRear = 202500 + MASS = 2923. * CV.LB_TO_KG + STD_CARGO_KG + WHEELBASE = 2.70 + CENTER_TO_FRONT = WHEELBASE * 0.4 + CENTER_TO_REAR = WHEELBASE - CENTER_TO_FRONT + ROTATIONAL_INERTIA = 2500 + TIRE_STIFFNESS_FRONT = 192150 + TIRE_STIFFNESS_REAR = 202500 # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase -def scaleRotInertia(mass, wheelbase): - return CivicParams.rotationalInertia * mass * wheelbase ** 2 / (CivicParams.mass * CivicParams.wheelbase ** 2) +def scale_rot_inertia(mass, wheelbase): + return CivicParams.ROTATIONAL_INERTIA * mass * wheelbase ** 2 / (CivicParams.MASS * CivicParams.WHEELBASE ** 2) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors -def scaleTireStiffness(mass, wheelbase, center_to_front, tire_stiffness_factor): +def scale_tire_stiffness(mass, wheelbase, center_to_front, tire_stiffness_factor): center_to_rear = wheelbase - center_to_front - tire_stiffness_front = (CivicParams.tireStiffnessFront * tire_stiffness_factor) * \ - mass / CivicParams.mass * \ - (center_to_rear / wheelbase) / (CivicParams.centerToRear / CivicParams.wheelbase) + tire_stiffness_front = (CivicParams.TIRE_STIFFNESS_FRONT * tire_stiffness_factor) * mass / CivicParams.MASS * \ + (center_to_rear / wheelbase) / (CivicParams.CENTER_TO_REAR / CivicParams.WHEELBASE) - tire_stiffness_rear = (CivicParams.tireStiffnessRear * tire_stiffness_factor) * \ - mass / CivicParams.mass * \ - (center_to_front / wheelbase) / (CivicParams.centerToFront / CivicParams.wheelbase) + tire_stiffness_rear = (CivicParams.TIRE_STIFFNESS_REAR * tire_stiffness_factor) * mass / CivicParams.MASS * \ + (center_to_front / wheelbase) / (CivicParams.CENTER_TO_FRONT / CivicParams.WHEELBASE) return tire_stiffness_front, tire_stiffness_rear diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index dcee8d8a60d684..acb72cb242bc8e 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.chrysler.carstate import CarState, get_can_parser, get_camera_parser from selfdrive.car.chrysler.values import ECU, check_ecu_msgs, CAR -from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness class CarInterface(object): @@ -79,13 +79,13 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 796f755dd91389..b4da91f4515a52 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -7,7 +7,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.ford.carstate import CarState, get_can_parser from selfdrive.car.ford.values import MAX_ANGLE -from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness class CarInterface(object): @@ -68,13 +68,13 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 70d3936e37826b..c4f4e3b1ae7843 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -7,7 +7,7 @@ from selfdrive.car.gm.values import DBC, CAR, STOCK_CONTROL_MSGS, AUDIO_HUD, \ SUPERCRUISE_CARS, AccState from selfdrive.car.gm.carstate import CarState, CruiseButtons, get_powertrain_can_parser -from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness class CanBus(object): @@ -138,13 +138,13 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # same tuning for Volt and CT6 for now ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index f9f9263f9accb5..8d001cffd93e54 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -10,7 +10,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.honda.carstate import CarState, get_can_parser, get_cam_can_parser from selfdrive.car.honda.values import CruiseButtons, CAR, HONDA_BOSCH, AUDIO_HUD, VISUAL_HUD, CAMERA_MSGS -from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness +from selfdrive.car import STD_CARGO_KG, CivicParams, scale_rot_inertia, scale_tire_stiffness from selfdrive.controls.lib.planner import _A_CRUISE_MAX_V_FOLLOWING A_ACC_MAX = max(_A_CRUISE_MAX_V_FOLLOWING) @@ -164,9 +164,9 @@ def get_params(candidate, fingerprint, vin=""): if candidate in [CAR.CIVIC, CAR.CIVIC_BOSCH]: stop_and_go = True - ret.mass = CivicParams.mass - ret.wheelbase = CivicParams.wheelbase - ret.centerToFront = CivicParams.centerToFront + ret.mass = CivicParams.MASS + ret.wheelbase = CivicParams.WHEELBASE + ret.centerToFront = CivicParams.CENTER_TO_FRONT ret.steerRatio = 14.63 # 10.93 is end-to-end spec tire_stiffness_factor = 1. # Civic at comma has modified steering FW, so different tuning for the Neo in that car @@ -326,13 +326,13 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 974e8e7198c1de..91cfd46f909cf5 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.hyundai.carstate import CarState, get_can_parser, get_camera_parser from selfdrive.car.hyundai.values import CAMERA_MSGS, CAR, get_hud_alerts, FEATURES -from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness class CarInterface(object): @@ -123,13 +123,13 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 16e561bd289008..9f7df99114e22b 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.subaru.values import CAR from selfdrive.car.subaru.carstate import CarState, get_powertrain_can_parser, get_camera_can_parser -from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness class CarInterface(object): @@ -86,13 +86,13 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) return ret diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index fe177aa615d09f..ddbd32c719124e 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -6,7 +6,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.car.toyota.carstate import CarState, get_can_parser, get_cam_can_parser from selfdrive.car.toyota.values import ECU, check_ecu_msgs, CAR, NO_STOP_TIMER_CAR -from selfdrive.car import STD_CARGO_KG, CivicParams, scaleRotInertia, scaleTireStiffness +from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness from selfdrive.swaglog import cloudlog @@ -187,13 +187,13 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scaleRotInertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scaleTireStiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, + center_to_front=ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. From aa498a40b74d75835a9437094ec6ed2bf96602c8 Mon Sep 17 00:00:00 2001 From: dk Date: Tue, 2 Jul 2019 15:12:22 -0400 Subject: [PATCH 5/7] remove import dependency --- selfdrive/car/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index bc0ef0f7a143fc..3f49cd503f9e1e 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -1,13 +1,14 @@ # functions common among cars from common.numpy_fast import clip -from selfdrive.config import Conversions as CV + # kg of standard extra cargo to count for drive, gas, etc... STD_CARGO_KG = 136. +LB_TO_KG = 0.453592 # FIXME: hardcoding honda civic 2016 touring params so they can be used to # scale unknown params for other cars class CivicParams: - MASS = 2923. * CV.LB_TO_KG + STD_CARGO_KG + MASS = 2923. * LB_TO_KG + STD_CARGO_KG WHEELBASE = 2.70 CENTER_TO_FRONT = WHEELBASE * 0.4 CENTER_TO_REAR = WHEELBASE - CENTER_TO_FRONT From 0206f71cdb27d8e75b0408d8ff1b7f7d190acf61 Mon Sep 17 00:00:00 2001 From: dk Date: Tue, 2 Jul 2019 15:55:07 -0400 Subject: [PATCH 6/7] requested changes --- selfdrive/car/__init__.py | 5 ++--- selfdrive/car/chrysler/interface.py | 8 ++------ selfdrive/car/ford/interface.py | 7 +++---- selfdrive/car/gm/interface.py | 13 +++---------- selfdrive/car/honda/interface.py | 5 ++--- selfdrive/car/hyundai/interface.py | 12 ++---------- selfdrive/car/subaru/interface.py | 7 ++----- selfdrive/car/toyota/interface.py | 5 ++--- 8 files changed, 18 insertions(+), 44 deletions(-) diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index 3f49cd503f9e1e..3b259c622289fd 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -3,12 +3,11 @@ # kg of standard extra cargo to count for drive, gas, etc... STD_CARGO_KG = 136. -LB_TO_KG = 0.453592 # FIXME: hardcoding honda civic 2016 touring params so they can be used to # scale unknown params for other cars class CivicParams: - MASS = 2923. * LB_TO_KG + STD_CARGO_KG + MASS = 1326. + STD_CARGO_KG WHEELBASE = 2.70 CENTER_TO_FRONT = WHEELBASE * 0.4 CENTER_TO_REAR = WHEELBASE - CENTER_TO_FRONT @@ -23,7 +22,7 @@ def scale_rot_inertia(mass, wheelbase): # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors -def scale_tire_stiffness(mass, wheelbase, center_to_front, tire_stiffness_factor): +def scale_tire_stiffness(mass, wheelbase, center_to_front, tire_stiffness_factor=1.0): center_to_rear = wheelbase - center_to_front tire_stiffness_front = (CivicParams.TIRE_STIFFNESS_FRONT * tire_stiffness_factor) * mass / CivicParams.MASS * \ (center_to_rear / wheelbase) / (CivicParams.CENTER_TO_REAR / CivicParams.WHEELBASE) diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index acb72cb242bc8e..793f7320844148 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -60,13 +60,11 @@ def get_params(candidate, fingerprint, vin=""): ret.lateralTuning.pid.kf = 0.00006 # full torque for 10 deg at 80mph means 0.00007818594 ret.steerActuatorDelay = 0.1 ret.steerRateCost = 0.7 - tire_stiffness_factor = 0.444 # not optimized yet if candidate in (CAR.JEEP_CHEROKEE, CAR.JEEP_CHEROKEE_2019): ret.wheelbase = 2.91 # in meters ret.steerRatio = 12.7 ret.steerActuatorDelay = 0.2 # in seconds - tire_stiffness_factor = 0.444 # not optimized yet ret.centerToFront = ret.wheelbase * 0.44 @@ -79,13 +77,11 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront) # no rear steering, at least on the listed cars above ret.steerRatioRear = 0. diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index b4da91f4515a52..0f3bbc33cc2b84 100755 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -60,7 +60,7 @@ def get_params(candidate, fingerprint, vin=""): ret.steerActuatorDelay = 0.1 # Default delay, not measured yet ret.steerRateCost = 1.0 ret.centerToFront = ret.wheelbase * 0.44 - tire_stiffness_factor = 0.444 # not optimized + tire_stiffness_factor = 0.5328 # min speed to enable ACC. if car can do stop and go, then set enabling speed # to a negative value, so it won't matter. @@ -68,12 +68,11 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index c4f4e3b1ae7843..c066a6523f2213 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -60,6 +60,7 @@ def get_params(candidate, fingerprint, vin=""): # or camera is on powertrain bus (LKA cars without ACC). ret.enableCamera = not any(x for x in STOCK_CONTROL_MSGS[candidate] if x in fingerprint) ret.openpilotLongitudinalControl = ret.enableCamera + tire_stiffness_factor = 0.444 # not optimized yet if candidate == CAR.VOLT: # supports stop and go, but initial engage must be above 18mph (which include conservatism) @@ -70,7 +71,6 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 15.7 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 # wild guess - tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.MALIBU: # supports stop and go, but initial engage must be above 18mph (which include conservatism) @@ -81,7 +81,6 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 15.8 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 # wild guess - tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.HOLDEN_ASTRA: ret.mass = 1363. + STD_CARGO_KG @@ -92,7 +91,6 @@ def get_params(candidate, fingerprint, vin=""): ret.safetyModel = car.CarParams.SafetyModel.gm ret.steerRatio = 15.7 ret.steerRatioRear = 0. - tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.ACADIA: ret.minEnableSpeed = -1. # engage speed is decided by pcm @@ -102,7 +100,6 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 14.4 #end to end is 13.46 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 - tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.BUICK_REGAL: ret.minEnableSpeed = 18 * CV.MPH_TO_MS @@ -112,7 +109,6 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 14.4 # guess for tourx ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.4 # guess for tourx - tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.CADILLAC_ATS: ret.minEnableSpeed = 18 * CV.MPH_TO_MS @@ -122,7 +118,6 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 15.3 ret.steerRatioRear = 0. ret.centerToFront = ret.wheelbase * 0.49 - tire_stiffness_factor = 0.444 # not optimized yet elif candidate == CAR.CADILLAC_CT6: # engage speed is decided by pcm @@ -133,17 +128,15 @@ def get_params(candidate, fingerprint, vin=""): ret.steerRatio = 14.6 # it's 16.3 without rear active steering ret.steerRatioRear = 0. # TODO: there is RAS on this car! ret.centerToFront = ret.wheelbase * 0.465 - tire_stiffness_factor = 0.444 # not optimized yet # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, tire_stiffness_factor=tire_stiffness_factor) # same tuning for Volt and CT6 for now diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 8d001cffd93e54..93aaf0182b7db6 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -326,12 +326,11 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 91cfd46f909cf5..5c05892b536cce 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -61,7 +61,6 @@ def get_params(candidate, fingerprint, vin=""): # Values from optimizer ret.steerRatio = 16.55 # 13.8 is spec end-to-end - tire_stiffness_factor = 0.82 ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[9., 22.], [9., 22.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2, 0.35], [0.05, 0.09]] @@ -71,7 +70,6 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 1985. + STD_CARGO_KG ret.wheelbase = 2.78 ret.steerRatio = 14.4 * 1.1 # 10% higher at the center seems reasonable - tire_stiffness_factor = 0.444 # not optimized yet ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] ret.minSteerSpeed = 0. @@ -80,7 +78,6 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 1275. + STD_CARGO_KG ret.wheelbase = 2.7 ret.steerRatio = 13.73 #Spec - tire_stiffness_factor = 0.385 ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] ret.minSteerSpeed = 32 * CV.MPH_TO_MS @@ -89,7 +86,6 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 2060. + STD_CARGO_KG ret.wheelbase = 3.01 ret.steerRatio = 16.5 - tire_stiffness_factor = 0.444 # not optimized yet ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.16], [0.01]] ret.minSteerSpeed = 35 * CV.MPH_TO_MS @@ -98,7 +94,6 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 3558. * CV.LB_TO_KG ret.wheelbase = 2.80 ret.steerRatio = 13.75 - tire_stiffness_factor = 0.5 ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] elif candidate == CAR.KIA_STINGER: @@ -106,7 +101,6 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 1825. + STD_CARGO_KG ret.wheelbase = 2.78 ret.steerRatio = 14.4 * 1.15 # 15% higher at the center seems reasonable - tire_stiffness_factor = 0.444 # not optimized yet ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] ret.minSteerSpeed = 0. @@ -123,13 +117,11 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront) # no rear steering, at least on the listed cars above diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 9f7df99114e22b..e9d9c117fc714c 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -58,7 +58,6 @@ def get_params(candidate, fingerprint, vin=""): ret.wheelbase = 2.67 ret.centerToFront = ret.wheelbase * 0.5 ret.steerRatio = 15 - tire_stiffness_factor = 1.0 ret.steerActuatorDelay = 0.4 # end-to-end angle controller ret.lateralTuning.pid.kf = 0.00005 ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0., 20.], [0., 20.]] @@ -86,13 +85,11 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, - tire_stiffness_factor=tire_stiffness_factor) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront) return ret diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index ddbd32c719124e..a1cffae9594942 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -187,12 +187,11 @@ def get_params(candidate, fingerprint, vin=""): # TODO: get actual value, for now starting with reasonable value for # civic and scaling by mass and wheelbase - ret.rotationalInertia = scale_rot_inertia(mass=ret.mass, wheelbase=ret.wheelbase) + ret.rotationalInertia = scale_rot_inertia(ret.mass, ret.wheelbase) # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(mass=ret.mass, wheelbase=ret.wheelbase, - center_to_front=ret.centerToFront, + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above From 44b8d0e374afd90b68f259dc63ddbda24e91c21f Mon Sep 17 00:00:00 2001 From: dk Date: Tue, 2 Jul 2019 20:07:37 -0400 Subject: [PATCH 7/7] keep hyundai --- selfdrive/car/hyundai/interface.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 5c05892b536cce..67ca2261ff7f17 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -53,6 +53,7 @@ def get_params(candidate, fingerprint, vin=""): ret.steerActuatorDelay = 0.1 # Default delay ret.steerRateCost = 0.5 + tire_stiffness_factor = 1. if candidate == CAR.SANTA_FE: ret.lateralTuning.pid.kf = 0.00005 @@ -61,6 +62,7 @@ def get_params(candidate, fingerprint, vin=""): # Values from optimizer ret.steerRatio = 16.55 # 13.8 is spec end-to-end + tire_stiffness_factor = 0.82 ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[9., 22.], [9., 22.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.2, 0.35], [0.05, 0.09]] @@ -78,6 +80,7 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 1275. + STD_CARGO_KG ret.wheelbase = 2.7 ret.steerRatio = 13.73 #Spec + tire_stiffness_factor = 0.385 ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] ret.minSteerSpeed = 32 * CV.MPH_TO_MS @@ -94,6 +97,7 @@ def get_params(candidate, fingerprint, vin=""): ret.mass = 3558. * CV.LB_TO_KG ret.wheelbase = 2.80 ret.steerRatio = 13.75 + tire_stiffness_factor = 0.5 ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0.], [0.]] ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.25], [0.05]] elif candidate == CAR.KIA_STINGER: @@ -121,7 +125,8 @@ def get_params(candidate, fingerprint, vin=""): # TODO: start from empirically derived lateral slip stiffness for the civic and scale by # mass and CG position, so all cars will have approximately similar dyn behaviors - ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront) + ret.tireStiffnessFront, ret.tireStiffnessRear = scale_tire_stiffness(ret.mass, ret.wheelbase, ret.centerToFront, + tire_stiffness_factor=tire_stiffness_factor) # no rear steering, at least on the listed cars above