Switch personalities via steering wheel / onroad UI

Added toggle to switch between the personalities via the steering wheel or an onroad UI button.

Co-Authored-By: henryccy <104284652+henryccy@users.noreply.github.com>
Co-Authored-By: Jason Jackrel <23621790+thinkpad4by3@users.noreply.github.com>
Co-Authored-By: Eric Brown <13560103+nworb-cire@users.noreply.github.com>
Co-Authored-By: Kevin Robert Keegan <3046315+krkeegan@users.noreply.github.com>
Co-Authored-By: Jacob Pfeifer <jacob@pfeifer.dev>
Co-Authored-By: mike8643 <98910897+mike8643@users.noreply.github.com>
This commit is contained in:
FrogAi
2024-02-27 16:34:47 -07:00
parent 71eecd224c
commit 437ecc73ca
38 changed files with 406 additions and 36 deletions

View File

@@ -131,7 +131,7 @@ class CarController:
can_sends.extend(hyundaicanfd.create_adrv_messages(self.packer, self.CAN, self.frame))
if self.frame % 2 == 0:
can_sends.append(hyundaicanfd.create_acc_control(self.packer, self.CAN, CC.enabled, self.accel_last, accel, stopping, CC.cruiseControl.override,
set_speed_in_units))
set_speed_in_units, CS.personality_profile))
self.accel_last = accel
else:
# button presses
@@ -151,7 +151,7 @@ class CarController:
use_fca = self.CP.flags & HyundaiFlags.USE_FCA.value
can_sends.extend(hyundaican.create_acc_commands(self.packer, CC.enabled, accel, jerk, int(self.frame / 2),
hud_control.leadVisible, set_speed_in_units, stopping,
CC.cruiseControl.override, use_fca, CS.out.cruiseState.available))
CC.cruiseControl.override, use_fca, CS.out.cruiseState.available, CS.personality_profile))
# 20 Hz LFA MFA message
if self.frame % 5 == 0 and self.CP.flags & HyundaiFlags.SEND_LFA.value:

View File

@@ -10,6 +10,7 @@ from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus
from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, CAR, DBC, CAN_GEARS, CAMERA_SCC_CAR, \
CANFD_CAR, Buttons, CarControllerParams
from openpilot.selfdrive.car.interfaces import CarStateBase
from openpilot.selfdrive.controls.lib.drive_helpers import CRUISE_LONG_PRESS
from openpilot.selfdrive.frogpilot.functions.speed_limit_controller import SpeedLimitController
@@ -182,9 +183,52 @@ class CarState(CarStateBase):
if self.prev_main_buttons == 0 and self.main_buttons[-1] != 0:
self.main_enabled = not self.main_enabled
# FrogPilot functions
distance_pressed = self.cruise_buttons[-1] == Buttons.GAP_DIST
# Driving personalities function
if ret.cruiseState.available:
# Sync with the onroad UI button
if self.fpf.personality_changed_via_ui:
self.personality_profile = self.fpf.current_personality
self.fpf.reset_personality_changed_param()
if distance_pressed:
self.distance_pressed_counter += 1
elif self.distance_previously_pressed:
# Set the distance lines on the dash to match the new personality if the button was held down for less than 0.5 seconds
if self.distance_pressed_counter < CRUISE_LONG_PRESS and frogpilot_variables.personalities_via_wheel:
self.personality_profile = (self.personality_profile + 2) % 3
self.fpf.distance_button_function(self.personality_profile)
self.distance_pressed_counter = 0
# Switch the current state of Experimental Mode if the button is held down for 0.5 seconds
if self.distance_pressed_counter == CRUISE_LONG_PRESS and frogpilot_variables.experimental_mode_via_distance:
if frogpilot_variables.conditional_experimental_mode:
self.fpf.update_cestatus_distance()
else:
self.fpf.update_experimental_mode()
# Switch the current state of Traffic Mode if the button is held down for 2.5 seconds
if self.distance_pressed_counter == CRUISE_LONG_PRESS * 5 and frogpilot_variables.traffic_mode:
self.fpf.update_traffic_mode()
# Revert the previous changes to Experimental Mode
if frogpilot_variables.experimental_mode_via_distance:
if frogpilot_variables.conditional_experimental_mode:
self.fpf.update_cestatus_distance()
else:
self.fpf.update_experimental_mode()
self.distance_previously_pressed = distance_pressed
# Toggle Experimental Mode from steering wheel function
if frogpilot_variables.experimental_mode_via_lkas and ret.cruiseState.available and self.CP.flags & HyundaiFlags.CAN_LFA_BTN:
lkas_pressed = cp.vl["BCM_PO_11"]["LFA_Pressed"]
if lkas_pressed and not self.lkas_previously_pressed:
if frogpilot_variables.conditional_experimental_mode:
self.fpf.update_cestatus_lkas()
@@ -280,11 +324,57 @@ class CarState(CarStateBase):
self.hda2_lfa_block_msg = copy.copy(cp_cam.vl["CAM_0x362"] if self.CP.flags & HyundaiFlags.CANFD_HDA2_ALT_STEERING
else cp_cam.vl["CAM_0x2a4"])
# FrogPilot functions
distance_pressed = self.cruise_buttons[-1] == Buttons.GAP_DIST and self.prev_cruise_buttons == 0
# Driving personalities function
if ret.cruiseState.available:
# Sync with the onroad UI button
if self.fpf.personality_changed_via_ui:
self.personality_profile = self.fpf.current_personality
self.fpf.reset_personality_changed_param()
if distance_pressed:
self.distance_pressed_counter += 1
elif self.distance_previously_pressed:
# Set the distance lines on the dash to match the new personality if the button was held down for less than 0.5 seconds
if self.distance_pressed_counter < CRUISE_LONG_PRESS and frogpilot_variables.personalities_via_wheel:
self.personality_profile = (self.personality_profile + 2) % 3
self.fpf.distance_button_function(self.personality_profile)
self.distance_pressed_counter = 0
# Switch the current state of Experimental Mode if the button is held down for 0.5 seconds
if self.distance_pressed_counter == CRUISE_LONG_PRESS and frogpilot_variables.experimental_mode_via_distance:
if frogpilot_variables.conditional_experimental_mode:
self.fpf.update_cestatus_distance()
else:
self.fpf.update_experimental_mode()
# Switch the current state of Traffic Mode if the button is held down for 2.5 seconds
if self.distance_pressed_counter == CRUISE_LONG_PRESS * 5 and frogpilot_variables.traffic_mode:
self.fpf.update_traffic_mode()
# Revert the previous changes to Experimental Mode
if frogpilot_variables.experimental_mode_via_distance:
if frogpilot_variables.conditional_experimental_mode:
self.fpf.update_cestatus_distance()
else:
self.fpf.update_experimental_mode()
self.distance_previously_pressed = distance_pressed
# Toggle Experimental Mode from steering wheel function
if frogpilot_variables.experimental_mode_via_lkas and ret.cruiseState.available:
lkas_pressed = cp.vl[self.cruise_btns_msg_canfd]["LKAS_BTN"]
if lkas_pressed and not self.lkas_previously_pressed:
self.fpf.lkas_button_function(frogpilot_variables.conditional_experimental_mode)
if frogpilot_variables.conditional_experimental_mode:
self.fpf.update_cestatus_lkas()
else:
self.fpf.update_experimental_mode()
self.lkas_previously_pressed = lkas_pressed
SpeedLimitController.car_speed_limit = self.calculate_speed_limit(cp, cp_cam) * speed_factor

View File

@@ -126,12 +126,12 @@ def create_lfahda_mfc(packer, enabled, lat_active, hda_set_speed=0):
}
return packer.make_can_msg("LFAHDA_MFC", 0, values)
def create_acc_commands(packer, enabled, accel, upper_jerk, idx, lead_visible, set_speed, stopping, long_override, use_fca, cruise_available):
def create_acc_commands(packer, enabled, accel, upper_jerk, idx, lead_visible, set_speed, stopping, long_override, use_fca, cruise_available, personality_profile):
commands = []
scc11_values = {
"MainMode_ACC": 1 if cruise_available else 0,
"TauGapSet": 4,
"TauGapSet": personality_profile + 1,
"VSetDis": set_speed if enabled else 0,
"AliveCounterACC": idx % 0x10,
"ObjValid": 1, # close lead makes controls tighter

View File

@@ -121,7 +121,7 @@ def create_lfahda_cluster(packer, CAN, enabled, lat_active):
return packer.make_can_msg("LFAHDA_CLUSTER", CAN.ECAN, values)
def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_override, set_speed):
def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_override, set_speed, personality_profile):
jerk = 5
jn = jerk / 50
if not enabled or gas_override:
@@ -146,7 +146,7 @@ def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_ov
"SET_ME_2": 0x4,
"SET_ME_3": 0x3,
"SET_ME_TMP_64": 0x64,
"DISTANCE_SETTING": 4,
"DISTANCE_SETTING": personality_profile + 1,
}
return packer.make_can_msg("SCC_CONTROL", CAN.ECAN, values)