From f9aeb650accdb4d5a918770bfc5747ff5e9724b9 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Fri, 6 Mar 2020 12:41:53 +1000 Subject: [PATCH] minor code refactor. --- selfdrive/car/honda/carcontroller.py | 20 ++++++---- selfdrive/car/hyundai/carcontroller.py | 20 ++++++---- selfdrive/car/toyota/carcontroller.py | 44 ++++++++++++--------- selfdrive/crash.py | 55 +++++++++++--------------- 4 files changed, 73 insertions(+), 66 deletions(-) diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index ae5c65ce4..098e1e1a5 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -167,15 +167,21 @@ class CarController(): can_sends = [] # dragonpilot - if enabled and (CS.left_blinker_on > 0 or CS.right_blinker_on > 0) and self.dragon_enable_steering_on_signal: - self.turning_signal_timer = 100 + if enabled: + if self.dragon_enable_steering_on_signal: + if CS.left_blinker_on == 0 and CS.right_blinker_on == 0: + self.turning_signal_timer = 0 + else: + self.turning_signal_timer = 100 - if self.turning_signal_timer > 0: - self.turning_signal_timer -= 1 - lkas_active = False + if self.turning_signal_timer > 0: + self.turning_signal_timer -= 1 + lkas_active = False + else: + self.turning_signal_timer = 0 - if not self.dragon_lat_ctrl: - lkas_active = False + if not self.dragon_lat_ctrl: + lkas_active = False # Send steering command. idx = frame % 4 diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 8b7f35688..28dc52d94 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -43,15 +43,21 @@ class CarController(): can_sends = [] # dragonpilot - if enabled and (CS.left_blinker_on > 0 or CS.right_blinker_on > 0) and self.dragon_enable_steering_on_signal: - self.turning_signal_timer = 100 + if enabled: + if self.dragon_enable_steering_on_signal: + if CS.left_blinker_on == 0 and CS.right_blinker_on == 0: + self.turning_signal_timer = 0 + else: + self.turning_signal_timer = 100 - if self.turning_signal_timer > 0: - self.turning_signal_timer -= 1 - steer_req = 0 + if self.turning_signal_timer > 0: + self.turning_signal_timer -= 1 + steer_req = 0 + else: + self.turning_signal_timer = 0 - if not self.dragon_lat_ctrl: - steer_req = 0 + if not self.dragon_lat_ctrl: + steer_req = 0 self.lkas11_cnt = self.cnt % 0x10 self.clu11_cnt = self.cnt % 0x10 diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index d33267d14..856feec0e 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -191,26 +191,32 @@ class CarController(): can_sends = [] # dragonpilot - if enabled and (CS.left_blinker_on or CS.right_blinker_on) and self.dragon_enable_steering_on_signal: - self.turning_signal_timer = 100 + if enabled: + if self.dragon_enable_steering_on_signal: + if CS.left_blinker_on == 0 and CS.right_blinker_on == 0: + self.turning_signal_timer = 0 + else: + self.turning_signal_timer = 100 + + if self.turning_signal_timer > 0: + self.turning_signal_timer -= 1 + apply_steer_req = 0 + else: + self.turning_signal_timer = 0 + + if not self.dragon_lat_ctrl: + apply_steer_req = 0 + else: + if CS.v_ego > 12.5: + if right_lane_depart and not CS.right_blinker_on: + apply_steer = self.last_steer + 3 + apply_steer = min(apply_steer , 800) + apply_steer_req = 1 - if self.turning_signal_timer > 0: - self.turning_signal_timer -= 1 - apply_steer_req = 0 - - if not self.dragon_lat_ctrl: - apply_steer_req = 0 - - if CS.v_ego > 12.5 and not enabled: - if right_lane_depart and not CS.right_blinker_on: - apply_steer = self.last_steer + 3 - apply_steer = min(apply_steer , 800) - apply_steer_req = 1 - - if left_lane_depart and not CS.left_blinker_on: - apply_steer = self.last_steer - 3 - apply_steer = max(apply_steer , -800) - apply_steer_req = 1 + if left_lane_depart and not CS.left_blinker_on: + apply_steer = self.last_steer - 3 + apply_steer = max(apply_steer , -800) + apply_steer_req = 1 #*** control msgs *** #print("steer {0} {1} {2} {3}".format(apply_steer, min_lim, max_lim, CS.steer_torque_motor) diff --git a/selfdrive/crash.py b/selfdrive/crash.py index 30f3b3475..98d49379d 100644 --- a/selfdrive/crash.py +++ b/selfdrive/crash.py @@ -1,10 +1,13 @@ """Install exception handler for process crash.""" import os import sys -import json -#from subprocess import check_output import threading -from selfdrive.version import version, dirty +import capnp +from common.params import Params +from selfdrive.version import version, dirty, origin, branch +from common.op_params import opParams +op_params = opParams() +uniqueID = op_params.get('uniqueID', None) from selfdrive.swaglog import cloudlog @@ -20,47 +23,33 @@ if os.getenv("NOLOG") or os.getenv("NOCRASH"): else: from raven import Client from raven.transport.http import HTTPTransport - - error_tags = {'dirty': dirty, 'username': 'char_error'} - + params = Params() try: - with open("/data/data/ai.comma.plus.offroad/files/persistStore/persist-auth", "r") as f: - auth = json.loads(f.read()) - auth = json.loads(auth['commaUser']) - tags = ['username', 'email'] - for tag in tags: - try: - error_tags[tag] = ''.join(char for char in auth[tag].decode('utf-8', 'ignore') if char.isalnum()) - except: - pass - except: - pass - - logging_data = {"branch": "/data/params/d/GitBranch", "commit": "/data/params/d/GitCommit", "remote": "/data/params/d/GitRemote"} - - for key in logging_data: - try: - with open(logging_data[key], "r") as f: - error_tags[key] = str(f.read()) - except: - error_tags[key] = "unknown" + dongle_id = params.get("DongleId").decode('utf8') + except AttributeError: + dongle_id = "None" + error_tags = {'dirty': dirty, 'username': uniqueID, 'dongle_id': dongle_id, 'branch': branch, 'remote': origin} client = Client('https://980a0cba712a4c3593c33c78a12446e1:fecab286bcaf4dba8b04f7cff0188e2d@sentry.io/1488600', install_sys_hook=False, transport=HTTPTransport, release=version, tags=error_tags) - def capture_warning(warning_string): - client.captureMessage(warning_string, level='warning') - - def capture_info(info_string): - client.captureMessage(info_string, level='info') - def capture_exception(*args, **kwargs): - client.captureException(*args, **kwargs) + exc_info = sys.exc_info() + if not exc_info[0] is capnp.lib.capnp.KjException: + client.captureException(*args, **kwargs) cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1)) def bind_user(**kwargs): client.user_context(kwargs) + def capture_warning(warning_string): + bind_user(id=dongle_id) + client.captureMessage(warning_string, level='warning') + + def capture_info(info_string): + bind_user(id=dongle_id) + client.captureMessage(info_string, level='info') + def bind_extra(**kwargs): client.extra_context(kwargs)