card: create pedal pressed event (#32393)

* move pedalPressed to card

* rm

* needs to be a builder

* move these

* clean up

* reader later

* Update ref_commit
pull/32414/head
Shane Smiskol 1 year ago committed by GitHub
parent 79c8fb0236
commit d18da895d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 26
      selfdrive/car/card.py
  2. 5
      selfdrive/car/interfaces.py
  3. 10
      selfdrive/controls/controlsd.py
  4. 2
      selfdrive/test/process_replay/ref_commit

@ -14,9 +14,12 @@ from openpilot.common.realtime import DT_CTRL
from openpilot.selfdrive.boardd.boardd import can_list_to_can_capnp
from openpilot.selfdrive.car.car_helpers import get_car, get_one_can
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
from openpilot.selfdrive.controls.lib.events import Events
REPLAY = "REPLAY" in os.environ
EventName = car.CarEvent.EventName
class CarD:
CI: CarInterfaceBase
@ -47,9 +50,9 @@ class CarD:
self.CI, self.CP = CI, CI.CP
# set alternative experiences from parameters
disengage_on_accelerator = self.params.get_bool("DisengageOnAccelerator")
self.disengage_on_accelerator = self.params.get_bool("DisengageOnAccelerator")
self.CP.alternativeExperience = 0
if not disengage_on_accelerator:
if not self.disengage_on_accelerator:
self.CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS
openpilot_enabled_toggle = self.params.get_bool("OpenpilotEnabledToggle")
@ -73,6 +76,9 @@ class CarD:
self.params.put_nonblocking("CarParamsCache", cp_bytes)
self.params.put_nonblocking("CarParamsPersistent", cp_bytes)
self.CS_prev = car.CarState.new_message()
self.events = Events()
def initialize(self):
"""Initialize CarInterface, once controls are ready"""
self.CI.init(self.CP, self.can_sock, self.pm.sock['sendcan'])
@ -100,10 +106,26 @@ class CarD:
if can_rcv_valid and REPLAY:
self.can_log_mono_time = messaging.log_from_bytes(can_strs[0]).logMonoTime
self.update_events(CS)
self.state_publish(CS)
CS = CS.as_reader()
self.CS_prev = CS
return CS
def update_events(self, CS: car.CarState) -> car.CarState:
self.events.clear()
self.events.add_from_msg(CS.events)
# Disable on rising edge of accelerator or brake. Also disable on brake when speed > 0
if (CS.gasPressed and not self.CS_prev.gasPressed and self.disengage_on_accelerator) or \
(CS.brakePressed and (not self.CS_prev.brakePressed or not CS.standstill)) or \
(CS.regenBraking and (not self.CS_prev.regenBraking or not CS.standstill)):
self.events.add(EventName.pedalPressed)
CS.events = self.events.to_msg()
def state_publish(self, CS: car.CarState):
"""carState and carParams publish loop"""

@ -242,11 +242,10 @@ class CarInterfaceBase(ABC):
ret.cruiseState.speedCluster = ret.cruiseState.speed
# copy back for next iteration
reader = ret.as_reader()
if self.CS is not None:
self.CS.out = reader
self.CS.out = ret.as_reader()
return reader
return ret
def create_common_events(self, cs_out, extra_gears=None, pcm_enable=True, allow_enable=True,

@ -96,7 +96,6 @@ class Controls:
self.joystick_mode = self.params.get_bool("JoystickDebugMode")
# read params
self.disengage_on_accelerator = self.params.get_bool("DisengageOnAccelerator")
self.is_metric = self.params.get_bool("IsMetric")
self.is_ldw_enabled = self.params.get_bool("IsLdwEnabled")
@ -111,7 +110,6 @@ class Controls:
if not self.CP.openpilotLongitudinalControl:
self.params.remove("ExperimentalMode")
self.CS_prev = car.CarState.new_message()
self.AM = AlertManager()
self.events = Events()
@ -205,12 +203,6 @@ class Controls:
if not self.CP.pcmCruise and not self.v_cruise_helper.v_cruise_initialized and resume_pressed:
self.events.add(EventName.resumeBlocked)
# Disable on rising edge of accelerator or brake. Also disable on brake when speed > 0
if (CS.gasPressed and not self.CS_prev.gasPressed and self.disengage_on_accelerator) or \
(CS.brakePressed and (not self.CS_prev.brakePressed or not CS.standstill)) or \
(CS.regenBraking and (not self.CS_prev.regenBraking or not CS.standstill)):
self.events.add(EventName.pedalPressed)
if not self.CP.notCar:
self.events.add_from_msg(self.sm['driverMonitoringState'].events)
@ -815,8 +807,6 @@ class Controls:
# Publish data
self.publish_logs(CS, start_time, CC, lac_log)
self.CS_prev = CS
def read_personality_param(self):
try:
return int(self.params.get('LongitudinalPersonality'))

@ -1 +1 @@
ef0c8cb36b9cda6381412493555c21a87360e539
e5a385503e4307ae77c73736a602380b08e61334

Loading…
Cancel
Save