From bddb126ed207d7b1437b5d388713ac4c2f858fb0 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Mon, 9 Mar 2020 22:46:52 +1000 Subject: [PATCH 01/17] add enable auto shutdown toggle --- common/params.py | 1 + selfdrive/dragonpilot/dragonconf/__init__.py | 1 + selfdrive/dragonpilot/shutdownd/shutdownd.py | 69 ++++++++++---------- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/common/params.py b/common/params.py index 111810ef6..f90ccfdca 100755 --- a/common/params.py +++ b/common/params.py @@ -106,6 +106,7 @@ keys = { #dragonpilot config "DragonEnableDashcam": [TxType.PERSISTENT], "DragonEnableDriverSafetyCheck": [TxType.PERSISTENT], + "DragonEnableAutoShutdown": [TxType.PERSISTENT], "DragonAutoShutdownAt": [TxType.PERSISTENT], "DragonEnableSteeringOnSignal": [TxType.PERSISTENT], "DragonEnableLogger": [TxType.PERSISTENT], diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index 020864dd7..89697146c 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -4,6 +4,7 @@ from common.params import Params, put_nonblocking default_conf = { 'DragonEnableDashcam': '0', 'DragonEnableDriverSafetyCheck': '1', + 'DragonEnableAutoShutdown': '1', 'DragonAutoShutdownAt': '0', # in minute 'DragonEnableSteeringOnSignal': '0', 'DragonEnableLogger': '1', diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index a467415de..f6cd8a17d 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -1,53 +1,50 @@ #!/usr/bin/env python3 - import os import time from common.params import Params params = Params() -import cereal import cereal.messaging as messaging +from common.realtime import sec_since_boot - -def main(gctx=None): - - shutdown_count = 0 - auto_shutdown_at = get_shutdown_val() - frame = 0 - last_shutdown_val = auto_shutdown_at +def main(): thermal_sock = messaging.sub_sock('thermal') + last_ts = 0 + secs = 0 + last_secs = 0 + shutdown_at = 0 started = False - + usb_online = False + enabled = False + last_enabled = False while 1: - if frame % 5 == 0: - msg = messaging.recv_sock(thermal_sock, wait=True) - started = msg.thermal.started - with open("/sys/class/power_supply/usb/present") as f: - usb_online = bool(int(f.read())) - auto_shutdown_at = get_shutdown_val() - if not last_shutdown_val == auto_shutdown_at: - shutdown_count = 0 - last_shutdown_val = auto_shutdown_at + cur_time = sec_since_boot() + if cur_time - last_ts >= 10.: + enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False + # reset timer when enabled status has changed + if not last_enabled and enabled: + shutdown_at = cur_time + secs + last_enabled = enabled - if not started and not usb_online: - shutdown_count += 1 - else: - shutdown_count = 0 + if enabled: + secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 + # reset timer when secs num has changed + if last_secs != secs: + shutdown_at = cur_time + secs + last_secs = secs - if auto_shutdown_at is None: - auto_shutdown_at = get_shutdown_val() - else: - if shutdown_count >= auto_shutdown_at > 0: - os.system('LD_LIBRARY_PATH="" svc power shutdown') + msg = messaging.recv_sock(thermal_sock, wait=True) + started = msg.thermal.started + with open("/sys/class/power_supply/usb/present") as f: + usb_online = bool(int(f.read())) - time.sleep(1) - -def get_shutdown_val(): - val = params.get("DragonAutoShutdownAt", encoding='utf8') - if val is None: - return None - else: - return int(val)*60 # convert to seconds + if enabled: + if started or usb_online: + shutdown_at = cur_time + secs + else: + if secs > 0 and cur_time >= shutdown_at: + os.system('LD_LIBRARY_PATH="" svc power shutdown') + time.sleep(10) if __name__ == "__main__": main() \ No newline at end of file From 35d27ee879695ae72f2a4e29548765dbd8a96388 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Mon, 9 Mar 2020 23:09:39 +1000 Subject: [PATCH 02/17] add greypandamode toggle From d0e76602cf1052a30c67af11febef45f011b1197 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Tue, 10 Mar 2020 15:41:01 +1000 Subject: [PATCH 03/17] performance optimisation. --- common/params.py | 1 + selfdrive/car/honda/carcontroller.py | 9 +++- selfdrive/car/honda/interface.py | 13 ++++-- selfdrive/car/hyundai/carcontroller.py | 10 +++-- selfdrive/car/hyundai/interface.py | 13 ++++-- selfdrive/car/toyota/carcontroller.py | 13 ++++-- selfdrive/car/toyota/interface.py | 13 ++++-- selfdrive/controls/controlsd.py | 15 ++++--- selfdrive/controls/lib/driver_monitor.py | 26 ++++++++--- selfdrive/controls/lib/lane_planner.py | 2 +- selfdrive/controls/lib/pathplanner.py | 45 +++++++++++--------- selfdrive/controls/lib/planner.py | 13 ++++-- selfdrive/dragonpilot/appd/appd.py | 15 +++++-- selfdrive/dragonpilot/dashcamd/dashcamd.py | 2 +- selfdrive/dragonpilot/dragonconf/__init__.py | 28 +++++++----- selfdrive/dragonpilot/shutdownd/shutdownd.py | 35 ++++++++------- selfdrive/thermald.py | 34 ++++++++++----- selfdrive/ui/ui.cc | 30 ++++++------- 18 files changed, 205 insertions(+), 112 deletions(-) diff --git a/common/params.py b/common/params.py index f90ccfdca..fa93520ee 100755 --- a/common/params.py +++ b/common/params.py @@ -168,6 +168,7 @@ keys = { "DragonBTG": [TxType.PERSISTENT], "DragonBootHotspot": [TxType.PERSISTENT], "DragonAccelProfile": [TxType.PERSISTENT], + "DragonLastModified": [TxType.PERSISTENT], } diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index 098e1e1a5..f8bf0f749 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -9,6 +9,7 @@ from selfdrive.car.honda.values import CruiseButtons, CAR, VISUAL_HUD from opendbc.can.packer import CANPacker from common.params import Params params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified VisualAlert = car.CarControl.HUDControl.VisualAlert @@ -96,14 +97,18 @@ class CarController(): self.turning_signal_timer = 0 self.dragon_enable_steering_on_signal = False self.dragon_lat_ctrl = True + self.dp_last_modified = None def update(self, enabled, CS, frame, actuators, \ pcm_speed, pcm_override, pcm_cancel_cmd, pcm_accel, \ hud_v_cruise, hud_show_lanes, hud_show_car, hud_alert): # dragonpilot, don't check for param too often as it's a kernel call if frame % 500 == 0: - self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False - self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dp_last_modified = modified # *** apply brake hysteresis *** brake, self.braking, self.brake_steady = actuator_hystereses(actuators.brake, self.braking, self.brake_steady, CS.v_ego, CS.CP.carFingerprint) diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index e43050514..e005c6c40 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -14,6 +14,7 @@ from selfdrive.controls.lib.planner import _A_CRUISE_MAX_V_FOLLOWING from selfdrive.car.interfaces import CarInterfaceBase from common.params import Params params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified A_ACC_MAX = max(_A_CRUISE_MAX_V_FOLLOWING) @@ -105,6 +106,7 @@ class CarInterface(CarInterfaceBase): self.dragon_allow_gas = False self.ts_last_check = 0. self.dragon_lat_ctrl = True + self.dp_last_modified = None @staticmethod def calc_accel_override(a_ego, a_target, v_ego, v_target): @@ -386,10 +388,13 @@ class CarInterface(CarInterfaceBase): def update(self, c, can_strings): # dragonpilot, don't check for param too often as it's a kernel call ts = sec_since_boot() - if ts - self.ts_last_check > 5.: - self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else True - self.dragon_allow_gas = True if params.get("DragonAllowGas", encoding='utf8') == "1" else False - self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + if ts - self.ts_last_check >= 5.: + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else True + self.dragon_allow_gas = True if params.get("DragonAllowGas", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dp_last_modified = modified self.ts_last_check = ts # ******************* do can recv ******************* diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 28dc52d94..fc0e49b3d 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -4,7 +4,7 @@ from selfdrive.car.hyundai.values import Buttons, SteerLimitParams from opendbc.can.packer import CANPacker from common.params import Params params = Params() - +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified class CarController(): def __init__(self, dbc_name, car_fingerprint): @@ -20,13 +20,17 @@ class CarController(): self.turning_signal_timer = 0 self.dragon_enable_steering_on_signal = False self.dragon_lat_ctrl = True + self.dp_last_modified = None def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, hud_alert): # dragonpilot, don't check for param too often as it's a kernel call if frame % 500 == 0: - self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False - self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dp_last_modified = modified ### Steering Torque new_steer = actuators.steer * SteerLimitParams.STEER_MAX diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 9dbcf74d5..5a8e58475 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -10,6 +10,7 @@ from selfdrive.car import STD_CARGO_KG, scale_rot_inertia, scale_tire_stiffness, from selfdrive.car.interfaces import CarInterfaceBase from common.params import Params params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified GearShifter = car.CarState.GearShifter ButtonType = car.CarState.ButtonEvent.Type @@ -42,6 +43,7 @@ class CarInterface(CarInterfaceBase): self.dragon_allow_gas = False self.ts_last_check = 0. self.dragon_lat_ctrl = True + self.dp_last_modified = None @staticmethod def compute_gb(accel, speed): @@ -162,10 +164,13 @@ class CarInterface(CarInterfaceBase): def update(self, c, can_strings): # dragonpilot, don't check for param too often as it's a kernel call ts = sec_since_boot() - if ts - self.ts_last_check > 5.: - self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else True - self.dragon_allow_gas = True if params.get("DragonAllowGas", encoding='utf8') == "1" else False - self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + if ts - self.ts_last_check >= 5.: + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else True + self.dragon_allow_gas = True if params.get("DragonAllowGas", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dp_last_modified = modified self.ts_last_check = ts # ******************* do can recv ******************* diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index 856feec0e..e65ade1cc 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -8,6 +8,7 @@ from selfdrive.car.toyota.values import Ecu, CAR, STATIC_MSGS, SteerLimitParams from opendbc.can.packer import CANPacker from common.params import Params params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified VisualAlert = car.CarControl.HUDControl.VisualAlert @@ -109,16 +110,20 @@ class CarController(): self.dragon_lat_ctrl = True self.dragon_lane_departure_warning = True self.dragon_toyota_sng_mod = False + self.dp_last_modified = None def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, hud_alert, left_line, right_line, lead, left_lane_depart, right_lane_depart): # dragonpilot, don't check for param too often as it's a kernel call if frame % 500 == 0: - self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False - self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True - self.dragon_lane_departure_warning = False if params.get("DragonToyotaLaneDepartureWarning", encoding='utf8') == "0" else True - self.dragon_toyota_sng_mod = True if params.get("DragonToyotaSnGMod", encoding='utf8') == "1" else False + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dragon_lane_departure_warning = False if params.get("DragonToyotaLaneDepartureWarning", encoding='utf8') == "0" else True + self.dragon_toyota_sng_mod = True if params.get("DragonToyotaSnGMod", encoding='utf8') == "1" else False + self.dp_last_modified = modified # *** compute control surfaces *** diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 2b2d65d60..62e60f200 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -11,6 +11,7 @@ from selfdrive.car.interfaces import CarInterfaceBase from common.realtime import sec_since_boot from common.params import Params params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified ButtonType = car.CarState.ButtonEvent.Type GearShifter = car.CarState.GearShifter @@ -41,6 +42,7 @@ class CarInterface(CarInterfaceBase): self.dragon_allow_gas = False self.ts_last_check = 0. self.dragon_lat_ctrl = True + self.dp_last_modified = None @staticmethod def compute_gb(accel, speed): @@ -382,10 +384,13 @@ class CarInterface(CarInterfaceBase): # dragonpilot, don't check for param too often as it's a kernel call ts = sec_since_boot() if ts - self.ts_last_check >= 5.: - self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False - self.dragon_allow_gas = True if params.get("DragonAllowGas", encoding='utf8') == "1" else False - self.dragon_toyota_stock_dsu = True if params.get("DragonToyotaStockDSU", encoding='utf8') == "1" else False - self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False + self.dragon_allow_gas = True if params.get("DragonAllowGas", encoding='utf8') == "1" else False + self.dragon_toyota_stock_dsu = True if params.get("DragonToyotaStockDSU", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dp_last_modified = modified self.ts_last_check = ts # ******************* do can recv ******************* diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 6397e08c2..4bef4b8a5 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -25,6 +25,7 @@ from selfdrive.controls.lib.alertmanager import AlertManager from selfdrive.controls.lib.vehicle_model import VehicleModel from selfdrive.controls.lib.planner import LON_MPC_STEP from selfdrive.locationd.calibration_helpers import Calibration, Filter +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified LANE_DEPARTURE_THRESHOLD = 0.1 @@ -546,15 +547,19 @@ def controlsd_thread(sm=None, pm=None, can_sock=None): dragon_display_steering_limit_alert = True dragon_stopped_has_lead_count = 0 dragon_lead_car_moving_alert = False + dp_last_modified = None while True: # dragonpilot, don't check for param too often as it's a kernel call ts = sec_since_boot() - if ts - ts_last_check > 5.: - dragon_toyota_stock_dsu = True if params.get("DragonToyotaStockDSU", encoding='utf8') == "1" else False - dragon_lat_control = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True - dragon_display_steering_limit_alert = False if params.get("DragonDisplaySteeringLimitAlert", encoding='utf8') == "0" else True - dragon_lead_car_moving_alert = True if params.get("DragonEnableLeadCarMovingAlert", encoding='utf8') == "1" else False + if ts - ts_last_check >= 5.: + modified = dp_get_last_modified() + if dp_last_modified != modified: + dragon_toyota_stock_dsu = True if params.get("DragonToyotaStockDSU", encoding='utf8') == "1" else False + dragon_lat_control = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + dragon_display_steering_limit_alert = False if params.get("DragonDisplaySteeringLimitAlert", encoding='utf8') == "0" else True + dragon_lead_car_moving_alert = True if params.get("DragonEnableLeadCarMovingAlert", encoding='utf8') == "1" else False + dp_last_modified = modified ts_last_check = ts start_time = sec_since_boot() diff --git a/selfdrive/controls/lib/driver_monitor.py b/selfdrive/controls/lib/driver_monitor.py index ef453243d..3c0a2f50b 100644 --- a/selfdrive/controls/lib/driver_monitor.py +++ b/selfdrive/controls/lib/driver_monitor.py @@ -1,11 +1,12 @@ from common.numpy_fast import interp from math import atan2, sqrt -from common.realtime import DT_DMON +from common.realtime import DT_DMON, sec_since_boot from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET from common.filter_simple import FirstOrderFilter from common.stat_live import RunningStatFilter from common.params import Params params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified _AWARENESS_TIME = 70. # one minute limit without user touching steering wheels make the car enter a terminal status _AWARENESS_PRE_TIME_TILL_TERMINAL = 15. # a first alert is issued 25s before expiration @@ -114,10 +115,11 @@ class DriverStatus(): self.is_rhd_region_checked = False # dragonpilot - self.awareness_time = float(params.get("DragonSteeringMonitorTimer", encoding='utf8')) - self.awareness_time = 86400 if self.awareness_time <= 0. else self.awareness_time * 60. - self.dragon_enable_driver_safety_check = False if params.get("DragonEnableDriverSafetyCheck", encoding='utf8') == "0" else True - self.dragon_enable_driver_monitoring = False if params.get("DragonEnableDriverMonitoring", encoding='utf8') == "0" else True + self.last_ts = 0 + self.dp_last_modified = None + self.awareness_time = 100 + self.dragon_enable_driver_safety_check = True + self.dragon_enable_driver_monitoring = True self._set_timers(active_monitoring=True) @@ -220,6 +222,20 @@ class DriverStatus(): self.hi_stds = 0 def update(self, events, driver_engaged, ctrl_active, standstill): + cur_time = sec_since_boot() + if cur_time - self.last_ts >= 5.: + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.awareness_time = int(params.get("DragonSteeringMonitorTimer", encoding='utf8')) + self.awareness_time = 100 if self.awareness_time <= 0. else self.awareness_time * 60. + + self.dragon_enable_driver_safety_check = False if params.get("DragonEnableDriverSafetyCheck", encoding='utf8') == "0" else True + if self.dragon_enable_driver_safety_check: + self.dragon_enable_driver_monitoring = False if params.get("DragonEnableDriverMonitoring", encoding='utf8') == "0" else True + else: + self.dragon_enable_driver_monitoring = False + self.dp_last_modified = modified + self.last_ts = cur_time if (driver_engaged and self.awareness > 0) or not ctrl_active or not self.dragon_enable_driver_safety_check: # reset only when on disengagement if red reached self.awareness = 1. diff --git a/selfdrive/controls/lib/lane_planner.py b/selfdrive/controls/lib/lane_planner.py index 2bc7b2b21..3e53ec3d0 100644 --- a/selfdrive/controls/lib/lane_planner.py +++ b/selfdrive/controls/lib/lane_planner.py @@ -77,7 +77,7 @@ class LanePlanner(): def update_d_poly(self, v_ego): ts = sec_since_boot() - if ts - self.ts_last_check > 5.: + if ts - self.ts_last_check >= 5.: self.camera_offset = int(params.get("DragonCameraOffset", encoding='utf8')) * 0.01 self.ts_last_check = ts # only offset left and right lane lines; offsetting p_poly does not make sense diff --git a/selfdrive/controls/lib/pathplanner.py b/selfdrive/controls/lib/pathplanner.py index 1f2eea032..9e784c4de 100644 --- a/selfdrive/controls/lib/pathplanner.py +++ b/selfdrive/controls/lib/pathplanner.py @@ -11,6 +11,7 @@ import cereal.messaging as messaging from cereal import log # dragonpilot from common.params import Params +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified LaneChangeState = log.PathPlan.LaneChangeState LaneChangeDirection = log.PathPlan.LaneChangeDirection @@ -72,6 +73,7 @@ class PathPlanner(): self.dragon_auto_lc_min_mph = 60 * CV.MPH_TO_MS self.dragon_auto_lc_delay = 2. self.last_ts = 0. + self.dp_last_modified = None def setup_mpc(self): self.libmpc = libmpc_py.libmpc @@ -92,26 +94,29 @@ class PathPlanner(): def update(self, sm, pm, CP, VM): # dragonpilot cur_time = sec_since_boot() - if cur_time - self.last_ts > 5.: - self.dragon_assisted_lc_enabled = self.lane_change_enabled - if self.dragon_assisted_lc_enabled: - self.dragon_auto_lc_enabled = True if self.params.get("DragonEnableAutoLC", encoding='utf8') == "1" else False - # adjustable assisted lc min speed - self.dragon_assisted_lc_min_mph = int(self.params.get("DragonAssistedLCMinMPH", encoding='utf8')) * CV.MPH_TO_MS - if self.dragon_assisted_lc_min_mph < 0: - self.dragon_assisted_lc_min_mph = 0 - if self.dragon_auto_lc_enabled: - # adjustable auto lc min speed - self.dragon_auto_lc_min_mph = int(self.params.get("DragonAutoLCMinMPH", encoding='utf8')) * CV.MPH_TO_MS - if self.dragon_auto_lc_min_mph < 0: - self.dragon_auto_lc_min_mph = 0 - # when auto lc is smaller than assisted lc, we set assisted lc to the same speed as auto lc - if self.dragon_auto_lc_min_mph < self.dragon_assisted_lc_min_mph: - self.dragon_assisted_lc_min_mph = self.dragon_auto_lc_min_mph - # adjustable auto lc delay - self.dragon_auto_lc_delay = int(self.params.get("DragonAutoLCDelay", encoding='utf8')) - if self.dragon_auto_lc_delay < 0: - self.dragon_auto_lc_delay = 0 + if cur_time - self.last_ts >= 5.: + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_assisted_lc_enabled = self.lane_change_enabled + if self.dragon_assisted_lc_enabled: + self.dragon_auto_lc_enabled = True if self.params.get("DragonEnableAutoLC", encoding='utf8') == "1" else False + # adjustable assisted lc min speed + self.dragon_assisted_lc_min_mph = int(self.params.get("DragonAssistedLCMinMPH", encoding='utf8')) * CV.MPH_TO_MS + if self.dragon_assisted_lc_min_mph < 0: + self.dragon_assisted_lc_min_mph = 0 + if self.dragon_auto_lc_enabled: + # adjustable auto lc min speed + self.dragon_auto_lc_min_mph = int(self.params.get("DragonAutoLCMinMPH", encoding='utf8')) * CV.MPH_TO_MS + if self.dragon_auto_lc_min_mph < 0: + self.dragon_auto_lc_min_mph = 0 + # when auto lc is smaller than assisted lc, we set assisted lc to the same speed as auto lc + if self.dragon_auto_lc_min_mph < self.dragon_assisted_lc_min_mph: + self.dragon_assisted_lc_min_mph = self.dragon_auto_lc_min_mph + # adjustable auto lc delay + self.dragon_auto_lc_delay = int(self.params.get("DragonAutoLCDelay", encoding='utf8')) + if self.dragon_auto_lc_delay < 0: + self.dragon_auto_lc_delay = 0 + self.dp_last_modified = modified self.last_ts = cur_time v_ego = sm['carState'].vEgo diff --git a/selfdrive/controls/lib/planner.py b/selfdrive/controls/lib/planner.py index 1fe641d21..8fd37832c 100755 --- a/selfdrive/controls/lib/planner.py +++ b/selfdrive/controls/lib/planner.py @@ -13,6 +13,7 @@ from selfdrive.controls.lib.speed_smoother import speed_smoother from selfdrive.controls.lib.longcontrol import LongCtrlState, MIN_CAN_SPEED from selfdrive.controls.lib.fcw import FCWChecker from selfdrive.controls.lib.long_mpc import LongitudinalMpc +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified MAX_SPEED = 255.0 @@ -111,6 +112,7 @@ class Planner(): self.dragon_fast_accel = False self.dragon_accel_profile = ACCEL_NORMAL_MODE self.last_ts = 0. + self.dp_last_modified = None def choose_solution(self, v_cruise_setpoint, enabled): if enabled: @@ -147,10 +149,13 @@ class Planner(): # dragonpilot # update variable status every 5 secs if cur_time - self.last_ts >= 5.: - self.dragon_slow_on_curve = False if self.params.get("DragonEnableSlowOnCurve", encoding='utf8') == "0" else True - self.dragon_accel_profile = int(self.params.get("DragonAccelProfile", encoding='utf8')) - if self.dragon_accel_profile >= 2 or self.dragon_accel_profile <= -2: - self.dragon_accel_profile = 0 + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_slow_on_curve = False if self.params.get("DragonEnableSlowOnCurve", encoding='utf8') == "0" else True + self.dragon_accel_profile = int(self.params.get("DragonAccelProfile", encoding='utf8')) + if self.dragon_accel_profile >= 2 or self.dragon_accel_profile <= -2: + self.dragon_accel_profile = 0 + self.dp_last_modified = modified self.last_ts = cur_time long_control_state = sm['controlsState'].longControlState diff --git a/selfdrive/dragonpilot/appd/appd.py b/selfdrive/dragonpilot/appd/appd.py index a6a4e7112..64b2ae152 100644 --- a/selfdrive/dragonpilot/appd/appd.py +++ b/selfdrive/dragonpilot/appd/appd.py @@ -8,6 +8,8 @@ from selfdrive.swaglog import cloudlog from common.realtime import sec_since_boot from common.params import Params, put_nonblocking params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified +from math import floor class App(): @@ -72,6 +74,8 @@ class App(): self.set_package_permissions() self.system("pm disable %s" % self.app) + if self.manual_ctrl_param is not None: + put_nonblocking(self.manual_ctrl_param, '0') self.last_ts = sec_since_boot() def read_params(self): @@ -107,6 +111,7 @@ class App(): # app is manually ctrl, we record that if self.manual_ctrl_param is not None and self.manual_ctrl_status == self.MANUAL_ON: put_nonblocking(self.manual_ctrl_param, '0') + put_nonblocking('DragonLastModified', str(floor(time.time()))) self.manually_ctrled = True self.is_running = False @@ -280,6 +285,7 @@ def main(): thermal_status = None start_ts = sec_since_boot() init_done = False + last_modified = None while 1: #has_enabled_apps: if not init_done and sec_since_boot() - start_ts >= 10: @@ -289,10 +295,13 @@ def main(): if init_done: enabled_apps = [] has_fullscreen_apps = False - + modified = dp_get_last_modified() + if last_modified != modified: + print("modified!!!!!") for app in apps: # read params loop - app.read_params() + if last_modified != modified: + app.read_params() if app.last_is_enabled and not app.is_enabled and app.is_running: app.kill(True) @@ -305,7 +314,7 @@ def main(): app.run(True) if app.manual_ctrl_status == App.MANUAL_ON else app.kill(True) enabled_apps.append(app) - + last_modified = modified msg = messaging.recv_sock(thermal_sock, wait=True) started = msg.thermal.started # when car is running diff --git a/selfdrive/dragonpilot/dashcamd/dashcamd.py b/selfdrive/dragonpilot/dashcamd/dashcamd.py index e4b0167f3..78aa49af1 100644 --- a/selfdrive/dragonpilot/dashcamd/dashcamd.py +++ b/selfdrive/dragonpilot/dashcamd/dashcamd.py @@ -29,7 +29,7 @@ def main(gctx=None): thermal_sock = messaging.sub_sock('thermal') while 1: - if params.get("DragonWazeMode", encoding='utf8') == "0" and params.get("DragonEnableDashcam", encoding='utf8') == "1": + if params.get("DragonEnableDashcam", encoding='utf8') == "1": now = datetime.datetime.now() file_name = now.strftime("%Y-%m-%d_%H-%M-%S") os.system("screenrecord --bit-rate %s --time-limit %s %s%s.mp4 &" % (bit_rates, duration, dashcam_videos, file_name)) diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index 89697146c..9437308ba 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -1,5 +1,7 @@ #!/usr/bin/env python2.7 from common.params import Params, put_nonblocking +import time +from math import floor default_conf = { 'DragonEnableDashcam': '0', @@ -67,6 +69,7 @@ default_conf = { 'DragonBTG': 0, 'DragonBootHotspot': 0, 'DragonAccelProfile': '0', + 'DragonLastModified': str(floor(time.time())) } deprecated_conf = { @@ -80,18 +83,21 @@ deprecated_conf_invert = { # 'DragonBBUI': False } +def dp_get_last_modified(): + return Params().get('DragonLastModified', encoding='utf-8') + def dragonpilot_set_params(params): - # remove deprecated params - for old, new in deprecated_conf.items(): - if params.get(old) is not None: - if new is not None: - old_val = str(params.get(old)) - new_val = old_val - # invert the value if true - if old in deprecated_conf_invert and deprecated_conf_invert[old] is True: - new_val = "1" if old_val == "0" else "0" - put_nonblocking(new, new_val) - params.delete(old) + # # remove deprecated params + # for old, new in deprecated_conf.items(): + # if params.get(old) is not None: + # if new is not None: + # old_val = str(params.get(old)) + # new_val = old_val + # # invert the value if true + # if old in deprecated_conf_invert and deprecated_conf_invert[old] is True: + # new_val = "1" if old_val == "0" else "0" + # put_nonblocking(new, new_val) + # params.delete(old) # set params for key, val in default_conf.items(): diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index f6cd8a17d..ab5f9bd95 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -5,6 +5,7 @@ from common.params import Params params = Params() import cereal.messaging as messaging from common.realtime import sec_since_boot +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified def main(): thermal_sock = messaging.sub_sock('thermal') @@ -16,26 +17,30 @@ def main(): usb_online = False enabled = False last_enabled = False + dp_last_modified = None while 1: cur_time = sec_since_boot() if cur_time - last_ts >= 10.: - enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False - # reset timer when enabled status has changed - if not last_enabled and enabled: - shutdown_at = cur_time + secs - last_enabled = enabled - - if enabled: - secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 - # reset timer when secs num has changed - if last_secs != secs: + modified = dp_get_last_modified() + if dp_last_modified != modified: + enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False + # reset timer when enabled status has changed + if not last_enabled and enabled: shutdown_at = cur_time + secs - last_secs = secs + last_enabled = enabled - msg = messaging.recv_sock(thermal_sock, wait=True) - started = msg.thermal.started - with open("/sys/class/power_supply/usb/present") as f: - usb_online = bool(int(f.read())) + if enabled: + secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 + # reset timer when secs num has changed + if last_secs != secs: + shutdown_at = cur_time + secs + last_secs = secs + + msg = messaging.recv_sock(thermal_sock, wait=True) + started = msg.thermal.started + with open("/sys/class/power_supply/usb/present") as f: + usb_online = bool(int(f.read())) + dp_last_modified = modified if enabled: if started or usb_online: diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index 93d7b4d38..652a4c22b 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -24,6 +24,7 @@ FW_SIGNATURE = get_expected_signature() params = Params() import subprocess import re +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified ThermalStatus = log.ThermalData.ThermalStatus NetworkType = log.ThermalData.NetworkType @@ -185,13 +186,14 @@ def thermald_thread(): # dragonpilot ts_last_ip = None - ts_last_update_vars = None + ts_last_update_vars = 0 ts_last_charging_ctrl = None + dp_last_modified = None ip_addr = '255.255.255.255' - dragon_charging_ctrl = True if params.get('DragonChargingCtrl', encoding='utf8') == "1" else False - dragon_charging_max = int(params.get('DragonCharging')) - dragon_discharging_min = int(params.get('DragonDisCharging')) + dragon_charging_ctrl = False + dragon_charging_at = 70 + dragon_discharging_at = 80 while 1: health = messaging.recv_sock(health_sock, wait=True) @@ -241,7 +243,7 @@ def thermald_thread(): # dragonpilot ip Mod # update ip every 10 seconds ts = sec_since_boot() - if ts_last_ip is None or ts - ts_last_ip > 10.: + if ts_last_ip is None or ts - ts_last_ip >= 10.: try: result = subprocess.check_output(["ifconfig", "wlan0"], encoding='utf8') # pylint: disable=unexpected-keyword-arg ip_addr = re.findall(r"inet addr:((\d+\.){3}\d+)", result)[0][0] @@ -412,18 +414,28 @@ def thermald_thread(): # dragonpilot ts = sec_since_boot() # update variable status every 10 secs - if ts_last_update_vars is None or ts - ts_last_update_vars >= 10.: - dragon_charging_ctrl = True if params.get('DragonChargingCtrl', encoding='utf8') == "1" else False - dragon_charging_max = int(params.get('DragonCharging', encoding='utf8')) - dragon_discharging_min = int(params.get('DragonDisCharging', encoding='utf8')) + if ts - ts_last_update_vars >= 10.: + modified = dp_get_last_modified() + if dp_last_modified != modified: + dragon_charging_ctrl = True if params.get('DragonChargingCtrl', encoding='utf8') == "1" else False + if dragon_charging_ctrl: + try: + dragon_charging_at = int(params.get('DragonCharging', encoding='utf8')) + except TypeError: + dragon_charging_at = 70 + try: + dragon_discharging_at = int(params.get('DragonDisCharging', encoding='utf8')) + except TypeError: + dragon_discharging_at = 80 + dp_last_modified = modified ts_last_update_vars = ts # we update charging status once every min if ts_last_charging_ctrl is None or ts - ts_last_charging_ctrl >= 60.: if dragon_charging_ctrl: - if msg.thermal.batteryPercent >= dragon_charging_max: + if msg.thermal.batteryPercent >= dragon_charging_at: os.system('echo "0" > /sys/class/power_supply/battery/charging_enabled') - if msg.thermal.batteryPercent <= dragon_discharging_min: + if msg.thermal.batteryPercent <= dragon_discharging_at: os.system('echo "1" > /sys/class/power_supply/battery/charging_enabled') else: os.system('echo "1" > /sys/class/power_supply/battery/charging_enabled') diff --git a/selfdrive/ui/ui.cc b/selfdrive/ui/ui.cc index 2a7fccd1f..4a232385a 100644 --- a/selfdrive/ui/ui.cc +++ b/selfdrive/ui/ui.cc @@ -238,21 +238,21 @@ static void ui_init_vision(UIState *s, const VisionStreamBufs back_bufs, s->limit_set_speed_timeout = UI_FREQ; // dragonpilot, 1hz - s->dragon_ui_speed_timeout = UI_FREQ * 3.1; - s->dragon_ui_event_timeout = UI_FREQ * 3.2; - s->dragon_ui_maxspeed_timeout = UI_FREQ * 3.3; - s->dragon_ui_face_timeout = UI_FREQ * 3.4; - s->dragon_ui_dev_timeout = UI_FREQ * 3.5; - s->dragon_ui_dev_mini_timeout = UI_FREQ * 3.6; - s->dragon_enable_dashcam_timeout = UI_FREQ * 3.7; - s->dragon_ui_volume_boost_timeout = UI_FREQ * 3.8; - s->dragon_driving_ui_timeout = UI_FREQ * 3.9; - s->dragon_ui_lane_timeout = UI_FREQ * 4.0; - s->dragon_ui_lead_timeout = UI_FREQ * 4.1; - s->dragon_ui_path_timeout = UI_FREQ * 4.2; - s->dragon_ui_blinker_timeout = UI_FREQ * 4.3; - s->dragon_waze_mode_timeout = UI_FREQ * 4.4; - s->dragon_ui_dm_view_timeout = UI_FREQ * 4.5; + s->dragon_ui_speed_timeout = UI_FREQ * 5.1; + s->dragon_ui_event_timeout = UI_FREQ * 5.2; + s->dragon_ui_maxspeed_timeout = UI_FREQ * 5.3; + s->dragon_ui_face_timeout = UI_FREQ * 5.4; + s->dragon_ui_dev_timeout = UI_FREQ * 5.5; + s->dragon_ui_dev_mini_timeout = UI_FREQ * 5.6; + s->dragon_enable_dashcam_timeout = UI_FREQ * 5.7; + s->dragon_ui_volume_boost_timeout = UI_FREQ * 5.8; + s->dragon_driving_ui_timeout = UI_FREQ * 5.9; + s->dragon_ui_lane_timeout = UI_FREQ * 6.0; + s->dragon_ui_lead_timeout = UI_FREQ * 6.1; + s->dragon_ui_path_timeout = UI_FREQ * 6.2; + s->dragon_ui_blinker_timeout = UI_FREQ * 6.3; + s->dragon_waze_mode_timeout = UI_FREQ * 6.4; + s->dragon_ui_dm_view_timeout = UI_FREQ * 6.5; } static PathData read_path(cereal_ModelData_PathData_ptr pathp) { From fffe34e93bb1dbe275a36bc93da1949ba3557cfe Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Tue, 10 Mar 2020 15:55:48 +1000 Subject: [PATCH 04/17] remove debug codes --- selfdrive/dragonpilot/appd/appd.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/selfdrive/dragonpilot/appd/appd.py b/selfdrive/dragonpilot/appd/appd.py index 64b2ae152..86c97e282 100644 --- a/selfdrive/dragonpilot/appd/appd.py +++ b/selfdrive/dragonpilot/appd/appd.py @@ -296,8 +296,6 @@ def main(): enabled_apps = [] has_fullscreen_apps = False modified = dp_get_last_modified() - if last_modified != modified: - print("modified!!!!!") for app in apps: # read params loop if last_modified != modified: From f7a890939aa2bbf0085a409d20d51568ee8c7864 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Tue, 10 Mar 2020 16:26:49 +1000 Subject: [PATCH 05/17] add subaru support: * steering on signal. * ability to disable steer ctrl. * allow gas. --- selfdrive/car/subaru/carcontroller.py | 35 ++++++++++++++++++++++- selfdrive/car/subaru/interface.py | 40 +++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/selfdrive/car/subaru/carcontroller.py b/selfdrive/car/subaru/carcontroller.py index dce4df810..fe1f309b0 100644 --- a/selfdrive/car/subaru/carcontroller.py +++ b/selfdrive/car/subaru/carcontroller.py @@ -3,7 +3,9 @@ from selfdrive.car import apply_std_steer_torque_limits from selfdrive.car.subaru import subarucan from selfdrive.car.subaru.values import DBC from opendbc.can.packer import CANPacker - +from common.params import Params +params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified class CarControllerParams(): def __init__(self, car_fingerprint): @@ -32,9 +34,23 @@ class CarController(): self.params = CarControllerParams(car_fingerprint) self.packer = CANPacker(DBC[car_fingerprint]['pt']) + # dragonpilot + self.turning_signal_timer = 0 + self.dragon_enable_steering_on_signal = False + self.dragon_lat_ctrl = True + self.dp_last_modified = None + def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, left_line, right_line): """ Controls thread """ + # dragonpilot, don't check for param too often as it's a kernel call + if frame % 500 == 0: + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dp_last_modified = modified + P = self.params # Send CAN commands. @@ -58,6 +74,23 @@ class CarController(): if not lkas_enabled: apply_steer = 0 + # dragonpilot + 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 = 0 + else: + self.turning_signal_timer = 0 + + if not self.dragon_lat_ctrl: + apply_steer = 0 + can_sends.append(subarucan.create_steering_control(self.packer, CS.CP.carFingerprint, apply_steer, frame, P.STEER_STEP)) self.apply_steer_last = apply_steer diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index d4388727b..021adb1a9 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -7,6 +7,10 @@ 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, scale_rot_inertia, scale_tire_stiffness, gen_empty_fingerprint from selfdrive.car.interfaces import CarInterfaceBase +from common.realtime import sec_since_boot +from common.params import Params +params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified ButtonType = car.CarState.ButtonEvent.Type @@ -30,6 +34,14 @@ class CarInterface(CarInterfaceBase): if CarController is not None: self.CC = CarController(CP.carFingerprint) + # dragonpilot + self.frame = 0 + self.dragon_enable_steering_on_signal = False + self.dragon_allow_gas = False + self.ts_last_check = 0. + self.dragon_lat_ctrl = True + self.dp_last_modified = None + @staticmethod def compute_gb(accel, speed): return float(accel) / 4.0 @@ -95,6 +107,17 @@ class CarInterface(CarInterfaceBase): # returns a car.CarState def update(self, c, can_strings): + # dragonpilot, don't check for param too often as it's a kernel call + ts = sec_since_boot() + if ts - self.ts_last_check >= 5.: + modified = dp_get_last_modified() + if self.dp_last_modified != modified: + self.dragon_enable_steering_on_signal = True if params.get("DragonEnableSteeringOnSignal", encoding='utf8') == "1" else True + self.dragon_allow_gas = True if params.get("DragonAllowGas", encoding='utf8') == "1" else False + self.dragon_lat_ctrl = False if params.get("DragonLatCtrl", encoding='utf8') == "0" else True + self.dp_last_modified = modified + self.ts_last_check = ts + self.pt_cp.update_strings(can_strings) self.cam_cp.update_strings(can_strings) @@ -166,17 +189,24 @@ class CarInterface(CarInterfaceBase): if ret.doorOpen: events.append(create_event('doorOpen', [ET.NO_ENTRY, ET.SOFT_DISABLE])) + if not self.dragon_lat_ctrl: + events.append(create_event('manualSteeringRequired', [ET.WARNING])) + elif (self.CS.left_blinker_on or self.CS.right_blinker_on) and self.dragon_enable_steering_on_signal: + events.append(create_event('manualSteeringRequiredBlinkersOn', [ET.WARNING])) + if self.CS.acc_active and not self.acc_active_prev: events.append(create_event('pcmEnable', [ET.ENABLE])) if not self.CS.acc_active: events.append(create_event('pcmDisable', [ET.USER_DISABLE])) - # disable on gas pedal rising edge - if (ret.gasPressed and not self.gas_pressed_prev): - events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) + # DragonAllowGas + if not self.dragon_allow_gas: + # disable on gas pedal rising edge + if (ret.gasPressed and not self.gas_pressed_prev): + events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) - if ret.gasPressed: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) + if ret.gasPressed: + events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) ret.events = events From 5e1c69b05cff9212657551de692d99125538b7ff Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 11 Mar 2020 11:20:19 +1000 Subject: [PATCH 06/17] allow higher error tolerance when dealing with steering torque in toyota. --- panda/board/safety/safety_toyota.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/panda/board/safety/safety_toyota.h b/panda/board/safety/safety_toyota.h index 9b06a7cd0..fa0848a04 100644 --- a/panda/board/safety/safety_toyota.h +++ b/panda/board/safety/safety_toyota.h @@ -4,8 +4,8 @@ const int TOYOTA_MAX_TORQUE = 1500; // max torque cmd allowed ever // rate based torque limit + stay within actually applied // packet is sent at 100hz, so this limit is 1000/sec const int TOYOTA_MAX_RATE_UP = 10; // ramp up slow -const int TOYOTA_MAX_RATE_DOWN = 25; // ramp down fast -const int TOYOTA_MAX_TORQUE_ERROR = 350; // max torque cmd in excess of torque motor +const int TOYOTA_MAX_RATE_DOWN = 44; // ramp down fast +const int TOYOTA_MAX_TORQUE_ERROR = 500; // max torque cmd in excess of torque motor // real time torque limit to prevent controls spamming // the real time limit is 1500/sec From bcc399f67758bf683a76a995257b9386f4b39830 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 11 Mar 2020 12:48:51 +1000 Subject: [PATCH 07/17] move driver monitor patch to dmonitoringd. --- selfdrive/controls/dmonitoringd.py | 44 +++++++++++++++++++++++- selfdrive/controls/lib/driver_monitor.py | 30 ++-------------- 2 files changed, 46 insertions(+), 28 deletions(-) diff --git a/selfdrive/controls/dmonitoringd.py b/selfdrive/controls/dmonitoringd.py index 3c888d7b3..a6c74571e 100755 --- a/selfdrive/controls/dmonitoringd.py +++ b/selfdrive/controls/dmonitoringd.py @@ -1,12 +1,15 @@ #!/usr/bin/env python3 import gc -from common.realtime import set_realtime_priority +from common.realtime import set_realtime_priority, sec_since_boot from common.params import Params, put_nonblocking import cereal.messaging as messaging from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET from selfdrive.controls.lib.driver_monitor import DriverStatus, MAX_TERMINAL_ALERTS, MAX_TERMINAL_DURATION from selfdrive.locationd.calibration_helpers import Calibration from selfdrive.controls.lib.gps_helpers import is_rhd_region +from common.params import Params +params = Params() +from selfdrive.dragonpilot.dragonconf import dp_get_last_modified def dmonitoringd_thread(sm=None, pm=None): gc.disable() @@ -40,8 +43,47 @@ def dmonitoringd_thread(sm=None, pm=None): v_cruise_last = 0 driver_engaged = False + # dragonpilot + last_ts = 0 + dp_last_modified = None + dp_enable_driver_safety_check = True + dp_enable_driver_monitoring = True + # 10Hz <- dmonitoringmodeld while True: + cur_time = sec_since_boot() + if cur_time - last_ts >= 5.: + modified = dp_get_last_modified() + if dp_last_modified != modified: + dp_enable_driver_safety_check = False if params.get("DragonEnableDriverSafetyCheck", encoding='utf8') == "0" else True + # load driver monitor val only when safety is on + if dp_enable_driver_safety_check: + dp_enable_driver_monitoring = False if params.get("DragonEnableDriverMonitoring", encoding='utf8') == "0" else True + # load steering monitor timer val only when driver monitor is on + if dp_enable_driver_monitoring: + try: + dp_awareness_time = int(params.get("DragonSteeringMonitorTimer", encoding='utf8')) + except TypeError: + dp_awareness_time = 0. + driver_status.awareness_time = 86400 if dp_awareness_time <= 0. else dp_awareness_time * 60. + dp_last_modified = modified + last_ts = cur_time + + # reset all awareness val + if not dp_enable_driver_safety_check: + dp_enable_driver_monitoring = False + driver_status.awareness = 1. + driver_status.awareness_active = 1. + driver_status.awareness_passive = 1. + driver_status.terminal_alert_cnt = 0 + driver_status.terminal_time = 0 + + # dm don't check rhd, set to true + if not dp_enable_driver_monitoring: + driver_status.awareness_time = 86400 + driver_status.is_rhd_region = True + driver_status.is_rhd_region_checked = True + sm.update() # GPS coords RHD parsing, once every restart diff --git a/selfdrive/controls/lib/driver_monitor.py b/selfdrive/controls/lib/driver_monitor.py index 3c0a2f50b..2b740000f 100644 --- a/selfdrive/controls/lib/driver_monitor.py +++ b/selfdrive/controls/lib/driver_monitor.py @@ -1,12 +1,9 @@ from common.numpy_fast import interp from math import atan2, sqrt -from common.realtime import DT_DMON, sec_since_boot +from common.realtime import DT_DMON from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET from common.filter_simple import FirstOrderFilter from common.stat_live import RunningStatFilter -from common.params import Params -params = Params() -from selfdrive.dragonpilot.dragonconf import dp_get_last_modified _AWARENESS_TIME = 70. # one minute limit without user touching steering wheels make the car enter a terminal status _AWARENESS_PRE_TIME_TILL_TERMINAL = 15. # a first alert is issued 25s before expiration @@ -115,11 +112,7 @@ class DriverStatus(): self.is_rhd_region_checked = False # dragonpilot - self.last_ts = 0 - self.dp_last_modified = None - self.awareness_time = 100 - self.dragon_enable_driver_safety_check = True - self.dragon_enable_driver_monitoring = True + self.awareness_time = 70. self._set_timers(active_monitoring=True) @@ -184,9 +177,6 @@ class DriverStatus(): if len(driver_state.faceOrientation) == 0 or len(driver_state.facePosition) == 0 or len(driver_state.faceOrientationStd) == 0 or len(driver_state.facePositionStd) == 0: return - if not self.dragon_enable_driver_monitoring: - self.is_rhd_region = True - self.pose.roll, self.pose.pitch, self.pose.yaw = face_orientation_from_net(driver_state.faceOrientation, driver_state.facePosition, cal_rpy) self.pose.pitch_std = driver_state.faceOrientationStd[0] self.pose.yaw_std = driver_state.faceOrientationStd[1] @@ -222,21 +212,7 @@ class DriverStatus(): self.hi_stds = 0 def update(self, events, driver_engaged, ctrl_active, standstill): - cur_time = sec_since_boot() - if cur_time - self.last_ts >= 5.: - modified = dp_get_last_modified() - if self.dp_last_modified != modified: - self.awareness_time = int(params.get("DragonSteeringMonitorTimer", encoding='utf8')) - self.awareness_time = 100 if self.awareness_time <= 0. else self.awareness_time * 60. - - self.dragon_enable_driver_safety_check = False if params.get("DragonEnableDriverSafetyCheck", encoding='utf8') == "0" else True - if self.dragon_enable_driver_safety_check: - self.dragon_enable_driver_monitoring = False if params.get("DragonEnableDriverMonitoring", encoding='utf8') == "0" else True - else: - self.dragon_enable_driver_monitoring = False - self.dp_last_modified = modified - self.last_ts = cur_time - if (driver_engaged and self.awareness > 0) or not ctrl_active or not self.dragon_enable_driver_safety_check: + if (driver_engaged and self.awareness > 0) or not ctrl_active: # reset only when on disengagement if red reached self.awareness = 1. self.awareness_active = 1. From 246003d345ed34b3c6f304b3adf6230a1260a156 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 11 Mar 2020 13:15:23 +1000 Subject: [PATCH 08/17] add warning for mismatch fw --- selfdrive/car/car_helpers.py | 1 + 1 file changed, 1 insertion(+) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index f11ad374f..a223b5cea 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -237,6 +237,7 @@ def get_car(logcan, sendcan, has_relay=False): y.start() cloudlog.warning("car doesn't match any fingerprints: %r", fingerprints) + cloudlog.warning("car doesn't match any fw: %s" % car_fw) candidate = "mock" if is_online(): From fe055633e7e134208775063b2cd0a53f3d99981a Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 11 Mar 2020 13:16:13 +1000 Subject: [PATCH 09/17] added manual CIVIC_BOSCH fw fingerprint from sentry. (AlexNoop) --- selfdrive/car/honda/values.py | 1 + 1 file changed, 1 insertion(+) diff --git a/selfdrive/car/honda/values.py b/selfdrive/car/honda/values.py index dfcbc566e..132d87da2 100644 --- a/selfdrive/car/honda/values.py +++ b/selfdrive/car/honda/values.py @@ -307,6 +307,7 @@ FW_VERSIONS = { b'37805-5AN-LJ20\x00\x00', b'37805-5AZ-E850\x00\x00', b'37805-5BB-L640\x00\x00', + b'37805-5AN-E410\x00\x00', # AlexNoop's CIVIC_BOSCH (manual car?) ], (Ecu.unknown, 0x18da1ef1, None): [ b'28101-5CG-A920\x00\x00', From 7d95159d24b5e626a983599043846115b5159926 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Wed, 11 Mar 2020 19:34:44 +1000 Subject: [PATCH 10/17] fix up driver/steering monitor toggle --- selfdrive/controls/dmonitoringd.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/selfdrive/controls/dmonitoringd.py b/selfdrive/controls/dmonitoringd.py index a6c74571e..a1639b522 100755 --- a/selfdrive/controls/dmonitoringd.py +++ b/selfdrive/controls/dmonitoringd.py @@ -59,31 +59,30 @@ def dmonitoringd_thread(sm=None, pm=None): # load driver monitor val only when safety is on if dp_enable_driver_safety_check: dp_enable_driver_monitoring = False if params.get("DragonEnableDriverMonitoring", encoding='utf8') == "0" else True - # load steering monitor timer val only when driver monitor is on - if dp_enable_driver_monitoring: - try: - dp_awareness_time = int(params.get("DragonSteeringMonitorTimer", encoding='utf8')) - except TypeError: - dp_awareness_time = 0. - driver_status.awareness_time = 86400 if dp_awareness_time <= 0. else dp_awareness_time * 60. + # load steering monitor timer val only when driver monitor is on + if dp_enable_driver_safety_check: + try: + dp_awareness_time = int(params.get("DragonSteeringMonitorTimer", encoding='utf8')) + except TypeError: + dp_awareness_time = 0. + driver_status.awareness_time = 86400 if dp_awareness_time <= 0. else dp_awareness_time * 60. dp_last_modified = modified last_ts = cur_time - # reset all awareness val if not dp_enable_driver_safety_check: dp_enable_driver_monitoring = False + driver_status.awareness_time = 86400 + + # reset all awareness val and set to rhd region, this will enforce steering monitor. + if not dp_enable_driver_monitoring: + driver_status.is_rhd_region = True + driver_status.is_rhd_region_checked = True driver_status.awareness = 1. driver_status.awareness_active = 1. driver_status.awareness_passive = 1. driver_status.terminal_alert_cnt = 0 driver_status.terminal_time = 0 - # dm don't check rhd, set to true - if not dp_enable_driver_monitoring: - driver_status.awareness_time = 86400 - driver_status.is_rhd_region = True - driver_status.is_rhd_region_checked = True - sm.update() # GPS coords RHD parsing, once every restart From d465fc9a80fb6d8d894752116a073c266a13e505 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Thu, 12 Mar 2020 10:54:45 +1000 Subject: [PATCH 11/17] added manual CIVIC_BOSCH fingerprint. (AlexNoop) --- selfdrive/car/honda/values.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/selfdrive/car/honda/values.py b/selfdrive/car/honda/values.py index 132d87da2..5c7562267 100644 --- a/selfdrive/car/honda/values.py +++ b/selfdrive/car/honda/values.py @@ -73,6 +73,10 @@ FINGERPRINTS = { # 2017 Civic Hatchback EX, 2019 Civic Sedan Touring Canadian, and 2018 Civic Hatchback Executive Premium 1.0L CVT European 57: 3, 148: 8, 228: 5, 304: 8, 330: 8, 344: 8, 380: 8, 399: 7, 401: 8, 420: 8, 427: 3, 428: 8, 432: 7, 441: 5, 450: 8, 460: 3, 464: 8, 470: 2, 476: 7, 477: 8, 479: 8, 490: 8, 493: 5, 495: 8, 506: 8, 545: 6, 597: 8, 662: 4, 773: 7, 777: 8, 780: 8, 795: 8, 800: 8, 804: 8, 806: 8, 808: 8, 829: 5, 862: 8, 884: 8, 891: 8, 892: 8, 927: 8, 929: 8, 985: 3, 1024: 5, 1027: 5, 1029: 8, 1036: 8, 1039: 8, 1108: 8, 1302: 8, 1322: 5, 1361: 5, 1365: 5, 1424: 5, 1600: 5, 1601: 8, 1625: 5, 1629: 5, 1633: 8, }, + # Manual CIVIC from AlexNoop + { + 57: 3, 148: 8, 228: 5, 274: 3, 304: 8, 330: 8, 344: 8, 380: 8, 399: 7, 420: 8, 427: 3, 428: 8, 432: 7, 441: 5, 450: 8, 460: 3, 464: 8, 470: 2, 476: 7, 477: 8, 479: 8, 490: 8, 493: 5, 495: 8, 506: 8, 545: 6, 597: 8, 662: 4, 773: 7, 777: 8, 780: 8, 795: 8, 800: 8, 804: 8, 806: 8, 808: 8, 829: 5, 862: 8, 884: 8, 891: 8, 892: 8, 927: 8, 929: 8, 985: 3, 1024: 5, 1029: 8, 1036: 8, 1108: 8, 1302: 8, 1322: 5, 1361: 5, 1365: 5, 1424: 5, 1600: 5, 1601: 8, 1625: 5, 1633: 8, + }, # 2017 Civic Hatchback LX { 57: 3, 148: 8, 228: 5, 304: 8, 330: 8, 344: 8, 380: 8, 399: 7, 401: 8, 420: 8, 423: 2, 427: 3, 428: 8, 432: 7, 441: 5, 450: 8, 464: 8, 470: 2, 476: 7, 477: 8, 479: 8, 490: 8, 493: 5, 495: 8, 506: 8, 545: 6, 597: 8, 662: 4, 773: 7, 777: 8, 780: 8, 795: 8, 800: 8, 804: 8, 806: 8, 808: 8, 815: 8, 825: 4, 829: 5, 846: 8, 862: 8, 881: 8, 882: 4, 884: 8, 888: 8, 891: 8, 892: 8, 918: 7, 927: 8, 929: 8, 983: 8, 985: 3, 1024: 5, 1027: 5, 1029: 8, 1036: 8, 1039: 8, 1064: 7, 1092: 1, 1108: 8, 1125: 8, 1127: 2, 1296: 8, 1302: 8, 1322: 5, 1361: 5, 1365: 5, 1424: 5, 1600: 5, 1601: 8, 1633: 8 @@ -307,7 +311,7 @@ FW_VERSIONS = { b'37805-5AN-LJ20\x00\x00', b'37805-5AZ-E850\x00\x00', b'37805-5BB-L640\x00\x00', - b'37805-5AN-E410\x00\x00', # AlexNoop's CIVIC_BOSCH (manual car?) + b'37805-5AN-E410\x00\x00', # AlexNoop's Manual CIVIC_BOSCH ], (Ecu.unknown, 0x18da1ef1, None): [ b'28101-5CG-A920\x00\x00', From 8152d530c7715786e55e3b3e087ac11fab53c081 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Thu, 12 Mar 2020 10:56:02 +1000 Subject: [PATCH 12/17] Fix charging ctrl logic. --- selfdrive/thermald.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index 652a4c22b..109688e39 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -192,8 +192,8 @@ def thermald_thread(): ip_addr = '255.255.255.255' dragon_charging_ctrl = False - dragon_charging_at = 70 - dragon_discharging_at = 80 + dragon_to_discharge = 70 + dragon_to_charge = 60 while 1: health = messaging.recv_sock(health_sock, wait=True) @@ -420,22 +420,22 @@ def thermald_thread(): dragon_charging_ctrl = True if params.get('DragonChargingCtrl', encoding='utf8') == "1" else False if dragon_charging_ctrl: try: - dragon_charging_at = int(params.get('DragonCharging', encoding='utf8')) + dragon_to_discharge = int(params.get('DragonCharging', encoding='utf8')) except TypeError: - dragon_charging_at = 70 + dragon_to_discharge = 70 try: - dragon_discharging_at = int(params.get('DragonDisCharging', encoding='utf8')) + dragon_to_charge = int(params.get('DragonDisCharging', encoding='utf8')) except TypeError: - dragon_discharging_at = 80 + dragon_to_charge = 60 dp_last_modified = modified ts_last_update_vars = ts # we update charging status once every min if ts_last_charging_ctrl is None or ts - ts_last_charging_ctrl >= 60.: if dragon_charging_ctrl: - if msg.thermal.batteryPercent >= dragon_charging_at: + if msg.thermal.batteryPercent >= dragon_to_discharge: os.system('echo "0" > /sys/class/power_supply/battery/charging_enabled') - if msg.thermal.batteryPercent <= dragon_discharging_at: + if msg.thermal.batteryPercent <= dragon_to_charge: os.system('echo "1" > /sys/class/power_supply/battery/charging_enabled') else: os.system('echo "1" > /sys/class/power_supply/battery/charging_enabled') From 053418d46bc3780f141c23b40eb1e5cc354df1ea Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Thu, 12 Mar 2020 23:21:06 +1000 Subject: [PATCH 13/17] fix shutdownd logic error --- selfdrive/dragonpilot/shutdownd/shutdownd.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index ab5f9bd95..cbf104554 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -11,12 +11,12 @@ def main(): thermal_sock = messaging.sub_sock('thermal') last_ts = 0 secs = 0 - last_secs = 0 + last_secs = None shutdown_at = 0 started = False usb_online = False enabled = False - last_enabled = False + last_enabled = None dp_last_modified = None while 1: cur_time = sec_since_boot() @@ -24,31 +24,25 @@ def main(): modified = dp_get_last_modified() if dp_last_modified != modified: enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False - # reset timer when enabled status has changed - if not last_enabled and enabled: - shutdown_at = cur_time + secs - last_enabled = enabled - if enabled: secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 # reset timer when secs num has changed - if last_secs != secs: + if last_secs != secs or last_enabled != enabled: shutdown_at = cur_time + secs - last_secs = secs msg = messaging.recv_sock(thermal_sock, wait=True) started = msg.thermal.started with open("/sys/class/power_supply/usb/present") as f: usb_online = bool(int(f.read())) + last_enabled = enabled dp_last_modified = modified - + last_ts = cur_time if enabled: if started or usb_online: shutdown_at = cur_time + secs else: if secs > 0 and cur_time >= shutdown_at: os.system('LD_LIBRARY_PATH="" svc power shutdown') - time.sleep(10) if __name__ == "__main__": From 5918e54e98739b4c4a7a2c61388f2ccf2c60a632 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Thu, 12 Mar 2020 23:49:03 +1000 Subject: [PATCH 14/17] remove duplicated candidate --- selfdrive/car/toyota/interface.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 62e60f200..69e052e5a 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -225,16 +225,6 @@ class CarInterface(CarInterfaceBase): ret.mass = 3800. * CV.LB_TO_KG + STD_CARGO_KG ret.lateralTuning.pid.kf = 0.00007818594 - elif candidate == CAR.RAV4H_TSS2: - stop_and_go = True - ret.safetyParam = 73 - ret.wheelbase = 2.68986 - ret.steerRatio = 14.3 - tire_stiffness_factor = 0.7933 - ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.6], [0.1]] - ret.mass = 3800. * CV.LB_TO_KG + STD_CARGO_KG - ret.lateralTuning.pid.kf = 0.00007818594 - elif candidate in [CAR.COROLLA_TSS2, CAR.COROLLAH_TSS2]: stop_and_go = True ret.safetyParam = 73 From e0456a01a18f850c1e9a10a655bc93a706969e12 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Fri, 13 Mar 2020 12:38:58 +1000 Subject: [PATCH 15/17] disable time validation --- selfdrive/thermald.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/selfdrive/thermald.py b/selfdrive/thermald.py index 109688e39..495df408b 100755 --- a/selfdrive/thermald.py +++ b/selfdrive/thermald.py @@ -286,15 +286,16 @@ def thermald_thread(): # **** starting logic **** # Check for last update time and display alerts if needed - now = datetime.datetime.now() - - # show invalid date/time alert - time_valid = now.year >= 2019 - if time_valid and not time_valid_prev: - params.delete("Offroad_InvalidTime") - if not time_valid and time_valid_prev: - params.put("Offroad_InvalidTime", json.dumps(OFFROAD_ALERTS["Offroad_InvalidTime"])) - time_valid_prev = time_valid + # now = datetime.datetime.now() + # + # # show invalid date/time alert + # time_valid = now.year >= 2019 + # if time_valid and not time_valid_prev: + # params.delete("Offroad_InvalidTime") + # if not time_valid and time_valid_prev: + # params.put("Offroad_InvalidTime", json.dumps(OFFROAD_ALERTS["Offroad_InvalidTime"])) + # time_valid_prev = time_valid + time_valid = True # Show update prompt # try: From 227229350840b11d600898c1f3d4c5a680d109c0 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Fri, 13 Mar 2020 14:02:11 +1000 Subject: [PATCH 16/17] fix shutdownd logic --- selfdrive/dragonpilot/shutdownd/shutdownd.py | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/selfdrive/dragonpilot/shutdownd/shutdownd.py b/selfdrive/dragonpilot/shutdownd/shutdownd.py index cbf104554..702bda718 100644 --- a/selfdrive/dragonpilot/shutdownd/shutdownd.py +++ b/selfdrive/dragonpilot/shutdownd/shutdownd.py @@ -26,23 +26,23 @@ def main(): enabled = True if params.get("DragonEnableAutoShutdown", encoding='utf8') == '1' else False if enabled: secs = int(params.get("DragonAutoShutdownAt", encoding='utf8')) * 60 - # reset timer when secs num has changed - if last_secs != secs or last_enabled != enabled: - shutdown_at = cur_time + secs - msg = messaging.recv_sock(thermal_sock, wait=True) - started = msg.thermal.started - with open("/sys/class/power_supply/usb/present") as f: - usb_online = bool(int(f.read())) - last_enabled = enabled dp_last_modified = modified - last_ts = cur_time - if enabled: - if started or usb_online: + + if enabled: + msg = messaging.recv_sock(thermal_sock, wait=True) + started = msg.thermal.started + usb_online = msg.thermal.usbOnline + + if last_enabled != enabled or last_secs != secs or started or usb_online: shutdown_at = cur_time + secs - else: - if secs > 0 and cur_time >= shutdown_at: - os.system('LD_LIBRARY_PATH="" svc power shutdown') + + last_enabled = enabled + last_secs = secs + last_ts = cur_time + + if enabled and not started and not usb_online and secs > 0 and cur_time >= shutdown_at: + os.system('LD_LIBRARY_PATH="" svc power shutdown') time.sleep(10) if __name__ == "__main__": From 11be9b8a908430bf247b5ad1d93ad0d9c4999e47 Mon Sep 17 00:00:00 2001 From: dragonpilot Date: Sat, 14 Mar 2020 11:11:03 +1000 Subject: [PATCH 17/17] bump prius mass, tested by Wei --- selfdrive/car/toyota/interface.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 69e052e5a..ebb26394f 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -74,7 +74,7 @@ class CarInterface(CarInterfaceBase): ret.wheelbase = 2.70 ret.steerRatio = 15.74 # unknown end-to-end spec tire_stiffness_factor = 0.6371 # hand-tune - ret.mass = 3045. * CV.LB_TO_KG + STD_CARGO_KG + ret.mass = 3370. * CV.LB_TO_KG + STD_CARGO_KG ret.lateralTuning.init('indi') ret.lateralTuning.indi.innerLoopGain = 4.0