Skip to content

Commit

Permalink
Revert "card: move all car events (#32427)" (#32439)
Browse files Browse the repository at this point in the history
* Revert "card: move all car events (#32427)"

This reverts commit 8f46028.

* keep the event here

* oops

* Revert "oops"

This reverts commit ea99a27.

* Revert "keep the event here"

This reverts commit ec089b4.
  • Loading branch information
sshane authored May 15, 2024
1 parent 6605743 commit 4077911
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
10 changes: 1 addition & 9 deletions selfdrive/car/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
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.drive_helpers import VCruiseHelper
from openpilot.selfdrive.controls.lib.events import Events

REPLAY = "REPLAY" in os.environ

EventName = car.CarEvent.EventName
ButtonType = car.CarState.ButtonEvent.Type


class CarD:
Expand All @@ -35,7 +33,6 @@ def __init__(self, CI=None):
self.can_rcv_cum_timeout_counter = 0 # cumulative timeout count

self.CC_prev = car.CarControl.new_message()
self.CS_prev = car.CarState.new_message()

self.last_actuators = None

Expand Down Expand Up @@ -79,8 +76,8 @@ def __init__(self, CI=None):
self.params.put_nonblocking("CarParamsCache", cp_bytes)
self.params.put_nonblocking("CarParamsPersistent", cp_bytes)

self.CS_prev = car.CarState.new_message()
self.events = Events()
self.v_cruise_helper = VCruiseHelper(self.CP)

def initialize(self):
"""Initialize CarInterface, once controls are ready"""
Expand Down Expand Up @@ -121,11 +118,6 @@ def update_events(self, CS: car.CarState) -> car.CarState:

self.events.add_from_msg(CS.events)

# Block resume if cruise never previously enabled
resume_pressed = any(be.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for be in CS.buttonEvents)
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 \
Expand Down
22 changes: 14 additions & 8 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from openpilot.selfdrive.car.car_helpers import get_startup_event
from openpilot.selfdrive.car.card import CarD
from openpilot.selfdrive.controls.lib.alertmanager import AlertManager, set_offroad_alert
from openpilot.selfdrive.controls.lib.drive_helpers import clip_curvature
from openpilot.selfdrive.controls.lib.drive_helpers import VCruiseHelper, clip_curvature
from openpilot.selfdrive.controls.lib.events import Events, ET
from openpilot.selfdrive.controls.lib.latcontrol import LatControl, MIN_LATERAL_CONTROL_SPEED
from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID
Expand Down Expand Up @@ -143,6 +143,7 @@ def __init__(self, CI=None):
self.desired_curvature = 0.0
self.experimental_mode = False
self.personality = self.read_personality_param()
self.v_cruise_helper = VCruiseHelper(self.CP)
self.recalibrating_seen = False

self.can_log_mono_time = 0
Expand All @@ -168,7 +169,7 @@ def set_initial_state(self):
controls_state = self.params.get("ReplayControlsState")
if controls_state is not None:
with log.ControlsState.from_bytes(controls_state) as controls_state:
self.card.v_cruise_helper.v_cruise_kph = controls_state.vCruise
self.v_cruise_helper.v_cruise_kph = controls_state.vCruise

if any(ps.controlsAllowed for ps in self.sm['pandaStates']):
self.state = State.enabled
Expand Down Expand Up @@ -197,6 +198,11 @@ def update_events(self, CS):
if self.CP.passive:
return

# Block resume if cruise never previously enabled
resume_pressed = any(be.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for be in CS.buttonEvents)
if not self.CP.pcmCruise and not self.v_cruise_helper.v_cruise_initialized and resume_pressed:
self.events.add(EventName.resumeBlocked)

if not self.CP.notCar:
self.events.add_from_msg(self.sm['driverMonitoringState'].events)

Expand Down Expand Up @@ -425,7 +431,7 @@ def data_sample(self):
def state_transition(self, CS):
"""Compute conditional state transitions and execute actions on state transitions"""

self.card.v_cruise_helper.update_v_cruise(CS, self.enabled, self.is_metric)
self.v_cruise_helper.update_v_cruise(CS, self.enabled, self.is_metric)

# decrement the soft disable timer at every step, as it's reset on
# entrance in SOFT_DISABLING state
Expand Down Expand Up @@ -500,7 +506,7 @@ def state_transition(self, CS):
else:
self.state = State.enabled
self.current_alert_types.append(ET.ENABLE)
self.card.v_cruise_helper.initialize_v_cruise(CS, self.experimental_mode)
self.v_cruise_helper.initialize_v_cruise(CS, self.experimental_mode)

# Check if openpilot is engaged and actuators are enabled
self.enabled = self.state in ENABLED_STATES
Expand Down Expand Up @@ -556,7 +562,7 @@ def state_control(self, CS):

if not self.joystick_mode:
# accel PID loop
pid_accel_limits = self.CI.get_pid_accel_limits(self.CP, CS.vEgo, self.card.v_cruise_helper.v_cruise_kph * CV.KPH_TO_MS)
pid_accel_limits = self.CI.get_pid_accel_limits(self.CP, CS.vEgo, self.v_cruise_helper.v_cruise_kph * CV.KPH_TO_MS)
t_since_plan = (self.sm.frame - self.sm.recv_frame['longitudinalPlan']) * DT_CTRL
actuators.accel = self.LoC.update(CC.longActive, CS, long_plan, pid_accel_limits, t_since_plan)

Expand Down Expand Up @@ -659,7 +665,7 @@ def publish_logs(self, CS, start_time, CC, lac_log):
CC.cruiseControl.resume = self.enabled and CS.cruiseState.standstill and speeds[-1] > 0.1

hudControl = CC.hudControl
hudControl.setSpeed = float(self.card.v_cruise_helper.v_cruise_cluster_kph * CV.KPH_TO_MS)
hudControl.setSpeed = float(self.v_cruise_helper.v_cruise_cluster_kph * CV.KPH_TO_MS)
hudControl.speedVisible = self.enabled
hudControl.lanesVisible = self.enabled
hudControl.leadVisible = self.sm['longitudinalPlan'].hasLead
Expand Down Expand Up @@ -743,8 +749,8 @@ def publish_logs(self, CS, start_time, CC, lac_log):
controlsState.engageable = not self.events.contains(ET.NO_ENTRY)
controlsState.longControlState = self.LoC.long_control_state
controlsState.vPid = float(self.LoC.v_pid)
controlsState.vCruise = float(self.card.v_cruise_helper.v_cruise_kph)
controlsState.vCruiseCluster = float(self.card.v_cruise_helper.v_cruise_cluster_kph)
controlsState.vCruise = float(self.v_cruise_helper.v_cruise_kph)
controlsState.vCruiseCluster = float(self.v_cruise_helper.v_cruise_cluster_kph)
controlsState.upAccelCmd = float(self.LoC.pid.p)
controlsState.uiAccelCmd = float(self.LoC.pid.i)
controlsState.ufAccelCmd = float(self.LoC.pid.f)
Expand Down

0 comments on commit 4077911

Please sign in to comment.