mypy can detect return type of CS.update() now

pull/33208/head
Shane Smiskol 9 months ago
parent 12d89d0036
commit 2c7baf348f
  1. 2
      selfdrive/car/body/carstate.py
  2. 14
      selfdrive/car/body/interface.py
  3. 2
      selfdrive/car/chrysler/carstate.py
  4. 5
      selfdrive/car/chrysler/interface.py
  5. 2
      selfdrive/car/ford/carstate.py
  6. 5
      selfdrive/car/ford/interface.py
  7. 2
      selfdrive/car/gm/carstate.py
  8. 5
      selfdrive/car/gm/interface.py
  9. 2
      selfdrive/car/honda/carstate.py
  10. 5
      selfdrive/car/honda/interface.py
  11. 4
      selfdrive/car/hyundai/carstate.py
  12. 5
      selfdrive/car/hyundai/interface.py
  13. 2
      selfdrive/car/mazda/carstate.py
  14. 4
      selfdrive/car/mazda/interface.py
  15. 2
      selfdrive/car/mock/interface.py
  16. 2
      selfdrive/car/nissan/carstate.py
  17. 4
      selfdrive/car/nissan/interface.py
  18. 2
      selfdrive/car/subaru/carstate.py
  19. 15
      selfdrive/car/subaru/interface.py
  20. 2
      selfdrive/car/tesla/carstate.py
  21. 18
      selfdrive/car/tesla/interface.py
  22. 4
      selfdrive/car/volkswagen/carstate.py
  23. 7
      selfdrive/car/volkswagen/interface.py

@ -6,7 +6,7 @@ from openpilot.selfdrive.car.body.values import DBC
STARTUP_TICKS = 100
class CarState(CarStateBase):
def update(self, cp):
def update(self, cp) -> structs.CarState:
ret = structs.CarState()
ret.wheelSpeeds.fl = cp.vl['MOTORS_DATA']['SPEED_L']

@ -1,16 +1,18 @@
import math
from cereal import car
from openpilot.selfdrive.car import DT_CTRL, get_safety_config
from openpilot.selfdrive.car.structs import CarParams
from openpilot.selfdrive.car import DT_CTRL, get_safety_config, structs
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.car.body.carstate import CarState
from openpilot.selfdrive.car.body.values import SPEED_FROM_RPM
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
ret.notCar = True
ret.carName = "body"
ret.safetyConfigs = [get_safety_config(CarParams.SafetyModel.body)]
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.body)]
ret.minSteerSpeed = -math.inf
ret.maxLateralAccel = math.inf # TODO: set to a reasonable value
@ -21,11 +23,11 @@ class CarInterface(CarInterfaceBase):
ret.radarUnavailable = True
ret.openpilotLongitudinalControl = True
ret.steerControlType = CarParams.SteerControlType.angle
ret.steerControlType = structs.CarParams.SteerControlType.angle
return ret
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp)
# wait for everything to init first

@ -24,7 +24,7 @@ class CarState(CarStateBase):
self.prev_distance_button = 0
self.distance_button = 0
def update(self, cp, cp_cam):
def update(self, cp, cp_cam) -> structs.CarState:
ret = structs.CarState()

@ -2,6 +2,7 @@
from cereal import car
from panda import Panda
from openpilot.selfdrive.car import create_button_events, get_safety_config, structs
from openpilot.selfdrive.car.chrysler.carstate import CarState
from openpilot.selfdrive.car.chrysler.values import CAR, RAM_HD, RAM_DT, RAM_CARS, ChryslerFlags
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
@ -9,6 +10,8 @@ ButtonType = structs.CarState.ButtonEvent.Type
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
ret.carName = "chrysler"
@ -76,7 +79,7 @@ class CarInterface(CarInterfaceBase):
return ret
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam)
ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

@ -22,7 +22,7 @@ class CarState(CarStateBase):
self.prev_distance_button = 0
self.distance_button = 0
def update(self, cp, cp_cam):
def update(self, cp, cp_cam) -> structs.CarState:
ret = structs.CarState()
# Occasionally on startup, the ABS module recalibrates the steering pinion offset, so we need to block engagement

@ -2,6 +2,7 @@ from cereal import car
from panda import Panda
from openpilot.selfdrive.car import create_button_events, get_safety_config, structs
from openpilot.selfdrive.car.conversions import Conversions as CV
from openpilot.selfdrive.car.ford.carstate import CarState
from openpilot.selfdrive.car.ford.fordcan import CanBus
from openpilot.selfdrive.car.ford.values import Ecu, FordFlags
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
@ -12,6 +13,8 @@ GearShifter = structs.CarState.GearShifter
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
ret.carName = "ford"
@ -67,7 +70,7 @@ class CarInterface(CarInterfaceBase):
ret.centerToFront = ret.wheelbase * 0.44
return ret
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam)
ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

@ -29,7 +29,7 @@ class CarState(CarStateBase):
self.prev_distance_button = 0
self.distance_button = 0
def update(self, pt_cp, cam_cp, loopback_cp):
def update(self, pt_cp, cam_cp, loopback_cp) -> structs.CarState:
ret = structs.CarState()
self.prev_cruise_buttons = self.cruise_buttons

@ -8,6 +8,7 @@ from panda import Panda
from openpilot.common.basedir import BASEDIR
from openpilot.selfdrive.car import create_button_events, get_safety_config, get_friction, structs
from openpilot.selfdrive.car.conversions import Conversions as CV
from openpilot.selfdrive.car.gm.carstate import CarState
from openpilot.selfdrive.car.gm.radar_interface import RADAR_HEADER_MSG
from openpilot.selfdrive.car.gm.values import CAR, CruiseButtons, CarControllerParams, EV_CAR, CAMERA_ACC_CAR, CanBus
from openpilot.selfdrive.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, FRICTION_THRESHOLD, LatControlInputs, NanoFFModel
@ -31,6 +32,8 @@ NEURAL_PARAMS_PATH = os.path.join(BASEDIR, 'selfdrive/car/torque_data/neural_ff_
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def get_pid_accel_limits(CP, current_speed, cruise_speed):
return CarControllerParams.ACCEL_MIN, CarControllerParams.ACCEL_MAX
@ -202,7 +205,7 @@ class CarInterface(CarInterfaceBase):
return ret
# returns a car.CarState
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam, self.cp_loopback)
# Don't add event if transitioning from INIT, unless it's to an actual button

@ -104,7 +104,7 @@ class CarState(CarStateBase):
# However, on cars without a digital speedometer this is not always present (HRV, FIT, CRV 2016, ILX and RDX)
self.dash_speed_seen = False
def update(self, cp, cp_cam, cp_body):
def update(self, cp, cp_cam, cp_body) -> structs.CarState:
ret = structs.CarState()
# car params

@ -4,6 +4,7 @@ from panda import Panda
from openpilot.selfdrive.car import create_button_events, get_safety_config, structs
from openpilot.selfdrive.car.conversions import Conversions as CV
from openpilot.selfdrive.car.helpers import interp
from openpilot.selfdrive.car.honda.carstate import CarState
from openpilot.selfdrive.car.honda.hondacan import CanBus
from openpilot.selfdrive.car.honda.values import CarControllerParams, CruiseButtons, CruiseSettings, HondaFlags, CAR, HONDA_BOSCH, \
HONDA_NIDEC_ALT_SCM_MESSAGES, HONDA_BOSCH_RADARLESS
@ -20,6 +21,8 @@ SETTINGS_BUTTONS_DICT = {CruiseSettings.DISTANCE: ButtonType.gapAdjustCruise, Cr
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def get_pid_accel_limits(CP, current_speed, cruise_speed):
if CP.carFingerprint in HONDA_BOSCH:
@ -222,7 +225,7 @@ class CarInterface(CarInterfaceBase):
disable_ecu(can_recv, can_send, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03')
# returns a car.CarState
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam, self.cp_body)
ret.buttonEvents = [

@ -52,7 +52,7 @@ class CarState(CarStateBase):
self.params = CarControllerParams(CP)
def update(self, cp, cp_cam):
def update(self, cp, cp_cam) -> structs.CarState:
if self.CP.carFingerprint in CANFD_CAR:
return self.update_canfd(cp, cp_cam)
@ -168,7 +168,7 @@ class CarState(CarStateBase):
return ret
def update_canfd(self, cp, cp_cam):
def update_canfd(self, cp, cp_cam) -> structs.CarState:
ret = structs.CarState()
self.is_metric = cp.vl["CRUISE_BUTTONS_ALT"]["DISTANCE_UNIT"] != 1

@ -1,6 +1,7 @@
from cereal import car
from panda import Panda
from openpilot.selfdrive.car import create_button_events, get_safety_config, structs
from openpilot.selfdrive.car.hyundai.carstate import CarState
from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus
from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CANFD_CAR, CAMERA_SCC_CAR, CANFD_RADAR_SCC_CAR, \
CANFD_UNSUPPORTED_LONGITUDINAL_CAR, EV_CAR, HYBRID_CAR, LEGACY_SAFETY_MODE_CAR, \
@ -18,6 +19,8 @@ BUTTONS_DICT = {Buttons.RES_ACCEL: ButtonType.accelCruise, Buttons.SET_DECEL: Bu
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
ret.carName = "hyundai"
@ -150,7 +153,7 @@ class CarInterface(CarInterfaceBase):
if CP.flags & HyundaiFlags.ENABLE_BLINKERS:
disable_ecu(can_recv, can_send, bus=CanBus(CP).ECAN, addr=0x7B1, com_cont_req=b'\x28\x83\x01')
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam)
if self.CS.CP.openpilotLongitudinalControl:

@ -21,7 +21,7 @@ class CarState(CarStateBase):
self.prev_distance_button = 0
self.distance_button = 0
def update(self, cp, cp_cam):
def update(self, cp, cp_cam) -> structs.CarState:
ret = structs.CarState()

@ -2,6 +2,7 @@
from cereal import car
from openpilot.selfdrive.car import create_button_events, get_safety_config, structs
from openpilot.selfdrive.car.conversions import Conversions as CV
from openpilot.selfdrive.car.mazda.carstate import CarState
from openpilot.selfdrive.car.mazda.values import CAR, LKAS_LIMITS
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
@ -9,6 +10,7 @@ ButtonType = structs.CarState.ButtonEvent.Type
EventName = car.CarEvent.EventName
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
@ -31,7 +33,7 @@ class CarInterface(CarInterfaceBase):
return ret
# returns a car.CarState
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam)
# TODO: add button types for inc and dec

@ -21,7 +21,7 @@ class CarInterface(CarInterfaceBase):
ret.dashcamOnly = True
return ret
def _update(self, c):
def _update(self, c) -> structs.CarState:
self.sm.update(0)
gps_sock = 'gpsLocationExternal' if self.sm.recv_frame['gpsLocationExternal'] > 1 else 'gpsLocation'

@ -23,7 +23,7 @@ class CarState(CarStateBase):
self.prev_distance_button = 0
self.distance_button = 0
def update(self, cp, cp_adas, cp_cam):
def update(self, cp, cp_adas, cp_cam) -> structs.CarState:
ret = structs.CarState()
self.prev_distance_button = self.distance_button

@ -2,12 +2,14 @@ from cereal import car
from panda import Panda
from openpilot.selfdrive.car import create_button_events, get_safety_config, structs
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.car.nissan.carstate import CarState
from openpilot.selfdrive.car.nissan.values import CAR
ButtonType = structs.CarState.ButtonEvent.Type
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
@ -29,7 +31,7 @@ class CarInterface(CarInterfaceBase):
return ret
# returns a car.CarState
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_adas, self.cp_cam)
ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise})

@ -16,7 +16,7 @@ class CarState(CarStateBase):
self.angle_rate_calulator = CanSignalRateCalculator(50)
def update(self, cp, cp_cam, cp_body):
def update(self, cp, cp_cam, cp_body) -> structs.CarState:
ret = structs.CarState()
throttle_msg = cp.vl["Throttle"] if not (self.CP.flags & SubaruFlags.HYBRID) else cp_body.vl["Throttle_Hybrid"]

@ -1,15 +1,16 @@
from panda import Panda
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car.structs import CarParams
from openpilot.selfdrive.car import get_safety_config, structs
from openpilot.selfdrive.car.disable_ecu import disable_ecu
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.car.subaru.carstate import CarState
from openpilot.selfdrive.car.subaru.values import CAR, GLOBAL_ES_ADDR, SubaruFlags
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: CarParams, candidate: CAR, fingerprint, car_fw, experimental_long, docs):
def _get_params(ret: structs.CarParams, candidate: CAR, fingerprint, car_fw, experimental_long, docs):
ret.carName = "subaru"
ret.radarUnavailable = True
# for HYBRID CARS to be upstreamed, we need:
@ -25,10 +26,10 @@ class CarInterface(CarInterfaceBase):
if ret.flags & SubaruFlags.PREGLOBAL:
ret.enableBsm = 0x25c in fingerprint[0]
ret.safetyConfigs = [get_safety_config(CarParams.SafetyModel.subaruPreglobal)]
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.subaruPreglobal)]
else:
ret.enableBsm = 0x228 in fingerprint[0]
ret.safetyConfigs = [get_safety_config(CarParams.SafetyModel.subaru)]
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.subaru)]
if ret.flags & SubaruFlags.GLOBAL_GEN2:
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_SUBARU_GEN2
@ -36,7 +37,7 @@ class CarInterface(CarInterfaceBase):
ret.steerActuatorDelay = 0.1
if ret.flags & SubaruFlags.LKAS_ANGLE:
ret.steerControlType = CarParams.SteerControlType.angle
ret.steerControlType = structs.CarParams.SteerControlType.angle
else:
CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning)
@ -97,7 +98,7 @@ class CarInterface(CarInterfaceBase):
return ret
# returns a car.CarState
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam, self.cp_body)

@ -21,7 +21,7 @@ class CarState(CarStateBase):
self.acc_state = 0
self.das_control_counters = deque(maxlen=32)
def update(self, cp, cp_cam):
def update(self, cp, cp_cam) -> structs.CarState:
ret = structs.CarState()
# Vehicle speed

@ -1,14 +1,16 @@
#!/usr/bin/env python3
from panda import Panda
from openpilot.selfdrive.car import get_safety_config
from openpilot.selfdrive.car.structs import CarParams
from openpilot.selfdrive.car import get_safety_config, structs
from openpilot.selfdrive.car.tesla.carstate import CarState
from openpilot.selfdrive.car.tesla.values import CANBUS, CAR
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
class CarInterface(CarInterfaceBase):
CS: CarState
@staticmethod
def _get_params(ret: CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
def _get_params(ret: structs.CarParams, candidate, fingerprint, car_fw, experimental_long, docs):
ret.carName = "tesla"
# There is no safe way to do steer blending with user torque,
@ -16,7 +18,7 @@ class CarInterface(CarInterfaceBase):
# how openpilot should be, hence dashcamOnly
ret.dashcamOnly = True
ret.steerControlType = CarParams.SteerControlType.angle
ret.steerControlType = structs.CarParams.SteerControlType.angle
ret.longitudinalActuatorDelay = 0.5 # s
ret.radarTimeStep = (1.0 / 8) # 8Hz
@ -28,18 +30,18 @@ class CarInterface(CarInterfaceBase):
ret.openpilotLongitudinalControl = True
flags |= Panda.FLAG_TESLA_LONG_CONTROL
ret.safetyConfigs = [
get_safety_config(CarParams.SafetyModel.tesla, flags),
get_safety_config(CarParams.SafetyModel.tesla, flags | Panda.FLAG_TESLA_POWERTRAIN),
get_safety_config(structs.CarParams.SafetyModel.tesla, flags),
get_safety_config(structs.CarParams.SafetyModel.tesla, flags | Panda.FLAG_TESLA_POWERTRAIN),
]
else:
ret.openpilotLongitudinalControl = False
ret.safetyConfigs = [get_safety_config(CarParams.SafetyModel.tesla, flags)]
ret.safetyConfigs = [get_safety_config(structs.CarParams.SafetyModel.tesla, flags)]
ret.steerLimitTimer = 1.0
ret.steerActuatorDelay = 0.25
return ret
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam)
ret.events = self.create_common_events(ret).to_msg()

@ -33,7 +33,7 @@ class CarState(CarStateBase):
return button_events
def update(self, pt_cp, cam_cp, ext_cp, trans_type):
def update(self, pt_cp, cam_cp, ext_cp, trans_type) -> structs.CarState:
if self.CP.flags & VolkswagenFlags.PQ:
return self.update_pq(pt_cp, cam_cp, ext_cp, trans_type)
@ -156,7 +156,7 @@ class CarState(CarStateBase):
self.frame += 1
return ret
def update_pq(self, pt_cp, cam_cp, ext_cp, trans_type):
def update_pq(self, pt_cp, cam_cp, ext_cp, trans_type) -> structs.CarState:
ret = structs.CarState()
# Update vehicle speed and acceleration from ABS wheel speeds.
ret.wheelSpeeds = self.get_wheel_speeds(

@ -2,6 +2,8 @@ from cereal import car
from panda import Panda
from openpilot.selfdrive.car import get_safety_config, structs
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.car.volkswagen.carcontroller import CarController
from openpilot.selfdrive.car.volkswagen.carstate import CarState
from openpilot.selfdrive.car.volkswagen.values import CAR, CANBUS, CarControllerParams, NetworkLocation, TransmissionType, GearShifter, VolkswagenFlags
ButtonType = structs.CarState.ButtonEvent.Type
@ -9,6 +11,9 @@ EventName = car.CarEvent.EventName
class CarInterface(CarInterfaceBase):
CS: CarState
CC: CarController
def __init__(self, CP, CarController, CarState):
super().__init__(CP, CarController, CarState)
@ -101,7 +106,7 @@ class CarInterface(CarInterfaceBase):
return ret
# returns a car.CarState
def _update(self, c):
def _update(self, c) -> structs.CarState:
ret = self.CS.update(self.cp, self.cp_cam, self.cp_ext, self.CP.transmissionType)
events = self.create_common_events(ret, extra_gears=[GearShifter.eco, GearShifter.sport, GearShifter.manumatic],

Loading…
Cancel
Save