diff --git a/cereal/messaging/__init__.py b/cereal/messaging/__init__.py index a3c50a2baac1b7..085c05af9aeddd 100644 --- a/cereal/messaging/__init__.py +++ b/cereal/messaging/__init__.py @@ -137,13 +137,11 @@ def __init__(self, services, ignore_alive=None, addr="127.0.0.1"): self.rcv_time = {s : 0. for s in services} self.rcv_frame = {s : 0 for s in services} self.alive = {s : False for s in services} - self.alive_cnt = {s: 0 for s in services} self.sock = {} self.freq = {} self.data = {} self.logMonoTime = {} self.valid = {} - self.valid_cnt = {s: 0 for s in services} if ignore_alive is not None: self.ignore_alive = ignore_alive @@ -163,13 +161,7 @@ def __init__(self, services, ignore_alive=None, addr="127.0.0.1"): self.data[s] = getattr(data, s) self.logMonoTime[s] = 0 - if data.valid: - self.valid_cnt[s] = 0 - self.valid[s] = True - else: - self.valid_cnt[s] += 1 - if self.valid_cnt[s] >= MSG_ERROR_LVL: - self.valid[s] = False + self.valid[s] = data.valid def __getitem__(self, s): return self.data[s] @@ -194,120 +186,25 @@ def update_msgs(self, cur_time, msgs): self.rcv_frame[s] = self.frame self.data[s] = getattr(msg, s) self.logMonoTime[s] = msg.logMonoTime - if msg.valid: - self.valid_cnt[s] = 0 - self.valid[s] = True - else: - self.valid_cnt[s] += 1 - if self.valid_cnt[s] >= MSG_ERROR_LVL: - self.valid[s] = False + self.valid[s] = msg.valid for s in self.data: # arbitrary small number to avoid float comparison. If freq is 0, we can skip the check if self.freq[s] > 1e-5: # alive if delay is within 10x the expected frequency - if (cur_time - self.rcv_time[s]) < (10. / self.freq[s]): - self.alive_cnt[s] = 0 - self.alive[s] = True - else: - self.alive_cnt[s] += 1 - if self.alive_cnt[s] >= MSG_ERROR_LVL: - self.alive[s] = False + self.alive[s] = (cur_time - self.rcv_time[s]) < (10. / self.freq[s]) else: - self.alive_cnt[s] = 0 self.alive[s] = True - def all_alive_with_info(self, service_list=None): - """Returns alive state for tracked processes. - Args: - service_list (list): Optional service list. - Returns: - tuple: areAllAlive, processName, count - """ - if service_list is None: # check all - service_list = self.alive.keys() - areAllAlive = True - processName = "" - count = 0 - for s in service_list: - if not self.alive[s]: - areAllAlive = False - processName = s - count = self.alive_cnt[s] - break - return (areAllAlive, processName, count) - def all_alive(self, service_list=None): - """Returns alive state for tracked processes. - - Args: - service_list (list): Optional service list. - - Returns: - tuple: areAllAlive, processName, count - """ if service_list is None: # check all service_list = self.alive.keys() return all(self.alive[s] for s in service_list if s not in self.ignore_alive) def all_valid(self, service_list=None): - """Returns valid state for tracked processes. - - Args: - service_list (list): Optional service list. - - Returns: - tuple: areAllValid, processName, count - """ - if service_list is None: # check all - service_list = self.valid.keys() - areAllValid = True - processName = "" - count = 0 - for s in service_list: - if not self.valid[s]: - areAllValid = False - processName = s - count = self.valid_cnt[s] - break - return areAllValid - - def all_valid_with_info(self, service_list=None): - """Returns valid state for tracked processes. - - Args: - service_list (list): Optional service list. - - Returns: - tuple: areAllValid, processName, count - """ if service_list is None: # check all service_list = self.valid.keys() - areAllValid = True - processName = "" - count = 0 - for s in service_list: - if not self.valid[s]: - areAllValid = False - processName = s - count = self.valid_cnt[s] - break - return (areAllValid, processName, count) - - def all_alive_and_valid_with_info(self, service_list=None): - """Returns alive and valid state for tracked processes. - - Args: - service_list (list): Optional service list. - - Returns: - tuple: areAllAlive, areAllValid, aliveProcessName, aliveCount, validProcessName, validCount - """ - if service_list is None: # check all - service_list = self.alive.keys() - areAllAlive, aliveProcessName, aliveCount = self.all_alive(service_list=service_list) - areAllValid, validProcessName, validCount = self.all_valid(service_list=service_list) - return (areAllAlive, areAllValid, aliveProcessName, aliveCount, validProcessName, ) + return all(self.valid[s] for s in service_list) def all_alive_and_valid(self, service_list=None): if service_list is None: # check all @@ -326,3 +223,4 @@ def send(self, s, dat): if not isinstance(dat, bytes): dat = dat.to_bytes() self.sock[s].send(dat) + diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 1cbe0eca65d3ef..6e8cd299611ce7 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -164,7 +164,7 @@ def get_car(logcan, sendcan, has_relay = False): fingerprints=["","",""] vin="TESLAFORCED123456" #BB - car_fw= "1234" + fw_candidates, car_fw = set(), [] source=car.CarParams.FingerprintSource.fixed cloudlog.warning("VIN %s", vin) Params().put("CarVin", vin) diff --git a/selfdrive/car/modules/ALCA_module.py b/selfdrive/car/modules/ALCA_module.py index b2238a39342671..6c2aaf92610342 100644 --- a/selfdrive/car/modules/ALCA_module.py +++ b/selfdrive/car/modules/ALCA_module.py @@ -48,7 +48,7 @@ from selfdrive.controls.lib.pid import PIController from common.realtime import sec_since_boot from cereal.services import service_list -import selfdrive.messaging as messaging +import cereal.messaging as messaging import numpy as np from cereal import tesla diff --git a/selfdrive/car/modules/GYRO_module.py b/selfdrive/car/modules/GYRO_module.py index a4d34cf691d060..4f9ef34d4e4f99 100644 --- a/selfdrive/car/modules/GYRO_module.py +++ b/selfdrive/car/modules/GYRO_module.py @@ -1,6 +1,6 @@ from cereal.services import service_list from collections import deque -import selfdrive.messaging as messaging +import cereal.messaging as messaging import cereal import math from common.realtime import sec_since_boot diff --git a/selfdrive/car/modules/UIEV_module.py b/selfdrive/car/modules/UIEV_module.py index 712c787cb2fbeb..5c84044d241050 100644 --- a/selfdrive/car/modules/UIEV_module.py +++ b/selfdrive/car/modules/UIEV_module.py @@ -1,6 +1,6 @@ from cereal import ui from common import realtime -import selfdrive.messaging as messaging +import cereal.messaging as messaging class UIEvents(): def __init__(self,carstate): diff --git a/selfdrive/car/tesla/ACC_module.py b/selfdrive/car/tesla/ACC_module.py index 68ee860196f4c9..5be456016c9297 100644 --- a/selfdrive/car/tesla/ACC_module.py +++ b/selfdrive/car/tesla/ACC_module.py @@ -1,7 +1,7 @@ from selfdrive.car.tesla.speed_utils.fleet_speed import FleetSpeed from selfdrive.car.tesla.values import CruiseButtons, CruiseState from selfdrive.config import Conversions as CV -import selfdrive.messaging as messaging +import cereal.messaging as messaging import sys import time diff --git a/selfdrive/car/tesla/AHB_module.py b/selfdrive/car/tesla/AHB_module.py index d7a92cf946e22f..0f5f4254f0b440 100644 --- a/selfdrive/car/tesla/AHB_module.py +++ b/selfdrive/car/tesla/AHB_module.py @@ -1,6 +1,6 @@ from selfdrive.config import Conversions as CV from cereal import tesla,log -import selfdrive.messaging as messaging +import cereal.messaging as messaging import time DEBUG = False diff --git a/selfdrive/car/tesla/PCC_module.py b/selfdrive/car/tesla/PCC_module.py index da07e440705796..8cee8c0ada3f07 100644 --- a/selfdrive/car/tesla/PCC_module.py +++ b/selfdrive/car/tesla/PCC_module.py @@ -7,7 +7,7 @@ from selfdrive.config import Conversions as CV from selfdrive.controls.lib.speed_smoother import speed_smoother from selfdrive.controls.lib.planner import calc_cruise_accel_limits -import selfdrive.messaging as messaging +import cereal.messaging as messaging import time import math from collections import OrderedDict diff --git a/selfdrive/car/tesla/carcontroller.py b/selfdrive/car/tesla/carcontroller.py index e68859dff9a705..f513068fb5ba9e 100644 --- a/selfdrive/car/tesla/carcontroller.py +++ b/selfdrive/car/tesla/carcontroller.py @@ -17,7 +17,7 @@ from selfdrive.car.tesla.HSO_module import HSOController from selfdrive.car.tesla.speed_utils.movingaverage import MovingAverage from selfdrive.car.tesla.AHB_module import AHBController -import selfdrive.messaging as messaging +import cereal.messaging as messaging # Steer angle limits ANGLE_MAX_BP = [0., 27., 36.] @@ -76,7 +76,7 @@ def process_hud_alert(hud_alert): class CarController(): - def __init__(self, dbc_name): + def __init__(self, dbc_name,CP,VM): self.fleet_speed_state = 0 self.cc_counter = 0 self.alcaStateData = None diff --git a/selfdrive/car/tesla/carstate.py b/selfdrive/car/tesla/carstate.py index a9fce760145698..99233b2936d06f 100644 --- a/selfdrive/car/tesla/carstate.py +++ b/selfdrive/car/tesla/carstate.py @@ -7,6 +7,7 @@ from selfdrive.car.modules.UIBT_module import UIButtons from selfdrive.car.modules.UIEV_module import UIEvents from selfdrive.car.tesla.readconfig import read_config_file +from selfdrive.car.interfaces import CarStateBase import os import subprocess from common.params import read_db, write_db @@ -183,20 +184,9 @@ def get_pedal_can_signals(CP): checks = [] return signals, checks -def get_can_parser(CP,mydbc): - signals, checks = get_can_signals(CP) - return CANParser(mydbc, signals, checks, 0) - -def get_epas_parser(CP,epascan): - signals, checks = get_epas_can_signals(CP) - return CANParser(DBC[CP.carFingerprint]['pt']+"_epas", signals, checks, epascan) - -def get_pedal_parser(CP,pedalcan): - signals, checks = get_pedal_can_signals(CP) - return CANParser(DBC[CP.carFingerprint]['pt']+"_pedal", signals, checks, pedalcan) - -class CarState(): +class CarState(CarStateBase): def __init__(self, CP): + super().__init__(CP) self.speed_control_enabled = 0 self.CL_MIN_V = 8.9 self.CL_MAX_A = 20. @@ -425,6 +415,28 @@ def __init__(self, CP): self.ahbLoBeamOn = 0 self.ahbHiBeamOn = 0 self.ahbNightMode = 0 + + @staticmethod + def get_can_parser(CP): + signals, checks = get_can_signals(CP) + return CANParser(DBC[CP.carFingerprint]['pt'], signals, checks, 0) + + @staticmethod + def get_can_parser2(CP,mydbc): + signals, checks = get_can_signals(CP) + return CANParser(mydbc, signals, checks, 0) + + @staticmethod + def get_epas_parser(CP,epascan): + signals, checks = get_epas_can_signals(CP) + return CANParser(DBC[CP.carFingerprint]['pt']+"_epas", signals, checks, epascan) + + @staticmethod + def get_pedal_parser(CP,pedalcan): + signals, checks = get_pedal_can_signals(CP) + return CANParser(DBC[CP.carFingerprint]['pt']+"_pedal", signals, checks, pedalcan) + + def config_ui_buttons(self, pcc_available, pcc_blocked_by_acc_mode): if pcc_available: diff --git a/selfdrive/car/tesla/interface.py b/selfdrive/car/tesla/interface.py index c8ab1d79833daa..22829a8b2c87bd 100644 --- a/selfdrive/car/tesla/interface.py +++ b/selfdrive/car/tesla/interface.py @@ -5,14 +5,14 @@ from selfdrive.config import Conversions as CV from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET, get_events from selfdrive.controls.lib.vehicle_model import VehicleModel -from selfdrive.car.tesla.carstate import CarState, get_can_parser, get_epas_parser, get_pedal_parser from selfdrive.car.tesla.values import CruiseButtons, CM, BP, AH, CAR,DBC from common.params import read_db from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, is_ecu_disconnected, gen_empty_fingerprint from selfdrive.car.tesla.readconfig import CarSettings -import selfdrive.messaging as messaging +import cereal.messaging as messaging from cereal.services import service_list from selfdrive.controls.lib.planner import _A_CRUISE_MAX_V +from selfdrive.car.interfaces import CarInterfaceBase A_ACC_MAX = max(_A_CRUISE_MAX_V) AudibleAlert = car.CarControl.HUDControl.AudibleAlert @@ -23,8 +23,9 @@ -class CarInterface(): - def __init__(self, CP, CarController): +class CarInterface(CarInterfaceBase): + def __init__(self, CP, CarController, CarState): + super().__init__(CP, CarController, CarState) self.CP = CP self.frame = 0 @@ -41,19 +42,19 @@ def __init__(self, CP, CarController): mydbc = DBC[CP.carFingerprint]['pt'] if CP.carFingerprint == CAR.MODELS and self.CS.fix1916: mydbc = mydbc + "1916" - self.cp = get_can_parser(CP,mydbc) + self.cp = self.CS.get_can_parser2(CP,mydbc) self.epas_cp = None self.pedal_cp = None if self.CS.useWithoutHarness: - self.epas_cp = get_epas_parser(CP,0) - self.pedal_cp = get_pedal_parser(CP,0) + self.epas_cp = self.CS.get_epas_parser(CP,0) + self.pedal_cp = self.CS.get_pedal_parser(CP,0) else: - self.epas_cp = get_epas_parser(CP,2) - self.pedal_cp = get_pedal_parser(CP,2) + self.epas_cp = self.CS.get_epas_parser(CP,2) + self.pedal_cp = self.CS.get_pedal_parser(CP,2) self.CC = None if CarController is not None: - self.CC = CarController(self.cp.dbc_name) + self.CC = CarController(self.cp.dbc_name,CP,self.VM) @staticmethod @@ -103,7 +104,6 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False, ret.carName = "tesla" ret.carFingerprint = candidate - ret.isPandaBlack = is_panda_black teslaModel = read_db('/data/params','TeslaModel') if teslaModel is not None: @@ -113,7 +113,7 @@ def get_params(candidate, fingerprint=gen_empty_fingerprint(), has_relay=False, ret.safetyModel = car.CarParams.SafetyModel.tesla ret.safetyParam = 1 - ret.carVin = vin + ret.carVin = "TESLAFAKEVIN12345" ret.enableCamera = True ret.enableGasInterceptor = False #keep this False for now diff --git a/selfdrive/car/tesla/radar_interface.py b/selfdrive/car/tesla/radar_interface.py index ee1507e594fb99..75398fb2d3fdc4 100644 --- a/selfdrive/car/tesla/radar_interface.py +++ b/selfdrive/car/tesla/radar_interface.py @@ -5,7 +5,7 @@ from selfdrive.can.parser import CANParser from common.realtime import DT_RDR from cereal.services import service_list -import selfdrive.messaging as messaging +import cereal.messaging as messaging from selfdrive.car.interfaces import RadarInterfaceBase from selfdrive.car.tesla.readconfig import CarSettings from selfdrive.tinklad.tinkla_interface import TinklaClient diff --git a/selfdrive/car/tesla/radar_tools/calibrateRadar.py b/selfdrive/car/tesla/radar_tools/calibrateRadar.py index 7276b165bf9c45..884f2a9804f8d1 100644 --- a/selfdrive/car/tesla/radar_tools/calibrateRadar.py +++ b/selfdrive/car/tesla/radar_tools/calibrateRadar.py @@ -11,7 +11,7 @@ from selfdrive.can.parser import CANParser from common.realtime import sec_since_boot from cereal.services import service_list -import selfdrive.messaging as messaging +import cereal.messaging as messaging from selfdrive.car.tesla.readconfig import read_config_file,CarSettings from selfdrive.car.tesla.radar_interface import RadarInterface