Skip to content

Commit

Permalink
more changes to get it to work
Browse files Browse the repository at this point in the history
  • Loading branch information
Comma Device committed Mar 25, 2020
1 parent 39164db commit 87fa257
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 143 deletions.
112 changes: 5 additions & 107 deletions cereal/messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -326,3 +223,4 @@ def send(self, s, dat):
if not isinstance(dat, bytes):
dat = dat.to_bytes()
self.sock[s].send(dat)

2 changes: 1 addition & 1 deletion selfdrive/car/car_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/modules/ALCA_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/modules/GYRO_module.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/modules/UIEV_module.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/tesla/ACC_module.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/tesla/AHB_module.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/tesla/PCC_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/tesla/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.]
Expand Down Expand Up @@ -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
Expand Down
38 changes: 25 additions & 13 deletions selfdrive/car/tesla/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 12 additions & 12 deletions selfdrive/car/tesla/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/tesla/radar_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/tesla/radar_tools/calibrateRadar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 87fa257

Please sign in to comment.