mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-06-30 19:12:07 +08:00
39afadb95f
UI Build LKAS engage/disengage sound It will now make the same sound as op engage/disengage Wheel Control fix 2 build Feature: Model Name on Developer Sidebar Model Name port and correct DEVELOPER_SIDEBAR_METRICS slot numbering Wheel Controls button fixes Mode/Star buttons were not showing on desk LKAS option was showing even when car was using it for AOL, not it hides it if being used for AOL MapGears Sync Accel/Decel on UI MapGears will sync with "Longitudinal Tuning" UI to show chosen accel/decel profile to match with chosen drive mode. Drive mode -> accel/decel profile mapping. Eco → Eco Normal → Standard Sport → Sport+/Sport Writes on gear state change, gated on MapAcceleration/MapDeceleration toggles independently ECU Disable and Auto long/exp check ECU Disable and Auto long/exp check compile Star and Mode buttons to wheel control options cereal/custom.capnp — Added modePressed @16 and customPressed @17 fields to StarPilotCarState opendbc_repo/opendbc/car/hyundai/carstate.py — Added STEERING_WHEEL_MEDIA_BUTTONS (50Hz) to the CANFD CAN parser, initialized mode_button/custom_button state, and set fp_ret.modePressed/fp_ret.customPressed in update_canfd() common/params_keys.h — Added 6 new params: ModeButtonControl, LongModeButtonControl, VeryLongModeButtonControl, StarButtonControl, LongStarButtonControl, VeryLongStarButtonControl starpilot/common/starpilot_variables.py — Added full short/long/very-long toggle processing for both Mode and Star buttons (gated on HyundaiFlags.CANFD), with has_canfd_media_buttons flag propagated to toggles starpilot/controls/starpilot_card.py — Added Mode and Star button press counters and short/long/very-long press event handling, mirroring the existing distance button logic selfdrive/ui/layouts/settings/starpilot/wheel.py — Added 6 new tiles for Mode/Star buttons (short, long, very long each), visible only when cs.isHKGCanFd is true MapGears for HKG Add HKG "Drive Modes" button ability to map to eco/normal/sport accel profiles. Dashboard speed limit reading for CANFD Add FR_CMR_02_100ms to CAN parsers in get_can_parsers_canfd: on ECAN (freq=10) for LKA_STEERING cars, on CAM (freq=0, optional) for all others calculate_canfd_speed_limit and fp_ret.dashboardSpeedLimit assignment were already present CAM bus uses freq=0 to avoid breaking canValid on non-LKA cars that don't have this message CANFD steering limits Raises STEER_MAX to 409 Speed-dependent deltas (DELTA_UP=10/DOWN=8 below 15 m/s, UP=2/DOWN=3 above), Update panda safety ceiling and tests to match. Removes TacoTuneHacks toggle dependency. Ioniq 6 toml values update Updated toml values closer to learned values DBC Update HKG Signals Added 5 new messages to hyundai_canfd.dbc and hyundai_canfd_generated.dbc: DRIVE_MODE_EV (0x205): EV drive mode state with Normal/Eco/Sport (button) values. Can be used to change acceleration profiles in openpilot based on drive mode. CAM_0x361 (0x361): Camera sign recognition with SIGN_TYPE and SIGN_TYPE_2 signals. Dashboard Speed Limit. Can be used as source for SLC. ADAS_0x380 (0x380): ADAS stop sign detection bit. Dashboard stop sign alert. Triggers 80-90ft before stop sign typically and can be used to help stopping for stop signs. DOOR_LOCK (0x414): Not actual command to lock/unlock, but may be used to detect lock state changes. STEERING_WHEEL_MEDIA_BUTTONS (0x448): Steering wheel button inputs (voice, phone, mode, next/prev, menu, scroll, custom) Can be used to assign custom functions to steering wheel buttons in openpilot. Targets Ioniq 6 but may apply to other Hyundai CAN FD vehicles.
160 lines
7.1 KiB
Python
160 lines
7.1 KiB
Python
#!/usr/bin/env python3
|
|
import numpy as np
|
|
|
|
from openpilot.common.params import Params
|
|
from openpilot.selfdrive.controls.lib.longitudinal_planner import A_CRUISE_MIN, get_max_accel
|
|
|
|
from openpilot.starpilot.common.accel_profile import (
|
|
ACCELERATION_PROFILES,
|
|
DECELERATION_PROFILES,
|
|
coerce_custom_accel_profile_values,
|
|
get_accel_profile_curve_values,
|
|
get_max_allowed_accel as get_profile_max_allowed_accel,
|
|
interpolate_accel_profile,
|
|
)
|
|
from openpilot.starpilot.common.starpilot_variables import CITY_SPEED_LIMIT
|
|
|
|
def cubic_interp(x, xp, fp):
|
|
"""Cubic interpolation using NumPy's native operations for speed."""
|
|
# Boundary conditions
|
|
if x <= xp[0]:
|
|
return fp[0]
|
|
elif x >= xp[-1]:
|
|
return fp[-1]
|
|
|
|
# Find interval
|
|
i = np.searchsorted(xp, x) - 1
|
|
i = max(0, min(i, len(xp)-2)) # clamp the index
|
|
|
|
# Normalized position
|
|
t = (x - xp[i]) / float(xp[i+1] - xp[i])
|
|
|
|
# Hermite cubic formula
|
|
return fp[i]*(1 - 3*t**2 + 2*t**3) + fp[i+1]*(3*t**2 - 2*t**3)
|
|
|
|
def akima_interp(x, xp, fp):
|
|
"""Akima-inspired interpolation with reduced overshoot characteristics."""
|
|
if x <= xp[0]:
|
|
return fp[0]
|
|
elif x >= xp[-1]:
|
|
return fp[-1]
|
|
|
|
i = np.searchsorted(xp, x) - 1
|
|
i = max(0, min(i, len(xp)-2)) # clamp the index
|
|
|
|
t = (x - xp[i]) / float(xp[i+1] - xp[i])
|
|
|
|
# Quintic polynomial to reduce overshoot
|
|
t2 = t*t
|
|
t4 = t2*t2
|
|
t3 = t2*t
|
|
return (fp[i]*(1 - 10*t3 + 15*t4 - 6*t3*t2)
|
|
+ fp[i+1]*(10*t3 - 15*t4 + 6*t3*t2))
|
|
|
|
A_CRUISE_MIN_ECO = A_CRUISE_MIN / 2
|
|
A_CRUISE_MIN_SPORT = A_CRUISE_MIN * 2
|
|
|
|
def get_max_accel_eco(v_ego, ev_tuning=True, truck_tuning=False):
|
|
return interpolate_accel_profile(v_ego, get_accel_profile_curve_values(ACCELERATION_PROFILES["ECO"], ev_tuning, truck_tuning))
|
|
|
|
def get_max_accel_sport(v_ego, ev_tuning=True, truck_tuning=False):
|
|
return interpolate_accel_profile(v_ego, get_accel_profile_curve_values(ACCELERATION_PROFILES["SPORT"], ev_tuning, truck_tuning))
|
|
|
|
def get_max_accel_standard(v_ego, ev_tuning=True, truck_tuning=False):
|
|
if ev_tuning or truck_tuning:
|
|
return interpolate_accel_profile(v_ego, get_accel_profile_curve_values(ACCELERATION_PROFILES["STANDARD"], ev_tuning, truck_tuning))
|
|
return interpolate_accel_profile(v_ego, [1.60, 1.40, 1.20, 1.0666666666666667, 0.9333333333333333, 0.80, 0.60])
|
|
|
|
def get_max_accel_custom(v_ego, custom_curve, acceleration_profile, ev_tuning=True, truck_tuning=False):
|
|
curve_values = coerce_custom_accel_profile_values(custom_curve, acceleration_profile, ev_tuning, truck_tuning)
|
|
return interpolate_accel_profile(v_ego, curve_values)
|
|
|
|
def get_max_accel_low_speeds(max_accel, v_cruise):
|
|
return float(akima_interp(v_cruise, [0., CITY_SPEED_LIMIT / 2, CITY_SPEED_LIMIT], [max_accel / 4, max_accel / 2, max_accel]))
|
|
|
|
def get_max_accel_ramp_off(max_accel, v_cruise, v_ego):
|
|
return float(akima_interp(v_cruise - v_ego, [0., 1., 5., 10.], [0., 0.5, 1.0, max_accel]))
|
|
|
|
def get_max_allowed_accel(v_ego, ev_tuning=True, truck_tuning=False):
|
|
return float(get_profile_max_allowed_accel(v_ego, ev_tuning, truck_tuning))
|
|
|
|
class StarPilotAcceleration:
|
|
def __init__(self, StarPilotPlanner):
|
|
self.starpilot_planner = StarPilotPlanner
|
|
self.params = Params()
|
|
|
|
self.max_accel = 0
|
|
self.min_accel = 0
|
|
|
|
self.last_gear_state = "init"
|
|
|
|
def update(self, v_ego, sm, starpilot_toggles):
|
|
eco_gear = sm["starpilotCarState"].ecoGear
|
|
sport_gear = sm["starpilotCarState"].sportGear
|
|
ev_tuning = getattr(starpilot_toggles, "ev_tuning", True)
|
|
truck_tuning = getattr(starpilot_toggles, "truck_tuning", False)
|
|
custom_accel_profile = getattr(starpilot_toggles, "custom_accel_profile", False)
|
|
custom_accel_profile_values = getattr(starpilot_toggles, "custom_accel_profile_values", [])
|
|
|
|
if custom_accel_profile:
|
|
self.max_accel = get_max_accel_custom(v_ego, custom_accel_profile_values, starpilot_toggles.acceleration_profile, ev_tuning, truck_tuning)
|
|
elif sm["starpilotCarState"].trafficModeEnabled:
|
|
self.max_accel = get_max_accel_standard(v_ego, ev_tuning, truck_tuning)
|
|
elif starpilot_toggles.map_acceleration and (eco_gear or sport_gear):
|
|
if eco_gear:
|
|
self.max_accel = get_max_accel_eco(v_ego, ev_tuning, truck_tuning)
|
|
else:
|
|
self.max_accel = get_max_allowed_accel(v_ego, ev_tuning, truck_tuning)
|
|
else:
|
|
if starpilot_toggles.acceleration_profile == ACCELERATION_PROFILES["ECO"]:
|
|
self.max_accel = get_max_accel_eco(v_ego, ev_tuning, truck_tuning)
|
|
elif starpilot_toggles.acceleration_profile == ACCELERATION_PROFILES["SPORT"]:
|
|
self.max_accel = get_max_accel_sport(v_ego, ev_tuning, truck_tuning)
|
|
elif starpilot_toggles.acceleration_profile == ACCELERATION_PROFILES["SPORT_PLUS"]:
|
|
self.max_accel = get_max_allowed_accel(v_ego, ev_tuning, truck_tuning)
|
|
else:
|
|
self.max_accel = get_max_accel_standard(v_ego, ev_tuning, truck_tuning)
|
|
|
|
if starpilot_toggles.human_acceleration:
|
|
self.max_accel = min(get_max_accel_low_speeds(self.max_accel, self.starpilot_planner.v_cruise), self.max_accel)
|
|
self.max_accel = min(get_max_accel_ramp_off(self.max_accel, self.starpilot_planner.v_cruise, v_ego), self.max_accel)
|
|
|
|
if self.starpilot_planner.starpilot_weather.weather_id != 0:
|
|
self.max_accel -= self.max_accel * self.starpilot_planner.starpilot_weather.reduce_acceleration
|
|
|
|
if sm["starpilotCarState"].forceCoast:
|
|
self.min_accel = A_CRUISE_MIN_ECO
|
|
elif starpilot_toggles.map_deceleration and (eco_gear or sport_gear):
|
|
if eco_gear:
|
|
self.min_accel = A_CRUISE_MIN_ECO
|
|
else:
|
|
self.min_accel = A_CRUISE_MIN_SPORT
|
|
else:
|
|
if starpilot_toggles.deceleration_profile == DECELERATION_PROFILES["ECO"]:
|
|
self.min_accel = A_CRUISE_MIN_ECO
|
|
elif starpilot_toggles.deceleration_profile == DECELERATION_PROFILES["SPORT"]:
|
|
self.min_accel = A_CRUISE_MIN_SPORT
|
|
else:
|
|
self.min_accel = A_CRUISE_MIN
|
|
|
|
# Sync AccelerationProfile and DecelerationProfile params so the UI reflects the active drive mode
|
|
# Eco → Eco, Normal → Standard, Sport → Sport+
|
|
gear_state = "eco" if eco_gear else ("sport" if sport_gear else "normal")
|
|
if gear_state != self.last_gear_state:
|
|
self.last_gear_state = gear_state
|
|
if gear_state == "eco":
|
|
if starpilot_toggles.map_acceleration:
|
|
self.params.put_nonblocking("AccelerationProfile", ACCELERATION_PROFILES["ECO"])
|
|
if starpilot_toggles.map_deceleration:
|
|
self.params.put_nonblocking("DecelerationProfile", DECELERATION_PROFILES["ECO"])
|
|
elif gear_state == "sport":
|
|
if starpilot_toggles.map_acceleration:
|
|
self.params.put_nonblocking("AccelerationProfile", ACCELERATION_PROFILES["SPORT_PLUS"])
|
|
if starpilot_toggles.map_deceleration:
|
|
self.params.put_nonblocking("DecelerationProfile", DECELERATION_PROFILES["SPORT"])
|
|
else:
|
|
if starpilot_toggles.map_acceleration:
|
|
self.params.put_nonblocking("AccelerationProfile", ACCELERATION_PROFILES["STANDARD"])
|
|
if starpilot_toggles.map_deceleration:
|
|
self.params.put_nonblocking("DecelerationProfile", DECELERATION_PROFILES["STANDARD"])
|