Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions selfdrive/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ def update(self, CC, CS, now_nanos):
can_sends += gmcan.create_adas_keepalive(CanBus.POWERTRAIN)

# TODO: integrate this with the code block below?
if (
(self.CP.flags & GMFlags.PEDAL_LONG.value) # Always cancel stock CC when using pedal interceptor
or (self.CP.flags & GMFlags.CC_LONG.value and not CC.enabled) # Cancel stock CC if OP is not active
if ((self.CP.flags & GMFlags.PEDAL_LONG.value) # Always cancel stock CC when using pedal interceptor
) and CS.out.cruiseState.enabled:
if (self.frame - self.last_button_frame) * DT_CTRL > 0.04:
self.last_button_frame = self.frame
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/car/gm/carstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def update(self, pt_cp, cam_cp, loopback_cp):
else:
ret.stockAeb = False
# openpilot controls nonAdaptive when not pcmCruise
if self.CP.pcmCruise:
if self.CP.pcmCruise and self.CP.carFingerprint not in CC_ONLY_CAR:
Comment thread
nworb-cire marked this conversation as resolved.
ret.cruiseState.nonAdaptive = cam_cp.vl["ASCMActiveCruiseControlStatus"]["ACCCruiseState"] not in (2, 3)
if self.CP.carFingerprint in CC_ONLY_CAR:
ret.accFaulted = False
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/gm/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ def _get_params(ret, candidate, fingerprint, car_fw, experimental_long, docs):

elif candidate in CC_ONLY_CAR:
ret.experimentalLongitudinalAvailable = True
ret.flags |= GMFlags.CC_LONG.value
ret.safetyConfigs[0].safetyParam |= Panda.FLAG_GM_CC_LONG
if experimental_long:
ret.openpilotLongitudinalControl = True
ret.flags |= GMFlags.CC_LONG.value
ret.radarUnavailable = True
ret.minEnableSpeed = 24 * CV.MPH_TO_MS
ret.pcmCruise = False
ret.pcmCruise = True

ret.stoppingDecelRate = 11.18 # == 25 mph/s (.04 rate)

Expand Down
8 changes: 7 additions & 1 deletion selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def __init__(self, CI=None):
self.personality = self.read_personality_param()
self.v_cruise_helper = VCruiseHelper(self.CP)
self.recalibrating_seen = False
self.resume_prev_button = False

self.can_log_mono_time = 0

Expand Down Expand Up @@ -510,7 +511,7 @@ def state_transition(self, CS):
else:
self.state = State.enabled
self.current_alert_types.append(ET.ENABLE)
self.v_cruise_helper.initialize_v_cruise(CS, self.experimental_mode)
self.v_cruise_helper.initialize_v_cruise(CS, self.experimental_mode, self.resume_prev_button)

# Check if openpilot is engaged and actuators are enabled
self.enabled = self.state in ENABLED_STATES
Expand All @@ -521,6 +522,11 @@ def state_transition(self, CS):
def state_control(self, CS):
"""Given the state, this function returns a CarControl packet"""

if any(be.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for be in CS.buttonEvents):
self.resume_prev_button = True
elif any(be.type in (ButtonType.decelCruise, ButtonType.setCruise) for be in CS.buttonEvents):
self.resume_prev_button = False

# Update VehicleModel
lp = self.sm['liveParameters']
x = max(lp.stiffnessFactor, 0.1)
Expand Down
10 changes: 6 additions & 4 deletions selfdrive/controls/lib/drive_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openpilot.common.numpy_fast import clip
from openpilot.common.realtime import DT_CTRL
from openpilot.system.version import get_build_metadata
from openpilot.selfdrive.car.gm.values import GMFlags, CC_ONLY_CAR

EventName = car.CarEvent.EventName

Expand Down Expand Up @@ -42,6 +43,7 @@
class VCruiseHelper:
def __init__(self, CP):
self.CP = CP
self.gm_cc_only = self.CP.carFingerprint in CC_ONLY_CAR and self.CP.flags & GMFlags.CC_LONG.value
self.v_cruise_kph = V_CRUISE_UNSET
self.v_cruise_cluster_kph = V_CRUISE_UNSET
self.v_cruise_kph_last = 0
Expand All @@ -56,7 +58,7 @@ def update_v_cruise(self, CS, enabled, is_metric):
self.v_cruise_kph_last = self.v_cruise_kph

if CS.cruiseState.available:
if not self.CP.pcmCruise:
if not self.CP.pcmCruise or self.gm_cc_only:
# if stock cruise is completely disabled, then we can use our own set speed logic
self._update_v_cruise_non_pcm(CS, enabled, is_metric)
self.v_cruise_cluster_kph = self.v_cruise_kph
Expand Down Expand Up @@ -128,15 +130,15 @@ def update_button_timers(self, CS, enabled):
self.button_timers[b.type.raw] = 1 if b.pressed else 0
self.button_change_states[b.type.raw] = {"standstill": CS.cruiseState.standstill, "enabled": enabled}

def initialize_v_cruise(self, CS, experimental_mode: bool) -> None:
def initialize_v_cruise(self, CS, experimental_mode: bool, resume_prev_button) -> None:
# initializing is handled by the PCM
if self.CP.pcmCruise:
if self.CP.pcmCruise and not self.gm_cc_only:
return

initial = V_CRUISE_INITIAL_EXPERIMENTAL_MODE if experimental_mode else V_CRUISE_INITIAL

# 250kph or above probably means we never had a set speed
if any(b.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for b in CS.buttonEvents) and self.v_cruise_kph_last < 250:
if (any(b.type in (ButtonType.accelCruise, ButtonType.resumeCruise) for b in CS.buttonEvents) or (self.gm_cc_only and resume_prev_button)) and self.v_cruise_kph_last < 250:
self.v_cruise_kph = self.v_cruise_kph_last
else:
self.v_cruise_kph = int(round(clip(CS.vEgo * CV.MS_TO_KPH, initial, V_CRUISE_MAX)))
Expand Down