mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-06-27 18:12:04 +08:00
Subaru: show LDW on dash for correct lane (#20934)
* Emit correct alerts for LDW Left & Right on Subarus
This change switches the ldw event to use VisualAlert.ldw and
alters all cars to use the prior behaviour for that alert, except
global subarus - they emit the correct warning to the dash
* Remove whitespace, and add comment about not overwriting stock alerts
Co-authored-by: Crispin Flowerday <crispin@theflowerdays.com>
old-commit-hash: 7458e143e3
This commit is contained in:
@@ -8,7 +8,7 @@ VisualAlert = car.CarControl.HUDControl.VisualAlert
|
||||
def create_lkas_hud(packer, gear, lkas_active, hud_alert, hud_count, lkas_car_model):
|
||||
# LKAS_HUD 0x2a6 (678) Controls what lane-keeping icon is displayed.
|
||||
|
||||
if hud_alert == VisualAlert.steerRequired:
|
||||
if hud_alert in [VisualAlert.steerRequired, VisualAlert.ldw]:
|
||||
msg = b'\x00\x00\x00\x03\x00\x00\x00\x00'
|
||||
return make_can_msg(0x2a6, msg, 0)
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ from selfdrive.car import make_can_msg
|
||||
from selfdrive.car.ford.fordcan import create_steer_command, create_lkas_ui, spam_cancel_button
|
||||
from opendbc.can.packer import CANPacker
|
||||
|
||||
VisualAlert = car.CarControl.HUDControl.VisualAlert
|
||||
|
||||
MAX_STEER_DELTA = 1
|
||||
TOGGLE_DEBUG = False
|
||||
@@ -22,7 +23,7 @@ class CarController():
|
||||
def update(self, enabled, CS, frame, actuators, visual_alert, pcm_cancel):
|
||||
|
||||
can_sends = []
|
||||
steer_alert = visual_alert == car.CarControl.HUDControl.VisualAlert.steerRequired
|
||||
steer_alert = visual_alert in [VisualAlert.steerRequired, VisualAlert.ldw]
|
||||
|
||||
apply_steer = actuators.steer
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ class CarController():
|
||||
lka_critical = lka_active and abs(actuators.steer) > 0.9
|
||||
lka_icon_status = (lka_active, lka_critical)
|
||||
if frame % P.CAMERA_KEEPALIVE_STEP == 0 or lka_icon_status != self.lka_icon_status_last:
|
||||
steer_alert = hud_alert == VisualAlert.steerRequired
|
||||
steer_alert = hud_alert in [VisualAlert.steerRequired, VisualAlert.ldw]
|
||||
can_sends.append(gmcan.create_lka_icon_command(CanBus.SW_GMLAN, lka_active, lka_critical, steer_alert))
|
||||
self.lka_icon_status_last = lka_icon_status
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ def process_hud_alert(hud_alert):
|
||||
# priority is: FCW, steer required, all others
|
||||
if hud_alert == VisualAlert.fcw:
|
||||
fcw_display = VISUAL_HUD[hud_alert.raw]
|
||||
elif hud_alert == VisualAlert.steerRequired:
|
||||
elif hud_alert in [VisualAlert.steerRequired, VisualAlert.ldw]:
|
||||
steer_required = VISUAL_HUD[hud_alert.raw]
|
||||
else:
|
||||
acc_alert = VISUAL_HUD[hud_alert.raw]
|
||||
|
||||
@@ -28,6 +28,7 @@ VISUAL_HUD = {
|
||||
VisualAlert.none: 0,
|
||||
VisualAlert.fcw: 1,
|
||||
VisualAlert.steerRequired: 1,
|
||||
VisualAlert.ldw: 1,
|
||||
VisualAlert.brakePressed: 10,
|
||||
VisualAlert.wrongGear: 6,
|
||||
VisualAlert.seatbeltUnbuckled: 5,
|
||||
|
||||
@@ -10,7 +10,7 @@ VisualAlert = car.CarControl.HUDControl.VisualAlert
|
||||
|
||||
def process_hud_alert(enabled, fingerprint, visual_alert, left_lane,
|
||||
right_lane, left_lane_depart, right_lane_depart):
|
||||
sys_warning = (visual_alert == VisualAlert.steerRequired)
|
||||
sys_warning = (visual_alert in [VisualAlert.steerRequired, VisualAlert.ldw])
|
||||
|
||||
# initialize to no line visible
|
||||
sys_state = 1
|
||||
|
||||
@@ -31,7 +31,7 @@ class CarController():
|
||||
lkas_hud_info_msg = CS.lkas_hud_info_msg
|
||||
apply_angle = actuators.steeringAngleDeg
|
||||
|
||||
steer_hud_alert = 1 if hud_alert == VisualAlert.steerRequired else 0
|
||||
steer_hud_alert = 1 if hud_alert in [VisualAlert.steerRequired, VisualAlert.ldw] else 0
|
||||
|
||||
if enabled:
|
||||
# # windup slower
|
||||
|
||||
@@ -15,7 +15,7 @@ class CarController():
|
||||
|
||||
self.packer = CANPacker(DBC[CP.carFingerprint]['pt'])
|
||||
|
||||
def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, left_line, right_line):
|
||||
def update(self, enabled, CS, frame, actuators, pcm_cancel_cmd, visual_alert, left_line, right_line, left_lane_depart, right_lane_depart):
|
||||
|
||||
can_sends = []
|
||||
|
||||
@@ -69,7 +69,7 @@ class CarController():
|
||||
self.es_distance_cnt = CS.es_distance_msg["Counter"]
|
||||
|
||||
if self.es_lkas_cnt != CS.es_lkas_msg["Counter"]:
|
||||
can_sends.append(subarucan.create_es_lkas(self.packer, CS.es_lkas_msg, visual_alert, left_line, right_line))
|
||||
can_sends.append(subarucan.create_es_lkas(self.packer, CS.es_lkas_msg, visual_alert, left_line, right_line, left_lane_depart, right_lane_depart))
|
||||
self.es_lkas_cnt = CS.es_lkas_msg["Counter"]
|
||||
|
||||
return can_sends
|
||||
|
||||
@@ -122,6 +122,6 @@ class CarInterface(CarInterfaceBase):
|
||||
def apply(self, c):
|
||||
can_sends = self.CC.update(c.enabled, self.CS, self.frame, c.actuators,
|
||||
c.cruiseControl.cancel, c.hudControl.visualAlert,
|
||||
c.hudControl.leftLaneVisible, c.hudControl.rightLaneVisible)
|
||||
c.hudControl.leftLaneVisible, c.hudControl.rightLaneVisible, c.hudControl.leftLaneDepart, c.hudControl.rightLaneDepart)
|
||||
self.frame += 1
|
||||
return can_sends
|
||||
|
||||
@@ -27,12 +27,20 @@ def create_es_distance(packer, es_distance_msg, pcm_cancel_cmd):
|
||||
|
||||
return packer.make_can_msg("ES_Distance", 0, values)
|
||||
|
||||
def create_es_lkas(packer, es_lkas_msg, visual_alert, left_line, right_line):
|
||||
def create_es_lkas(packer, es_lkas_msg, visual_alert, left_line, right_line, left_lane_depart, right_lane_depart):
|
||||
|
||||
values = copy.copy(es_lkas_msg)
|
||||
if visual_alert == VisualAlert.steerRequired:
|
||||
values["Keep_Hands_On_Wheel"] = 1
|
||||
|
||||
# Ensure we don't overwrite potentially more important alerts from stock (e.g. FCW)
|
||||
if visual_alert == VisualAlert.ldw and values["LKAS_Alert"] == 0:
|
||||
if left_lane_depart:
|
||||
values["LKAS_Alert"] = 12 # Left lane departure dash alert
|
||||
|
||||
elif right_lane_depart:
|
||||
values["LKAS_Alert"] = 11 # Right lane departure dash alert
|
||||
|
||||
values["LKAS_Left_Line_Visible"] = int(left_line)
|
||||
values["LKAS_Right_Line_Visible"] = int(right_line)
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ class CarController():
|
||||
# - there is something to display
|
||||
# - there is something to stop displaying
|
||||
fcw_alert = hud_alert == VisualAlert.fcw
|
||||
steer_alert = hud_alert == VisualAlert.steerRequired
|
||||
steer_alert = hud_alert in [VisualAlert.steerRequired, VisualAlert.ldw]
|
||||
|
||||
send_ui = False
|
||||
if ((fcw_alert or steer_alert) and not self.alert_active) or \
|
||||
|
||||
@@ -4,6 +4,7 @@ from selfdrive.car.volkswagen import volkswagencan
|
||||
from selfdrive.car.volkswagen.values import DBC, CANBUS, MQB_LDW_MESSAGES, BUTTON_STATES, CarControllerParams
|
||||
from opendbc.can.packer import CANPacker
|
||||
|
||||
VisualAlert = car.CarControl.HUDControl.VisualAlert
|
||||
|
||||
class CarController():
|
||||
def __init__(self, dbc_name, CP, VM):
|
||||
@@ -110,7 +111,7 @@ class CarController():
|
||||
# filters LDW_02 from the factory camera and OP emits LDW_02 at 10Hz.
|
||||
|
||||
if frame % P.LDW_STEP == 0:
|
||||
if visual_alert == car.CarControl.HUDControl.VisualAlert.steerRequired:
|
||||
if visual_alert in [VisualAlert.steerRequired, VisualAlert.ldw]:
|
||||
hud_alert = MQB_LDW_MESSAGES["laneAssistTakeOverSilent"]
|
||||
else:
|
||||
hud_alert = MQB_LDW_MESSAGES["none"]
|
||||
|
||||
@@ -340,7 +340,7 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo
|
||||
"TAKE CONTROL",
|
||||
"Lane Departure Detected",
|
||||
AlertStatus.userPrompt, AlertSize.mid,
|
||||
Priority.LOW, VisualAlert.steerRequired, AudibleAlert.chimePrompt, 1., 2., 3.),
|
||||
Priority.LOW, VisualAlert.ldw, AudibleAlert.chimePrompt, 1., 2., 3.),
|
||||
},
|
||||
|
||||
# ********** events only containing alerts that display while engaged **********
|
||||
|
||||
Reference in New Issue
Block a user