From 09533fee0cf0cfae44d90a0c617186aaa17be0af Mon Sep 17 00:00:00 2001 From: Dragonpilot Date: Tue, 23 Jul 2019 15:40:30 +1000 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=20DragonAllowGas=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/params.py | 1 + selfdrive/car/honda/carcontroller.py | 10 ++++++++++ selfdrive/car/honda/interface.py | 17 +++++++++++------ selfdrive/car/toyota/carcontroller.py | 13 +++++++++++++ selfdrive/car/toyota/interface.py | 17 +++++++++++------ selfdrive/dragonpilot/dragonconf/__init__.py | 1 + 6 files changed, 47 insertions(+), 12 deletions(-) diff --git a/common/params.py b/common/params.py index 4a2bf44a3..1ba9a0aeb 100755 --- a/common/params.py +++ b/common/params.py @@ -92,6 +92,7 @@ keys = { "DragonCachedModel": [TxType.PERSISTENT], "DragonCachedFP": [TxType.PERSISTENT], "DragonCachedVIN": [TxType.PERSISTENT], + "DragonAllowGas": [TxType.PERSISTENT], } diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index c90c1e4e4..91b944e21 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -182,6 +182,16 @@ class CarController(object): idx = frame // 2 ts = frame * DT_CTRL pump_on, self.last_pump_ts = brake_pump_hysteresis(apply_brake, self.apply_brake_last, self.last_pump_ts, ts) + # DragonAllowGas + # if we detect gas pedal pressed, we do not want OP to apply gas or brake + # gasPressed code from interface.py + if not CS.CP.enableGasInterceptor: + gasPressed = CS.pedal_gas > 0 + else: + gasPressed = CS.user_gas_pressed + if params.get("DragonAllowGas") == "1" and gasPressed: + apply_brake = 0 + apply_gas = 0 can_sends.append(hondacan.create_brake_command(self.packer, apply_brake, pump_on, pcm_override, pcm_cancel_cmd, hud.chime, hud.fcw, idx)) self.apply_brake_last = apply_brake diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 0d0bbd669..28f5443d2 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -504,13 +504,18 @@ class CarInterface(object): if self.CP.enableCruise and ret.vEgo < self.CP.minEnableSpeed: 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) or \ - (ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001)): - events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) + # DragonAllowGas + if params.get("DragonAllowGas") == "0": + # disable on pedals rising edge or when brake is pressed and speed isn't zero + if (ret.gasPressed and not self.gas_pressed_prev) or \ + (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: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) + if ret.gasPressed: + events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) + else: + 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])) # it can happen that car cruise disables while comma system is enabled: need to # keep braking if needed or if the speed is very low diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index 242d9cd85..be3bd5ecf 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -229,6 +229,19 @@ class CarController(object): elif ECU.APGS in self.fake_ecus: can_sends.append(create_ipas_steer_command(self.packer, 0, 0, True)) + # DragonAllowGas + # if we detect gas pedal pressed, we do not want OP to apply gas or brake + # gasPressed code from interface.py + if CS.CP.enableGasInterceptor: + # use interceptor values to disengage on pedal press + gasPressed = CS.pedal_gas > 15 + else: + gasPressed = CS.pedal_gas > 0 + + if params.get("DragonAllowGas") == "1" and gasPressed: + 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 if (frame % 3 == 0 and ECU.DSU in self.fake_ecus) or (pcm_cancel_cmd and ECU.CAM in self.fake_ecus): lead = lead or CS.v_ego < 12. # at low speed we always assume the lead is present do ACC can be engaged diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 1b2220cea..7f3f7bb78 100755 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -370,13 +370,18 @@ class CarInterface(object): elif not ret.cruiseState.enabled: events.append(create_event('pcmDisable', [ET.USER_DISABLE])) - # disable on pedals rising edge or when brake is pressed and speed isn't zero - if (ret.gasPressed and not self.gas_pressed_prev) or \ - (ret.brakePressed and (not self.brake_pressed_prev or ret.vEgo > 0.001)): - events.append(create_event('pedalPressed', [ET.NO_ENTRY, ET.USER_DISABLE])) + # DragonAllowGas + if params.get("DragonAllowGas") == "0": + # disable on pedals rising edge or when brake is pressed and speed isn't zero + if (ret.gasPressed and not self.gas_pressed_prev) or \ + (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: - events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) + if ret.gasPressed: + events.append(create_event('pedalPressed', [ET.PRE_ENABLE])) + else: + 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])) ret.events = events diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index 3c5ac474e..c41bed987 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -17,6 +17,7 @@ default_conf = { 'DragonCachedModel': '', # for cache car 'DragonCachedFP': '', # for cache car 'DragonCachedVIN': '', # for cache car + 'DragonAllowGas': '0', } def dragonpilot_set_params(params):