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

@@ -185,7 +185,7 @@ class CarController:
# Send dashboard UI commands (ACC status)
send_fcw = hud_alert == VisualAlert.fcw
can_sends.append(gmcan.create_acc_dashboard_command(self.packer_pt, CanBus.POWERTRAIN, CC.enabled,
hud_v_cruise * CV.MS_TO_KPH, hud_control.leadVisible, send_fcw))
hud_v_cruise * CV.MS_TO_KPH, hud_control.leadVisible, send_fcw, CS.display_menu, CS.personality_profile))
else:
# to keep accel steady for logs when not sending gas
accel += self.accel_g

View File

@@ -30,6 +30,11 @@ class CarState(CarStateBase):
# FrogPilot variables
self.single_pedal_mode = False
# FrogPilot variables
self.display_menu = False
self.display_timer = 0
def update(self, pt_cp, cam_cp, loopback_cp, frogpilot_variables):
ret = car.CarState.new_message()
@@ -162,6 +167,45 @@ class CarState(CarStateBase):
ret.leftBlindspot = cam_cp.vl["BCMBlindSpotMonitor"]["LeftBSM"] == 1
ret.rightBlindspot = cam_cp.vl["BCMBlindSpotMonitor"]["RightBSM"] == 1
# Driving personalities function - Credit goes to Mangomoose!
if frogpilot_variables.personalities_via_wheel and ret.cruiseState.available:
# Sync with the onroad UI button
if self.fpf.personality_changed_via_ui:
self.personality_profile = self.fpf.current_personality
self.previous_personality_profile = self.personality_profile
self.fpf.reset_personality_changed_param()
# Check if the car has a camera
has_camera = self.CP.networkLocation == NetworkLocation.fwdCamera
has_camera &= not self.CP.flags & GMFlags.NO_CAMERA.value
has_camera &= not self.CP.carFingerprint in (CC_ONLY_CAR)
if has_camera:
# Need to subtract by 1 to comply with the personality profiles of "0", "1", and "2"
self.personality_profile = cam_cp.vl["ASCMActiveCruiseControlStatus"]["ACCGapLevel"] - 1
else:
if self.CP.carFingerprint in SDGM_CAR:
distance_button = cam_cp.vl["ASCMSteeringButton"]["DistanceButton"]
else:
distance_button = pt_cp.vl["ASCMSteeringButton"]["DistanceButton"]
if distance_button and not self.distance_previously_pressed:
if self.display_menu:
self.personality_profile = (self.previous_personality_profile + 2) % 3
self.display_timer = 350
self.distance_previously_pressed = distance_button
# Check if the display is open
if self.display_timer > 0:
self.display_timer -= 1
self.display_menu = True
else:
self.display_menu = False
if self.personality_profile != self.previous_personality_profile and self.personality_profile >= 0:
self.fpf.distance_button_function(self.personality_profile)
self.previous_personality_profile = self.personality_profile
# Toggle Experimental Mode from steering wheel function
if frogpilot_variables.experimental_mode_via_lkas and ret.cruiseState.available:
if self.CP.carFingerprint in SDGM_CAR:

View File

@@ -105,14 +105,15 @@ def create_friction_brake_command(packer, bus, apply_brake, idx, enabled, near_s
return packer.make_can_msg("EBCMFrictionBrakeCmd", bus, values)
def create_acc_dashboard_command(packer, bus, enabled, target_speed_kph, lead_car_in_sight, fcw):
def create_acc_dashboard_command(packer, bus, enabled, target_speed_kph, lead_car_in_sight, fcw, display, personality_profile):
target_speed = min(target_speed_kph, 255)
values = {
"ACCAlwaysOne": 1,
"ACCResumeButton": 0,
"DisplayDistance": display,
"ACCSpeedSetpoint": target_speed,
"ACCGapLevel": 3 * enabled, # 3 "far", 0 "inactive"
"ACCGapLevel": min(personality_profile + 1, 3), # 3 "far", 0 "inactive"
"ACCCmdActive": enabled,
"ACCAlwaysOne2": 1,
"ACCLeadCar": lead_car_in_sight,