Compare commits

...

14 Commits

Author SHA1 Message Date
James Vecellio-Grant
874f04ac1a Merge branch 'master' into blend-exp 2025-08-29 16:20:17 -05:00
James Vecellio-Grant
d5eea30ad4 Merge branch 'master' into blend-exp 2025-08-26 16:06:56 -07:00
discountchubbs
fd790e684b longitudinal_planner: fix mode transition argument 2025-08-24 21:14:51 -05:00
James Vecellio-Grant
a7d6ac1a03 Merge branch 'master' into blend-exp 2025-08-24 19:11:55 -07:00
James Vecellio-Grant
2b2d0fe941 Merge branch 'master' into blend-exp 2025-08-21 06:42:21 -07:00
James Vecellio-Grant
2eb60e2b97 Merge branch 'master' into blend-exp 2025-08-18 12:17:04 -07:00
discountchubbs
b609bb1391 update 2025-08-18 12:15:37 -07:00
James Vecellio-Grant
8987ee1f9d Merge branch 'master' into blend-exp 2025-08-11 07:13:21 -07:00
Kumar
a39c9d8a2a Merge branch 'master' into blend-exp 2025-08-10 09:36:39 -07:00
discountchubbs
04189ae030 link to dec.active boolean 2025-08-07 09:48:15 -07:00
discountchubbs
9353e3c277 Attach to dynamic experimental controller 2025-08-01 15:00:34 -07:00
James Vecellio-Grant
1ce97e6033 Merge branch 'master' into blend-exp 2025-08-01 07:58:59 -07:00
discountchubbs
29c1f1d06b move to sunny long planner 2025-07-31 11:50:34 -07:00
discountchubbs
9cbce2af33 longitudinal_planner: acc to e2e transition
Use a k=2 sigmoid normalized at 0.5

longitudinal_planner: simple transition

Allow a toggleable param in the cruise panel
2025-07-31 11:26:45 -07:00
2 changed files with 32 additions and 1 deletions

View File

@@ -102,6 +102,8 @@ class LongitudinalPlanner(LongitudinalPlannerSP):
if not self.mlsim:
self.mpc.mode = dec_mpc_mode
self.handle_mode_transition(mode)
if len(sm['carControl'].orientationNED) == 3:
accel_coast = get_coast_accel(sm['carControl'].orientationNED[1])
else:
@@ -177,7 +179,7 @@ class LongitudinalPlanner(LongitudinalPlannerSP):
output_a_target = output_a_target_mpc
self.output_should_stop = output_should_stop_mpc
else:
output_a_target = min(output_a_target_mpc, output_a_target_e2e)
output_a_target = self.blend_accel_transition(output_a_target_mpc, output_a_target_e2e, v_ego)
self.output_should_stop = output_should_stop_e2e or output_should_stop_mpc
for idx in range(2):

View File

@@ -4,9 +4,11 @@ Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors.
This file is part of sunnypilot and is licensed under the MIT License.
See the LICENSE.md file in the root directory for more details.
"""
import math
from cereal import messaging, custom
from opendbc.car import structs
from opendbc.car.interfaces import ACCEL_MIN
from openpilot.sunnypilot.selfdrive.controls.lib.dec.dec import DynamicExperimentalController
from openpilot.sunnypilot.models.helpers import get_active_bundle
@@ -16,6 +18,7 @@ DecState = custom.LongitudinalPlanSP.DynamicExperimentalControl.DynamicExperimen
class LongitudinalPlannerSP:
def __init__(self, CP: structs.CarParams, mpc):
self.dec = DynamicExperimentalController(CP, mpc)
self.transition_init()
self.generation = int(model_bundle.generation) if (model_bundle := get_active_bundle()) else None
@property
@@ -29,6 +32,32 @@ class LongitudinalPlannerSP:
return self.dec.mode()
def transition_init(self) -> None:
self._transition_counter = 0
self._transition_steps = 20
self._last_mode = 'acc'
def handle_mode_transition(self, mode: str) -> None:
if self._last_mode != mode:
if mode == 'blended':
self._transition_counter = 0
self._last_mode = mode
def blend_accel_transition(self, mpc_accel: float, e2e_accel: float, v_ego: float) -> float:
if self.dec.enabled():
if self._transition_counter < self._transition_steps:
self._transition_counter += 1
progress = self._transition_counter / self._transition_steps
if v_ego > 5.0 and e2e_accel < 0.0:
if mpc_accel < 0.0 and e2e_accel > mpc_accel:
return mpc_accel
# use k3.0 and normalize midpoint at 0.5
sigmoid = 1.0 / (1.0 + math.exp(-3.0 * (abs(e2e_accel / ACCEL_MIN) - 0.5)))
blend_factor = 1.0 - (1.0 - progress) * (1.0 - sigmoid)
blended = mpc_accel + (e2e_accel - mpc_accel) * blend_factor
return blended
return min(mpc_accel, e2e_accel)
def update(self, sm: messaging.SubMaster) -> None:
self.dec.update(sm)