sync with custom enable button branch

mqb-long
Jason Young 3 years ago
parent c50c7c292d
commit f43a3736e2
  1. 17
      selfdrive/car/__init__.py
  2. 10
      selfdrive/car/interfaces.py

@ -3,7 +3,7 @@ import capnp
from cereal import car
from common.numpy_fast import clip
from typing import Dict, List, Tuple
from typing import Dict
# kg of standard extra cargo to count for drive, gas, etc...
STD_CARGO_KG = 136.
@ -32,21 +32,6 @@ def create_button_event(cur_but: int, prev_but: int, buttons_dict: Dict[int, cap
return be
def create_button_enable_events(buttonEvents: capnp.lib.capnp._DynamicListBuilder,
enable_buttons: Tuple[capnp.lib.capnp._EnumModule, ...],
pcm_cruise: bool = False) -> List[int]:
events = []
for b in buttonEvents:
# do enable on both accel and decel buttons
if not pcm_cruise:
if b.type in enable_buttons and not b.pressed:
events.append(EventName.buttonEnable)
# do disable on button down
if b.type == ButtonType.cancel and b.pressed:
events.append(EventName.buttonCancel)
return events
def gen_empty_fingerprint():
return {i: {} for i in range(0, 8)}

@ -10,7 +10,7 @@ from common.conversions import Conversions as CV
from common.kalman.simple_kalman import KF1D
from common.numpy_fast import interp
from common.realtime import DT_CTRL
from selfdrive.car import apply_hysteresis, create_button_enable_events, gen_empty_fingerprint
from selfdrive.car import apply_hysteresis, gen_empty_fingerprint
from selfdrive.controls.lib.drive_helpers import V_CRUISE_MAX, apply_deadzone
from selfdrive.controls.lib.events import Events
from selfdrive.controls.lib.vehicle_model import VehicleModel
@ -246,7 +246,13 @@ class CarInterfaceBase(ABC):
events.add(EventName.steerOverride)
# Handle button presses
events.events.extend(create_button_enable_events(cs_out.buttonEvents, enable_buttons, pcm_cruise=self.CP.pcmCruise))
for b in cs_out.buttonEvents:
# Enable OP long on falling edge of enable buttons (defaults to accelCruise and decelCruise, overridable per-port)
if not self.CP.pcm_cruise and (b.type in enable_buttons and not b.pressed):
events.add(EventName.buttonEnable)
# Disable on rising edge of cancel for both stock and OP long
if b.type == ButtonType.cancel and b.pressed:
events.add(EventName.buttonCancel)
# Handle permanent and temporary steering faults
self.steering_unpressed = 0 if cs_out.steeringPressed else self.steering_unpressed + 1

Loading…
Cancel
Save