mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-25 07:52:03 +08:00
將 dragonconf 移至系統的 params, 方便將來移植到 APK
This commit is contained in:
@@ -76,6 +76,12 @@ keys = {
|
||||
"SubscriberInfo": [TxType.PERSISTENT],
|
||||
"TrainingVersion": [TxType.PERSISTENT],
|
||||
"Version": [TxType.PERSISTENT],
|
||||
#dragonpilot config
|
||||
"d_enableDashcam": [TxType.PERSISTENT],
|
||||
"d_enableDriverMonitor": [TxType.PERSISTENT],
|
||||
"d_autoShutdownAt": [TxType.PERSISTENT],
|
||||
"d_tempDisableSteerOnSignal": [TxType.PERSISTENT],
|
||||
"d_allowGasOnOP": [TxType.PERSISTENT],
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ from selfdrive.car import create_gas_command
|
||||
from selfdrive.car.honda import hondacan
|
||||
from selfdrive.car.honda.values import AH, CruiseButtons, CAR
|
||||
from selfdrive.can.packer import CANPacker
|
||||
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
|
||||
dragonconf = dragonconf()
|
||||
from common.params import Params
|
||||
params = Params()
|
||||
|
||||
def actuator_hystereses(brake, braking, brake_steady, v_ego, car_fingerprint):
|
||||
# hyst params
|
||||
@@ -148,8 +148,8 @@ class CarController(object):
|
||||
# Send CAN commands.
|
||||
can_sends = []
|
||||
|
||||
if (CS.left_blinker_on or CS.right_blinker_on) and dragonconf.conf["tempDisableSteerOnSignal"]:
|
||||
apply_steer = 0.
|
||||
if (CS.left_blinker_on or CS.right_blinker_on) and params.get("d_tempDisableSteerOnSignal") == "1":
|
||||
apply_steer = 0
|
||||
# Send steering command.
|
||||
idx = frame % 4
|
||||
can_sends.append(hondacan.create_steering_control(self.packer, apply_steer,
|
||||
@@ -168,9 +168,9 @@ class CarController(object):
|
||||
can_sends.append(hondacan.spam_buttons_command(self.packer, CruiseButtons.RES_ACCEL, idx))
|
||||
|
||||
else:
|
||||
if CS.car_gas > 0 and dragonconf.conf["allowGasOnOP"]:
|
||||
if CS.car_gas > 0 and params.get("d_allowGasOnOP") == "1":
|
||||
apply_brake = 0
|
||||
apply_gas = 0.
|
||||
apply_gas = 0
|
||||
# Send gas and brake commands.
|
||||
if (frame % 2) == 0:
|
||||
idx = frame // 2
|
||||
|
||||
@@ -11,8 +11,8 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel
|
||||
from selfdrive.car.honda.carstate import CarState, get_can_parser, get_cam_can_parser
|
||||
from selfdrive.car.honda.values import CruiseButtons, CAR, HONDA_BOSCH, AUDIO_HUD, VISUAL_HUD
|
||||
from selfdrive.controls.lib.planner import _A_CRUISE_MAX_V_FOLLOWING
|
||||
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
|
||||
dragonconf = dragonconf()
|
||||
from common.params import Params
|
||||
params = Params()
|
||||
|
||||
# msgs sent for steering controller by camera module on can 0.
|
||||
# those messages are mutually exclusive on CRV and non-CRV cars
|
||||
@@ -540,13 +540,13 @@ class CarInterface(object):
|
||||
events.append(create_event('speedTooLow', [ET.NO_ENTRY]))
|
||||
|
||||
# disable on pedals rising edge or when brake is pressed and speed isn't zero
|
||||
if ret.gasPressed and not self.gas_pressed_prev and not dragonconf.conf["allowGasOnOP"]:
|
||||
if ret.gasPressed and not self.gas_pressed_prev and params.get("d_allowGasOnOP") == "0":
|
||||
events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE]))
|
||||
|
||||
if ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001):
|
||||
events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE]))
|
||||
|
||||
if ret.gasPressed and not dragonconf.conf["allowGasOnOP"]:
|
||||
if ret.gasPressed and params.get("d_allowGasOnOP") == "0":
|
||||
events.append(create_event('pedalPressed', [ET.PRE_ENABLE]))
|
||||
|
||||
# it can happen that car cruise disables while comma system is enabled: need to
|
||||
|
||||
@@ -8,8 +8,8 @@ from selfdrive.car.toyota.toyotacan import make_can_msg, create_video_target,\
|
||||
create_fcw_command
|
||||
from selfdrive.car.toyota.values import ECU, STATIC_MSGS, TSSP2_CAR
|
||||
from selfdrive.can.packer import CANPacker
|
||||
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
|
||||
dragonconf = dragonconf()
|
||||
from common.params import Params
|
||||
params = Params()
|
||||
|
||||
|
||||
VisualAlert = car.CarControl.HUDControl.VisualAlert
|
||||
@@ -200,8 +200,9 @@ class CarController(object):
|
||||
|
||||
can_sends = []
|
||||
|
||||
if (CS.left_blinker_on or CS.right_blinker_on) and dragonconf.conf["tempDisableSteerOnSignal"]:
|
||||
apply_steer = 0.
|
||||
if (CS.left_blinker_on or CS.right_blinker_on) and params.get("d_tempDisableSteerOnSignal") == "1":
|
||||
apply_steer = 0
|
||||
apply_steer_req = 0
|
||||
#*** control msgs ***
|
||||
#print("steer {0} {1} {2} {3}".format(apply_steer, min_lim, max_lim, CS.steer_torque_motor)
|
||||
|
||||
@@ -220,7 +221,7 @@ class CarController(object):
|
||||
elif ECU.APGS in self.fake_ecus:
|
||||
can_sends.append(create_ipas_steer_command(self.packer, 0, 0, True))
|
||||
|
||||
if CS.gas_pressed and dragonconf.conf["allowGasOnOP"]:
|
||||
if CS.gas_pressed and params.get("d_allowGasOnOP") == "1":
|
||||
apply_accel = 0
|
||||
apply_gas = 0
|
||||
# accel cmd comes from DSU, but we can spam can to cancel the system even if we are using lat only control
|
||||
|
||||
@@ -7,9 +7,8 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel
|
||||
from selfdrive.car.toyota.carstate import CarState, get_can_parser, get_cam_can_parser
|
||||
from selfdrive.car.toyota.values import ECU, check_ecu_msgs, CAR, NO_STOP_TIMER_CAR
|
||||
from selfdrive.swaglog import cloudlog
|
||||
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
|
||||
dragonconf = dragonconf()
|
||||
|
||||
from common.params import Params
|
||||
params = Params()
|
||||
|
||||
class CarInterface(object):
|
||||
def __init__(self, CP, CarController):
|
||||
@@ -375,7 +374,7 @@ class CarInterface(object):
|
||||
# while in standstill, send a user alert
|
||||
events.append(create_event('manualRestart', [ET.WARNING]))
|
||||
|
||||
if ret.gasPressed and not self.gas_pressed_prev and not dragonconf.conf["allowGasOnOP"]:
|
||||
if ret.gasPressed and not self.gas_pressed_prev and params.get("d_allowGasOnOP") == "0":
|
||||
events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE]))
|
||||
|
||||
if ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001):
|
||||
@@ -386,7 +385,7 @@ class CarInterface(object):
|
||||
(ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001)):
|
||||
events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE]))
|
||||
|
||||
if ret.gasPressed and not dragonconf.conf["allowGasOnOP"]:
|
||||
if ret.gasPressed and params.get("d_allowGasOnOP") == "0":
|
||||
events.append(create_event('pedalPressed', [ET.PRE_ENABLE]))
|
||||
|
||||
ret.events = events
|
||||
|
||||
@@ -2,8 +2,8 @@ import numpy as np
|
||||
from common.realtime import sec_since_boot
|
||||
from selfdrive.controls.lib.drive_helpers import create_event, EventTypes as ET
|
||||
from common.filter_simple import FirstOrderFilter
|
||||
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
|
||||
dragonconf = dragonconf()
|
||||
from common.params import Params
|
||||
params = Params()
|
||||
|
||||
_DT = 0.01 # update runs at 100Hz
|
||||
_DTM = 0.1 # DM runs at 10Hz
|
||||
@@ -147,7 +147,7 @@ class DriverStatus():
|
||||
not (standstill and self.awareness - self.step_change <= self.threshold_prompt):
|
||||
self.awareness = max(self.awareness - self.step_change, -0.1)
|
||||
|
||||
if dragonconf.conf["enableDriverMonitor"]:
|
||||
if params.get("d_enableDriverMonitor") == "1":
|
||||
alert = None
|
||||
if self.awareness <= 0.:
|
||||
# terminal red alert: disengagement required
|
||||
|
||||
@@ -13,8 +13,8 @@ import datetime
|
||||
import zmq
|
||||
import selfdrive.messaging as messaging
|
||||
from selfdrive.services import service_list
|
||||
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
|
||||
dragonconf = dragonconf()
|
||||
from common.params import Params
|
||||
params = Params()
|
||||
|
||||
dashcam_videos = '/sdcard/dashcam/'
|
||||
duration = 60 # max is 180
|
||||
@@ -31,7 +31,7 @@ def main(gctx=None):
|
||||
thermal_sock = messaging.sub_sock(context, service_list['thermal'].port)
|
||||
|
||||
while 1:
|
||||
if dragonconf.conf["enableDashcam"]:
|
||||
if params.get("d_enableDashcam") == "1":
|
||||
# get health of board, log this in "thermal"
|
||||
msg = messaging.recv_sock(thermal_sock, wait=True)
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python2.7
|
||||
import os
|
||||
import json
|
||||
|
||||
file = '/data/dragonpilot.json'
|
||||
|
||||
|
||||
default_conf = {
|
||||
'd_enableDashcam': '1',
|
||||
'd_enableDriverMonitor': '1',
|
||||
'd_autoShutdownAt': '1800', # shutdown after 30 mins
|
||||
'd_tempDisableSteerOnSignal': '0',
|
||||
'd_allowGasOnOP': '0',
|
||||
}
|
||||
|
||||
def write_json_config(config):
|
||||
with open(file, 'w') as f:
|
||||
json.dump(config, f, indent=2, sort_keys=True)
|
||||
os.chmod(file, 0644)
|
||||
|
||||
def dragonpilot_set_params(params):
|
||||
# create new json file
|
||||
if not os.path.isfile(file):
|
||||
write_json_config(default_conf)
|
||||
config = default_conf
|
||||
else:
|
||||
# load from json
|
||||
with open(file, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
json_update_needed = False
|
||||
# add new keys
|
||||
for key, val in default_conf.items():
|
||||
if key not in config:
|
||||
json_update_needed = True
|
||||
config[key] = val
|
||||
|
||||
# remove invalid keys
|
||||
for key, val in config.items():
|
||||
if key not in default_conf:
|
||||
json_update_needed = True
|
||||
config.pop(key, None)
|
||||
|
||||
# write to json if it's been updated
|
||||
if json_update_needed:
|
||||
write_json_config(config)
|
||||
|
||||
# set params
|
||||
for key, val in config.items():
|
||||
params.put(key, str(val))
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
#!/usr/bin/env python2.7
|
||||
import os
|
||||
import json
|
||||
|
||||
file = '/data/dragonpilot.json'
|
||||
|
||||
class dragonconf():
|
||||
|
||||
def __init__(self):
|
||||
self.conf = self.read()
|
||||
|
||||
def read(self):
|
||||
has_new_def = False
|
||||
config = {}
|
||||
if not os.path.isfile(file):
|
||||
self.write(config)
|
||||
|
||||
with open(file, 'r') as f:
|
||||
config = json.load(f)
|
||||
|
||||
# add config here
|
||||
|
||||
# Dashcam, default Enable
|
||||
if "enableDashCam" not in config:
|
||||
config["enableDashCam"] = True
|
||||
has_new_def = True
|
||||
if has_new_def:
|
||||
self.write(config)
|
||||
|
||||
# Driver Monitor, default Enable
|
||||
if "enableDriverMonitor" not in config:
|
||||
config["enableDriverMonitor"] = True
|
||||
has_new_def = True
|
||||
if has_new_def:
|
||||
self.write(config)
|
||||
|
||||
# Auto shutdown, default 0 (disable)
|
||||
if "autoShutdownAt" not in config:
|
||||
config["autoShutdownAt"] = 0
|
||||
has_new_def = True
|
||||
if has_new_def:
|
||||
self.write(config)
|
||||
|
||||
# Temporary disable OP lat control when on turning singal, default False
|
||||
if "tempDisableSteerOnSignal" not in config:
|
||||
config["tempDisableSteerOnSignal"] = False
|
||||
has_new_def = True
|
||||
if has_new_def:
|
||||
self.write(config)
|
||||
|
||||
# Allow Gas with OP, default False
|
||||
if "allowGasOnOP" not in config:
|
||||
config["allowGasOnOP"] = False
|
||||
has_new_def = True
|
||||
if has_new_def:
|
||||
self.write(config)
|
||||
|
||||
|
||||
return config
|
||||
|
||||
def write(self, config):
|
||||
with open(file, 'w') as f:
|
||||
json.dump(config, f, indent=2, sort_keys=True)
|
||||
os.chmod(file, 0644)
|
||||
|
||||
if __name__ == "__main__":
|
||||
dragonconf = dragonconf()
|
||||
@@ -2,12 +2,13 @@
|
||||
|
||||
import os
|
||||
import time
|
||||
from selfdrive.dragonpilot.dragonconf.dragonconf import dragonconf
|
||||
dragonconf = dragonconf()
|
||||
from common.params import Params
|
||||
params = Params()
|
||||
|
||||
def main(gctx=None):
|
||||
|
||||
shutdown_count = 0
|
||||
autoShutdownAt = get_shutdown_val()
|
||||
|
||||
while 1:
|
||||
with open("/sys/class/power_supply/usb/present") as f:
|
||||
@@ -18,10 +19,21 @@ def main(gctx=None):
|
||||
else:
|
||||
shutdown_count = 0
|
||||
|
||||
if shutdown_count >= dragonconf.conf["autoShutdownAt"] > 0:
|
||||
os.system('LD_LIBRARY_PATH="" svc power shutdown')
|
||||
if autoShutdownAt is None:
|
||||
autoShutdownAt = get_shutdown_val()
|
||||
else:
|
||||
if shutdown_count >= autoShutdownAt > 0:
|
||||
os.system('LD_LIBRARY_PATH="" svc power shutdown')
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
def get_shutdown_val():
|
||||
val = params.get("d_autoShutdownAt")
|
||||
if val is None:
|
||||
return None
|
||||
else:
|
||||
return int(val)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -10,6 +10,8 @@ from common.basedir import BASEDIR
|
||||
sys.path.append(os.path.join(BASEDIR, "pyextra"))
|
||||
os.environ['BASEDIR'] = BASEDIR
|
||||
|
||||
from selfdrive.dragonpilot.dragonconf import dragonpilot_set_params
|
||||
|
||||
def unblock_stdout():
|
||||
# get a non-blocking stdout
|
||||
child_pid, child_pty = os.forkpty()
|
||||
@@ -498,6 +500,8 @@ def main():
|
||||
if params.get("LimitSetSpeed") is None:
|
||||
params.put("LimitSetSpeed", "0")
|
||||
|
||||
dragonpilot_set_params(params)
|
||||
|
||||
# is this chffrplus?
|
||||
if os.getenv("PASSIVE") is not None:
|
||||
params.put("Passive", str(int(os.getenv("PASSIVE"))))
|
||||
|
||||
Reference in New Issue
Block a user